/*
* 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 =
'
' +
'{{#if isSharingAllowed}}' +
'' +
'
' +
' ' +
' '+
'{{{remoteShareInfo}}}' +
'
' +
'{{/if}}' +
'' +
'' +
'' +
'';
var TEMPLATE_REMOTE_SHARE_INFO =
'';
/**
* @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,
/** @type {object} **/
linkShareView: undefined,
/** @type {object} **/
expirationView: undefined,
/** @type {object} **/
shareeListView: undefined,
initialize: function(options) {
var view = this;
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';
}
this.configModel.on('change:isRemoteShareAllowed', function() {
view.render();
});
this.model.on('change:permissions', function() {
view.render();
});
this.model.on('request', this._onRequest, this);
this.model.on('sync', this._onEndRequest, this);
var subViewOptions = {
model: this.model,
configModel: this.configModel
};
var subViews = {
resharerInfoView: 'ShareDialogResharerInfoView',
linkShareView: 'ShareDialogLinkShareView',
expirationView: 'ShareDialogExpirationView',
shareeListView: 'ShareDialogShareeListView'
};
for(var name in subViews) {
var className = subViews[name];
this[name] = _.isUndefined(options[name])
? new OC.Share[className](subViewOptions)
: options[name];
}
_.bindAll(this, 'autocompleteHandler', '_onSelectRecipient');
},
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) {
$('.shareWithField').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);
});
},
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 $("