2019-09-25 19:19:42 +03:00
|
|
|
/* eslint-disable */
|
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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.Share = {}
|
2015-08-21 16:40:50 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var PASSWORD_PLACEHOLDER = '**********'
|
|
|
|
var PASSWORD_PLACEHOLDER_MESSAGE = t('core', 'Choose a password for the public link')
|
|
|
|
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: '',
|
|
|
|
|
2018-11-05 12:46:13 +03:00
|
|
|
/** @type {string} **/
|
|
|
|
newShareId: 'new-share',
|
|
|
|
|
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
|
2019-09-25 19:19:42 +03:00
|
|
|
'click input.share-pass-submit': 'onPasswordEntered',
|
2018-11-16 18:19:13 +03:00
|
|
|
'keyup input.linkPassText': 'onPasswordKeyUp', // check for the enter key
|
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
|
2019-09-25 19:19:42 +03:00
|
|
|
'click .expireDate': 'onExpireDateChange',
|
2018-07-19 11:04:37 +03:00
|
|
|
'change .datepicker': 'onChangeExpirationDate',
|
2019-09-25 19:19:42 +03:00
|
|
|
'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
|
2019-09-25 19:19:42 +03:00
|
|
|
'submit .enforcedPassForm': 'enforcedPasswordSet'
|
2015-09-14 19:24:58 +03:00
|
|
|
},
|
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
initialize: function(options) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var view = this
|
2015-08-21 16:40:50 +03:00
|
|
|
|
|
|
|
this.model.on('change:permissions', function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
view.render()
|
|
|
|
})
|
2015-08-21 16:40:50 +03:00
|
|
|
|
|
|
|
this.model.on('change:itemType', function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
view.render()
|
|
|
|
})
|
2015-08-21 16:40:50 +03:00
|
|
|
|
|
|
|
this.model.on('change:allowPublicUploadStatus', function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
view.render()
|
|
|
|
})
|
2015-08-21 16:40:50 +03:00
|
|
|
|
2016-06-07 13:28:02 +03:00
|
|
|
this.model.on('change:hideFileListStatus', function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
view.render()
|
|
|
|
})
|
2016-06-07 13:28:02 +03:00
|
|
|
|
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).
|
2019-09-25 19:19:42 +03:00
|
|
|
|
|
|
|
var previousLinkShares = model.previous('linkShares')
|
2018-10-15 18:09:46 +03:00
|
|
|
if (previousLinkShares.length !== linkShares.length) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2018-10-15 18:09:46 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var i
|
2018-10-15 18:09:46 +03:00
|
|
|
for (i = 0; i < linkShares.length; i++) {
|
|
|
|
if (linkShares[i].id !== previousLinkShares[i].id) {
|
|
|
|
// A resorting should never happen, but just in case.
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2018-10-15 18:09:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (linkShares[i].password !== previousLinkShares[i].password) {
|
2019-09-25 19:19:42 +03:00
|
|
|
view.render()
|
2018-10-15 18:09:46 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2018-10-15 18:09:46 +03:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2018-10-15 18:09:46 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
if (!_.isUndefined(options.configModel)) {
|
|
|
|
this.configModel = options.configModel
|
2015-08-21 16:40:50 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
throw 'missing OC.Share.ShareConfigModel'
|
2015-08-21 16:40:50 +03:00
|
|
|
}
|
2015-09-12 15:21:14 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var clipboard = new Clipboard('.clipboard-button')
|
2016-07-08 15:30:32 +03:00
|
|
|
clipboard.on('success', function(e) {
|
2019-09-25 19:19:42 +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')
|
2019-09-25 19:19:42 +03:00
|
|
|
.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')
|
2019-09-25 19:19:42 +03:00
|
|
|
}, 3000)
|
|
|
|
})
|
|
|
|
clipboard.on('error', function(e) {
|
|
|
|
var $trigger = $(e.trigger)
|
|
|
|
var $menu = $trigger.next('.share-menu').find('.popovermenu')
|
|
|
|
var $linkTextMenu = $menu.find('li.linkTextMenu')
|
|
|
|
var $input = $linkTextMenu.find('.linkText')
|
2018-07-19 11:04:37 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var $li = $trigger.closest('li[data-share-id]')
|
|
|
|
var shareId = $li.data('share-id')
|
2018-10-31 12:28:18 +03:00
|
|
|
|
|
|
|
// show menu
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.showMenu(null, $menu)
|
2018-10-31 12:28:18 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var actionMsg = ''
|
2016-07-08 15:30:32 +03:00
|
|
|
if (/iPhone|iPad/i.test(navigator.userAgent)) {
|
2019-09-25 19:19:42 +03:00
|
|
|
actionMsg = t('core', 'Not supported!')
|
2016-07-08 15:30:32 +03:00
|
|
|
} else if (/Mac/i.test(navigator.userAgent)) {
|
2019-09-25 19:19:42 +03:00
|
|
|
actionMsg = t('core', 'Press ⌘-C to copy.')
|
2016-07-08 15:30:32 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
actionMsg = t('core', 'Press Ctrl-C to copy.')
|
2016-07-08 15:30:32 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +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')
|
2019-09-25 19:19:42 +03:00
|
|
|
.tooltip({ placement: 'bottom', trigger: 'manual' })
|
|
|
|
.tooltip('show')
|
|
|
|
_.delay(function() {
|
|
|
|
$input.tooltip('hide')
|
2018-07-19 11:04:37 +03:00
|
|
|
$input.attr('data-original-title', t('core', 'Copy'))
|
2019-09-25 19:19:42 +03:00
|
|
|
.tooltip('fixTitle')
|
|
|
|
}, 3000)
|
|
|
|
})
|
2015-09-12 15:21:14 +03:00
|
|
|
},
|
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
newShare: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var self = this
|
|
|
|
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')
|
2018-10-31 13:43:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
if (!$loading.hasClass('hidden') && this.password === '') {
|
2018-10-29 15:58:14 +03:00
|
|
|
// in process
|
2019-09-25 19:19:42 +03:00
|
|
|
return false
|
2015-09-12 15:21:14 +03:00
|
|
|
}
|
2018-10-31 13:43:05 +03:00
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
// hide all icons and show loading
|
2019-09-25 19:19:42 +03:00
|
|
|
$li.find('.icon').addClass('hidden')
|
|
|
|
$loading.removeClass('hidden')
|
2018-10-29 15:58:14 +03:00
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
// hide menu
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.hideMenus()
|
2018-10-31 13:43:05 +03:00
|
|
|
|
2018-10-31 13:22:47 +03:00
|
|
|
var shareData = {}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var isPasswordEnforced = this.configModel.get('enforcePasswordForPublicLink')
|
|
|
|
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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var defaultExpireDays = this.configModel.get('defaultExpireDate')
|
2018-10-31 13:22:47 +03:00
|
|
|
var expireDate = moment().add(defaultExpireDays, 'day').format('DD-MM-YYYY')
|
2019-09-25 19:19:42 +03:00
|
|
|
shareData.expireDate = expireDate
|
2018-10-31 13:22:47 +03:00
|
|
|
}
|
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
// if password is set, add to data
|
|
|
|
if (isPasswordEnforced && this.password !== '') {
|
|
|
|
shareData.password = this.password
|
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var newShareId = false
|
2018-11-01 16:55:32 +03:00
|
|
|
|
2018-10-31 13:43:05 +03:00
|
|
|
// We need a password before the share creation
|
|
|
|
if (isPasswordEnforced && !this.showPending && this.password === '') {
|
2019-09-25 19:19:42 +03:00
|
|
|
this.showPending = shareId
|
|
|
|
var self = this.render()
|
|
|
|
self.$el.find('.pending #enforcedPassText').focus()
|
2018-10-31 13:43:05 +03:00
|
|
|
} 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() {
|
2019-09-25 19:19:42 +03:00
|
|
|
$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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var shares = self.$el.find('li[data-share-id]')
|
|
|
|
var $newShare = self.$el.find('li[data-share-id="' + newShareId + '"]')
|
2018-11-01 16:55:32 +03:00
|
|
|
}
|
2018-10-31 13:43:05 +03:00
|
|
|
},
|
|
|
|
error: function() {
|
2018-11-06 12:47:27 +03: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-19 01:53:10 +03:00
|
|
|
var $input = self.$el.find('.pending #enforcedPassText')
|
2019-09-25 19:19:42 +03:00
|
|
|
$input.tooltip('destroy')
|
|
|
|
$input.attr('title', response.responseJSON.ocs.meta.message)
|
|
|
|
$input.tooltip({ placement: 'bottom', trigger: 'manual' })
|
|
|
|
$input.tooltip('show')
|
2018-11-06 12:47:27 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.Notification.showTemporary(t('core', 'Unable to create a link share'))
|
|
|
|
$loading.addClass('hidden')
|
|
|
|
$li.find('.icon').removeClass('hidden')
|
2018-10-31 13:43:05 +03:00
|
|
|
}
|
2018-11-06 12:47:27 +03:00
|
|
|
}).then(function(response) {
|
2018-11-01 16:55:32 +03:00
|
|
|
// resolve before success
|
|
|
|
newShareId = response.ocs.data.id
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2018-10-31 13:43:05 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
enforcedPasswordSet: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var $element = $(event.target)
|
|
|
|
var $li = $element.closest('li[data-share-id]')
|
|
|
|
var $el = $li.find('.linkText')
|
|
|
|
$el.focus()
|
|
|
|
$el.select()
|
2015-09-12 16:53:05 +03:00
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onHideDownloadChange: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var $element = $(event.target)
|
|
|
|
var $li = $element.closest('li[data-share-id]')
|
|
|
|
var shareId = $li.data('share-id')
|
|
|
|
var $checkbox = $li.find('.hideDownloadCheckbox')
|
|
|
|
$checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock')
|
|
|
|
|
|
|
|
var hideDownload = false
|
|
|
|
if ($checkbox.is(':checked')) {
|
|
|
|
hideDownload = true
|
2018-10-22 12:06:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.model.saveLinkShare({
|
2018-10-29 15:58:14 +03:00
|
|
|
hideDownload: hideDownload,
|
|
|
|
cid: shareId
|
|
|
|
}, {
|
|
|
|
success: function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock')
|
2018-10-29 15:58:14 +03:00
|
|
|
},
|
|
|
|
error: function(obj, msg) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2018-10-22 12:06:53 +03:00
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onShowPasswordClick: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2015-09-12 18:02:03 +03:00
|
|
|
} else {
|
2017-02-15 15:50:53 +03:00
|
|
|
if (!OC.Util.isIE()) {
|
2019-09-25 19:19:42 +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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
if (event.keyCode === 13) {
|
|
|
|
this.onPasswordEntered(event)
|
2015-09-12 18:02:03 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onPasswordEntered: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2015-09-29 16:30:01 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
var $input = $li.find('.linkPassText')
|
|
|
|
$input.removeClass('error')
|
|
|
|
$input.parent().find('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
|
2019-09-25 19:19:42 +03:00
|
|
|
if (password === PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL) {
|
|
|
|
password = ''
|
2016-10-17 15:23:55 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// in IE9 the password might be the placeholder due to bugs in the placeholders polyfill
|
2019-09-25 19:19:42 +03:00
|
|
|
if (password === '' || password === PASSWORD_PLACEHOLDER || password === PASSWORD_PLACEHOLDER_MESSAGE) {
|
|
|
|
return
|
2016-10-17 15:23:55 +03:00
|
|
|
}
|
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')
|
2019-09-25 19:19:42 +03:00
|
|
|
.addClass('inlineblock')
|
2015-09-12 18:02:03 +03:00
|
|
|
|
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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$loading.removeClass('inlineblock').addClass('hidden')
|
2017-04-23 19:54:33 +03:00
|
|
|
},
|
2015-09-29 16:30:01 +03:00
|
|
|
error: function(model, msg) {
|
2019-04-16 11:12:25 +03:00
|
|
|
// Add visual feedback to both the input and the submit button
|
2019-09-25 19:19:42 +03:00
|
|
|
$input.parent().find('input').addClass('error')
|
2019-04-16 11:12:25 +03:00
|
|
|
|
2016-03-04 20:11:42 +03:00
|
|
|
// destroy old tooltips
|
2019-09-25 19:19:42 +03:00
|
|
|
var $container = $input.parent()
|
|
|
|
$container.tooltip('destroy')
|
|
|
|
$input.addClass('error')
|
|
|
|
$container.attr('title', msg)
|
|
|
|
$container.tooltip({ placement: 'bottom', trigger: 'manual' })
|
|
|
|
$container.tooltip('show')
|
2015-09-29 16:30:01 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2015-09-12 18:02:03 +03:00
|
|
|
},
|
|
|
|
|
2018-10-15 18:09:46 +03:00
|
|
|
onPasswordByTalkChange: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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
|
2018-10-15 18:09:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.model.saveLinkShare({
|
|
|
|
sendPasswordByTalk: sendPasswordByTalk,
|
|
|
|
cid: shareId
|
|
|
|
}, {
|
|
|
|
success: function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock')
|
2018-10-15 18:09:46 +03:00
|
|
|
},
|
|
|
|
error: function(obj, msg) {
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.Notification.showTemporary(t('core', 'Unable to toggle this option'))
|
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock')
|
2018-10-15 18:09:46 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2018-10-15 18:09:46 +03:00
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onAllowPublicEditingChange: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var $element = $(event.target)
|
|
|
|
var $li = $element.closest('li[data-share-id]')
|
|
|
|
var shareId = $li.data('share-id')
|
|
|
|
var $checkbox = $li.find('.publicEditingCheckbox')
|
|
|
|
$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
|
2017-01-24 15:24:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.model.saveLinkShare({
|
2018-10-29 15:58:14 +03:00
|
|
|
permissions: permissions,
|
|
|
|
cid: shareId
|
|
|
|
}, {
|
|
|
|
success: function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
$checkbox.siblings('.icon-loading-small').addClass('hidden').removeClass('inlineblock')
|
2018-10-29 15:58:14 +03:00
|
|
|
},
|
|
|
|
error: function(obj, msg) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2017-01-24 15:24:46 +03:00
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
onPublicUploadChange: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
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) {
|
2019-09-25 19:19:42 +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')
|
2018-07-19 11:04:37 +03:00
|
|
|
|
|
|
|
// show elements
|
2019-09-25 19:19:42 +03:00
|
|
|
$menu.find('.share-note-delete').toggleClass('hidden')
|
|
|
|
$form.toggleClass('hidden')
|
|
|
|
$form.find('textarea').focus()
|
2018-07-19 11:04:37 +03:00
|
|
|
},
|
|
|
|
|
2018-07-20 10:39:52 +03:00
|
|
|
deleteNote: function(event) {
|
2019-09-25 19:19:42 +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
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$form.find('.share-note').val('')
|
2018-10-01 12:02:12 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$form.addClass('hidden')
|
|
|
|
$menu.find('.share-note-delete').addClass('hidden')
|
2018-07-19 11:04:37 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
self.sendNote('', shareId, $menu)
|
2018-07-19 11:04:37 +03:00
|
|
|
},
|
|
|
|
|
2018-07-20 10:39:52 +03:00
|
|
|
updateNote: function(event) {
|
2019-09-25 19:19:42 +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()
|
2018-07-19 11:04:37 +03:00
|
|
|
|
|
|
|
if (message.length < 1) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2018-07-19 11:04:37 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
self.sendNote(message, shareId, $menu)
|
2018-07-19 11:04:37 +03:00
|
|
|
},
|
|
|
|
|
2018-07-20 10:39:52 +03:00
|
|
|
sendNote: function(note, shareId, $menu) {
|
2019-09-25 19:19:42 +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')
|
2018-07-19 11:04:37 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
$submit.prop('disabled', true)
|
|
|
|
$menu.find('.icon-loading-small').removeClass('hidden')
|
|
|
|
$menu.find('.icon-edit').hide()
|
2018-07-19 11:04:37 +03:00
|
|
|
|
|
|
|
var complete = function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
$submit.prop('disabled', false)
|
|
|
|
$menu.find('.icon-loading-small').addClass('hidden')
|
|
|
|
$menu.find('.icon-edit').show()
|
|
|
|
}
|
2018-07-19 11:04:37 +03:00
|
|
|
var error = function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
$error.show()
|
2018-07-19 11:04:37 +03:00
|
|
|
setTimeout(function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
$error.hide()
|
|
|
|
}, 3000)
|
|
|
|
}
|
2018-07-19 11:04:37 +03:00
|
|
|
|
|
|
|
// send data
|
|
|
|
$.ajax({
|
|
|
|
method: 'PUT',
|
2019-09-25 19:19:42 +03:00
|
|
|
url: OC.linkToOCS('apps/files_sharing/api/v1/shares', 2) + shareId + '?' + OC.buildQueryString({ format: 'json' }),
|
2018-07-19 11:04:37 +03:00
|
|
|
data: { note: note },
|
2019-09-25 19:19:42 +03:00
|
|
|
complete: complete,
|
2018-07-19 11:04:37 +03:00
|
|
|
error: error
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2018-07-19 11:04:37 +03:00
|
|
|
},
|
2015-09-14 02:01:02 +03:00
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
render: function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
this.$el.find('.has-tooltip').tooltip()
|
2018-10-31 13:43:05 +03:00
|
|
|
|
|
|
|
// reset previously set passwords
|
2019-09-25 19:19:42 +03:00
|
|
|
this.password = ''
|
2018-11-01 04:36:05 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var linkShareTemplate = this.template()
|
|
|
|
var resharingAllowed = this.model.sharePermissionPossible()
|
2015-08-21 21:29:12 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
if (!resharingAllowed
|
2015-08-21 16:40:50 +03:00
|
|
|
|| !this.showLink
|
2019-09-25 19:19:42 +03:00
|
|
|
|| !this.configModel.isShareWithLinkAllowed()) {
|
|
|
|
var templateData = { shareAllowed: false }
|
2015-12-07 18:53:56 +03:00
|
|
|
if (!resharingAllowed) {
|
|
|
|
// add message
|
2019-09-25 19:19:42 +03:00
|
|
|
templateData.noSharingPlaceholder = t('core', 'Resharing is not allowed')
|
2015-12-07 18:53:56 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
this.$el.html(linkShareTemplate(templateData))
|
|
|
|
return this
|
2015-08-21 16:40:50 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var publicUpload
|
|
|
|
= this.model.isFolder()
|
2015-09-01 13:43:04 +03:00
|
|
|
&& this.model.createPermissionPossible()
|
2019-09-25 19:19:42 +03:00
|
|
|
&& this.configModel.isPublicUploadEnabled()
|
2015-08-21 16:40:50 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var publicEditingChecked = ''
|
|
|
|
if (this.model.isPublicEditingAllowed()) {
|
|
|
|
publicEditingChecked = 'checked="checked"'
|
2017-01-24 15:24:46 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +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')
|
2019-09-25 19:19:42 +03:00
|
|
|
? PASSWORD_PLACEHOLDER_MESSAGE : PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL
|
2015-09-03 16:53:17 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var publicEditable
|
|
|
|
= !this.model.isFolder()
|
|
|
|
&& this.model.updatePermissionPossible()
|
2017-01-24 15:24:46 +03:00
|
|
|
|
2019-09-25 19:19:42 +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?
|
2019-09-25 19:19:42 +03:00
|
|
|
var minDate = new Date()
|
2018-07-19 21:05:37 +03:00
|
|
|
// min date should always be the next day
|
2019-09-25 19:19:42 +03:00
|
|
|
minDate.setDate(minDate.getDate() + 1)
|
2018-07-19 21:05:37 +03:00
|
|
|
|
|
|
|
$.datepicker.setDefaults({
|
2018-10-29 15:58:14 +03:00
|
|
|
minDate: minDate
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2018-07-19 21:05:37 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
this.$el.find('.datepicker').datepicker({ dateFormat: 'dd-mm-yy' })
|
2018-07-19 21:05:37 +03:00
|
|
|
|
2018-11-01 16:55:32 +03:00
|
|
|
var minPasswordLength = 4
|
|
|
|
// password policy?
|
2019-09-25 19:19:42 +03:00
|
|
|
if (OC.getCapabilities().password_policy && OC.getCapabilities().password_policy.minLength) {
|
|
|
|
minPasswordLength = OC.getCapabilities().password_policy.minLength
|
2018-11-01 16:55:32 +03:00
|
|
|
}
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
var popoverBase = {
|
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'),
|
2019-09-25 19:19:42 +03:00
|
|
|
newShareLabel: t('core', 'Add another link')
|
|
|
|
}
|
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,
|
2019-09-25 19:19:42 +03:00
|
|
|
minPasswordLength: minPasswordLength
|
|
|
|
}
|
2018-10-31 13:43:05 +03:00
|
|
|
var pendingPopoverMenu = this.pendingPopoverMenuTemplate(_.extend({}, pendingPopover))
|
2018-10-29 15:58:14 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var linkShares = this.getShareeList()
|
|
|
|
if (_.isArray(linkShares)) {
|
2018-10-29 15:58:14 +03:00
|
|
|
for (var i = 0; i < linkShares.length; i++) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var social = []
|
|
|
|
OC.Share.Social.Collection.each(function(model) {
|
|
|
|
var url = model.get('url')
|
|
|
|
url = url.replace('{{reference}}', linkShares[i].shareLinkURL)
|
2019-01-22 17:29:45 +03:00
|
|
|
social.push({
|
|
|
|
url: url,
|
2019-09-25 19:19:42 +03:00
|
|
|
label: t('core', 'Share to {name}', { name: model.get('name') }),
|
2019-01-22 17:29:45 +03:00
|
|
|
name: model.get('name'),
|
|
|
|
iconClass: model.get('iconClass'),
|
|
|
|
newWindow: model.get('newWindow')
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
})
|
2018-10-29 15:58:14 +03:00
|
|
|
var popover = this.getPopoverObject(linkShares[i])
|
2019-09-25 19:19:42 +03:00
|
|
|
linkShares[i].popoverMenu = this.popoverMenuTemplate(_.extend({}, popoverBase, popover, { social: social }))
|
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,
|
2018-11-05 12:46:13 +03:00
|
|
|
showPending: this.showPending === this.newShareId,
|
2019-09-25 19:19:42 +03:00
|
|
|
newShareId: this.newShareId
|
|
|
|
}))
|
2017-03-03 15:36:20 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
this.delegateEvents()
|
2015-09-14 19:24:58 +03:00
|
|
|
|
2018-07-19 21:05:37 +03:00
|
|
|
// new note autosize
|
2019-09-25 19:19:42 +03:00
|
|
|
autosize(this.$el.find('.share-note-form .share-note'))
|
2018-07-19 21:05:37 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
return this
|
2015-08-21 16:40:50 +03:00
|
|
|
},
|
|
|
|
|
2017-03-03 15:27:06 +03:00
|
|
|
onToggleMenu: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
|
|
|
var $element = $(event.target)
|
|
|
|
var $li = $element.closest('li[data-share-id]')
|
|
|
|
var $menu = $li.find('.sharingOptionsGroup .popovermenu')
|
|
|
|
var shareId = $li.data('share-id')
|
2017-03-03 15:27:06 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.showMenu(null, $menu)
|
2018-10-31 13:43:05 +03:00
|
|
|
|
|
|
|
// focus the password if not set and enforced
|
2019-09-25 19:19:42 +03:00
|
|
|
var isPasswordEnabledByDefault = this.configModel.get('enableLinkPasswordByDefault') === true
|
|
|
|
var haspassword = $menu.find('.linkPassText').val() !== ''
|
2018-10-31 13:43:05 +03:00
|
|
|
|
|
|
|
if (!haspassword && isPasswordEnabledByDefault) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$menu.find('.linkPassText').focus()
|
2018-10-31 13:43:05 +03:00
|
|
|
}
|
2017-03-03 15:27:06 +03:00
|
|
|
},
|
|
|
|
|
2015-08-21 16:40:50 +03:00
|
|
|
/**
|
|
|
|
* @returns {Function} from Handlebars
|
|
|
|
* @private
|
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
template: function() {
|
|
|
|
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) {
|
2019-09-25 19:19:42 +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) {
|
2019-09-25 19:19:42 +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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
2017-03-15 07:50:32 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var url = $(event.currentTarget).data('url')
|
|
|
|
var newWindow = $(event.currentTarget).data('window')
|
|
|
|
$(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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
window.open(url, 'name', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left)
|
2017-04-20 17:32:46 +03:00
|
|
|
} else {
|
2019-09-25 19:19:42 +03:00
|
|
|
window.location.href = url
|
2017-04-20 17:32:46 +03:00
|
|
|
}
|
2017-03-03 15:27:06 +03:00
|
|
|
}
|
2018-07-19 11:04:37 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onExpireDateChange: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var $element = $(event.target)
|
|
|
|
var li = $element.closest('li[data-share-id]')
|
|
|
|
var shareId = li.data('share-id')
|
|
|
|
var expirationDatePicker = '#expirationDateContainer-' + shareId
|
|
|
|
var datePicker = $(expirationDatePicker)
|
|
|
|
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
|
2019-09-25 19:19:42 +03:00
|
|
|
$element.closest('li').next('li').addClass('hidden')
|
|
|
|
this.setExpirationDate('', shareId)
|
2018-07-19 11:04:37 +03:00
|
|
|
} else {
|
|
|
|
// enabled, show the input and the datepicker
|
2019-09-25 19:19:42 +03:00
|
|
|
$element.closest('li').next('li').removeClass('hidden')
|
|
|
|
this.showDatePicker(event)
|
2018-07-19 11:04:37 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showDatePicker: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var $element = $(event.target)
|
|
|
|
var li = $element.closest('li[data-share-id]')
|
|
|
|
var shareId = li.data('share-id')
|
|
|
|
var maxDate = $element.data('max-date')
|
|
|
|
var expirationDatePicker = '#expirationDatePicker-' + shareId
|
|
|
|
var self = this
|
2018-07-19 11:04:37 +03:00
|
|
|
|
|
|
|
$(expirationDatePicker).datepicker({
|
2019-09-25 19:19:42 +03:00
|
|
|
dateFormat: 'dd-mm-yy',
|
|
|
|
onSelect: function(expireDate) {
|
|
|
|
self.setExpirationDate(expireDate, shareId)
|
2018-10-29 15:58:14 +03:00
|
|
|
},
|
|
|
|
maxDate: maxDate
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
$(expirationDatePicker).datepicker('show')
|
|
|
|
$(expirationDatePicker).focus()
|
2018-07-19 11:04:37 +03:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
setExpirationDate: function(expireDate, shareId) {
|
2019-09-25 19:19:42 +03:00
|
|
|
this.model.saveLinkShare({ expireDate: expireDate, cid: shareId })
|
2018-07-19 11:04:37 +03:00
|
|
|
},
|
2015-08-21 16:40:50 +03:00
|
|
|
|
2019-02-26 21:29:15 +03:00
|
|
|
onChangeExpirationDate: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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')
|
2019-02-26 21:29:15 +03:00
|
|
|
},
|
|
|
|
|
2018-10-29 15:58:14 +03:00
|
|
|
/**
|
|
|
|
* get an array of sharees' share properties
|
|
|
|
*
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
getShareeList: function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
var shares = this.model.get('linkShares')
|
2018-10-29 15:58:14 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
if (!this.model.hasLinkShares()) {
|
|
|
|
return []
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var list = []
|
|
|
|
for (var index = 0; index < shares.length; index++) {
|
|
|
|
var share = this.getShareeObject(index)
|
2018-10-29 15:58:14 +03:00
|
|
|
// first empty {} is necessary, otherwise we get in trouble
|
|
|
|
// with references
|
2019-09-25 19:19:42 +03:00
|
|
|
list.push(_.extend({}, share))
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
return list
|
2018-10-29 15:58:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {OC.Share.Types.ShareInfo} shareInfo
|
|
|
|
* @returns {object}
|
|
|
|
*/
|
|
|
|
getShareeObject: function(shareIndex) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var share = this.model.get('linkShares')[shareIndex]
|
2018-10-29 15:58:14 +03:00
|
|
|
|
|
|
|
return _.extend({}, share, {
|
|
|
|
cid: share.id,
|
|
|
|
shareAllowed: true,
|
2018-11-07 17:14:29 +03:00
|
|
|
linkShareLabel: share.label ? share.label : t('core', 'Share link'),
|
2018-10-29 15:58:14 +03:00
|
|
|
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-11-26 20:37:58 +03:00
|
|
|
linkShareCreationDate: t('core', 'Created on {time}', { time: moment(share.stime * 1000).format('LLLL') })
|
2018-10-29 15:58:14 +03:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
getPopoverObject: function(share) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var publicUploadRWChecked = ''
|
|
|
|
var publicUploadRChecked = ''
|
|
|
|
var publicUploadWChecked = ''
|
2018-10-29 15:58:14 +03:00
|
|
|
|
|
|
|
switch (this.model.linkSharePermissions(share.id)) {
|
2019-09-25 19:19:42 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-10-29 15:58:14 +03:00
|
|
|
if (hasExpireDate) {
|
2019-09-25 19:19:42 +03:00
|
|
|
expireDate = moment(share.expiration, 'YYYY-MM-DD').format('DD-MM-YYYY')
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var isTalkEnabled = OC.appswebroots['spreed'] !== undefined
|
|
|
|
var sendPasswordByTalk = share.sendPasswordByTalk
|
2018-10-15 18:09:46 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var hideDownload = share.hideDownload
|
2018-10-29 15:58:14 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var maxDate = null
|
2018-10-29 15:58:14 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
if (hasExpireDate) {
|
|
|
|
if (isExpirationEnforced) {
|
2018-10-29 15:58:14 +03:00
|
|
|
// TODO: hack: backend returns string instead of integer
|
2019-09-25 19:19:42 +03:00
|
|
|
var shareTime = share.stime
|
2018-10-29 15:58:14 +03:00
|
|
|
if (_.isNumber(shareTime)) {
|
2019-09-25 19:19:42 +03:00
|
|
|
shareTime = new Date(shareTime * 1000)
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
|
|
|
if (!shareTime) {
|
2019-09-25 19:19:42 +03:00
|
|
|
shareTime = new Date() // now
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
shareTime = OC.Util.stripTime(shareTime).getTime()
|
|
|
|
maxDate = new Date(shareTime + defaultExpireDays * 24 * 3600 * 1000)
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
cid: share.id,
|
|
|
|
shareLinkURL: share.url,
|
|
|
|
passwordPlaceholder: isPasswordSet ? PASSWORD_PLACEHOLDER : PASSWORD_PLACEHOLDER_MESSAGE,
|
|
|
|
isPasswordSet: isPasswordSet || isPasswordEnabledByDefault || isPasswordEnforced,
|
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,
|
|
|
|
hideDownload: hideDownload,
|
2019-09-25 19:19:42 +03:00
|
|
|
isExpirationEnforced: isExpirationEnforced
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onUnshare: function(event) {
|
2019-09-25 19:19:42 +03:00
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
|
|
|
var self = this
|
|
|
|
var $element = $(event.target)
|
2018-10-29 15:58:14 +03:00
|
|
|
if (!$element.is('a')) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$element = $element.closest('a')
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var $loading = $element.find('.icon-loading-small').eq(0)
|
|
|
|
if (!$loading.hasClass('hidden')) {
|
2018-10-29 15:58:14 +03:00
|
|
|
// in process
|
2019-09-25 19:19:42 +03:00
|
|
|
return false
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
$loading.removeClass('hidden')
|
2018-10-29 15:58:14 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var $li = $element.closest('li[data-share-id]')
|
2018-10-29 15:58:14 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
var shareId = $li.data('share-id')
|
2018-10-29 15:58:14 +03:00
|
|
|
|
|
|
|
self.model.removeShare(shareId, {
|
|
|
|
success: function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
$li.remove()
|
2018-10-29 15:58:14 +03:00
|
|
|
self.render()
|
|
|
|
},
|
|
|
|
error: function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
$loading.addClass('hidden')
|
|
|
|
OC.Notification.showTemporary(t('core', 'Could not unshare'))
|
2018-10-29 15:58:14 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
2018-10-29 15:58:14 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2015-08-21 16:40:50 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.Share.ShareDialogLinkShareView = ShareDialogLinkShareView
|
2015-08-21 16:40:50 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
})()
|