summaryrefslogtreecommitdiffstats
path: root/core/js/shareitemmodel.js
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2017-04-25 14:12:44 +0200
committerGitHub <noreply@github.com>2017-04-25 14:12:44 +0200
commit82c9eb1c5654562e8057953356af49b7295a7561 (patch)
tree852acfbf17793033f932fed8da3a39b5f242c812 /core/js/shareitemmodel.js
parent026070a2fc3b766f9d686c50c358b6f03462ad18 (diff)
parent58cc1251be33b43a5bb9163e1b042970b8e81b4b (diff)
downloadnextcloud-server-82c9eb1c5654562e8057953356af49b7295a7561.tar.gz
nextcloud-server-82c9eb1c5654562e8057953356af49b7295a7561.zip
Merge pull request #4462 from danxuliu/fix-sharing-password-protected-link
Fix sharing a password protected link
Diffstat (limited to 'core/js/shareitemmodel.js')
-rw-r--r--core/js/shareitemmodel.js60
1 files changed, 28 insertions, 32 deletions
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index bc3ea88aa56..41f9eb5e0aa 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -104,7 +104,14 @@
/**
* Saves the current link share information.
*
- * This will trigger an ajax call and refetch the model afterwards.
+ * This will trigger an ajax call and, if successful, refetch the model
+ * afterwards. Callbacks "success", "error" and "complete" can be given
+ * in the options object; "success" is called after a successful save
+ * once the model is refetch, "error" is called after a failed save, and
+ * "complete" is called both after a successful save and after a failed
+ * save. Note that "complete" is called before "success" and "error" are
+ * called (unlike in jQuery, in which it is called after them); this
+ * ensures that "complete" is called even if refetching the model fails.
*
* TODO: this should be a separate model
*/
@@ -149,7 +156,6 @@
addShare: function(attributes, options) {
var shareType = attributes.shareType;
- options = options || {};
attributes = _.extend({}, attributes);
// Default permissions are Edit (CRUD) and Share
@@ -173,53 +179,43 @@
attributes.path = this.fileInfoModel.getFullPath();
}
- var self = this;
- return $.ajax({
+ return this._addOrUpdateShare({
type: 'POST',
url: this._getUrl('shares'),
data: attributes,
dataType: 'json'
- }).done(function() {
- self.fetch().done(function() {
- if (_.isFunction(options.success)) {
- options.success(self);
- }
- });
- }).fail(function(xhr) {
- var msg = t('core', 'Error');
- var result = xhr.responseJSON;
- if (result && result.ocs && result.ocs.meta) {
- msg = result.ocs.meta.message;
- }
-
- if (_.isFunction(options.error)) {
- options.error(self, msg);
- } else {
- OC.dialogs.alert(msg, t('core', 'Error while sharing'));
- }
- });
+ }, options);
},
updateShare: function(shareId, attrs, options) {
- var self = this;
- options = options || {};
- return $.ajax({
+ return this._addOrUpdateShare({
type: 'PUT',
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
data: attrs,
dataType: 'json'
+ }, options);
+ },
+
+ _addOrUpdateShare: function(ajaxSettings, options) {
+ var self = this;
+ options = options || {};
+
+ return $.ajax(
+ ajaxSettings
+ ).always(function() {
+ if (_.isFunction(options.complete)) {
+ options.complete(self);
+ }
}).done(function() {
- self.fetch({
- success: function() {
- if (_.isFunction(options.success)) {
- options.success(self);
- }
+ self.fetch().done(function() {
+ if (_.isFunction(options.success)) {
+ options.success(self);
}
});
}).fail(function(xhr) {
var msg = t('core', 'Error');
var result = xhr.responseJSON;
- if (result.ocs && result.ocs.meta) {
+ if (result && result.ocs && result.ocs.meta) {
msg = result.ocs.meta.message;
}