From edd163a6113664921a2fda730037dcf68bfe08ae Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 31 Jul 2015 00:07:41 +0200 Subject: refactor share dialog for multi-purpose use (dropdown, sidebar) and better maintainability --- core/js/sharedialogview.js | 253 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 core/js/sharedialogview.js (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js new file mode 100644 index 00000000000..cbab9694afe --- /dev/null +++ b/core/js/sharedialogview.js @@ -0,0 +1,253 @@ +/* + * 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_BASE = + '
' + + ' {{{resharerInfo}}}' + + ' ' + + '
' + + ' ' + + ' '+ + '
' + + // FIXME: find a good position for remoteShareInfo + ' {{{remoteShareInfo}}}' + + ' ' + + ' {{{linkShare}}}' + + '
'; + + var TEMPLATE_RESHARER_INFO = + '' + + ' {{#if avatarEnabled}}' + + '
' + + ' {{/if}}' + + ' {{sharedByText}}' + + '

'; + + var TEMPLATE_REMOTE_SHARE_INFO = + ''; + + var TEMPLATE_LINK_SHARE = + '' + ' ' + + ' {{#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 efce69f0f3e..eb93b91ce92 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 65968f581f5..cd3f0cbfb34 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'); -- cgit v1.2.3 From a57ff13a23ce06846160c1264369ff4b07619890 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 18 Aug 2015 12:13:08 +0200 Subject: move remaining global settings to configModel --- core/js/shareconfigmodel.js | 28 ++++++++++++++++++++++++++++ core/js/sharedialogview.js | 10 +++++----- 2 files changed, 33 insertions(+), 5 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index 371cc96df5e..857e356a351 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -19,6 +19,13 @@ publicUploadEnabled: false }, + /** + * @returns {boolean} + */ + areAvatarsEnabled: function() { + return oc_config.enable_avatars === true; + }, + /** * @returns {boolean} */ @@ -41,6 +48,27 @@ return oc_appconfig.core.defaultExpireDateEnforced === true; }, + /** + * @returns {boolean} + */ + isRemoteShareAllowed: function() { + return oc_appconfig.core.remoteShareAllowed; + }, + + /** + * @returns {boolean} + */ + isShareWithLinkAllowed: function() { + return $('#allowShareWithLink').val() === 'yes'; + }, + + /** + * @returns {string} + */ + getFederatedShareDocLink: function() { + return oc_appconfig.core.federatedCloudShareDoc; + }, + /** * @returns {number} */ diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 7b0af2bc84c..abf45a6bf45 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -182,17 +182,17 @@ } return reshareTemplate({ - avatarEnabled: oc_config.enable_avatars === true, + avatarEnabled: this.configModel.areAvatarsEnabled(), sharedByText: sharedByText }); }, _renderRemoteShareInfoPart: function() { var remoteShareInfo = ''; - if(oc_appconfig.core.remoteShareAllowed) { + if(this.configModel.isRemoteShareAllowed()) { var infoTemplate = this._getRemoteShareInfoTemplate(); remoteShareInfo = infoTemplate({ - docLink: oc_appconfig.core.federatedCloudShareDoc, + docLink: this.configModel.getFederatedShareDocLink(), tooltip: t('core', 'Share with people on other ownClouds using the syntax username@example.com/owncloud') }); } @@ -203,7 +203,7 @@ var linkShare = ''; if( this.model.hasSharePermission() && this._showLink - && $('#allowShareWithLink').val() === 'yes') + && this.configModel.isShareWithLinkAllowed()) { var linkShareTemplate = this._getLinkShareTemplate(); @@ -236,7 +236,7 @@ _renderSharePlaceholderPart: function () { var sharePlaceholder = t('core', 'Share with users or groups …'); - if (oc_appconfig.core.remoteShareAllowed) { + if (this.configModel.isRemoteShareAllowed()) { sharePlaceholder = t('core', 'Share with users, groups or remote users …'); } return sharePlaceholder; -- cgit v1.2.3 From 1bd6942be70da621da9acae56a23a39040ef24bf Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 18 Aug 2015 17:23:32 +0200 Subject: show tooltips and load avatar --- core/js/sharedialogview.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index abf45a6bf45..5e3fb8b8d97 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -41,7 +41,7 @@ '
'; var TEMPLATE_REMOTE_SHARE_INFO = - ''; var TEMPLATE_LINK_SHARE = @@ -141,6 +141,9 @@ expiration: this._renderExpirationPart() })); + this.$el.find('.hasTooltip').tooltip(); + this.$el.find('.avatar').avatar(this.model.getReshareOwner, 32); + return this; }, @@ -196,6 +199,7 @@ tooltip: t('core', 'Share with people on other ownClouds using the syntax username@example.com/owncloud') }); } + return remoteShareInfo; }, -- cgit v1.2.3 From dcb084a617b2ee24031a14bce8b8e9749c821b75 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 19 Aug 2015 00:04:16 +0200 Subject: split ShareDialogResharerInfoView from base view --- core/js/sharedialogresharerinfoview.js | 117 +++++++++++++++++++++++++++++++++ core/js/sharedialogview.js | 62 ++++++----------- core/js/shareitemmodel.js | 1 + lib/private/share/share.php | 1 + 4 files changed, 138 insertions(+), 43 deletions(-) create mode 100644 core/js/sharedialogresharerinfoview.js (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogresharerinfoview.js b/core/js/sharedialogresharerinfoview.js new file mode 100644 index 00000000000..3f996bb6d21 --- /dev/null +++ b/core/js/sharedialogresharerinfoview.js @@ -0,0 +1,117 @@ +/* + * 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 = + '' + + ' {{#if avatarEnabled}}' + + '
' + + ' {{/if}}' + + ' {{sharedByText}}' + + '

' + ; + + /** + * @class OCA.Share.ShareDialogView + * @member {OC.Share.ShareItemModel} model + * @member {jQuery} $el + * @memberof OCA.Sharing + * @classdesc + * + * Represents the GUI of the share dialogue + * + */ + var ShareDialogResharerInfoView = OC.Backbone.View.extend({ + /** @type {string} **/ + id: 'shareDialogResharerInfo', + + /** @type {string} **/ + tagName: 'div', + + /** @type {string} **/ + className: 'reshare', + + /** @type {OC.Share.ShareConfigModel} **/ + configModel: undefined, + + /** @type {Function} **/ + _template: undefined, + + initialize: function(options) { + var view = this; + + //FIXME: specific to reshares stuff + this.model.on('change', function() { + view.render(); + }); + + if(!_.isUndefined(options.configModel)) { + this.configModel = options.configModel; + } else { + console.warn('missing OC.Share.ShareConfigModel'); + } + }, + + render: function() { + if ( !this.model.hasReshare() + || !this.model.getReshareOwner() !== OC.currentUser) + { + this.$el.html(''); + return this; + } + + var reshareTemplate = this.template(); + var ownerDisplayName = this.model.getReshareOwnerDisplayname(); + var sharedByText = ''; + if (this.model.getReshareType() === OC.Share.SHARE_TYPE_GROUP) { + sharedByText = t( + 'core', + 'Shared with you and the group {group} by {owner}', + { + group: this.model.getReshareWith(), + owner: ownerDisplayName + } + ); + } else { + sharedByText = t( + 'core', + 'Shared with you by {owner}', + { owner: ownerDisplayName } + ); + } + + this.$el.html(reshareTemplate({ + avatarEnabled: this.configModel.areAvatarsEnabled(), + sharedByText: sharedByText + })); + + return this; + }, + + /** + * @returns {Function} from Handlebars + * @private + */ + template: function () { + if (!this._template) { + this._template = Handlebars.compile(TEMPLATE); + } + return this._template; + } + + }); + + OC.Share.ShareDialogResharerInfoView = ShareDialogResharerInfoView; + +})(); diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 5e3fb8b8d97..179d818e90f 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -32,14 +32,6 @@ '{{{expiration}}}' ; - var TEMPLATE_RESHARER_INFO = - '' + - ' {{#if avatarEnabled}}' + - '
' + - ' {{/if}}' + - ' {{sharedByText}}' + - '

'; - var TEMPLATE_REMOTE_SHARE_INFO = ''; @@ -110,6 +102,9 @@ /** @type {OC.Share.ShareConfigModel} **/ configModel: undefined, + /** @type {object} **/ + resharerInfoView: undefined, + initialize: function(options) { var view = this; this.model.on('change', function() { @@ -125,14 +120,26 @@ } else { console.warn('missing OC.Share.ShareConfigModel'); } + + var subViewOptions = { + model: this.model, + configModel: this.configModel + }; + + this.resharerInfoView = _.isUndefined(options.resharerInfoView) + ? new OC.Share.ShareDialogResharerInfoView(subViewOptions) + : options.resharerInfoView; + }, render: function() { var baseTemplate = this._getTemplate('base', TEMPLATE_BASE); + this.resharerInfoView.render(); + this.$el.html(baseTemplate({ shareLabel: t('core', 'Share'), - resharerInfo: this._renderResharerInfo(), + resharerInfo: this.resharerInfoView.el.innerHTML, sharePlaceholder: this._renderSharePlaceholderPart(), remoteShareInfo: this._renderRemoteShareInfoPart(), linkShare: this._renderLinkSharePart(), @@ -142,7 +149,9 @@ })); this.$el.find('.hasTooltip').tooltip(); - this.$el.find('.avatar').avatar(this.model.getReshareOwner, 32); + if(this.configModel.areAvatarsEnabled()) { + this.$el.find('.avatar').avatar(this.model.getReshareOwner, 32); + } return this; }, @@ -157,39 +166,6 @@ this._showLink = (typeof showLink === 'boolean') ? showLink : true; }, - _renderResharerInfo: function() { - var resharerInfo = ''; - if ( !this.model.hasReshare() - || !this.model.getReshareOwner() !== OC.currentUser) - { - return ''; - } - - var reshareTemplate = this._getReshareTemplate(); - var sharedByText = ''; - if (this.model.getReshareType() === OC.Share.SHARE_TYPE_GROUP) { - sharedByText = t( - 'core', - 'Shared with you and the group {group} by {owner}', - { - group: this.model.getReshareWith(), - owner: this.model.getReshareOwnerDisplayname() - } - ); - } else { - sharedByText = t( - 'core', - 'Shared with you by {owner}', - { owner: this.model.getReshareOwnerDisplayname() } - ); - } - - return reshareTemplate({ - avatarEnabled: this.configModel.areAvatarsEnabled(), - sharedByText: sharedByText - }); - }, - _renderRemoteShareInfoPart: function() { var remoteShareInfo = ''; if(this.configModel.isRemoteShareAllowed()) { diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index eb93b91ce92..0d2bce8b2ef 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -112,6 +112,7 @@ * @returns {string} */ getReshareOwnerDisplayname: function() { + return 'foo'; return this.get('reshare').displayname_owner; }, diff --git a/lib/private/share/share.php b/lib/private/share/share.php index cd3f0cbfb34..10d0480ab89 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -85,6 +85,7 @@ class Share extends Constants { if(count(self::$backendTypes) === 1) { \OC_Util::addScript('core', 'shareconfigmodel'); \OC_Util::addScript('core', 'shareitemmodel'); + \OC_Util::addScript('core', 'sharedialogresharerinfoview'); \OC_Util::addScript('core', 'sharedialogview'); \OC_Util::addScript('core', 'share'); \OC_Util::addStyle('core', 'share'); -- cgit v1.2.3 From 277b786886de7979fea308595e4cf658e85aacf7 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 21 Aug 2015 15:00:15 +0200 Subject: ShareDialogResharerInfoView improvements --- core/js/sharedialogresharerinfoview.js | 8 ++++---- core/js/sharedialogview.js | 8 ++++---- core/js/shareitemmodel.js | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogresharerinfoview.js b/core/js/sharedialogresharerinfoview.js index 3f996bb6d21..8970d857fc3 100644 --- a/core/js/sharedialogresharerinfoview.js +++ b/core/js/sharedialogresharerinfoview.js @@ -51,8 +51,7 @@ initialize: function(options) { var view = this; - //FIXME: specific to reshares stuff - this.model.on('change', function() { + this.model.on('change:reshare', function() { view.render(); }); @@ -67,7 +66,7 @@ if ( !this.model.hasReshare() || !this.model.getReshareOwner() !== OC.currentUser) { - this.$el.html(''); + this.$el.empty(); return this; } @@ -91,7 +90,8 @@ ); } - this.$el.html(reshareTemplate({ + this.$el.empty(); + this.$el.append(reshareTemplate({ avatarEnabled: this.configModel.areAvatarsEnabled(), sharedByText: sharedByText })); diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 179d818e90f..67017778632 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -14,7 +14,7 @@ } var TEMPLATE_BASE = - '{{{resharerInfo}}}' + + '
' + '' + '
' + ' ' + @@ -135,11 +135,8 @@ render: function() { var baseTemplate = this._getTemplate('base', TEMPLATE_BASE); - this.resharerInfoView.render(); - this.$el.html(baseTemplate({ shareLabel: t('core', 'Share'), - resharerInfo: this.resharerInfoView.el.innerHTML, sharePlaceholder: this._renderSharePlaceholderPart(), remoteShareInfo: this._renderRemoteShareInfoPart(), linkShare: this._renderLinkSharePart(), @@ -148,6 +145,9 @@ expiration: this._renderExpirationPart() })); + this.resharerInfoView.$el = this.$el.find('.resharerInfo'); + this.resharerInfoView.render(); + this.$el.find('.hasTooltip').tooltip(); if(this.configModel.areAvatarsEnabled()) { this.$el.find('.avatar').avatar(this.model.getReshareOwner, 32); diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 0d2bce8b2ef..9c4a8141cda 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -90,7 +90,8 @@ * @returns {boolean} */ hasReshare: function() { - return _.isObject(this.get('reshare')) && !_.isUndefined(this.get('reshare').uid_owner); + var reshare = this.get('reshare'); + return _.isObject(reshare) && !_.isUndefined(reshare.uid_owner); }, /** -- cgit v1.2.3 From f9c232c4ce16b101fce233f1f20e0cafc7e4d1fa Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 21 Aug 2015 15:40:50 +0200 Subject: split off linkShareView --- core/js/sharedialoglinkshareview.js | 143 ++++++++++++++++++++++++++++++++++++ core/js/sharedialogview.js | 94 ++++-------------------- lib/private/share/share.php | 1 + 3 files changed, 158 insertions(+), 80 deletions(-) create mode 100644 core/js/sharedialoglinkshareview.js (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js new file mode 100644 index 00000000000..ccd705803f6 --- /dev/null +++ b/core/js/sharedialoglinkshareview.js @@ -0,0 +1,143 @@ +/* + * 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 = + '' + ; + + /** + * @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, + + 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(); + }); + + if(!_.isUndefined(options.configModel)) { + this.configModel = options.configModel; + } else { + console.warn('missing OC.Share.ShareConfigModel'); + } + }, + + render: function() { + if( !this.model.hasSharePermission() + || !this.showLink + || !this.configModel.isShareWithLinkAllowed()) + { + this.$el.empty(); + return this; + } + + var publicUpload = + this.model.isFolder() + && this.model.hasCreatePermission() + && this.configModel.isPublicUploadEnabled(); + + var publicUploadChecked = ''; + if(this.model.isPublicUploadAllowed()) { + publicUploadChecked = 'checked="checked"'; + } + + var linkShareTemplate = this.template(); + this.$el.empty(); + this.$el.append(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'), + 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 this; + }, + + /** + * @returns {Function} from Handlebars + * @private + */ + template: function () { + if (!this._template) { + this._template = Handlebars.compile(TEMPLATE); + } + return this._template; + } + + }); + + OC.Share.ShareDialogLinkShareView = ShareDialogLinkShareView; + +})(); diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 67017778632..cc9590815a7 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -25,7 +25,7 @@ '
    ' + '
' + '{{#if shareAllowed}}' + - '{{{linkShare}}}' + + '
' + '{{else}}' + '{{{noSharing}}}' + '{{/if}}' + @@ -36,35 +36,6 @@ ''; - var TEMPLATE_LINK_SHARE = - '' - ; - var TEMPLATE_NO_SHARING = '' ; @@ -105,6 +76,9 @@ /** @type {object} **/ resharerInfoView: undefined, + /** @type {object} **/ + linkShareView: undefined, + initialize: function(options) { var view = this; this.model.on('change', function() { @@ -130,6 +104,10 @@ ? new OC.Share.ShareDialogResharerInfoView(subViewOptions) : options.resharerInfoView; + this.linkShareView = _.isUndefined(options.linkShareView) + ? new OC.Share.ShareDialogLinkShareView(subViewOptions) + : options.linkShareView; + }, render: function() { @@ -139,7 +117,6 @@ shareLabel: t('core', 'Share'), sharePlaceholder: this._renderSharePlaceholderPart(), remoteShareInfo: this._renderRemoteShareInfoPart(), - linkShare: this._renderLinkSharePart(), shareAllowed: this.model.hasSharePermission(), noSharing: this._renderNoSharing(), expiration: this._renderExpirationPart() @@ -148,6 +125,11 @@ this.resharerInfoView.$el = this.$el.find('.resharerInfo'); this.resharerInfoView.render(); + if(this.model.hasSharePermission()) { + this.linkShareView.$el = this.$el.find('.linkShare'); + this.linkShareView.render(); + } + this.$el.find('.hasTooltip').tooltip(); if(this.configModel.areAvatarsEnabled()) { this.$el.find('.avatar').avatar(this.model.getReshareOwner, 32); @@ -164,6 +146,7 @@ */ setShowLink: function(showLink) { this._showLink = (typeof showLink === 'boolean') ? showLink : true; + this.linkShareView.showLink = this._showLink; }, _renderRemoteShareInfoPart: function() { @@ -179,41 +162,6 @@ return remoteShareInfo; }, - _renderLinkSharePart: function() { - var linkShare = ''; - if( this.model.hasSharePermission() - && this._showLink - && this.configModel.isShareWithLinkAllowed()) - { - 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'), - 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; - }, - _renderSharePlaceholderPart: function () { var sharePlaceholder = t('core', 'Share with users or groups …'); if (this.configModel.isRemoteShareAllowed()) { @@ -278,20 +226,6 @@ */ _getRemoteShareInfoTemplate: function() { return this._getTemplate('remoteShareInfo', TEMPLATE_REMOTE_SHARE_INFO); - }, - - /** - * returns the info template for link sharing - * - * @returns {Function} - * @private - */ - _getLinkShareTemplate: function() { - return this._getTemplate('linkShare', TEMPLATE_LINK_SHARE); - }, - - _getReshareTemplate: function() { - return this._getTemplate('reshare', TEMPLATE_RESHARER_INFO); } }); diff --git a/lib/private/share/share.php b/lib/private/share/share.php index 10d0480ab89..ea4f01c0a95 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -86,6 +86,7 @@ class Share extends Constants { \OC_Util::addScript('core', 'shareconfigmodel'); \OC_Util::addScript('core', 'shareitemmodel'); \OC_Util::addScript('core', 'sharedialogresharerinfoview'); + \OC_Util::addScript('core', 'sharedialoglinkshareview'); \OC_Util::addScript('core', 'sharedialogview'); \OC_Util::addScript('core', 'share'); \OC_Util::addStyle('core', 'share'); -- cgit v1.2.3 From ffd4e0dc5a1977885b639b3ba1bb87a533e6a75a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 21 Aug 2015 19:35:13 +0200 Subject: split off expirationView --- core/js/sharedialogexpirationview.js | 93 ++++++++++++++++++++++++++++++++++++ core/js/sharedialogview.js | 54 ++++++--------------- lib/private/share/share.php | 1 + 3 files changed, 109 insertions(+), 39 deletions(-) create mode 100644 core/js/sharedialogexpirationview.js (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogexpirationview.js b/core/js/sharedialogexpirationview.js new file mode 100644 index 00000000000..e752c66bf35 --- /dev/null +++ b/core/js/sharedialogexpirationview.js @@ -0,0 +1,93 @@ +/* + * 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 = + '' + + '' + + '' + + '' + + '{{defaultExpireMessage}}' + ; + + /** + * @class OCA.Share.ShareDialogExpirationView + * @member {OC.Share.ShareItemModel} model + * @member {jQuery} $el + * @memberof OCA.Sharing + * @classdesc + * + * Represents the expiration part in the GUI of the share dialogue + * + */ + var ShareDialogExpirationView = OC.Backbone.View.extend({ + /** @type {string} **/ + id: 'shareDialogLinkShare', + + /** @type {OC.Share.ShareConfigModel} **/ + configModel: undefined, + + /** @type {Function} **/ + _template: undefined, + + /** @type {boolean} **/ + showLink: true, + + initialize: function(options) { + if(!_.isUndefined(options.configModel)) { + this.configModel = options.configModel; + } else { + console.warn('missing OC.Share.ShareConfigModel'); + } + }, + + render: function() { + 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 expirationTemplate = this.template(); + this.$el.empty(); + this.$el.append(expirationTemplate({ + setExpirationLabel: t('core', 'Set expiration date'), + expirationLabel: t('core', 'Expiration'), + expirationDatePlaceholder: t('core', 'Expiration date'), + defaultExpireMessage: defaultExpireMessage + })); + + return this; + }, + + /** + * @returns {Function} from Handlebars + * @private + */ + template: function () { + if (!this._template) { + this._template = Handlebars.compile(TEMPLATE); + } + return this._template; + } + + }); + + OC.Share.ShareDialogExpirationView = ShareDialogExpirationView; + +})(); diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index cc9590815a7..cdf5214fa65 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -14,7 +14,7 @@ } var TEMPLATE_BASE = - '
' + + '
' + '' + '
' + ' ' + @@ -25,11 +25,11 @@ '
    ' + '
' + '{{#if shareAllowed}}' + - '
' + + '
' + '{{else}}' + '{{{noSharing}}}' + '{{/if}}' + - '{{{expiration}}}' + '
' ; var TEMPLATE_REMOTE_SHARE_INFO = @@ -40,16 +40,6 @@ '' ; - var TEMPLATE_EXPIRATION = - '
' + - ' ' + - ' ' + - ' ' + - ' ' + - ' {{defaultExpireMessage}}' + - '
' - ; - /** * @class OCA.Share.ShareDialogView * @member {OC.Share.ShareItemModel} model @@ -79,6 +69,9 @@ /** @type {object} **/ linkShareView: undefined, + /** @type {object} **/ + expirationView: undefined, + initialize: function(options) { var view = this; this.model.on('change', function() { @@ -108,6 +101,10 @@ ? new OC.Share.ShareDialogLinkShareView(subViewOptions) : options.linkShareView; + this.expirationView = _.isUndefined(options.expirationView) + ? new OC.Share.ShareDialogExpirationView(subViewOptions) + : options.expirationView; + }, render: function() { @@ -119,14 +116,16 @@ remoteShareInfo: this._renderRemoteShareInfoPart(), shareAllowed: this.model.hasSharePermission(), noSharing: this._renderNoSharing(), - expiration: this._renderExpirationPart() })); - this.resharerInfoView.$el = this.$el.find('.resharerInfo'); + this.resharerInfoView.$el = this.$el.find('.resharerInfoView'); this.resharerInfoView.render(); + this.expirationView.$el = this.$el.find('.expirationView'); + this.expirationView.render(); + if(this.model.hasSharePermission()) { - this.linkShareView.$el = this.$el.find('.linkShare'); + this.linkShareView.$el = this.$el.find('.linkShareView'); this.linkShareView.render(); } @@ -181,29 +180,6 @@ 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/lib/private/share/share.php b/lib/private/share/share.php index ea4f01c0a95..b5d508b30ba 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -87,6 +87,7 @@ class Share extends Constants { \OC_Util::addScript('core', 'shareitemmodel'); \OC_Util::addScript('core', 'sharedialogresharerinfoview'); \OC_Util::addScript('core', 'sharedialoglinkshareview'); + \OC_Util::addScript('core', 'sharedialogexpirationview'); \OC_Util::addScript('core', 'sharedialogview'); \OC_Util::addScript('core', 'share'); \OC_Util::addStyle('core', 'share'); -- cgit v1.2.3 From 8f3884145e3992ec5195d6bdd7c4c97926c0c582 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 21 Aug 2015 20:05:50 +0200 Subject: less stupid initalization of subviews --- core/js/sharedialogview.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index cdf5214fa65..b33130a83dc 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -93,18 +93,18 @@ configModel: this.configModel }; - this.resharerInfoView = _.isUndefined(options.resharerInfoView) - ? new OC.Share.ShareDialogResharerInfoView(subViewOptions) - : options.resharerInfoView; - - this.linkShareView = _.isUndefined(options.linkShareView) - ? new OC.Share.ShareDialogLinkShareView(subViewOptions) - : options.linkShareView; - - this.expirationView = _.isUndefined(options.expirationView) - ? new OC.Share.ShareDialogExpirationView(subViewOptions) - : options.expirationView; + var subViews = { + resharerInfoView: 'ShareDialogResharerInfoView', + linkShareView: 'ShareDialogLinkShareView', + expirationView: 'ShareDialogExpirationView' + }; + for(var name in subViews) { + var className = subViews[name]; + this[name] = _.isUndefined(options[name]) + ? new OC.Share[className](subViewOptions) + : options[name]; + } }, render: function() { -- cgit v1.2.3 From 6af6024e172bc4810691f54ccaa2da6912395962 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 21 Aug 2015 20:29:12 +0200 Subject: integraton noshare part into ShareDialogLinkShareView --- core/js/sharedialoglinkshareview.js | 52 +++++++++++++++++++++---------------- core/js/sharedialogview.js | 25 +++--------------- 2 files changed, 33 insertions(+), 44 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index ccd705803f6..ca6413761b0 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -14,32 +14,34 @@ } var TEMPLATE = - '' + '{{else}}' + + '' + + '{{/if}}' ; /** @@ -88,11 +90,17 @@ }, render: function() { + var linkShareTemplate = this.template(); + if( !this.model.hasSharePermission() || !this.showLink || !this.configModel.isShareWithLinkAllowed()) { this.$el.empty(); + this.$el.append(linkShareTemplate({ + shareAllowed: false, + noSharingPlaceholder: t('core', 'Resharing is not allowed') + })); return this; } @@ -106,9 +114,9 @@ publicUploadChecked = 'checked="checked"'; } - var linkShareTemplate = this.template(); this.$el.empty(); this.$el.append(linkShareTemplate({ + shareAllowed: true, linkShareLabel: t('core', 'Share link'), urlLabel: t('core', 'Link'), enablePasswordLabel: t('core', 'Password protect'), diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index b33130a83dc..63c3473252f 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -24,11 +24,7 @@ '{{{remoteShareInfo}}}' + '
    ' + '
' + - '{{#if shareAllowed}}' + '
' + - '{{else}}' + - '{{{noSharing}}}' + - '{{/if}}' + '
' ; @@ -114,21 +110,17 @@ shareLabel: t('core', 'Share'), sharePlaceholder: this._renderSharePlaceholderPart(), remoteShareInfo: this._renderRemoteShareInfoPart(), - shareAllowed: this.model.hasSharePermission(), - noSharing: this._renderNoSharing(), })); this.resharerInfoView.$el = this.$el.find('.resharerInfoView'); this.resharerInfoView.render(); + this.linkShareView.$el = this.$el.find('.linkShareView'); + this.linkShareView.render(); + this.expirationView.$el = this.$el.find('.expirationView'); this.expirationView.render(); - if(this.model.hasSharePermission()) { - this.linkShareView.$el = this.$el.find('.linkShareView'); - this.linkShareView.render(); - } - this.$el.find('.hasTooltip').tooltip(); if(this.configModel.areAvatarsEnabled()) { this.$el.find('.avatar').avatar(this.model.getReshareOwner, 32); @@ -169,17 +161,6 @@ 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; - }, - /** * * @param {string} key - an identifier for the template -- cgit v1.2.3 From fdb95613e9b133feed7b7dbad22dc289a54ef094 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 24 Aug 2015 23:20:01 +0200 Subject: simplification, and throwing where throwing is needed --- core/js/sharedialogexpirationview.js | 5 ++--- core/js/sharedialoglinkshareview.js | 8 +++----- core/js/sharedialogresharerinfoview.js | 5 ++--- core/js/sharedialogview.js | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogexpirationview.js b/core/js/sharedialogexpirationview.js index e752c66bf35..4c628f5498a 100644 --- a/core/js/sharedialogexpirationview.js +++ b/core/js/sharedialogexpirationview.js @@ -48,7 +48,7 @@ if(!_.isUndefined(options.configModel)) { this.configModel = options.configModel; } else { - console.warn('missing OC.Share.ShareConfigModel'); + throw 'missing OC.Share.ShareConfigModel'; } }, @@ -64,8 +64,7 @@ } var expirationTemplate = this.template(); - this.$el.empty(); - this.$el.append(expirationTemplate({ + this.$el.html(expirationTemplate({ setExpirationLabel: t('core', 'Set expiration date'), expirationLabel: t('core', 'Expiration'), expirationDatePlaceholder: t('core', 'Expiration date'), diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index ca6413761b0..ff22b629dc4 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -85,7 +85,7 @@ if(!_.isUndefined(options.configModel)) { this.configModel = options.configModel; } else { - console.warn('missing OC.Share.ShareConfigModel'); + throw 'missing OC.Share.ShareConfigModel'; } }, @@ -96,8 +96,7 @@ || !this.showLink || !this.configModel.isShareWithLinkAllowed()) { - this.$el.empty(); - this.$el.append(linkShareTemplate({ + this.$el.html(linkShareTemplate({ shareAllowed: false, noSharingPlaceholder: t('core', 'Resharing is not allowed') })); @@ -114,8 +113,7 @@ publicUploadChecked = 'checked="checked"'; } - this.$el.empty(); - this.$el.append(linkShareTemplate({ + this.$el.html(linkShareTemplate({ shareAllowed: true, linkShareLabel: t('core', 'Share link'), urlLabel: t('core', 'Link'), diff --git a/core/js/sharedialogresharerinfoview.js b/core/js/sharedialogresharerinfoview.js index 8970d857fc3..63df25b4ed8 100644 --- a/core/js/sharedialogresharerinfoview.js +++ b/core/js/sharedialogresharerinfoview.js @@ -58,7 +58,7 @@ if(!_.isUndefined(options.configModel)) { this.configModel = options.configModel; } else { - console.warn('missing OC.Share.ShareConfigModel'); + throw 'missing OC.Share.ShareConfigModel'; } }, @@ -90,8 +90,7 @@ ); } - this.$el.empty(); - this.$el.append(reshareTemplate({ + this.$el.html(reshareTemplate({ avatarEnabled: this.configModel.areAvatarsEnabled(), sharedByText: sharedByText })); diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 63c3473252f..e07a5cee49a 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -81,7 +81,7 @@ if(!_.isUndefined(options.configModel)) { this.configModel = options.configModel; } else { - console.warn('missing OC.Share.ShareConfigModel'); + throw 'missing OC.Share.ShareConfigModel'; } var subViewOptions = { -- cgit v1.2.3 From f62a3be59069510f4afa479316a665011cd014f5 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 25 Aug 2015 14:41:52 +0200 Subject: cleanup --- core/js/sharedialogview.js | 4 ---- 1 file changed, 4 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index e07a5cee49a..8cd68962d42 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -32,10 +32,6 @@ ''; - var TEMPLATE_NO_SHARING = - '' - ; - /** * @class OCA.Share.ShareDialogView * @member {OC.Share.ShareItemModel} model -- cgit v1.2.3 From c17d022ca42dda31f321276f2c4973ca2e43c8a4 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 25 Aug 2015 16:07:14 +0200 Subject: started to implement sharee list view. not completed yet, do not cry please. --- core/js/shareconfigmodel.js | 7 +++ core/js/sharedialogshareelistview.js | 111 +++++++++++++++++++++++++++++++++++ core/js/sharedialogview.js | 9 ++- lib/private/share/share.php | 1 + 4 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 core/js/sharedialogshareelistview.js (limited to 'core/js/sharedialogview.js') diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index 857e356a351..e948c57cbac 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -55,6 +55,13 @@ return oc_appconfig.core.remoteShareAllowed; }, + /** + * @returns {boolean} + */ + isResharingAllowed: function() { + return oc_appconfig.core.resharingAllowed + }, + /** * @returns {boolean} */ diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js new file mode 100644 index 00000000000..177e0b4a899 --- /dev/null +++ b/core/js/sharedialogshareelistview.js @@ -0,0 +1,111 @@ +/* + * 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 = + '
    ' + + '{{#each sharees}}' + + '
  • ' + + ' {{unshareLabel}}' + + ' {{#if avatarEnabled}}' + + '
    ' + + ' {{/if}}' + + ' {{shareWithDisplayName}}' + + ' {{#if mailPublicNotificationEnabled}} {{#unless isRemoteShare}}' + + ' ' + + ' {{/unless}} {{/if}}' + + ' {{#if isResharingAllowed}} {{#if hasSharePermission}}' + + ' {{/if}} {{/if}}' + + '
  • ' + + '{{/each}}' + + '
' + ; + + /** + * @class OCA.Share.ShareDialogShareeListView + * @member {OC.Share.ShareItemModel} model + * @member {jQuery} $el + * @memberof OCA.Sharing + * @classdesc + * + * Represents the sharee list part in the GUI of the share dialogue + * + */ + var ShareDialogShareeListView = OC.Backbone.View.extend({ + /** @type {string} **/ + id: 'shareDialogLinkShare', + + /** @type {OC.Share.ShareConfigModel} **/ + configModel: undefined, + + /** @type {Function} **/ + _template: undefined, + + /** @type {boolean} **/ + showLink: true, + + initialize: function(options) { + if(!_.isUndefined(options.configModel)) { + this.configModel = options.configModel; + } else { + throw 'missing OC.Share.ShareConfigModel'; + } + }, + + getShareeList: function() { + var universal = { + avatarEnabled: this.configModel.areAvatarsEnabled(), + mailPublicNotificationEnabled: this.configModel.isMailPublicNotificationEnabled(), + notifyByMailLabel: t('core', 'notify by email'), + unshareLabel: t('core', 'Unshare'), + unshareImage: OC.imagePath('core', 'actions/delete') + }; + + // TODO: sharess must have following attributes + // shareType + // shareWith + // shareWithDisplayName + // isRemoteShare + // isMailSent + + var list = _.extend({}, universal); + + return list; + }, + + render: function() { + var shareeListTemplate = this.template(); + this.$el.html(shareeListTemplate({ + sharees: this.getShareeList() + })); + + return this; + }, + + /** + * @returns {Function} from Handlebars + * @private + */ + template: function () { + if (!this._template) { + this._template = Handlebars.compile(TEMPLATE); + } + return this._template; + } + + }); + + OC.Share.ShareDialogShareeListView = ShareDialogShareeListView; + +})(); diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 8cd68962d42..2348c14bb88 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -22,8 +22,7 @@ '
' + // FIXME: find a good position for remoteShareInfo '{{{remoteShareInfo}}}' + - '
    ' + - '
' + + '
' + '
' + '
' ; @@ -88,7 +87,8 @@ var subViews = { resharerInfoView: 'ShareDialogResharerInfoView', linkShareView: 'ShareDialogLinkShareView', - expirationView: 'ShareDialogExpirationView' + expirationView: 'ShareDialogExpirationView', + shareeListView: 'ShareDialogShareeListView' }; for(var name in subViews) { @@ -117,6 +117,9 @@ this.expirationView.$el = this.$el.find('.expirationView'); this.expirationView.render(); + this.shareeListView.$el = this.$el.find('.shareeListView'); + this.shareeListView.redner(); + this.$el.find('.hasTooltip').tooltip(); if(this.configModel.areAvatarsEnabled()) { this.$el.find('.avatar').avatar(this.model.getReshareOwner, 32); diff --git a/lib/private/share/share.php b/lib/private/share/share.php index b5d508b30ba..802b146cfb6 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -88,6 +88,7 @@ class Share extends Constants { \OC_Util::addScript('core', 'sharedialogresharerinfoview'); \OC_Util::addScript('core', 'sharedialoglinkshareview'); \OC_Util::addScript('core', 'sharedialogexpirationview'); + \OC_Util::addScript('core', 'sharedialogshareelistview'); \OC_Util::addScript('core', 'sharedialogview'); \OC_Util::addScript('core', 'share'); \OC_Util::addStyle('core', 'share'); -- cgit v1.2.3 From 5db1db38efffc2110e34886263f3a1117fe8efa5 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 1 Sep 2015 12:43:04 +0200 Subject: continue to reimplement sharee list view. still WIP --- core/js/sharedialoglinkshareview.js | 4 +- core/js/sharedialogresharerinfoview.js | 3 +- core/js/sharedialogshareelistview.js | 113 ++++++++++++++++-- core/js/sharedialogview.js | 14 ++- core/js/shareitemmodel.js | 212 ++++++++++++++++++++++++++++++++- 5 files changed, 327 insertions(+), 19 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index ff22b629dc4..eebf8a34247 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -92,7 +92,7 @@ render: function() { var linkShareTemplate = this.template(); - if( !this.model.hasSharePermission() + if( !this.model.sharePermissionPossible() || !this.showLink || !this.configModel.isShareWithLinkAllowed()) { @@ -105,7 +105,7 @@ var publicUpload = this.model.isFolder() - && this.model.hasCreatePermission() + && this.model.createPermissionPossible() && this.configModel.isPublicUploadEnabled(); var publicUploadChecked = ''; diff --git a/core/js/sharedialogresharerinfoview.js b/core/js/sharedialogresharerinfoview.js index 63df25b4ed8..f7de90e264f 100644 --- a/core/js/sharedialogresharerinfoview.js +++ b/core/js/sharedialogresharerinfoview.js @@ -16,7 +16,7 @@ var TEMPLATE = '' + ' {{#if avatarEnabled}}' + - '
' + + '
' + ' {{/if}}' + ' {{sharedByText}}' + '

' @@ -92,6 +92,7 @@ this.$el.html(reshareTemplate({ avatarEnabled: this.configModel.areAvatarsEnabled(), + reshareOwner: this.model.getReshareOwner(), sharedByText: sharedByText })); diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js index 177e0b4a899..8179926ad51 100644 --- a/core/js/sharedialogshareelistview.js +++ b/core/js/sharedialogshareelistview.js @@ -16,18 +16,41 @@ var TEMPLATE = '
    ' + '{{#each sharees}}' + + ' {{#if isCollection}}' + + '
  • {{text}}
  • ' + + ' {{/if}}' + + ' {{#unless isCollection}}' + '
  • ' + ' {{unshareLabel}}' + ' {{#if avatarEnabled}}' + - '
    ' + + '
    ' + ' {{/if}}' + ' {{shareWithDisplayName}}' + ' {{#if mailPublicNotificationEnabled}} {{#unless isRemoteShare}}' + - ' ' + + ' ' + ' {{/unless}} {{/if}}' + - ' {{#if isResharingAllowed}} {{#if hasSharePermission}}' + + ' {{#if isResharingAllowed}} {{#if sharePermissionPossible}}' + + ' ' + ' {{/if}} {{/if}}' + + ' {{#if editPermissionPossible}}' + + ' ' + + ' {{/if}}' + + ' {{#unless isRemoteShare}}' + + ' {{crudsLabel}}' + + '
    ' + + ' {{#if createPermissionPossible}}' + + ' ' + + ' {{/if}}' + + ' {{#if updatePermissionPossible}}' + + ' ' + + ' {{/if}}' + + ' {{#if deletePermissionPossible}}' + + ' ' + + ' {{/if}}' + + '
    ' + + ' {{/unless}}' + '
  • ' + + ' {{/unless}}' + '{{/each}}' + '
' ; @@ -61,6 +84,54 @@ } else { throw 'missing OC.Share.ShareConfigModel'; } + + var view = this; + this.model.on('change:shares', function() { + view.render(); + }); + }, + + getCollectionObject: function(shareIndex) { + var type = this.model.getCollectionType(shareIndex); + var id = this.model.getCollectionPath(shareIndex); + if(type !== 'file' && type !== 'folder') { + id = this.model.getCollectionSource(shareIndex); + } + return { + collectionID: id, + text: t('core', 'Shared in {item} with {user}', {'item': id, user: this.model.getShareWithDisplayName(shareIndex)}) + } + }, + + /** + * + * @param {OC.Share.Types.ShareInfo} shareInfo + * @returns {object} + */ + getShareeObject: function(shareIndex) { + var shareWith = this.model.getShareWith(shareIndex); + var shareWithDisplayName = this.model.getShareWithDisplayName(shareIndex); + var shareType = this.model.getShareType(shareIndex); + + if (shareType === OC.Share.SHARE_TYPE_GROUP) { + shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'group') + ')'; + } else if (shareType === OC.Share.SHARE_TYPE_REMOTE) { + shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'remote') + ')'; + } + + + return { + hasSharePermission: this.model.hasSharePermission(shareIndex), + hasEditPermission: this.model.hasEditPermission(shareIndex), + hasCreatePermission: this.model.hasCreatePermission(shareIndex), + hasUpdatePermission: this.model.hasUpdatePermission(shareIndex), + hasDeletePermission: this.model.hasDeletePermission(shareIndex), + wasMailSent: this.model.notificationMailWasSent(shareIndex), + shareWith: shareWith, + shareWithDisplayName: shareWithDisplayName, + shareType: shareType, + modSeed: shareType !== OC.Share.SHARE_TYPE_USER + }; }, getShareeList: function() { @@ -69,23 +140,49 @@ mailPublicNotificationEnabled: this.configModel.isMailPublicNotificationEnabled(), notifyByMailLabel: t('core', 'notify by email'), unshareLabel: t('core', 'Unshare'), - unshareImage: OC.imagePath('core', 'actions/delete') + unshareImage: OC.imagePath('core', 'actions/delete'), + canShareLabel: t('core', 'can share'), + canEditLabel: t('core', 'can edit'), + createPermissionLabel: t('core', 'create'), + updatePermissionLabel: t('core', 'change'), + deletePermissionLabel: t('core', 'delete'), + crudsLabel: t('core', 'access control'), + triangleSImage: OC.imagePath('core', 'actions/triangle-s'), + isResharingAllowed: this.configModel.isResharingAllowed(), + sharePermissionPossible: this.model.sharePermissionPossible(), + editPermissionPossible: this.model.editPermissionPossible(), + createPermissionPossible: this.model.createPermissionPossible(), + updatePermissionPossible: this.model.updatePermissionPossible(), + deletePermissionPossible: this.model.deletePermissionPossible(), + sharePermission: OC.PERMISSION_SHARE, + createPermission: OC.PERMISSION_CREATE, + updatePermission: OC.PERMISSION_UPDATE, + deletePermission: OC.PERMISSION_DELETE }; // TODO: sharess must have following attributes - // shareType - // shareWith - // shareWithDisplayName // isRemoteShare // isMailSent - var list = _.extend({}, universal); + if(!this.model.hasShares()) { + return []; + } + + var list = []; + for(var index in this.model.get('shares')) { + if(this.model.isCollection(index)) { + list.unshift(this.getCollectionObject(index)); + } else { + list.push(_.extend(this.getShareeObject(index), universal)) + } + } return list; }, render: function() { var shareeListTemplate = this.template(); + var list = this.getShareeList(); this.$el.html(shareeListTemplate({ sharees: this.getShareeList() })); diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 2348c14bb88..9bfe38eea3c 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -63,6 +63,9 @@ /** @type {object} **/ expirationView: undefined, + /** @type {object} **/ + shareeListView: undefined, + initialize: function(options) { var view = this; this.model.on('change', function() { @@ -118,11 +121,18 @@ this.expirationView.render(); this.shareeListView.$el = this.$el.find('.shareeListView'); - this.shareeListView.redner(); + this.shareeListView.render(); this.$el.find('.hasTooltip').tooltip(); if(this.configModel.areAvatarsEnabled()) { - this.$el.find('.avatar').avatar(this.model.getReshareOwner, 32); + this.$el.find('.avatar').each(function() { + var $this = $(this); + $this.avatar($this.data('username'), 32); + }); + this.$el.find('.avatar.imageplaceholderseed').each(function() { + var $this = $(this); + $this.imageplaceholder($this.data('seed')); + }); } return this; diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index c5d0581390c..b5370faca0a 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -14,6 +14,13 @@ OC.Share.Types = {}; } + /** + * @typedef {object} OC.Share.Types.Collection + * @property {string} item_type + * @property {string} path + * @property {string} item_source TODO: verify + */ + /** * @typedef {object} OC.Share.Types.Reshare * @property {string} uid_owner @@ -33,7 +40,7 @@ * @property {string} share_with * @property {string} share_with_displayname * @property {string} share_mail_send - * @property {bool} collection //TODO: verify + * @property {OC.Share.Types.Collection|undefined} collection * @property {Date} expiration optional? * @property {number} stime optional? */ @@ -95,13 +102,79 @@ }, /** - * whether this item has reshare information + * whether this item has share information * @returns {boolean} */ hasShares: function() { - return _.isObject(this.get('shares')); + var shares = this.get('shares'); + return _.isArray(this.get('shares')); }, + /** + * @param {number} shareIndex + * @returns {string} + */ + getCollectionType: function(shareIndex) { + /** @type OC.Share.Types.ShareInfo **/ + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } else if(_.isUndefined(share.collection)) { + throw "Share is not a collection"; + } + + return share.collection.item_type; + }, + + /** + * @param {number} shareIndex + * @returns {string} + */ + getCollectionPath: function(shareIndex) { + /** @type OC.Share.Types.ShareInfo **/ + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } else if(_.isUndefined(share.collection)) { + throw "Share is not a collection"; + } + + return share.collection.path; + }, + + /** + * @param {number} shareIndex + * @returns {string} + */ + getCollectionSource: function(shareIndex) { + /** @type OC.Share.Types.ShareInfo **/ + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } else if(_.isUndefined(share.collection)) { + throw "Share is not a collection"; + } + + return share.collection.item_source; + }, + + /** + * @param {number} shareIndex + * @returns {boolean} + */ + isCollection: function(shareIndex) { + /** @type OC.Share.Types.ShareInfo **/ + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } + if(_.isUndefined(share.collection)) { + return false; + } + return true; + }, + + /** * @returns {string} */ @@ -131,20 +204,145 @@ return this.get('reshare').share_type; }, + /** + * @param shareIndex + * @returns {string} + */ + getShareWith: function(shareIndex) { + /** @type OC.Share.Types.ShareInfo **/ + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } + return share.share_with; + }, + + /** + * @param shareIndex + * @returns {string} + */ + getShareWithDisplayName: function(shareIndex) { + /** @type OC.Share.Types.ShareInfo **/ + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } + return share.share_with_displayname; + }, + + getShareType: function(shareIndex) { + /** @type OC.Share.Types.ShareInfo **/ + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } + return share.share_type; + }, + + /** + * whether a share from shares has the requested permission + * + * @param {number} shareIndex + * @param {number} permission + * @returns {boolean} + * @private + */ + _shareHasPermission: function(shareIndex, permission) { + /** @type OC.Share.Types.ShareInfo **/ + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } + return (share.permissions & permission) === permission; + }, + + notificationMailWasSent: function(shareIndex) { + /** @type OC.Share.Types.ShareInfo **/ + var share = this.get('shares')[shareIndex]; + if(!_.isObject(share)) { + throw "Unknown Share"; + } + return share.share_mail_send === '1'; + }, + /** * @returns {boolean} */ - hasSharePermission: function() { + sharePermissionPossible: function() { return (this.get('permissions') & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE; }, + /** + * @param {number} shareIndex + * @returns {boolean} + */ + hasSharePermission: function(shareIndex) { + return this._shareHasPermission(shareIndex, OC.PERMISSION_SHARE); + }, + /** * @returns {boolean} */ - hasCreatePermission: function() { + createPermissionPossible: function() { return (this.get('permissions') & OC.PERMISSION_CREATE) === OC.PERMISSION_CREATE; }, + /** + * @param {number} shareIndex + * @returns {boolean} + */ + hasCreatePermission: function(shareIndex) { + return this._shareHasPermission(shareIndex, OC.PERMISSION_CREATE); + }, + + /** + * @returns {boolean} + */ + updatePermissionPossible: function() { + return (this.get('permissions') & OC.PERMISSION_UPDATE) === OC.PERMISSION_UPDATE; + }, + + /** + * @param {number} shareIndex + * @returns {boolean} + */ + hasUpdatePermission: function(shareIndex) { + return this._shareHasPermission(shareIndex, OC.PERMISSION_UPDATE); + }, + + /** + * @returns {boolean} + */ + deletePermissionPossible: function() { + return (this.get('permissions') & OC.PERMISSION_DELETE) === OC.PERMISSION_DELETE; + }, + + /** + * @param {number} shareIndex + * @returns {boolean} + */ + hasDeletePermission: function(shareIndex) { + return this._shareHasPermission(shareIndex, OC.PERMISSION_DELETE); + }, + + /** + * @returns {boolean} + */ + editPermissionPossible: function() { + return this.createPermissionPossible() + || this.updatePermissionPossible() + || this.deletePermissionPossible(); + }, + + /** + * @returns {boolean} + */ + hasEditPermission: function(shareIndex) { + return this.hasCreatePermission(shareIndex) + || this.hasUpdatePermission(shareIndex) + || this.hasDeletePermission(shareIndex); + }, + fetch: function() { var model = this; OC.Share.loadItem(this.get('itemType'), this.get('itemSource'), function(data) { @@ -159,6 +357,8 @@ return {}; } + console.log(data.shares); + var permissions = this.get('possiblePermissions'); if(!_.isUndefined(data.reshare) && !_.isUndefined(data.reshare.permissions)) { permissions = permissions & data.reshare.permissions; @@ -176,7 +376,7 @@ return { reshare: data.reshare, - shares: data.shares, + shares: $.map(data.shares, function(value) { return [value]; }), permissions: permissions, allowPublicUploadStatus: allowPublicUploadStatus }; -- cgit v1.2.3 From 858a2a4e6c42f8cc68212439930c16029a6bba36 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 4 Sep 2015 15:31:45 +0200 Subject: display expiration info --- core/js/shareconfigmodel.js | 18 ++---------- core/js/sharedialogexpirationview.js | 57 +++++++++++++++++++++++++++++++----- core/js/sharedialogview.js | 1 + core/js/shareitemmodel.js | 7 ++++- 4 files changed, 60 insertions(+), 23 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index 846b2692ecb..472fdcc75d7 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -17,7 +17,9 @@ var ShareConfigModel = OC.Backbone.Model.extend({ defaults: { publicUploadEnabled: false, - enforcePasswordForPublicLink: oc_appconfig.core.enforcePasswordForPublicLink + enforcePasswordForPublicLink: oc_appconfig.core.enforcePasswordForPublicLink, + isDefaultExpireDateEnforced: oc_appconfig.core.defaultExpireDateEnforced === true, + defaultExpireDate: oc_appconfig.core.defaultExpireDate, }, /** @@ -42,13 +44,6 @@ return $('input:hidden[name=mailPublicNotificationEnabled]').val() === 'yes'; }, - /** - * @returns {boolean} - */ - isDefaultExpireDateEnforced: function() { - return oc_appconfig.core.defaultExpireDateEnforced === true; - }, - /** * @returns {boolean} */ @@ -75,13 +70,6 @@ */ getFederatedShareDocLink: function() { return oc_appconfig.core.federatedCloudShareDoc; - }, - - /** - * @returns {number} - */ - getDefaultExpireDate: function () { - return oc_appconfig.core.defaultExpireDate; } }); diff --git a/core/js/sharedialogexpirationview.js b/core/js/sharedialogexpirationview.js index 9fb404a090e..56473cdb1fa 100644 --- a/core/js/sharedialogexpirationview.js +++ b/core/js/sharedialogexpirationview.js @@ -14,13 +14,22 @@ } var TEMPLATE = - // well that could go to linkShareView… + // currently expiration is only effective for link share. + // this is about to change in future. Therefore this is not included + // in the LinkShareView to ease reusing it in future. Then, + // modifications (getting rid of IDs) are still necessary. '{{#if isLinkShare}}' + - '' + + '' + '' + - '' + - '' + + ' {{#if isExpirationSet}}' + + '' + + '' + + ' {{/if}}' + + ' {{#if isExpirationEnforced}}' + + // originally the expire message was shown when a default date was set, however it never had text '{{defaultExpireMessage}}' + + ' {{/if}}' + '{{/if}}' ; @@ -59,24 +68,58 @@ render: function() { var defaultExpireMessage = ''; + var defaultExpireDays = this.configModel.get('defaultExpireDate'); if( (this.model.isFolder() || this.model.isFile()) - && this.configModel.isDefaultExpireDateEnforced()) { + && this.configModel.get('isDefaultExpireDateEnforced')) { defaultExpireMessage = t( 'core', 'The public link will expire no later than {days} days after it is created', - {'days': this.configModel.getDefaultExpireDate()} + {'days': defaultExpireDays } ); } + var isExpirationSet = !!this.model.get('linkShare').expiration; + var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced'); + var expirationTemplate = this.template(); this.$el.html(expirationTemplate({ setExpirationLabel: t('core', 'Set expiration date'), expirationLabel: t('core', 'Expiration'), expirationDatePlaceholder: t('core', 'Expiration date'), defaultExpireMessage: defaultExpireMessage, - isLinkShare: this.model.get('linkShare').isLinkShare + isLinkShare: this.model.get('linkShare').isLinkShare, + isExpirationSet: isExpirationSet, + isExpirationEnforced: isExpirationEnforced, + disableCheckbox: isExpirationEnforced && isExpirationSet, + expirationValue: this.model.get('linkShare').expiration })); + if(isExpirationSet) { + // 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); + + var maxDate = null; + if(isExpirationEnforced) { + // TODO: hack: backend returns string instead of integer + var shareTime = this.model.get('linkShare').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); + } + + $.datepicker.setDefaults({ + minDate: minDate, + maxDate: maxDate + }); + } + return this; }, diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 9bfe38eea3c..12e682a3b82 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -134,6 +134,7 @@ $this.imageplaceholder($this.data('seed')); }); } + this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'}); return this; }, diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index e8371e16e0a..24aa5fe344d 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -20,6 +20,8 @@ * @property {string} token * @property {string|null} password * @property {string} link + * @property {Date} expiration + * @property {number} stime share time */ /** @@ -445,7 +447,10 @@ isLinkShare: true, token: share.token, password: share.share_with, - link: link + link: link, + // currently expiration is only effective for link shares. + expiration: share.expiration, + stime: share.stime }; return share; -- cgit v1.2.3 From 258a2e2696c0c2a1e784fe27cbd8ca9a4dc8b8ca Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 5 Sep 2015 02:02:55 +0200 Subject: now you even can share --- apps/files_sharing/appinfo/app.php | 1 + apps/files_sharing/css/sharetabview.css | 1 - core/js/shareconfigmodel.js | 8 +----- core/js/sharedialogshareelistview.js | 8 +++--- core/js/sharedialogview.js | 46 +++++++++++++++++++++++++++++++++ core/js/shareitemmodel.js | 41 +++++++++++++++++++++++++++++ 6 files changed, 94 insertions(+), 11 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 2bb872eaad6..8d919d1466f 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -61,6 +61,7 @@ $eventDispatcher->addListener( \OCP\Util::addScript('files_sharing', 'share'); \OCP\Util::addScript('files_sharing', 'sharetabview'); \OCP\Util::addScript('files_sharing', 'external'); + \OCP\Util::addStyle('files_sharing', 'sharetabview'); } ); diff --git a/apps/files_sharing/css/sharetabview.css b/apps/files_sharing/css/sharetabview.css index 8b9af852531..96a75717c53 100644 --- a/apps/files_sharing/css/sharetabview.css +++ b/apps/files_sharing/css/sharetabview.css @@ -5,7 +5,6 @@ .shareTabView .oneline { white-space: nowrap; } .shareTabView .shareWithLoading { - display: inline-block !important; padding-left: 10px; position: relative; right: 30px; diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index 472fdcc75d7..98280e01eb6 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -20,6 +20,7 @@ enforcePasswordForPublicLink: oc_appconfig.core.enforcePasswordForPublicLink, isDefaultExpireDateEnforced: oc_appconfig.core.defaultExpireDateEnforced === true, defaultExpireDate: oc_appconfig.core.defaultExpireDate, + isResharingAllowed: oc_appconfig.core.resharingAllowed }, /** @@ -51,13 +52,6 @@ return oc_appconfig.core.remoteShareAllowed; }, - /** - * @returns {boolean} - */ - isResharingAllowed: function() { - return oc_appconfig.core.resharingAllowed - }, - /** * @returns {boolean} */ diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js index 6a356b8144c..4ac669ee2b9 100644 --- a/core/js/sharedialogshareelistview.js +++ b/core/js/sharedialogshareelistview.js @@ -161,7 +161,7 @@ deletePermissionLabel: t('core', 'delete'), crudsLabel: t('core', 'access control'), triangleSImage: OC.imagePath('core', 'actions/triangle-s'), - isResharingAllowed: this.configModel.isResharingAllowed(), + isResharingAllowed: this.configModel.get('isResharingAllowed'), sharePermissionPossible: this.model.sharePermissionPossible(), editPermissionPossible: this.model.editPermissionPossible(), createPermissionPossible: this.model.createPermissionPossible(), @@ -185,10 +185,12 @@ if(this.model.isCollection(index)) { this.processCollectionShare(index); } else { - list.push(_.extend(universal, this.getShareeObject(index))) + // first empty {} is necessary, otherwise we get in trouble + // with references + list.push(_.extend({}, universal, this.getShareeObject(index))); } - list = _.union(_.values(this._collections), list); } + list = _.union(_.values(this._collections), list); return list; }, diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 12e682a3b82..e3da0384fa4 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -100,6 +100,36 @@ ? new OC.Share[className](subViewOptions) : options[name]; } + + _.bindAll(this, 'autocompleteHandler'); + }, + + autocompleteHandler: function (search, response) { + var view = this; + var $loading = this.$el.find('.shareWithLoading'); + $loading.removeClass('hidden'); + $loading.addClass('inlineblock'); + $.get(OC.filePath('core', 'ajax', 'share.php'), { + fetch: 'getShareWith', + search: search.term.trim(), + limit: 200, + itemShares: OC.Share.itemShares, + itemType: view.model.get('itemType') + }, function (result) { + $loading.addClass('hidden'); + $loading.removeClass('inlineblock'); + if (result.status == 'success' && result.data.length > 0) { + $("#shareWith").autocomplete("option", "autoFocus", true); + response(result.data); + } else { + response(); + } + }).fail(function () { + $loading.addClass('hidden'); + $loading.removeClass('inlineblock'); + OC.Notification.show(t('core', 'An error occured. Please try again')); + window.setTimeout(OC.Notification.hide, 5000); + }); }, render: function() { @@ -111,6 +141,22 @@ remoteShareInfo: this._renderRemoteShareInfoPart(), })); + var view = this; + this.$el.find('#shareWith').autocomplete({ + minLength: 2, + delay: 750, + source: this.autocompleteHandler, + select: function(e, s) { + var expiration = ''; + if($('#expirationCheckbox').is(':checked') === true) { + expiration = view.$el.find('#expirationDate').val() + } + view.model.addShare(e, s, { + expiration: expiration + }); + } + }); + this.resharerInfoView.$el = this.$el.find('.resharerInfoView'); this.resharerInfoView.render(); diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 24aa5fe344d..81e905b082e 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -79,6 +79,8 @@ /** @type {OC.Files.FileInfo} **/ this.fileInfoModel = options.fileInfoModel; } + + _.bindAll(this, 'addShare'); }, defaults: { @@ -87,6 +89,45 @@ linkShare: {} }, + addShare: function(event, selected, options) { + event.preventDefault(); + + //console.warn(selected); + //return false; + + var shareType = selected.item.value.shareType; + var shareWith = selected.item.value.shareWith; + var fileName = this.fileInfoModel.get('name'); + options = options || {}; + + // Default permissions are Edit (CRUD) and Share + // Check if these permissions are possible + var permissions = OC.PERMISSION_READ; + if (shareType === OC.Share.SHARE_TYPE_REMOTE) { + permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_READ; + } else { + if (this.updatePermissionPossible()) { + permissions = permissions | OC.PERMISSION_UPDATE; + } + if (this.createPermissionPossible()) { + permissions = permissions | OC.PERMISSION_CREATE; + } + if (this.deletePermissionPossible()) { + permissions = permissions | OC.PERMISSION_DELETE; + } + if (this.configModel.get('isResharingAllowed') && (this.sharePermissionPossible())) { + permissions = permissions | OC.PERMISSION_SHARE; + } + } + + var model = this; + OC.Share.share(this.get('itemType'), this.get('itemSource'), shareType, shareWith, permissions, fileName, options.expiration, function() { + model.fetch() + //FIXME: updateIcon belongs to view + OC.Share.updateIcon(itemType, itemSource); + }); + }, + /** * @returns {boolean} */ -- cgit v1.2.3 From 4c702aa8fdfb28bea4b021e55e7df5eeeb6999d2 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 12 Sep 2015 12:17:15 +0200 Subject: format groups and remotes in autocomplete list --- core/js/sharedialogview.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index e3da0384fa4..6588da7d429 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -132,6 +132,24 @@ }); }, + autocompleteRenderItem: function(ul, item) { + var insert = $(""); + var text = item.label; + if (item.value.shareType === OC.Share.SHARE_TYPE_GROUP) { + text = text + ' ('+t('core', 'group')+')'; + } else if (item.value.shareType === OC.Share.SHARE_TYPE_REMOTE) { + text = text + ' ('+t('core', 'remote')+')'; + } + insert.text(text); + if(item.value.shareType === OC.Share.SHARE_TYPE_GROUP) { + insert = insert.wrapInner(''); + } + return $("
  • ") + .addClass((item.value.shareType === OC.Share.SHARE_TYPE_GROUP) ? 'group' : 'user') + .append(insert) + .appendTo(ul); + }, + render: function() { var baseTemplate = this._getTemplate('base', TEMPLATE_BASE); @@ -155,7 +173,7 @@ expiration: expiration }); } - }); + }).data('ui-autocomplete')._renderItem = this.autocompleteRenderItem; this.resharerInfoView.$el = this.$el.find('.resharerInfoView'); this.resharerInfoView.render(); -- cgit v1.2.3 From f29b51682bc0be785e1a3e4e5901db3255e4a377 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 12 Sep 2015 14:21:14 +0200 Subject: share and unshare via link (not yet password). also some internal changes to reduce unnecessary rendering --- core/js/share.js | 74 ---------------------------------- core/js/shareconfigmodel.js | 23 +++++++---- core/js/sharedialogexpirationview.js | 22 ++++++++-- core/js/sharedialoglinkshareview.js | 37 +++++++++++++++-- core/js/sharedialogresharerinfoview.js | 7 ++++ core/js/sharedialogshareelistview.js | 11 +++++ core/js/sharedialogview.js | 22 +++------- core/js/shareitemmodel.js | 33 ++++++++++++--- 8 files changed, 121 insertions(+), 108 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/share.js b/core/js/share.js index bd87ab10d40..6581c401281 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -956,80 +956,6 @@ $(document).ready(function() { permissions); }); - $(document).on('change', '#dropdown #linkCheckbox', function() { - var $dropDown = $('#dropdown'); - var itemType = $dropDown.data('item-type'); - var itemSource = $dropDown.data('item-source'); - var itemSourceName = $dropDown.data('item-source-name'); - var $loading = $dropDown.find('#link .icon-loading-small'); - var $button = $(this); - - if (!$loading.hasClass('hidden')) { - // already in progress - return false; - } - - if (this.checked) { - // Reset password placeholder - $('#linkPassText').attr('placeholder', t('core', 'Choose a password for the public link')); - // Reset link - $('#linkText').val(''); - $('#showPassword').prop('checked', false); - $('#linkPass').hide(); - $('#sharingDialogAllowPublicUpload').prop('checked', false); - $('#expirationCheckbox').prop('checked', false); - $('#expirationDate').hide(); - var expireDateString = ''; - // Create a link - if (oc_appconfig.core.enforcePasswordForPublicLink === false) { - expireDateString = OC.Share.getDefaultExpirationDate(); - $loading.removeClass('hidden'); - $button.addClass('hidden'); - $button.prop('disabled', true); - - OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, itemSourceName, expireDateString, function(data) { - $loading.addClass('hidden'); - $button.removeClass('hidden'); - $button.prop('disabled', false); - OC.Share.showLink(data.token, null, itemSource); - $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); - OC.Share.updateIcon(itemType, itemSource); - }); - } else { - $('#linkPass').slideToggle(OC.menuSpeed); - // TODO drop with IE8 drop - if($('html').hasClass('ie8')) { - $('#linkPassText').attr('placeholder', null); - $('#linkPassText').val(''); - } - $('#linkPassText').focus(); - } - if (expireDateString !== '') { - OC.Share.showExpirationDate(expireDateString); - } - } else { - // Delete private link - OC.Share.hideLink(); - $('#expiration').slideUp(OC.menuSpeed); - if ($('#linkText').val() !== '') { - $loading.removeClass('hidden'); - $button.addClass('hidden'); - $button.prop('disabled', true); - OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() { - $loading.addClass('hidden'); - $button.removeClass('hidden'); - $button.prop('disabled', false); - OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false; - $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); - OC.Share.updateIcon(itemType, itemSource); - if (typeof OC.Share.statuses[itemSource] === 'undefined') { - $('#expiration').slideUp(OC.menuSpeed); - } - }); - } - } - }); - $(document).on('click', '#dropdown #linkText', function() { $(this).focus(); $(this).select(); diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index 98280e01eb6..c6891154c98 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -19,6 +19,8 @@ publicUploadEnabled: false, enforcePasswordForPublicLink: oc_appconfig.core.enforcePasswordForPublicLink, isDefaultExpireDateEnforced: oc_appconfig.core.defaultExpireDateEnforced === true, + isDefaultExpireDateEnabled: oc_appconfig.core.defaultExpireDateEnabled === true, + isRemoteShareAllowed: oc_appconfig.core.remoteShareAllowed, defaultExpireDate: oc_appconfig.core.defaultExpireDate, isResharingAllowed: oc_appconfig.core.resharingAllowed }, @@ -45,13 +47,6 @@ return $('input:hidden[name=mailPublicNotificationEnabled]').val() === 'yes'; }, - /** - * @returns {boolean} - */ - isRemoteShareAllowed: function() { - return oc_appconfig.core.remoteShareAllowed; - }, - /** * @returns {boolean} */ @@ -64,6 +59,20 @@ */ getFederatedShareDocLink: function() { return oc_appconfig.core.federatedCloudShareDoc; + }, + + getDefaultExpirationDateString: function () { + var expireDateString = ''; + if (this.get('isDefaultExpireDateEnabled')) { + var date = new Date().getTime(); + var expireAfterMs = this.get('defaultExpireDate') * 24 * 60 * 60 * 1000; + var expireDate = new Date(date + expireAfterMs); + var month = expireDate.getMonth() + 1; + var year = expireDate.getFullYear(); + var day = expireDate.getDate(); + expireDateString = year + "-" + month + '-' + day + ' 00:00:00'; + } + return expireDateString; } }); diff --git a/core/js/sharedialogexpirationview.js b/core/js/sharedialogexpirationview.js index 56473cdb1fa..f244fe56548 100644 --- a/core/js/sharedialogexpirationview.js +++ b/core/js/sharedialogexpirationview.js @@ -24,7 +24,7 @@ '' + ' {{#if isExpirationSet}}' + '' + - '' + + '' + ' {{/if}}' + ' {{#if isExpirationEnforced}}' + // originally the expire message was shown when a default date was set, however it never had text @@ -64,13 +64,28 @@ } else { throw 'missing OC.Share.ShareConfigModel'; } + + var view = this; + this.configModel.on('change:isDefaultExpireDateEnforced', function() { + view.render(); + }); + + this.model.on('change:itemType', function() { + view.render(); + }); + + this.model.on('change:linkShare', function() { + view.render(); + }); }, render: function() { var defaultExpireMessage = ''; var defaultExpireDays = this.configModel.get('defaultExpireDate'); + var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced'); + if( (this.model.isFolder() || this.model.isFile()) - && this.configModel.get('isDefaultExpireDateEnforced')) { + && isExpirationEnforced) { defaultExpireMessage = t( 'core', 'The public link will expire no later than {days} days after it is created', @@ -79,7 +94,6 @@ } var isExpirationSet = !!this.model.get('linkShare').expiration; - var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced'); var expirationTemplate = this.template(); this.$el.html(expirationTemplate({ @@ -120,6 +134,8 @@ }); } + this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'}); + return this; }, diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index 373d6d180bc..b94f1c3e70b 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -23,13 +23,11 @@ ' {{#if showPasswordCheckBox}}' + '' + ' {{/if}}' + - ' {{#if isPasswordSet}}' + - '
    ' + + '
    ' + ' ' + ' ' + ' ' + '
    ' + - ' {{/if}}' + ' {{#if publicUpload}}' + '' + '{{/if}}' + '
    ' + '
    ' + -- cgit v1.2.3