|
|
@ -316,22 +316,18 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var getFriendsList = function (common) {
|
|
|
|
var getFriendsList = function (config) { // XXX test from the drive and don't forget to pass the title
|
|
|
|
var priv = common.getMetadataMgr().getPrivateData();
|
|
|
|
var common = config.common;
|
|
|
|
var friends = priv.friends;
|
|
|
|
var title = config.title;
|
|
|
|
|
|
|
|
var friends = config.friends;
|
|
|
|
|
|
|
|
var myName = common.getMetadataMgr().getUserData().name;
|
|
|
|
var order = [];
|
|
|
|
var order = [];
|
|
|
|
if (!friends) { return; }
|
|
|
|
if (!friends) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
// XXX
|
|
|
|
|
|
|
|
for (var i = 0; i < 30; i++) {
|
|
|
|
|
|
|
|
friends[i] = {
|
|
|
|
|
|
|
|
curvePublic: Hash.createChannelId(),
|
|
|
|
|
|
|
|
displayName: i+ ' blu'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var others = Object.keys(friends).map(function (curve, i) {
|
|
|
|
var others = Object.keys(friends).map(function (curve, i) {
|
|
|
|
|
|
|
|
if (curve.length <= 40) { return; }
|
|
|
|
var data = friends[curve];
|
|
|
|
var data = friends[curve];
|
|
|
|
|
|
|
|
if (!data.notifications) { return; }
|
|
|
|
var avatar = h('span.cp-share-friend-avatar.cp-avatar');
|
|
|
|
var avatar = h('span.cp-share-friend-avatar.cp-avatar');
|
|
|
|
UIElements.displayAvatar(common, $(avatar), data.avatar, data.displayName);
|
|
|
|
UIElements.displayAvatar(common, $(avatar), data.avatar, data.displayName);
|
|
|
|
return h('div.cp-share-friend', {
|
|
|
|
return h('div.cp-share-friend', {
|
|
|
@ -343,32 +339,32 @@ define([
|
|
|
|
avatar,
|
|
|
|
avatar,
|
|
|
|
h('span.cp-share-friend-name', data.displayName)
|
|
|
|
h('span.cp-share-friend-name', data.displayName)
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}).filter(function (x) { return x; });
|
|
|
|
var smallCurves = Object.keys(friends).map(function (c) {
|
|
|
|
var smallCurves = Object.keys(friends).map(function (c) {
|
|
|
|
return friends[c].curvePublic.slice(0,8);
|
|
|
|
return friends[c].curvePublic.slice(0,8);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var noOthers = others.length === 0 ? '.cp-recent-only' : '';
|
|
|
|
var noOthers = others.length === 0 ? '.cp-recent-only' : '';
|
|
|
|
|
|
|
|
|
|
|
|
var buttonSelect = h('button.cp-share-with-friends', Messages.shareSelectAll || 'Select'); // XXX
|
|
|
|
var buttonSelect = h('button.cp-share-with-friends', Messages.share_selectAll);
|
|
|
|
var buttonDeselect = h('button.cp-share-with-friends', Messages.shareDeselectAll || 'Deselect'); // XXX
|
|
|
|
var buttonDeselect = h('button.cp-share-with-friends', Messages.share_deselectAll);
|
|
|
|
var inputFilter = h('input', {
|
|
|
|
var inputFilter = h('input', {
|
|
|
|
placeholder: 'Search friend...'
|
|
|
|
placeholder: Messages.share_filterFriend
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var bloc = h('div.cp-share-friends.cp-share-column' + noOthers, [
|
|
|
|
var div = h('div.cp-share-friends.cp-share-column' + noOthers, [
|
|
|
|
h('label', Messages.share_linkFriends || "Friends"), // XXX
|
|
|
|
h('label', Messages.share_linkFriends),
|
|
|
|
h('div.cp-share-grid-filter', [
|
|
|
|
h('div.cp-share-grid-filter', [
|
|
|
|
inputFilter,
|
|
|
|
inputFilter,
|
|
|
|
buttonSelect,
|
|
|
|
buttonSelect,
|
|
|
|
buttonDeselect
|
|
|
|
buttonDeselect
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
var $bloc = $(bloc);
|
|
|
|
var $div = $(div);
|
|
|
|
|
|
|
|
|
|
|
|
// Fill with fake friends to have a uniform spacing (from the flexbox)
|
|
|
|
// Fill with fake friends to have a uniform spacing (from the flexbox)
|
|
|
|
var addFake = function (els) {
|
|
|
|
var addFake = function (els) {
|
|
|
|
$(bloc).find('.cp-fake-friend').remove();
|
|
|
|
$div.find('.cp-fake-friend').remove();
|
|
|
|
var n = (6 - els.length%6)%6;
|
|
|
|
var n = (6 - els.length%6)%6;
|
|
|
|
for (var j = 0; j < n; j++) {
|
|
|
|
for (var j = 0; j < n; j++) {
|
|
|
|
els.push(h('div.cp-share-friend.cp-fake-friend', {
|
|
|
|
els.push(h('div.cp-share-friend.cp-fake-friend', {
|
|
|
@ -380,17 +376,17 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var redraw = function () {
|
|
|
|
var redraw = function () {
|
|
|
|
var name = $(inputFilter).val().trim().replace(/"/g, '');
|
|
|
|
var name = $(inputFilter).val().trim().replace(/"/g, '');
|
|
|
|
$bloc.find('.cp-share-friend').show();
|
|
|
|
$div.find('.cp-share-friend').show();
|
|
|
|
if (!name) { return; }
|
|
|
|
if (!name) { return; }
|
|
|
|
$bloc.find('.cp-share-friend:not(.cp-selected):not([data-name*="'+name+'"])').hide();
|
|
|
|
$div.find('.cp-share-friend:not(.cp-selected):not([data-name*="'+name+'"])').hide();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$(inputFilter).on('keydown keyup change', redraw);
|
|
|
|
$(inputFilter).on('keydown keyup change', redraw);
|
|
|
|
$(buttonSelect).click(function () {
|
|
|
|
$(buttonSelect).click(function () {
|
|
|
|
$bloc.find('.cp-share-friend:not(.cp-selected):visible').addClass('cp-selected');
|
|
|
|
$div.find('.cp-share-friend:not(.cp-selected):visible').addClass('cp-selected');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(buttonDeselect).click(function () {
|
|
|
|
$(buttonDeselect).click(function () {
|
|
|
|
$bloc.find('.cp-share-friend.cp-selected').removeClass('cp-selected').each(function (i, el) {
|
|
|
|
$div.find('.cp-share-friend.cp-selected').removeClass('cp-selected').each(function (i, el) {
|
|
|
|
var order = $(el).attr('data-order');
|
|
|
|
var order = $(el).attr('data-order');
|
|
|
|
if (!order) { return; }
|
|
|
|
if (!order) { return; }
|
|
|
|
$(el).attr('style', 'order:'+order);
|
|
|
|
$(el).attr('style', 'order:'+order);
|
|
|
@ -398,38 +394,51 @@ define([
|
|
|
|
redraw();
|
|
|
|
redraw();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
console.log(smallCurves);
|
|
|
|
|
|
|
|
var refreshButtons = function () {
|
|
|
|
var refreshButtons = function () {
|
|
|
|
var $nav = $bloc.parents('.alertify-tabs-content').find('nav');
|
|
|
|
var $nav = $div.parents('.alertify-tabs-content').find('nav');
|
|
|
|
if (!$nav.find('.cp-share-with-friends').length) {
|
|
|
|
if (!$nav.find('.cp-share-with-friends').length) {
|
|
|
|
var button = h('button.primary.cp-share-with-friends', {
|
|
|
|
var button = h('button.primary.cp-share-with-friends', {
|
|
|
|
'data-keys': '[13]'
|
|
|
|
'data-keys': '[13]'
|
|
|
|
}, Messages.shareLinkWithFriends || 'Share with friends'); // XXX
|
|
|
|
}, Messages.share_withFriends);
|
|
|
|
$(button).click(function () {
|
|
|
|
$(button).click(function () {
|
|
|
|
|
|
|
|
var href = Hash.getRelativeHref($('#cp-share-link-preview').val());
|
|
|
|
|
|
|
|
var $friends = $div.find('.cp-share-friend.cp-selected');
|
|
|
|
|
|
|
|
$friends.each(function (i, el) {
|
|
|
|
|
|
|
|
var curve = $(el).attr('data-curve');
|
|
|
|
|
|
|
|
if (!curve || !friends[curve]) { return; }
|
|
|
|
|
|
|
|
var friend = friends[curve];
|
|
|
|
|
|
|
|
if (!friend.notifications || !friend.curvePublic) { return; }
|
|
|
|
|
|
|
|
common.mailbox.sendTo("SHARE_PAD", {
|
|
|
|
|
|
|
|
href: href,
|
|
|
|
|
|
|
|
name: myName,
|
|
|
|
|
|
|
|
title: title
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
|
|
|
channel: friend.notifications,
|
|
|
|
|
|
|
|
curvePublic: friend.curvePublic
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(UI.findCancelButton());
|
|
|
|
|
|
|
|
UI.findCancelButton().click();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update the "recently shared with" array:
|
|
|
|
// Get the selected curves
|
|
|
|
// Get the selected curves
|
|
|
|
var $friends = $bloc.find('.cp-share-friend.cp-selected');
|
|
|
|
|
|
|
|
var curves = $friends.toArray().map(function (el) {
|
|
|
|
var curves = $friends.toArray().map(function (el) {
|
|
|
|
return ($(el).attr('data-curve') || '').slice(0,8);
|
|
|
|
return ($(el).attr('data-curve') || '').slice(0,8);
|
|
|
|
}).filter(function (x) { return x; });
|
|
|
|
}).filter(function (x) { return x; });
|
|
|
|
// Prepend them to the "order" array
|
|
|
|
// Prepend them to the "order" array
|
|
|
|
Array.prototype.unshift.apply(order, curves);
|
|
|
|
Array.prototype.unshift.apply(order, curves);
|
|
|
|
console.log(order);
|
|
|
|
|
|
|
|
order = Util.deduplicateString(order);
|
|
|
|
order = Util.deduplicateString(order);
|
|
|
|
console.log(order);
|
|
|
|
|
|
|
|
// Make sure we don't have "old" friends and save
|
|
|
|
// Make sure we don't have "old" friends and save
|
|
|
|
order = order.filter(function (curve) {
|
|
|
|
order = order.filter(function (curve) {
|
|
|
|
return smallCurves.indexOf(curve) !== -1;
|
|
|
|
return smallCurves.indexOf(curve) !== -1;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
console.log(order);
|
|
|
|
|
|
|
|
common.setAttribute(['general', 'share-friends'], order);
|
|
|
|
common.setAttribute(['general', 'share-friends'], order);
|
|
|
|
|
|
|
|
|
|
|
|
// XXX send to mailboxes
|
|
|
|
|
|
|
|
// Notes: we need to filter the friend to only have th eones with mailboxes!
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$nav.append(button);
|
|
|
|
$nav.append(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var friendMode = $bloc.find('.cp-share-friend.cp-selected').length;
|
|
|
|
var friendMode = $div.find('.cp-share-friend.cp-selected').length;
|
|
|
|
if (friendMode) {
|
|
|
|
if (friendMode) {
|
|
|
|
$nav.find('button.primary[data-keys]').hide();
|
|
|
|
$nav.find('button.primary[data-keys]').hide();
|
|
|
|
$nav.find('button.cp-share-with-friends').show();
|
|
|
|
$nav.find('button.cp-share-with-friends').show();
|
|
|
@ -462,8 +471,8 @@ define([
|
|
|
|
$(el).attr('data-order', i).css('order', i);
|
|
|
|
$(el).attr('data-order', i).css('order', i);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// Display them
|
|
|
|
// Display them
|
|
|
|
$bloc.append(h('div.cp-share-grid', others));
|
|
|
|
$div.append(h('div.cp-share-grid', others));
|
|
|
|
$bloc.find('.cp-share-friend').click(function () {
|
|
|
|
$div.find('.cp-share-friend').click(function () {
|
|
|
|
var sel = $(this).hasClass('cp-selected');
|
|
|
|
var sel = $(this).hasClass('cp-selected');
|
|
|
|
if (!sel) {
|
|
|
|
if (!sel) {
|
|
|
|
$(this).addClass('cp-selected');
|
|
|
|
$(this).addClass('cp-selected');
|
|
|
@ -475,7 +484,7 @@ define([
|
|
|
|
refreshButtons();
|
|
|
|
refreshButtons();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return bloc;
|
|
|
|
return div;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UIElements.createShareModal = function (config) {
|
|
|
|
UIElements.createShareModal = function (config) {
|
|
|
@ -487,28 +496,18 @@ define([
|
|
|
|
if (!hashes) { return; }
|
|
|
|
if (!hashes) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
// Share link tab
|
|
|
|
// Share link tab
|
|
|
|
var friendsList = getFriendsList(common);
|
|
|
|
var hasFriends = Object.keys(config.friends || {}).length !== 0;
|
|
|
|
var link = h('div.cp-share-modal.cp-share-columns', [
|
|
|
|
var friendsList = hasFriends ? getFriendsList(config) : undefined;
|
|
|
|
|
|
|
|
var friendsUIClass = hasFriends ? '.cp-share-columns' : '';
|
|
|
|
|
|
|
|
var link = h('div.cp-share-modal' + friendsUIClass, [
|
|
|
|
h('div.cp-share-column', [
|
|
|
|
h('div.cp-share-column', [
|
|
|
|
h('p', 'Select the access rights you want to use and copy the share URL or send it directly to your CryptPad friends'), // XXX
|
|
|
|
hasFriends ? h('p', Messages.share_description) : undefined,
|
|
|
|
h('label', Messages.share_linkAccess),
|
|
|
|
h('label', Messages.share_linkAccess),
|
|
|
|
h('br'),
|
|
|
|
h('br'),
|
|
|
|
UI.createRadio('cp-share-editable', 'cp-share-editable-true',
|
|
|
|
UI.createRadio('cp-share-editable', 'cp-share-editable-true',
|
|
|
|
Messages.share_linkEdit, true, { mark: {tabindex:1} }),
|
|
|
|
Messages.share_linkEdit, true, { mark: {tabindex:1} }),
|
|
|
|
UI.createRadio('cp-share-editable', 'cp-share-editable-false',
|
|
|
|
UI.createRadio('cp-share-editable', 'cp-share-editable-false',
|
|
|
|
Messages.share_linkView, false, { mark: {tabindex:1} }),
|
|
|
|
Messages.share_linkView, false, { mark: {tabindex:1} }),
|
|
|
|
/*h('input#cp-share-editable-true.cp-share-editable-value', {
|
|
|
|
|
|
|
|
type: 'radio',
|
|
|
|
|
|
|
|
name: 'cp-share-editable',
|
|
|
|
|
|
|
|
value: 1,
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
h('label', { 'for': 'cp-share-editable-true' }, Messages.share_linkEdit),
|
|
|
|
|
|
|
|
h('input#cp-share-editable-false.cp-share-editable-value', {
|
|
|
|
|
|
|
|
type: 'radio',
|
|
|
|
|
|
|
|
name: 'cp-share-editable',
|
|
|
|
|
|
|
|
value: 0
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
h('label', { 'for': 'cp-share-editable-false' }, Messages.share_linkView),*/
|
|
|
|
|
|
|
|
h('br'),
|
|
|
|
h('br'),
|
|
|
|
h('label', Messages.share_linkOptions),
|
|
|
|
h('label', Messages.share_linkOptions),
|
|
|
|
h('br'),
|
|
|
|
h('br'),
|
|
|
@ -549,6 +548,7 @@ define([
|
|
|
|
$(link).find('#cp-share-link-preview').val(getLinkValue());
|
|
|
|
$(link).find('#cp-share-link-preview').val(getLinkValue());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var linkButtons = [{
|
|
|
|
var linkButtons = [{
|
|
|
|
|
|
|
|
className: 'cancel',
|
|
|
|
name: Messages.cancel,
|
|
|
|
name: Messages.cancel,
|
|
|
|
onClick: function () {},
|
|
|
|
onClick: function () {},
|
|
|
|
keys: [27]
|
|
|
|
keys: [27]
|
|
|
@ -592,6 +592,7 @@ define([
|
|
|
|
UI.dialog.selectable(getEmbedValue())
|
|
|
|
UI.dialog.selectable(getEmbedValue())
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
var embedButtons = [{
|
|
|
|
var embedButtons = [{
|
|
|
|
|
|
|
|
className: 'cancel',
|
|
|
|
name: Messages.cancel,
|
|
|
|
name: Messages.cancel,
|
|
|
|
onClick: function () {},
|
|
|
|
onClick: function () {},
|
|
|
|
keys: [27]
|
|
|
|
keys: [27]
|
|
|
@ -664,6 +665,7 @@ define([
|
|
|
|
var getLinkValue = function () { return url; };
|
|
|
|
var getLinkValue = function () { return url; };
|
|
|
|
$(link).find('#cp-share-link-preview').val(getLinkValue());
|
|
|
|
$(link).find('#cp-share-link-preview').val(getLinkValue());
|
|
|
|
var linkButtons = [{
|
|
|
|
var linkButtons = [{
|
|
|
|
|
|
|
|
className: 'cancel',
|
|
|
|
name: Messages.cancel,
|
|
|
|
name: Messages.cancel,
|
|
|
|
onClick: function () {},
|
|
|
|
onClick: function () {},
|
|
|
|
keys: [27]
|
|
|
|
keys: [27]
|
|
|
@ -690,6 +692,7 @@ define([
|
|
|
|
UI.dialog.selectable(common.getMediatagFromHref(fileData)),
|
|
|
|
UI.dialog.selectable(common.getMediatagFromHref(fileData)),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
var embedButtons = [{
|
|
|
|
var embedButtons = [{
|
|
|
|
|
|
|
|
className: 'cancel',
|
|
|
|
name: Messages.cancel,
|
|
|
|
name: Messages.cancel,
|
|
|
|
onClick: function () {},
|
|
|
|
onClick: function () {},
|
|
|
|
keys: [27]
|
|
|
|
keys: [27]
|
|
|
|