From d59a47f79c85f526f3fc6d501b7a6e16ecaf9261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 23 Aug 2013 11:16:47 +0200 Subject: [PATCH] [IMP] website: merge snippet insert and mutation drag & drop code bzr revid: fva@openerp.com-20130823091647-uoatz0k1458idhf3 --- addons/website/static/src/js/website.js | 51 +++++++++---------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/addons/website/static/src/js/website.js b/addons/website/static/src/js/website.js index 928723feec5..ff8c3ea18ae 100644 --- a/addons/website/static/src/js/website.js +++ b/addons/website/static/src/js/website.js @@ -368,17 +368,22 @@ start_snippets: function(){ var self = this; - this.$('.oe_snippet[data-action="insert"]').draggable({ + this.$('.oe_snippe').draggable({ helper: 'clone', zIndex: '1000', appendTo: 'body', start: function(){ var snippet = $(this); + var action = snippet.data('action'); - self.activate_drop_zones({ - siblings: snippet.data('selector-siblings'), - childs: snippet.data('selector-childs') - }); + if( action === 'insert'){ + self.activate_drop_zones({ + siblings: snippet.data('selector-siblings'), + childs: snippet.data('selector-childs') + }); + }else if( action === 'mutate' ){ + self.activate_hover_zones(snippet.data('selector')); + } $('.oe_drop_zone').droppable({ over: function(){ @@ -391,9 +396,13 @@ $(this).removeClass("oe_hover"); }, drop: function(){ - $(".oe_drop_zone.oe_hover") - .replaceWith(snippet.find('.oe_snippet_body').clone()) - .removeClass('oe_snippet_body'); + if( action === 'insert' ){ + $(".oe_drop_zone.oe_hover") + .replaceWith(snippet.find('.oe_snippet_body').clone()) + .removeClass('oe_snippet_body'); + }else if( action === 'mutate' ){ + self.path_eval(snippet.data('action-function'))( $(".oe_drop_zone.oe_hover").data('target') ); + } }, }); }, @@ -402,32 +411,6 @@ }, }); - this.$('.oe_snippet[data-action="mutate"]').draggable({ - helper: 'clone', - zIndex: '1000', - appendTo: 'body', - start: function(){ - var snippet = $(this); - - self.activate_hover_zones(snippet.data('selector')); - - $('.oe_drop_zone').droppable({ - over: function(){ - $(".oe_drop_zone.oe_hover").removeClass("oe_hover"); - $(this).addClass("oe_hover"); - }, - out: function(){ - $(this).removeClass("oe_hover"); - }, - drop: function(){ - self.path_eval(snippet.data('action-function'))( $(".oe_drop_zone.oe_hover").data('target') ); - }, - }); - }, - stop: function(){ - self.deactivate_drop_zones(); - }, - }); }, // A generic drop zone generator. two css selectors can be provided // selector.childs -> will insert drop zones as direct child of the selected elements