diff --git a/addons/base_diagram/static/src/js/diagram.js b/addons/base_diagram/static/src/js/diagram.js index 1ee3f7fc8f1..bc57bf24cac 100644 --- a/addons/base_diagram/static/src/js/diagram.js +++ b/addons/base_diagram/static/src/js/diagram.js @@ -6,119 +6,119 @@ openerp.base_diagram = function (openerp) { QWeb.add_template('/base_diagram/static/src/xml/base_diagram.xml'); openerp.base.views.add('diagram', 'openerp.base_diagram.DiagramView'); openerp.base_diagram.DiagramView = openerp.base.View.extend({ - init: function(parent, element_id, dataset, view_id, options) { - this._super(parent, element_id); - this.set_default_options(options); + init: function(parent, element_id, dataset, view_id, options) { + this._super(parent, element_id); + this.set_default_options(options); this.view_manager = parent; this.dataset = dataset; this.model = this.dataset.model; this.view_id = view_id; this.name = ""; - this.domain = this.dataset._domain || []; - this.context = {}; - this.ids = this.dataset.ids; - }, - start: function() { - return this.rpc("/base_diagram/diagram/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded); - }, - - toTitleCase: function(str) { - return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); - }, - - on_loaded: function(result) { - - var self = this; - if(this.ids && this.ids.length) { - this.id = this.ids[self.dataset.index || 0]; - } - this.fields_view = result.fields_view; - - this.view_id = this.fields_view.view_id; - this.name = this.fields_view.name; - - this.fields = this.fields_view.fields; - var children = this.fields_view.arch.children; - - /* - * For Nodes (Fields) - */ - this.node = ''; - this.bgcolor = ''; - this.shape = ''; - this.visible_fields_nodes = []; - this.invisible_fields_nodes = []; - this.fields_nodes_string = []; - - /* - * For Arrows (Connector) - */ - this.connector = ''; - this.src_node = ''; - this.des_node = ''; - this.connector_fields = []; - this.fields_connector_string = []; - - for(var ch in children) { - if(children[ch]['tag'] == 'node') { - this.node = children[ch]['attrs']['object']; - this.bgcolor = children[ch]['attrs']['bgcolor'] || ''; - this.shape = children[ch]['attrs']['shape'] || ''; - for(var node_chld in children[ch]['children']) { - if (children[ch]['children'][node_chld]['tag'] = 'field') { - var ch_name = children[ch]['children'][node_chld]['attrs']['name']; - - if (children[ch]['children'][node_chld]['attrs']['invisible']) { - if (children[ch]['children'][node_chld]['attrs']['invisible'] == 1 && children[ch]['children'][node_chld]['attrs']['invisible'] == '1') { - this.invisible_fields_nodes.push(ch_name) - } - } - else { - this.visible_fields_nodes.push(ch_name); - var ch_node_string = this.fields[ch_name]['string'] || this.toTitleCase(ch_name); - this.fields_nodes_string.push(ch_node_string) - } - } - } - } else if(children[ch]['tag'] == 'arrow') { - this.connector = children[ch]['attrs']['object']; - this.src_node = children[ch]['attrs']['source']; - this.des_node = children[ch]['attrs']['destination']; - for (var arrow_chld in children[ch]['children']) { - if (children[ch]['children'][arrow_chld]['tag'] = 'field') { - var arr_ch_name = children[ch]['children'][arrow_chld]['attrs']['name']; - var ch_node_string = this.fields[arr_ch_name]['string'] || this.toTitleCase(arr_ch_name); - this.fields_connector_string.push(ch_node_string); - this.connector_fields.push(arr_ch_name); - } - } - } - } - - this.$element.html(QWeb.render("DiagramView", this)); - - this.$element.find('div.oe_diagram_pager button[data-pager-action]').click(function() { + this.domain = this.dataset._domain || []; + this.context = {}; + this.ids = this.dataset.ids; + }, + start: function() { + return this.rpc("/base_diagram/diagram/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded); + }, + + toTitleCase: function(str) { + return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); + }, + + on_loaded: function(result) { + + var self = this; + if(this.ids && this.ids.length) { + this.id = this.ids[self.dataset.index || 0]; + } + this.fields_view = result.fields_view; + + this.view_id = this.fields_view.view_id; + this.name = this.fields_view.name; + + this.fields = this.fields_view.fields; + var children = this.fields_view.arch.children; + + /* + * For Nodes (Fields) + */ + this.node = ''; + this.bgcolor = ''; + this.shape = ''; + this.visible_fields_nodes = []; + this.invisible_fields_nodes = []; + this.fields_nodes_string = []; + + /* + * For Arrows (Connector) + */ + this.connector = ''; + this.src_node = ''; + this.des_node = ''; + this.connector_fields = []; + this.fields_connector_string = []; + + for(var ch in children) { + if(children[ch]['tag'] == 'node') { + this.node = children[ch]['attrs']['object']; + this.bgcolor = children[ch]['attrs']['bgcolor'] || ''; + this.shape = children[ch]['attrs']['shape'] || ''; + for(var node_chld in children[ch]['children']) { + if (children[ch]['children'][node_chld]['tag'] = 'field') { + var ch_name = children[ch]['children'][node_chld]['attrs']['name']; + + if (children[ch]['children'][node_chld]['attrs']['invisible']) { + if (children[ch]['children'][node_chld]['attrs']['invisible'] == 1 && children[ch]['children'][node_chld]['attrs']['invisible'] == '1') { + this.invisible_fields_nodes.push(ch_name) + } + } + else { + this.visible_fields_nodes.push(ch_name); + var ch_node_string = this.fields[ch_name]['string'] || this.toTitleCase(ch_name); + this.fields_nodes_string.push(ch_node_string) + } + } + } + } else if(children[ch]['tag'] == 'arrow') { + this.connector = children[ch]['attrs']['object']; + this.src_node = children[ch]['attrs']['source']; + this.des_node = children[ch]['attrs']['destination']; + for (var arrow_chld in children[ch]['children']) { + if (children[ch]['children'][arrow_chld]['tag'] = 'field') { + var arr_ch_name = children[ch]['children'][arrow_chld]['attrs']['name']; + var ch_node_string = this.fields[arr_ch_name]['string'] || this.toTitleCase(arr_ch_name); + this.fields_connector_string.push(ch_node_string); + this.connector_fields.push(arr_ch_name); + } + } + } + } + + this.$element.html(QWeb.render("DiagramView", this)); + + this.$element.find('div.oe_diagram_pager button[data-pager-action]').click(function() { var action = $(this).data('pager-action'); self.on_pager_action(action); }); - - this.do_update_pager(); - - // New Node,Edge - this.$element.find('#new_node.oe_diagram_button_new').click(function(){self.add_edit_node(null, self.node)}); - this.$element.find('#new_edge.oe_diagram_button_new').click(function(){self.add_edit_node(null, self.connector)}); - - this.$element.find('#toggle_grid').click(function() { - self.$element.find('.diagram').toggleClass('show_grid') - }); - + + this.do_update_pager(); + + // New Node,Edge + this.$element.find('#new_node.oe_diagram_button_new').click(function(){self.add_edit_node(null, self.node)}); + this.$element.find('#new_edge.oe_diagram_button_new').click(function(){self.add_edit_node(null, self.connector)}); + + this.$element.find('#toggle_grid').click(function() { + self.$element.find('.diagram').toggleClass('show_grid') + }); + if(this.id) { - self.get_diagram_info(); + self.get_diagram_info(); } - }, - - get_diagram_info: function() { - var self = this; + }, + + get_diagram_info: function() { + var self = this; this.rpc( '/base_diagram/diagram/get_diagram_info', { @@ -137,128 +137,128 @@ openerp.base_diagram.DiagramView = openerp.base.View.extend({ 'connector_fields_string': this.fields_connector_string }, function(result) { - self.draw_diagram(result); + self.draw_diagram(result); } ); - }, - - on_diagram_loaded: function(record) { - var id_record = record['id']; - if(id_record) { - this.id = id_record; - this.get_diagram_info(); + }, + + on_diagram_loaded: function(record) { + var id_record = record['id']; + if(id_record) { + this.id = id_record; + this.get_diagram_info(); } }, - + draw_diagram: function(result) { var dia = new Graph(); - + this.active_model = result['id_model']; this.in_transition_field = result['in_transition_field']; this.out_transition_field = result['out_transition_field']; var res_nodes = result['nodes']; var res_connectors = result['conn']; - + //Custom logic var self = this; var renderer = function(r, n) { - var node; - var set; - - // ellipse - if (n.node.shape == 'ellipse') { - node = r.ellipse(n.node.x - 30, n.node.y - 13, 40, 20).attr({ - "fill": n.node.color, - r: "12px", - "stroke-width": n.distance == 0 ? "3px" : "1px" - }); - - set = r.set().push(node).push(r.text(n.node.x - 30, n.node.y - 10, (n.label || n.id))); - } - - // rectangle - else if(n.node.shape == 'rectangle') { - node = r.rect(n.node.x-30, n.node.y-13, 60, 44).attr({ - "fill": n.node.color, - r : "12px", - "stroke-width" : n.distance == 0 ? "3px" : "1px" - }); - set = r.set().push(node).push(r.text(n.node.x , n.node.y+10 , (n.label || n.id))); - } - - // circle - else { - node = r.circle(n.node.x, n.node.y, 150).attr({ - "fill": n.node.color, - r : "30px", - "stroke-width" : n.distance == 0 ? "3px" : "1px" - }); - set = r.set().push(node).push(r.text(n.node.x , n.node.y , (n.label || n.id))); - } - - //Shape Node Event - jQuery(node.node).attr({ - 'id': n.node.id, - 'name': n.id, - 'kind': n.node.options['Kind'] || n.node.options['kind'] - }).dblclick(function() { - var $this = jQuery(this); - self.add_edit_node($this.attr('id'), self.node); - }); - - //Text Node Event - jQuery(node.next.node).attr({ - 'id': n.node.id, - 'name': n.id, - 'kind': n.node.options['Kind'] || n.node.options['kind'] - }).dblclick(function() { - var $this = jQuery(this); - self.add_edit_node($this.attr('id'), self.node); - }); - return set; + var node; + var set; + + // ellipse + if (n.node.shape == 'ellipse') { + node = r.ellipse(n.node.x - 30, n.node.y - 13, 40, 20).attr({ + "fill": n.node.color, + r: "12px", + "stroke-width": n.distance == 0 ? "3px" : "1px" + }); + + set = r.set().push(node).push(r.text(n.node.x - 30, n.node.y - 10, (n.label || n.id))); + } + + // rectangle + else if(n.node.shape == 'rectangle') { + node = r.rect(n.node.x-30, n.node.y-13, 60, 44).attr({ + "fill": n.node.color, + r : "12px", + "stroke-width" : n.distance == 0 ? "3px" : "1px" + }); + set = r.set().push(node).push(r.text(n.node.x , n.node.y+10 , (n.label || n.id))); + } + + // circle + else { + node = r.circle(n.node.x, n.node.y, 150).attr({ + "fill": n.node.color, + r : "30px", + "stroke-width" : n.distance == 0 ? "3px" : "1px" + }); + set = r.set().push(node).push(r.text(n.node.x , n.node.y , (n.label || n.id))); + } + + //Shape Node Event + jQuery(node.node).attr({ + 'id': n.node.id, + 'name': n.id, + 'kind': n.node.options['Kind'] || n.node.options['kind'] + }).dblclick(function() { + var $this = jQuery(this); + self.add_edit_node($this.attr('id'), self.node); + }); + + //Text Node Event + jQuery(node.next.node).attr({ + 'id': n.node.id, + 'name': n.id, + 'kind': n.node.options['Kind'] || n.node.options['kind'] + }).dblclick(function() { + var $this = jQuery(this); + self.add_edit_node($this.attr('id'), self.node); + }); + return set; }; - + for(var node in res_nodes) { var res_node = res_nodes[node]; dia.addNode(res_node['name'],{node: res_node,render: renderer}); } - + // Set Ides for Path(Edges) var edge_ids = []; - + $.each(res_connectors, function(index, connector) { - edge_ids.push(index); - dia.addEdge(connector['source'], connector['destination'], {directed : true, label: connector['signal']}); + edge_ids.push(index); + dia.addEdge(connector['source'], connector['destination'], {directed : true, label: connector['signal']}); }); - + var layouter = new Graph.Layout.Spring(dia); layouter.layout(); if ($('div#dia-canvas').children().length > 0) { - $('div#dia-canvas').children().remove(); + $('div#dia-canvas').children().remove(); } var renderer = new Graph.Renderer.Raphael('dia-canvas', dia, $('div#dia-canvas').width(), $('div#dia-canvas').height()); renderer.draw(); - + //Path(Edges) $.each(dia.edges, function(index, edge) { - if(edge.connection) - edge.connection.fg.node.id = edge_ids[index]; + if(edge.connection) + edge.connection.fg.node.id = edge_ids[index]; }); - + jQuery('path',renderer.r.canvas).dblclick(function() { - self.add_edit_node(this.id, self.connector) + self.add_edit_node(this.id, self.connector) }); }, - + add_edit_node: function(id, model) { - var self = this; - - if(!model) - model = self.node; - if(id) - id = parseInt(id, 10); - var action_manager = new openerp.base.ActionManager(this); - var dialog = new openerp.base.Dialog(this, { + var self = this; + + if(!model) + model = self.node; + if(id) + id = parseInt(id, 10); + var action_manager = new openerp.base.ActionManager(this); + var dialog = new openerp.base.Dialog(this, { width: 800, height: 600, buttons : { @@ -266,63 +266,63 @@ openerp.base_diagram.DiagramView = openerp.base.View.extend({ $(this).dialog('destroy'); }, Save : function() { - var form_dataset = action_manager.inner_viewmanager.dataset; - var form_view = action_manager.inner_viewmanager.views.form.controller; - - form_view.do_save(function() { - self.dataset.index = jQuery.inArray(parseInt(self.id,10), self.dataset.ids); - self.dataset.read_index(_.keys(self.fields_view.fields), self.on_diagram_loaded) - }); + var form_dataset = action_manager.inner_viewmanager.dataset; + var form_view = action_manager.inner_viewmanager.views.form.controller; + + form_view.do_save(function() { + self.dataset.index = jQuery.inArray(parseInt(self.id,10), self.dataset.ids); + self.dataset.read_index(_.keys(self.fields_view.fields), self.on_diagram_loaded) + }); $(this).dialog('destroy'); } } }).start().open(); - action_manager.appendTo(dialog.$element); - action_manager.do_action({ + action_manager.appendTo(dialog.$element); + action_manager.do_action({ res_model : model, res_id: id, views : [[false, 'form']], type : 'ir.actions.act_window', auto_search : false, flags : { - search_view: false, + search_view: false, sidebar : false, views_switcher : false, action_buttons : false, pager: false } }); - - var form_controller = action_manager.inner_viewmanager.views.form.controller; - - var form_fields; - - if(model == self.node) { - form_fields = ['wkf_id']; - } else { - form_fields = ['act_from', 'act_to']; - } - - if(model == self.node || id) { - $.each(form_fields, function(index, fld) { - form_controller.on_record_loaded.add_first(function() { - form_controller.fields[fld].modifiers.readonly = true; - form_controller.fields[fld].$input.attr('disabled', true); - form_controller.fields[fld].$drop_down.unbind(); - form_controller.fields[fld].$menu_btn.unbind(); - }); - }); - } - if(!id && (model == self.node)) { - $.each(form_fields, function(index, fld) { - form_controller.on_record_loaded.add_last(function() { - form_controller.fields[fld].set_value([self.id,self.active_model]); - form_controller.fields[fld].dirty = true; - }); - }); - } + + var form_controller = action_manager.inner_viewmanager.views.form.controller; + + var form_fields; + + if(model == self.node) { + form_fields = ['wkf_id']; + } else { + form_fields = ['act_from', 'act_to']; + } + + if(model == self.node || id) { + $.each(form_fields, function(index, fld) { + form_controller.on_record_loaded.add_first(function() { + form_controller.fields[fld].modifiers.readonly = true; + form_controller.fields[fld].$input.attr('disabled', true); + form_controller.fields[fld].$drop_down.unbind(); + form_controller.fields[fld].$menu_btn.unbind(); + }); + }); + } + if(!id && (model == self.node)) { + $.each(form_fields, function(index, fld) { + form_controller.on_record_loaded.add_last(function() { + form_controller.fields[fld].set_value([self.id,self.active_model]); + form_controller.fields[fld].dirty = true; + }); + }); + } }, - + do_search: function(domains, contexts, groupbys) { var self = this; this.rpc('/base/session/eval_domain_and_context', { @@ -338,40 +338,40 @@ openerp.base_diagram.DiagramView = openerp.base.View.extend({ }); }); }, - + on_pager_action: function(action) { - switch (action) { - case 'first': - this.dataset.index = 0; - break; - case 'previous': - this.dataset.previous(); - break; - case 'next': - this.dataset.next(); - break; - case 'last': - this.dataset.index = this.dataset.ids.length - 1; - break; - } - this.dataset.read_index(_.keys(this.fields_view.fields), this.on_diagram_loaded); - this.do_update_pager(); + switch (action) { + case 'first': + this.dataset.index = 0; + break; + case 'previous': + this.dataset.previous(); + break; + case 'next': + this.dataset.next(); + break; + case 'last': + this.dataset.index = this.dataset.ids.length - 1; + break; + } + this.dataset.read_index(_.keys(this.fields_view.fields), this.on_diagram_loaded); + this.do_update_pager(); }, - + do_update_pager: function(hide_index) { var $pager = this.$element.find('div.oe_diagram_pager'); var index = hide_index ? '-' : this.dataset.index + 1; if(!this.dataset.count) { - this.dataset.count = this.dataset.ids.length; + this.dataset.count = this.dataset.ids.length; } $pager.find('span.oe_pager_index').html(index); $pager.find('span.oe_pager_count').html(this.dataset.count); }, - - do_show: function () { + + do_show: function () { this.$element.show(); }, - + do_hide: function () { this.$element.hide(); }