diff options
| author | qsm-odoo <qsm@odoo.com> | 2016-09-15 17:24:01 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2016-09-16 17:02:33 +0200 |
| commit | fe0478a5c425585af0ca6f0cb728c8a78750519c (patch) | |
| tree | f3e8f7eb3d8bcf80a745842ddd7f509f37ce4e99 /addons/web_editor/static/src/js/snippets.editor.js | |
| parent | 911de68e7079e18d58246233c0f5d7a9ab2f1c9c (diff) | |
[FIX] web_editor: remove dead code and refactore show_blocks method
Following commit e634a52cace081edfce324f14228ddb419af0a31, the
show_blocks method had to be refactored to remove the dead code and
refactore the old one it contained.
Diffstat (limited to 'addons/web_editor/static/src/js/snippets.editor.js')
| -rw-r--r-- | addons/web_editor/static/src/js/snippets.editor.js | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/addons/web_editor/static/src/js/snippets.editor.js b/addons/web_editor/static/src/js/snippets.editor.js index 3fd9bfca2e4..cc2d6fcbc38 100644 --- a/addons/web_editor/static/src/js/snippets.editor.js +++ b/addons/web_editor/static/src/js/snippets.editor.js @@ -325,39 +325,22 @@ data.Class = Widget.extend({ show_blocks: function () { var self = this; var cache = {}; - this.$(".o_panel").each(function () { - var catcheck = false; - var $category = $(this); - $category.find(".oe_snippet_body").each(function () { - var $snippet = $(this); - - var check = false; - - for (var k in self.templateOptions) { - var option = self.templateOptions[k]; - if ($snippet.is(option.base_selector)) { + this.$snippets.each(function () { + var $snippet = $(this); + var $snippet_body = $snippet.find(".oe_snippet_body"); - cache[k] = cache[k] || { - 'drop-near': option['drop-near'] ? option['drop-near'].all() : [], - 'drop-in': option['drop-in'] ? option['drop-in'].all() : [] - }; + var check = false; + _.each(self.templateOptions, function (option, k) { + if (check || !$snippet_body.is(option.base_selector)) return; - if (cache[k]['drop-near'].length || cache[k]['drop-in'].length) { - catcheck = true; - check = true; - break; - } - } - } - - if (check) { - $snippet.closest(".oe_snippet").removeClass("disable"); - } else { - $snippet.closest(".oe_snippet").addClass("disable"); - } + cache[k] = cache[k] || { + 'drop-near': option['drop-near'] ? option['drop-near'].all().length : 0, + 'drop-in': option['drop-in'] ? option['drop-in'].all().length : 0 + }; + check = (cache[k]['drop-near'] || cache[k]['drop-in']); }); - $('#oe_snippets .scroll a[data-toggle="tab"][href="#' + $category.attr("id") + '"]').toggle(catcheck); + $snippet.toggleClass("disable", !check); }); }, bind_snippet_click_editor: function () { |
