diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2015-08-11 23:14:44 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-09-16 07:23:25 +0200 |
commit | b015eff2e92ba83c6bf95c0084e283ddc7a5df70 (patch) | |
tree | 3ac43c69f3c73598d6dce227202b979e3e2f5a1b /core/js | |
parent | 97b5fe0b1e7ece1c402f9226f13a6e9d711055cf (diff) | |
download | nextcloud-server-b015eff2e92ba83c6bf95c0084e283ddc7a5df70.tar.gz nextcloud-server-b015eff2e92ba83c6bf95c0084e283ddc7a5df70.zip |
improve reshare rendering part and move permission calculation to model
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/share.js | 7 | ||||
-rw-r--r-- | core/js/sharedialogview.js | 62 | ||||
-rw-r--r-- | core/js/shareitemmodel.js | 57 |
3 files changed, 87 insertions, 39 deletions
diff --git a/core/js/share.js b/core/js/share.js index d84da322274..db35a2e111c 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -382,18 +382,19 @@ OC.Share = _.extend(OC.Share, { }); }, showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) { - var attributes = {itemType: itemType, itemSource: itemSource}; + var attributes = {itemType: itemType, itemSource: itemSource, possiblePermissions: possiblePermissions}; var itemModel = new OC.Share.ShareItemModel(attributes); var dialogView = new OC.Share.ShareDialogView({ id: 'dropdown', model: itemModel, className: 'drop shareDropDown', attributes: { - 'data-item-source-name': filename + 'data-item-source-name': filename, + 'data-item-type': itemType, + 'data-item-soruce': itemSource } }); dialogView.setShowLink(link); - dialogView.setPossiblePermissions(possiblePermissions); var $dialog = dialogView.render().$el; $dialog.appendTo(appendTo); $dialog.slideDown(OC.menuSpeed, function() { diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 3c12bedca86..4ff4eb9a94e 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -70,9 +70,6 @@ /** @type {boolean} **/ _showLink: true, - /** @type {unknown} **/ - _possiblePermissions: null, - /** @type {string} **/ tagName: 'div', @@ -91,7 +88,6 @@ var baseTemplate = this._getTemplate('base', TEMPLATE_BASE); this.$el.html(baseTemplate({ - shareLabel: t('core', 'Share'), resharerInfo: this._renderResharerInfo(), sharePlaceholder: this._renderSharePlaceholderPart(), @@ -112,41 +108,37 @@ this._showLink = (typeof showLink === 'boolean') ? showLink : true; }, - setPossiblePermissions: function(permissions) { - //TODO: maybe move to model? Whatever this is. - this._possiblePermissions = permissions; - }, - _renderResharerInfo: function() { var resharerInfo = ''; - if ( this.model.hasReshare() - && this.model.getReshareOwner() !== OC.currentUser) + if ( !this.model.hasReshare() + || !this.model.getReshareOwner() !== OC.currentUser) { - 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() } - ); - } - - - resharerInfo = reshareTemplate({ - avatarEnabled: oc_config.enable_avatars === true, - sharedByText: sharedByText - }); + 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: oc_config.enable_avatars === true, + sharedByText: sharedByText + }); }, _renderRemoteShareInfoPart: function() { diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index fe7aed46509..efce69f0f3e 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -57,6 +57,22 @@ this.fetch(); }, + defaults: { + allowPublicUploadStatus: false + }, + + /** + * @returns {boolean|jQuery} + */ + isPublicUploadEnabled: function() { + // FIXME: this really needs a better place + var publicUploadEnabled = $('#filestable').data('allow-public-upload'); + if (_.isUndefined(publicUploadEnabled)) { + publicUploadEnabled = 'no'; + } + return publicUploadEnabled; + }, + /** * whether this item has reshare information * @returns {boolean} @@ -101,6 +117,26 @@ return this.get('reshare').share_type; }, + /** + * @returns {number} + */ + getPermissions: function() { + var permissions = this.get('permissions'); + if(_.isUndefined(permissions)) { + // model was not properly initialized + console.warn('Sharing error: undefined permissions'); + permissions = 0; + } + return permissions; + }, + + /** + * @returns {boolean} + */ + hasSharePermission: function() { + return (this.getPermissions & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE; + }, + fetch: function() { var model = this; OC.Share.loadItem(this.get('itemType'), this.get('itemSource'), function(data) { @@ -114,10 +150,29 @@ trigger('fetchError'); return {}; } + + var permissions = this.get('possiblePermissions'); + if(!_.isUndefined(data.reshare) && !_.isUndefined(data.reshare.permissions)) { + permissions = permissions & data.reshare.permissions; + } + + var allowPublicUploadStatus = false; + if(!_.isUndefined(data.shares)) { + $.each(data.shares, function (key, value) { + if (value.share_type === OC.Share.SHARE_TYPE_LINK) { + allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false; + return true; + } + }); + } + var attributes = { reshare: data.reshare, - shares: data.shares + shares: data.shares, + permissions: permissions, + allowPublicUploadStatus: allowPublicUploadStatus }; + return attributes; } }); |