2015-07-30 22:07:41 +00:00
|
|
|
/*
|
|
|
|
* 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-09-28 13:57:57 +00:00
|
|
|
'<div class="resharerInfoView subView"></div>' +
|
2015-09-15 13:29:30 +00:00
|
|
|
'{{#if isSharingAllowed}}' +
|
2015-10-16 08:54:45 +00:00
|
|
|
'<label for="shareWith-{{cid}}" class="hidden-visually">{{shareLabel}}</label>' +
|
2015-08-07 22:23:06 +00:00
|
|
|
'<div class="oneline">' +
|
2015-10-16 08:54:45 +00:00
|
|
|
' <input id="shareWith-{{cid}}" class="shareWithField" type="text" placeholder="{{sharePlaceholder}}" />' +
|
2015-08-07 22:23:06 +00:00
|
|
|
' <span class="shareWithLoading icon-loading-small hidden"></span>'+
|
|
|
|
'{{{remoteShareInfo}}}' +
|
2015-09-15 14:14:29 +00:00
|
|
|
'</div>' +
|
2015-09-15 13:29:30 +00:00
|
|
|
'{{/if}}' +
|
2015-09-28 13:57:57 +00:00
|
|
|
'<div class="shareeListView subView"></div>' +
|
|
|
|
'<div class="linkShareView subView"></div>' +
|
|
|
|
'<div class="expirationView subView"></div>' +
|
|
|
|
'<div class="loading hidden" style="height: 50px"></div>';
|
2015-07-30 22:07:41 +00:00
|
|
|
|
|
|
|
var TEMPLATE_REMOTE_SHARE_INFO =
|
2015-08-18 15:23:32 +00:00
|
|
|
'<a target="_blank" class="icon-info svg shareWithRemoteInfo hasTooltip" href="{{docLink}}" ' +
|
2015-07-30 22:07:41 +00:00
|
|
|
'title="{{tooltip}}"></a>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class OCA.Share.ShareDialogView
|
2015-08-07 22:23:06 +00:00
|
|
|
* @member {OC.Share.ShareItemModel} model
|
|
|
|
* @member {jQuery} $el
|
|
|
|
* @memberof OCA.Sharing
|
2015-07-30 22:07:41 +00:00
|
|
|
* @classdesc
|
|
|
|
*
|
|
|
|
* Represents the GUI of the share dialogue
|
|
|
|
*
|
|
|
|
*/
|
2015-08-07 22:23:06 +00:00
|
|
|
var ShareDialogView = OC.Backbone.View.extend({
|
|
|
|
/** @type {Object} **/
|
2015-07-30 22:07:41 +00:00
|
|
|
_templates: {},
|
|
|
|
|
2015-08-07 22:23:06 +00:00
|
|
|
/** @type {boolean} **/
|
2015-07-30 22:07:41 +00:00
|
|
|
_showLink: true,
|
|
|
|
|
2015-08-07 22:23:06 +00:00
|
|
|
/** @type {string} **/
|
|
|
|
tagName: 'div',
|
|
|
|
|
2015-08-13 00:38:14 +00:00
|
|
|
/** @type {OC.Share.ShareConfigModel} **/
|
|
|
|
configModel: undefined,
|
|
|
|
|
2015-08-18 22:04:16 +00:00
|
|
|
/** @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,
|
|
|
|
|
2015-09-01 10:43:04 +00:00
|
|
|
/** @type {object} **/
|
|
|
|
shareeListView: undefined,
|
|
|
|
|
2015-08-13 00:38:14 +00:00
|
|
|
initialize: function(options) {
|
2015-08-11 20:36:28 +00:00
|
|
|
var view = this;
|
|
|
|
|
|
|
|
this.model.on('fetchError', function() {
|
|
|
|
OC.Notification.showTemporary(t('core', 'Share details could not be loaded for this item.'));
|
|
|
|
});
|
2015-08-13 00:38:14 +00:00
|
|
|
|
|
|
|
if(!_.isUndefined(options.configModel)) {
|
|
|
|
this.configModel = options.configModel;
|
|
|
|
} else {
|
2015-08-24 21:20:01 +00:00
|
|
|
throw 'missing OC.Share.ShareConfigModel';
|
2015-08-13 00:38:14 +00:00
|
|
|
}
|
2015-08-18 22:04:16 +00:00
|
|
|
|
2015-09-12 12:21:14 +00:00
|
|
|
this.configModel.on('change:isRemoteShareAllowed', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
2015-09-15 13:29:30 +00:00
|
|
|
this.model.on('change:permissions', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
2015-09-12 12:21:14 +00:00
|
|
|
|
2015-09-28 13:57:57 +00:00
|
|
|
this.model.on('request', this._onRequest, this);
|
|
|
|
this.model.on('sync', this._onEndRequest, this);
|
|
|
|
|
2015-08-18 22:04:16 +00:00
|
|
|
var subViewOptions = {
|
|
|
|
model: this.model,
|
|
|
|
configModel: this.configModel
|
|
|
|
};
|
|
|
|
|
2015-08-21 18:05:50 +00:00
|
|
|
var subViews = {
|
|
|
|
resharerInfoView: 'ShareDialogResharerInfoView',
|
|
|
|
linkShareView: 'ShareDialogLinkShareView',
|
2015-08-25 14:07:14 +00:00
|
|
|
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];
|
|
|
|
}
|
2015-09-05 00:02:55 +00:00
|
|
|
|
2015-09-14 15:47:47 +00:00
|
|
|
_.bindAll(this, 'autocompleteHandler', '_onSelectRecipient');
|
2015-09-05 00:02:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
autocompleteHandler: function (search, response) {
|
|
|
|
var view = this;
|
|
|
|
var $loading = this.$el.find('.shareWithLoading');
|
|
|
|
$loading.removeClass('hidden');
|
|
|
|
$loading.addClass('inlineblock');
|
2015-12-23 09:16:57 +00:00
|
|
|
$.get(
|
|
|
|
OC.linkToOCS('apps/files_sharing/api/v1') + 'sharees',
|
|
|
|
{
|
|
|
|
format: 'json',
|
|
|
|
search: search.term.trim(),
|
|
|
|
perPage: 200,
|
|
|
|
itemType: view.model.get('itemType')
|
|
|
|
},
|
|
|
|
function (result) {
|
|
|
|
$loading.addClass('hidden');
|
|
|
|
$loading.removeClass('inlineblock');
|
|
|
|
if (result.ocs.meta.statuscode == 100) {
|
|
|
|
var users = [].concat(result.ocs.data.exact.users).concat(result.ocs.data.users);
|
|
|
|
var groups = result.ocs.data.exact.groups.concat(result.ocs.data.groups);
|
|
|
|
var remotes = result.ocs.data.exact.remotes.concat(result.ocs.data.remotes);
|
|
|
|
|
|
|
|
var usersLength;
|
|
|
|
var groupsLength;
|
|
|
|
var remotesLength;
|
|
|
|
|
|
|
|
var i, j;
|
|
|
|
|
|
|
|
//Filter out the current user
|
|
|
|
usersLength = users.length;
|
|
|
|
for (i = 0 ; i < usersLength; i++) {
|
|
|
|
if (users[i].value.shareWith === OC.currentUser) {
|
|
|
|
users.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter out the owner of the share
|
|
|
|
|
|
|
|
var shares = view.model.get('shares');
|
|
|
|
var sharesLength = shares.length;
|
|
|
|
|
|
|
|
// Now filter out all sharees that are already shared with
|
|
|
|
for (i = 0; i < sharesLength; i++) {
|
|
|
|
var share = shares[i];
|
|
|
|
|
|
|
|
if (share.share_type === OC.Share.SHARE_TYPE_USER) {
|
|
|
|
usersLength = users.length;
|
|
|
|
for (j = 0; j < usersLength; j++) {
|
|
|
|
if (users[j].value.shareWith === share.share_with) {
|
|
|
|
users.splice(j, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (share.share_type === OC.Share.SHARE_TYPE_GROUP) {
|
|
|
|
groupsLength = groups.length;
|
|
|
|
for (j = 0; j < groupsLength; j++) {
|
|
|
|
if (groups[j].value.shareWith === share.share_with) {
|
|
|
|
groups.splice(j, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (share.share_type === OC.Share.SHARE_TYPE_REMOTE) {
|
|
|
|
remotesLength = remotes.length;
|
|
|
|
for (j = 0; j < remotesLength; j++) {
|
|
|
|
if (remotes[j].value.shareWith === share.share_with) {
|
|
|
|
remotes.splice(j, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var suggestions = users.concat(groups).concat(remotes);
|
|
|
|
|
|
|
|
$('.shareWithField').autocomplete("option", "autoFocus", true);
|
|
|
|
response(suggestions);
|
|
|
|
} else {
|
|
|
|
response();
|
|
|
|
}
|
2015-09-05 00:02:55 +00:00
|
|
|
}
|
2015-12-23 09:16:57 +00:00
|
|
|
).fail(function() {
|
2015-09-05 00:02:55 +00:00
|
|
|
$loading.addClass('hidden');
|
|
|
|
$loading.removeClass('inlineblock');
|
|
|
|
OC.Notification.show(t('core', 'An error occured. Please try again'));
|
|
|
|
window.setTimeout(OC.Notification.hide, 5000);
|
|
|
|
});
|
2015-08-11 20:36:28 +00:00
|
|
|
},
|
|
|
|
|
2015-09-12 10:17:15 +00:00
|
|
|
autocompleteRenderItem: function(ul, item) {
|
|
|
|
var insert = $("<a>");
|
|
|
|
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('<strong></strong>');
|
|
|
|
}
|
|
|
|
return $("<li>")
|
|
|
|
.addClass((item.value.shareType === OC.Share.SHARE_TYPE_GROUP) ? 'group' : 'user')
|
|
|
|
.append(insert)
|
|
|
|
.appendTo(ul);
|
|
|
|
},
|
|
|
|
|
2015-09-14 15:47:47 +00:00
|
|
|
_onSelectRecipient: function(e, s) {
|
|
|
|
e.preventDefault();
|
2015-09-14 15:49:48 +00:00
|
|
|
$(e.target).val('');
|
2015-09-14 15:47:47 +00:00
|
|
|
this.model.addShare(s.item.value);
|
|
|
|
},
|
|
|
|
|
2015-09-28 13:57:57 +00:00
|
|
|
_toggleLoading: function(state) {
|
|
|
|
this._loading = state;
|
|
|
|
this.$el.find('.subView').toggleClass('hidden', state);
|
|
|
|
this.$el.find('.loading').toggleClass('hidden', !state);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onRequest: function() {
|
|
|
|
// only show the loading spinner for the first request (for now)
|
|
|
|
if (!this._loadingOnce) {
|
|
|
|
this._toggleLoading(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onEndRequest: function() {
|
2015-10-02 14:35:33 +00:00
|
|
|
var self = this;
|
2015-09-28 13:57:57 +00:00
|
|
|
this._toggleLoading(false);
|
2015-10-02 14:35:33 +00:00
|
|
|
if (!this._loadingOnce) {
|
|
|
|
this._loadingOnce = true;
|
|
|
|
// the first time, focus on the share field after the spinner disappeared
|
|
|
|
_.defer(function() {
|
2015-10-16 08:54:45 +00:00
|
|
|
self.$('.shareWithField').focus();
|
2015-10-02 14:35:33 +00:00
|
|
|
});
|
|
|
|
}
|
2015-09-28 13:57:57 +00:00
|
|
|
},
|
|
|
|
|
2015-07-30 22:07:41 +00:00
|
|
|
render: function() {
|
|
|
|
var baseTemplate = this._getTemplate('base', TEMPLATE_BASE);
|
|
|
|
|
2015-08-07 22:23:06 +00:00
|
|
|
this.$el.html(baseTemplate({
|
2015-10-16 08:54:45 +00:00
|
|
|
cid: this.cid,
|
2015-07-30 22:07:41 +00:00
|
|
|
shareLabel: t('core', 'Share'),
|
|
|
|
sharePlaceholder: this._renderSharePlaceholderPart(),
|
2015-09-15 13:29:30 +00:00
|
|
|
remoteShareInfo: this._renderRemoteShareInfoPart(),
|
|
|
|
isSharingAllowed: this.model.sharePermissionPossible()
|
2015-07-30 22:07:41 +00:00
|
|
|
}));
|
|
|
|
|
2015-10-16 08:54:45 +00:00
|
|
|
var $shareField = this.$el.find('.shareWithField');
|
2015-09-15 13:29:30 +00:00
|
|
|
if ($shareField.length) {
|
|
|
|
$shareField.autocomplete({
|
|
|
|
minLength: 2,
|
|
|
|
delay: 750,
|
2015-09-22 15:16:20 +00:00
|
|
|
focus: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
2015-09-15 13:29:30 +00:00
|
|
|
source: this.autocompleteHandler,
|
|
|
|
select: this._onSelectRecipient
|
|
|
|
}).data('ui-autocomplete')._renderItem = this.autocompleteRenderItem;
|
|
|
|
}
|
2015-09-05 00:02:55 +00:00
|
|
|
|
2015-08-21 17:35:13 +00:00
|
|
|
this.resharerInfoView.$el = this.$el.find('.resharerInfoView');
|
2015-08-21 13:00:15 +00:00
|
|
|
this.resharerInfoView.render();
|
|
|
|
|
2015-08-21 18:29:12 +00:00
|
|
|
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();
|
|
|
|
|
2015-08-25 14:07:14 +00:00
|
|
|
this.shareeListView.$el = this.$el.find('.shareeListView');
|
2015-09-01 10:43:04 +00:00
|
|
|
this.shareeListView.render();
|
2015-08-25 14:07:14 +00:00
|
|
|
|
2015-08-18 15:23:32 +00:00
|
|
|
this.$el.find('.hasTooltip').tooltip();
|
|
|
|
|
2015-08-07 22:23:06 +00:00
|
|
|
return this;
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2015-07-30 22:07:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_renderRemoteShareInfoPart: function() {
|
|
|
|
var remoteShareInfo = '';
|
2015-09-12 12:21:14 +00:00
|
|
|
if(this.configModel.get('isRemoteShareAllowed')) {
|
2015-07-30 22:07:41 +00:00
|
|
|
var infoTemplate = this._getRemoteShareInfoTemplate();
|
|
|
|
remoteShareInfo = infoTemplate({
|
2015-08-18 10:13:08 +00:00
|
|
|
docLink: this.configModel.getFederatedShareDocLink(),
|
2015-07-30 22:07:41 +00:00
|
|
|
tooltip: t('core', 'Share with people on other ownClouds using the syntax username@example.com/owncloud')
|
|
|
|
});
|
|
|
|
}
|
2015-08-18 15:23:32 +00:00
|
|
|
|
2015-07-30 22:07:41 +00:00
|
|
|
return remoteShareInfo;
|
|
|
|
},
|
|
|
|
|
|
|
|
_renderSharePlaceholderPart: function () {
|
|
|
|
var sharePlaceholder = t('core', 'Share with users or groups …');
|
2015-09-12 12:21:14 +00:00
|
|
|
if (this.configModel.get('isRemoteShareAllowed')) {
|
2015-07-30 22:07:41 +00:00
|
|
|
sharePlaceholder = t('core', 'Share with users, groups or remote users …');
|
|
|
|
}
|
|
|
|
return sharePlaceholder;
|
|
|
|
},
|
|
|
|
|
2015-08-10 19:46:46 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {string} key - an identifier for the template
|
|
|
|
* @param {string} template - the HTML to be compiled by Handlebars
|
|
|
|
* @returns {Function} from Handlebars
|
|
|
|
* @private
|
|
|
|
*/
|
2015-07-30 22:07:41 +00:00
|
|
|
_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
|
|
|
|
*
|
2015-08-10 19:46:46 +00:00
|
|
|
* @returns {Function}
|
2015-07-30 22:07:41 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_getRemoteShareInfoTemplate: function() {
|
|
|
|
return this._getTemplate('remoteShareInfo', TEMPLATE_REMOTE_SHARE_INFO);
|
2015-08-07 22:23:06 +00:00
|
|
|
}
|
|
|
|
});
|
2015-07-30 22:07:41 +00:00
|
|
|
|
|
|
|
OC.Share.ShareDialogView = ShareDialogView;
|
|
|
|
|
|
|
|
})();
|