2015-08-25 17:07:14 +03: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 =
|
|
|
|
'<ul id="shareWithList">' +
|
|
|
|
'{{#each sharees}}' +
|
2015-09-01 13:43:04 +03:00
|
|
|
' {{#if isCollection}}' +
|
|
|
|
' <li data-collection="{{collectionID}}">{{text}}</li>' +
|
|
|
|
' {{/if}}' +
|
|
|
|
' {{#unless isCollection}}' +
|
2015-08-25 17:07:14 +03:00
|
|
|
' <li data-share-type="{{shareType}}" data-share-with="{{shareWith}}" title="{{shareWith}}">' +
|
2015-09-25 13:11:50 +03:00
|
|
|
' <a href="#" class="unshare"><span class="icon-loading-small hidden"></span><img class="svg" alt="{{unshareLabel}}" title="{{unshareLabel}}" src="{{unshareImage}}" /></a>' +
|
2015-08-25 17:07:14 +03:00
|
|
|
' {{#if avatarEnabled}}' +
|
2015-09-01 13:43:04 +03:00
|
|
|
' <div class="avatar {{#if modSeed}}imageplaceholderseed{{/if}}" data-username="{{shareWith}}" {{#if modSeed}}data-seed="{{shareWith}} {{shareType}}"{{/if}}></div>' +
|
2015-08-25 17:07:14 +03:00
|
|
|
' {{/if}}' +
|
|
|
|
' <span class="username">{{shareWithDisplayName}}</span>' +
|
|
|
|
' {{#if mailPublicNotificationEnabled}} {{#unless isRemoteShare}}' +
|
2015-09-25 12:54:26 +03:00
|
|
|
' <input id="mail-{{shareWith}}" type="checkbox" name="mailNotification" class="mailNotification checkbox" {{#if wasMailSent}}checked="checked"{{/if}} />' +
|
2015-09-17 16:05:24 +03:00
|
|
|
' <label for="mail-{{shareWith}}">{{notifyByMailLabel}}</label>' +
|
2015-08-25 17:07:14 +03:00
|
|
|
' {{/unless}} {{/if}}' +
|
2015-09-02 18:27:25 +03:00
|
|
|
' {{#if isResharingAllowed}} {{#if sharePermissionPossible}} {{#unless isRemoteShare}}' +
|
2015-09-25 12:54:26 +03:00
|
|
|
' <input id="canShare-{{shareWith}}" type="checkbox" name="share" class="permissions checkbox" {{#if hasSharePermission}}checked="checked"{{/if}} data-permissions="{{sharePermission}}" />' +
|
2015-09-17 16:05:24 +03:00
|
|
|
' <label for="canShare-{{shareWith}}">{{canShareLabel}}</label>' +
|
2015-09-02 18:27:25 +03:00
|
|
|
' {{/unless}} {{/if}} {{/if}}' +
|
2015-09-01 13:43:04 +03:00
|
|
|
' {{#if editPermissionPossible}}' +
|
2015-09-25 12:54:26 +03:00
|
|
|
' <input id="canEdit-{{shareWith}}" type="checkbox" name="edit" class="permissions checkbox" {{#if hasEditPermission}}checked="checked"{{/if}} />' +
|
2015-09-17 16:05:24 +03:00
|
|
|
' <label for="canEdit-{{shareWith}}">{{canEditLabel}}</label>' +
|
2015-09-01 13:43:04 +03:00
|
|
|
' {{/if}}' +
|
|
|
|
' {{#unless isRemoteShare}}' +
|
|
|
|
' <a href="#" class="showCruds"><img class="svg" alt="{{crudsLabel}}" src="{{triangleSImage}}"/></a>' +
|
2015-09-14 02:40:16 +03:00
|
|
|
' <div class="cruds hidden">' +
|
2015-09-01 13:43:04 +03:00
|
|
|
' {{#if createPermissionPossible}}' +
|
2015-09-25 12:54:26 +03:00
|
|
|
' <input id="canCreate-{{shareWith}}" type="checkbox" name="create" class="permissions checkbox" {{#if hasCreatePermission}}checked="checked"{{/if}} data-permissions="{{createPermission}}"/>' +
|
2015-09-17 16:05:24 +03:00
|
|
|
' <label for="canCreate-{{shareWith}}">{{createPermissionLabel}}</label>' +
|
2015-09-01 13:43:04 +03:00
|
|
|
' {{/if}}' +
|
|
|
|
' {{#if updatePermissionPossible}}' +
|
2015-09-25 12:54:26 +03:00
|
|
|
' <input id="canUpdate-{{shareWith}}" type="checkbox" name="update" class="permissions checkbox" {{#if hasUpdatePermission}}checked="checked"{{/if}} data-permissions="{{updatePermission}}"/>' +
|
2015-09-17 16:05:24 +03:00
|
|
|
' <label for="canUpdate-{{shareWith}}">{{updatePermissionLabel}}</label>' +
|
2015-09-01 13:43:04 +03:00
|
|
|
' {{/if}}' +
|
2015-09-02 18:27:25 +03:00
|
|
|
' {{#if deletePermissionPossible}} {{#unless isRemoteShare}}' +
|
2015-09-25 12:54:26 +03:00
|
|
|
' <input id="canDelete-{{shareWith}}" type="checkbox" name="delete" class="permissions checkbox" {{#if hasDeletePermission}}checked="checked"{{/if}} data-permissions="{{deletePermission}}"/>' +
|
2015-09-17 16:05:24 +03:00
|
|
|
' <label for="canDelete-{{shareWith}}">{{deletePermissionLabel}}</label>' +
|
2015-09-02 18:27:25 +03:00
|
|
|
' {{/unless}} {{/if}}' +
|
2015-09-01 13:43:04 +03:00
|
|
|
' </div>' +
|
|
|
|
' {{/unless}}' +
|
2015-08-25 17:07:14 +03:00
|
|
|
' </li>' +
|
2015-09-01 13:43:04 +03:00
|
|
|
' {{/unless}}' +
|
2015-08-25 17:07:14 +03:00
|
|
|
'{{/each}}' +
|
|
|
|
'</ul>'
|
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class OCA.Share.ShareDialogShareeListView
|
|
|
|
* @member {OC.Share.ShareItemModel} model
|
|
|
|
* @member {jQuery} $el
|
|
|
|
* @memberof OCA.Sharing
|
|
|
|
* @classdesc
|
|
|
|
*
|
|
|
|
* Represents the sharee list part in the GUI of the share dialogue
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
var ShareDialogShareeListView = OC.Backbone.View.extend({
|
|
|
|
/** @type {string} **/
|
|
|
|
id: 'shareDialogLinkShare',
|
|
|
|
|
|
|
|
/** @type {OC.Share.ShareConfigModel} **/
|
|
|
|
configModel: undefined,
|
|
|
|
|
|
|
|
/** @type {Function} **/
|
|
|
|
_template: undefined,
|
|
|
|
|
|
|
|
/** @type {boolean} **/
|
|
|
|
showLink: true,
|
|
|
|
|
2015-09-02 14:06:00 +03:00
|
|
|
/** @type {object} **/
|
|
|
|
_collections: {},
|
|
|
|
|
2015-09-14 18:47:47 +03:00
|
|
|
events: {
|
|
|
|
'click .unshare': 'onUnshare',
|
|
|
|
'click .permissions': 'onPermissionChange',
|
2015-09-14 19:03:44 +03:00
|
|
|
'click .showCruds': 'onCrudsToggle',
|
|
|
|
'click .mailNotification': 'onSendMailNotification'
|
2015-09-14 18:47:47 +03:00
|
|
|
},
|
|
|
|
|
2015-08-25 17:07:14 +03:00
|
|
|
initialize: function(options) {
|
|
|
|
if(!_.isUndefined(options.configModel)) {
|
|
|
|
this.configModel = options.configModel;
|
|
|
|
} else {
|
|
|
|
throw 'missing OC.Share.ShareConfigModel';
|
|
|
|
}
|
2015-09-01 13:43:04 +03:00
|
|
|
|
|
|
|
var view = this;
|
|
|
|
this.model.on('change:shares', function() {
|
|
|
|
view.render();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-09-02 14:06:00 +03:00
|
|
|
processCollectionShare: function(shareIndex) {
|
|
|
|
var type = this.model.getCollectionType(shareIndex);
|
|
|
|
var id = this.model.getCollectionPath(shareIndex);
|
|
|
|
if(type !== 'file' && type !== 'folder') {
|
|
|
|
id = this.model.getCollectionSource(shareIndex);
|
|
|
|
}
|
|
|
|
var displayName = this.model.getShareWithDisplayName(shareIndex);
|
|
|
|
if(!_.isUndefined(this._collections[id])) {
|
|
|
|
this._collections[id].text = this._collections[id].text + ", " + displayName;
|
|
|
|
} else {
|
|
|
|
this._collections[id] = {};
|
|
|
|
this._collections[id].text = t('core', 'Shared in {item} with {user}', {'item': id, user: displayName});
|
|
|
|
this._collections[id].id = id;
|
|
|
|
this._collections[id].isCollection = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-09-01 13:43:04 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {OC.Share.Types.ShareInfo} shareInfo
|
|
|
|
* @returns {object}
|
|
|
|
*/
|
|
|
|
getShareeObject: function(shareIndex) {
|
|
|
|
var shareWith = this.model.getShareWith(shareIndex);
|
|
|
|
var shareWithDisplayName = this.model.getShareWithDisplayName(shareIndex);
|
|
|
|
var shareType = this.model.getShareType(shareIndex);
|
|
|
|
|
2015-09-02 18:27:25 +03:00
|
|
|
var hasPermissionOverride = {};
|
2015-09-01 13:43:04 +03:00
|
|
|
if (shareType === OC.Share.SHARE_TYPE_GROUP) {
|
|
|
|
shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'group') + ')';
|
|
|
|
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
|
|
|
|
shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'remote') + ')';
|
2015-09-02 18:27:25 +03:00
|
|
|
hasPermissionOverride = {
|
|
|
|
createPermissionPossible: true,
|
|
|
|
updatePermissionPossible: true
|
|
|
|
};
|
2015-09-01 13:43:04 +03:00
|
|
|
}
|
|
|
|
|
2015-09-02 18:27:25 +03:00
|
|
|
return _.extend(hasPermissionOverride, {
|
2015-09-01 13:43:04 +03:00
|
|
|
hasSharePermission: this.model.hasSharePermission(shareIndex),
|
|
|
|
hasEditPermission: this.model.hasEditPermission(shareIndex),
|
|
|
|
hasCreatePermission: this.model.hasCreatePermission(shareIndex),
|
|
|
|
hasUpdatePermission: this.model.hasUpdatePermission(shareIndex),
|
|
|
|
hasDeletePermission: this.model.hasDeletePermission(shareIndex),
|
|
|
|
wasMailSent: this.model.notificationMailWasSent(shareIndex),
|
|
|
|
shareWith: shareWith,
|
|
|
|
shareWithDisplayName: shareWithDisplayName,
|
|
|
|
shareType: shareType,
|
2015-09-02 17:47:25 +03:00
|
|
|
modSeed: shareType !== OC.Share.SHARE_TYPE_USER,
|
|
|
|
isRemoteShare: shareType === OC.Share.SHARE_TYPE_REMOTE
|
2015-09-02 18:27:25 +03:00
|
|
|
});
|
2015-08-25 17:07:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getShareeList: function() {
|
|
|
|
var universal = {
|
|
|
|
avatarEnabled: this.configModel.areAvatarsEnabled(),
|
|
|
|
mailPublicNotificationEnabled: this.configModel.isMailPublicNotificationEnabled(),
|
|
|
|
notifyByMailLabel: t('core', 'notify by email'),
|
|
|
|
unshareLabel: t('core', 'Unshare'),
|
2015-09-01 13:43:04 +03:00
|
|
|
unshareImage: OC.imagePath('core', 'actions/delete'),
|
|
|
|
canShareLabel: t('core', 'can share'),
|
|
|
|
canEditLabel: t('core', 'can edit'),
|
|
|
|
createPermissionLabel: t('core', 'create'),
|
|
|
|
updatePermissionLabel: t('core', 'change'),
|
|
|
|
deletePermissionLabel: t('core', 'delete'),
|
|
|
|
crudsLabel: t('core', 'access control'),
|
|
|
|
triangleSImage: OC.imagePath('core', 'actions/triangle-s'),
|
2015-09-05 03:02:55 +03:00
|
|
|
isResharingAllowed: this.configModel.get('isResharingAllowed'),
|
2015-09-01 13:43:04 +03:00
|
|
|
sharePermissionPossible: this.model.sharePermissionPossible(),
|
|
|
|
editPermissionPossible: this.model.editPermissionPossible(),
|
|
|
|
createPermissionPossible: this.model.createPermissionPossible(),
|
|
|
|
updatePermissionPossible: this.model.updatePermissionPossible(),
|
|
|
|
deletePermissionPossible: this.model.deletePermissionPossible(),
|
|
|
|
sharePermission: OC.PERMISSION_SHARE,
|
|
|
|
createPermission: OC.PERMISSION_CREATE,
|
|
|
|
updatePermission: OC.PERMISSION_UPDATE,
|
|
|
|
deletePermission: OC.PERMISSION_DELETE
|
2015-08-25 17:07:14 +03:00
|
|
|
};
|
|
|
|
|
2015-09-02 14:06:00 +03:00
|
|
|
this._collections = {};
|
|
|
|
|
2015-09-14 18:20:51 +03:00
|
|
|
if(!this.model.hasUserShares()) {
|
2015-09-01 13:43:04 +03:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2015-09-02 14:06:00 +03:00
|
|
|
var shares = this.model.get('shares');
|
2015-09-01 13:43:04 +03:00
|
|
|
var list = [];
|
2015-09-02 14:06:00 +03:00
|
|
|
for(var index = 0; index < shares.length; index++) {
|
2015-09-01 13:43:04 +03:00
|
|
|
if(this.model.isCollection(index)) {
|
2015-09-02 14:06:00 +03:00
|
|
|
this.processCollectionShare(index);
|
2015-09-01 13:43:04 +03:00
|
|
|
} else {
|
2015-09-05 03:02:55 +03:00
|
|
|
// first empty {} is necessary, otherwise we get in trouble
|
|
|
|
// with references
|
|
|
|
list.push(_.extend({}, universal, this.getShareeObject(index)));
|
2015-09-01 13:43:04 +03:00
|
|
|
}
|
|
|
|
}
|
2015-09-05 03:02:55 +03:00
|
|
|
list = _.union(_.values(this._collections), list);
|
2015-08-25 17:07:14 +03:00
|
|
|
|
|
|
|
return list;
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var shareeListTemplate = this.template();
|
|
|
|
this.$el.html(shareeListTemplate({
|
|
|
|
sharees: this.getShareeList()
|
|
|
|
}));
|
|
|
|
|
2015-09-12 15:21:14 +03:00
|
|
|
if(this.configModel.areAvatarsEnabled()) {
|
|
|
|
this.$el.find('.avatar').each(function() {
|
|
|
|
var $this = $(this);
|
2015-09-15 16:29:30 +03:00
|
|
|
if ($this.hasClass('imageplaceholderseed')) {
|
|
|
|
$this.css({width: 32, height: 32});
|
|
|
|
$this.imageplaceholder($this.data('seed'));
|
|
|
|
} else {
|
|
|
|
$this.avatar($this.data('username'), 32);
|
|
|
|
}
|
2015-09-12 15:21:14 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-09-14 18:47:47 +03:00
|
|
|
this.delegateEvents();
|
2015-09-14 02:24:21 +03:00
|
|
|
|
2015-08-25 17:07:14 +03:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {Function} from Handlebars
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
template: function () {
|
|
|
|
if (!this._template) {
|
|
|
|
this._template = Handlebars.compile(TEMPLATE);
|
|
|
|
}
|
|
|
|
return this._template;
|
2015-09-14 02:24:21 +03:00
|
|
|
},
|
|
|
|
|
2015-09-14 18:47:47 +03:00
|
|
|
onUnshare: function(event) {
|
|
|
|
var $element = $(event.target);
|
2015-09-25 13:11:50 +03:00
|
|
|
console.log($element);
|
2015-09-14 02:24:21 +03:00
|
|
|
|
2015-09-25 13:11:50 +03:00
|
|
|
var $loading = $element.siblings('.icon-loading-small').eq(0);
|
|
|
|
if(!$loading.hasClass('hidden')) {
|
2015-09-14 02:24:21 +03:00
|
|
|
// in process
|
|
|
|
return;
|
|
|
|
}
|
2015-09-25 13:11:50 +03:00
|
|
|
$loading.removeClass('hidden');
|
2015-09-14 02:24:21 +03:00
|
|
|
|
|
|
|
var $li = $element.closest('li');
|
|
|
|
var shareType = $li.data('share-type');
|
|
|
|
var shareWith = $li.attr('data-share-with');
|
|
|
|
|
2015-09-14 18:47:47 +03:00
|
|
|
this.model.removeShare(shareType, shareWith);
|
2015-09-14 02:24:21 +03:00
|
|
|
|
2015-09-14 02:40:16 +03:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-09-14 18:47:47 +03:00
|
|
|
onPermissionChange: function(event) {
|
|
|
|
var $element = $(event.target);
|
2015-09-14 03:29:22 +03:00
|
|
|
var $li = $element.closest('li');
|
|
|
|
var shareType = $li.data('share-type');
|
|
|
|
var shareWith = $li.attr('data-share-with');
|
|
|
|
|
|
|
|
// adjust checkbox states
|
|
|
|
var $checkboxes = $('.permissions', $li).not('input[name="edit"]').not('input[name="share"]');
|
2015-09-14 18:47:47 +03:00
|
|
|
var checked;
|
2015-09-14 03:29:22 +03:00
|
|
|
if ($element.attr('name') === 'edit') {
|
2015-09-14 18:47:47 +03:00
|
|
|
checked = $element.is(':checked');
|
2015-09-14 03:29:22 +03:00
|
|
|
// Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck
|
|
|
|
$($checkboxes).attr('checked', checked);
|
|
|
|
} else {
|
|
|
|
var numberChecked = $checkboxes.filter(':checked').length;
|
2015-09-14 18:47:47 +03:00
|
|
|
checked = numberChecked > 0;
|
2015-09-14 03:29:22 +03:00
|
|
|
$('input[name="edit"]', $li).attr('checked', checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
var permissions = OC.PERMISSION_READ;
|
|
|
|
$('.permissions', $li).not('input[name="edit"]').filter(':checked').each(function(index, checkbox) {
|
|
|
|
permissions |= $(checkbox).data('permissions');
|
|
|
|
});
|
|
|
|
|
2015-09-14 18:47:47 +03:00
|
|
|
this.model.setPermissions(shareType, shareWith, permissions);
|
2015-09-14 03:29:22 +03:00
|
|
|
},
|
|
|
|
|
2015-09-15 16:51:21 +03:00
|
|
|
onCrudsToggle: function(event) {
|
|
|
|
var $target = $(event.target);
|
|
|
|
$target.closest('li').find('.cruds').toggleClass('hidden');
|
2015-09-14 02:24:21 +03:00
|
|
|
return false;
|
2015-09-14 19:03:44 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onSendMailNotification: function(event) {
|
|
|
|
var $target = $(event.target);
|
|
|
|
var $li = $(event.target).closest('li');
|
|
|
|
var shareType = $li.data('share-type');
|
|
|
|
var shareWith = $li.attr('data-share-with');
|
2015-08-25 17:07:14 +03:00
|
|
|
|
2015-09-14 19:03:44 +03:00
|
|
|
this.model.sendNotificationForShare(shareType, shareWith, $target.is(':checked'));
|
|
|
|
}
|
2015-08-25 17:07:14 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
OC.Share.ShareDialogShareeListView = ShareDialogShareeListView;
|
|
|
|
|
|
|
|
})();
|