diff --git a/core/js/sharedialogresharerinfoview.js b/core/js/sharedialogresharerinfoview.js new file mode 100644 index 0000000000..3f996bb6d2 --- /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 5e3fb8b8d9..179d818e90 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 eb93b91ce9..0d2bce8b2e 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 cd3f0cbfb3..10d0480ab8 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');