improve reshare rendering part and move permission calculation to model
This commit is contained in:
parent
97b5fe0b1e
commit
b015eff2e9
3 changed files with 87 additions and 39 deletions
|
@ -382,18 +382,19 @@ OC.Share = _.extend(OC.Share, {
|
|||
});
|
||||
},
|
||||
showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) {
|
||||
var attributes = {itemType: itemType, itemSource: itemSource};
|
||||
var attributes = {itemType: itemType, itemSource: itemSource, possiblePermissions: possiblePermissions};
|
||||
var itemModel = new OC.Share.ShareItemModel(attributes);
|
||||
var dialogView = new OC.Share.ShareDialogView({
|
||||
id: 'dropdown',
|
||||
model: itemModel,
|
||||
className: 'drop shareDropDown',
|
||||
attributes: {
|
||||
'data-item-source-name': filename
|
||||
'data-item-source-name': filename,
|
||||
'data-item-type': itemType,
|
||||
'data-item-soruce': itemSource
|
||||
}
|
||||
});
|
||||
dialogView.setShowLink(link);
|
||||
dialogView.setPossiblePermissions(possiblePermissions);
|
||||
var $dialog = dialogView.render().$el;
|
||||
$dialog.appendTo(appendTo);
|
||||
$dialog.slideDown(OC.menuSpeed, function() {
|
||||
|
|
|
@ -70,9 +70,6 @@
|
|||
/** @type {boolean} **/
|
||||
_showLink: true,
|
||||
|
||||
/** @type {unknown} **/
|
||||
_possiblePermissions: null,
|
||||
|
||||
/** @type {string} **/
|
||||
tagName: 'div',
|
||||
|
||||
|
@ -91,7 +88,6 @@
|
|||
var baseTemplate = this._getTemplate('base', TEMPLATE_BASE);
|
||||
|
||||
this.$el.html(baseTemplate({
|
||||
|
||||
shareLabel: t('core', 'Share'),
|
||||
resharerInfo: this._renderResharerInfo(),
|
||||
sharePlaceholder: this._renderSharePlaceholderPart(),
|
||||
|
@ -112,41 +108,37 @@
|
|||
this._showLink = (typeof showLink === 'boolean') ? showLink : true;
|
||||
},
|
||||
|
||||
setPossiblePermissions: function(permissions) {
|
||||
//TODO: maybe move to model? Whatever this is.
|
||||
this._possiblePermissions = permissions;
|
||||
},
|
||||
|
||||
_renderResharerInfo: function() {
|
||||
var resharerInfo = '';
|
||||
if ( this.model.hasReshare()
|
||||
&& this.model.getReshareOwner() !== OC.currentUser)
|
||||
if ( !this.model.hasReshare()
|
||||
|| !this.model.getReshareOwner() !== OC.currentUser)
|
||||
{
|
||||
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() }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
resharerInfo = reshareTemplate({
|
||||
avatarEnabled: oc_config.enable_avatars === true,
|
||||
sharedByText: sharedByText
|
||||
});
|
||||
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: oc_config.enable_avatars === true,
|
||||
sharedByText: sharedByText
|
||||
});
|
||||
},
|
||||
|
||||
_renderRemoteShareInfoPart: function() {
|
||||
|
|
|
@ -57,6 +57,22 @@
|
|||
this.fetch();
|
||||
},
|
||||
|
||||
defaults: {
|
||||
allowPublicUploadStatus: false
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {boolean|jQuery}
|
||||
*/
|
||||
isPublicUploadEnabled: function() {
|
||||
// FIXME: this really needs a better place
|
||||
var publicUploadEnabled = $('#filestable').data('allow-public-upload');
|
||||
if (_.isUndefined(publicUploadEnabled)) {
|
||||
publicUploadEnabled = 'no';
|
||||
}
|
||||
return publicUploadEnabled;
|
||||
},
|
||||
|
||||
/**
|
||||
* whether this item has reshare information
|
||||
* @returns {boolean}
|
||||
|
@ -101,6 +117,26 @@
|
|||
return this.get('reshare').share_type;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
getPermissions: function() {
|
||||
var permissions = this.get('permissions');
|
||||
if(_.isUndefined(permissions)) {
|
||||
// model was not properly initialized
|
||||
console.warn('Sharing error: undefined permissions');
|
||||
permissions = 0;
|
||||
}
|
||||
return permissions;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasSharePermission: function() {
|
||||
return (this.getPermissions & OC.PERMISSION_SHARE) === OC.PERMISSION_SHARE;
|
||||
},
|
||||
|
||||
fetch: function() {
|
||||
var model = this;
|
||||
OC.Share.loadItem(this.get('itemType'), this.get('itemSource'), function(data) {
|
||||
|
@ -114,10 +150,29 @@
|
|||
trigger('fetchError');
|
||||
return {};
|
||||
}
|
||||
|
||||
var permissions = this.get('possiblePermissions');
|
||||
if(!_.isUndefined(data.reshare) && !_.isUndefined(data.reshare.permissions)) {
|
||||
permissions = permissions & data.reshare.permissions;
|
||||
}
|
||||
|
||||
var allowPublicUploadStatus = false;
|
||||
if(!_.isUndefined(data.shares)) {
|
||||
$.each(data.shares, function (key, value) {
|
||||
if (value.share_type === OC.Share.SHARE_TYPE_LINK) {
|
||||
allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var attributes = {
|
||||
reshare: data.reshare,
|
||||
shares: data.shares
|
||||
shares: data.shares,
|
||||
permissions: permissions,
|
||||
allowPublicUploadStatus: allowPublicUploadStatus
|
||||
};
|
||||
|
||||
return attributes;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue