improve owned pads management in the drive

pull/1/head
yflory 7 years ago
parent cd7c5abc3e
commit 8c9490868b

@ -419,6 +419,7 @@ define(function () {
out.fc_open = "Ouvrir"; out.fc_open = "Ouvrir";
out.fc_open_ro = "Ouvrir (lecture seule)"; out.fc_open_ro = "Ouvrir (lecture seule)";
out.fc_delete = "Déplacer vers la corbeille"; out.fc_delete = "Déplacer vers la corbeille";
out.fc_delete_owned = "Supprimer du serveur";
out.fc_restore = "Restaurer"; out.fc_restore = "Restaurer";
out.fc_remove = "Supprimer de votre CryptDrive"; out.fc_remove = "Supprimer de votre CryptDrive";
out.fc_empty = "Vider la corbeille"; out.fc_empty = "Vider la corbeille";

@ -422,6 +422,7 @@ define(function () {
out.fc_open = "Open"; out.fc_open = "Open";
out.fc_open_ro = "Open (read-only)"; out.fc_open_ro = "Open (read-only)";
out.fc_delete = "Move to trash"; out.fc_delete = "Move to trash";
out.fc_delete_owned = "Delete from the server";
out.fc_restore = "Restore"; out.fc_restore = "Restore";
out.fc_remove = "Remove from your CryptDrive"; out.fc_remove = "Remove from your CryptDrive";
out.fc_empty = "Empty the trash"; out.fc_empty = "Empty the trash";

@ -107,9 +107,11 @@ define([
.appendTo($d); .appendTo($d);
var owners = Messages.creation_noOwner; var owners = Messages.creation_noOwner;
var edPublic = common.getMetadataMgr().getPrivateData().edPublic; var edPublic = common.getMetadataMgr().getPrivateData().edPublic;
var owned = false;
if (data.owners && data.owners.length) { if (data.owners && data.owners.length) {
if (data.owners.indexOf(edPublic) !== -1) { if (data.owners.indexOf(edPublic) !== -1) {
owners = Messages.yourself; owners = Messages.yourself;
owned = true;
} else { } else {
owners = Messages.creation_ownedByOther; owners = Messages.creation_ownedByOther;
} }
@ -117,6 +119,12 @@ define([
$d.append(UI.dialog.selectable(owners, { $d.append(UI.dialog.selectable(owners, {
id: 'cp-app-prop-owners', id: 'cp-app-prop-owners',
})); }));
/* TODO
if (owned) {
var $deleteOwned = $('button').text(Messages.fc_delete_owned).click(function () {
});
$d.append($deleteOwned);
}*/
var expire = Messages.creation_expireFalse; var expire = Messages.creation_expireFalse;
if (data.expire && typeof (data.expire) === "number") { if (data.expire && typeof (data.expire) === "number") {

@ -494,6 +494,10 @@ define([
Cryptpad.setLanguage(data, cb); Cryptpad.setLanguage(data, cb);
}); });
sframeChan.on('Q_CONTACTS_CLEAR_OWNED_CHANNEL', function (channel, cb) {
Cryptpad.clearOwnedChannel(channel, cb);
});
if (cfg.addRpc) { if (cfg.addRpc) {
cfg.addRpc(sframeChan, Cryptpad, Utils); cfg.addRpc(sframeChan, Cryptpad, Utils);
} }
@ -530,9 +534,6 @@ define([
sframeChan.on('Q_CONTACTS_SET_CHANNEL_HEAD', function (opt, cb) { sframeChan.on('Q_CONTACTS_SET_CHANNEL_HEAD', function (opt, cb) {
Cryptpad.messenger.setChannelHead(opt, cb); Cryptpad.messenger.setChannelHead(opt, cb);
}); });
sframeChan.on('Q_CONTACTS_CLEAR_OWNED_CHANNEL', function (channel, cb) {
Cryptpad.clearOwnedChannel(channel, cb);
});
Cryptpad.messenger.onMessageEvent.reg(function (data) { Cryptpad.messenger.onMessageEvent.reg(function (data) {
sframeChan.event('EV_CONTACTS_MESSAGE', data); sframeChan.event('EV_CONTACTS_MESSAGE', data);

@ -24,6 +24,7 @@
<li><a tabindex="-1" data-icon="fa-eye" class="cp-app-drive-context-openro dropdown-item" data-localization="fc_open_ro">Open (read-only)</a></li> <li><a tabindex="-1" data-icon="fa-eye" class="cp-app-drive-context-openro dropdown-item" data-localization="fc_open_ro">Open (read-only)</a></li>
<li><a tabindex="-1" data-icon="fa-pencil" class="cp-app-drive-context-rename cp-app-drive-context-editable dropdown-item" data-localization="fc_rename">Rename</a></li> <li><a tabindex="-1" data-icon="fa-pencil" class="cp-app-drive-context-rename cp-app-drive-context-editable dropdown-item" data-localization="fc_rename">Rename</a></li>
<li><a tabindex="-1" data-icon="fa-trash" class="cp-app-drive-context-delete cp-app-drive-context-editable dropdown-item" data-localization="fc_delete">Delete</a></li> <li><a tabindex="-1" data-icon="fa-trash" class="cp-app-drive-context-delete cp-app-drive-context-editable dropdown-item" data-localization="fc_delete">Delete</a></li>
<li><a tabindex="-1" data-icon="fa-eraser" class="cp-app-drive-context-deleteowned dropdown-item" data-localization="fc_delete_owned">Delete permanently</a></li>
<li><a tabindex="-1" data-icon="fa-folder" class="cp-app-drive-context-newfolder cp-app-drive-context-editable dropdown-item" data-localization="fc_newfolder">New folder</a></li> <li><a tabindex="-1" data-icon="fa-folder" class="cp-app-drive-context-newfolder cp-app-drive-context-editable dropdown-item" data-localization="fc_newfolder">New folder</a></li>
<li><a tabindex="-1" data-icon="fa-database" class="cp-app-drive-context-properties dropdown-item" data-localization="fc_prop">Properties</a></li> <li><a tabindex="-1" data-icon="fa-database" class="cp-app-drive-context-properties dropdown-item" data-localization="fc_prop">Properties</a></li>
<li><a tabindex="-1" data-icon="fa-hashtag" class="cp-app-drive-context-hashtag dropdown-item" data-localization="fc_hashtag">Tags</a></li> <li><a tabindex="-1" data-icon="fa-hashtag" class="cp-app-drive-context-hashtag dropdown-item" data-localization="fc_hashtag">Tags</a></li>
@ -44,7 +45,7 @@
<li><a tabindex="-1" data-icon="fa-folder-open" class="cp-app-drive-context-open dropdown-item" data-localization="fc_open">Open</a></li> <li><a tabindex="-1" data-icon="fa-folder-open" class="cp-app-drive-context-open dropdown-item" data-localization="fc_open">Open</a></li>
<li><a tabindex="-1" data-icon="fa-eye" class="cp-app-drive-context-openro dropdown-item" data-localization="fc_open_ro">Open (read-only)</a></li> <li><a tabindex="-1" data-icon="fa-eye" class="cp-app-drive-context-openro dropdown-item" data-localization="fc_open_ro">Open (read-only)</a></li>
<li><a tabindex="-1" data-icon="fa-trash" class="cp-app-drive-context-delete dropdown-item" data-localization="fc_delete">Delete</a></li> <li><a tabindex="-1" data-icon="fa-trash" class="cp-app-drive-context-delete dropdown-item" data-localization="fc_delete">Delete</a></li>
<li><a tabindex="-1" data-icon="fa-eraser" class="cp-app-drive-context-deleteowned dropdown-item" data-localization="fc_remove">Delete permanently</a></li> <li><a tabindex="-1" data-icon="fa-eraser" class="cp-app-drive-context-deleteowned dropdown-item" data-localization="fc_delete_owned">Delete permanently</a></li>
<li><a tabindex="-1" data-icon="fa-database" class="cp-app-drive-context-properties dropdown-item" data-localization="fc_prop">Properties</a></li> <li><a tabindex="-1" data-icon="fa-database" class="cp-app-drive-context-properties dropdown-item" data-localization="fc_prop">Properties</a></li>
<li><a tabindex="-1" data-icon="fa-hashtag" class="cp-app-drive-context-hashtag dropdown-item" data-localization="fc_hashtag">Tags</a></li> <li><a tabindex="-1" data-icon="fa-hashtag" class="cp-app-drive-context-hashtag dropdown-item" data-localization="fc_hashtag">Tags</a></li>
</ul> </ul>

@ -658,11 +658,12 @@ define([
if (!isOwnDrive()) { if (!isOwnDrive()) {
hide.push($menu.find('a.cp-app-drive-context-own')); hide.push($menu.find('a.cp-app-drive-context-own'));
} }
if ($element.is('.cp-app-drive-element-owned')) { if (!$element.is('.cp-app-drive-element-owned')) {
hide.push($menu.find('a.cp-app-drive-context-delete'));
} else {
hide.push($menu.find('a.cp-app-drive-context-deleteowned')); hide.push($menu.find('a.cp-app-drive-context-deleteowned'));
} }
if ($element.is('.cp-app-drive-element-notrash')) {
hide.push($menu.find('a.cp-app-drive-context-delete'));
}
if ($element.is('.cp-app-drive-element-file')) { if ($element.is('.cp-app-drive-element-file')) {
// No folder in files // No folder in files
hide.push($menu.find('a.cp-app-drive-context-newfolder')); hide.push($menu.find('a.cp-app-drive-context-newfolder'));
@ -1183,6 +1184,7 @@ define([
if (data.owners && data.owners.indexOf(edPublic) !== -1) { if (data.owners && data.owners.indexOf(edPublic) !== -1) {
var $owned = $ownedIcon.clone().appendTo($state); var $owned = $ownedIcon.clone().appendTo($state);
$owned.attr('title', Messages.fm_padIsOwned); $owned.attr('title', Messages.fm_padIsOwned);
$span.addClass('cp-app-drive-element-owned');
} else if (data.owners && data.owners.length) { } else if (data.owners && data.owners.length) {
var $owner = $ownerIcon.clone().appendTo($state); var $owner = $ownerIcon.clone().appendTo($state);
$owner.attr('title', Messages.fm_padIsOwnedOther); $owner.attr('title', Messages.fm_padIsOwnedOther);
@ -2065,7 +2067,7 @@ define([
var roClass = typeof(ro) === 'undefined' ? ' cp-app-drive-element-noreadonly' : var roClass = typeof(ro) === 'undefined' ? ' cp-app-drive-element-noreadonly' :
ro ? ' cp-app-drive-element-readonly' : ''; ro ? ' cp-app-drive-element-readonly' : '';
var $element = $('<li>', { var $element = $('<li>', {
'class': 'cp-app-drive-element cp-app-drive-element-file cp-app-drive-element-row' + roClass, 'class': 'cp-app-drive-element cp-app-drive-element-notrash cp-app-drive-element-file cp-app-drive-element-row' + roClass,
}); });
$element.prepend($icon).dblclick(function () { $element.prepend($icon).dblclick(function () {
openFile(id); openFile(id);
@ -2103,7 +2105,8 @@ define([
var roClass = typeof(ro) === 'undefined' ? ' cp-app-drive-element-noreadonly' : var roClass = typeof(ro) === 'undefined' ? ' cp-app-drive-element-noreadonly' :
ro ? ' cp-app-drive-element-readonly' : ''; ro ? ' cp-app-drive-element-readonly' : '';
var $element = $('<li>', { var $element = $('<li>', {
'class': 'cp-app-drive-element cp-app-drive-element-owned cp-app-drive-element-file cp-app-drive-element-row' + roClass 'class': 'cp-app-drive-element cp-app-drive-element-notrash ' +
'cp-app-drive-element-file cp-app-drive-element-row' + roClass
}); });
$element.prepend($icon).dblclick(function () { $element.prepend($icon).dblclick(function () {
openFile(id); openFile(id);
@ -2600,6 +2603,30 @@ define([
paths.forEach(function (p) { pathsList.push(p.path); }); paths.forEach(function (p) { pathsList.push(p.path); });
moveElements(pathsList, [TRASH], false, refresh); moveElements(pathsList, [TRASH], false, refresh);
} }
else if ($(this).hasClass('cp-app-drive-context-deleteowned')) {
var pathsListD = [];
var msgD = Messages.fm_deleteOwnedPads;
UI.confirm(msgD, function(res) {
$(window).focus();
if (!res) { return; }
// Try to delete each selected pad from server, and delete from drive if no error
var n = nThen(function () {});
paths.forEach(function (p) {
var el = filesOp.find(p.path);
var data = filesOp.getFileData(el);
var parsed = Hash.parsePadUrl(data.href);
var channel = Util.base64ToHex(parsed.hashData.channel);
n = n.nThen(function (waitFor) {
sframeChan.query('Q_CONTACTS_CLEAR_OWNED_CHANNEL', channel,
waitFor(function (e) {
if (e) { return void console.error(e); }
filesOp.delete([p.path], refresh);
}));
});
});
});
return;
}
else if ($(this).hasClass('cp-app-drive-context-open')) { else if ($(this).hasClass('cp-app-drive-context-open')) {
paths.forEach(function (p) { paths.forEach(function (p) {
var $element = p.element; var $element = p.element;
@ -2689,17 +2716,26 @@ define([
moveElements(pathsList, [TRASH], false, refresh); moveElements(pathsList, [TRASH], false, refresh);
} }
else if ($(this).hasClass('cp-app-drive-context-deleteowned')) { else if ($(this).hasClass('cp-app-drive-context-deleteowned')) {
// TODO
// Remove owned pad from drive and remove from server
var pathsListD = []; var pathsListD = [];
paths.forEach(function (p) { pathsListD.push(p.path); });
var msgD = Messages.fm_deleteOwnedPads; var msgD = Messages.fm_deleteOwnedPads;
UI.confirm(msgD, function(res) { UI.confirm(msgD, function(res) {
$(window).focus(); $(window).focus();
if (!res) { return; } if (!res) { return; }
filesOp.delete(pathsListD, refresh); // Try to delete each selected pad from server, and delete from drive if no error
// TODO XXX HERE var n = nThen(function () {});
// RPC to delete from server paths.forEach(function (p) {
var el = filesOp.find(p.path);
var data = filesOp.getFileData(el);
var parsed = Hash.parsePadUrl(data.href);
var channel = Util.base64ToHex(parsed.hashData.channel);
n = n.nThen(function (waitFor) {
sframeChan.query('Q_CONTACTS_CLEAR_OWNED_CHANNEL', channel,
waitFor(function (e) {
if (e) { return void console.error(e); }
filesOp.delete([p.path], refresh);
}));
});
});
}); });
return; return;
} }

Loading…
Cancel
Save