2015-08-21 15:40:50 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
if (!OC.Share) {
|
|
|
|
OC.Share = {};
|
|
|
|
}
|
|
|
|
|
2015-10-16 11:55:23 +02:00
|
|
|
var PASSWORD_PLACEHOLDER = '**********';
|
|
|
|
var PASSWORD_PLACEHOLDER_MESSAGE = t('core', 'Choose a password for the public link');
|
|
|
|
|
2015-08-21 15:40:50 +02:00
|
|
|
var TEMPLATE =
|
2015-08-21 20:29:12 +02:00
|
|
|
'{{#if shareAllowed}}' +
|
|
|
|
'<span class="icon-loading-small hidden"></span>' +
|
2015-10-16 10:54:45 +02:00
|
|
|
'<input type="checkbox" name="linkCheckbox" id="linkCheckbox-{{cid}}" class="checkbox linkCheckbox" value="1" {{#if isLinkShare}}checked="checked"{{/if}} />' +
|
|
|
|
'<label for="linkCheckbox-{{cid}}">{{linkShareLabel}}</label>' +
|
2015-08-21 20:29:12 +02:00
|
|
|
'<br />' +
|
2015-10-16 10:54:45 +02:00
|
|
|
'<label for="linkText-{{cid}}" class="hidden-visually">{{urlLabel}}</label>' +
|
|
|
|
'<input id="linkText-{{cid}}" class="linkText {{#unless isLinkShare}}hidden{{/unless}}" type="text" readonly="readonly" value="{{shareLinkURL}}" />' +
|
2015-09-03 15:53:17 +02:00
|
|
|
' {{#if showPasswordCheckBox}}' +
|
2015-10-16 10:54:45 +02:00
|
|
|
'<input type="checkbox" name="showPassword" id="showPassword-{{cid}}" class="checkbox showPasswordCheckbox" {{#if isPasswordSet}}checked="checked"{{/if}} value="1" />' +
|
|
|
|
'<label for="showPassword-{{cid}}">{{enablePasswordLabel}}</label>' +
|
2015-09-03 15:53:17 +02:00
|
|
|
' {{/if}}' +
|
2015-10-16 10:54:45 +02:00
|
|
|
'<div id="linkPass" class="linkPass {{#unless isPasswordSet}}hidden{{/unless}}">' +
|
|
|
|
' <label for="linkPassText-{{cid}}" class="hidden-visually">{{passwordLabel}}</label>' +
|
|
|
|
' <input id="linkPassText-{{cid}}" class="linkPassText" type="password" placeholder="{{passwordPlaceholder}}" />' +
|
2015-08-21 15:40:50 +02:00
|
|
|
' <span class="icon-loading-small hidden"></span>' +
|
2015-08-21 20:29:12 +02:00
|
|
|
'</div>' +
|
2015-08-21 15:40:50 +02:00
|
|
|
' {{#if publicUpload}}' +
|
2015-09-14 00:43:11 +02:00
|
|
|
'<div id="allowPublicUploadWrapper">' +
|
2015-08-21 20:29:12 +02:00
|
|
|
' <span class="icon-loading-small hidden"></span>' +
|
2015-10-16 10:54:45 +02:00
|
|
|
' <input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload-{{cid}}" class="checkbox publicUploadCheckbox" {{{publicUploadChecked}}} />' +
|
|
|
|
'<label for="sharingDialogAllowPublicUpload-{{cid}}">{{publicUploadLabel}}</label>' +
|
2015-08-21 20:29:12 +02:00
|
|
|
'</div>' +
|
2015-08-21 15:40:50 +02:00
|
|
|
' {{/if}}' +
|
|
|
|
' {{#if mailPublicNotificationEnabled}}' +
|
2015-09-14 18:24:58 +02:00
|
|
|
'<form id="emailPrivateLink" class="emailPrivateLinkForm">' +
|
2015-10-16 10:54:45 +02:00
|
|
|
' <input id="email" class="emailField" value="" placeholder="{{mailPrivatePlaceholder}}" type="text" />' +
|
|
|
|
' <input id="emailButton" class="emailButton" type="submit" value="{{mailButtonText}}" />' +
|
2015-08-21 20:29:12 +02:00
|
|
|
'</form>' +
|
2015-08-21 15:40:50 +02:00
|
|
|
' {{/if}}' +
|
2015-08-21 20:29:12 +02:00
|
|
|
'{{else}}' +
|
2015-10-16 10:54:45 +02:00
|
|
|
// FIXME: this doesn't belong in this view
|
2015-12-07 16:53:56 +01:00
|
|
|
'{{#if noSharingPlaceholder}}<input id="shareWith-{{cid}}" class="shareWithField" type="text" placeholder="{{noSharingPlaceholder}}" disabled="disabled"/>{{/if}}' +
|
2015-08-21 20:29:12 +02:00
|
|
|
'{{/if}}'
|
2015-08-21 15:40:50 +02: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 {Function} **/
|
|
|
|
_template: undefined,
|
|
|
|
|
|
|
|
/** @type {boolean} **/
|
|
|
|
showLink: true,
|
|
|
|
|
2015-09-14 18:24:58 +02:00
|
|
|
events: {
|
2015-10-16 10:54:45 +02:00
|
|
|
'submit .emailPrivateLinkForm': '_onEmailPrivateLink',
|
|
|
|
'focusout input.linkPassText': 'onPasswordEntered',
|
|
|
|
'keyup input.linkPassText': 'onPasswordKeyUp',
|
|
|
|
'click .linkCheckbox': 'onLinkCheckBoxChange',
|
|
|
|
'click .linkText': 'onLinkTextClick',
|
|
|
|
'change .publicUploadCheckbox': 'onAllowPublicUploadChange',
|
|
|
|
'click .showPasswordCheckbox': 'onShowPasswordClick'
|
2015-09-14 18:24:58 +02:00
|
|
|
},
|
|
|
|
|
2015-08-21 15:40:50 +02: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();
|
|
|
|
});
|
|
|
|
|
2015-09-12 14:21:14 +02:00
|
|
|
this.model.on('change:linkShare', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
|
|
|
|
2015-08-21 15:40:50 +02:00
|
|
|
if(!_.isUndefined(options.configModel)) {
|
|
|
|
this.configModel = options.configModel;
|
|
|
|
} else {
|
2015-08-24 23:20:01 +02:00
|
|
|
throw 'missing OC.Share.ShareConfigModel';
|
2015-08-21 15:40:50 +02:00
|
|
|
}
|
2015-09-12 14:21:14 +02:00
|
|
|
|
2015-10-16 10:54:45 +02:00
|
|
|
_.bindAll(
|
|
|
|
this,
|
|
|
|
'_onEmailPrivateLink',
|
|
|
|
'onLinkCheckBoxChange',
|
|
|
|
'onPasswordEntered',
|
|
|
|
'onPasswordKeyUp',
|
|
|
|
'onLinkTextClick',
|
|
|
|
'onShowPasswordClick',
|
|
|
|
'onAllowPublicUploadChange'
|
|
|
|
);
|
2015-09-12 14:21:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onLinkCheckBoxChange: function() {
|
2015-10-16 10:54:45 +02:00
|
|
|
var $checkBox = this.$el.find('.linkCheckbox');
|
2015-09-12 14:21:14 +02:00
|
|
|
var $loading = $checkBox.siblings('.icon-loading-small');
|
|
|
|
if(!$loading.hasClass('hidden')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($checkBox.is(':checked')) {
|
|
|
|
if(this.configModel.get('enforcePasswordForPublicLink') === false) {
|
|
|
|
$loading.removeClass('hidden');
|
2015-09-14 12:48:01 +02:00
|
|
|
// this will create it
|
|
|
|
this.model.saveLinkShare();
|
2015-09-12 14:21:14 +02:00
|
|
|
} else {
|
2015-10-16 10:54:45 +02:00
|
|
|
this.$el.find('.linkPass').slideToggle(OC.menuSpeed);
|
|
|
|
this.$el.find('.linkPassText').focus();
|
2015-09-12 14:21:14 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-16 15:54:27 +02:00
|
|
|
$loading.removeClass('hidden');
|
2015-10-04 10:28:58 +02:00
|
|
|
if (this.model.get('linkShare').isLinkShare) {
|
|
|
|
this.model.removeLinkShare();
|
|
|
|
} else {
|
2015-10-16 10:54:45 +02:00
|
|
|
this.$el.find('.linkPass').slideToggle(OC.menuSpeed);
|
2015-10-04 10:28:58 +02:00
|
|
|
}
|
2015-09-12 14:21:14 +02:00
|
|
|
}
|
2015-08-21 15:40:50 +02:00
|
|
|
},
|
|
|
|
|
2015-09-12 15:53:05 +02:00
|
|
|
onLinkTextClick: function() {
|
2015-10-26 12:49:52 +01:00
|
|
|
var $el = this.$el.find('.linkText');
|
|
|
|
$el.focus();
|
|
|
|
$el.select();
|
2015-09-12 15:53:05 +02:00
|
|
|
},
|
|
|
|
|
2015-09-12 17:02:03 +02:00
|
|
|
onShowPasswordClick: function() {
|
2015-10-16 10:54:45 +02:00
|
|
|
this.$el.find('.linkPass').slideToggle(OC.menuSpeed);
|
|
|
|
if(!this.$el.find('.showPasswordCheckbox').is(':checked')) {
|
2015-09-14 12:48:01 +02:00
|
|
|
this.model.setPassword('');
|
|
|
|
this.model.saveLinkShare();
|
2015-09-12 17:02:03 +02:00
|
|
|
} else {
|
2015-10-16 10:54:45 +02:00
|
|
|
this.$el.find('.linkPassText').focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onPasswordKeyUp: function(event) {
|
|
|
|
if(event.keyCode == 13) {
|
|
|
|
this.onPasswordEntered();
|
2015-09-12 17:02:03 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onPasswordEntered: function() {
|
2015-09-29 15:30:01 +02:00
|
|
|
var self = this;
|
2015-10-16 10:54:45 +02:00
|
|
|
var $loading = this.$el.find('.linkPass .icon-loading-small');
|
2015-09-29 15:30:01 +02:00
|
|
|
if (!$loading.hasClass('hidden')) {
|
|
|
|
// still in process
|
|
|
|
return;
|
|
|
|
}
|
2015-10-16 10:54:45 +02:00
|
|
|
var $input = this.$el.find('.linkPassText');
|
2015-09-29 15:30:01 +02:00
|
|
|
$input.removeClass('error');
|
|
|
|
var password = $input.val();
|
2015-10-16 11:55:23 +02:00
|
|
|
// in IE9 the password might be the placeholder due to bugs in the placeholders polyfill
|
|
|
|
if(password === '' || password === PASSWORD_PLACEHOLDER || password === PASSWORD_PLACEHOLDER_MESSAGE) {
|
2015-09-12 17:02:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-29 15:30:01 +02:00
|
|
|
$loading
|
2015-09-12 17:02:03 +02:00
|
|
|
.removeClass('hidden')
|
|
|
|
.addClass('inlineblock');
|
|
|
|
|
2015-09-14 12:48:01 +02:00
|
|
|
this.model.setPassword(password);
|
2015-09-29 15:30:01 +02:00
|
|
|
this.model.saveLinkShare({}, {
|
|
|
|
error: function(model, msg) {
|
|
|
|
$loading.removeClass('inlineblock').addClass('hidden');
|
|
|
|
$input.addClass('error');
|
|
|
|
$input.attr('title', msg);
|
|
|
|
$input.tooltip({placement: 'bottom', trigger: 'manual'});
|
|
|
|
$input.tooltip('show');
|
|
|
|
}
|
|
|
|
});
|
2015-09-12 17:02:03 +02:00
|
|
|
},
|
|
|
|
|
2015-09-14 01:01:02 +02:00
|
|
|
onAllowPublicUploadChange: function() {
|
2015-10-16 10:54:45 +02:00
|
|
|
var $checkbox = this.$('.publicUploadCheckbox');
|
|
|
|
$checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock');
|
|
|
|
this.model.setPublicUpload($checkbox.is(':checked'));
|
2015-09-14 12:48:01 +02:00
|
|
|
this.model.saveLinkShare();
|
2015-09-14 01:01:02 +02:00
|
|
|
},
|
|
|
|
|
2015-09-14 18:24:58 +02:00
|
|
|
_onEmailPrivateLink: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2015-10-16 10:54:45 +02:00
|
|
|
var $emailField = this.$el.find('.emailField');
|
|
|
|
var $emailButton = this.$el.find('.emailButton');
|
|
|
|
var email = $emailField.val();
|
2015-09-14 18:24:58 +02:00
|
|
|
if (email !== '') {
|
|
|
|
$emailField.prop('disabled', true);
|
|
|
|
$emailButton.prop('disabled', true);
|
|
|
|
$emailField.val(t('core', 'Sending ...'));
|
2015-10-07 17:50:51 +02:00
|
|
|
this.model.sendEmailPrivateLink(email).done(function() {
|
2015-09-14 18:24:58 +02:00
|
|
|
$emailField.css('font-weight', 'bold').val(t('core','Email sent'));
|
|
|
|
setTimeout(function() {
|
2015-10-07 17:50:51 +02:00
|
|
|
$emailField.val('');
|
|
|
|
$emailField.css('font-weight', 'normal');
|
2015-09-14 18:24:58 +02:00
|
|
|
$emailField.prop('disabled', false);
|
|
|
|
$emailButton.prop('disabled', false);
|
|
|
|
}, 2000);
|
2015-10-07 17:50:51 +02:00
|
|
|
}).fail(function() {
|
|
|
|
$emailField.val(email);
|
|
|
|
$emailField.css('font-weight', 'normal');
|
|
|
|
$emailField.prop('disabled', false);
|
|
|
|
$emailButton.prop('disabled', false);
|
2015-09-14 18:24:58 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-08-21 15:40:50 +02:00
|
|
|
render: function() {
|
2015-08-21 20:29:12 +02:00
|
|
|
var linkShareTemplate = this.template();
|
2015-12-07 16:53:56 +01:00
|
|
|
var resharingAllowed = this.model.sharePermissionPossible();
|
2015-08-21 20:29:12 +02:00
|
|
|
|
2015-12-07 16:53:56 +01:00
|
|
|
if(!resharingAllowed
|
2015-08-21 15:40:50 +02:00
|
|
|
|| !this.showLink
|
|
|
|
|| !this.configModel.isShareWithLinkAllowed())
|
|
|
|
{
|
2015-12-07 16:53:56 +01: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 15:40:50 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
var publicUpload =
|
|
|
|
this.model.isFolder()
|
2015-09-01 12:43:04 +02:00
|
|
|
&& this.model.createPermissionPossible()
|
2015-08-21 15:40:50 +02:00
|
|
|
&& this.configModel.isPublicUploadEnabled();
|
|
|
|
|
|
|
|
var publicUploadChecked = '';
|
|
|
|
if(this.model.isPublicUploadAllowed()) {
|
|
|
|
publicUploadChecked = 'checked="checked"';
|
|
|
|
}
|
|
|
|
|
2015-09-03 15:53:17 +02:00
|
|
|
var isLinkShare = this.model.get('linkShare').isLinkShare;
|
|
|
|
var isPasswordSet = !!this.model.get('linkShare').password;
|
|
|
|
var showPasswordCheckBox = isLinkShare
|
|
|
|
&& ( !this.configModel.get('enforcePasswordForPublicLink')
|
|
|
|
|| !this.model.get('linkShare').password);
|
|
|
|
|
2015-08-24 23:20:01 +02:00
|
|
|
this.$el.html(linkShareTemplate({
|
2015-10-16 10:54:45 +02:00
|
|
|
cid: this.cid,
|
2015-08-21 20:29:12 +02:00
|
|
|
shareAllowed: true,
|
2015-09-03 15:53:17 +02:00
|
|
|
isLinkShare: isLinkShare,
|
|
|
|
shareLinkURL: this.model.get('linkShare').link,
|
2015-08-21 15:40:50 +02:00
|
|
|
linkShareLabel: t('core', 'Share link'),
|
|
|
|
urlLabel: t('core', 'Link'),
|
|
|
|
enablePasswordLabel: t('core', 'Password protect'),
|
|
|
|
passwordLabel: t('core', 'Password'),
|
2015-10-16 11:55:23 +02:00
|
|
|
passwordPlaceholder: isPasswordSet ? PASSWORD_PLACEHOLDER : PASSWORD_PLACEHOLDER_MESSAGE,
|
2015-09-03 15:53:17 +02:00
|
|
|
isPasswordSet: isPasswordSet,
|
|
|
|
showPasswordCheckBox: showPasswordCheckBox,
|
|
|
|
publicUpload: publicUpload && isLinkShare,
|
2015-08-21 15:40:50 +02:00
|
|
|
publicUploadChecked: publicUploadChecked,
|
|
|
|
publicUploadLabel: t('core', 'Allow editing'),
|
2015-09-03 15:53:17 +02:00
|
|
|
mailPublicNotificationEnabled: isLinkShare && this.configModel.isMailPublicNotificationEnabled(),
|
2015-08-21 15:40:50 +02:00
|
|
|
mailPrivatePlaceholder: t('core', 'Email link to person'),
|
|
|
|
mailButtonText: t('core', 'Send')
|
|
|
|
}));
|
|
|
|
|
2015-10-16 10:54:45 +02:00
|
|
|
var $emailField = this.$el.find('.emailField');
|
2015-09-14 18:34:56 +02:00
|
|
|
if (isLinkShare && $emailField.length !== 0) {
|
|
|
|
$emailField.autocomplete({
|
|
|
|
minLength: 1,
|
|
|
|
source: function (search, response) {
|
|
|
|
$.get(
|
|
|
|
OC.generateUrl('core/ajax/share.php'), {
|
|
|
|
fetch: 'getShareWithEmail',
|
|
|
|
search: search.term
|
|
|
|
}, function(result) {
|
|
|
|
if (result.status == 'success' && result.data.length > 0) {
|
|
|
|
response(result.data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
select: function( event, item ) {
|
|
|
|
$emailField.val(item.item.email);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.data("ui-autocomplete")._renderItem = function( ul, item ) {
|
|
|
|
return $('<li>')
|
|
|
|
.append('<a>' + escapeHTML(item.displayname) + "<br>" + escapeHTML(item.email) + '</a>' )
|
|
|
|
.appendTo( ul );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-10-16 11:55:23 +02:00
|
|
|
// TODO drop with IE8 drop
|
|
|
|
if($('html').hasClass('ie8')) {
|
|
|
|
this.$el.find('#linkPassText').removeAttr('placeholder');
|
|
|
|
this.$el.find('#linkPassText').val('');
|
|
|
|
}
|
|
|
|
|
2015-09-14 18:24:58 +02:00
|
|
|
this.delegateEvents();
|
|
|
|
|
2015-08-21 15:40:50 +02:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {Function} from Handlebars
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
template: function () {
|
|
|
|
if (!this._template) {
|
|
|
|
this._template = Handlebars.compile(TEMPLATE);
|
|
|
|
}
|
|
|
|
return this._template;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
OC.Share.ShareDialogLinkShareView = ShareDialogLinkShareView;
|
|
|
|
|
|
|
|
})();
|