Skip to content

Commit

Permalink
Share dialog use OCS API
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Jan 27, 2016
1 parent 308396b commit f8aa0f5
Show file tree
Hide file tree
Showing 8 changed files with 613 additions and 537 deletions.
7 changes: 0 additions & 7 deletions core/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,6 @@ OC.Share = _.extend(OC.Share || {}, {
}
});
},
setPermissions:function(itemType, itemSource, shareType, shareWith, permissions) {
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
if (!result || result.status !== 'success') {
OC.dialogs.alert(t('core', 'Error while changing permissions'), t('core', 'Error'));
}
});
},
showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) {
var configModel = new OC.Share.ShareConfigModel();
var attributes = {itemType: itemType, itemSource: itemSource, possiblePermissions: possiblePermissions};
Expand Down
10 changes: 6 additions & 4 deletions core/js/sharedialogexpirationview.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@
this.$el.find('.expirationDateContainer').toggleClass('hidden', !state);
if (!state) {
// discard expiration date
this.model.setExpirationDate('');
this.model.saveLinkShare();
this.model.saveLinkShare({
expiration: ''
});
}
},

Expand All @@ -103,8 +104,9 @@
$target.tooltip('hide');
$target.removeClass('error');

this.model.setExpirationDate($target.val());
this.model.saveLinkShare(null, {
this.model.saveLinkShare({
expiration: moment($target.val(), 'DD-MM-YYYY').format('YYYY-MM-DD')
}, {
error: function(model, message) {
if (!message) {
$target.attr('title', t('core', 'Error setting expiration date'));
Expand Down
22 changes: 15 additions & 7 deletions core/js/sharedialoglinkshareview.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@
onShowPasswordClick: function() {
this.$el.find('.linkPass').slideToggle(OC.menuSpeed);
if(!this.$el.find('.showPasswordCheckbox').is(':checked')) {
this.model.setPassword('');
this.model.saveLinkShare();
this.model.saveLinkShare({
password: ''
});
} else {
this.$el.find('.linkPassText').focus();
}
Expand All @@ -171,7 +172,6 @@
},

onPasswordEntered: function() {
var self = this;
var $loading = this.$el.find('.linkPass .icon-loading-small');
if (!$loading.hasClass('hidden')) {
// still in process
Expand All @@ -189,8 +189,9 @@
.removeClass('hidden')
.addClass('inlineblock');

this.model.setPassword(password);
this.model.saveLinkShare({}, {
this.model.saveLinkShare({
password: password
}, {
error: function(model, msg) {
$loading.removeClass('inlineblock').addClass('hidden');
$input.addClass('error');
Expand All @@ -204,8 +205,15 @@
onAllowPublicUploadChange: function() {
var $checkbox = this.$('.publicUploadCheckbox');
$checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock');
this.model.setPublicUpload($checkbox.is(':checked'));
this.model.saveLinkShare();

var permissions = OC.PERMISSION_READ;
if($checkbox.is(':checked')) {
permissions = OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_READ;
}

this.model.saveLinkShare({
permissions: permissions
});
},

_onEmailPrivateLink: function(event) {
Expand Down
60 changes: 17 additions & 43 deletions core/js/sharedialogshareelistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
var TEMPLATE =
'<ul id="shareWithList" class="shareWithList">' +
'{{#each sharees}}' +
' {{#if isCollection}}' +
' <li data-collection="{{collectionID}}">{{text}}</li>' +
' {{/if}}' +
' {{#unless isCollection}}' +
' <li data-share-type="{{shareType}}" data-share-with="{{shareWith}}" title="{{shareWith}}">' +
' <li data-share-id="{{shareId}}" data-share-type="{{shareType}}" data-share-with="{{shareWith}}" title="{{shareWith}}">' +
' <a href="#" class="unshare"><span class="icon-loading-small hidden"></span><img class="svg" alt="{{unshareLabel}}" title="{{unshareLabel}}" src="{{unshareImage}}" /></a>' +
' {{#if avatarEnabled}}' +
' <div class="avatar {{#if modSeed}}imageplaceholderseed{{/if}}" data-username="{{shareWith}}" {{#if modSeed}}data-seed="{{shareWith}} {{shareType}}"{{/if}}></div>' +
Expand Down Expand Up @@ -56,7 +52,6 @@
' </div>' +
' {{/unless}}' +
' </li>' +
' {{/unless}}' +
'{{/each}}' +
'</ul>'
;
Expand All @@ -81,12 +76,6 @@
/** @type {Function} **/
_template: undefined,

/** @type {boolean} **/
showLink: true,

/** @type {object} **/
_collections: {},

events: {
'click .unshare': 'onUnshare',
'click .permissions': 'onPermissionChange',
Expand All @@ -107,23 +96,6 @@
});
},

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;
}
},

/**
*
* @param {OC.Share.Types.ShareInfo} shareInfo
Expand Down Expand Up @@ -156,6 +128,7 @@
shareWith: shareWith,
shareWithDisplayName: shareWithDisplayName,
shareType: shareType,
shareId: this.model.get('shares')[shareIndex].id,
modSeed: shareType !== OC.Share.SHARE_TYPE_USER,
isRemoteShare: shareType === OC.Share.SHARE_TYPE_REMOTE
});
Expand Down Expand Up @@ -187,24 +160,17 @@
deletePermission: OC.PERMISSION_DELETE
};

this._collections = {};

if(!this.model.hasUserShares()) {
return [];
}

var shares = this.model.get('shares');
var list = [];
for(var index = 0; index < shares.length; index++) {
if(this.model.isCollection(index)) {
this.processCollectionShare(index);
} else {
// first empty {} is necessary, otherwise we get in trouble
// with references
list.push(_.extend({}, universal, this.getShareeObject(index)));
}
// first empty {} is necessary, otherwise we get in trouble
// with references
list.push(_.extend({}, universal, this.getShareeObject(index)));
}
list = _.union(_.values(this._collections), list);

return list;
},
Expand Down Expand Up @@ -244,6 +210,7 @@
},

onUnshare: function(event) {
var self = this;
var $element = $(event.target);
if (!$element.is('a')) {
$element = $element.closest('a');
Expand All @@ -257,17 +224,24 @@
$loading.removeClass('hidden');

var $li = $element.closest('li');
var shareType = $li.data('share-type');
var shareWith = $li.attr('data-share-with');

this.model.removeShare(shareType, shareWith);
var shareId = $li.data('share-id');

self.model.removeShare(shareId)
.done(function() {
$li.remove();
})
.fail(function() {
$loading.addClass('hidden');
OC.Notification.showTemporary(t('core', 'Could not unshare'));
});
return false;
},

onPermissionChange: function(event) {
var $element = $(event.target);
var $li = $element.closest('li');
var shareId = $li.data('share-id');
var shareType = $li.data('share-type');
var shareWith = $li.attr('data-share-with');

Expand All @@ -289,7 +263,7 @@
permissions |= $(checkbox).data('permissions');
});

this.model.setPermissions(shareType, shareWith, permissions);
this.model.updateShare(shareId, {permissions: permissions});
},

onCrudsToggle: function(event) {
Expand Down
Loading

0 comments on commit f8aa0f5

Please sign in to comment.