[FIX] website: snippet editor call on_clone & on_remove on children
This commit is contained in:
@@ -500,7 +500,8 @@
|
||||
this.snippets.push($snippet.get(0));
|
||||
}
|
||||
this.$active_snipped_id = $snippet;
|
||||
this.create_overlay(this.$active_snipped_id);
|
||||
this.create_snippet_editor(this.$active_snipped_id);
|
||||
this.cover_target($snippet.data('overlay'), $snippet);
|
||||
this.snippet_focus($snippet);
|
||||
}
|
||||
this.$snippet.trigger('snippet-activated', $snippet);
|
||||
@@ -508,13 +509,11 @@
|
||||
$snippet.trigger('snippet-activated', $snippet);
|
||||
}
|
||||
},
|
||||
create_overlay: function ($snippet) {
|
||||
create_snippet_editor: function ($snippet) {
|
||||
if (typeof $snippet.data("snippet-editor") === 'undefined') {
|
||||
var $targets = this.activate_overlay_zones($snippet);
|
||||
if (!$targets.length) return;
|
||||
if (!this.activate_overlay_zones($snippet).length) return;
|
||||
$snippet.data("snippet-editor", new website.snippet.Editor(this, $snippet));
|
||||
}
|
||||
this.cover_target($snippet.data('overlay'), $snippet);
|
||||
},
|
||||
|
||||
// activate drag and drop for the snippets in the snippet toolbar
|
||||
@@ -624,22 +623,12 @@
|
||||
|
||||
website.snippet.start_animation(true, $target);
|
||||
|
||||
// drop_and_build_snippet
|
||||
self.create_overlay($target);
|
||||
if ($target.data("snippet-editor")) {
|
||||
$target.data("snippet-editor").drop_and_build_snippet();
|
||||
}
|
||||
for (var k in website.snippet.templateOptions) {
|
||||
website.snippet.templateOptions[k].selector.all($target).each(function () {
|
||||
var $snippet = $(this);
|
||||
self.create_overlay($snippet);
|
||||
if ($snippet.data("snippet-editor")) {
|
||||
$snippet.data("snippet-editor").drop_and_build_snippet();
|
||||
}
|
||||
});
|
||||
}
|
||||
self.call_for_all_snippets($target, function (editor, $snippet) {
|
||||
editor.drop_and_build_snippet();
|
||||
});
|
||||
self.create_snippet_editor($target);
|
||||
self.cover_target($target.data('overlay'), $target);
|
||||
$target.closest(".o_editable").trigger("content_changed");
|
||||
// end
|
||||
|
||||
self.make_active($target);
|
||||
},0);
|
||||
@@ -650,6 +639,20 @@
|
||||
});
|
||||
},
|
||||
|
||||
// call a method on a snippet and all his children
|
||||
call_for_all_snippets: function ($snippet, callback) {
|
||||
var self = this;
|
||||
$snippet.add(website.snippet.globalSelector.all($snippet)).each(function () {
|
||||
var $snippet = $(this);
|
||||
setTimeout(function () {
|
||||
self.create_snippet_editor($snippet);
|
||||
if ($snippet.data("snippet-editor")) {
|
||||
callback.call(self, $snippet.data("snippet-editor"), $snippet);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// return the original snippet in the editor bar from a snippet id (string)
|
||||
get_snippet_from_id: function(id){
|
||||
return $('.oe_snippet').filter(function(){
|
||||
@@ -1965,7 +1968,9 @@
|
||||
self.BuildingBlock.editor_busy = false;
|
||||
|
||||
self.get_parent_block();
|
||||
setTimeout(function () {self.BuildingBlock.create_overlay(self.$target);},0);
|
||||
setTimeout(function () {
|
||||
self.BuildingBlock.cover_target(self.$target.data('overlay'), self.$target);
|
||||
},0);
|
||||
},
|
||||
|
||||
load_style_options: function () {
|
||||
@@ -2002,7 +2007,10 @@
|
||||
get_parent_block: function () {
|
||||
var self = this;
|
||||
var $button = this.$overlay.find('.oe_snippet_parent');
|
||||
var $parent = website.snippet.globalSelector.closest(this.$target.parent());
|
||||
var $parent = this.$target.parents().filter(function () { return $(this).data("snippet-editor"); });
|
||||
if (!$parent.length) {
|
||||
$parent = website.snippet.globalSelector.closest(this.$target.parent());
|
||||
}
|
||||
if ($parent.length) {
|
||||
$button.removeClass("hidden");
|
||||
$button.off("click").on('click', function (event) {
|
||||
@@ -2038,10 +2046,11 @@
|
||||
this.BuildingBlock.parent.rte.historyRecordUndo(this.$target);
|
||||
|
||||
this.$target.after($clone);
|
||||
for (var i in this.styles){
|
||||
this.styles[i].on_clone($clone);
|
||||
}
|
||||
this.BuildingBlock.create_overlay(this.$target);
|
||||
this.BuildingBlock.call_for_all_snippets($clone, function (editor, $snippet) {
|
||||
for (var i in editor.styles){
|
||||
editor.styles[i].on_clone($snippet);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
},
|
||||
|
||||
@@ -2052,9 +2061,11 @@
|
||||
this.BuildingBlock.parent.rte.historyRecordUndo(this.$target);
|
||||
|
||||
var index = _.indexOf(this.BuildingBlock.snippets, this.$target.get(0));
|
||||
for (var i in this.styles){
|
||||
this.styles[i].on_remove();
|
||||
}
|
||||
this.BuildingBlock.call_for_all_snippets(this.$target, function (editor, $snippet) {
|
||||
for (var i in editor.styles){
|
||||
editor.styles[i].on_remove();
|
||||
}
|
||||
});
|
||||
delete this.BuildingBlock.snippets[index];
|
||||
|
||||
// remove node and his empty
|
||||
|
||||
Reference in New Issue
Block a user