server/core/js/sharedialogview.js

191 lines
4.9 KiB
JavaScript
Raw Normal View History

/*
* 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 =
2015-08-21 17:35:13 +00:00
'<div class="resharerInfoView"></div>' +
'<label for="shareWith" class="hidden-visually">{{shareLabel}}</label>' +
'<div class="oneline">' +
' <input id="shareWith" type="text" placeholder="{{sharePlaceholder}}" />' +
' <span class="shareWithLoading icon-loading-small hidden"></span>'+
'</div>' +
// FIXME: find a good position for remoteShareInfo
'{{{remoteShareInfo}}}' +
'<div class="shareeListView"></div>' +
2015-08-21 17:35:13 +00:00
'<div class="linkShareView"></div>' +
'<div class="expirationView"></div>'
;
var TEMPLATE_REMOTE_SHARE_INFO =
2015-08-18 15:23:32 +00:00
'<a target="_blank" class="icon-info svg shareWithRemoteInfo hasTooltip" href="{{docLink}}" ' +
'title="{{tooltip}}"></a>';
/**
* @class OCA.Share.ShareDialogView
* @member {OC.Share.ShareItemModel} model
* @member {jQuery} $el
* @memberof OCA.Sharing
* @classdesc
*
* Represents the GUI of the share dialogue
*
*/
var ShareDialogView = OC.Backbone.View.extend({
/** @type {Object} **/
_templates: {},
/** @type {boolean} **/
_showLink: true,
/** @type {string} **/
tagName: 'div',
/** @type {OC.Share.ShareConfigModel} **/
configModel: undefined,
/** @type {object} **/
resharerInfoView: undefined,
2015-08-21 13:40:50 +00:00
/** @type {object} **/
linkShareView: undefined,
2015-08-21 17:35:13 +00:00
/** @type {object} **/
expirationView: undefined,
initialize: function(options) {
var view = this;
this.model.on('change', function() {
view.render();
});
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 {
throw 'missing OC.Share.ShareConfigModel';
}
var subViewOptions = {
model: this.model,
configModel: this.configModel
};
2015-08-21 18:05:50 +00:00
var subViews = {
resharerInfoView: 'ShareDialogResharerInfoView',
linkShareView: 'ShareDialogLinkShareView',
expirationView: 'ShareDialogExpirationView',
shareeListView: 'ShareDialogShareeListView'
2015-08-21 18:05:50 +00:00
};
2015-08-21 17:35:13 +00:00
2015-08-21 18:05:50 +00:00
for(var name in subViews) {
var className = subViews[name];
this[name] = _.isUndefined(options[name])
? new OC.Share[className](subViewOptions)
: options[name];
}
},
render: function() {
var baseTemplate = this._getTemplate('base', TEMPLATE_BASE);
this.$el.html(baseTemplate({
shareLabel: t('core', 'Share'),
sharePlaceholder: this._renderSharePlaceholderPart(),
remoteShareInfo: this._renderRemoteShareInfoPart(),
}));
2015-08-21 17:35:13 +00:00
this.resharerInfoView.$el = this.$el.find('.resharerInfoView');
this.resharerInfoView.render();
this.linkShareView.$el = this.$el.find('.linkShareView');
this.linkShareView.render();
2015-08-21 17:35:13 +00:00
this.expirationView.$el = this.$el.find('.expirationView');
this.expirationView.render();
this.shareeListView.$el = this.$el.find('.shareeListView');
this.shareeListView.redner();
2015-08-18 15:23:32 +00:00
this.$el.find('.hasTooltip').tooltip();
if(this.configModel.areAvatarsEnabled()) {
this.$el.find('.avatar').avatar(this.model.getReshareOwner, 32);
}
2015-08-18 15:23:32 +00:00
return this;
},
/**
* sets whether share by link should be displayed or not. Default is
* true.
*
* @param {bool} showLink
*/
setShowLink: function(showLink) {
this._showLink = (typeof showLink === 'boolean') ? showLink : true;
2015-08-21 13:40:50 +00:00
this.linkShareView.showLink = this._showLink;
},
_renderRemoteShareInfoPart: function() {
var remoteShareInfo = '';
if(this.configModel.isRemoteShareAllowed()) {
var infoTemplate = this._getRemoteShareInfoTemplate();
remoteShareInfo = infoTemplate({
docLink: this.configModel.getFederatedShareDocLink(),
tooltip: t('core', 'Share with people on other ownClouds using the syntax username@example.com/owncloud')
});
}
2015-08-18 15:23:32 +00:00
return remoteShareInfo;
},
_renderSharePlaceholderPart: function () {
var sharePlaceholder = t('core', 'Share with users or groups …');
if (this.configModel.isRemoteShareAllowed()) {
sharePlaceholder = t('core', 'Share with users, groups or remote users …');
}
return sharePlaceholder;
},
/**
*
* @param {string} key - an identifier for the template
* @param {string} template - the HTML to be compiled by Handlebars
* @returns {Function} from Handlebars
* @private
*/
_getTemplate: function (key, template) {
if (!this._templates[key]) {
this._templates[key] = Handlebars.compile(template);
}
return this._templates[key];
},
/**
* returns the info template for remote sharing
*
* @returns {Function}
* @private
*/
_getRemoteShareInfoTemplate: function() {
return this._getTemplate('remoteShareInfo', TEMPLATE_REMOTE_SHARE_INFO);
}
});
OC.Share.ShareDialogView = ShareDialogView;
})();