diff --git a/core/js/share.js b/core/js/share.js
index db35a2e111..8d25749a10 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -382,11 +382,13 @@ OC.Share = _.extend(OC.Share, {
});
},
showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) {
+ var configModel = new OC.Share.ShareConfigModel();
var attributes = {itemType: itemType, itemSource: itemSource, possiblePermissions: possiblePermissions};
- var itemModel = new OC.Share.ShareItemModel(attributes);
+ var itemModel = new OC.Share.ShareItemModel(attributes, {configModel: configModel});
var dialogView = new OC.Share.ShareDialogView({
id: 'dropdown',
model: itemModel,
+ configModel: configModel,
className: 'drop shareDropDown',
attributes: {
'data-item-source-name': filename,
diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js
new file mode 100644
index 0000000000..371cc96df5
--- /dev/null
+++ b/core/js/shareconfigmodel.js
@@ -0,0 +1,54 @@
+/*
+ * 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 = {};
+ OC.Share.Types = {};
+ }
+
+ var ShareConfigModel = OC.Backbone.Model.extend({
+ defaults: {
+ publicUploadEnabled: false
+ },
+
+ /**
+ * @returns {boolean}
+ */
+ isPublicUploadEnabled: function() {
+ var publicUploadEnabled = $('#filestable').data('allow-public-upload');
+ return !_.isUndefined(publicUploadEnabled);
+ },
+
+ /**
+ * @returns {boolean}
+ */
+ isMailPublicNotificationEnabled: function() {
+ return $('input:hidden[name=mailPublicNotificationEnabled]').val() === 'yes';
+ },
+
+ /**
+ * @returns {boolean}
+ */
+ isDefaultExpireDateEnforced: function() {
+ return oc_appconfig.core.defaultExpireDateEnforced === true;
+ },
+
+ /**
+ * @returns {number}
+ */
+ getDefaultExpireDate: function () {
+ return oc_appconfig.core.defaultExpireDate;
+ }
+ });
+
+
+ OC.Share.ShareConfigModel = ShareConfigModel;
+})();
diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js
index 4ff4eb9a94..7b0af2bc84 100644
--- a/core/js/sharedialogview.js
+++ b/core/js/sharedialogview.js
@@ -24,7 +24,13 @@
'{{{remoteShareInfo}}}' +
'
' +
- '{{{linkShare}}}';
+ '{{#if shareAllowed}}' +
+ '{{{linkShare}}}' +
+ '{{else}}' +
+ '{{{noSharing}}}' +
+ '{{/if}}' +
+ '{{{expiration}}}'
+ ;
var TEMPLATE_RESHARER_INFO =
'' +
@@ -50,9 +56,37 @@
' ' +
' ' +
' ' +
- ' '
+ ' ' +
+ ' {{#if publicUpload}}' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ '
' +
+ ' {{/if}}' +
+ ' {{#if mailPublicNotificationEnabled}}' +
+ ' ' +
+ ' {{/if}}' +
+ ''
;
+ var TEMPLATE_NO_SHARING =
+ ''
+ ;
+
+ var TEMPLATE_EXPIRATION =
+ '' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' {{defaultExpireMessage}}' +
+ '
'
+ ;
+
/**
* @class OCA.Share.ShareDialogView
* @member {OC.Share.ShareItemModel} model
@@ -73,7 +107,10 @@
/** @type {string} **/
tagName: 'div',
- initialize: function() {
+ /** @type {OC.Share.ShareConfigModel} **/
+ configModel: undefined,
+
+ initialize: function(options) {
var view = this;
this.model.on('change', function() {
view.render();
@@ -82,6 +119,12 @@
this.model.on('fetchError', function() {
OC.Notification.showTemporary(t('core', 'Share details could not be loaded for this item.'));
});
+
+ if(!_.isUndefined(options.configModel)) {
+ this.configModel = options.configModel;
+ } else {
+ console.warn('missing OC.Share.ShareConfigModel');
+ }
},
render: function() {
@@ -92,7 +135,10 @@
resharerInfo: this._renderResharerInfo(),
sharePlaceholder: this._renderSharePlaceholderPart(),
remoteShareInfo: this._renderRemoteShareInfoPart(),
- linkShare: this._renderLinkSharePart()
+ linkShare: this._renderLinkSharePart(),
+ shareAllowed: this.model.hasSharePermission(),
+ noSharing: this._renderNoSharing(),
+ expiration: this._renderExpirationPart()
}));
return this;
@@ -155,14 +201,34 @@
_renderLinkSharePart: function() {
var linkShare = '';
- if(this._showLink && $('#allowShareWithLink').val() === 'yes') {
+ if( this.model.hasSharePermission()
+ && this._showLink
+ && $('#allowShareWithLink').val() === 'yes')
+ {
var linkShareTemplate = this._getLinkShareTemplate();
+
+ var publicUpload =
+ this.model.isFolder()
+ && this.model.hasCreatePermission()
+ && this.configModel.isPublicUploadEnabled();
+
+ var publicUploadChecked = '';
+ if(this.model.isPublicUploadAllowed) {
+ publicUploadChecked = 'checked="checked"';
+ }
+
linkShare = linkShareTemplate({
linkShareLabel: t('core', 'Share link'),
urlLabel: t('core', 'Link'),
enablePasswordLabel: t('core', 'Password protect'),
passwordLabel: t('core', 'Password'),
- passwordPlaceholder: t('core', 'Choose a password for the public link')
+ passwordPlaceholder: t('core', 'Choose a password for the public link'),
+ publicUpload: publicUpload,
+ publicUploadChecked: publicUploadChecked,
+ publicUploadLabel: t('core', 'Allow editing'),
+ mailPublicNotificationEnabled: this.configModel.isMailPublicNotificationEnabled(),
+ mailPrivatePlaceholder: t('core', 'Email link to person'),
+ mailButtonText: t('core', 'Send')
});
}
return linkShare;
@@ -176,6 +242,40 @@
return sharePlaceholder;
},
+ _renderNoSharing: function () {
+ var noSharing = '';
+ if(!this.model.hasSharePermission()) {
+ var noSharingTemplate = this._getTemplate('noSharing', TEMPLATE_NO_SHARING);
+ noSharing = noSharingTemplate({
+ placeholder: t('core', 'Resharing is not allowed')
+ });
+ }
+ return noSharing;
+ },
+
+ _renderExpirationPart: function() {
+ var expirationTemplate = this._getTemplate('expiration', TEMPLATE_EXPIRATION);
+
+ var defaultExpireMessage = '';
+ if(( this.model.isFolder() || this.model.isFile())
+ && this.configModel.isDefaultExpireDateEnforced()) {
+ defaultExpireMessage = t(
+ 'core',
+ 'The public link will expire no later than {days} days after it is created',
+ {'days': this.configModel.getDefaultExpireDate()}
+ );
+ }
+
+ var expiration = expirationTemplate({
+ setExpirationLabel: t('core', 'Set expiration date'),
+ expirationLabel: t('core', 'Expiration'),
+ expirationDatePlaceholder: t('core', 'Expiration date'),
+ defaultExpireMessage: defaultExpireMessage
+ });
+
+ return expiration;
+ },
+
/**
*
* @param {string} key - an identifier for the template
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index efce69f0f3..eb93b91ce9 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -53,7 +53,10 @@
* // FIXME: use OC Share API once #17143 is done
*/
var ShareItemModel = OC.Backbone.Model.extend({
- initialize: function() {
+ initialize: function(attributes, options) {
+ if(!_.isUndefined(options.configModel)) {
+ this.configModel = options.configModel;
+ }
this.fetch();
},
@@ -62,15 +65,24 @@
},
/**
- * @returns {boolean|jQuery}
+ * @returns {boolean}
*/
- isPublicUploadEnabled: function() {
- // FIXME: this really needs a better place
- var publicUploadEnabled = $('#filestable').data('allow-public-upload');
- if (_.isUndefined(publicUploadEnabled)) {
- publicUploadEnabled = 'no';
- }
- return publicUploadEnabled;
+ isPublicUploadAllowed: function() {
+ return this.get('allowPublicUploadStatus');
+ },
+
+ /**
+ * @returns {boolean}
+ */
+ isFolder: function() {
+ return this.get('itemType') === 'folder';
+ },
+
+ /**
+ * @returns {boolean}
+ */
+ isFile: function() {
+ return this.get('itemType') === 'file';
},
/**
@@ -134,7 +146,14 @@
* @returns {boolean}
*/
hasSharePermission: function() {
- return (this.getPermissions & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE;
+ return (this.getPermissions() & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE;
+ },
+
+ /**
+ * @returns {boolean}
+ */
+ hasCreatePermission: function() {
+ return (this.getPermissions() & OC.PERMISSION_CREATE) === OC.PERMISSION_CREATE;
},
fetch: function() {
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 65968f581f..cd3f0cbfb3 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -83,6 +83,7 @@ class Share extends Constants {
'supportedFileExtensions' => $supportedFileExtensions
);
if(count(self::$backendTypes) === 1) {
+ \OC_Util::addScript('core', 'shareconfigmodel');
\OC_Util::addScript('core', 'shareitemmodel');
\OC_Util::addScript('core', 'sharedialogview');
\OC_Util::addScript('core', 'share');