summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/website.editor.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2014-03-04 12:07:16 +0100
committerXavier Morel <xmo@openerp.com>2014-03-04 12:07:16 +0100
commite78a3b18cc6c049a712d594ab70287c486447f0a (patch)
treef7bc1bd00c6c1407497eaf0c66de58eb105a3b17 /addons/website/static/src/js/website.editor.js
parentf3638567738cdc242fa43dc0a1770ea7bd4b4b6e (diff)
[ADD] tentative removal of attachments
Attachments ought be removed only if they are not used in an existing page/web view. Theoretically this could be set directly in unlink(), but: * that would make a nice error message significantly harder * the expenses of performing a text search in all view archs would be a bit expensive Notes: * the views set could be reduced to only "web" views * the search is likely sensible to false negatives e.g. different order of query parameters. It *will* remove images still being used. bzr revid: xmo@openerp.com-20140304110716-u14w6uo8fbkfa42i
Diffstat (limited to 'addons/website/static/src/js/website.editor.js')
-rw-r--r--addons/website/static/src/js/website.editor.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js
index f7e3255de24..3915c3daaeb 100644
--- a/addons/website/static/src/js/website.editor.js
+++ b/addons/website/static/src/js/website.editor.js
@@ -1441,6 +1441,7 @@
this.page += $target.hasClass('previous') ? -1 : 1;
this.display_attachments();
},
+ 'click .existing-attachment-remove': 'try_remove',
}),
init: function (parent) {
this.image = null;
@@ -1473,6 +1474,7 @@
this.display_attachments();
},
display_attachments: function () {
+ this.$('.help-block').empty();
var per_screen = IMAGES_PER_ROW * IMAGES_ROWS;
var from = this.page * per_screen;
@@ -1500,6 +1502,34 @@
}
this.close()
},
+
+ try_remove: function (e) {
+ var $help_block = this.$('.help-block').empty();
+ var self = this;
+ var id = parseInt($(e.target).data('id'), 10);
+ var attachment = _.findWhere(this.records, {id: id});
+
+ return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
+ model: 'ir.attachment',
+ method: 'try_remove',
+ args: [],
+ kwargs: {
+ ids: [id],
+ context: website.get_context()
+ }
+ }).then(function (prevented) {
+ if (_.isEmpty(prevented)) {
+ self.records = _.without(self.records, attachment);
+ self.display_attachments();
+ return;
+ }
+ $help_block.replaceWith(openerp.qweb.render(
+ 'website.editor.dialog.image.existing.error', {
+ views: prevented[id]
+ }
+ ));
+ });
+ },
});
function get_selected_link(editor) {