Refresh properties modal when receiving metadata updates

pull/1/head
yflory 5 years ago
parent d52e449f87
commit 32f1d1627f

@ -271,14 +271,12 @@ define([
} }
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
console.log('koko');
// Send the command // Send the command
sframeChan.query('Q_SET_PAD_METADATA', { sframeChan.query('Q_SET_PAD_METADATA', {
channel: channel, channel: channel,
command: 'ADD_PENDING_OWNERS', command: 'ADD_PENDING_OWNERS',
value: toAdd value: toAdd
}, waitFor(function (err, res) { }, waitFor(function (err, res) {
console.error(arguments);
err = err || (res && res.error); err = err || (res && res.error);
if (err) { if (err) {
waitFor.abort(); waitFor.abort();
@ -286,8 +284,6 @@ define([
} // XXX } // XXX
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
console.log('okok');
// TODO send notifications
sel.forEach(function (el) { sel.forEach(function (el) {
var friend = friends[$(el).attr('data-curve')]; var friend = friends[$(el).attr('data-curve')];
if (!friend) { return; } if (!friend) { return; }
@ -318,13 +314,17 @@ define([
return $div2; return $div2;
}; };
var pending = false;
redrawAll = function () { redrawAll = function () {
$div1.empty(); if (pending) { return; }
$div2.empty(); pending = true;
common.getPadMetadata(null, function (obj) { common.getPadMetadata(null, function (obj) {
pending = false;
if (obj && obj.error) { return; } if (obj && obj.error) { return; }
owners = obj.owners; owners = obj.owners;
pending_owners = obj.pending_owners; pending_owners = obj.pending_owners;
$div1.empty();
$div2.empty();
$div1.append(drawRemove(false)).append(drawRemove(true)); $div1.append(drawRemove(false)).append(drawRemove(true));
$div2.append(drawAdd()); $div2.append(drawAdd());
}); });
@ -333,6 +333,15 @@ define([
$div1.append(drawRemove(false)).append(drawRemove(true)); $div1.append(drawRemove(false)).append(drawRemove(true));
$div2.append(drawAdd()); $div2.append(drawAdd());
var handler = sframeChan.on('EV_RT_METADATA', function (md) {
if (!$div1.length) {
return void handler.stop();
}
owners = md.owners;
pending_owners = md.pending_owners;
redrawAll();
});
// Create modal // Create modal
var link = h('div.cp-share-columns', [ var link = h('div.cp-share-columns', [
div1, div1,
@ -349,139 +358,158 @@ define([
return UI.dialog.customModal(link, {buttons: linkButtons}); return UI.dialog.customModal(link, {buttons: linkButtons});
}; };
var getRightsProperties = function (common, data, cb) { var getRightsProperties = function (common, data, cb) {
var $d = $('<div>'); var $div = $('<div>');
if (!data) { return void cb(void 0, $d); } if (!data) { return void cb(void 0, $div); }
$('<label>', {'for': 'cp-app-prop-owners'}).text(Messages.creation_owners) var draw = function () {
.appendTo($d); var $d = $('<div>');
var owners = Messages.creation_noOwner; $('<label>', {'for': 'cp-app-prop-owners'}).text(Messages.creation_owners)
var priv = common.getMetadataMgr().getPrivateData(); .appendTo($d);
var edPublic = priv.edPublic; var owners = Messages.creation_noOwner;
var owned = false; var priv = common.getMetadataMgr().getPrivateData();
if (data.owners && data.owners.length) { var edPublic = priv.edPublic;
if (data.owners.indexOf(edPublic) !== -1) { var owned = false;
owned = true; if (data.owners && data.owners.length) {
} if (data.owners.indexOf(edPublic) !== -1) {
var names = []; owned = true;
var strangers = 0;
data.owners.forEach(function (ed) {
// If a friend is an owner, add their name to the list
// otherwise, increment the list of strangers
if (ed === edPublic) {
names.push(Messages.yourself);
return;
} }
if (!Object.keys(priv.friends || {}).some(function (c) { var names = [];
var friend = priv.friends[c] || {}; var strangers = 0;
if (friend.edPublic !== ed || c === 'me') { return; } data.owners.forEach(function (ed) {
names.push(friend.displayName); // If a friend is an owner, add their name to the list
return true; // otherwise, increment the list of strangers
})) { if (ed === edPublic) {
strangers++; names.push(Messages.yourself);
return;
}
if (!Object.keys(priv.friends || {}).some(function (c) {
var friend = priv.friends[c] || {};
if (friend.edPublic !== ed || c === 'me') { return; }
names.push(friend.displayName);
return true;
})) {
strangers++;
}
});
if (strangers) {
names.push(Messages._getKey('properties_unknownUser', [strangers]));
} }
}); owners = names.join(', ');
if (strangers) {
names.push(Messages._getKey('properties_unknownUser', [strangers]));
} }
owners = names.join(', '); $d.append(UI.dialog.selectable(owners, {
} id: 'cp-app-prop-owners',
$d.append(UI.dialog.selectable(owners, { }));
id: 'cp-app-prop-owners', if (owned) {
})); var manageOwners = h('button.no-margin', 'Manage owners'); // XXX
if (owned) { $(manageOwners).click(function () {
var manageOwners = h('button.no-margin', 'Manage owners'); // XXX var modal = createOwnerModal(common, data);
$(manageOwners).click(function () { UI.openCustomModal(modal, {
var modal = createOwnerModal(common, data); wide: true,
UI.openCustomModal(modal, { });
wide: true,
}); });
}); $d.append(h('p', manageOwners));
$d.append(h('p', manageOwners));
}
if (!data.noExpiration) {
var expire = Messages.creation_expireFalse;
if (data.expire && typeof (data.expire) === "number") {
expire = new Date(data.expire).toLocaleString();
} }
$('<label>', {'for': 'cp-app-prop-expire'}).text(Messages.creation_expiration)
.appendTo($d);
$d.append(UI.dialog.selectable(expire, {
id: 'cp-app-prop-expire',
}));
}
if (!data.noPassword) { if (!data.noExpiration) {
var hasPassword = data.password; var expire = Messages.creation_expireFalse;
if (hasPassword) { if (data.expire && typeof (data.expire) === "number") {
$('<label>', {'for': 'cp-app-prop-password'}).text(Messages.creation_passwordValue) expire = new Date(data.expire).toLocaleString();
}
$('<label>', {'for': 'cp-app-prop-expire'}).text(Messages.creation_expiration)
.appendTo($d); .appendTo($d);
var password = UI.passwordInput({ $d.append(UI.dialog.selectable(expire, {
id: 'cp-app-prop-password', id: 'cp-app-prop-expire',
readonly: 'readonly' }));
});
var $pwInput = $(password).find('.cp-password-input');
$pwInput.val(data.password).click(function () {
$pwInput[0].select();
});
$d.append(password);
} }
var parsed = Hash.parsePadUrl(data.href || data.roHref); if (!data.noPassword) {
if (!data.noEditPassword && owned && parsed.hashData.type === 'pad' && parsed.type !== "sheet") { // FIXME SHEET fix password change for sheets var hasPassword = data.password;
var sframeChan = common.getSframeChannel(); if (hasPassword) {
var changePwTitle = Messages.properties_changePassword; $('<label>', {'for': 'cp-app-prop-password'}).text(Messages.creation_passwordValue)
var changePwConfirm = Messages.properties_confirmChange; .appendTo($d);
if (!hasPassword) { var password = UI.passwordInput({
changePwTitle = Messages.properties_addPassword; id: 'cp-app-prop-password',
changePwConfirm = Messages.properties_confirmNew; readonly: 'readonly'
});
var $pwInput = $(password).find('.cp-password-input');
$pwInput.val(data.password).click(function () {
$pwInput[0].select();
});
$d.append(password);
} }
$('<label>', {'for': 'cp-app-prop-change-password'})
.text(changePwTitle).appendTo($d); var parsed = Hash.parsePadUrl(data.href || data.roHref);
var newPassword = UI.passwordInput({ if (!data.noEditPassword && owned && parsed.hashData.type === 'pad' && parsed.type !== "sheet") { // FIXME SHEET fix password change for sheets
id: 'cp-app-prop-change-password', var sframeChan = common.getSframeChannel();
style: 'flex: 1;' var changePwTitle = Messages.properties_changePassword;
}); var changePwConfirm = Messages.properties_confirmChange;
var passwordOk = h('button', Messages.properties_changePasswordButton); if (!hasPassword) {
var changePass = h('span.cp-password-container', [ changePwTitle = Messages.properties_addPassword;
newPassword, changePwConfirm = Messages.properties_confirmNew;
passwordOk
]);
$(passwordOk).click(function () {
var newPass = $(newPassword).find('input').val();
if (data.password === newPass ||
(!data.password && !newPass)) {
return void UI.alert(Messages.properties_passwordSame);
} }
UI.confirm(changePwConfirm, function (yes) { $('<label>', {'for': 'cp-app-prop-change-password'})
if (!yes) { return; } .text(changePwTitle).appendTo($d);
sframeChan.query("Q_PAD_PASSWORD_CHANGE", { var newPassword = UI.passwordInput({
href: data.href || data.roHref, id: 'cp-app-prop-change-password',
password: newPass style: 'flex: 1;'
}, function (err, data) { });
if (err || data.error) { var passwordOk = h('button', Messages.properties_changePasswordButton);
return void UI.alert(Messages.properties_passwordError); var changePass = h('span.cp-password-container', [
} newPassword,
UI.findOKButton().click(); passwordOk
// If we didn't have a password, we have to add the /p/ ]);
// If we had a password and we changed it to a new one, we just have to reload $(passwordOk).click(function () {
// If we had a password and we removed it, we have to remove the /p/ var newPass = $(newPassword).find('input').val();
if (data.warning) { if (data.password === newPass ||
return void UI.alert(Messages.properties_passwordWarning, function () { (!data.password && !newPass)) {
return void UI.alert(Messages.properties_passwordSame);
}
UI.confirm(changePwConfirm, function (yes) {
if (!yes) { return; }
sframeChan.query("Q_PAD_PASSWORD_CHANGE", {
href: data.href || data.roHref,
password: newPass
}, function (err, data) {
if (err || data.error) {
return void UI.alert(Messages.properties_passwordError);
}
UI.findOKButton().click();
// If we didn't have a password, we have to add the /p/
// If we had a password and we changed it to a new one, we just have to reload
// If we had a password and we removed it, we have to remove the /p/
if (data.warning) {
return void UI.alert(Messages.properties_passwordWarning, function () {
common.gotoURL(hasPassword && newPass ? undefined : (data.href || data.roHref));
}, {force: true});
}
return void UI.alert(Messages.properties_passwordSuccess, function () {
common.gotoURL(hasPassword && newPass ? undefined : (data.href || data.roHref)); common.gotoURL(hasPassword && newPass ? undefined : (data.href || data.roHref));
}, {force: true}); }, {force: true});
} });
return void UI.alert(Messages.properties_passwordSuccess, function () {
common.gotoURL(hasPassword && newPass ? undefined : (data.href || data.roHref));
}, {force: true});
}); });
}); });
}); $d.append(changePass);
$d.append(changePass); }
} }
} return $d;
};
var sframeChan = common.getSframeChannel();
var handler = sframeChan.on('EV_RT_METADATA', function (md) {
if (!$div.length) {
handler.stop();
return;
}
md = JSON.parse(JSON.stringify(md));
data.owners = md.owners;
data.expire = md.expire;
data.pending_owners = md.pending_owners;
$div.empty();
$div.append(draw());
});
$div.append(draw());
cb(void 0, $d); cb(void 0, $div);
}; };
var getPadProperties = function (common, data, cb) { var getPadProperties = function (common, data, cb) {
var $d = $('<div>'); var $d = $('<div>');
@ -568,6 +596,8 @@ define([
} else { } else {
cb(void 0, $d); cb(void 0, $d);
} }
}; };
UIElements.getProperties = function (common, data, cb) { UIElements.getProperties = function (common, data, cb) {
var c1; var c1;

@ -757,6 +757,7 @@ define([
pad.onDisconnectEvent = Util.mkEvent(); pad.onDisconnectEvent = Util.mkEvent();
pad.onConnectEvent = Util.mkEvent(); pad.onConnectEvent = Util.mkEvent();
pad.onErrorEvent = Util.mkEvent(); pad.onErrorEvent = Util.mkEvent();
pad.onMetadataEvent = Util.mkEvent();
pad.getPadMetadata = function (data, cb) { pad.getPadMetadata = function (data, cb) {
postMessage('GET_PAD_METADATA', data, cb); postMessage('GET_PAD_METADATA', data, cb);
@ -1208,6 +1209,7 @@ define([
PAD_DISCONNECT: common.padRpc.onDisconnectEvent.fire, PAD_DISCONNECT: common.padRpc.onDisconnectEvent.fire,
PAD_CONNECT: common.padRpc.onConnectEvent.fire, PAD_CONNECT: common.padRpc.onConnectEvent.fire,
PAD_ERROR: common.padRpc.onErrorEvent.fire, PAD_ERROR: common.padRpc.onErrorEvent.fire,
PAD_METADATA: common.padRpc.onMetadataEvent.fire,
// Drive // Drive
DRIVE_LOG: common.drive.onLog.fire, DRIVE_LOG: common.drive.onLog.fire,
DRIVE_CHANGE: common.drive.onChange.fire, DRIVE_CHANGE: common.drive.onChange.fire,

@ -1205,7 +1205,6 @@ define([
} }
}, },
onMetadataUpdate: function (metadata) { onMetadataUpdate: function (metadata) {
console.log('onMetadataUpdate', metadata);
channel.data = metadata || {}; channel.data = metadata || {};
var allData = store.manager.findChannel(data.channel); var allData = store.manager.findChannel(data.channel);
allData.forEach(function (obj) { allData.forEach(function (obj) {
@ -1214,7 +1213,7 @@ define([
obj.data.expire = +metadata.expire; obj.data.expire = +metadata.expire;
} }
}); });
//channel.bcast("PAD_METADATA", metadata); channel.bcast("PAD_METADATA", metadata);
}, },
crypto: { crypto: {
// The encryption and decryption is done in the outer window. // The encryption and decryption is done in the outer window.
@ -1374,7 +1373,6 @@ define([
}; };
Store.getPadMetadata = function (clientId, data, cb) { Store.getPadMetadata = function (clientId, data, cb) {
console.log(data);
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); } if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
var channel = channels[data.channel]; var channel = channels[data.channel];
if (!channel) { return void cb({ error: 'ENOTFOUND' }); } if (!channel) { return void cb({ error: 'ENOTFOUND' }); }
@ -1397,7 +1395,6 @@ define([
cb(channel.data || {}); cb(channel.data || {});
}; };
Store.setPadMetadata = function (clientId, data, cb) { Store.setPadMetadata = function (clientId, data, cb) {
console.log(data);
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); } if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
if (!data.command) { return void cb({ error: 'EINVAL' }); } if (!data.command) { return void cb({ error: 'EINVAL' }); }
store.rpc.setMetadata(data, function (err, res) { store.rpc.setMetadata(data, function (err, res) {

@ -742,7 +742,7 @@ define([
datas.forEach(function (d) { datas.forEach(function (d) {
var atime = d.data.atime; var atime = d.data.atime;
var value = attr ? d.data[attr] : JSON.parse(JSON.stringify(d.data)); var value = data.attr ? d.data[data.attr] : JSON.parse(JSON.stringify(d.data));
if (!res.value || res.atime < atime) { if (!res.value || res.atime < atime) {
res.atime = atime; res.atime = atime;
res.value = value; res.value = value;

@ -118,6 +118,10 @@ define([], function () {
onOpen(data); onOpen(data);
}); });
padRpc.onMetadataEvent.reg(function (data) {
sframeChan.event('EV_RT_METADATA', data);
});
padRpc.onErrorEvent.reg(function (err) { padRpc.onErrorEvent.reg(function (err) {
sframeChan.event('EV_RT_ERROR', err); sframeChan.event('EV_RT_ERROR', err);
}); });

@ -1025,7 +1025,6 @@ define([
channel: secret.channel channel: secret.channel
}; };
} }
console.log(data);
Cryptpad.getPadMetadata(data, cb); Cryptpad.getPadMetadata(data, cb);
}); });
sframeChan.on('Q_SET_PAD_METADATA', function (data, cb) { sframeChan.on('Q_SET_PAD_METADATA', function (data, cb) {

Loading…
Cancel
Save