resolve merge conflicts

This commit is contained in:
ansuz
2017-11-23 16:56:49 +01:00
88 changed files with 2238 additions and 8645 deletions

View File

@@ -2,8 +2,11 @@ define([
'jquery',
'/common/toolbar3.js',
'json.sortify',
'/common/cryptpad-common.js',
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-ui-elements.js',
'/common/common-interface.js',
'/common/common-constants.js',
'/common/cryptget.js',
'/bower_components/nthen/index.js',
'/common/sframe-common.js',
@@ -11,6 +14,7 @@ define([
'/common/userObject.js',
'/customize/application_config.js',
'/common/sframe-chainpad-listmap.js',
'/customize/messages.js',
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
@@ -19,21 +23,22 @@ define([
$,
Toolbar,
JSONSortify,
Cryptpad,
Util,
Hash,
UIElements,
UI,
Constants,
Cryptget,
nThen,
SFCommon,
CommonRealtime,
FO,
AppConfig,
Listmap)
Listmap,
Messages)
{
var Messages = Cryptpad.Messages;
var APP = window.APP = {
editable: false,
Cryptpad: Cryptpad,
mobile: function () { return $('body').width() <= 600; } // Menu and content area are not inline-block anymore for mobiles
};
@@ -41,17 +46,13 @@ define([
return JSONSortify(obj);
};
var onConnectError = function () {
Cryptpad.errorLoadingScreen(Messages.websocketError);
};
var E_OVER_LIMIT = 'E_OVER_LIMIT';
var SEARCH = "search";
var SEARCH_NAME = Messages.fm_searchName;
var ROOT = "root";
var ROOT_NAME = Messages.fm_rootName;
var FILES_DATA = Cryptpad.storageKey;
var FILES_DATA = Constants.storageKey;
var FILES_DATA_NAME = Messages.fm_filesDataName;
var TEMPLATE = "template";
var TEMPLATE_NAME = Messages.fm_templateName;
@@ -74,7 +75,7 @@ define([
var logError = config.logError = function () {
console.error.apply(console, arguments);
};
var log = config.log = Cryptpad.log;
var log = config.log = UI.log;
var localStore = window.cryptpadStore;
APP.store = {};
@@ -191,13 +192,11 @@ define([
var user = metadataMgr.getUserData();
var isOwnDrive = function () {
return true; // TODO
//return Cryptpad.getUserHash() === APP.hash || localStorage.FS_hash === APP.hash;
};
var isWorkgroup = function () {
return files.workgroup === 1;
};
config.workgroup = isWorkgroup();
config.Cryptpad = Cryptpad;
config.loggedIn = APP.loggedIn;
APP.origin = priv.origin;
@@ -253,7 +252,7 @@ define([
currentPath = [FILES_DATA];
$tree.hide();
if (Object.keys(files.root).length && !proxy.anonymousAlert) {
Cryptpad.alert(Messages.fm_alert_anonymous, null, true);
UI.alert(Messages.fm_alert_anonymous, null, true);
proxy.anonymousAlert = true;
}
}
@@ -415,10 +414,6 @@ define([
var ev = {};
if (e.ctrlKey) { ev.ctrlKey = true; }
if (e.shiftKey) { ev.shiftKey = true; }
var click = function (el) {
if (!el) { return; }
APP.onElementClick(ev, $(el));
};
// Enter
if (e.which === 13) {
@@ -440,6 +435,11 @@ define([
if ([37, 38, 39, 40].indexOf(e.which) === -1) { return; }
e.preventDefault();
var click = function (el) {
if (!el) { return; }
APP.onElementClick(ev, $(el));
};
var $selection = $content.find('.cp-app-drive-element.cp-app-drive-element-selected');
if ($selection.length === 0) { return void click($elements.first()[0]); }
@@ -577,6 +577,7 @@ define([
$input.on('keydown', function (e) { e.stopPropagation(); });
$input.on('keyup', function (e) {
e.stopPropagation();
if (e.which === 13) {
removeInput(true);
filesOp.rename(path, $input.val(), refresh);
@@ -585,7 +586,7 @@ define([
if (e.which === 27) {
removeInput(true);
}
});
}).on('keypress', function (e) { e.stopPropagation(); });
//$element.parent().append($input);
$name.after($input);
$input.focus();
@@ -1142,7 +1143,7 @@ define([
var data = filesOp.getFileData(element);
if (!data) { return void logError("No data for the file", element); }
var hrefData = Cryptpad.parsePadUrl(data.href);
var hrefData = Hash.parsePadUrl(data.href);
if (hrefData.type) {
$span.addClass('cp-border-color-'+hrefData.type);
}
@@ -1209,9 +1210,9 @@ define([
// This is duplicated in cryptpad-common, it should be unified
var getFileIcon = function (id) {
var data = filesOp.getFileData(id);
return Cryptpad.getFileIcon(data);
return UI.getFileIcon(data);
};
var getIcon = Cryptpad.getIcon;
var getIcon = UI.getIcon;
// Create the "li" element corresponding to the file/folder located in "path"
var createElement = function (path, elPath, root, isFolder) {
@@ -1440,7 +1441,7 @@ define([
$button.addClass('cp-app-drive-toolbar-emptytrash');
$button.attr('title', Messages.fc_empty);
$button.click(function () {
Cryptpad.confirm(Messages.fm_emptyTrashDialog, function(res) {
UI.confirm(Messages.fm_emptyTrashDialog, function(res) {
if (!res) { return; }
filesOp.emptyTrash(refresh);
});
@@ -1455,7 +1456,7 @@ define([
if (type === 'contacts') { return; }
if (type === 'todo') { return; }
if (type === 'file') { return; }
if (!Cryptpad.isLoggedIn() && AppConfig.registeredOnlyTypes &&
if (!APP.loggedIn && AppConfig.registeredOnlyTypes &&
AppConfig.registeredOnlyTypes.indexOf(type) !== -1) {
return;
}
@@ -1469,9 +1470,9 @@ define([
var onCreated = function (err, info) {
if (err) {
if (err === E_OVER_LIMIT) {
return void Cryptpad.alert(Messages.pinLimitDrive, null, true);
return void UI.alert(Messages.pinLimitDrive, null, true);
}
return void Cryptpad.alert(Messages.fm_error_cantPin);
return void UI.alert(Messages.fm_error_cantPin);
}
APP.newFolder = info.newPath;
refresh();
@@ -1500,7 +1501,7 @@ define([
.click(function () {
var type = $(this).attr('data-type') || 'pad';
var path = filesOp.isPathIn(currentPath, [TRASH]) ? '' : currentPath;
common.sessionStorage.put(Cryptpad.newPadPathKey, path, function () {
common.sessionStorage.put(Constants.newPadPathKey, path, function () {
common.openURL('/' + type + '/');
});
});
@@ -1547,7 +1548,7 @@ define([
options: options,
feedback: 'DRIVE_NEWPAD_LOCALFOLDER',
};
var $block = Cryptpad.createDropdown(dropdownConfig);
var $block = UIElements.createDropdown(dropdownConfig);
// Custom style:
$block.find('button').addClass('cp-app-drive-toolbar-new');
@@ -1701,7 +1702,7 @@ define([
var data = filesOp.getFileData(id);
if (!data) { return ''; }
if (prop === 'type') {
var hrefData = Cryptpad.parsePadUrl(data.href);
var hrefData = Hash.parsePadUrl(data.href);
return hrefData.type;
}
if (prop === 'atime' || prop === 'ctime') {
@@ -1736,7 +1737,7 @@ define([
};
}
if (prop === 'type') {
var hrefData = Cryptpad.parsePadUrl(e.href);
var hrefData = Hash.parsePadUrl(e.href);
return hrefData.type;
}
if (prop === 'atime' || prop === 'ctime') {
@@ -1797,7 +1798,7 @@ define([
.text(Messages.fm_newFile));
$element.attr('title', Messages.fm_newFile);
$element.click(function () {
var $modal = Cryptpad.createModal({
var $modal = UIElements.createModal({
id: 'cp-app-drive-new-ghost-dialog',
$body: $('body')
});
@@ -1951,7 +1952,7 @@ define([
filesList.forEach(function (r) {
r.paths.forEach(function (path) {
var href = r.data.href;
var parsed = Cryptpad.parsePadUrl(href);
var parsed = Hash.parsePadUrl(href);
var $table = $('<table>');
var $icon = $('<td>', {'rowspan': '3', 'class': 'cp-app-drive-search-icon'})
.append(getFileIcon(href));
@@ -2382,6 +2383,13 @@ define([
if (!filesOp.comparePath(newLocation, currentPath.slice())) { displayDirectory(newLocation); }
return;
}
if (e.which === 27) {
$input.val('');
setSearchCursor(0);
if (search.oldLocation && search.oldLocation.length) { displayDirectory(search.oldLocation); }
else { displayDirectory([ROOT]); }
return;
}
if (APP.mobile()) { return; }
search.to = window.setTimeout(function () {
if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); }
@@ -2441,13 +2449,13 @@ define([
if (!filesOp.isFile(id)) { return; }
var data = filesOp.getFileData(id);
if (!data) { return; }
var parsed = Cryptpad.parsePadUrl(data.href);
var parsed = Hash.parsePadUrl(data.href);
if (parsed.hashData.type !== "pad") { return; }
var i = data.href.indexOf('#') + 1;
var base = APP.origin + data.href.slice(0, i);
var hrefsecret = Cryptpad.getSecrets(parsed.type, parsed.hash);
var base = data.href.slice(0, i);
var hrefsecret = Hash.getSecrets(parsed.type, parsed.hash);
if (!hrefsecret.keys) { return; }
var viewHash = Cryptpad.getViewHashFromKeys(hrefsecret.channel, hrefsecret.keys);
var viewHash = Hash.getViewHashFromKeys(hrefsecret.channel, hrefsecret.keys);
return base + viewHash;
};
@@ -2475,17 +2483,17 @@ define([
$('<br>').appendTo($d);
if (!ro) {
$('<label>', {'for': 'cp-app-drive-prop-link'}).text(Messages.editShare).appendTo($d);
$d.append(Cryptpad.dialog.selectable(base + data.href, {
$d.append(UI.dialog.selectable(base + data.href, {
id: 'cp-app-drive-prop-link',
}));
}
var parsed = Cryptpad.parsePadUrl(data.href);
var parsed = Hash.parsePadUrl(data.href);
if (parsed.hashData && parsed.hashData.type === 'pad') {
var roLink = ro ? base + data.href : getReadOnlyUrl(el);
var roLink = ro ? base + data.href : base + getReadOnlyUrl(el);
if (roLink) {
$('<label>', {'for': 'cp-app-drive-prop-rolink'}).text(Messages.viewShare).appendTo($d);
$d.append(Cryptpad.dialog.selectable(roLink, {
$d.append(UI.dialog.selectable(roLink, {
id: 'cp-app-drive-prop-rolink',
}));
}
@@ -2493,20 +2501,20 @@ define([
if (data.tags && Array.isArray(data.tags)) {
$('<label>', {'for': 'cp-app-drive-prop-tags'}).text(Messages.fm_prop_tagsList).appendTo($d);
$d.append(Cryptpad.dialog.selectable(data.tags.join(', '), {
$d.append(UI.dialog.selectable(data.tags.join(', '), {
id: 'cp-app-drive-prop-tags',
}));
}
$('<label>', {'for': 'cp-app-drive-prop-ctime'}).text(Messages.fm_creation)
.appendTo($d);
$d.append(Cryptpad.dialog.selectable(new Date(data.ctime).toLocaleString(), {
$d.append(UI.dialog.selectable(new Date(data.ctime).toLocaleString(), {
id: 'cp-app-drive-prop-ctime',
}));
$('<label>', {'for': 'cp-app-drive-prop-atime'}).text(Messages.fm_lastAccess)
.appendTo($d);
$d.append(Cryptpad.dialog.selectable(new Date(data.atime).toLocaleString(), {
$d.append(UI.dialog.selectable(new Date(data.atime).toLocaleString(), {
id: 'cp-app-drive-prop-atime',
}));
@@ -2522,7 +2530,7 @@ define([
return void cb(void 0, $d);
}
var KB = Cryptpad.bytesToKilobytes(bytes);
var KB = Util.bytesToKilobytes(bytes);
var formatted = Messages._getKey('formattedKB', [KB]);
$('<br>').appendTo($d);
@@ -2531,7 +2539,7 @@ define([
'for': 'cp-app-drive-prop-size'
}).text(Messages.fc_sizeInKilobytes).appendTo($d);
$d.append(Cryptpad.dialog.selectable(formatted, {
$d.append(UI.dialog.selectable(formatted, {
id: 'cp-app-drive-prop-size',
}));
cb(void 0, $d);
@@ -2591,7 +2599,7 @@ define([
el = filesOp.find(paths[0].path);
getProperties(el, function (e, $prop) {
if (e) { return void logError(e); }
Cryptpad.alert($prop[0], undefined, true);
UI.alert($prop[0], undefined, true);
});
}
else if ($(this).hasClass("cp-app-drive-context-hashtag")) {
@@ -2637,7 +2645,7 @@ define([
if (paths.length === 1) {
msg = Messages.fm_removePermanentlyDialog;
}
Cryptpad.confirm(msg, function(res) {
UI.confirm(msg, function(res) {
$(window).focus();
if (!res) { return; }
filesOp.delete(pathsList, refresh);
@@ -2651,7 +2659,7 @@ define([
el = filesOp.find(paths[0].path);
getProperties(el, function (e, $prop) {
if (e) { return void logError(e); }
Cryptpad.alert($prop[0], undefined, true);
UI.alert($prop[0], undefined, true);
});
}
else if ($(this).hasClass("cp-app-drive-context-hashtag")) {
@@ -2670,10 +2678,10 @@ define([
var path = $(this).data('path');
var onCreated = function (err, info) {
if (err === E_OVER_LIMIT) {
return void Cryptpad.alert(Messages.pinLimitDrive, null, true);
return void UI.alert(Messages.pinLimitDrive, null, true);
}
if (err) {
return void Cryptpad.alert(Messages.fm_error_cantPin);
return void UI.alert(Messages.fm_error_cantPin);
}
APP.newFolder = info.newPath;
refresh();
@@ -2683,8 +2691,10 @@ define([
}
else if ($(this).hasClass("cp-app-drive-context-newdoc")) {
var type = $(this).data('type') || 'pad';
sessionStorage[Cryptpad.newPadPathKey] = filesOp.isPathIn(currentPath, [TRASH]) ? '' : currentPath;
window.open(APP.origin + '/' + type + '/');
var path2 = filesOp.isPathIn(currentPath, [TRASH]) ? '' : currentPath;
common.sessionStorage.put(Constants.newPadPathKey, path2, function () {
common.openURL('/' + type + '/');
});
}
APP.hideMenu();
});
@@ -2698,7 +2708,7 @@ define([
return;
}
if ($(this).hasClass("cp-app-drive-context-empty")) {
Cryptpad.confirm(Messages.fm_emptyTrashDialog, function(res) {
UI.confirm(Messages.fm_emptyTrashDialog, function(res) {
if (!res) { return; }
filesOp.emptyTrash(refresh);
});
@@ -2718,7 +2728,7 @@ define([
var name = paths[0].path[paths[0].path.length - 1];
if ($(this).hasClass("cp-app-drive-context-remove")) {
if (paths.length === 1) {
Cryptpad.confirm(Messages.fm_removePermanentlyDialog, function(res) {
UI.confirm(Messages.fm_removePermanentlyDialog, function(res) {
if (!res) { return; }
filesOp.delete([path], refresh);
});
@@ -2727,7 +2737,7 @@ define([
var pathsList = [];
paths.forEach(function (p) { pathsList.push(p.path); });
var msg = Messages._getKey("fm_removeSeveralPermanentlyDialog", [paths.length]);
Cryptpad.confirm(msg, function(res) {
UI.confirm(msg, function(res) {
if (!res) { return; }
filesOp.delete(pathsList, refresh);
});
@@ -2742,7 +2752,7 @@ define([
name = path[1];
}
}
Cryptpad.confirm(Messages._getKey("fm_restoreDialog", [name]), function(res) {
UI.confirm(Messages._getKey("fm_restoreDialog", [name]), function(res) {
if (!res) { return; }
filesOp.restore(path, refresh);
});
@@ -2751,7 +2761,7 @@ define([
if (paths.length !== 1 || path.length !== 4) { return; }
var element = filesOp.find(path.slice(0,3)); // element containing the oldpath
var sPath = stringifyPath(element.path);
Cryptpad.alert('<strong>' + Messages.fm_originalPath + "</strong>:<br>" + sPath, undefined, true);
UI.alert('<strong>' + Messages.fm_originalPath + "</strong>:<br>" + sPath, undefined, true);
}
APP.hideMenu();
});
@@ -2800,7 +2810,7 @@ define([
msg = Messages.fm_removePermanentlyDialog;
}
Cryptpad.confirm(msg, function(res) {
UI.confirm(msg, function(res) {
$(window).focus();
if (!res) { return; }
filesOp.delete(paths, refresh);
@@ -2811,6 +2821,19 @@ define([
moveElements(paths, [TRASH], false, refresh);
}
});
var isCharacterKey = function (e) {
return e.which === "undefined" /* IE */ ||
(e.which > 0 && e.which !== 13 && e.which !== 27 && !e.ctrlKey && !e.altKey);
};
$appContainer.on('keypress', function (e) {
var $searchBar = $tree.find('#cp-app-drive-tree-search-input');
if ($searchBar.is(':focus')) { return; }
if (isCharacterKey(e)) {
$searchBar.focus();
e.preventDefault();
return;
}
});
$appContainer.contextmenu(function () {
APP.hideMenu();
return false;
@@ -2882,7 +2905,7 @@ define([
APP.FM = common.createFileManager(fmConfig);
refresh();
Cryptpad.removeLoadingScreen();
UI.removeLoadingScreen();
};
var setHistory = function (bool, update) {
@@ -2900,7 +2923,7 @@ define([
nThen(function (waitFor) {
$(waitFor(function () {
Cryptpad.addLoadingScreen();
UI.addLoadingScreen();
}));
window.cryptpadStore.getAll(waitFor(function (val) {
APP.store = JSON.parse(JSON.stringify(val));
@@ -2948,7 +2971,6 @@ define([
metadataMgr: metadataMgr,
readOnly: readOnly,
realtime: info.realtime,
common: Cryptpad,
sfCommon: common,
$container: APP.$bar
};
@@ -2979,26 +3001,6 @@ define([
$toolbar: APP.$bar,
};
/* TODO iframe: backup button here?
if (!readOnly && !APP.loggedIn) {
// TODO secure drive
// cryptpad-backup --> cp-toolbar-backup
var $backupButton = Cryptpad.createButton('', true).removeClass('fa').removeClass('fa-question').addClass('cryptpad-backup');
$backupButton.append($backupIcon.clone().css('marginRight', '0px'));
$backupButton.attr('title', Messages.fm_backup_title);
$backupButton.on('click', function() {
var url = window.location.origin + window.location.pathname + '#' + editHash;
var msg = Messages.fm_alert_backupUrl + '<input type="text" readonly="readonly" id="fm_backupUrl" value="'+url+'">';
Cryptpad.alert(msg, undefined, true);
$('#fm_backupUrl').val(url);
$('#fm_backupUrl').click(function () {
$(this).select();
});
});
$userBlock.append($backupButton);
}
*/
metadataMgr.onChange(function () {
var name = metadataMgr.getUserData().name || Messages.anonymous;
APP.$displayName.text(name);
@@ -3012,19 +3014,19 @@ define([
APP.files = proxy;
if (!proxy.drive || typeof(proxy.drive) !== 'object') { proxy.drive = {}; }
andThen(common, proxy);
Cryptpad.removeLoadingScreen();
UI.removeLoadingScreen();
};
var onDisconnect = APP.onDisconnect = function (noAlert) {
setEditable(false);
if (APP.refresh) { APP.refresh(); }
APP.toolbar.failed();
if (!noAlert) { Cryptpad.alert(Messages.common_connectionLost, undefined, true); }
if (!noAlert) { UI.alert(Messages.common_connectionLost, undefined, true); }
};
var onReconnect = function (info) {
setEditable(true);
if (APP.refresh) { APP.refresh(); }
APP.toolbar.reconnecting(info.myId);
Cryptpad.findOKButton().click();
UI.findOKButton().click();
};
proxy.on('create', function (info) {
@@ -3038,13 +3040,7 @@ define([
proxy.on('reconnect', function (info) {
onReconnect(info);
});
Cryptpad.onError(function (info) {
if (info && info.type === "store") {
onConnectError();
}
});
//Cryptpad.onLogout(function () { setEditable(false); });
common.onLogout(function () { setEditable(false); });
});
};
main();