|
|
|
@ -9,11 +9,11 @@ define([
|
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
|
], function ($, Util, Hash, UI, UIElements, h,
|
|
|
|
|
Messages, nThen) {
|
|
|
|
|
console.log(UI, UIElements, h);
|
|
|
|
|
|
|
|
|
|
var Access = {};
|
|
|
|
|
|
|
|
|
|
var createOwnerModal = function (common, data) {
|
|
|
|
|
var getOwnersTab = function (common, data, opts, _cb) {
|
|
|
|
|
var cb = Util.once(Util.mkAsync(_cb));
|
|
|
|
|
|
|
|
|
|
var friends = common.getFriends(true);
|
|
|
|
|
var sframeChan = common.getSframeChannel();
|
|
|
|
|
var priv = common.getMetadataMgr().getPrivateData();
|
|
|
|
@ -23,13 +23,19 @@ console.log(UI, UIElements, h);
|
|
|
|
|
var owners = data.owners || [];
|
|
|
|
|
var pending_owners = data.pending_owners || [];
|
|
|
|
|
var teams = priv.teams;
|
|
|
|
|
var teamsData = Util.tryParse(JSON.stringify(priv.teams)) || {};
|
|
|
|
|
var teamOwner = data.teamId;
|
|
|
|
|
|
|
|
|
|
opts = opts || {};
|
|
|
|
|
var redrawAll = function () {};
|
|
|
|
|
|
|
|
|
|
var div1 = h('div.cp-usergrid-user.cp-share-column.cp-ownership');
|
|
|
|
|
var div2 = h('div.cp-usergrid-user.cp-share-column.cp-ownership');
|
|
|
|
|
var addBtn = h('button.btn.btn-primary.fa.fa-arrow-left');
|
|
|
|
|
|
|
|
|
|
var div1 = h('div.cp-share-column.cp-ownership');
|
|
|
|
|
var divMid = h('div.cp-share-column-mid', addBtn);
|
|
|
|
|
var div2 = h('div.cp-share-column.cp-ownership');
|
|
|
|
|
var $div1 = $(div1);
|
|
|
|
|
$divMid = $(divMid);
|
|
|
|
|
var $div2 = $(div2);
|
|
|
|
|
|
|
|
|
|
// Remove owner column
|
|
|
|
@ -105,7 +111,7 @@ console.log(UI, UIElements, h);
|
|
|
|
|
err = err || (res && res.error);
|
|
|
|
|
if (err) {
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
redrawAll();
|
|
|
|
|
redrawAll(true);
|
|
|
|
|
var text = err === "INSUFFICIENT_PERMISSIONS" ? Messages.fm_forbidden
|
|
|
|
|
: Messages.error;
|
|
|
|
|
return void UI.warn(text);
|
|
|
|
@ -127,7 +133,7 @@ console.log(UI, UIElements, h);
|
|
|
|
|
}, waitFor());
|
|
|
|
|
});
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
redrawAll();
|
|
|
|
|
redrawAll(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
$div.append(h('p', removeButton));
|
|
|
|
@ -154,7 +160,6 @@ console.log(UI, UIElements, h);
|
|
|
|
|
});
|
|
|
|
|
$div.append(addCol.div);
|
|
|
|
|
|
|
|
|
|
var teamsData = Util.tryParse(JSON.stringify(priv.teams)) || {};
|
|
|
|
|
Object.keys(teamsData).forEach(function (id) {
|
|
|
|
|
var t = teamsData[id];
|
|
|
|
|
t.teamId = id;
|
|
|
|
@ -171,293 +176,289 @@ console.log(UI, UIElements, h);
|
|
|
|
|
$div.append(teamsList.div);
|
|
|
|
|
|
|
|
|
|
// When clicking on the add button, we get the selected users.
|
|
|
|
|
var addButton = h('button.no-margin', Messages.owner_addButton);
|
|
|
|
|
$(addButton).click(function () {
|
|
|
|
|
// Check selection
|
|
|
|
|
var $sel = $div.find('.cp-usergrid-user.cp-selected');
|
|
|
|
|
var sel = $sel.toArray();
|
|
|
|
|
if (!sel.length) { return; }
|
|
|
|
|
var toAdd = sel.map(function (el) {
|
|
|
|
|
var curve = $(el).attr('data-curve');
|
|
|
|
|
// If the pad is woned by a team, we can transfer ownership to ourselves
|
|
|
|
|
if (curve === user.curvePublic && teamOwner) { return priv.edPublic; }
|
|
|
|
|
var friend = friends[curve];
|
|
|
|
|
if (!friend) { return; }
|
|
|
|
|
return friend.edPublic;
|
|
|
|
|
}).filter(function (x) { return x; });
|
|
|
|
|
var toAddTeams = sel.map(function (el) {
|
|
|
|
|
var team = teamsData[$(el).attr('data-teamid')];
|
|
|
|
|
if (!team || !team.edPublic) { return; }
|
|
|
|
|
return {
|
|
|
|
|
edPublic: team.edPublic,
|
|
|
|
|
id: $(el).attr('data-teamid')
|
|
|
|
|
};
|
|
|
|
|
}).filter(function (x) { return x; });
|
|
|
|
|
//var addButton = h('button.no-margin', Messages.owner_addButton); // XXX
|
|
|
|
|
//$div.append(h('p', addButton));
|
|
|
|
|
return $div;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
|
var msg = Messages.owner_addConfirm;
|
|
|
|
|
UI.confirm(msg, waitFor(function (yes) {
|
|
|
|
|
if (!yes) {
|
|
|
|
|
$(addBtn).click(function () {
|
|
|
|
|
var $div = $div2.find('.cp-share-column');
|
|
|
|
|
// Check selection
|
|
|
|
|
var $sel = $div.find('.cp-usergrid-user.cp-selected');
|
|
|
|
|
var sel = $sel.toArray();
|
|
|
|
|
if (!sel.length) { return; }
|
|
|
|
|
var toAdd = sel.map(function (el) {
|
|
|
|
|
var curve = $(el).attr('data-curve');
|
|
|
|
|
// If the pad is woned by a team, we can transfer ownership to ourselves
|
|
|
|
|
if (curve === user.curvePublic && teamOwner) { return priv.edPublic; }
|
|
|
|
|
var friend = friends[curve];
|
|
|
|
|
if (!friend) { return; }
|
|
|
|
|
return friend.edPublic;
|
|
|
|
|
}).filter(function (x) { return x; });
|
|
|
|
|
var toAddTeams = sel.map(function (el) {
|
|
|
|
|
var team = teamsData[$(el).attr('data-teamid')];
|
|
|
|
|
if (!team || !team.edPublic) { return; }
|
|
|
|
|
return {
|
|
|
|
|
edPublic: team.edPublic,
|
|
|
|
|
id: $(el).attr('data-teamid')
|
|
|
|
|
};
|
|
|
|
|
}).filter(function (x) { return x; });
|
|
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
|
var msg = Messages.owner_addConfirm;
|
|
|
|
|
UI.confirm(msg, waitFor(function (yes) {
|
|
|
|
|
if (!yes) {
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
// Add one of our teams as an owner
|
|
|
|
|
if (toAddTeams.length) {
|
|
|
|
|
// Send the command
|
|
|
|
|
sframeChan.query('Q_SET_PAD_METADATA', {
|
|
|
|
|
channel: channel,
|
|
|
|
|
command: 'ADD_OWNERS',
|
|
|
|
|
value: toAddTeams.map(function (obj) { return obj.edPublic; }),
|
|
|
|
|
teamId: teamOwner
|
|
|
|
|
}, waitFor(function (err, res) {
|
|
|
|
|
err = err || (res && res.error);
|
|
|
|
|
if (err) {
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
return;
|
|
|
|
|
redrawAll(true);
|
|
|
|
|
var text = err === "INSUFFICIENT_PERMISSIONS" ?
|
|
|
|
|
Messages.fm_forbidden : Messages.error;
|
|
|
|
|
return void UI.warn(text);
|
|
|
|
|
}
|
|
|
|
|
var isTemplate = priv.isTemplate || opts.isTemplate;
|
|
|
|
|
toAddTeams.forEach(function (obj) {
|
|
|
|
|
sframeChan.query('Q_STORE_IN_TEAM', {
|
|
|
|
|
href: data.href || data.rohref,
|
|
|
|
|
password: data.password,
|
|
|
|
|
path: isTemplate ? ['template'] : undefined,
|
|
|
|
|
title: data.title || '',
|
|
|
|
|
teamId: obj.id
|
|
|
|
|
}, waitFor(function (err) {
|
|
|
|
|
if (err) { return void console.error(err); }
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
// Add one of our teams as an owner
|
|
|
|
|
if (toAddTeams.length) {
|
|
|
|
|
// Send the command
|
|
|
|
|
sframeChan.query('Q_SET_PAD_METADATA', {
|
|
|
|
|
channel: channel,
|
|
|
|
|
command: 'ADD_OWNERS',
|
|
|
|
|
value: toAddTeams.map(function (obj) { return obj.edPublic; }),
|
|
|
|
|
teamId: teamOwner
|
|
|
|
|
}, waitFor(function (err, res) {
|
|
|
|
|
err = err || (res && res.error);
|
|
|
|
|
if (err) {
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
redrawAll();
|
|
|
|
|
var text = err === "INSUFFICIENT_PERMISSIONS" ?
|
|
|
|
|
Messages.fm_forbidden : Messages.error;
|
|
|
|
|
return void UI.warn(text);
|
|
|
|
|
}
|
|
|
|
|
var isTemplate = priv.isTemplate || data.isTemplate;
|
|
|
|
|
toAddTeams.forEach(function (obj) {
|
|
|
|
|
sframeChan.query('Q_STORE_IN_TEAM', {
|
|
|
|
|
href: data.href || data.rohref,
|
|
|
|
|
password: data.password,
|
|
|
|
|
path: isTemplate ? ['template'] : undefined,
|
|
|
|
|
title: data.title || '',
|
|
|
|
|
teamId: obj.id
|
|
|
|
|
}, waitFor(function (err) {
|
|
|
|
|
if (err) { return void console.error(err); }
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
// Offer ownership to a friend
|
|
|
|
|
if (toAdd.length) {
|
|
|
|
|
// Send the command
|
|
|
|
|
sframeChan.query('Q_SET_PAD_METADATA', {
|
|
|
|
|
channel: channel,
|
|
|
|
|
command: 'ADD_PENDING_OWNERS',
|
|
|
|
|
value: toAdd,
|
|
|
|
|
teamId: teamOwner
|
|
|
|
|
}, waitFor(function (err, res) {
|
|
|
|
|
err = err || (res && res.error);
|
|
|
|
|
if (err) {
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
redrawAll();
|
|
|
|
|
var text = err === "INSUFFICIENT_PERMISSIONS" ? Messages.fm_forbidden
|
|
|
|
|
: Messages.error;
|
|
|
|
|
return void UI.warn(text);
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
sel.forEach(function (el) {
|
|
|
|
|
var curve = $(el).attr('data-curve');
|
|
|
|
|
var friend = curve === user.curvePublic ? user : friends[curve];
|
|
|
|
|
if (!friend) { return; }
|
|
|
|
|
common.mailbox.sendTo("ADD_OWNER", {
|
|
|
|
|
channel: channel,
|
|
|
|
|
href: data.href,
|
|
|
|
|
password: data.password,
|
|
|
|
|
title: data.title
|
|
|
|
|
}, {
|
|
|
|
|
channel: friend.notifications,
|
|
|
|
|
curvePublic: friend.curvePublic
|
|
|
|
|
}, waitFor());
|
|
|
|
|
});
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
redrawAll();
|
|
|
|
|
UI.log(Messages.saved);
|
|
|
|
|
}
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
// Offer ownership to a friend
|
|
|
|
|
if (toAdd.length) {
|
|
|
|
|
// Send the command
|
|
|
|
|
sframeChan.query('Q_SET_PAD_METADATA', {
|
|
|
|
|
channel: channel,
|
|
|
|
|
command: 'ADD_PENDING_OWNERS',
|
|
|
|
|
value: toAdd,
|
|
|
|
|
teamId: teamOwner
|
|
|
|
|
}, waitFor(function (err, res) {
|
|
|
|
|
err = err || (res && res.error);
|
|
|
|
|
if (err) {
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
redrawAll(true);
|
|
|
|
|
var text = err === "INSUFFICIENT_PERMISSIONS" ? Messages.fm_forbidden
|
|
|
|
|
: Messages.error;
|
|
|
|
|
return void UI.warn(text);
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
sel.forEach(function (el) {
|
|
|
|
|
var curve = $(el).attr('data-curve');
|
|
|
|
|
var friend = curve === user.curvePublic ? user : friends[curve];
|
|
|
|
|
if (!friend) { return; }
|
|
|
|
|
common.mailbox.sendTo("ADD_OWNER", {
|
|
|
|
|
channel: channel,
|
|
|
|
|
href: data.href,
|
|
|
|
|
password: data.password,
|
|
|
|
|
title: data.title
|
|
|
|
|
}, {
|
|
|
|
|
channel: friend.notifications,
|
|
|
|
|
curvePublic: friend.curvePublic
|
|
|
|
|
}, waitFor());
|
|
|
|
|
});
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
redrawAll(true);
|
|
|
|
|
UI.log(Messages.saved);
|
|
|
|
|
});
|
|
|
|
|
$div.append(h('p', addButton));
|
|
|
|
|
return $div;
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
redrawAll = function (md) {
|
|
|
|
|
var todo = function (obj) {
|
|
|
|
|
if (obj && obj.error) { return; }
|
|
|
|
|
owners = obj.owners || [];
|
|
|
|
|
pending_owners = obj.pending_owners || [];
|
|
|
|
|
redrawAll = function (reload) {
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
|
if (!reload) { return; }
|
|
|
|
|
common.getPadMetadata({
|
|
|
|
|
channel: data.channel
|
|
|
|
|
}, waitFor(function (md) {
|
|
|
|
|
data.owners = md.owners || [];
|
|
|
|
|
data.pending_owners = md.pending_owners || [];
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
owners = data.owners || [];
|
|
|
|
|
pending_owners = data.pending_owners || [];
|
|
|
|
|
$div1.empty();
|
|
|
|
|
$div2.empty();
|
|
|
|
|
$div1.append(drawRemove(false)).append(drawRemove(true));
|
|
|
|
|
$div2.append(drawAdd());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (md) { return void todo(md); }
|
|
|
|
|
common.getPadMetadata({
|
|
|
|
|
channel: data.channel
|
|
|
|
|
}, todo);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$div1.append(drawRemove(false)).append(drawRemove(true));
|
|
|
|
|
$div2.append(drawAdd());
|
|
|
|
|
redrawAll();
|
|
|
|
|
|
|
|
|
|
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(md);
|
|
|
|
|
data.owners = md.owners || [];
|
|
|
|
|
data.pending_owners = md.pending_owners || [];
|
|
|
|
|
redrawAll();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Create modal
|
|
|
|
|
var link = h('div.cp-share-columns', [
|
|
|
|
|
div1,
|
|
|
|
|
divMid,
|
|
|
|
|
div2
|
|
|
|
|
/*drawRemove()[0],
|
|
|
|
|
drawAdd()[0]*/
|
|
|
|
|
]);
|
|
|
|
|
var linkButtons = [{
|
|
|
|
|
className: 'cancel',
|
|
|
|
|
name: Messages.filePicker_close,
|
|
|
|
|
onClick: function () {},
|
|
|
|
|
keys: [27]
|
|
|
|
|
}];
|
|
|
|
|
return UI.dialog.customModal(link, {buttons: linkButtons});
|
|
|
|
|
cb(void 0, link);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var getRightsProperties = function (common, data, cb) {
|
|
|
|
|
var $div = $('<div>');
|
|
|
|
|
if (!data) { return void cb(void 0, $div); }
|
|
|
|
|
|
|
|
|
|
var draw = function () {
|
|
|
|
|
var $d = $('<div>');
|
|
|
|
|
var priv = common.getMetadataMgr().getPrivateData();
|
|
|
|
|
var user = common.getMetadataMgr().getUserData();
|
|
|
|
|
var edPublic = priv.edPublic;
|
|
|
|
|
var owned = false;
|
|
|
|
|
var _owners = {};
|
|
|
|
|
if (data.owners && data.owners.length) {
|
|
|
|
|
if (data.owners.indexOf(edPublic) !== -1) {
|
|
|
|
|
owned = true;
|
|
|
|
|
} else {
|
|
|
|
|
Object.keys(priv.teams || {}).some(function (id) {
|
|
|
|
|
var team = priv.teams[id] || {};
|
|
|
|
|
if (team.viewer) { return; }
|
|
|
|
|
if (data.owners.indexOf(team.edPublic) === -1) { return; }
|
|
|
|
|
owned = id;
|
|
|
|
|
return 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
|
|
|
|
|
|
|
|
|
|
// Our edPublic? print "Yourself"
|
|
|
|
|
if (ed === edPublic) {
|
|
|
|
|
_owners[ed] = {
|
|
|
|
|
selected: true,
|
|
|
|
|
name: user.name,
|
|
|
|
|
avatar: user.avatar
|
|
|
|
|
};
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// One of our teams? print the team name
|
|
|
|
|
if (Object.keys(priv.teams || {}).some(function (id) {
|
|
|
|
|
var team = priv.teams[id] || {};
|
|
|
|
|
if (team.edPublic !== ed) { return; }
|
|
|
|
|
_owners[ed] = {
|
|
|
|
|
name: team.name,
|
|
|
|
|
avatar: team.avatar
|
|
|
|
|
};
|
|
|
|
|
return true;
|
|
|
|
|
})) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// One of our friends? print the friend name
|
|
|
|
|
if (Object.keys(priv.friends || {}).some(function (c) {
|
|
|
|
|
var friend = priv.friends[c] || {};
|
|
|
|
|
if (friend.edPublic !== ed || c === 'me') { return; }
|
|
|
|
|
_owners[friend.edPublic] = {
|
|
|
|
|
name: friend.displayName,
|
|
|
|
|
avatar: friend.avatar
|
|
|
|
|
};
|
|
|
|
|
return true;
|
|
|
|
|
})) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Otherwise it's a stranger
|
|
|
|
|
strangers++;
|
|
|
|
|
var isOwned = function (common, data) {
|
|
|
|
|
data = data || {};
|
|
|
|
|
var priv = common.getMetadataMgr().getPrivateData();
|
|
|
|
|
var edPublic = priv.edPublic;
|
|
|
|
|
var owned = false;
|
|
|
|
|
if (data.owners && data.owners.length) {
|
|
|
|
|
if (data.owners.indexOf(edPublic) !== -1) {
|
|
|
|
|
owned = true;
|
|
|
|
|
} else {
|
|
|
|
|
Object.keys(priv.teams || {}).some(function (id) {
|
|
|
|
|
var team = priv.teams[id] || {};
|
|
|
|
|
if (team.viewer) { return; }
|
|
|
|
|
if (data.owners.indexOf(team.edPublic) === -1) { return; }
|
|
|
|
|
owned = id;
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
if (strangers) {
|
|
|
|
|
_owners['stangers'] = {
|
|
|
|
|
name: Messages._getKey('properties_unknownUser', [strangers]),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var _ownersGrid = UIElements.getUserGrid(Messages.creation_owners, {
|
|
|
|
|
common: common,
|
|
|
|
|
noSelect: true,
|
|
|
|
|
data: _owners,
|
|
|
|
|
large: true
|
|
|
|
|
}, function () {});
|
|
|
|
|
if (_ownersGrid && Object.keys(_owners).length) {
|
|
|
|
|
$d.append(_ownersGrid.div);
|
|
|
|
|
} else {
|
|
|
|
|
$d.append([
|
|
|
|
|
h('label', Messages.creation_owners),
|
|
|
|
|
]);
|
|
|
|
|
$d.append(UI.dialog.selectable(Messages.creation_noOwner, {
|
|
|
|
|
id: 'cp-app-prop-owners',
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
return owned;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var getUserList = function (common, list) {
|
|
|
|
|
if (!Array.isArray(list)) { return; }
|
|
|
|
|
var priv = common.getMetadataMgr().getPrivateData();
|
|
|
|
|
var user = common.getMetadataMgr().getUserData();
|
|
|
|
|
var edPublic = priv.edPublic;
|
|
|
|
|
var strangers = 0;
|
|
|
|
|
var _owners = {};
|
|
|
|
|
list.forEach(function (ed) {
|
|
|
|
|
// If a friend is an owner, add their name to the list
|
|
|
|
|
// otherwise, increment the list of strangers
|
|
|
|
|
|
|
|
|
|
// Our edPublic? print "Yourself"
|
|
|
|
|
if (ed === edPublic) {
|
|
|
|
|
_owners[ed] = {
|
|
|
|
|
//selected: true,
|
|
|
|
|
name: user.name,
|
|
|
|
|
avatar: user.avatar
|
|
|
|
|
};
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var parsed;
|
|
|
|
|
if (data.href || data.roHref) {
|
|
|
|
|
parsed = Hash.parsePadUrl(data.href || data.roHref);
|
|
|
|
|
// One of our teams? print the team name
|
|
|
|
|
if (Object.keys(priv.teams || {}).some(function (id) {
|
|
|
|
|
var team = priv.teams[id] || {};
|
|
|
|
|
if (team.edPublic !== ed) { return; }
|
|
|
|
|
_owners[ed] = {
|
|
|
|
|
name: team.name,
|
|
|
|
|
avatar: team.avatar
|
|
|
|
|
};
|
|
|
|
|
return true;
|
|
|
|
|
})) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (owned && parsed.hashData.type === 'pad') {
|
|
|
|
|
var manageOwners = h('button.no-margin', Messages.owner_openModalButton);
|
|
|
|
|
$(manageOwners).click(function () {
|
|
|
|
|
data.teamId = typeof(owned) !== "boolean" ? owned : undefined;
|
|
|
|
|
var modal = createOwnerModal(common, data);
|
|
|
|
|
UI.openCustomModal(modal, {
|
|
|
|
|
wide: true,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
$d.append(h('p', manageOwners));
|
|
|
|
|
// One of our friends? print the friend name
|
|
|
|
|
if (Object.keys(priv.friends || {}).some(function (c) {
|
|
|
|
|
var friend = priv.friends[c] || {};
|
|
|
|
|
if (friend.edPublic !== ed || c === 'me') { return; }
|
|
|
|
|
_owners[friend.edPublic] = {
|
|
|
|
|
name: friend.displayName,
|
|
|
|
|
avatar: friend.avatar
|
|
|
|
|
};
|
|
|
|
|
return true;
|
|
|
|
|
})) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Otherwise it's a stranger
|
|
|
|
|
_owners[ed] = {
|
|
|
|
|
name: '???', // XXX unkwown?
|
|
|
|
|
};
|
|
|
|
|
strangers++;
|
|
|
|
|
});
|
|
|
|
|
if (!Object.keys(_owners).length) { return; }
|
|
|
|
|
/*
|
|
|
|
|
if (strangers) {
|
|
|
|
|
_owners['stangers'] = {
|
|
|
|
|
name: Messages._getKey('properties_unknownUser', [strangers]),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
return UIElements.getUserGrid(null, {
|
|
|
|
|
common: common,
|
|
|
|
|
noSelect: true,
|
|
|
|
|
data: _owners,
|
|
|
|
|
large: true
|
|
|
|
|
}, function () {});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!data.noExpiration) {
|
|
|
|
|
var getAccessTab = function (common, data, opts, _cb) {
|
|
|
|
|
var cb = Util.once(Util.mkAsync(_cb));
|
|
|
|
|
opts = opts || {};
|
|
|
|
|
|
|
|
|
|
var priv = common.getMetadataMgr().getPrivateData();
|
|
|
|
|
var edPublic = priv.edPublic;
|
|
|
|
|
|
|
|
|
|
var $div = $(h('div.cp-share-columns'));
|
|
|
|
|
if (!data) { return void cb(void 0, $div); }
|
|
|
|
|
|
|
|
|
|
var div1 = h('div.cp-usergrid-user.cp-share-column.cp-access');
|
|
|
|
|
var div2 = h('div.cp-usergrid-user.cp-share-column.cp-access');
|
|
|
|
|
var $div1 = $(div1).appendTo($div);
|
|
|
|
|
var $div2 = $(div2).appendTo($div);
|
|
|
|
|
|
|
|
|
|
var parsed = Hash.parsePadUrl(data.href || data.roHref);
|
|
|
|
|
if (!parsed || !parsed.hashData) { return void console.error("Invalid href"); }
|
|
|
|
|
|
|
|
|
|
var drawLeft = function () {
|
|
|
|
|
var $d = $('<div>');
|
|
|
|
|
|
|
|
|
|
var owned = isOwned(common, data);
|
|
|
|
|
|
|
|
|
|
if (!opts.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',
|
|
|
|
|
}));
|
|
|
|
|
$d.append(h('div.cp-app-prop', [
|
|
|
|
|
Messages.creation_expiration,
|
|
|
|
|
h('br'),
|
|
|
|
|
h('span.cp-app-prop-content', expire)
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var $pwLabel = $('<label>', {'for': 'cp-app-prop-password'})
|
|
|
|
|
.text(Messages.creation_passwordValue).appendTo($d);
|
|
|
|
|
var password = UI.passwordInput({
|
|
|
|
|
id: 'cp-app-prop-password',
|
|
|
|
|
readonly: 'readonly'
|
|
|
|
|
});
|
|
|
|
|
$d.append(password);
|
|
|
|
|
if (!data.noPassword) {
|
|
|
|
|
var hasPassword = data.password;
|
|
|
|
|
var $pwLabel = $('<label>', {'for': 'cp-app-prop-password'}).text(Messages.creation_passwordValue)
|
|
|
|
|
.hide().appendTo($d);
|
|
|
|
|
var password = UI.passwordInput({
|
|
|
|
|
id: 'cp-app-prop-password',
|
|
|
|
|
readonly: 'readonly'
|
|
|
|
|
});
|
|
|
|
|
var $password = $(password).hide();
|
|
|
|
|
var $password = $(password);
|
|
|
|
|
var $pwInput = $password.find('.cp-password-input');
|
|
|
|
|
$pwInput.val(data.password).click(function () {
|
|
|
|
|
$pwInput.val(data.password || '').click(function () {
|
|
|
|
|
$pwInput[0].select();
|
|
|
|
|
});
|
|
|
|
|
$d.append(password);
|
|
|
|
|
|
|
|
|
|
if (hasPassword) {
|
|
|
|
|
$pwLabel.show();
|
|
|
|
|
$password.css('display', 'flex');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// In the properties, we should have the edit href if we know it.
|
|
|
|
|
// We should know it because the pad is stored, but it's better to check...
|
|
|
|
@ -532,8 +533,6 @@ console.log(UI, UIElements, h);
|
|
|
|
|
}
|
|
|
|
|
UI.findOKButton().click();
|
|
|
|
|
|
|
|
|
|
$pwLabel.show();
|
|
|
|
|
$password.css('display', 'flex');
|
|
|
|
|
$pwInput.val(newPass);
|
|
|
|
|
|
|
|
|
|
// If the current document is a file or if we're changing the password from a drive,
|
|
|
|
@ -576,8 +575,45 @@ console.log(UI, UIElements, h);
|
|
|
|
|
}
|
|
|
|
|
return $d;
|
|
|
|
|
};
|
|
|
|
|
var drawRight = function () {
|
|
|
|
|
var content = [
|
|
|
|
|
h('label', Messages.creation_owners),
|
|
|
|
|
];
|
|
|
|
|
var _ownersGrid = getUserList(common, data.owners);
|
|
|
|
|
if (_ownersGrid && _ownersGrid.div) {
|
|
|
|
|
content.push(_ownersGrid.div);
|
|
|
|
|
} else {
|
|
|
|
|
content.push(UI.dialog.selectable(Messages.creation_noOwner, {
|
|
|
|
|
id: 'cp-app-prop-owners',
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
var owned = isOwned(common, data);
|
|
|
|
|
var parsed = Hash.parsePadUrl(data.href || data.roHref);
|
|
|
|
|
if (!parsed || !parsed.hashData) { return; }
|
|
|
|
|
if (owned && parsed.hashData.type === 'pad') {
|
|
|
|
|
var manageOwners = h('button.no-margin', Messages.owner_openModalButton);
|
|
|
|
|
$(manageOwners).click(function () {
|
|
|
|
|
data.teamId = typeof(owned) !== "boolean" ? owned : undefined;
|
|
|
|
|
var modal = createOwnerModal(common, data);
|
|
|
|
|
UI.openCustomModal(modal, {
|
|
|
|
|
wide: true,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
$d.append(h('p', manageOwners));
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
return h('div', content);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var sframeChan = common.getSframeChannel();
|
|
|
|
|
var redraw = function () {
|
|
|
|
|
$div1.empty();
|
|
|
|
|
$div1.append(drawLeft());
|
|
|
|
|
$div2.empty();
|
|
|
|
|
$div2.append(drawRight());
|
|
|
|
|
};
|
|
|
|
|
var handler = sframeChan.on('EV_RT_METADATA', function (md) {
|
|
|
|
|
if (!$div.length) {
|
|
|
|
|
handler.stop();
|
|
|
|
@ -587,10 +623,9 @@ console.log(UI, UIElements, h);
|
|
|
|
|
data.owners = md.owners;
|
|
|
|
|
data.expire = md.expire;
|
|
|
|
|
data.pending_owners = md.pending_owners;
|
|
|
|
|
$div.empty();
|
|
|
|
|
$div.append(draw());
|
|
|
|
|
redraw();
|
|
|
|
|
});
|
|
|
|
|
$div.append(draw());
|
|
|
|
|
redraw();
|
|
|
|
|
|
|
|
|
|
cb(void 0, $div);
|
|
|
|
|
};
|
|
|
|
@ -631,7 +666,14 @@ console.log(UI, UIElements, h);
|
|
|
|
|
};
|
|
|
|
|
Access.getAccessModal = function (common, opts, cb) {
|
|
|
|
|
var data;
|
|
|
|
|
var content;
|
|
|
|
|
var tab1, tab2, tab3;
|
|
|
|
|
var owned = false;
|
|
|
|
|
var button = [{
|
|
|
|
|
className: 'cancel',
|
|
|
|
|
name: Messages.filePicker_close,
|
|
|
|
|
onClick: function () {},
|
|
|
|
|
keys: [13,27]
|
|
|
|
|
}];
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
|
getAccessData(common, opts, waitFor(function (e, _data) {
|
|
|
|
|
if (e) {
|
|
|
|
@ -641,15 +683,48 @@ console.log(UI, UIElements, h);
|
|
|
|
|
data = _data;
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
|
getRightsProperties(common, data, waitFor(function (e, c) {
|
|
|
|
|
owned = isOwned(common, data);
|
|
|
|
|
|
|
|
|
|
getAccessTab(common, data, opts, waitFor(function (e, c) {
|
|
|
|
|
if (e) {
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
return void cb(e);
|
|
|
|
|
}
|
|
|
|
|
content = c[0];
|
|
|
|
|
tab1 = UI.dialog.customModal(c[0], {
|
|
|
|
|
buttons: button
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
if (!owned) { return; }
|
|
|
|
|
|
|
|
|
|
getOwnersTab(common, data, opts, waitFor(function (e, c) {
|
|
|
|
|
if (e) {
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
return void cb(e);
|
|
|
|
|
}
|
|
|
|
|
tab3 = UI.dialog.customModal(c, {
|
|
|
|
|
buttons: button
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
var modal = UI.alert(content);
|
|
|
|
|
var tabs = UI.dialog.tabs([{
|
|
|
|
|
title: "ACCESS", // XXX
|
|
|
|
|
icon: "fa fa-unlock-alt",
|
|
|
|
|
content: tab1
|
|
|
|
|
}, {
|
|
|
|
|
title: "ALLOW LIST", // XXX
|
|
|
|
|
disabled: !owned,
|
|
|
|
|
icon: "fa fa-list",
|
|
|
|
|
content: h('div')
|
|
|
|
|
}, {
|
|
|
|
|
title: Messages.creation_owners,
|
|
|
|
|
disabled: !owned,
|
|
|
|
|
icon: "fa fa-id-badge",
|
|
|
|
|
content: tab3
|
|
|
|
|
}]);
|
|
|
|
|
var modal = UI.openCustomModal(tabs, {
|
|
|
|
|
wide: true
|
|
|
|
|
});
|
|
|
|
|
cb (void 0, modal);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|