Make code2 the default code app
This commit is contained in:
@@ -556,6 +556,16 @@ define([
|
||||
});
|
||||
common.findOKButton().text(Messages.cancelButton);
|
||||
};
|
||||
// Secure iframes
|
||||
common.useTemplate = function (href, Crypt, cb) {
|
||||
var parsed = parsePadUrl(href);
|
||||
if(!parsed) { throw new Error("Cannot get template hash"); }
|
||||
Crypt.get(parsed.hash, function (err, val) {
|
||||
if (err) { throw new Error(err); }
|
||||
var p = parsePadUrl(window.location.href);
|
||||
Crypt.put(p.hash, val, cb);
|
||||
});
|
||||
};
|
||||
|
||||
// STORAGE
|
||||
/* fetch and migrate your pad history from the store */
|
||||
@@ -735,17 +745,19 @@ define([
|
||||
return list;
|
||||
};
|
||||
// Needed for the secure filepicker app
|
||||
common.getSecureFilesList = function (cb) {
|
||||
common.getSecureFilesList = function (filter, cb) {
|
||||
var store = common.getStore();
|
||||
if (!store) { return void cb("Store is not ready"); }
|
||||
var proxy = store.getProxy();
|
||||
var fo = proxy.fo;
|
||||
var list = {};
|
||||
var hashes = [];
|
||||
fo.getFiles([fo.ROOT]).forEach(function (id) {
|
||||
var types = filter.types;
|
||||
var where = filter.where;
|
||||
fo.getFiles(where).forEach(function (id) {
|
||||
var data = fo.getFileData(id);
|
||||
var parsed = parsePadUrl(data.href);
|
||||
if ((parsed.type === 'file' || parsed.type === 'media')
|
||||
if ((!types || types.length === 0 || types.indexOf(parsed.type) !== -1)
|
||||
&& hashes.indexOf(parsed.hash) === -1) {
|
||||
hashes.push(parsed.hash);
|
||||
list[id] = data;
|
||||
|
||||
@@ -73,6 +73,7 @@ define(['json.sortify'], function (Sortify) {
|
||||
});
|
||||
};
|
||||
|
||||
console.log('here register');
|
||||
sframeChan.on('EV_METADATA_UPDATE', function (ev) {
|
||||
meta = ev;
|
||||
if (ev.priv) {
|
||||
|
||||
@@ -46,7 +46,9 @@ define([
|
||||
$('<td>').text(Messages.cancel).appendTo($thead);
|
||||
|
||||
var createTableContainer = function ($body) {
|
||||
console.log($body);
|
||||
File.$container = $('<div>', { id: 'cp-fileupload' }).append($table).appendTo($body);
|
||||
console.log('done');
|
||||
return File.$container;
|
||||
};
|
||||
|
||||
@@ -62,6 +64,25 @@ define([
|
||||
return data;
|
||||
};
|
||||
|
||||
var sframeChan = common.getSframeChannel();
|
||||
var onError = $.noop,
|
||||
onComplete = $.noop,
|
||||
updateProgress = $.noop,
|
||||
onPending = $.noop;
|
||||
sframeChan.on('EV_FILE_UPLOAD_STATE', function (data) {
|
||||
if (data.error) {
|
||||
return void onError(data.error);
|
||||
}
|
||||
if (data.complete && data.href) {
|
||||
return void onComplete(data.href);
|
||||
}
|
||||
if (typeof data.progress !== "undefined") {
|
||||
return void updateProgress(data.progress);
|
||||
}
|
||||
});
|
||||
sframeChan.on('Q_CANCEL_PENDING_FILE_UPLOAD', function (data, cb) {
|
||||
onPending(cb);
|
||||
});
|
||||
var upload = function (file) {
|
||||
var blob = file.blob; // This is not a blob but an array buffer
|
||||
var u8 = new Uint8Array(blob);
|
||||
@@ -80,16 +101,14 @@ define([
|
||||
var $pc = $row.find('.cp-fileupload-table-progress');
|
||||
var $link = $row.find('.cp-fileupload-table-link');
|
||||
|
||||
var sframeChan = common.getSframeChannel();
|
||||
|
||||
var updateProgress = function (progressValue) {
|
||||
updateProgress = function (progressValue) {
|
||||
$pv.text(Math.round(progressValue*100)/100 + '%');
|
||||
$pb.css({
|
||||
width: (progressValue/100)*$pc.width()+'px'
|
||||
});
|
||||
};
|
||||
|
||||
var onComplete = function (href) {
|
||||
onComplete = function (href) {
|
||||
$link.attr('href', href)
|
||||
.click(function (e) {
|
||||
e.preventDefault();
|
||||
@@ -108,7 +127,7 @@ define([
|
||||
queue.next();
|
||||
};
|
||||
|
||||
var onError = function (e) {
|
||||
onError = function (e) {
|
||||
queue.inProgress = false;
|
||||
queue.next();
|
||||
if (e === 'TOO_LARGE') {
|
||||
@@ -123,24 +142,10 @@ define([
|
||||
return void Cryptpad.alert(Messages.upload_serverError);
|
||||
};
|
||||
|
||||
var onPending = function (cb) {
|
||||
onPending = function (cb) {
|
||||
Cryptpad.confirm(Messages.upload_uploadPending, cb);
|
||||
};
|
||||
|
||||
sframeChan.on('EV_FILE_UPLOAD_STATE', function (data) {
|
||||
if (data.error) {
|
||||
return void onError(data.error);
|
||||
}
|
||||
if (data.complete && data.href) {
|
||||
return void onComplete(data.href);
|
||||
}
|
||||
if (typeof data.progress !== "undefined") {
|
||||
return void updateProgress(data.progress);
|
||||
}
|
||||
});
|
||||
sframeChan.on('Q_CANCEL_PENDING_FILE_UPLOAD', function (data, cb) {
|
||||
onPending(cb);
|
||||
});
|
||||
file.noStore = config.noStore;
|
||||
try {
|
||||
file.blob = Nacl.util.encodeBase64(u8);
|
||||
@@ -168,7 +173,8 @@ define([
|
||||
return;
|
||||
}
|
||||
if (queue.inProgress) { return; }
|
||||
File.$container.show();
|
||||
// setTimeout to fix a firefox error 'NS_ERROR_NOT_AVAILABLE'
|
||||
window.setTimeout(function () { File.$container.show(); });
|
||||
var file = queue.queue.shift();
|
||||
upload(file);
|
||||
};
|
||||
@@ -177,7 +183,8 @@ define([
|
||||
obj.id = id;
|
||||
queue.queue.push(obj);
|
||||
|
||||
$table.show();
|
||||
// setTimeout to fix a firefox error 'NS_ERROR_NOT_AVAILABLE'
|
||||
window.setTimeout(function () { $table.show(); });
|
||||
var estimate = FileCrypto.computeEncryptedSize(obj.blob.byteLength, obj.metadata);
|
||||
|
||||
var $progressBar = $('<div>', {'class':'cp-fileupload-table-progress-container'});
|
||||
|
||||
@@ -261,69 +261,6 @@ define([
|
||||
return $userAdmin;
|
||||
};
|
||||
|
||||
// createFileDialog can only be used in filepicker due to access rights restrictions
|
||||
UI.createFileDialog = function (cfg) {
|
||||
var common = cfg.common;
|
||||
var sframeChan = common.getSframeChannel();
|
||||
var updateContainer;
|
||||
var hideFileDialog = function () {
|
||||
sframeChan.event('EV_FILE_PICKER_CLOSE');
|
||||
};
|
||||
// Create modal
|
||||
var $blockContainer = Cryptpad.createModal({
|
||||
id: 'cp-filepicker-dialog',
|
||||
$body: cfg.$body,
|
||||
onClose: hideFileDialog
|
||||
}).show();
|
||||
// Set the fixed content
|
||||
var $block = $blockContainer.find('.cp-modal');
|
||||
var $description = $('<p>').text(Messages.filePicker_description);
|
||||
$block.append($description);
|
||||
var $filter = $('<p>', {'class': 'cp-modal-form'}).appendTo($block);
|
||||
var to;
|
||||
$('<input>', {
|
||||
type: 'text',
|
||||
'class': 'cp-filepicker-filter',
|
||||
'placeholder': Messages.filePicker_filter
|
||||
}).appendTo($filter).on('keypress', function () {
|
||||
if (to) { window.clearTimeout(to); }
|
||||
to = window.setTimeout(updateContainer, 300);
|
||||
});
|
||||
$filter.append(common.createButton('upload', false, cfg.data, function () {
|
||||
hideFileDialog();
|
||||
}));
|
||||
var $container = $('<span>', {'class': 'cp-filepicker-content'}).appendTo($block);
|
||||
// Update the files list when needed
|
||||
updateContainer = function () {
|
||||
$container.html('');
|
||||
var filter = $filter.find('.cp-filepicker-filter').val().trim();
|
||||
var todo = function (err, list) {
|
||||
if (err) { return void console.error(err); }
|
||||
Object.keys(list).forEach(function (id) {
|
||||
var data = list[id];
|
||||
var name = data.title || '?';
|
||||
if (filter && name.toLowerCase().indexOf(filter.toLowerCase()) === -1) {
|
||||
return;
|
||||
}
|
||||
var $span = $('<span>', {
|
||||
'class': 'cp-filepicker-content-element',
|
||||
'title': name,
|
||||
}).appendTo($container);
|
||||
$span.append(Cryptpad.getFileIcon(data));
|
||||
$span.append(name);
|
||||
$span.click(function () {
|
||||
if (typeof cfg.onSelect === "function") { cfg.onSelect(data.href); }
|
||||
hideFileDialog();
|
||||
});
|
||||
});
|
||||
};
|
||||
common.getFilesList(todo);
|
||||
};
|
||||
updateContainer();
|
||||
sframeChan.on('EV_FILE_PICKER_REFRESH', updateContainer);
|
||||
};
|
||||
|
||||
|
||||
UI.initFilePicker = function (common, cfg) {
|
||||
var onSelect = cfg.onSelect || $.noop;
|
||||
var sframeChan = common.getSframeChannel();
|
||||
@@ -331,9 +268,35 @@ define([
|
||||
onSelect(data);
|
||||
});
|
||||
};
|
||||
UI.openFilePicker = function (common) {
|
||||
UI.openFilePicker = function (common, types) {
|
||||
var sframeChan = common.getSframeChannel();
|
||||
sframeChan.event("EV_FILE_PICKER_OPEN");
|
||||
sframeChan.event("EV_FILE_PICKER_OPEN", types);
|
||||
};
|
||||
|
||||
UI.openTemplatePicker = function (common) {
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
var type = metadataMgr.getMetadataLazy().type;
|
||||
var first = true; // We can only pick a template once (for a new document)
|
||||
var fileDialogCfg = {
|
||||
onSelect: function (data) {
|
||||
if (data.type === type && first) {
|
||||
Cryptpad.addLoadingScreen(null, true);
|
||||
var sframeChan = common.getSframeChannel();
|
||||
sframeChan.query('Q_TEMPLATE_USE', data.href, function () {
|
||||
first = false;
|
||||
Cryptpad.removeLoadingScreen();
|
||||
common.feedback('TEMPLATE_USED');
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
common.initFilePicker(common, fileDialogCfg);
|
||||
var pickerCfg = {
|
||||
types: [type],
|
||||
where: ['template']
|
||||
};
|
||||
common.openFilePicker(common, pickerCfg);
|
||||
};
|
||||
|
||||
return UI;
|
||||
|
||||
@@ -255,7 +255,7 @@ define([
|
||||
});
|
||||
|
||||
var FP = {};
|
||||
var initFilePicker = function () {
|
||||
var initFilePicker = function (types) {
|
||||
var config = {};
|
||||
config.onFilePicked = function (data) {
|
||||
sframeChan.event('EV_FILE_PICKED', data);
|
||||
@@ -264,16 +264,21 @@ define([
|
||||
FP.$iframe.hide();
|
||||
};
|
||||
config.onFileUpload = onFileUpload;
|
||||
config.types = types;
|
||||
if (!FP.$iframe) {
|
||||
FP.$iframe = $('<iframe>', {id: 'sbox-filePicker-iframe'}).appendTo($('body'));
|
||||
FP.picker = FilePicker.create(config);
|
||||
} else {
|
||||
FP.$iframe.show();
|
||||
FP.picker.refresh();
|
||||
FP.picker.refresh(types);
|
||||
}
|
||||
};
|
||||
sframeChan.on('EV_FILE_PICKER_OPEN', function () {
|
||||
initFilePicker();
|
||||
sframeChan.on('EV_FILE_PICKER_OPEN', function (data) {
|
||||
initFilePicker(data);
|
||||
});
|
||||
|
||||
sframeChan.on('Q_TEMPLATE_USE', function (href, cb) {
|
||||
Cryptpad.useTemplate(href, Cryptget, cb);
|
||||
});
|
||||
|
||||
CpNfOuter.start({
|
||||
|
||||
@@ -55,9 +55,9 @@ define([
|
||||
// UI
|
||||
funcs.createUserAdminMenu = UI.createUserAdminMenu;
|
||||
funcs.displayAvatar = UI.displayAvatar;
|
||||
funcs.createFileDialog = UI.createFileDialog;
|
||||
funcs.initFilePicker = UI.initFilePicker;
|
||||
funcs.openFilePicker = UI.openFilePicker;
|
||||
funcs.openTemplatePicker = UI.openTemplatePicker;
|
||||
|
||||
// History
|
||||
funcs.getHistory = function (config) { return History.create(funcs, config); };
|
||||
@@ -341,8 +341,8 @@ define([
|
||||
|
||||
|
||||
// Can, only be called by the filepicker app
|
||||
funcs.getFilesList = function (cb) {
|
||||
ctx.sframeChan.query('Q_GET_FILES_LIST', null, function (err, data) {
|
||||
funcs.getFilesList = function (types, cb) {
|
||||
ctx.sframeChan.query('Q_GET_FILES_LIST', types, function (err, data) {
|
||||
cb(err || data.error, data.data);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -100,6 +100,9 @@ define({
|
||||
// Get all the files from the drive to display them in a file picker secure app
|
||||
'Q_GET_FILES_LIST': true,
|
||||
|
||||
// Template picked, replace the content of the pad
|
||||
'Q_TEMPLATE_USE': true,
|
||||
|
||||
// File upload queries and events
|
||||
'Q_UPLOAD_FILE': true,
|
||||
'EV_FILE_UPLOAD_STATE': true,
|
||||
|
||||
Reference in New Issue
Block a user