From 344a48ab55e29e5bcef33273403da079cdf3c64f Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Fri, 15 Jul 2011 18:35:40 +0530 Subject: [PATCH 01/19] [FIX] Fixed DATA_ERROR, dhtmlx is not supported datetime formate, Then when render parent task it reduce the hours. bzr revid: sma@tinyerp.com-20110715130540-y7par5uca2xxmlpp --- addons/base_gantt/static/src/js/gantt.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index cf0ce449d60..6d8db18b5bd 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -246,7 +246,7 @@ init: function(view_manager, session, element_id, dataset, view_id) { for (i in all_events){ res = all_events[i]; if ((typeof(res['evt'][3])) == "object"){ - res['evt'][3] = self.hours_between(res['evt'][2],res['evt'][3]); + res['evt'][3] = self.hours_between(res['evt'][2],res['evt'][3], true); } k = res['evt'][0].toString().indexOf('_'); @@ -356,14 +356,14 @@ init: function(view_manager, session, element_id, dataset, view_id) { return dat; }, - hours_between: function(date1, date2) { + hours_between: function(date1, date2, parent_task) { var ONE_DAY = 1000 * 60 * 60 * 24; var date1_ms = date1.getTime(); var date2_ms = date2.getTime(); var difference_ms = Math.abs(date1_ms - date2_ms); - d = Math.floor(difference_ms / ONE_DAY); + d = parent_task? Math.ceil(difference_ms / ONE_DAY) : Math.floor(difference_ms / ONE_DAY); h = (difference_ms % ONE_DAY)/(1000 * 60 * 60); num = (d * this.day_length) + h; return parseFloat(num.toFixed(2)); From ff5acb435146bff358b98a93374b4d967397bd90 Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Mon, 18 Jul 2011 11:47:22 +0530 Subject: [PATCH 02/19] [IMP] Improve edit, when open popup on dblclick of tasks. bzr revid: sma@tinyerp.com-20110718061722-8uy5eqw9tzu04bqg --- addons/base_gantt/static/src/js/gantt.js | 62 +++++++++++++++++------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index 6d8db18b5bd..c68e704a14e 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -289,7 +289,7 @@ init: function(view_manager, session, element_id, dataset, view_id) { ganttChartControl.attachEvent("onTaskStartDrag", function(task) {self.on_drag_start(task);}); ganttChartControl.attachEvent("onTaskEndResize", function(task) {self.on_resize_drag_end(task, "resize");}); ganttChartControl.attachEvent("onTaskEndDrag", function(task) {self.on_resize_drag_end(task, "drag");}); - ganttChartControl.attachEvent("onTaskDblClick", function(task) {self.open_popup(task);}); + ganttChartControl.attachEvent("onTaskDblClick", function(task, evt) {self.open_popup(task); evt.stopPropagation(); evt.preventDefault();}); taskdiv = jQuery("div.taskPanel").parent(); taskdiv.addClass('ganttTaskPanel'); @@ -372,27 +372,53 @@ init: function(view_manager, session, element_id, dataset, view_id) { open_popup : function(task) { var event_id = task.getId(); - if(event_id.toString().search("_") != -1) return; - if (event_id) { - event_id = parseInt(event_id, 10); - var dataset_event_index = jQuery.inArray(event_id, this.ids); - } else { - var dataset_event_index = null; + if(event_id) event_id = parseInt(event_id, 10); + + var action = { + "res_model": this.dataset.model, + "res_id": event_id, + "views":[[false,"form"]], + "type":"ir.actions.act_window", + "view_type":"form", + "view_mode":"form" } - this.dataset.index = dataset_event_index; + + action.flags = { + search_view: false, + sidebar : false, + views_switcher : false, + action_buttons : false, + pager: false + } var element_id = _.uniqueId("act_window_dialog"); - var dialog = jQuery('
', - {'id': element_id - }).dialog({ - title: 'Gantt Chart', - modal: true, - minWidth: 800, - position: 'top' - }); - var event_form = new openerp.base.FormView(this.view_manager, this.session, element_id, this.dataset, false); - event_form.start(); + var dialog = jQuery('
', { + 'id': element_id + }).dialog({ + modal: true, + width: 'auto', + height: 'auto', + buttons: { + Cancel: function() { + $(this).dialog("destroy"); + }, + Save: function() { + var view_manager = action_manager.viewmanager; + var _dialog = this; + view_manager.views[view_manager.active_view].controller.do_save(function(r) { + $(_dialog).dialog("destroy"); + self.reload_gantt(); + }) + } + } + }); + var action_manager = new openerp.base.ActionManager(this.session, element_id); + action_manager.start(); + action_manager.do_action(action); + + //Default_get + if(!event_id) action_manager.viewmanager.dataset.index = null; }, on_drag_start : function(task){ From 9ed55ee3f545029143bed141fbce788701ba8db5 Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Wed, 27 Jul 2011 12:32:20 +0530 Subject: [PATCH 03/19] [FIX] Show Save/Edit and New buttons in popups. bzr revid: sma@tinyerp.com-20110727070220-vyk3w7001lpi7l04 --- addons/base_gantt/static/src/js/gantt.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index c68e704a14e..e3c2b79fc58 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -389,7 +389,6 @@ init: function(view_manager, session, element_id, dataset, view_id) { search_view: false, sidebar : false, views_switcher : false, - action_buttons : false, pager: false } var element_id = _.uniqueId("act_window_dialog"); From f61dadb8490a45e9b9cf07384fb65c1e9cb2e8af Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Tue, 2 Aug 2011 11:22:16 +0530 Subject: [PATCH 04/19] [IMP] Use parent and remove session from ganttview. bzr revid: sma@tinyerp.com-20110802055216-0t9fq66nmthdwzyp --- addons/base_gantt/static/src/js/gantt.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index 06ec4be2634..cde8cd18b9d 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -1,16 +1,14 @@ /*--------------------------------------------------------- * OpenERP base_gantt *---------------------------------------------------------*/ - openerp.base_gantt = function (openerp) { QWeb.add_template('/base_gantt/static/src/xml/base_gantt.xml'); openerp.base.views.add('gantt', 'openerp.base_gantt.GanttView'); -openerp.base_gantt.GanttView = openerp.base.Widget.extend({ +openerp.base_gantt.GanttView = openerp.base.View.extend({ -init: function(view_manager, session, element_id, dataset, view_id) { - - this._super(session, element_id); - this.view_manager = view_manager; +init: function(parent, element_id, dataset, view_id) { + this._super(parent, element_id); + this.view_manager = parent || new openerp.base.NullViewManager(); this.dataset = dataset; this.model = dataset.model; this.view_id = view_id; @@ -29,7 +27,7 @@ init: function(view_manager, session, element_id, dataset, view_id) { this.calendar_fields = {}; this.info_fields = []; this.domain = this.dataset._domain ? this.dataset._domain: []; - this.context = {}; + this.context = this.dataset.context || {}; }, start: function() { From 72f7aa772edfae4162ba450db5b57229df49d631 Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Tue, 2 Aug 2011 11:40:30 +0530 Subject: [PATCH 05/19] [FIX] Need to load all js files for calendar, gantt, graph view. bzr revid: sma@tinyerp.com-20110802061030-eqvqab8ruwxjhpuy --- addons/base/static/src/js/chrome.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index ed84c32071b..50d4c6e418e 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -250,9 +250,9 @@ openerp.base.Session = openerp.base.Widget.extend( /** @lends openerp.base.Sessi if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done ) return; tag.onload_done = true; - self.do_load_js(files); }; - document.head.appendChild(tag); + $('head').append(tag); + self.do_load_js(files); } else { this.on_modules_loaded(); } From 5075601ddc655111b41bb34b6daec2e646a6aa4d Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Tue, 2 Aug 2011 12:00:45 +0530 Subject: [PATCH 06/19] [FIX] Fixed session. bzr revid: sma@tinyerp.com-20110802063045-4q4c3rf45tqdf25l --- addons/base_gantt/static/src/js/gantt.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index cde8cd18b9d..dc31eb0a9d7 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -410,10 +410,10 @@ init: function(parent, element_id, dataset, view_id) { } } }); - var action_manager = new openerp.base.ActionManager(this.session, element_id); + var action_manager = new openerp.base.ActionManager(this, element_id); action_manager.start(); action_manager.do_action(action); - + //Default_get if(!event_id) action_manager.viewmanager.dataset.index = null; }, From e0a7ee0df10db7df30c72e10312abe74730ee9fd Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Tue, 2 Aug 2011 12:03:14 +0530 Subject: [PATCH 07/19] [FIX] Fixed click events. bzr revid: sma@tinyerp.com-20110802063314-yb41yj6m53tobpso --- addons/base_gantt/static/src/js/gantt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index dc31eb0a9d7..7513948125a 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -287,7 +287,7 @@ init: function(parent, element_id, dataset, view_id) { ganttChartControl.attachEvent("onTaskStartDrag", function(task) {self.on_drag_start(task);}); ganttChartControl.attachEvent("onTaskEndResize", function(task) {self.on_resize_drag_end(task, "resize");}); ganttChartControl.attachEvent("onTaskEndDrag", function(task) {self.on_resize_drag_end(task, "drag");}); - ganttChartControl.attachEvent("onTaskDblClick", function(task, evt) {self.open_popup(task); evt.stopPropagation(); evt.preventDefault();}); + ganttChartControl.attachEvent("onTaskDblClick", function(task) {self.open_popup(task);}); taskdiv = jQuery("div.taskPanel").parent(); taskdiv.addClass('ganttTaskPanel'); From d70785e2e8abef875a18a9e983f1938decfe2990 Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Fri, 5 Aug 2011 12:52:34 +0530 Subject: [PATCH 08/19] [FIX] Replace group name False to Undefined. bzr revid: sma@tinyerp.com-20110805072234-f4zvl4fnzhiewkcv --- addons/base_gantt/static/src/js/gantt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index 7513948125a..9b86f791f32 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -173,7 +173,7 @@ init: function(parent, element_id, dataset, view_id) { } if (grp_key == false){ - grp_key = "False"; + grp_key = "Undefined"; } if (j == 0){ From 5be9b44ac8c77e6eb56296e83b5932cc325c25bf Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Wed, 10 Aug 2011 14:15:28 +0530 Subject: [PATCH 09/19] [IMP] Consider to remove level tag from xml and display first time without group_by. bzr revid: sma@tinyerp.com-20110810084528-059auhvl25neb63p --- addons/base_gantt/static/src/js/gantt.js | 84 ++++++++++++++---------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index 9b86f791f32..b31e02eeb78 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -50,8 +50,7 @@ init: function(parent, element_id, dataset, view_id) { this.color_field = this.fields_view.arch.attrs.color; this.day_length = this.fields_view.arch.attrs.day_length || 8; this.colors = this.fields_view.arch.attrs.colors; - - this.text = this.fields_view.arch.children[0].children[0].attrs.name; + this.text = this.fields_view.arch.children[0].attrs.name; this.parent = this.fields_view.arch.children[0].attrs.link; this.format = "yyyy-MM-dd"; @@ -98,7 +97,7 @@ init: function(parent, element_id, dataset, view_id) { if (result.length != 0){ var show_event = []; - for (i in result){ + for (var i in result){ var res = result[i]; if (res[this.date_start] != false){ @@ -130,7 +129,7 @@ init: function(parent, element_id, dataset, view_id) { var child_event = {}; var temp_id = ""; var final_events = []; - for (i in show_event) { + for (var i in show_event) { var res = show_event[i]; @@ -159,11 +158,8 @@ init: function(parent, element_id, dataset, view_id) { if (duration == false) duration = 0 - if (self.grp.length == 0){ - self.grp.push({'group_by' : this.parent}) - } - if (self.grp != undefined){ - for (j in self.grp){ + if (self.grp.length){ + for (var j in self.grp){ var grp_key = res[self.grp[j]['group_by']]; if (typeof(grp_key) == "object"){ grp_key = res[self.grp[j]['group_by']][1]; @@ -205,9 +201,18 @@ init: function(parent, element_id, dataset, view_id) { all_events[id] = {'parent': temp_id, 'evt':[id , text, start_date, duration, 100, "", color_box[color]]}; final_events.push(id); } + else { + if (i == 0) { + var mod_id = "_" + i; + child_event[mod_id] = {}; + all_events[mod_id] = {'parent': "", 'evt': [mod_id, this.name, start_date, start_date, 100, "", "white"]}; + } + all_events[id] = {'parent': mod_id, 'evt':[id , text, start_date, duration, 100, "", color_box[color]]}; + final_events.push(id); + } } - for (i in final_events){ + for (var i in final_events){ var evt_id = final_events[i]; var evt_date = all_events[evt_id]['evt'][2]; while (all_events[evt_id]['parent'] != "") { @@ -223,7 +228,7 @@ init: function(parent, element_id, dataset, view_id) { var evt_duration = ""; var evt_end_date = ""; - for (i in final_events){ + for (var i in final_events){ evt_id = final_events[i]; evt_date = all_events[evt_id]['evt'][2]; evt_duration = all_events[evt_id]['evt'][3]; @@ -240,32 +245,17 @@ init: function(parent, element_id, dataset, view_id) { } } - for (j in self.grp){ - for (i in all_events){ - res = all_events[i]; - if ((typeof(res['evt'][3])) == "object"){ - res['evt'][3] = self.hours_between(res['evt'][2],res['evt'][3], true); - } - - k = res['evt'][0].toString().indexOf('_'); - if (k != -1){ - if (res['evt'][0].substring(k) == "_"+j){ - if (j == 0){ - task = new GanttTaskInfo(res['evt'][0], res['evt'][1], res['evt'][2], res['evt'][3], res['evt'][4], "",res['evt'][6]); - project.addTask(task); - } else { - task = new GanttTaskInfo(res['evt'][0], res['evt'][1], res['evt'][2], res['evt'][3], res['evt'][4], "",res['evt'][6]); - prt = project.getTaskById(res['parent']); - prt.addChildTask(task); - } - } - } - } + for (var j in self.grp) { + self.render_events(all_events, j); } - for (i in final_events){ + + if (!self.grp.length) { + self.render_events(all_events, 0); + } + + for (var i in final_events){ evt_id = final_events[i]; res = all_events[evt_id]; - task=new GanttTaskInfo(res['evt'][0], res['evt'][1], res['evt'][2], res['evt'][3], res['evt'][4], "",res['evt'][6]); prt = project.getTaskById(res['parent']); prt.addChildTask(task); @@ -368,6 +358,32 @@ init: function(parent, element_id, dataset, view_id) { }, + render_events : function(all_events, j) { + + var self = this; + for (var i in all_events){ + var res = all_events[i]; + if ((typeof(res['evt'][3])) == "object"){ + res['evt'][3] = self.hours_between(res['evt'][2],res['evt'][3], true); + } + + k = res['evt'][0].toString().indexOf('_'); + + if (k != -1) { + if (res['evt'][0].substring(k) == "_"+j){ + if (j == 0){ + task = new GanttTaskInfo(res['evt'][0], res['evt'][1], res['evt'][2], res['evt'][3], res['evt'][4], "",res['evt'][6]); + project.addTask(task); + } else { + task = new GanttTaskInfo(res['evt'][0], res['evt'][1], res['evt'][2], res['evt'][3], res['evt'][4], "",res['evt'][6]); + prt = project.getTaskById(res['parent']); + prt.addChildTask(task); + } + } + } + } + }, + open_popup : function(task) { var event_id = task.getId(); if(event_id.toString().search("_") != -1) From 15aef31efd1f6f2a92cf3ac5c822eba08b8c28b3 Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Wed, 10 Aug 2011 15:11:38 +0530 Subject: [PATCH 10/19] [FIX] Initialize implicit globals. bzr revid: sma@tinyerp.com-20110810094138-sb0ed029xsfrs239 --- addons/base_gantt/static/src/js/gantt.js | 39 ++++++++++++------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index b31e02eeb78..18c8617022c 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -50,7 +50,8 @@ init: function(parent, element_id, dataset, view_id) { this.color_field = this.fields_view.arch.attrs.color; this.day_length = this.fields_view.arch.attrs.day_length || 8; this.colors = this.fields_view.arch.attrs.colors; - this.text = this.fields_view.arch.children[0].attrs.name; + var arch_children = this.fields_view.arch.children[0]; + this.text = arch_children.children[0] ? arch_children.children[0].attrs.name : arch_children.attrs.name; this.parent = this.fields_view.arch.children[0].attrs.link; this.format = "yyyy-MM-dd"; @@ -65,7 +66,7 @@ init: function(parent, element_id, dataset, view_id) { create_gantt: function() { - ganttChartControl = new GanttChart(this.day_length); + var ganttChartControl = new GanttChart(this.day_length); ganttChartControl.setImagePath("/base_gantt/static/lib/dhtmlxGantt/codebase/imgs/"); ganttChartControl.setEditable(true); ganttChartControl.showTreePanel(true); @@ -204,7 +205,6 @@ init: function(parent, element_id, dataset, view_id) { else { if (i == 0) { var mod_id = "_" + i; - child_event[mod_id] = {}; all_events[mod_id] = {'parent': "", 'evt': [mod_id, this.name, start_date, start_date, 100, "", "white"]}; } all_events[id] = {'parent': mod_id, 'evt':[id , text, start_date, duration, 100, "", color_box[color]]}; @@ -261,11 +261,11 @@ init: function(parent, element_id, dataset, view_id) { prt.addChildTask(task); } - oth_hgt = 264; - min_hgt = 150; - name_min_wdt = 150; - gantt_hgt = jQuery(window).height() - oth_hgt; - search_wdt = jQuery("#oe_app_search").width(); + var oth_hgt = 264; + var min_hgt = 150; + var name_min_wdt = 150; + var gantt_hgt = jQuery(window).height() - oth_hgt; + var search_wdt = jQuery("#oe_app_search").width(); if (gantt_hgt > min_hgt){ jQuery('#GanttDiv').height(gantt_hgt).width(search_wdt); @@ -279,13 +279,13 @@ init: function(parent, element_id, dataset, view_id) { ganttChartControl.attachEvent("onTaskEndDrag", function(task) {self.on_resize_drag_end(task, "drag");}); ganttChartControl.attachEvent("onTaskDblClick", function(task) {self.open_popup(task);}); - taskdiv = jQuery("div.taskPanel").parent(); + var taskdiv = jQuery("div.taskPanel").parent(); taskdiv.addClass('ganttTaskPanel'); taskdiv.prev().addClass('ganttDayPanel'); - $gantt_panel = jQuery(".ganttTaskPanel , .ganttDayPanel"); + var $gantt_panel = jQuery(".ganttTaskPanel , .ganttDayPanel"); - ganttrow = jQuery('.taskPanel').closest('tr'); - gtd = ganttrow.children(':first-child'); + var ganttrow = jQuery('.taskPanel').closest('tr'); + var gtd = ganttrow.children(':first-child'); gtd.children().addClass('task-name'); jQuery(".toggle-sidebar").click(function(e) { @@ -307,9 +307,8 @@ init: function(parent, element_id, dataset, view_id) { $gantt_panel.width(1); jQuery(".ganttTaskPanel").parent().width(1); - search_wdt = jQuery("#oe_app_search").width(); - day_wdt = jQuery(".ganttDayPanel").children().children().width(); - name_wdt = jQuery('.task-name').width(); + var search_wdt = jQuery("#oe_app_search").width(); + var day_wdt = jQuery(".ganttDayPanel").children().children().width(); jQuery('#GanttDiv').css('width','100%'); if (search_wdt - day_wdt <= name_min_wdt){ @@ -333,7 +332,7 @@ init: function(parent, element_id, dataset, view_id) { var self = this; - dat = this.convert_str_date(dat); + var dat = this.convert_str_date(dat); var day = Math.floor(duration/self.day_length); var hrs = duration % self.day_length; @@ -351,9 +350,9 @@ init: function(parent, element_id, dataset, view_id) { var date2_ms = date2.getTime(); var difference_ms = Math.abs(date1_ms - date2_ms); - d = parent_task? Math.ceil(difference_ms / ONE_DAY) : Math.floor(difference_ms / ONE_DAY); - h = (difference_ms % ONE_DAY)/(1000 * 60 * 60); - num = (d * this.day_length) + h; + var d = parent_task? Math.ceil(difference_ms / ONE_DAY) : Math.floor(difference_ms / ONE_DAY); + var h = (difference_ms % ONE_DAY)/(1000 * 60 * 60); + var num = (d * this.day_length) + h; return parseFloat(num.toFixed(2)); }, @@ -435,7 +434,7 @@ init: function(parent, element_id, dataset, view_id) { }, on_drag_start : function(task){ - st_date = task.getEST(); + var st_date = task.getEST(); if(st_date.getHours()){ self.hh = st_date.getHours(); self.mm = st_date.getMinutes(); From 33f984d056f6fc367ed1194f7e81aba4c0deca3e Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Thu, 11 Aug 2011 12:49:34 +0530 Subject: [PATCH 11/19] [FIX] Minor changes. bzr revid: sma@tinyerp.com-20110811071934-adjiwyspxegdpzk5 --- addons/base_gantt/static/src/js/gantt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index 18c8617022c..61f9a443d56 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -66,7 +66,7 @@ init: function(parent, element_id, dataset, view_id) { create_gantt: function() { - var ganttChartControl = new GanttChart(this.day_length); + ganttChartControl = new GanttChart(this.day_length); ganttChartControl.setImagePath("/base_gantt/static/lib/dhtmlxGantt/codebase/imgs/"); ganttChartControl.setEditable(true); ganttChartControl.showTreePanel(true); From 18de9c065a33e6cb0e32195be0d374ec93a3e763 Mon Sep 17 00:00:00 2001 From: Jigar Amin - OpenERP Date: Fri, 12 Aug 2011 13:10:21 +0530 Subject: [PATCH 12/19] [FIX] typo fied name lp bug: https://launchpad.net/bugs/825008 fixed bzr revid: jam@tinyerp.com-20110812074021-7cbge6mgfamim32w --- addons/project_issue/project_issue_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/project_issue/project_issue_view.xml b/addons/project_issue/project_issue_view.xml index 23f12b3907f..86e232e91b5 100644 --- a/addons/project_issue/project_issue_view.xml +++ b/addons/project_issue/project_issue_view.xml @@ -153,7 +153,7 @@ - + From 86a5de431bc6c59569cef680fc41ed712caa0f31 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 12 Aug 2011 10:38:20 +0200 Subject: [PATCH 13/19] [FIX] don't use @string on filters inside fields in search view, use @help bzr revid: xmo@openerp.com-20110812083820-tnk2yv7kkuylg9aw --- openerp/addons/base/res/partner/partner_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/addons/base/res/partner/partner_view.xml b/openerp/addons/base/res/partner/partner_view.xml index 763147fb47e..7dc4a595adf 100644 --- a/openerp/addons/base/res/partner/partner_view.xml +++ b/openerp/addons/base/res/partner/partner_view.xml @@ -344,7 +344,7 @@ - + From 4e5f4bd565bbaff2a8f89117c791de9299015e08 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 12 Aug 2011 11:45:41 +0200 Subject: [PATCH 14/19] [IMP] simple style fixes bzr revid: xmo@openerp.com-20110812094541-zeb5lz6nk0jgq21y --- addons/base/static/src/js/search.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/addons/base/static/src/js/search.js b/addons/base/static/src/js/search.js index 4b746832a65..63ccec088a6 100644 --- a/addons/base/static/src/js/search.js +++ b/addons/base/static/src/js/search.js @@ -875,11 +875,10 @@ openerp.base.search.ExtendedSearchGroup = openerp.base.OldWidget.extend({ this._super(); var _this = this; this.add_prop(); - this.$element.find('.searchview_extended_add_proposition').click(function (e) { + this.$element.find('.searchview_extended_add_proposition').click(function () { _this.add_prop(); }); - var delete_btn = this.$element.find('.searchview_extended_delete_group'); - delete_btn.click(function (e) { + this.$element.find('.searchview_extended_delete_group').click(function () { _this.stop(); }); }, @@ -889,7 +888,7 @@ openerp.base.search.ExtendedSearchGroup = openerp.base.OldWidget.extend({ }).compact().value(); var choice = this.$element.find(".searchview_extended_group_choice").val(); var op = choice == "all" ? "&" : "|"; - return [].concat(choice == "none" ? ['!'] : [], + return choice == "none" ? ['!'] : [].concat( _.map(_.range(_.max([0,props.length - 1])), function() { return op; }), props); }, @@ -901,10 +900,7 @@ openerp.base.search.ExtendedSearchGroup = openerp.base.OldWidget.extend({ parent.check_last_element(); }, set_last_group: function(is_last) { - if(is_last) - this.$element.addClass("last_group"); - else - this.$element.removeClass("last_group"); + this.$element.toggleClass('last_group', is_last); } }); @@ -927,8 +923,7 @@ openerp.base.search.ExtendedSearchProposition = openerp.base.OldWidget.extend({ this.$element.find(".searchview_extended_prop_field").change(function() { _this.changed(); }); - var delete_btn = this.$element.find('.searchview_extended_delete_prop'); - delete_btn.click(function (e) { + this.$element.find('.searchview_extended_delete_prop').click(function () { _this.stop(); }); }, From d6074e66195065581a002f865df76d192fbc8ab1 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 12 Aug 2011 12:36:43 +0200 Subject: [PATCH 15/19] [IMP] move openerp.base.Widget to relevant section of the actual dogs (as a guide), remove old manual openerp.base.Widget APIDoc bzr revid: xmo@openerp.com-20110812103643-2ew32jiqdsm71jqe --- addons/base/controllers/main.py | 8 +- addons/base/static/src/js/core.js | 53 ------ doc/source/addons.rst | 291 +++++++++++------------------- doc/source/development.rst | 12 +- 4 files changed, 115 insertions(+), 249 deletions(-) diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 4f6b3ea4f70..36db03d6bba 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -772,8 +772,8 @@ class View(openerpweb.Controller): """ Parses an arbitrary string containing a domain, transforms it to either a literal domain or a :class:`openerpweb.nonliterals.Domain` - :param domain: the domain to parse, if the domain is not a string it is assumed to - be a literal domain and is returned as-is + :param domain: the domain to parse, if the domain is not a string it + is assumed to be a literal domain and is returned as-is :param session: Current OpenERP session :type session: openerpweb.openerpweb.OpenERPSession """ @@ -789,8 +789,8 @@ class View(openerpweb.Controller): """ Parses an arbitrary string containing a context, transforms it to either a literal context or a :class:`openerpweb.nonliterals.Context` - :param context: the context to parse, if the context is not a string it is assumed to - be a literal domain and is returned as-is + :param context: the context to parse, if the context is not a string it + is assumed to be a literal domain and is returned as-is :param session: Current OpenERP session :type session: openerpweb.openerpweb.OpenERPSession """ diff --git a/addons/base/static/src/js/core.js b/addons/base/static/src/js/core.js index 859c96645a1..da9b5abf3e8 100644 --- a/addons/base/static/src/js/core.js +++ b/addons/base/static/src/js/core.js @@ -373,59 +373,6 @@ openerp.base.SessionAware = openerp.base.Class.extend({ } }); -/** - * Base class for all visual components. Provides a lot of functionalities helpful - * for the management of a part of the DOM. - * - * Widget handles: - * - Rendering with QWeb. - * - Life-cycle management and parenting (when a parent is destroyed, all its children are - * destroyed too). - * - Insertion in DOM. - * - * Widget also extends SessionAware for ease of use. - * - * Guide to create implementations of the Widget class: - * ============================================== - * - * Here is a sample child class: - * - * MyWidget = openerp.base.Widget.extend({ - * // the name of the QWeb template to use for rendering - * template: "MyQWebTemplate", - * // identifier prefix, it is useful to put an obvious one for debugging - * identifier_prefix: 'my-id-prefix-', - * - * init: function(parent) { - * this._super(parent); - * // stuff that you want to init before the rendering - * }, - * start: function() { - * this._super(); - * // stuff you want to make after the rendering, `this.$element` holds a correct value - * this.$element.find(".my_button").click(/* an example of event binding * /); - * - * // if you have some asynchronous operations, it's a good idea to return - * // a promise in start() - * var promise = this.rpc(...); - * return promise; - * } - * }); - * - * Now this class can simply be used with the following syntax: - * - * var my_widget = new MyWidget(this); - * my_widget.appendTo($(".some-div")); - * - * With these two lines, the MyWidget instance was inited, rendered, it was inserted into the - * DOM inside the ".some-div" div and its events were binded. - * - * And of course, when you don't need that widget anymore, just do: - * - * my_widget.stop(); - * - * That will kill the widget in a clean way and erase its content from the dom. - */ openerp.base.Widget = openerp.base.SessionAware.extend({ /** * The name of the QWeb template that will be used for rendering. Must be diff --git a/doc/source/addons.rst b/doc/source/addons.rst index 4f371192760..7261e57ebd3 100644 --- a/doc/source/addons.rst +++ b/doc/source/addons.rst @@ -113,6 +113,98 @@ initializing the addon. Creating new standard roles --------------------------- +Widget +++++++ + +This is the base class for all visual components. It provides a number of +services for the management of a DOM subtree: + +* Rendering with QWeb + +* Parenting-child relations + +* Life-cycle management (including facilitating children destruction when a + parent object is removed) + +* DOM insertion, via jQuery-powered insertion methods. Insertion targets can + be anything the corresponding jQuery method accepts (generally selectors, + DOM nodes and jQuery objects): + + :js:func:`~openerp.base.Widget.appendTo` + Renders the widget and inserts it as the last child of the target, uses + `.appendTo()`_ + + :js:func:`~openerp.base.Widget.prependTo` + Renders the widget and inserts it as the first child of the target, uses + `.prependTo()`_ + + :js:func:`~openerp.base.Widget.insertAfter` + Renders the widget and inserts it as the preceding sibling of the target, + uses `.insertAfter()`_ + + :js:func:`~openerp.base.Widget.insertBefore` + Renders the widget and inserts it as the following sibling of the target, + uses `.insertBefore()`_ + +:js:class:`~openerp.base.Widget` inherits from +:js:class:`~openerp.base.SessionAware`, so subclasses can easily access the +RPC layers. + +Subclassing Widget +~~~~~~~~~~~~~~~~~~ + +:js:class:`~openerp.base.Widget` is subclassed in the standard manner (via the +:js:func:`~openerp.base.Class.extend` method), and provides a number of +abstract properties and concrete methods (which you may or may not want to +override). Creating a subclass looks like this: + +.. code-block:: javascript + + var MyWidget = openerp.base.Widget.extend({ + // QWeb template to use when rendering the object + template: "MyQWebTemplate", + // autogenerated id prefix, specificity helps when debugging + identifier_prefix: 'my-id-prefix-', + + init: function(parent) { + this._super(parent); + // insert code to execute before rendering, for object + // initialization + }, + start: function() { + this._super(); + // post-rendering initialization code, at this point + // ``this.$element`` has been initialized + this.$element.find(".my_button").click(/* an example of event binding * /); + + // if ``start`` is asynchronous, return a promise object so callers + // know when the object is done initializing + return this.rpc(/* … */) + } + }); + +The new class can then be used in the following manner: + +.. code-block:: javascript + + // Create the instance + var my_widget = new MyWidget(this); + // Render and insert into DOM + my_widget.appendTo(".some-div"); + +After these two lines have executed (and any promise returned by ``appendTo`` +has been resolved if needed), the widget is ready to be used. + +If the widget is not needed anymore (because it's transient), simply terminate +it: + +.. code-block:: javascript + + my_widget.stop(); + +will unbind all DOM events, remove the widget's content from the DOM and +destroy all widget data. + Views +++++ @@ -236,193 +328,6 @@ replace ``addons`` by the directory in which your own addon lives. and run ``nosetests addons`` instead of the ``unit2`` command, the result should be exactly the same. -APIs ----- - -Javascript -++++++++++ - -.. js:class:: openerp.base.Widget(view, node) - - :param openerp.base.Controller view: The view to which the widget belongs - :param Object node: the ``fields_view_get`` descriptor for the widget - - .. js:attribute:: $element - - The widget's root element as jQuery object - -.. js:class:: openerp.base.DataSet(session, model) - - :param openerp.base.Session session: the RPC session object - :param String model: the model managed by this dataset - - The DataSet is the abstraction for a sequence of records stored in - database. - - It provides interfaces for reading records based on search - criteria, and for selecting and fetching records based on - activated ids. - - .. js:function:: fetch([offset][, limit]) - - :param Number offset: the index from which records should start - being returned (section) - :param Number limit: the maximum number of records to return - :returns: the dataset instance it was called on - - Asynchronously fetches the records selected by the DataSet's - domain and context, in the provided sort order if any. - - Only fetches the fields selected by the DataSet. - - On success, triggers :js:func:`on_fetch` - - .. js:function:: on_fetch(records, event) - - :param Array records: an array of - :js:class:`openerp.base.DataRecord` - matching the DataSet's selection - :param event: a data holder letting the event handler fetch - meta-informations about the event. - :type event: OnFetchEvent - - Fired after :js:func:`fetch` is done fetching the records - selected by the DataSet. - - .. js:function:: active_ids - - :returns: the dataset instance it was called on - - Asynchronously fetches the active records for this DataSet. - - On success, triggers :js:func:`on_active_ids` - - .. js:function:: on_active_ids(records) - - :param Array records: an array of - :js:class:`openerp.base.DataRecord` - matching the currently active ids - - Fired after :js:func:`active_ids` fetched the records matching - the DataSet's active ids. - - .. js:function:: active_id - - :returns: the dataset instance in was called on - - Asynchronously fetches the current active record. - - On success, triggers :js:func:`on_active_id` - - .. js:function:: on_active_id(record) - - :param Object record: the record fetched by - :js:func:`active_id`, or ``null`` - :type record: openerp.base.DataRecord - - Fired after :js:func:`active_id` fetched the record matching - the dataset's active id - - .. js:function:: set(options) - - :param Object options: the options to set on the dataset - :type options: DataSetOptions - :returns: the dataset instance it was called on - - Configures the data set by setting various properties on it - - .. js:function:: prev - - :returns: the dataset instance it was called on - - Activates the id preceding the current one in the active ids - sequence of the dataset. - - If the current active id is at the start of the sequence, - wraps back to the last id of the sequence. - - .. js:function:: next - - :returns: the dataset instance it was called on - - Activates the id following the current one in the active ids - sequence. - - If the current active id is the last of the sequence, wraps - back to the beginning of the active ids sequence. - - .. js:function:: select(ids) - - :param Array ids: the identifiers to activate on the dataset - :returns: the dataset instance it was called on - - Activates all the ids specified in the dataset, resets the - current active id to be the first id of the new sequence. - - The internal order will be the same as the ids list provided. - - .. js:function:: get_active_ids - - :returns: the list of current active ids for the dataset - - .. js:function:: activate(id) - - :param Number id: the id to activate - :returns: the dataset instance it was called on - - Activates the id provided in the dataset. If no ids are - selected, selects the id in the dataset. - - If ids are already selected and the provided id is not in that - selection, raises an error. - - .. js:function:: get_active_id - - :returns: the dataset's current active id - -Ad-hoc objects and structural types -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -These objects are not associated with any specific class, they're -generally literal objects created on the spot. Names are merely -convenient ways to refer to them and their properties. - -.. js:class:: OnFetchEvent - - .. js:attribute:: context - - The context used for the :js:func:`fetch` call (domain set on - the :js:class:`openerp.base.DataSet` when ``fetch`` was - called) - - .. js:attribute:: domain - - The domain used for the :js:func:`fetch` call - - .. js:attribute:: limit - - The limit with which the original :js:func:`fetch` call was - performed - - .. js:attribute:: offset - - The offset with which the original :js:func:`fetch` call was - performed - - .. js:attribute:: sort - - The sorting criteria active on the - :js:class:`openerp.base.DataSet` when :js:func:`fetch` was - called - -.. js:class:: DataSetOptions - - .. js:attribute:: context - - .. js:attribute:: domain - - .. js:attribute:: sort - Python ++++++ @@ -499,3 +404,15 @@ Python .. _promise object: http://api.jquery.com/deferred.promise/ + +.. _.appendTo(): + http://api.jquery.com/appendTo/ + +.. _.prependTo(): + http://api.jquery.com/prependTo/ + +.. _.insertAfter(): + http://api.jquery.com/insertAfter/ + +.. _.insertBefore(): + http://api.jquery.com/insertBefore/ diff --git a/doc/source/development.rst b/doc/source/development.rst index bfb176cb5c5..85fbebcceb3 100644 --- a/doc/source/development.rst +++ b/doc/source/development.rst @@ -374,11 +374,13 @@ Deletion can be overridden by replacing the calls :js:func:`~openerp.base.DataSet.unlink` in order to remove the records entirely. -.. note:: the list-wise deletion button (next to the record addition button) - simply proxies to :js:func:`~openerp.base.ListView.do_delete` after - obtaining all selected record ids, but it is possible to override it - alone by replacing - :js:func:`~openerp.base.ListView.do_delete_selected`. +.. note:: + + the list-wise deletion button (next to the record addition button) + simply proxies to :js:func:`~openerp.base.ListView.do_delete` after + obtaining all selected record ids, but it is possible to override it + alone by replacing + :js:func:`~openerp.base.ListView.do_delete_selected`. Internal API Doc ---------------- From 2c2fe7a691fb31a72a19662750dda0422105c4e5 Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Fri, 12 Aug 2011 16:08:18 +0530 Subject: [PATCH 16/19] [FIX] Remove conflicts. bzr revid: sma@tinyerp.com-20110812103818-q8wet6opinckiv1a --- addons/base/static/src/js/chrome.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index 1ff49eb773a..92e3c298420 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -4,7 +4,7 @@ openerp.base.chrome = function(openerp) { -<<<<<<< TREE + openerp.base.Session = openerp.base.Widget.extend( /** @lends openerp.base.Session# */{ /** * @constructs @@ -273,8 +273,6 @@ openerp.base.Session = openerp.base.Widget.extend( /** @lends openerp.base.Sessi } }); -======= ->>>>>>> MERGE-SOURCE openerp.base.Notification = openerp.base.Widget.extend({ init: function(parent, element_id) { this._super(parent, element_id); From ee581f8247fa3d0df9ace2505f6977f48fcd0257 Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Fri, 12 Aug 2011 17:14:02 +0530 Subject: [PATCH 17/19] [IMP] simplify code of padding function in date formatting. bzr revid: sma@tinyerp.com-20110812114402-u9u8vxxp1fnonq3m --- addons/base/static/src/js/formats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base/static/src/js/formats.js b/addons/base/static/src/js/formats.js index fb1ada544a4..eb5ff6d8368 100644 --- a/addons/base/static/src/js/formats.js +++ b/addons/base/static/src/js/formats.js @@ -83,7 +83,7 @@ openerp.base.parse_time = function(str) { */ var zpad = function(str, size) { str = "" + str; - return new Array(size - str.length).join('0') + str; + return new Array(_.range(size - str.length)).join('0') + str; }; /** From 964ae3f196f1b61bbb8b924cbd3862af41b7fd12 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 12 Aug 2011 14:11:27 +0200 Subject: [PATCH 18/19] [FIX] stupid bug introduced in revision xmo@openerp.com-20110810141545-k98nvymjy5r7sslb bzr revid: xmo@openerp.com-20110812121127-m50vupb36bv0tnjy --- addons/base/static/src/js/formats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base/static/src/js/formats.js b/addons/base/static/src/js/formats.js index fb1ada544a4..074cabe5eee 100644 --- a/addons/base/static/src/js/formats.js +++ b/addons/base/static/src/js/formats.js @@ -83,7 +83,7 @@ openerp.base.parse_time = function(str) { */ var zpad = function(str, size) { str = "" + str; - return new Array(size - str.length).join('0') + str; + return new Array(size - str.length + 1).join('0') + str; }; /** From a4f9eb398b39978be8c35a8eb2e1eb561ef26ecf Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 12 Aug 2011 15:31:08 +0200 Subject: [PATCH 19/19] [REM] listview columns filtering on a name being present: don't try to read buttons with a name, it's kinda stupid bzr revid: xmo@openerp.com-20110812133108-5bync0jgo0krn0u4 --- addons/base/static/src/js/list.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index 3032e702a73..a0440221520 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -772,7 +772,7 @@ openerp.base.ListView.List = openerp.base.Class.extend( /** @lends openerp.base. var old_index = this.dataset.index; this.dataset.index = record_index; read_p = this.dataset.read_index( - _.filter(_.pluck(this.columns, 'name'), _.identity), + _.pluck(_(this.columns).filter(function (r) {return r.tag === 'field';}), 'name'), function (record) { var form_record = self.transform_record(record); self.rows.splice(record_index, 1, form_record); @@ -1035,7 +1035,7 @@ openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.bas page = this.datagroup.openable ? this.page : view.page; dataset.read_slice({ - fields: _.filter(_.pluck(_.select(this.columns, function(x) {return x.tag == "field";}), 'name'), _.identity), + fields: _.pluck(_.select(this.columns, function(x) {return x.tag == "field"}), 'name'), offset: page * limit, limit: limit }, function (records) {