mirror of https://github.com/xwiki-labs/cryptpad
Forget button in pad2
This commit is contained in:
parent
e4020ba8d4
commit
e2d39de143
|
@ -1039,6 +1039,28 @@ define([
|
|||
};
|
||||
};
|
||||
|
||||
// Forget button
|
||||
var moveToTrash = common.moveToTrash = function (cb) {
|
||||
var href = window.location.href;
|
||||
common.forgetPad(href, function (err) {
|
||||
if (err) {
|
||||
console.log("unable to forget pad");
|
||||
console.error(err);
|
||||
cb(err, null);
|
||||
return;
|
||||
}
|
||||
var n = getNetwork();
|
||||
var r = getRealtime();
|
||||
if (n && r) {
|
||||
whenRealtimeSyncs(r, function () {
|
||||
n.disconnect();
|
||||
cb();
|
||||
});
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
};
|
||||
common.createButton = function (type, rightside, data, callback) {
|
||||
var button;
|
||||
var size = "17px";
|
||||
|
@ -1164,25 +1186,11 @@ define([
|
|||
var msg = isLoggedIn() ? Messages.forgetPrompt : Messages.fm_removePermanentlyDialog;
|
||||
common.confirm(msg, function (yes) {
|
||||
if (!yes) { return; }
|
||||
common.forgetPad(href, function (err) {
|
||||
if (err) {
|
||||
console.log("unable to forget pad");
|
||||
console.error(err);
|
||||
callback(err, null);
|
||||
return;
|
||||
}
|
||||
var n = getNetwork();
|
||||
var r = getRealtime();
|
||||
if (n && r) {
|
||||
whenRealtimeSyncs(r, function () {
|
||||
n.disconnect();
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
moveToTrash(function (err) {
|
||||
if (err) { return void callback(err); }
|
||||
var cMsg = isLoggedIn() ? Messages.movedToTrash : Messages.deleted;
|
||||
common.alert(cMsg, undefined, true);
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
define([
|
||||
'/bower_components/nthen/index.js',
|
||||
'/customize/messages.js',
|
||||
'/common/sframe-chainpad-netflux-inner.js',
|
||||
'/common/sframe-channel.js',
|
||||
'/common/sframe-common-title.js',
|
||||
'/common/sframe-common-interface.js',
|
||||
'/common/metadata-manager.js',
|
||||
|
||||
], function (nThen, CpNfInner, SFrameChannel, Title, UI, MetadataMgr) {
|
||||
'/common/cryptpad-common.js'
|
||||
], function (nThen, Messages, CpNfInner, SFrameChannel, Title, UI, MetadataMgr, Cryptpad) {
|
||||
|
||||
// Chainpad Netflux Inner
|
||||
var funcs = {};
|
||||
|
@ -21,7 +23,7 @@ define([
|
|||
return ctx.cpNfInner;
|
||||
};
|
||||
|
||||
funcs.isLoggedIn = function () {
|
||||
var isLoggedIn = funcs.isLoggedIn = function () {
|
||||
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); }
|
||||
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
|
||||
};
|
||||
|
@ -77,16 +79,169 @@ define([
|
|||
});
|
||||
};
|
||||
|
||||
// TODO
|
||||
|
||||
funcs.feedback = function () {};
|
||||
var prepareFeedback = function () {};
|
||||
|
||||
// BUTTONS
|
||||
var isStrongestStored = function () {
|
||||
var data = ctx.metadataMgr.getPrivateData();
|
||||
return !data.readOnly || !data.availableHashes.editHash;
|
||||
};
|
||||
funcs.createButton = function (type, rightside, data, callback) {
|
||||
var button;
|
||||
var size = "17px";
|
||||
switch (type) {
|
||||
case 'export':
|
||||
button = $('<button>', {
|
||||
'class': 'fa fa-download',
|
||||
title: Messages.exportButtonTitle,
|
||||
}).append($('<span>', {'class': 'drawer'}).text(Messages.exportButton));
|
||||
|
||||
button.click(prepareFeedback(type));
|
||||
if (callback) {
|
||||
button.click(callback);
|
||||
}
|
||||
break;
|
||||
case 'import':
|
||||
button = $('<button>', {
|
||||
'class': 'fa fa-upload',
|
||||
title: Messages.importButtonTitle,
|
||||
}).append($('<span>', {'class': 'drawer'}).text(Messages.importButton));
|
||||
if (callback) {
|
||||
button
|
||||
.click(prepareFeedback(type))
|
||||
.click(UI.importContent('text/plain', function (content, file) {
|
||||
callback(content, file);
|
||||
}, {accept: data ? data.accept : undefined}));
|
||||
}
|
||||
break;
|
||||
case 'template':
|
||||
if (!AppConfig.enableTemplates) { return; }
|
||||
button = $('<button>', {
|
||||
title: Messages.saveTemplateButton,
|
||||
}).append($('<span>', {'class':'fa fa-bookmark', style: 'font:'+size+' FontAwesome'}));
|
||||
if (data.rt && data.Crypt) {
|
||||
button
|
||||
.click(function () {
|
||||
var title = data.getTitle() || document.title;
|
||||
var todo = function (val) {
|
||||
if (typeof(val) !== "string") { return; }
|
||||
var toSave = data.rt.getUserDoc();
|
||||
if (val.trim()) {
|
||||
val = val.trim();
|
||||
title = val;
|
||||
try {
|
||||
var parsed = JSON.parse(toSave);
|
||||
var meta;
|
||||
if (Array.isArray(parsed) && typeof(parsed[3]) === "object") {
|
||||
meta = parsed[3].metadata; // pad
|
||||
} else if (parsed.info) {
|
||||
meta = parsed.info; // poll
|
||||
} else {
|
||||
meta = parsed.metadata;
|
||||
}
|
||||
if (typeof(meta) === "object") {
|
||||
meta.title = val;
|
||||
meta.defaultTitle = val;
|
||||
delete meta.users;
|
||||
}
|
||||
toSave = JSON.stringify(parsed);
|
||||
} catch(e) {
|
||||
console.error("Parse error while setting the title", e);
|
||||
}
|
||||
}
|
||||
var p = parsePadUrl(window.location.href);
|
||||
if (!p.type) { return; }
|
||||
var hash = createRandomHash();
|
||||
var href = '/' + p.type + '/#' + hash;
|
||||
data.Crypt.put(hash, toSave, function (e) {
|
||||
if (e) { throw new Error(e); }
|
||||
common.addTemplate(makePad(href, title));
|
||||
whenRealtimeSyncs(getStore().getProxy().info.realtime, function () {
|
||||
common.alert(Messages.templateSaved);
|
||||
common.feedback('TEMPLATE_CREATED');
|
||||
});
|
||||
});
|
||||
};
|
||||
common.prompt(Messages.saveTemplatePrompt, title || document.title, todo);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'forget':
|
||||
button = $('<button>', {
|
||||
id: 'cryptpad-forget',
|
||||
title: Messages.forgetButtonTitle,
|
||||
'class': "fa fa-trash cryptpad-forget",
|
||||
style: 'font:'+size+' FontAwesome'
|
||||
});
|
||||
if (!isStrongestStored()) {
|
||||
button.addClass('hidden');
|
||||
}
|
||||
if (callback) {
|
||||
button
|
||||
.click(prepareFeedback(type))
|
||||
.click(function() {
|
||||
var msg = isLoggedIn() ? Messages.forgetPrompt : Messages.fm_removePermanentlyDialog;
|
||||
Cryptpad.confirm(msg, function (yes) {
|
||||
if (!yes) { return; }
|
||||
ctx.sframeChan.query('Q_MOVE_TO_TRASH', null, function (err) {
|
||||
if (err) { return void callback(err); }
|
||||
var cMsg = isLoggedIn() ? Messages.movedToTrash : Messages.deleted;
|
||||
Cryptpad.alert(cMsg, undefined, true);
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'history':
|
||||
if (!AppConfig.enableHistory) {
|
||||
button = $('<span>');
|
||||
break;
|
||||
}
|
||||
button = $('<button>', {
|
||||
title: Messages.historyButton,
|
||||
'class': "fa fa-history history",
|
||||
}).append($('<span>', {'class': 'drawer'}).text(Messages.historyText));
|
||||
if (data.histConfig) {
|
||||
button
|
||||
.click(prepareFeedback(type))
|
||||
.on('click', function () {
|
||||
common.getHistory(data.histConfig);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'more':
|
||||
button = $('<button>', {
|
||||
title: Messages.moreActions || 'TODO',
|
||||
'class': "drawer-button fa fa-ellipsis-h",
|
||||
style: 'font:'+size+' FontAwesome'
|
||||
});
|
||||
break;
|
||||
default:
|
||||
button = $('<button>', {
|
||||
'class': "fa fa-question",
|
||||
style: 'font:'+size+' FontAwesome'
|
||||
})
|
||||
.click(prepareFeedback(type));
|
||||
}
|
||||
if (rightside) {
|
||||
button.addClass('rightside-button');
|
||||
}
|
||||
return button;
|
||||
|
||||
};
|
||||
/* funcs.storeLinkToClipboard = function (readOnly, cb) {
|
||||
ctx.sframeChan.query('Q_STORE_LINK_TO_CLIPBOARD', readOnly, function (err) {
|
||||
if (cb) { cb(err); }
|
||||
});
|
||||
};
|
||||
*/
|
||||
// TODO
|
||||
|
||||
funcs.feedback = function () {};
|
||||
|
||||
|
||||
Object.freeze(funcs);
|
||||
return { create: function (cb) {
|
||||
nThen(function (waitFor) {
|
||||
|
|
|
@ -62,4 +62,6 @@ define({
|
|||
// display a warning
|
||||
'Q_GET_PIN_LIMIT_STATUS': true,
|
||||
|
||||
// Move a pad to the trash using the forget button
|
||||
'Q_MOVE_TO_TRASH': true,
|
||||
});
|
||||
|
|
|
@ -75,8 +75,6 @@ define([
|
|||
.append($('<div>', {'class': RIGHTSIDE_CLS}))
|
||||
.append($('<div>', {'class': HISTORY_CLS}));
|
||||
|
||||
// TODO
|
||||
/*
|
||||
var $rightside = $toolbar.find('.'+RIGHTSIDE_CLS);
|
||||
if (!config.hideDrawer) {
|
||||
var $drawerContent = $('<div>', {
|
||||
|
@ -104,7 +102,7 @@ define([
|
|||
$drawerContent.hide();
|
||||
};
|
||||
$drawerContent.blur(onBlur);
|
||||
}*/
|
||||
}
|
||||
|
||||
// The 'notitle' class removes the line added for the title with a small screen
|
||||
if (!config.title || typeof config.title !== "object") {
|
||||
|
|
|
@ -1157,6 +1157,7 @@ define([
|
|||
if (!href) { return $icon; }
|
||||
|
||||
if (href.indexOf('/pad/') !== -1) { $icon = Cryptpad.getIcon('pad'); }
|
||||
else if (href.indexOf('/pad2/') !== -1) { $icon = Cryptpad.getIcon('pad'); } // SFRAME
|
||||
else if (href.indexOf('/code/') !== -1) { $icon = Cryptpad.getIcon('code'); }
|
||||
else if (href.indexOf('/slide/') !== -1) { $icon = Cryptpad.getIcon('slide'); }
|
||||
else if (href.indexOf('/poll/') !== -1) { $icon = Cryptpad.getIcon('poll'); }
|
||||
|
|
|
@ -486,6 +486,7 @@ define([
|
|||
Title.setToolbar(toolbar);
|
||||
|
||||
var $rightside = toolbar.$rightside;
|
||||
var $drawer = toolbar.$drawer;
|
||||
|
||||
var src = 'less!/customize/src/less/toolbar.less';
|
||||
require([
|
||||
|
@ -524,6 +525,13 @@ define([
|
|||
$rightside.append($collapse);
|
||||
}
|
||||
|
||||
/* add a forget button */
|
||||
var forgetCb = function (err) {
|
||||
if (err) { return; }
|
||||
setEditable(false);
|
||||
};
|
||||
var $forgetPad = common.createButton('forget', true, {}, forgetCb);
|
||||
$rightside.append($forgetPad);
|
||||
// TODO
|
||||
|
||||
return;
|
||||
|
@ -572,7 +580,6 @@ define([
|
|||
//Title.setToolbar(toolbar);
|
||||
|
||||
//var $rightside = toolbar.$rightside;
|
||||
var $drawer = toolbar.$drawer;
|
||||
|
||||
var editHash;
|
||||
|
||||
|
@ -642,15 +649,15 @@ define([
|
|||
}
|
||||
|
||||
/* add a forget button */
|
||||
var forgetCb = function (err) {
|
||||
/* var forgetCb = function (err) {
|
||||
if (err) { return; }
|
||||
setEditable(false);
|
||||
};
|
||||
var $forgetPad = Cryptpad.createButton('forget', true, {}, forgetCb);
|
||||
$rightside.append($forgetPad);
|
||||
|
||||
*/
|
||||
// set the hash
|
||||
if (!readOnly) { Cryptpad.replaceHash(editHash); }
|
||||
//if (!readOnly) { Cryptpad.replaceHash(editHash); }
|
||||
};
|
||||
|
||||
// this should only ever get called once, when the chain syncs
|
||||
|
|
|
@ -132,6 +132,10 @@ define([
|
|||
});
|
||||
});
|
||||
|
||||
sframeChan.on('Q_MOVE_TO_TRASH', function (data, cb) {
|
||||
Cryptpad.moveToTrash(cb);
|
||||
});
|
||||
|
||||
CpNfOuter.start({
|
||||
sframeChan: sframeChan,
|
||||
channel: secret.channel,
|
||||
|
|
Loading…
Reference in New Issue