Merge branch 'staging' into slide2

This commit is contained in:
yflory 2017-09-08 18:21:38 +02:00
commit 5bf966633c
6 changed files with 134 additions and 104 deletions

View File

@ -58,35 +58,52 @@ define([
var dialog = UI.dialog = {}; var dialog = UI.dialog = {};
dialog.selectable = function (value) { var merge = function (a, b) {
var input = h('input', { var c = {};
if (a) {
Object.keys(a).forEach(function (k) {
c[k] = a[k];
});
}
if (b) {
Object.keys(b).forEach(function (k) {
c[k] = b[k];
});
}
return c;
};
dialog.selectable = function (value, opt) {
var attrs = merge({
type: 'text', type: 'text',
readonly: 'readonly', readonly: 'readonly',
}); }, opt);
var input = h('input', attrs);
$(input).val(value).click(function () { $(input).val(value).click(function () {
input.select(); input.select();
}); });
return input; return input;
}; };
dialog.okButton = function () { dialog.okButton = function (content) {
return h('button.ok', { tabindex: '2', }, Messages.okButton); return h('button.ok', { tabindex: '2', }, content || Messages.okButton);
}; };
dialog.cancelButton = function () { dialog.cancelButton = function (content) {
return h('button.cancel', { tabindex: '1'}, Messages.cancelButton); return h('button.cancel', { tabindex: '1'}, content || Messages.cancelButton);
}; };
dialog.message = function (text) { dialog.message = function (text) {
return h('p.message', text); return h('p.msg', text);
}; };
dialog.textInput = function (opt) { dialog.textInput = function (opt) {
return h('input', opt || { var attrs = merge({
placeholder: '',
type: 'text', type: 'text',
'class': 'cp-text-input', 'class': 'cp-text-input',
}); }, opt);
return h('input', attrs);
}; };
dialog.nav = function (content) { dialog.nav = function (content) {
@ -191,12 +208,20 @@ define([
UI.alert = function (msg, cb, force) { UI.alert = function (msg, cb, force) {
cb = cb || function () {}; cb = cb || function () {};
if (typeof(msg) === 'string' && force !== true) {
msg = Util.fixHTML(msg); var message;
if (typeof(msg) === 'string') {
// sanitize
if (!force) { msg = Util.fixHTML(msg); }
message = dialog.message();
message.innerHTML = msg;
} else {
message = dialog.message(msg);
} }
var ok = dialog.okButton(); var ok = dialog.okButton();
var frame = dialog.frame([ var frame = dialog.frame([
dialog.message(msg), message,
dialog.nav(ok), dialog.nav(ok),
]); ]);
@ -211,92 +236,102 @@ define([
document.body.appendChild(frame); document.body.appendChild(frame);
setTimeout(function () { setTimeout(function () {
$ok.focus(); $ok.focus();
if (typeof(UI.notify) === 'function') { UI.notify();
UI.notify();
}
}); });
}; };
UI.prompt = function (msg, def, cb, opt, force) { UI.prompt = function (msg, def, cb, opt, force) {
opt = opt || {};
cb = cb || function () {}; cb = cb || function () {};
if (force !== true) { msg = Util.fixHTML(msg); } opt = opt || {};
var keyHandler = listenForKeys(function () { // yes var input = dialog.textInput();
findOKButton().click(); input.value = typeof(def) === 'string'? def: '';
}, function () { // no
findCancelButton().click(); var message;
if (typeof(msg) === 'string') {
if (!force) { msg = Util.fixHTML(msg); }
message = dialog.message();
message.innerHTML = msg;
} else {
message = dialog.message(msg);
}
var ok = dialog.okButton(opt.ok);
var cancel = dialog.cancelButton(opt.cancel);
var frame = dialog.frame([
message,
input,
dialog.nav([ cancel, ok, ]),
]);
var listener;
var close = Util.once(function () {
$(frame).fadeOut(150, function () { $(this).remove(); });
stopListening(listener);
}); });
// Make sure we don't call both the "yes" and "no" handlers if we use "findOKButton().click()" var $ok = $(ok).click(function (ev) { cb(input.value, ev); });
// in the callback var $cancel = $(cancel).click(function (ev) { cb(null, ev); });
var isClicked = false; listener = listenForKeys(function () { // yes
close(); $ok.click();
}, function () { // no
close(); $cancel.click();
});
Alertify document.body.appendChild(frame);
.defaultValue(def || '') setTimeout(function () {
.okBtn(opt.ok || Messages.okButton || 'OK') input.select().focus();
.cancelBtn(opt.cancel || Messages.cancelButton || 'Cancel')
.prompt(msg, function (val, ev) {
if (isClicked) { return; }
isClicked = true;
cb(val, ev);
stopListening(keyHandler);
}, function (ev) {
if (isClicked) { return; }
isClicked = true;
cb(null, ev);
stopListening(keyHandler);
});
if (typeof(UI.notify) === 'function') {
UI.notify(); UI.notify();
} });
}; };
UI.confirm = function (msg, cb, opt, force, styleCB) { UI.confirm = function (msg, cb, opt, force, styleCB) {
opt = opt || {};
cb = cb || function () {}; cb = cb || function () {};
if (force !== true) { msg = Util.fixHTML(msg); } opt = opt || {};
var keyHandler = listenForKeys(function () { var message;
findOKButton().click(); if (typeof(msg) === 'string') {
}, function () { if (!force) { msg = Util.fixHTML(msg); }
findCancelButton().click(); message = dialog.message();
message.innerHTML = msg;
} else {
message = dialog.message(msg);
}
var ok = dialog.okButton(opt.ok);
var cancel = dialog.cancelButton(opt.cancel);
var frame = dialog.frame([
message,
dialog.nav(opt.reverseOrder?
[ok, cancel]: [cancel, ok]),
]);
var listener;
var close = Util.once(function () {
$(frame).fadeOut(150, function () { $(this).remove(); });
stopListening(listener);
}); });
// Make sure we don't call both the "yes" and "no" handlers if we use "findOKButton().click()" var $ok = $(ok).click(function (ev) { close(); cb(true, ev); });
// in the callback var $cancel = $(cancel).click(function (ev) { close(); cb(false, ev); });
var isClicked = false;
Alertify if (opt.cancelClass) { $cancel.addClass(opt.cancelClass); }
.okBtn(opt.ok || Messages.okButton || 'OK') if (opt.okClass) { $ok.addClass(opt.okClass); }
.cancelBtn(opt.cancel || Messages.cancelButton || 'Cancel')
.confirm(msg, function () {
if (isClicked) { return; }
isClicked = true;
cb(true);
stopListening(keyHandler);
}, function () {
if (isClicked) { return; }
isClicked = true;
cb(false);
stopListening(keyHandler);
});
window.setTimeout(function () { listener = listenForKeys(function () {
var $ok = findOKButton(); $ok.click();
var $cancel = findCancelButton(); }, function () {
if (opt.okClass) { $ok.addClass(opt.okClass); } $cancel.click();
if (opt.cancelClass) { $cancel.addClass(opt.cancelClass); } });
if (opt.reverseOrder) {
$ok.insertBefore($ok.prev()); document.body.appendChild(frame);
} setTimeout(function () {
UI.notify();
if (typeof(styleCB) === 'function') { if (typeof(styleCB) === 'function') {
styleCB($ok.closest('.dialog')); styleCB($ok.closest('.dialog'));
} }
}, 0); });
if (typeof(UI.notify) === 'function') {
UI.notify();
}
}; };
UI.log = function (msg) { UI.log = function (msg) {

View File

@ -3,8 +3,7 @@ define([
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/common/curve.js', '/common/curve.js',
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-realtime.js' ], function ($, Crypto, Curve, Hash) {
], function ($, Crypto, Curve, Hash, Realtime) {
'use strict'; 'use strict';
var Msg = { var Msg = {
inputs: [], inputs: [],
@ -242,7 +241,7 @@ define([
if (!proxy.friends) { return; } if (!proxy.friends) { return; }
var friends = proxy.friends; var friends = proxy.friends;
delete friends[curvePublic]; delete friends[curvePublic];
Realtime.whenRealtimeSyncs(common, realtime, cb); common.whenRealtimeSyncs(realtime, cb);
}; };
var pushMsg = function (channel, cryptMsg) { var pushMsg = function (channel, cryptMsg) {
@ -472,7 +471,7 @@ define([
channel.wc.bcast(cryptMsg).then(function () { channel.wc.bcast(cryptMsg).then(function () {
delete friends[curvePublic]; delete friends[curvePublic];
delete channels[curvePublic]; delete channels[curvePublic];
Realtime.whenRealtimeSyncs(common, realtime, function () { common.whenRealtimeSyncs(realtime, function () {
cb(); cb();
}); });
}, function (err) { }, function (err) {

View File

@ -1089,6 +1089,7 @@ define([
*/ */
var LIMIT_REFRESH_RATE = 30000; // milliseconds var LIMIT_REFRESH_RATE = 30000; // milliseconds
common.createUsageBar = function (cb) { common.createUsageBar = function (cb) {
if (!isLoggedIn()) { return cb("NOT_LOGGED_IN"); }
// getPinnedUsage updates common.account.usage, and other values // getPinnedUsage updates common.account.usage, and other values
// so we can just use those and only check for errors // so we can just use those and only check for errors
var $container = $('<span>', {'class':'limit-container'}); var $container = $('<span>', {'class':'limit-container'});

View File

@ -2340,9 +2340,9 @@ define([
$('<br>').appendTo($d); $('<br>').appendTo($d);
if (!ro) { if (!ro) {
$('<label>', {'for': 'propLink'}).text(Messages.editShare).appendTo($d); $('<label>', {'for': 'propLink'}).text(Messages.editShare).appendTo($d);
$('<input>', {'id': 'propLink', 'readonly': 'readonly', 'value': base + data.href}) $d.append(Cryptpad.dialog.selectable(base + data.href, {
.click(function () { $(this).select(); }) id: 'propLink',
.appendTo($d); }));
} }
var parsed = Cryptpad.parsePadUrl(data.href); var parsed = Cryptpad.parsePadUrl(data.href);
@ -2350,9 +2350,9 @@ define([
var roLink = ro ? base + data.href : getReadOnlyUrl(el); var roLink = ro ? base + data.href : getReadOnlyUrl(el);
if (roLink) { if (roLink) {
$('<label>', {'for': 'propROLink'}).text(Messages.viewShare).appendTo($d); $('<label>', {'for': 'propROLink'}).text(Messages.viewShare).appendTo($d);
$('<input>', {'id': 'propROLink', 'readonly': 'readonly', 'value': roLink}) $d.append(Cryptpad.dialog.selectable(roLink, {
.click(function () { $(this).select(); }) id: 'propROLink',
.appendTo($d); }));
} }
} }
@ -2370,20 +2370,17 @@ define([
return void cb(void 0, $d); return void cb(void 0, $d);
} }
var KB = Cryptpad.bytesToKilobytes(bytes); var KB = Cryptpad.bytesToKilobytes(bytes);
var formatted = Messages._getKey('formattedKB', [KB]);
$('<br>').appendTo($d); $('<br>').appendTo($d);
$('<label>', { $('<label>', {
'for': 'size' 'for': 'size'
}).text(Messages.fc_sizeInKilobytes).appendTo($d); }).text(Messages.fc_sizeInKilobytes).appendTo($d);
$('<input>', { $d.append(Cryptpad.dialog.selectable(formatted, {
id: 'size', id: 'size',
readonly: 'readonly', }));
value: KB + 'KB',
})
.click(function () { $(this).select(); })
.appendTo($d);
cb(void 0, $d); cb(void 0, $d);
}); });
} else { } else {
@ -2439,8 +2436,7 @@ define([
var el = filesOp.find(paths[0].path); var el = filesOp.find(paths[0].path);
getProperties(el, function (e, $prop) { getProperties(el, function (e, $prop) {
if (e) { return void logError(e); } if (e) { return void logError(e); }
Cryptpad.alert('', undefined, true); Cryptpad.alert($prop[0], undefined, true);
$('.alertify .msg').html("").append($prop);
}); });
} }
module.hideMenu(); module.hideMenu();
@ -2491,8 +2487,7 @@ define([
var el = filesOp.find(paths[0].path); var el = filesOp.find(paths[0].path);
getProperties(el, function (e, $prop) { getProperties(el, function (e, $prop) {
if (e) { return void logError(e); } if (e) { return void logError(e); }
Cryptpad.alert('', undefined, true); Cryptpad.alert($prop[0], undefined, true);
$('.alertify .msg').html("").append($prop);
}); });
} }
module.hideMenu(); module.hideMenu();

View File

@ -90,7 +90,7 @@ define([
// Description // Description
var text = Messages.filePicker_description; var text = Messages.filePicker_description;
if (types.length === 1 && types[0] !== 'file') { if (types && types.length === 1 && types[0] !== 'file') {
// Should be Templates // Should be Templates
text = Messages.selectTemplate; text = Messages.selectTemplate;
} }
@ -117,7 +117,8 @@ define([
// Update the files list when needed // Update the files list when needed
updateContainer = function () { updateContainer = function () {
$container.html(''); $container.html('');
var filter = $filter.find('.cp-filepicker-filter').val().trim(); var $input = $filter.find('.cp-filepicker-filter');
var filter = $input.val().trim();
var todo = function (err, list) { var todo = function (err, list) {
if (err) { return void console.error(err); } if (err) { return void console.error(err); }
Object.keys(list).forEach(function (id) { Object.keys(list).forEach(function (id) {
@ -136,6 +137,7 @@ define([
if (typeof onSelect === "function") { onSelect(data.href); } if (typeof onSelect === "function") { onSelect(data.href); }
}); });
}); });
$input.focus();
}; };
common.getFilesList(filters, todo); common.getFilesList(filters, todo);
}; };

View File

@ -75,9 +75,7 @@ define([
var userHref = Cryptpad.getUserHrefFromKeys(accountName, publicKey); var userHref = Cryptpad.getUserHrefFromKeys(accountName, publicKey);
var $pubLabel = $('<span>', {'class': 'label'}) var $pubLabel = $('<span>', {'class': 'label'})
.text(Messages.settings_publicSigningKey); .text(Messages.settings_publicSigningKey);
var $pubKey = $('<input>', {type: 'text', readonly: true}) $key.append($pubLabel).append(Cryptpad.dialog.selectable(userHref));
.val(userHref);
$key.append($pubLabel).append($pubKey);
} }
return $div; return $div;