2015-08-21 13:40:50 +00: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 19:03:25 +00:00
|
|
|
/* globals Clipboard, Handlebars */
|
|
|
|
|
2015-08-21 13:40:50 +00:00
|
|
|
(function() {
|
|
|
|
if (!OC.Share) {
|
|
|
|
OC.Share = {};
|
|
|
|
}
|
|
|
|
|
2015-10-16 09:55:23 +00:00
|
|
|
var PASSWORD_PLACEHOLDER = '**********';
|
|
|
|
var PASSWORD_PLACEHOLDER_MESSAGE = t('core', 'Choose a password for the public link');
|
2017-06-12 14:30:08 +00:00
|
|
|
var PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL = t('core', 'Choose a password for the public link or press the "Enter" key');
|
2015-10-16 09:55:23 +00:00
|
|
|
|
2015-08-21 13:40:50 +00: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 09:50:48 +00:00
|
|
|
/** @type {boolean} **/
|
|
|
|
showPending: false,
|
|
|
|
|
2018-10-31 10:43:05 +00:00
|
|
|
/** @type {string} **/
|
|
|
|
password: '',
|
|
|
|
|
2018-11-05 09:46:13 +00:00
|
|
|
/** @type {string} **/
|
|
|
|
newShareId: 'new-share',
|
|
|
|
|
2015-09-14 16:24:58 +00:00
|
|
|
events: {
|
2018-08-15 09:50:48 +00:00
|
|
|
// open menu
|
|
|
|
'click .share-menu .icon-more': 'onToggleMenu',
|
2018-10-22 09:06:53 +00:00
|
|
|
// hide download
|
|
|
|
'change .hideDownloadCheckbox': 'onHideDownloadChange',
|
2018-08-15 09:50:48 +00:00
|
|
|
// password
|
2018-11-16 15:19:13 +00:00
|
|
|
'click input.share-pass-submit': 'onPasswordEntered',
|
|
|
|
'keyup input.linkPassText': 'onPasswordKeyUp', // check for the enter key
|
2018-08-16 05:31:17 +00:00
|
|
|
'change .showPasswordCheckbox': 'onShowPasswordClick',
|
2018-10-15 15:09:46 +00:00
|
|
|
'change .passwordByTalkCheckbox': 'onPasswordByTalkChange',
|
2018-08-15 09:50:48 +00:00
|
|
|
'change .publicEditingCheckbox': 'onAllowPublicEditingChange',
|
|
|
|
// copy link url
|
|
|
|
'click .linkText': 'onLinkTextClick',
|
|
|
|
// social
|
2017-03-09 12:56:27 +00:00
|
|
|
'click .pop-up': 'onPopUpClick',
|
2018-08-15 09:50:48 +00:00
|
|
|
// permission change
|
2018-07-19 08:04:37 +00:00
|
|
|
'change .publicUploadRadio': 'onPublicUploadChange',
|
2018-08-15 09:50:48 +00:00
|
|
|
// expire date
|
2018-07-19 08:04:37 +00:00
|
|
|
'click .expireDate' : 'onExpireDateChange',
|
|
|
|
'change .datepicker': 'onChangeExpirationDate',
|
|
|
|
'click .datepicker' : 'showDatePicker',
|
2018-08-15 09:50:48 +00:00
|
|
|
// note
|
2018-07-19 08:04:37 +00:00
|
|
|
'click .share-add': 'showNoteForm',
|
|
|
|
'click .share-note-delete': 'deleteNote',
|
2018-10-29 12:58:14 +00:00
|
|
|
'click .share-note-submit': 'updateNote',
|
|
|
|
// remove
|
|
|
|
'click .unshare': 'onUnshare',
|
|
|
|
// new share
|
|
|
|
'click .new-share': 'newShare',
|
2018-10-31 10:43:05 +00:00
|
|
|
// enforced pass set
|
|
|
|
'submit .enforcedPassForm': 'enforcedPasswordSet',
|
2015-09-14 16:24:58 +00:00
|
|
|
},
|
|
|
|
|
2015-08-21 13:40:50 +00: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 10:28:02 +00:00
|
|
|
this.model.on('change:hideFileListStatus', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
|
|
|
|
2018-10-15 15:09:46 +00: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 13:40:50 +00:00
|
|
|
if(!_.isUndefined(options.configModel)) {
|
|
|
|
this.configModel = options.configModel;
|
|
|
|
} else {
|
2015-08-24 21:20:01 +00:00
|
|
|
throw 'missing OC.Share.ShareConfigModel';
|
2015-08-21 13:40:50 +00:00
|
|
|
}
|
2015-09-12 12:21:14 +00:00
|
|
|
|
2018-10-31 09:28:18 +00:00
|
|
|
var clipboard = new Clipboard('.clipboard-button');
|
2016-07-08 12:30:32 +00:00
|
|
|
clipboard.on('success', function(e) {
|
2018-10-31 09:28:18 +00:00
|
|
|
var $trigger = $(e.trigger);
|
2018-07-19 08:04:37 +00:00
|
|
|
|
2018-10-31 09:28:18 +00:00
|
|
|
$trigger.tooltip('hide')
|
2016-11-16 14:36:44 +00:00
|
|
|
.attr('data-original-title', t('core', 'Copied!'))
|
|
|
|
.tooltip('fixTitle')
|
|
|
|
.tooltip({placement: 'bottom', trigger: 'manual'})
|
|
|
|
.tooltip('show');
|
2016-07-08 12:30:32 +00:00
|
|
|
_.delay(function() {
|
2018-10-31 09:28:18 +00:00
|
|
|
$trigger.tooltip('hide')
|
|
|
|
.attr('data-original-title', t('core', 'Copy link'))
|
|
|
|
.tooltip('fixTitle')
|
2016-07-08 12:30:32 +00:00
|
|
|
}, 3000);
|
|
|
|
});
|
|
|
|
clipboard.on('error', function (e) {
|
2018-10-31 09:28:18 +00:00
|
|
|
var $trigger = $(e.trigger);
|
|
|
|
var $menu = $trigger.next('.share-menu').find('.popovermenu');
|
|
|
|
var $linkTextMenu = $menu.find('li.linkTextMenu');
|
2018-07-19 08:04:37 +00:00
|
|
|
var $input = $linkTextMenu.find('.linkText');
|
|
|
|
|
2018-10-31 09:28:18 +00:00
|
|
|
var $li = $trigger.closest('li[data-share-id]');
|
|
|
|
var shareId = $li.data('share-id');
|
|
|
|
|
|
|
|
// show menu
|
|
|
|
OC.showMenu(null, $menu);
|
|
|
|
|
2016-07-08 12:30:32 +00: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 08:04:37 +00:00
|
|
|
$linkTextMenu.removeClass('hidden');
|
|
|
|
$input.select();
|
2016-11-16 14:36:44 +00:00
|
|
|
$input.tooltip('hide')
|
|
|
|
.attr('data-original-title', actionMsg)
|
|
|
|
.tooltip('fixTitle')
|
|
|
|
.tooltip({placement: 'bottom', trigger: 'manual'})
|
|
|
|
.tooltip('show');
|
2016-07-08 12:30:32 +00:00
|
|
|
_.delay(function () {
|
2017-03-03 12:36:20 +00:00
|
|
|
$input.tooltip('hide');
|
2018-07-19 08:04:37 +00:00
|
|
|
$input.attr('data-original-title', t('core', 'Copy'))
|
|
|
|
.tooltip('fixTitle');
|
2016-07-08 12:30:32 +00:00
|
|
|
}, 3000);
|
|
|
|
});
|
2015-09-12 12:21:14 +00:00
|
|
|
},
|
|
|
|
|
2018-10-31 10:43:05 +00:00
|
|
|
newShare: function(event) {
|
2018-10-29 12:58:14 +00:00
|
|
|
var self = this;
|
2018-10-31 10:43:05 +00: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 12:58:14 +00:00
|
|
|
// in process
|
2015-09-12 12:21:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-31 10:43:05 +00:00
|
|
|
|
2018-10-29 12:58:14 +00:00
|
|
|
// hide all icons and show loading
|
2018-10-31 10:43:05 +00:00
|
|
|
$li.find('.icon').addClass('hidden');
|
2018-10-29 12:58:14 +00:00
|
|
|
$loading.removeClass('hidden');
|
|
|
|
|
2018-10-31 10:43:05 +00:00
|
|
|
// hide menu
|
|
|
|
OC.hideMenus();
|
|
|
|
|
2018-10-31 10:22:47 +00:00
|
|
|
var shareData = {}
|
|
|
|
|
2018-10-31 10:43:05 +00:00
|
|
|
var isPasswordEnforced = this.configModel.get('enforcePasswordForPublicLink');
|
2018-10-31 10:22:47 +00:00
|
|
|
var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced');
|
2018-10-31 10:43:05 +00:00
|
|
|
|
|
|
|
// set default expire date
|
2018-10-31 10:22:47 +00: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 10:43:05 +00:00
|
|
|
// if password is set, add to data
|
|
|
|
if (isPasswordEnforced && this.password !== '') {
|
|
|
|
shareData.password = this.password
|
|
|
|
}
|
|
|
|
|
2018-11-01 13:55:32 +00:00
|
|
|
var newShareId = false;
|
|
|
|
|
2018-10-31 10:43:05 +00:00
|
|
|
// We need a password before the share creation
|
|
|
|
if (isPasswordEnforced && !this.showPending && this.password === '') {
|
|
|
|
this.showPending = shareId;
|
2018-11-06 09:31:48 +00:00
|
|
|
var self = this.render();
|
|
|
|
self.$el.find('.pending #enforcedPassText').focus();
|
2018-10-31 10:43:05 +00:00
|
|
|
} else {
|
|
|
|
// else, we have a password or it is not enforced
|
2018-11-01 13:55:32 +00:00
|
|
|
$.when(this.model.saveLinkShare(shareData, {
|
2018-10-31 10:43:05 +00:00
|
|
|
success: function() {
|
|
|
|
$loading.addClass('hidden');
|
|
|
|
$li.find('.icon').removeClass('hidden');
|
|
|
|
self.render();
|
2018-11-01 13:55:32 +00: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) {
|
2019-01-18 22:53:10 +00:00
|
|
|
var $menu = $newShare.find('.popovermenu');
|
2018-11-01 13:55:32 +00:00
|
|
|
OC.showMenu(null, $menu);
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 10:43:05 +00:00
|
|
|
},
|
|
|
|
error: function() {
|
2018-11-06 09:47:27 +00:00
|
|
|
// empty function to override the default Dialog warning
|
|
|
|
}
|
|
|
|
})).fail(function(response) {
|
|
|
|
// password failure? Show error
|
|
|
|
self.password = ''
|
|
|
|
if (isPasswordEnforced && response && response.responseJSON && response.responseJSON.ocs.meta && response.responseJSON.ocs.meta.message) {
|
2019-01-18 22:53:10 +00:00
|
|
|
var $input = self.$el.find('.pending #enforcedPassText')
|
2018-11-06 09:47:27 +00:00
|
|
|
$input.tooltip('destroy');
|
|
|
|
$input.attr('title', response.responseJSON.ocs.meta.message);
|
|
|
|
$input.tooltip({placement: 'bottom', trigger: 'manual'});
|
|
|
|
$input.tooltip('show');
|
|
|
|
} else {
|
2018-10-31 10:43:05 +00:00
|
|
|
OC.Notification.showTemporary(t('core', 'Unable to create a link share'));
|
|
|
|
$loading.addClass('hidden');
|
|
|
|
$li.find('.icon').removeClass('hidden');
|
|
|
|
}
|
2018-11-06 09:47:27 +00:00
|
|
|
}).then(function(response) {
|
2018-11-01 13:55:32 +00:00
|
|
|
// resolve before success
|
|
|
|
newShareId = response.ocs.data.id
|
|
|
|
});
|
2018-10-31 10:43:05 +00: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 13:40:50 +00:00
|
|
|
},
|
|
|
|
|
2018-10-29 12:58:14 +00:00
|
|
|
onLinkTextClick: function(event) {
|
|
|
|
var $element = $(event.target);
|
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var $el = $li.find('.linkText');
|
2015-10-26 11:49:52 +00:00
|
|
|
$el.focus();
|
|
|
|
$el.select();
|
2015-09-12 13:53:05 +00:00
|
|
|
},
|
|
|
|
|
2018-10-29 12:58:14 +00: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 09:06:53 +00: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 12:58:14 +00: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 09:06:53 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-10-29 12:58:14 +00: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 16:30:18 +00:00
|
|
|
this.model.saveLinkShare({
|
2018-10-29 12:58:14 +00:00
|
|
|
password: '',
|
|
|
|
cid: shareId
|
2016-01-22 16:30:18 +00:00
|
|
|
});
|
2015-09-12 15:02:03 +00:00
|
|
|
} else {
|
2017-02-15 12:50:53 +00:00
|
|
|
if (!OC.Util.isIE()) {
|
2018-10-29 12:58:14 +00:00
|
|
|
$li.find('.linkPassText').focus();
|
2017-02-15 12:50:53 +00:00
|
|
|
}
|
2015-10-16 08:54:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onPasswordKeyUp: function(event) {
|
2016-08-19 19:03:25 +00:00
|
|
|
if(event.keyCode === 13) {
|
2018-10-29 12:58:14 +00:00
|
|
|
this.onPasswordEntered(event);
|
2015-09-12 15:02:03 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-29 12:58:14 +00: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 13:30:01 +00:00
|
|
|
if (!$loading.hasClass('hidden')) {
|
|
|
|
// still in process
|
|
|
|
return;
|
|
|
|
}
|
2018-10-29 12:58:14 +00:00
|
|
|
var $input = $li.find('.linkPassText');
|
2015-09-29 13:30:01 +00:00
|
|
|
$input.removeClass('error');
|
2019-04-16 08:12:25 +00:00
|
|
|
$input.parent().find('input').removeClass('error');
|
2015-09-29 13:30:01 +00:00
|
|
|
var password = $input.val();
|
2016-10-17 12:23:55 +00:00
|
|
|
|
2018-10-29 12:58:14 +00:00
|
|
|
if ($li.find('.linkPassText').attr('placeholder') === PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL) {
|
2016-10-17 12:23:55 +00: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 15:02:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:30:01 +00:00
|
|
|
$loading
|
2015-09-12 15:02:03 +00:00
|
|
|
.removeClass('hidden')
|
|
|
|
.addClass('inlineblock');
|
|
|
|
|
2016-01-22 16:30:18 +00:00
|
|
|
this.model.saveLinkShare({
|
2018-10-29 12:58:14 +00:00
|
|
|
password: password,
|
|
|
|
cid: shareId
|
2016-01-22 16:30:18 +00:00
|
|
|
}, {
|
2017-04-24 20:18:52 +00:00
|
|
|
complete: function(model) {
|
2017-04-23 16:54:33 +00:00
|
|
|
$loading.removeClass('inlineblock').addClass('hidden');
|
|
|
|
},
|
2015-09-29 13:30:01 +00:00
|
|
|
error: function(model, msg) {
|
2019-04-16 08:12:25 +00:00
|
|
|
// Add visual feedback to both the input and the submit button
|
|
|
|
$input.parent().find('input').addClass('error');
|
|
|
|
|
2016-03-04 17:11:42 +00:00
|
|
|
// destroy old tooltips
|
2018-11-16 15:19:13 +00:00
|
|
|
var $container = $input.parent();
|
|
|
|
$container.tooltip('destroy');
|
2015-09-29 13:30:01 +00:00
|
|
|
$input.addClass('error');
|
2018-11-16 15:19:13 +00:00
|
|
|
$container.attr('title', msg);
|
|
|
|
$container.tooltip({placement: 'bottom', trigger: 'manual'});
|
|
|
|
$container.tooltip('show');
|
2015-09-29 13:30:01 +00:00
|
|
|
}
|
|
|
|
});
|
2015-09-12 15:02:03 +00:00
|
|
|
},
|
|
|
|
|
2018-10-15 15:09:46 +00: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 12:58:14 +00: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 12:24:46 +00: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 12:58:14 +00: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 12:24:46 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-06-07 10:28:02 +00:00
|
|
|
|
2018-10-29 12:58:14 +00: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 16:17:04 +00:00
|
|
|
this.model.saveLinkShare({
|
2018-10-29 12:58:14 +00:00
|
|
|
permissions: permissions,
|
|
|
|
cid: shareId
|
2016-06-09 16:17:04 +00:00
|
|
|
});
|
|
|
|
},
|
2018-10-01 09:02:12 +00:00
|
|
|
|
2018-07-20 07:39:52 +00:00
|
|
|
showNoteForm: function(event) {
|
2018-07-19 08:04:37 +00: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 09:49:06 +00:00
|
|
|
$menu.find('.share-note-delete').toggleClass('hidden');
|
2018-07-19 08:04:37 +00:00
|
|
|
$form.toggleClass('hidden');
|
2018-07-19 18:05:37 +00:00
|
|
|
$form.find('textarea').focus();
|
2018-07-19 08:04:37 +00:00
|
|
|
},
|
|
|
|
|
2018-07-20 07:39:52 +00:00
|
|
|
deleteNote: function(event) {
|
2018-07-19 08:04:37 +00: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 09:02:12 +00:00
|
|
|
|
2018-07-19 08:04:37 +00:00
|
|
|
$form.find('.share-note').val('');
|
2018-10-01 09:02:12 +00:00
|
|
|
|
2018-07-19 08:04:37 +00:00
|
|
|
$form.addClass('hidden');
|
2018-10-31 09:49:06 +00:00
|
|
|
$menu.find('.share-note-delete').addClass('hidden');
|
2018-07-19 08:04:37 +00:00
|
|
|
|
|
|
|
self.sendNote('', shareId, $menu);
|
|
|
|
},
|
|
|
|
|
2018-07-20 07:39:52 +00:00
|
|
|
updateNote: function(event) {
|
2018-07-19 08:04:37 +00: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 07:39:52 +00:00
|
|
|
sendNote: function(note, shareId, $menu) {
|
2018-07-19 08:04:37 +00: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-13 23:01:02 +00:00
|
|
|
|
2015-08-21 13:40:50 +00:00
|
|
|
render: function() {
|
2018-10-31 09:28:18 +00:00
|
|
|
this.$el.find('.has-tooltip').tooltip();
|
2018-10-31 10:43:05 +00:00
|
|
|
|
|
|
|
// reset previously set passwords
|
|
|
|
this.password = '';
|
2018-11-01 01:36:05 +00:00
|
|
|
|
2015-08-21 18:29:12 +00:00
|
|
|
var linkShareTemplate = this.template();
|
2015-12-07 15:53:56 +00:00
|
|
|
var resharingAllowed = this.model.sharePermissionPossible();
|
2015-08-21 18:29:12 +00:00
|
|
|
|
2015-12-07 15:53:56 +00:00
|
|
|
if(!resharingAllowed
|
2015-08-21 13:40:50 +00:00
|
|
|
|| !this.showLink
|
|
|
|
|| !this.configModel.isShareWithLinkAllowed())
|
|
|
|
{
|
2015-12-07 15:53:56 +00: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 13:40:50 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
var publicUpload =
|
|
|
|
this.model.isFolder()
|
2015-09-01 10:43:04 +00:00
|
|
|
&& this.model.createPermissionPossible()
|
2015-08-21 13:40:50 +00:00
|
|
|
&& this.configModel.isPublicUploadEnabled();
|
|
|
|
|
|
|
|
|
2017-01-24 12:24:46 +00:00
|
|
|
var publicEditingChecked = '';
|
|
|
|
if(this.model.isPublicEditingAllowed()) {
|
|
|
|
publicEditingChecked = 'checked="checked"';
|
|
|
|
}
|
|
|
|
|
2018-10-19 09:23:33 +00:00
|
|
|
var isPasswordEnforced = this.configModel.get('enforcePasswordForPublicLink');
|
|
|
|
var isPasswordEnabledByDefault = this.configModel.get('enableLinkPasswordByDefault') === true;
|
2016-10-17 12:23:55 +00:00
|
|
|
var passwordPlaceholderInitial = this.configModel.get('enforcePasswordForPublicLink')
|
|
|
|
? PASSWORD_PLACEHOLDER_MESSAGE : PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL;
|
2015-09-03 13:53:17 +00:00
|
|
|
|
2017-01-24 12:24:46 +00:00
|
|
|
var publicEditable =
|
|
|
|
!this.model.isFolder()
|
|
|
|
&& this.model.updatePermissionPossible();
|
|
|
|
|
2018-07-19 08:04:37 +00:00
|
|
|
var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced');
|
2018-11-01 01:36:05 +00:00
|
|
|
|
2018-07-19 18:05:37 +00: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 12:58:14 +00:00
|
|
|
minDate: minDate
|
2018-07-19 18:05:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'});
|
|
|
|
|
2018-11-01 13:55:32 +00: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 12:58:14 +00:00
|
|
|
var popoverBase = {
|
2015-08-21 13:40:50 +00:00
|
|
|
urlLabel: t('core', 'Link'),
|
2018-10-22 09:06:53 +00:00
|
|
|
hideDownloadLabel: t('core', 'Hide download'),
|
2018-10-31 10:43:05 +00:00
|
|
|
enablePasswordLabel: isPasswordEnforced ? t('core', 'Password protection enforced') : t('core', 'Password protect'),
|
2015-08-21 13:40:50 +00:00
|
|
|
passwordLabel: t('core', 'Password'),
|
2016-10-17 12:23:55 +00:00
|
|
|
passwordPlaceholderInitial: passwordPlaceholderInitial,
|
2018-10-29 12:58:14 +00:00
|
|
|
publicUpload: publicUpload,
|
2017-01-24 12:24:46 +00:00
|
|
|
publicEditing: publicEditable,
|
|
|
|
publicEditingChecked: publicEditingChecked,
|
|
|
|
publicEditingLabel: t('core', 'Allow editing'),
|
2015-08-21 13:40:50 +00:00
|
|
|
mailPrivatePlaceholder: t('core', 'Email link to person'),
|
2017-03-03 12:27:06 +00:00
|
|
|
mailButtonText: t('core', 'Send'),
|
2017-03-09 12:56:27 +00:00
|
|
|
publicUploadRWLabel: t('core', 'Allow upload and editing'),
|
|
|
|
publicUploadRLabel: t('core', 'Read only'),
|
2017-05-18 14:53:10 +00:00
|
|
|
publicUploadWLabel: t('core', 'File drop (upload only)'),
|
2017-03-09 12:56:27 +00: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 10:22:47 +00:00
|
|
|
expireDateLabel: isExpirationEnforced ? t('core', 'Expiration date enforced') : t('core', 'Set expiration date'),
|
2018-07-19 08:04:37 +00:00
|
|
|
expirationLabel: t('core', 'Expiration'),
|
|
|
|
expirationDatePlaceholder: t('core', 'Expiration date'),
|
|
|
|
isExpirationEnforced: isExpirationEnforced,
|
2018-08-16 05:31:17 +00:00
|
|
|
isPasswordEnforced: isPasswordEnforced,
|
2018-07-19 08:04:37 +00:00
|
|
|
defaultExpireDate: moment().add(1, 'day').format('DD-MM-YYYY'), // Can't expire today
|
2018-07-31 12:20:09 +00:00
|
|
|
addNoteLabel: t('core', 'Note to recipient'),
|
2018-10-29 12:58:14 +00:00
|
|
|
unshareLabel: t('core', 'Unshare'),
|
2018-11-01 01:36:05 +00:00
|
|
|
unshareLinkLabel: t('core', 'Delete share link'),
|
|
|
|
newShareLabel: t('core', 'Add another link'),
|
2018-10-29 12:58:14 +00:00
|
|
|
};
|
2015-08-21 13:40:50 +00:00
|
|
|
|
2018-10-31 10:43:05 +00:00
|
|
|
var pendingPopover = {
|
2018-08-15 09:50:48 +00:00
|
|
|
isPasswordEnforced: isPasswordEnforced,
|
2018-10-31 10:43:05 +00:00
|
|
|
enforcedPasswordLabel: t('core', 'Password protection for links is mandatory'),
|
|
|
|
passwordPlaceholder: passwordPlaceholderInitial,
|
2018-11-01 13:55:32 +00:00
|
|
|
minPasswordLength: minPasswordLength,
|
2018-10-29 12:58:14 +00:00
|
|
|
};
|
2018-10-31 10:43:05 +00:00
|
|
|
var pendingPopoverMenu = this.pendingPopoverMenuTemplate(_.extend({}, pendingPopover))
|
2018-10-29 12:58:14 +00:00
|
|
|
|
|
|
|
var linkShares = this.getShareeList();
|
|
|
|
if(_.isArray(linkShares)) {
|
|
|
|
for (var i = 0; i < linkShares.length; i++) {
|
2019-01-22 14:29:45 +00:00
|
|
|
var social = [];
|
|
|
|
OC.Share.Social.Collection.each(function (model) {
|
|
|
|
var url = model.get('url');
|
|
|
|
url = url.replace('{{reference}}', linkShares[i].shareLinkURL);
|
|
|
|
social.push({
|
|
|
|
url: url,
|
|
|
|
label: t('core', 'Share to {name}', {name: model.get('name')}),
|
|
|
|
name: model.get('name'),
|
|
|
|
iconClass: model.get('iconClass'),
|
|
|
|
newWindow: model.get('newWindow')
|
|
|
|
});
|
|
|
|
});
|
2018-10-29 12:58:14 +00:00
|
|
|
var popover = this.getPopoverObject(linkShares[i])
|
2019-01-22 14:29:45 +00:00
|
|
|
linkShares[i].popoverMenu = this.popoverMenuTemplate(_.extend({}, popoverBase, popover, {social: social}));
|
2018-10-31 10:43:05 +00:00
|
|
|
linkShares[i].pendingPopoverMenu = pendingPopoverMenu
|
2018-10-29 12:58:14 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-15 09:50:48 +00:00
|
|
|
|
2018-07-19 08:04:37 +00:00
|
|
|
this.$el.html(linkShareTemplate({
|
2018-10-29 12:58:14 +00:00
|
|
|
linkShares: linkShares,
|
2018-07-19 08:04:37 +00:00
|
|
|
shareAllowed: true,
|
2018-10-29 12:58:14 +00:00
|
|
|
nolinkShares: linkShares.length === 0,
|
|
|
|
newShareLabel: t('core', 'Share link'),
|
2018-10-31 10:43:05 +00:00
|
|
|
newShareTitle: t('core', 'New share link'),
|
|
|
|
pendingPopoverMenu: pendingPopoverMenu,
|
2018-11-05 09:46:13 +00:00
|
|
|
showPending: this.showPending === this.newShareId,
|
|
|
|
newShareId: this.newShareId,
|
2018-07-19 08:04:37 +00:00
|
|
|
}));
|
2017-03-03 12:36:20 +00:00
|
|
|
|
2015-09-14 16:24:58 +00:00
|
|
|
this.delegateEvents();
|
|
|
|
|
2018-07-19 18:05:37 +00:00
|
|
|
// new note autosize
|
|
|
|
autosize(this.$el.find('.share-note-form .share-note'));
|
|
|
|
|
2015-08-21 13:40:50 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-03-03 12:27:06 +00:00
|
|
|
onToggleMenu: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
var $element = $(event.target);
|
2018-07-19 08:04:37 +00:00
|
|
|
var $li = $element.closest('li[data-share-id]');
|
|
|
|
var $menu = $li.find('.sharingOptionsGroup .popovermenu');
|
2018-10-29 12:58:14 +00:00
|
|
|
var shareId = $li.data('share-id');
|
2017-03-03 12:27:06 +00:00
|
|
|
|
|
|
|
OC.showMenu(null, $menu);
|
2018-10-31 10:43:05 +00: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 12:27:06 +00:00
|
|
|
},
|
|
|
|
|
2015-08-21 13:40:50 +00:00
|
|
|
/**
|
|
|
|
* @returns {Function} from Handlebars
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
template: function () {
|
2018-10-01 18:46:29 +00:00
|
|
|
return OC.Share.Templates['sharedialoglinkshareview'];
|
2017-03-03 12:27:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* renders the popover template and returns the resulting HTML
|
|
|
|
*
|
|
|
|
* @param {Object} data
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
popoverMenuTemplate: function(data) {
|
2018-10-01 18:46:29 +00:00
|
|
|
return OC.Share.Templates['sharedialoglinkshareview_popover_menu'](data);
|
2017-03-03 12:27:06 +00:00
|
|
|
},
|
|
|
|
|
2018-08-15 09:50:48 +00:00
|
|
|
/**
|
|
|
|
* renders the pending popover template and returns the resulting HTML
|
|
|
|
*
|
|
|
|
* @param {Object} data
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
pendingPopoverMenuTemplate: function(data) {
|
2018-10-01 18:46:29 +00:00
|
|
|
return OC.Share.Templates['sharedialoglinkshareview_popover_menu_pending'](data);
|
2018-08-15 09:50:48 +00:00
|
|
|
},
|
|
|
|
|
2017-03-03 12:27:06 +00:00
|
|
|
onPopUpClick: function(event) {
|
2017-03-15 04:50:32 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
var url = $(event.currentTarget).data('url');
|
2017-04-20 14:32:46 +00:00
|
|
|
var newWindow = $(event.currentTarget).data('window');
|
2017-03-15 04:50:32 +00:00
|
|
|
$(event.currentTarget).tooltip('hide');
|
2017-03-03 12:27:06 +00:00
|
|
|
if (url) {
|
2017-04-20 14:32:46 +00: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 12:27:06 +00:00
|
|
|
|
2017-04-20 14:32:46 +00:00
|
|
|
window.open(url, 'name', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left);
|
|
|
|
} else {
|
|
|
|
window.location.href = url;
|
|
|
|
}
|
2017-03-03 12:27:06 +00:00
|
|
|
}
|
2018-07-19 08:04:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onExpireDateChange: function(event) {
|
|
|
|
var $element = $(event.target);
|
2018-07-19 18:05:37 +00: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 08:04:37 +00:00
|
|
|
var state = $element.prop('checked');
|
|
|
|
datePicker.toggleClass('hidden', !state);
|
2018-10-01 09:02:12 +00:00
|
|
|
|
2018-07-19 08:04:37 +00:00
|
|
|
if (!state) {
|
|
|
|
// disabled, let's hide the input and
|
|
|
|
// set the expireDate to nothing
|
|
|
|
$element.closest('li').next('li').addClass('hidden');
|
2019-02-05 17:12:16 +00:00
|
|
|
this.setExpirationDate('', shareId);
|
2018-07-19 08:04:37 +00:00
|
|
|
} else {
|
|
|
|
// enabled, show the input and the datepicker
|
|
|
|
$element.closest('li').next('li').removeClass('hidden');
|
|
|
|
this.showDatePicker(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showDatePicker: function(event) {
|
2018-07-19 18:05:37 +00:00
|
|
|
var $element = $(event.target);
|
|
|
|
var li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = li.data('share-id');
|
2018-10-29 12:58:14 +00:00
|
|
|
var maxDate = $element.data('max-date');
|
2018-07-19 18:05:37 +00:00
|
|
|
var expirationDatePicker = '#expirationDatePicker-' + shareId;
|
2018-07-19 08:04:37 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$(expirationDatePicker).datepicker({
|
|
|
|
dateFormat : 'dd-mm-yy',
|
|
|
|
onSelect: function (expireDate) {
|
2018-10-29 12:58:14 +00:00
|
|
|
self.setExpirationDate(expireDate, shareId);
|
|
|
|
},
|
|
|
|
maxDate: maxDate
|
2018-07-19 08:04:37 +00:00
|
|
|
});
|
2018-07-19 18:05:37 +00:00
|
|
|
$(expirationDatePicker).datepicker('show');
|
2018-07-19 08:04:37 +00:00
|
|
|
$(expirationDatePicker).focus();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-10-29 12:58:14 +00:00
|
|
|
setExpirationDate: function(expireDate, shareId) {
|
|
|
|
this.model.saveLinkShare({expireDate: expireDate, cid: shareId});
|
2018-07-19 08:04:37 +00:00
|
|
|
},
|
2015-08-21 13:40:50 +00:00
|
|
|
|
2019-02-26 18:29:15 +00:00
|
|
|
onChangeExpirationDate: function(event) {
|
|
|
|
var $element = $(event.target);
|
|
|
|
var expireDate = $element.val();
|
|
|
|
var li = $element.closest('li[data-share-id]');
|
|
|
|
var shareId = li.data('share-id');
|
|
|
|
var expirationDatePicker = '#expirationDatePicker-' + shareId;
|
|
|
|
|
|
|
|
this.setExpirationDate(expireDate, shareId);
|
|
|
|
$(expirationDatePicker).datepicker('hide');
|
|
|
|
},
|
|
|
|
|
2018-10-29 12:58:14 +00: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,
|
2018-11-07 14:14:29 +00:00
|
|
|
linkShareLabel: share.label ? share.label : t('core', 'Share link'),
|
2018-10-29 12:58:14 +00:00
|
|
|
popoverMenu: {},
|
2018-10-31 09:28:18 +00:00
|
|
|
shareLinkURL: share.url,
|
|
|
|
newShareTitle: t('core', 'New share link'),
|
|
|
|
copyLabel: t('core', 'Copy link'),
|
2018-10-31 10:43:05 +00:00
|
|
|
showPending: this.showPending === share.id,
|
2018-11-26 17:37:58 +00:00
|
|
|
linkShareCreationDate: t('core', 'Created on {time}', { time: moment(share.stime * 1000).format('LLLL') })
|
2018-10-29 12:58:14 +00: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 01:36:05 +00:00
|
|
|
|
2018-10-29 12:58:14 +00:00
|
|
|
var isPasswordSet = !!share.password;
|
|
|
|
var isPasswordEnabledByDefault = this.configModel.get('enableLinkPasswordByDefault') === true;
|
|
|
|
var isPasswordEnforced = this.configModel.get('enforcePasswordForPublicLink');
|
|
|
|
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 15:09:46 +00:00
|
|
|
var isTalkEnabled = oc_appswebroots['spreed'] !== undefined;
|
|
|
|
var sendPasswordByTalk = share.sendPasswordByTalk;
|
|
|
|
|
2018-10-29 12:58:14 +00:00
|
|
|
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,
|
2018-10-15 15:09:46 +00:00
|
|
|
showPasswordByTalkCheckBox: isTalkEnabled && isPasswordSet,
|
|
|
|
passwordByTalkLabel: t('core', 'Password protect by Talk'),
|
|
|
|
isPasswordByTalkSet: sendPasswordByTalk,
|
2018-10-29 12:58:14 +00:00
|
|
|
publicUploadRWChecked: publicUploadRWChecked,
|
|
|
|
publicUploadRChecked: publicUploadRChecked,
|
|
|
|
publicUploadWChecked: publicUploadWChecked,
|
|
|
|
hasExpireDate: hasExpireDate,
|
|
|
|
expireDate: expireDate,
|
|
|
|
shareNote: share.note,
|
|
|
|
hasNote: share.note !== '',
|
|
|
|
maxDate: maxDate,
|
|
|
|
hideDownload: hideDownload,
|
2018-10-31 10:22:47 +00:00
|
|
|
isExpirationEnforced: isExpirationEnforced,
|
2018-10-29 12:58:14 +00: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 13:40:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
OC.Share.ShareDialogLinkShareView = ShareDialogLinkShareView;
|
|
|
|
|
|
|
|
})();
|