split ShareDialogResharerInfoView from base view

This commit is contained in:
Arthur Schiwon 2015-08-19 00:04:16 +02:00 committed by Vincent Petry
parent 1bd6942be7
commit dcb084a617
4 changed files with 138 additions and 43 deletions

View File

@ -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 =
'<span class="reshare">' +
' {{#if avatarEnabled}}' +
' <div class="avatar"></div>' +
' {{/if}}' +
' {{sharedByText}}' +
'</span><br/>'
;
/**
* @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;
})();

View File

@ -32,14 +32,6 @@
'{{{expiration}}}'
;
var TEMPLATE_RESHARER_INFO =
'<span class="reshare">' +
' {{#if avatarEnabled}}' +
' <div class="avatar"></div>' +
' {{/if}}' +
' {{sharedByText}}' +
'</span><br />';
var TEMPLATE_REMOTE_SHARE_INFO =
'<a target="_blank" class="icon-info svg shareWithRemoteInfo hasTooltip" href="{{docLink}}" ' +
'title="{{tooltip}}"></a>';
@ -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()) {

View File

@ -112,6 +112,7 @@
* @returns {string}
*/
getReshareOwnerDisplayname: function() {
return 'foo';
return this.get('reshare').displayname_owner;
},

View File

@ -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');