Allow text overwrite of content delete modal

This commit is contained in:
Lucas Bartholemy 2018-06-11 17:23:46 +02:00
parent a8d2c236b8
commit 86b192483e
2 changed files with 39 additions and 29 deletions

View File

@ -55,6 +55,7 @@ humhub.module('content', function (module, require, $) {
Content.prototype.delete = function (options) {
options = options || {};
var that = this;
return new Promise(function (resolve, reject) {
if (!that.hasAction('delete')) {
@ -63,41 +64,50 @@ humhub.module('content', function (module, require, $) {
var modalOptions = options.modal || module.config.modal.deleteConfirm;
modal.confirm(modalOptions).then(function ($confirmed) {
if (!$confirmed) {
resolve(false);
return;
}
if(options.$trigger && options.$trigger.is('[data-action-confirm]')) {
that.deleteContent(resolve, reject);
} else {
modal.confirm(modalOptions).then(function ($confirmed) {
if (!$confirmed) {
resolve(false);
return;
}
that.loader();
var deleteUrl = that.data(DATA_CONTENT_DELETE_URL) || module.config.deleteUrl;
if (deleteUrl) {
client.post(deleteUrl, {
data: {id: that.getKey()}
}).then(function (response) {
that.remove().then(function () {
resolve(true);
});
}).catch(function (err) {
reject(err);
}).finally(function () {
that.loader(false);
});
} else {
reject('Content delete was called, but no url could be determined for ' + that.base);
that.loader(false);
}
});
that.deleteContent(resolve, reject);
});
}
});
};
Content.prototype.deleteContent = function(resolve, reject) {
var that = this;
that.loader();
var deleteUrl = that.data(DATA_CONTENT_DELETE_URL) || module.config.deleteUrl;
if (deleteUrl) {
client.post(deleteUrl, {
data: {id: that.getKey()}
}).then(function (response) {
that.remove().then(function () {
resolve(true);
});
}).catch(function (err) {
reject(err);
}).finally(function () {
that.loader(false);
});
} else {
reject('Content delete was called, but no url could be determined for ' + that.base);
that.loader(false);
}
};
/**
* Abstract loader function which can be used to activate or deactivate a
* loader within a content entry.
*
*
* If $show is undefined or true the loader animation should be rendered
* otherwise it should be removed.
*
*
* @param {type} $show
* @returns {undefined}
*/
@ -144,4 +154,4 @@ humhub.module('content', function (module, require, $) {
Content: Content,
templates: templates
});
});
});

View File

@ -92,10 +92,10 @@ humhub.module('stream', function (module, require, $) {
return ['delete', 'edit'];
};
StreamEntry.prototype.delete = function () {
StreamEntry.prototype.delete = function (evt) {
// Either call delete of a nestet content component or call default content delete
var content = this.contentComponent();
var promise = (content && content.delete) ? content.delete() : this.super('delete');
var promise = (content && content.delete) ? content.delete(evt) : this.super('delete', evt);
var that = this;
var stream = this.stream();