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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
if (!OC.Share) {
|
|
|
|
OC.Share = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
var TEMPLATE =
|
2015-08-21 18:29:12 +00:00
|
|
|
'{{#if shareAllowed}}' +
|
|
|
|
'<span class="icon-loading-small hidden"></span>' +
|
2015-09-03 13:53:17 +00:00
|
|
|
'<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" {{#if isLinkShare}}checked="checked"{{/if}} /><label for="linkCheckbox">{{linkShareLabel}}</label>' +
|
2015-08-21 18:29:12 +00:00
|
|
|
'<br />' +
|
|
|
|
'<label for="linkText" class="hidden-visually">{{urlLabel}}</label>' +
|
2015-09-03 13:53:17 +00:00
|
|
|
'<input id="linkText" {{#unless isLinkShare}}class="hidden"{{/unless}} type="text" readonly="readonly" value="{{shareLinkURL}}" />' +
|
|
|
|
' {{#if showPasswordCheckBox}}' +
|
|
|
|
'<input type="checkbox" name="showPassword" id="showPassword" {{#if isPasswordSet}}checked="checked"{{/if}} value="1" /><label for="showPassword">{{enablePasswordLabel}}</label>' +
|
|
|
|
' {{/if}}' +
|
2015-09-12 12:21:14 +00:00
|
|
|
'<div id="linkPass" {{#unless isPasswordSet}}class="hidden"{{/unless}}>' +
|
2015-08-21 18:29:12 +00:00
|
|
|
' <label for="linkPassText" class="hidden-visually">{{passwordLabel}}</label>' +
|
2015-09-03 13:53:17 +00:00
|
|
|
' <input id="linkPassText" type="password" placeholder="{{passwordPlaceholder}}" />' +
|
2015-08-21 13:40:50 +00:00
|
|
|
' <span class="icon-loading-small hidden"></span>' +
|
2015-08-21 18:29:12 +00:00
|
|
|
'</div>' +
|
2015-08-21 13:40:50 +00:00
|
|
|
' {{#if publicUpload}}' +
|
2015-09-13 22:43:11 +00:00
|
|
|
'<div id="allowPublicUploadWrapper">' +
|
2015-08-21 18:29:12 +00:00
|
|
|
' <span class="icon-loading-small hidden"></span>' +
|
|
|
|
' <input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload" {{{publicUploadChecked}}} />' +
|
2015-09-15 14:14:29 +00:00
|
|
|
'<label for="sharingDialogAllowPublicUpload">{{publicUploadLabel}}</label>' +
|
2015-08-21 18:29:12 +00:00
|
|
|
'</div>' +
|
2015-08-21 13:40:50 +00:00
|
|
|
' {{/if}}' +
|
|
|
|
' {{#if mailPublicNotificationEnabled}}' +
|
2015-09-14 16:24:58 +00:00
|
|
|
'<form id="emailPrivateLink" class="emailPrivateLinkForm">' +
|
2015-09-03 13:53:17 +00:00
|
|
|
' <input id="email" value="" placeholder="{{mailPrivatePlaceholder}}" type="text" />' +
|
|
|
|
' <input id="emailButton" type="submit" value="{{mailButtonText}}" />' +
|
2015-08-21 18:29:12 +00:00
|
|
|
'</form>' +
|
2015-08-21 13:40:50 +00:00
|
|
|
' {{/if}}' +
|
2015-08-21 18:29:12 +00:00
|
|
|
'{{else}}' +
|
|
|
|
'<input id="shareWith" type="text" placeholder="{{noSharingPlaceholder}}" disabled="disabled"/>' +
|
|
|
|
'{{/if}}'
|
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 {Function} **/
|
|
|
|
_template: undefined,
|
|
|
|
|
|
|
|
/** @type {boolean} **/
|
|
|
|
showLink: true,
|
|
|
|
|
2015-09-14 16:24:58 +00:00
|
|
|
events: {
|
|
|
|
'submit .emailPrivateLinkForm': '_onEmailPrivateLink'
|
|
|
|
},
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2015-09-12 12:21:14 +00:00
|
|
|
this.model.on('change:linkShare', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2015-09-13 23:01:02 +00:00
|
|
|
_.bindAll(this, 'onLinkCheckBoxChange', 'onPasswordEntered',
|
|
|
|
'onShowPasswordClick', 'onAllowPublicUploadChange');
|
2015-09-12 12:21:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onLinkCheckBoxChange: function() {
|
|
|
|
var $checkBox = this.$el.find('#linkCheckbox');
|
|
|
|
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 10:48:01 +00:00
|
|
|
// this will create it
|
|
|
|
this.model.saveLinkShare();
|
2015-09-12 12:21:14 +00:00
|
|
|
} else {
|
|
|
|
this.$el.find('#linkPass').slideToggle(OC.menuSpeed);
|
|
|
|
// TODO drop with IE8 drop
|
|
|
|
if($('html').hasClass('ie8')) {
|
|
|
|
this.$el.find('#linkPassText').attr('placeholder', null);
|
|
|
|
this.$el.find('#linkPassText').val('');
|
|
|
|
}
|
|
|
|
this.$el.find('#linkPassText').focus();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.model.removeLinkShare();
|
|
|
|
}
|
2015-08-21 13:40:50 +00:00
|
|
|
},
|
|
|
|
|
2015-09-12 13:53:05 +00:00
|
|
|
onLinkTextClick: function() {
|
|
|
|
this.focus();
|
|
|
|
this.select();
|
|
|
|
},
|
|
|
|
|
2015-09-12 15:02:03 +00:00
|
|
|
onShowPasswordClick: function() {
|
|
|
|
this.$el.find('#linkPass').slideToggle(OC.menuSpeed);
|
|
|
|
if(!this.$el.find('#showPassword').is(':checked')) {
|
2015-09-14 10:48:01 +00:00
|
|
|
this.model.setPassword('');
|
|
|
|
this.model.saveLinkShare();
|
2015-09-12 15:02:03 +00:00
|
|
|
} else {
|
|
|
|
this.$el.find('#linkPassText').focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onPasswordEntered: function() {
|
|
|
|
var password = this.$el.find('#linkPassText').val();
|
|
|
|
if(password === '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$el.find('#linkPass .icon-loading-small')
|
|
|
|
.removeClass('hidden')
|
|
|
|
.addClass('inlineblock');
|
|
|
|
|
2015-09-14 10:48:01 +00:00
|
|
|
this.model.setPassword(password);
|
|
|
|
this.model.saveLinkShare();
|
2015-09-12 15:02:03 +00:00
|
|
|
},
|
|
|
|
|
2015-09-13 23:01:02 +00:00
|
|
|
onAllowPublicUploadChange: function() {
|
|
|
|
this.$el.find('#sharingDialogAllowPublicUpload')
|
|
|
|
.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock');
|
|
|
|
this.model.setPublicUpload(this.$el.find('#sharingDialogAllowPublicUpload').is(':checked'));
|
2015-09-14 10:48:01 +00:00
|
|
|
this.model.saveLinkShare();
|
2015-09-13 23:01:02 +00:00
|
|
|
},
|
|
|
|
|
2015-09-14 16:24:58 +00:00
|
|
|
_onEmailPrivateLink: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var $emailField = this.$el.find('#email');
|
|
|
|
var $emailButton = this.$el.find('#emailButton');
|
|
|
|
var email = this.$el.find('#email').val();
|
|
|
|
if (email !== '') {
|
|
|
|
$emailField.prop('disabled', true);
|
|
|
|
$emailButton.prop('disabled', true);
|
|
|
|
$emailField.val(t('core', 'Sending ...'));
|
|
|
|
this.model.sendEmailPrivateLink(email).then(function() {
|
|
|
|
$emailField.css('font-weight', 'bold').val(t('core','Email sent'));
|
|
|
|
setTimeout(function() {
|
|
|
|
$emailField.css('font-weight', 'normal').val('');
|
|
|
|
$emailField.prop('disabled', false);
|
|
|
|
$emailButton.prop('disabled', false);
|
|
|
|
}, 2000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-08-21 13:40:50 +00:00
|
|
|
render: function() {
|
2015-08-21 18:29:12 +00:00
|
|
|
var linkShareTemplate = this.template();
|
|
|
|
|
2015-09-01 10:43:04 +00:00
|
|
|
if( !this.model.sharePermissionPossible()
|
2015-08-21 13:40:50 +00:00
|
|
|
|| !this.showLink
|
|
|
|
|| !this.configModel.isShareWithLinkAllowed())
|
|
|
|
{
|
2015-08-24 21:20:01 +00:00
|
|
|
this.$el.html(linkShareTemplate({
|
2015-08-21 18:29:12 +00:00
|
|
|
shareAllowed: false,
|
|
|
|
noSharingPlaceholder: t('core', 'Resharing is not allowed')
|
|
|
|
}));
|
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();
|
|
|
|
|
|
|
|
var publicUploadChecked = '';
|
|
|
|
if(this.model.isPublicUploadAllowed()) {
|
|
|
|
publicUploadChecked = 'checked="checked"';
|
|
|
|
}
|
|
|
|
|
2015-09-03 13:53:17 +00: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 21:20:01 +00:00
|
|
|
this.$el.html(linkShareTemplate({
|
2015-08-21 18:29:12 +00:00
|
|
|
shareAllowed: true,
|
2015-09-03 13:53:17 +00:00
|
|
|
isLinkShare: isLinkShare,
|
|
|
|
shareLinkURL: this.model.get('linkShare').link,
|
2015-08-21 13:40:50 +00:00
|
|
|
linkShareLabel: t('core', 'Share link'),
|
|
|
|
urlLabel: t('core', 'Link'),
|
|
|
|
enablePasswordLabel: t('core', 'Password protect'),
|
|
|
|
passwordLabel: t('core', 'Password'),
|
2015-09-03 13:53:17 +00:00
|
|
|
passwordPlaceholder: isPasswordSet ? '**********' : t('core', 'Choose a password for the public link'),
|
|
|
|
isPasswordSet: isPasswordSet,
|
|
|
|
showPasswordCheckBox: showPasswordCheckBox,
|
|
|
|
publicUpload: publicUpload && isLinkShare,
|
2015-08-21 13:40:50 +00:00
|
|
|
publicUploadChecked: publicUploadChecked,
|
|
|
|
publicUploadLabel: t('core', 'Allow editing'),
|
2015-09-03 13:53:17 +00:00
|
|
|
mailPublicNotificationEnabled: isLinkShare && this.configModel.isMailPublicNotificationEnabled(),
|
2015-08-21 13:40:50 +00:00
|
|
|
mailPrivatePlaceholder: t('core', 'Email link to person'),
|
|
|
|
mailButtonText: t('core', 'Send')
|
|
|
|
}));
|
|
|
|
|
2015-09-14 10:48:01 +00:00
|
|
|
// TODO: move this to delegate events instead
|
2015-09-15 08:27:33 +00:00
|
|
|
this.$el.find('#linkCheckbox').click(this.onLinkCheckBoxChange);
|
2015-09-13 23:01:02 +00:00
|
|
|
this.$el.find('#sharingDialogAllowPublicUpload').change(this.onAllowPublicUploadChange);
|
2015-09-12 13:53:05 +00:00
|
|
|
this.$el.find('#linkText').click(this.onLinkTextClick);
|
2015-09-12 15:02:03 +00:00
|
|
|
this.$el.find('#showPassword').click(this.onShowPasswordClick);
|
|
|
|
this.$el.find('#linkPassText').focusout(this.onPasswordEntered);
|
|
|
|
var view = this;
|
|
|
|
this.$el.find('#linkPassText').keyup(function(event) {
|
|
|
|
if(event.keyCode == 13) {
|
|
|
|
view.onPasswordEntered();
|
|
|
|
}
|
|
|
|
});
|
2015-09-12 12:21:14 +00:00
|
|
|
|
2015-09-14 16:34:56 +00:00
|
|
|
var $emailField = this.$el.find('#email');
|
|
|
|
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-09-14 16:24:58 +00:00
|
|
|
this.delegateEvents();
|
|
|
|
|
2015-08-21 13:40:50 +00: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;
|
|
|
|
|
|
|
|
})();
|