2015-08-21 16:40:50 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-08-19 22:03:25 +03:00
|
|
|
/* globals Clipboard, Handlebars */
|
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
(function() {
|
|
|
|
if (!OC.Share) {
|
|
|
|
OC.Share = {};
|
|
|
|
}
|
|
|
|
|
2015-10-16 12:55:23 +03:00
|
|
|
var PASSWORD_PLACEHOLDER = '**********';
|
|
|
|
var PASSWORD_PLACEHOLDER_MESSAGE = t('core', 'Choose a password for the public link');
|
2017-06-12 17:30:08 +03:00
|
|
|
var PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL = t('core', 'Choose a password for the public link or press the "Enter" key');
|
2015-10-16 12:55:23 +03:00
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
/**
|
|
|
|
* @class OCA.Share.ShareDialogLinkShareView
|
|
|
|
* @member {OC.Share.ShareItemModel} model
|
|
|
|
* @member {jQuery} $el
|
|
|
|
* @memberof OCA.Sharing
|
|
|
|
* @classdesc
|
|
|
|
*
|
|
|
|
* Represents the GUI of the share dialogue
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
var ShareDialogLinkShareView = OC.Backbone.View.extend({
|
|
|
|
/** @type {string} **/
|
|
|
|
id: 'shareDialogLinkShare',
|
|
|
|
|
|
|
|
/** @type {OC.Share.ShareConfigModel} **/
|
|
|
|
configModel: undefined,
|
|
|
|
|
|
|
|
/** @type {boolean} **/
|
|
|
|
showLink: true,
|
|
|
|
|
2018-08-15 12:50:48 +03:00
|
|
|
/** @type {boolean} **/
|
|
|
|
showPending: false,
|
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
/** @type {string} **/
|
|
|
|
password: '',
|
|
|
|
|
2015-09-14 19:24:58 +03:00
|
|
|
events: {
|
2018-08-15 12:50:48 +03:00
|
|
|
// open menu
|
|
|
|
'click .share-menu .icon-more': 'onToggleMenu',
|
2018-10-22 12:06:53 +03:00
|
|
|
// hide download
|
|
|
|
'change .hideDownloadCheckbox': 'onHideDownloadChange',
|
2018-08-15 12:50:48 +03:00
|
|
|
// password
|
2015-10-16 11:54:45 +03:00
|
|
|
'focusout input.linkPassText': 'onPasswordEntered',
|
|
|
|
'keyup input.linkPassText': 'onPasswordKeyUp',
|
2018-08-16 08:31:17 +03:00
|
|
|
'change .showPasswordCheckbox': 'onShowPasswordClick',
|
2018-10-15 18:09:46 +03:00
|
|
|
'change .passwordByTalkCheckbox': 'onPasswordByTalkChange',
|
2018-08-15 12:50:48 +03:00
|
|
|
'change .publicEditingCheckbox': 'onAllowPublicEditingChange',
|
|
|
|
// copy link url
|
|
|
|
'click .linkText': 'onLinkTextClick',
|
|
|
|
// social
|
2017-03-09 15:56:27 +03:00
|
|
|
'click .pop-up': 'onPopUpClick',
|
2018-08-15 12:50:48 +03:00
|
|
|
// permission change
|
2018-07-19 11:04:37 +03:00
|
|
|
'change .publicUploadRadio': 'onPublicUploadChange',
|
2018-08-15 12:50:48 +03:00
|
|
|
// expire date
|
2018-07-19 11:04:37 +03:00
|
|
|
'click .expireDate' : 'onExpireDateChange',
|
|
|
|
'change .datepicker': 'onChangeExpirationDate',
|
|
|
|
'click .datepicker' : 'showDatePicker',
|
2018-08-15 12:50:48 +03:00
|
|
|
// note
|
2018-07-19 11:04:37 +03:00
|
|
|
'click .share-add': 'showNoteForm',
|
|
|
|
'click .share-note-delete': 'deleteNote',
|
2018-10-29 15:58:14 +03:00
|
|
|
'click .share-note-submit': 'updateNote',
|
|
|
|
// remove
|
|
|
|
'click .unshare': 'onUnshare',
|
|
|
|
// new share
|
|
|
|
'click .new-share': 'newShare',
|
2018-10-31 13:43:05 +03:00
|
|
|
// enforced pass set
|
|
|
|
'submit .enforcedPassForm': 'enforcedPasswordSet',
|
2015-09-14 19:24:58 +03:00
|
|
|
},
|
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
initialize: function(options) {
|
|
|
|
var view = this;
|
|
|
|
|
|
|
|
this.model.on('change:permissions', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.model.on('change:itemType', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.model.on('change:allowPublicUploadStatus', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
|
|
|
|
2016-06-07 13:28:02 +03:00
|
|
|
this.model.on('change:hideFileListStatus', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
|
|
|
|
2018-10-15 18:09:46 +03:00
|
|
|
this.model.on('change:linkShares', function(model, linkShares) {
|
|
|
|
// The "Password protect by Talk" item is shown only when there
|
|
|
|
// is a password. Unfortunately there is no fine grained
|
|
|
|
// rendering of items in the link shares, so the whole view
|
|
|
|
// needs to be rendered again when the password of a share
|
|
|
|
// changes.
|
|
|
|
// Note that this event handler is concerned only about password
|
|
|
|
// changes; other changes in the link shares does not trigger
|
|
|
|
// a rendering, so the view must be rendered again as needed in
|
|
|
|
// those cases (for example, when a link share is removed).
|
|
|
|
|
|
|
|
var previousLinkShares = model.previous('linkShares');
|
|
|
|
if (previousLinkShares.length !== linkShares.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var i;
|
|
|
|
for (i = 0; i < linkShares.length; i++) {
|
|
|
|
if (linkShares[i].id !== previousLinkShares[i].id) {
|
|
|
|
// A resorting should never happen, but just in case.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linkShares[i].password !== previousLinkShares[i].password) {
|
|
|
|
view.render();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
if(!_.isUndefined(options.configModel)) {
|
|
|
|
this.configModel = options.configModel;
|
|
|
|
} else {
|
2015-08-25 00:20:01 +03:00
|
|
|
throw 'missing OC.Share.ShareConfigModel';
|
2015-08-21 16:40:50 +03:00
|
|
|
}
|
2015-09-12 15:21:14 +03:00
|
|
|
|
2018-10-31 12:28:18 +03:00
|
|
|
var clipboard = new Clipboard('.clipboard-button');
|
2016-07-08 15:30:32 +03:00
|
|
|
clipboard.on('success', function(e) {
|
2018-10-31 12:28:18 +03:00
|
|
|
var $trigger = $(e.trigger);
|
2018-07-19 11:04:37 +03:00
|
|
|
|
2018-10-31 12:28:18 +03:00
|
|
|
$trigger.tooltip('hide')
|
2016-11-16 17:36:44 +03:00
|
|
|
.attr('data-original-title', t('core', 'Copied!'))
|
|
|
|
.tooltip('fixTitle')
|
|
|
|
.tooltip({placement: 'bottom', trigger: 'manual'})
|
|
|
|
.tooltip('show');
|
2016-07-08 15:30:32 +03:00
|
|
|
_.delay(function() {
|
2018-10-31 12:28:18 +03:00
|
|
|
$trigger.tooltip('hide')
|
|
|
|
.attr('data-original-title', t('core', 'Copy link'))
|
|
|
|
.tooltip('fixTitle')
|
2016-07-08 15:30:32 +03:00
|
|
|
}, 3000);
|
|
|
|
});
|
|
|
|
clipboard.on('error', function (e) {
|
2018-10-31 12:28:18 +03:00
|
|
|
var $trigger = $(e.trigger);
|
|
|
|
var $menu = $trigger.next('.share-menu').find('.popovermenu');
|
|
|
|
var $linkTextMenu = $menu.find('li.linkTextMenu');
|
2018-07-19 11:04:37 +03:00
|
|
|
var $input = $linkTextMenu.find('.linkText');
|
|
|
|
|
2018-10-31 12:28:18 +03:00
|
|
|
var $li = $trigger.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
|
|
|
|
// show menu
|
|
|
|
OC.showMenu(null, $menu);
|
|
|
|
|
2016-07-08 15:30:32 +03:00
|
|
|
var actionMsg = '';
|
|
|
|
if (/iPhone|iPad/i.test(navigator.userAgent)) {
|
|
|
|
actionMsg = t('core', 'Not supported!');
|
|
|
|
} else if (/Mac/i.test(navigator.userAgent)) {
|
|
|
|
actionMsg = t('core', 'Press ⌘-C to copy.');
|
|
|
|
} else {
|
|
|
|
actionMsg = t('core', 'Press Ctrl-C to copy.');
|
|
|
|
}
|
|
|
|
|
2018-07-19 11:04:37 +03:00
|
|
|
$linkTextMenu.removeClass('hidden');
|
|
|
|
$input.select();
|
2016-11-16 17:36:44 +03:00
|
|
|
$input.tooltip('hide')
|
|
|
|
.attr('data-original-title', actionMsg)
|
|
|
|
.tooltip('fixTitle')
|
|
|
|
.tooltip({placement: 'bottom', trigger: 'manual'})
|
|
|
|
.tooltip('show');
|
2016-07-08 15:30:32 +03:00
|
|
|
_.delay(function () {
|
2017-03-03 15:36:20 +03:00
|
|
|
$input.tooltip('hide');
|
2018-07-19 11:04:37 +03:00
|
|
|
$input.attr('data-original-title', t('core', 'Copy'))
|
|
|
|
.tooltip('fixTitle');
|
2016-07-08 15:30:32 +03:00
|
|
|
}, 3000);
|
|
|
|
});
|
2015-09-12 15:21:14 +03:00
|
|
|
},
|
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
newShare: function(event) {
|
2018-10-29 15:58:14 +03:00
|
|
|
var self = this;
|
2018-10-31 13:43:05 +03:00
|
|
|
var $target = $(event.target);
|
|
|
|
var $li = $target.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
var $loading = $li.find('.share-menu > .icon-loading-small');
|
|
|
|
|
|
|
|
if(!$loading.hasClass('hidden') && this.password === '') {
|
2018-10-29 15:58:14 +03:00
|
|
|
// in process
|
2015-09-12 15:21:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-31 13:43:05 +03:00
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
// hide all icons and show loading
|
2018-10-31 13:43:05 +03:00
|
|
|
$li.find('.icon').addClass('hidden');
|
2018-10-29 15:58:14 +03:00
|
|
|
$loading.removeClass('hidden');
|
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
// hide menu
|
|
|
|
OC.hideMenus();
|
|
|
|
|
2018-10-31 13:22:47 +03:00
|
|
|
var shareData = {}
|
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
var isPasswordEnforced = this.configModel.get('enforcePasswordForPublicLink');
|
2018-10-31 13:22:47 +03:00
|
|
|
var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced');
|
2018-10-31 13:43:05 +03:00
|
|
|
|
|
|
|
// set default expire date
|
2018-10-31 13:22:47 +03:00
|
|
|
if (isExpirationEnforced) {
|
|
|
|
var defaultExpireDays = this.configModel.get('defaultExpireDate');
|
|
|
|
var expireDate = moment().add(defaultExpireDays, 'day').format('DD-MM-YYYY')
|
|
|
|
shareData.expireDate = expireDate;
|
|
|
|
}
|
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
// if password is set, add to data
|
|
|
|
if (isPasswordEnforced && this.password !== '') {
|
|
|
|
shareData.password = this.password
|
|
|
|
}
|
|
|
|
|
2018-11-01 16:55:32 +03:00
|
|
|
var newShareId = false;
|
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
// We need a password before the share creation
|
|
|
|
if (isPasswordEnforced && !this.showPending && this.password === '') {
|
|
|
|
this.showPending = shareId;
|
|
|
|
this.render();
|
|
|
|
$li.find('#enforcedPassText').focus();
|
|
|
|
} else {
|
|
|
|
// else, we have a password or it is not enforced
|
2018-11-01 16:55:32 +03:00
|
|
|
$.when(this.model.saveLinkShare(shareData, {
|
2018-10-31 13:43:05 +03:00
|
|
|
success: function() {
|
|
|
|
$loading.addClass('hidden');
|
|
|
|
$li.find('.icon').removeClass('hidden');
|
|
|
|
self.render();
|
2018-11-01 16:55:32 +03:00
|
|
|
// open the menu by default
|
|
|
|
// we can only do that after the render
|
|
|
|
if (newShareId) {
|
|
|
|
var shares = self.$el.find('li[data-share-id]');
|
|
|
|
var $newShare = self.$el.find('li[data-share-id="'+newShareId+'"]');
|
|
|
|
// only open the menu by default if this is the first share
|
|
|
|
if ($newShare && shares.length === 1) {
|
|
|
|
$menu = $newShare.find('.popovermenu');
|
|
|
|
OC.showMenu(null, $menu);
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 13:43:05 +03:00
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
OC.Notification.showTemporary(t('core', 'Unable to create a link share'));
|
|
|
|
$loading.addClass('hidden');
|
|
|
|
$li.find('.icon').removeClass('hidden');
|
|
|
|
}
|
2018-11-01 16:55:32 +03:00
|
|
|
})).then(function(response) {
|
|
|
|
// resolve before success
|
|
|
|
newShareId = response.ocs.data.id
|
|
|
|
});
|
2018-10-31 13:43:05 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
enforcedPasswordSet: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var $form = $(event.target);
|
|
|
|
var $input = $form.find('input.enforcedPassText');
|
|
|
|
this.password = $input.val();
|
|
|
|
this.showPending = false;
|
|
|
|
this.newShare(event);
|
2015-08-21 16:40:50 +03:00
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onLinkTextClick: function(event) {
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var $el = $li.find('.linkText');
|
2015-10-26 14:49:52 +03:00
|
|
|
$el.focus();
|
|
|
|
$el.select();
|
2015-09-12 16:53:05 +03:00
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onHideDownloadChange: function(event) {
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
var $checkbox = $li.find('.hideDownloadCheckbox');
|
2018-10-22 12:06:53 +03:00
|
|
|
$checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock');
|
|
|
|
|
|
|
|
var hideDownload = false;
|
|
|
|
if($checkbox.is(':checked')) {
|
|
|
|
hideDownload = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.model.saveLinkShare({
|
2018-10-29 15:58:14 +03:00
|
|
|
hideDownload: hideDownload,
|
|
|
|
cid: shareId
|
|
|
|
}, {
|
|
|
|
success: function() {
|
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock');
|
|
|
|
},
|
|
|
|
error: function(obj, msg) {
|
|
|
|
OC.Notification.showTemporary(t('core', 'Unable to toggle this option'));
|
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock');
|
|
|
|
}
|
2018-10-22 12:06:53 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onShowPasswordClick: function(event) {
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
$li.find('.linkPass').slideToggle(OC.menuSpeed);
|
|
|
|
$li.find('.linkPassMenu').toggleClass('hidden');
|
|
|
|
if(!$li.find('.showPasswordCheckbox').is(':checked')) {
|
2016-01-22 19:30:18 +03:00
|
|
|
this.model.saveLinkShare({
|
2018-10-29 15:58:14 +03:00
|
|
|
password: '',
|
|
|
|
cid: shareId
|
2016-01-22 19:30:18 +03:00
|
|
|
});
|
2015-09-12 18:02:03 +03:00
|
|
|
} else {
|
2017-02-15 15:50:53 +03:00
|
|
|
if (!OC.Util.isIE()) {
|
2018-10-29 15:58:14 +03:00
|
|
|
$li.find('.linkPassText').focus();
|
2017-02-15 15:50:53 +03:00
|
|
|
}
|
2015-10-16 11:54:45 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onPasswordKeyUp: function(event) {
|
2016-08-19 22:03:25 +03:00
|
|
|
if(event.keyCode === 13) {
|
2018-10-29 15:58:14 +03:00
|
|
|
this.onPasswordEntered(event);
|
2015-09-12 18:02:03 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onPasswordEntered: function(event) {
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
var $loading = $li.find('.linkPassMenu .icon-loading-small');
|
2015-09-29 16:30:01 +03:00
|
|
|
if (!$loading.hasClass('hidden')) {
|
|
|
|
// still in process
|
|
|
|
return;
|
|
|
|
}
|
2018-10-29 15:58:14 +03:00
|
|
|
var $input = $li.find('.linkPassText');
|
2015-09-29 16:30:01 +03:00
|
|
|
$input.removeClass('error');
|
|
|
|
var password = $input.val();
|
2016-10-17 15:23:55 +03:00
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
if ($li.find('.linkPassText').attr('placeholder') === PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL) {
|
2016-10-17 15:23:55 +03:00
|
|
|
|
|
|
|
// in IE9 the password might be the placeholder due to bugs in the placeholders polyfill
|
|
|
|
if(password === PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL) {
|
|
|
|
password = '';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// in IE9 the password might be the placeholder due to bugs in the placeholders polyfill
|
|
|
|
if(password === '' || password === PASSWORD_PLACEHOLDER || password === PASSWORD_PLACEHOLDER_MESSAGE) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-12 18:02:03 +03:00
|
|
|
}
|
|
|
|
|
2015-09-29 16:30:01 +03:00
|
|
|
$loading
|
2015-09-12 18:02:03 +03:00
|
|
|
.removeClass('hidden')
|
|
|
|
.addClass('inlineblock');
|
|
|
|
|
2016-01-22 19:30:18 +03:00
|
|
|
this.model.saveLinkShare({
|
2018-10-29 15:58:14 +03:00
|
|
|
password: password,
|
|
|
|
cid: shareId
|
2016-01-22 19:30:18 +03:00
|
|
|
}, {
|
2017-04-24 23:18:52 +03:00
|
|
|
complete: function(model) {
|
2017-04-23 19:54:33 +03:00
|
|
|
$loading.removeClass('inlineblock').addClass('hidden');
|
|
|
|
},
|
2015-09-29 16:30:01 +03:00
|
|
|
error: function(model, msg) {
|
2016-03-04 20:11:42 +03:00
|
|
|
// destroy old tooltips
|
|
|
|
$input.tooltip('destroy');
|
2015-09-29 16:30:01 +03:00
|
|
|
$input.addClass('error');
|
|
|
|
$input.attr('title', msg);
|
|
|
|
$input.tooltip({placement: 'bottom', trigger: 'manual'});
|
|
|
|
$input.tooltip('show');
|
|
|
|
}
|
|
|
|
});
|
2015-09-12 18:02:03 +03:00
|
|
|
},
|
|
|
|
|
2018-10-15 18:09:46 +03:00
|
|
|
onPasswordByTalkChange: function(event) {
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
var $checkbox = $li.find('.passwordByTalkCheckbox');
|
|
|
|
$checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock');
|
|
|
|
|
|
|
|
var sendPasswordByTalk = false;
|
|
|
|
if($checkbox.is(':checked')) {
|
|
|
|
sendPasswordByTalk = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.model.saveLinkShare({
|
|
|
|
sendPasswordByTalk: sendPasswordByTalk,
|
|
|
|
cid: shareId
|
|
|
|
}, {
|
|
|
|
success: function() {
|
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock');
|
|
|
|
},
|
|
|
|
error: function(obj, msg) {
|
|
|
|
OC.Notification.showTemporary(t('core', 'Unable to toggle this option'));
|
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onAllowPublicEditingChange: function(event) {
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
var $checkbox = $li.find('.publicEditingCheckbox');
|
2017-01-24 15:24:46 +03:00
|
|
|
$checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock');
|
|
|
|
|
|
|
|
var permissions = OC.PERMISSION_READ;
|
|
|
|
if($checkbox.is(':checked')) {
|
|
|
|
permissions = OC.PERMISSION_UPDATE | OC.PERMISSION_READ;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.model.saveLinkShare({
|
2018-10-29 15:58:14 +03:00
|
|
|
permissions: permissions,
|
|
|
|
cid: shareId
|
|
|
|
}, {
|
|
|
|
success: function() {
|
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock');
|
|
|
|
},
|
|
|
|
error: function(obj, msg) {
|
|
|
|
OC.Notification.showTemporary(t('core', 'Unable to toggle this option'));
|
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock');
|
|
|
|
}
|
2017-01-24 15:24:46 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-06-07 13:28:02 +03:00
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onPublicUploadChange: function(event) {
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
var permissions = event.currentTarget.value;
|
2016-06-09 19:17:04 +03:00
|
|
|
this.model.saveLinkShare({
|
2018-10-29 15:58:14 +03:00
|
|
|
permissions: permissions,
|
|
|
|
cid: shareId
|
2016-06-09 19:17:04 +03:00
|
|
|
});
|
|
|
|
},
|
2018-10-01 12:02:12 +03:00
|
|
|
|
2018-07-20 10:39:52 +03:00
|
|
|
showNoteForm: function(event) {
|
2018-07-19 11:04:37 +03:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
var self = this;
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var $menu = $element.closest('li');
|
|
|
|
var $form = $menu.next('li.share-note-form');
|
|
|
|
|
|
|
|
// show elements
|
2018-10-31 12:49:06 +03:00
|
|
|
$menu.find('.share-note-delete').toggleClass('hidden');
|
2018-07-19 11:04:37 +03:00
|
|
|
$form.toggleClass('hidden');
|
2018-07-19 21:05:37 +03:00
|
|
|
$form.find('textarea').focus();
|
2018-07-19 11:04:37 +03:00
|
|
|
},
|
|
|
|
|
2018-07-20 10:39:52 +03:00
|
|
|
deleteNote: function(event) {
|
2018-07-19 11:04:37 +03:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
var self = this;
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
var $menu = $element.closest('li');
|
|
|
|
var $form = $menu.next('li.share-note-form');
|
2018-10-01 12:02:12 +03:00
|
|
|
|
2018-07-19 11:04:37 +03:00
|
|
|
$form.find('.share-note').val('');
|
2018-10-01 12:02:12 +03:00
|
|
|
|
2018-07-19 11:04:37 +03:00
|
|
|
$form.addClass('hidden');
|
2018-10-31 12:49:06 +03:00
|
|
|
$menu.find('.share-note-delete').addClass('hidden');
|
2018-07-19 11:04:37 +03:00
|
|
|
|
|
|
|
self.sendNote('', shareId, $menu);
|
|
|
|
},
|
|
|
|
|
2018-07-20 10:39:52 +03:00
|
|
|
updateNote: function(event) {
|
2018-07-19 11:04:37 +03:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
var self = this;
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
var $form = $element.closest('li.share-note-form');
|
|
|
|
var $menu = $form.prev('li');
|
|
|
|
var message = $form.find('.share-note').val().trim();
|
|
|
|
|
|
|
|
if (message.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.sendNote(message, shareId, $menu);
|
|
|
|
},
|
|
|
|
|
2018-07-20 10:39:52 +03:00
|
|
|
sendNote: function(note, shareId, $menu) {
|
2018-07-19 11:04:37 +03:00
|
|
|
var $form = $menu.next('li.share-note-form');
|
|
|
|
var $submit = $form.find('input.share-note-submit');
|
|
|
|
var $error = $form.find('input.share-note-error');
|
|
|
|
|
|
|
|
$submit.prop('disabled', true);
|
|
|
|
$menu.find('.icon-loading-small').removeClass('hidden');
|
|
|
|
$menu.find('.icon-edit').hide();
|
|
|
|
|
|
|
|
var complete = function() {
|
|
|
|
$submit.prop('disabled', false);
|
|
|
|
$menu.find('.icon-loading-small').addClass('hidden');
|
|
|
|
$menu.find('.icon-edit').show();
|
|
|
|
};
|
|
|
|
var error = function() {
|
|
|
|
$error.show();
|
|
|
|
setTimeout(function() {
|
|
|
|
$error.hide();
|
|
|
|
}, 3000);
|
|
|
|
};
|
|
|
|
|
|
|
|
// send data
|
|
|
|
$.ajax({
|
|
|
|
method: 'PUT',
|
|
|
|
url: OC.linkToOCS('apps/files_sharing/api/v1/shares',2) + shareId + '?' + OC.buildQueryString({format: 'json'}),
|
|
|
|
data: { note: note },
|
|
|
|
complete : complete,
|
|
|
|
error: error
|
|
|
|
});
|
|
|
|
},
|
2015-09-14 02:01:02 +03:00
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
render: function() {
|
2018-10-31 12:28:18 +03:00
|
|
|
this.$el.find('.has-tooltip').tooltip();
|
2018-10-31 13:43:05 +03:00
|
|
|
|
|
|
|
// reset previously set passwords
|
|
|
|
this.password = '';
|
2018-11-01 04:36:05 +03:00
|
|
|
|
2015-08-21 21:29:12 +03:00
|
|
|
var linkShareTemplate = this.template();
|
2015-12-07 18:53:56 +03:00
|
|
|
var resharingAllowed = this.model.sharePermissionPossible();
|
2015-08-21 21:29:12 +03:00
|
|
|
|
2015-12-07 18:53:56 +03:00
|
|
|
if(!resharingAllowed
|
2015-08-21 16:40:50 +03:00
|
|
|
|| !this.showLink
|
|
|
|
|| !this.configModel.isShareWithLinkAllowed())
|
|
|
|
{
|
2015-12-07 18:53:56 +03:00
|
|
|
var templateData = {shareAllowed: false};
|
|
|
|
if (!resharingAllowed) {
|
|
|
|
// add message
|
|
|
|
templateData.noSharingPlaceholder = t('core', 'Resharing is not allowed');
|
|
|
|
}
|
|
|
|
this.$el.html(linkShareTemplate(templateData));
|
2015-08-21 16:40:50 +03:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
var publicUpload =
|
|
|
|
this.model.isFolder()
|
2015-09-01 13:43:04 +03:00
|
|
|
&& this.model.createPermissionPossible()
|
2015-08-21 16:40:50 +03:00
|
|
|
&& this.configModel.isPublicUploadEnabled();
|
|
|
|
|
|
|
|
|
2017-01-24 15:24:46 +03:00
|
|
|
var publicEditingChecked = '';
|
|
|
|
if(this.model.isPublicEditingAllowed()) {
|
|
|
|
publicEditingChecked = 'checked="checked"';
|
|
|
|
}
|
|
|
|
|
2018-10-19 12:23:33 +03:00
|
|
|
var isPasswordEnforced = this.configModel.get('enforcePasswordForPublicLink');
|
|
|
|
var isPasswordEnabledByDefault = this.configModel.get('enableLinkPasswordByDefault') === true;
|
2016-10-17 15:23:55 +03:00
|
|
|
var passwordPlaceholderInitial = this.configModel.get('enforcePasswordForPublicLink')
|
|
|
|
? PASSWORD_PLACEHOLDER_MESSAGE : PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL;
|
2015-09-03 16:53:17 +03:00
|
|
|
|
2017-01-24 15:24:46 +03:00
|
|
|
var publicEditable =
|
|
|
|
!this.model.isFolder()
|
|
|
|
&& this.model.updatePermissionPossible();
|
|
|
|
|
2017-03-03 15:27:06 +03:00
|
|
|
var social = [];
|
|
|
|
OC.Share.Social.Collection.each(function(model) {
|
|
|
|
var url = model.get('url');
|
|
|
|
url = url.replace('{{reference}}', link);
|
|
|
|
|
|
|
|
social.push({
|
|
|
|
url: url,
|
|
|
|
label: t('core', 'Share to {name}', {name: model.get('name')}),
|
|
|
|
name: model.get('name'),
|
2017-04-20 17:32:46 +03:00
|
|
|
iconClass: model.get('iconClass'),
|
|
|
|
newWindow: model.get('newWindow')
|
2017-03-03 15:27:06 +03:00
|
|
|
});
|
|
|
|
});
|
2018-07-19 11:04:37 +03:00
|
|
|
var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced');
|
2018-11-01 04:36:05 +03:00
|
|
|
|
2018-07-19 21:05:37 +03:00
|
|
|
// what if there is another date picker on that page?
|
|
|
|
var minDate = new Date();
|
|
|
|
// min date should always be the next day
|
|
|
|
minDate.setDate(minDate.getDate()+1);
|
|
|
|
|
|
|
|
$.datepicker.setDefaults({
|
2018-10-29 15:58:14 +03:00
|
|
|
minDate: minDate
|
2018-07-19 21:05:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'});
|
|
|
|
|
2018-11-01 16:55:32 +03:00
|
|
|
var minPasswordLength = 4
|
|
|
|
// password policy?
|
|
|
|
if(oc_capabilities.password_policy && oc_capabilities.password_policy.minLength) {
|
|
|
|
minPasswordLength = oc_capabilities.password_policy.minLength;
|
|
|
|
}
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
var popoverBase = {
|
2018-07-19 11:04:37 +03:00
|
|
|
social: social,
|
2015-08-21 16:40:50 +03:00
|
|
|
urlLabel: t('core', 'Link'),
|
2018-10-22 12:06:53 +03:00
|
|
|
hideDownloadLabel: t('core', 'Hide download'),
|
2018-10-31 13:43:05 +03:00
|
|
|
enablePasswordLabel: isPasswordEnforced ? t('core', 'Password protection enforced') : t('core', 'Password protect'),
|
2015-08-21 16:40:50 +03:00
|
|
|
passwordLabel: t('core', 'Password'),
|
2016-10-17 15:23:55 +03:00
|
|
|
passwordPlaceholderInitial: passwordPlaceholderInitial,
|
2018-10-29 15:58:14 +03:00
|
|
|
publicUpload: publicUpload,
|
2017-01-24 15:24:46 +03:00
|
|
|
publicEditing: publicEditable,
|
|
|
|
publicEditingChecked: publicEditingChecked,
|
|
|
|
publicEditingLabel: t('core', 'Allow editing'),
|
2015-08-21 16:40:50 +03:00
|
|
|
mailPrivatePlaceholder: t('core', 'Email link to person'),
|
2017-03-03 15:27:06 +03:00
|
|
|
mailButtonText: t('core', 'Send'),
|
2017-03-09 15:56:27 +03:00
|
|
|
publicUploadRWLabel: t('core', 'Allow upload and editing'),
|
|
|
|
publicUploadRLabel: t('core', 'Read only'),
|
2017-05-18 17:53:10 +03:00
|
|
|
publicUploadWLabel: t('core', 'File drop (upload only)'),
|
2017-03-09 15:56:27 +03:00
|
|
|
publicUploadRWValue: OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_READ | OC.PERMISSION_DELETE,
|
|
|
|
publicUploadRValue: OC.PERMISSION_READ,
|
|
|
|
publicUploadWValue: OC.PERMISSION_CREATE,
|
2018-10-31 13:22:47 +03:00
|
|
|
expireDateLabel: isExpirationEnforced ? t('core', 'Expiration date enforced') : t('core', 'Set expiration date'),
|
2018-07-19 11:04:37 +03:00
|
|
|
expirationLabel: t('core', 'Expiration'),
|
|
|
|
expirationDatePlaceholder: t('core', 'Expiration date'),
|
|
|
|
isExpirationEnforced: isExpirationEnforced,
|
2018-08-16 08:31:17 +03:00
|
|
|
isPasswordEnforced: isPasswordEnforced,
|
2018-07-19 11:04:37 +03:00
|
|
|
defaultExpireDate: moment().add(1, 'day').format('DD-MM-YYYY'), // Can't expire today
|
2018-07-31 15:20:09 +03:00
|
|
|
addNoteLabel: t('core', 'Note to recipient'),
|
2018-10-29 15:58:14 +03:00
|
|
|
unshareLabel: t('core', 'Unshare'),
|
2018-11-01 04:36:05 +03:00
|
|
|
unshareLinkLabel: t('core', 'Delete share link'),
|
|
|
|
newShareLabel: t('core', 'Add another link'),
|
2018-10-29 15:58:14 +03:00
|
|
|
};
|
2015-08-21 16:40:50 +03:00
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
var pendingPopover = {
|
2018-08-15 12:50:48 +03:00
|
|
|
isPasswordEnforced: isPasswordEnforced,
|
2018-10-31 13:43:05 +03:00
|
|
|
enforcedPasswordLabel: t('core', 'Password protection for links is mandatory'),
|
|
|
|
passwordPlaceholder: passwordPlaceholderInitial,
|
2018-11-01 16:55:32 +03:00
|
|
|
minPasswordLength: minPasswordLength,
|
2018-10-29 15:58:14 +03:00
|
|
|
};
|
2018-10-31 13:43:05 +03:00
|
|
|
var pendingPopoverMenu = this.pendingPopoverMenuTemplate(_.extend({}, pendingPopover))
|
2018-10-29 15:58:14 +03:00
|
|
|
|
|
|
|
var linkShares = this.getShareeList();
|
|
|
|
if(_.isArray(linkShares)) {
|
|
|
|
for (var i = 0; i < linkShares.length; i++) {
|
|
|
|
var popover = this.getPopoverObject(linkShares[i])
|
|
|
|
linkShares[i].popoverMenu = this.popoverMenuTemplate(_.extend({}, popoverBase, popover));
|
2018-10-31 13:43:05 +03:00
|
|
|
linkShares[i].pendingPopoverMenu = pendingPopoverMenu
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
|
|
|
}
|
2018-08-15 12:50:48 +03:00
|
|
|
|
2018-07-19 11:04:37 +03:00
|
|
|
this.$el.html(linkShareTemplate({
|
2018-10-29 15:58:14 +03:00
|
|
|
linkShares: linkShares,
|
2018-07-19 11:04:37 +03:00
|
|
|
shareAllowed: true,
|
2018-10-29 15:58:14 +03:00
|
|
|
nolinkShares: linkShares.length === 0,
|
|
|
|
newShareLabel: t('core', 'Share link'),
|
2018-10-31 13:43:05 +03:00
|
|
|
newShareTitle: t('core', 'New share link'),
|
|
|
|
pendingPopoverMenu: pendingPopoverMenu,
|
|
|
|
showPending: this.showPending === 'new',
|
2018-07-19 11:04:37 +03:00
|
|
|
}));
|
2017-03-03 15:36:20 +03:00
|
|
|
|
2015-09-14 19:24:58 +03:00
|
|
|
this.delegateEvents();
|
|
|
|
|
2018-07-19 21:05:37 +03:00
|
|
|
// new note autosize
|
|
|
|
autosize(this.$el.find('.share-note-form .share-note'));
|
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-03-03 15:27:06 +03:00
|
|
|
onToggleMenu: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
var $element = $(event.target);
|
2018-07-19 11:04:37 +03:00
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var $menu = $li.find('.sharingOptionsGroup .popovermenu');
|
2018-10-29 15:58:14 +03:00
|
|
|
var shareId = $li.data('share-id');
|
2017-03-03 15:27:06 +03:00
|
|
|
|
|
|
|
OC.showMenu(null, $menu);
|
2018-10-31 13:43:05 +03:00
|
|
|
|
|
|
|
// focus the password if not set and enforced
|
|
|
|
var isPasswordEnabledByDefault = this.configModel.get('enableLinkPasswordByDefault') === true;
|
|
|
|
var haspassword = $menu.find('.linkPassText').val() !== '';
|
|
|
|
|
|
|
|
if (!haspassword && isPasswordEnabledByDefault) {
|
|
|
|
$menu.find('.linkPassText').focus();
|
|
|
|
}
|
2017-03-03 15:27:06 +03:00
|
|
|
},
|
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
/**
|
|
|
|
* @returns {Function} from Handlebars
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
template: function () {
|
2018-10-01 21:46:29 +03:00
|
|
|
return OC.Share.Templates['sharedialoglinkshareview'];
|
2017-03-03 15:27:06 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* renders the popover template and returns the resulting HTML
|
|
|
|
*
|
|
|
|
* @param {Object} data
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
popoverMenuTemplate: function(data) {
|
2018-10-01 21:46:29 +03:00
|
|
|
return OC.Share.Templates['sharedialoglinkshareview_popover_menu'](data);
|
2017-03-03 15:27:06 +03:00
|
|
|
},
|
|
|
|
|
2018-08-15 12:50:48 +03:00
|
|
|
/**
|
|
|
|
* renders the pending popover template and returns the resulting HTML
|
|
|
|
*
|
|
|
|
* @param {Object} data
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
pendingPopoverMenuTemplate: function(data) {
|
2018-10-01 21:46:29 +03:00
|
|
|
return OC.Share.Templates['sharedialoglinkshareview_popover_menu_pending'](data);
|
2018-08-15 12:50:48 +03:00
|
|
|
},
|
|
|
|
|
2017-03-03 15:27:06 +03:00
|
|
|
onPopUpClick: function(event) {
|
2017-03-15 07:50:32 +03:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
var url = $(event.currentTarget).data('url');
|
2017-04-20 17:32:46 +03:00
|
|
|
var newWindow = $(event.currentTarget).data('window');
|
2017-03-15 07:50:32 +03:00
|
|
|
$(event.currentTarget).tooltip('hide');
|
2017-03-03 15:27:06 +03:00
|
|
|
if (url) {
|
2017-04-20 17:32:46 +03:00
|
|
|
if (newWindow === true) {
|
|
|
|
var width = 600;
|
|
|
|
var height = 400;
|
|
|
|
var left = (screen.width / 2) - (width / 2);
|
|
|
|
var top = (screen.height / 2) - (height / 2);
|
2017-03-03 15:27:06 +03:00
|
|
|
|
2017-04-20 17:32:46 +03:00
|
|
|
window.open(url, 'name', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left);
|
|
|
|
} else {
|
|
|
|
window.location.href = url;
|
|
|
|
}
|
2017-03-03 15:27:06 +03:00
|
|
|
}
|
2018-07-19 11:04:37 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onExpireDateChange: function(event) {
|
|
|
|
var $element = $(event.target);
|
2018-07-19 21:05:37 +03:00
|
|
|
var li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = li.data('share-id');
|
|
|
|
var expirationDatePicker = '#expirationDateContainer-' + shareId;
|
|
|
|
var datePicker = $(expirationDatePicker);
|
2018-07-19 11:04:37 +03:00
|
|
|
var state = $element.prop('checked');
|
|
|
|
datePicker.toggleClass('hidden', !state);
|
2018-10-01 12:02:12 +03:00
|
|
|
|
2018-07-19 11:04:37 +03:00
|
|
|
if (!state) {
|
|
|
|
// disabled, let's hide the input and
|
|
|
|
// set the expireDate to nothing
|
|
|
|
$element.closest('li').next('li').addClass('hidden');
|
|
|
|
this.setExpirationDate('');
|
|
|
|
} else {
|
|
|
|
// enabled, show the input and the datepicker
|
|
|
|
$element.closest('li').next('li').removeClass('hidden');
|
|
|
|
this.showDatePicker(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showDatePicker: function(event) {
|
2018-07-19 21:05:37 +03:00
|
|
|
var $element = $(event.target);
|
|
|
|
var li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = li.data('share-id');
|
2018-10-29 15:58:14 +03:00
|
|
|
var maxDate = $element.data('max-date');
|
2018-07-19 21:05:37 +03:00
|
|
|
var expirationDatePicker = '#expirationDatePicker-' + shareId;
|
2018-07-19 11:04:37 +03:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$(expirationDatePicker).datepicker({
|
|
|
|
dateFormat : 'dd-mm-yy',
|
|
|
|
onSelect: function (expireDate) {
|
2018-10-29 15:58:14 +03:00
|
|
|
self.setExpirationDate(expireDate, shareId);
|
|
|
|
},
|
|
|
|
maxDate: maxDate
|
2018-07-19 11:04:37 +03:00
|
|
|
});
|
2018-07-19 21:05:37 +03:00
|
|
|
$(expirationDatePicker).datepicker('show');
|
2018-07-19 11:04:37 +03:00
|
|
|
$(expirationDatePicker).focus();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
setExpirationDate: function(expireDate, shareId) {
|
|
|
|
this.model.saveLinkShare({expireDate: expireDate, cid: shareId});
|
2018-07-19 11:04:37 +03:00
|
|
|
},
|
2015-08-21 16:40:50 +03:00
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
/**
|
|
|
|
* get an array of sharees' share properties
|
|
|
|
*
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
getShareeList: function() {
|
|
|
|
var shares = this.model.get('linkShares');
|
|
|
|
|
|
|
|
if(!this.model.hasLinkShares()) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
var list = [];
|
|
|
|
for(var index = 0; index < shares.length; index++) {
|
|
|
|
var share = this.getShareeObject(index);
|
|
|
|
// first empty {} is necessary, otherwise we get in trouble
|
|
|
|
// with references
|
|
|
|
list.push(_.extend({}, share));
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {OC.Share.Types.ShareInfo} shareInfo
|
|
|
|
* @returns {object}
|
|
|
|
*/
|
|
|
|
getShareeObject: function(shareIndex) {
|
|
|
|
var share = this.model.get('linkShares')[shareIndex];
|
|
|
|
|
|
|
|
return _.extend({}, share, {
|
|
|
|
cid: share.id,
|
|
|
|
shareAllowed: true,
|
|
|
|
linkShareLabel: share.label !== '' ? share.label : t('core', 'Share link'),
|
|
|
|
popoverMenu: {},
|
2018-10-31 12:28:18 +03:00
|
|
|
shareLinkURL: share.url,
|
|
|
|
newShareTitle: t('core', 'New share link'),
|
|
|
|
copyLabel: t('core', 'Copy link'),
|
2018-10-31 13:43:05 +03:00
|
|
|
showPending: this.showPending === share.id,
|
2018-10-29 15:58:14 +03:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
getPopoverObject: function(share) {
|
|
|
|
var publicUploadRWChecked = '';
|
|
|
|
var publicUploadRChecked = '';
|
|
|
|
var publicUploadWChecked = '';
|
|
|
|
|
|
|
|
switch (this.model.linkSharePermissions(share.id)) {
|
|
|
|
case OC.PERMISSION_READ:
|
|
|
|
publicUploadRChecked = 'checked';
|
|
|
|
break;
|
|
|
|
case OC.PERMISSION_CREATE:
|
|
|
|
publicUploadWChecked = 'checked';
|
|
|
|
break;
|
|
|
|
case OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_READ | OC.PERMISSION_DELETE:
|
|
|
|
publicUploadRWChecked = 'checked';
|
|
|
|
break;
|
|
|
|
}
|
2018-11-01 04:36:05 +03:00
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
var isPasswordSet = !!share.password;
|
|
|
|
var isPasswordEnabledByDefault = this.configModel.get('enableLinkPasswordByDefault') === true;
|
|
|
|
var isPasswordEnforced = this.configModel.get('enforcePasswordForPublicLink');
|
2018-10-31 13:43:05 +03:00
|
|
|
var showPasswordCheckBox = !isPasswordEnforced || !share.password;
|
2018-10-29 15:58:14 +03:00
|
|
|
var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced');
|
|
|
|
var defaultExpireDays = this.configModel.get('defaultExpireDate');
|
|
|
|
var hasExpireDate = !!share.expiration || isExpirationEnforced;
|
|
|
|
|
|
|
|
var expireDate;
|
|
|
|
if (hasExpireDate) {
|
|
|
|
expireDate = moment(share.expiration, 'YYYY-MM-DD').format('DD-MM-YYYY');
|
|
|
|
}
|
|
|
|
|
2018-10-15 18:09:46 +03:00
|
|
|
var isTalkEnabled = oc_appswebroots['spreed'] !== undefined;
|
|
|
|
var sendPasswordByTalk = share.sendPasswordByTalk;
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
var showHideDownloadCheckbox = !this.model.isFolder();
|
|
|
|
var hideDownload = share.hideDownload;
|
|
|
|
|
|
|
|
var maxDate = null;
|
|
|
|
|
|
|
|
if(hasExpireDate) {
|
|
|
|
if(isExpirationEnforced) {
|
|
|
|
// TODO: hack: backend returns string instead of integer
|
|
|
|
var shareTime = share.stime;
|
|
|
|
if (_.isNumber(shareTime)) {
|
|
|
|
shareTime = new Date(shareTime * 1000);
|
|
|
|
}
|
|
|
|
if (!shareTime) {
|
|
|
|
shareTime = new Date(); // now
|
|
|
|
}
|
|
|
|
shareTime = OC.Util.stripTime(shareTime).getTime();
|
|
|
|
maxDate = new Date(shareTime + defaultExpireDays * 24 * 3600 * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
cid: share.id,
|
|
|
|
shareLinkURL: share.url,
|
|
|
|
passwordPlaceholder: isPasswordSet ? PASSWORD_PLACEHOLDER : PASSWORD_PLACEHOLDER_MESSAGE,
|
|
|
|
isPasswordSet: isPasswordSet || isPasswordEnabledByDefault || isPasswordEnforced,
|
|
|
|
showPasswordCheckBox: showPasswordCheckBox,
|
2018-10-15 18:09:46 +03:00
|
|
|
showPasswordByTalkCheckBox: isTalkEnabled && isPasswordSet,
|
|
|
|
passwordByTalkLabel: t('core', 'Password protect by Talk'),
|
|
|
|
isPasswordByTalkSet: sendPasswordByTalk,
|
2018-10-29 15:58:14 +03:00
|
|
|
publicUploadRWChecked: publicUploadRWChecked,
|
|
|
|
publicUploadRChecked: publicUploadRChecked,
|
|
|
|
publicUploadWChecked: publicUploadWChecked,
|
|
|
|
hasExpireDate: hasExpireDate,
|
|
|
|
expireDate: expireDate,
|
|
|
|
shareNote: share.note,
|
|
|
|
hasNote: share.note !== '',
|
|
|
|
maxDate: maxDate,
|
|
|
|
showHideDownloadCheckbox: showHideDownloadCheckbox,
|
|
|
|
hideDownload: hideDownload,
|
2018-10-31 13:22:47 +03:00
|
|
|
isExpirationEnforced: isExpirationEnforced,
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onUnshare: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
var self = this;
|
|
|
|
var $element = $(event.target);
|
|
|
|
if (!$element.is('a')) {
|
|
|
|
$element = $element.closest('a');
|
|
|
|
}
|
|
|
|
|
|
|
|
var $loading = $element.find('.icon-loading-small').eq(0);
|
|
|
|
if(!$loading.hasClass('hidden')) {
|
|
|
|
// in process
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$loading.removeClass('hidden');
|
|
|
|
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
|
|
|
|
self.model.removeShare(shareId, {
|
|
|
|
success: function() {
|
|
|
|
$li.remove();
|
|
|
|
self.render()
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
$loading.addClass('hidden');
|
|
|
|
OC.Notification.showTemporary(t('core', 'Could not unshare'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
OC.Share.ShareDialogLinkShareView = ShareDialogLinkShareView;
|
|
|
|
|
|
|
|
})();
|