From 24edc5615ba7e20f465e4b1b8e11fcabb81fdb79 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 21 Mar 2013 12:01:52 +0100 Subject: [ADD] basic widget for goal list bzr revid: mat@openerp.com-20130321110152-0wa9b3uuyk2qvk0d --- addons/gamification/static/src/js/gamification.js | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 addons/gamification/static/src/js/gamification.js (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js new file mode 100644 index 00000000000..4c7e25980d9 --- /dev/null +++ b/addons/gamification/static/src/js/gamification.js @@ -0,0 +1,38 @@ +openerp.gamification = function(instance) { + console.log("Debug statement: file loaded"); + + instance.Side_bar = instance.mail.Widget.include( { + init: function (parent, action) { + console.log("Init function"); + var self = this; + this._super(parent, action); + this.deferred = $.Deferred(); + this.res_user = new instance.web.DataSetSearch(this, 'res.users'); + this.goals_info = {}; + console.log("init"); + }, + renderElement: function() { + var self = this; + this._super.apply(this, arguments); + console.log("Render!"); + self.render_template(self.$el.filter(".oe_user_sidebar"),'user_wall'); + self.get_goal_todo_info(); + }, + render_template: function(target,template) { + var self = this; + target.append(instance.web.qweb.render(template,{'widget': self})); + }, + get_goal_todo_info: function() { + var self = this; + var goals_info = this.res_user.call('get_goals_todo_info', {}).then(function(res) { + self.goals_info['info'] = res + }); + $.when(goals_info).done(function() { + console.log(self.goals_info.info); + if(self.goals_info.info.length > 0){ + self.render_template(self.$el.find(".oe_gamification_goal"),'goal_list_to_do'); + } + }); + }, + }); +}; -- cgit v1.2.3 From f691d138103ec351be61855d226239d47054b7d4 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 22 Mar 2013 09:51:51 +0100 Subject: [IMP] skip plans with all goals finished bzr revid: mat@openerp.com-20130322085151-r6sse6383z6ya9by --- addons/gamification/static/src/js/gamification.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 4c7e25980d9..2820666d56d 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -22,6 +22,10 @@ openerp.gamification = function(instance) { var self = this; target.append(instance.web.qweb.render(template,{'widget': self})); }, + render_template_replace: function(target,template) { + var self = this; + target.html(instance.web.qweb.render(template,{'widget': self})); + }, get_goal_todo_info: function() { var self = this; var goals_info = this.res_user.call('get_goals_todo_info', {}).then(function(res) { @@ -30,7 +34,7 @@ openerp.gamification = function(instance) { $.when(goals_info).done(function() { console.log(self.goals_info.info); if(self.goals_info.info.length > 0){ - self.render_template(self.$el.find(".oe_gamification_goal"),'goal_list_to_do'); + self.render_template_replace(self.$el.find(".oe_gamification_goal"),'goal_list_to_do'); } }); }, -- cgit v1.2.3 From 80541abdbf27d77014dec403d562f616408061c5 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 22 Mar 2013 12:13:44 +0100 Subject: [IMP] update button with refresh bzr revid: mat@openerp.com-20130322111344-7qs3o2tvbx7h4qln --- addons/gamification/static/src/js/gamification.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 2820666d56d..667f856059e 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -3,18 +3,26 @@ openerp.gamification = function(instance) { instance.Side_bar = instance.mail.Widget.include( { init: function (parent, action) { - console.log("Init function"); var self = this; this._super(parent, action); this.deferred = $.Deferred(); this.res_user = new instance.web.DataSetSearch(this, 'res.users'); this.goals_info = {}; - console.log("init"); + }, + events: { + 'click a.oe_update_goal': function(event) { + var self = this; + var goal_id = parseInt(event.target.id); + console.log(goal_id); + var goal_updated = new instance.web.Model('gamification.goal').call('update', [[goal_id]]); + $.when(goal_updated).done(function() { + self.get_goal_todo_info(); + }); + } }, renderElement: function() { var self = this; this._super.apply(this, arguments); - console.log("Render!"); self.render_template(self.$el.filter(".oe_user_sidebar"),'user_wall'); self.get_goal_todo_info(); }, @@ -28,6 +36,7 @@ openerp.gamification = function(instance) { }, get_goal_todo_info: function() { var self = this; + console.log(this); var goals_info = this.res_user.call('get_goals_todo_info', {}).then(function(res) { self.goals_info['info'] = res }); @@ -38,5 +47,13 @@ openerp.gamification = function(instance) { } }); }, + update_goal: function() { + console.log(this); + console.log(instance.Side_bar); + var goal_update = new instance.web.Model('gamification.goal').call('update', [[parseInt(this.id)]]); + $.when(goal_update).done(function() { + // $(".oe_user_sidebar").find(".oe_gamification_goal").html(instance.web.qweb.render('goal_list_to_do')); + }); + }, }); }; -- cgit v1.2.3 From 391947f7cc94c237d05f970872fdbec02f56fc65 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 22 Mar 2013 16:18:03 +0100 Subject: [IMP] using sidebar and better javascript bzr revid: mat@openerp.com-20130322151803-nzb41s0mxvaidrel --- addons/gamification/static/src/js/gamification.js | 32 +++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 667f856059e..5b503171337 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -1,7 +1,9 @@ openerp.gamification = function(instance) { console.log("Debug statement: file loaded"); + var QWeb = instance.web.qweb; - instance.Side_bar = instance.mail.Widget.include( { + instance.gamification.Sidebar = instance.web.Widget.extend({ + template: 'gamification.user_wall_sidebar', init: function (parent, action) { var self = this; this._super(parent, action); @@ -12,8 +14,7 @@ openerp.gamification = function(instance) { events: { 'click a.oe_update_goal': function(event) { var self = this; - var goal_id = parseInt(event.target.id); - console.log(goal_id); + var goal_id = parseInt(event.currentTarget.id); var goal_updated = new instance.web.Model('gamification.goal').call('update', [[goal_id]]); $.when(goal_updated).done(function() { self.get_goal_todo_info(); @@ -23,37 +24,46 @@ openerp.gamification = function(instance) { renderElement: function() { var self = this; this._super.apply(this, arguments); - self.render_template(self.$el.filter(".oe_user_sidebar"),'user_wall'); self.get_goal_todo_info(); }, render_template: function(target,template) { var self = this; - target.append(instance.web.qweb.render(template,{'widget': self})); + target.append(QWeb.render(template,{'widget': self})); }, render_template_replace: function(target,template) { var self = this; - target.html(instance.web.qweb.render(template,{'widget': self})); + target.html(QWeb.render(template,{'widget': self})); }, get_goal_todo_info: function() { var self = this; - console.log(this); var goals_info = this.res_user.call('get_goals_todo_info', {}).then(function(res) { self.goals_info['info'] = res }); $.when(goals_info).done(function() { console.log(self.goals_info.info); if(self.goals_info.info.length > 0){ - self.render_template_replace(self.$el.find(".oe_gamification_goal"),'goal_list_to_do'); + self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do'); } }); }, update_goal: function() { - console.log(this); - console.log(instance.Side_bar); var goal_update = new instance.web.Model('gamification.goal').call('update', [[parseInt(this.id)]]); $.when(goal_update).done(function() { - // $(".oe_user_sidebar").find(".oe_gamification_goal").html(instance.web.qweb.render('goal_list_to_do')); + $(".oe_user_sidebar").find(".oe_gamification_goal").html(QWeb.render('gamification.goal_list_to_do')); }); }, }); + + instance.mail.Widget.include({ + init: function (parent, action) { + var self = this; + this._super(parent, action); + }, + start: function() { + this._super(); + var self = this; + var sidebar = new instance.gamification.Sidebar(self); + sidebar.appendTo($('.oe_mail_wall_aside')); + } + }); }; -- cgit v1.2.3 From 632a9d4bcbd89398e9d165422a35779902552039 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 22 Mar 2013 17:05:20 +0100 Subject: [IMP] show description button bzr revid: mat@openerp.com-20130322160520-pq9eaoqtnsvwvj7d --- addons/gamification/static/src/js/gamification.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 5b503171337..485f18b67dd 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -19,7 +19,11 @@ openerp.gamification = function(instance) { $.when(goal_updated).done(function() { self.get_goal_todo_info(); }); - } + }, + 'click a.oe_show_description': function(event) { + var goal_id = parseInt(event.currentTarget.id); + this.$el.find('.oe_type_description_'+goal_id).toggle(10); + }, }, renderElement: function() { var self = this; @@ -43,15 +47,10 @@ openerp.gamification = function(instance) { console.log(self.goals_info.info); if(self.goals_info.info.length > 0){ self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do'); + self.$el.find('.oe_type_description').hide(); } }); }, - update_goal: function() { - var goal_update = new instance.web.Model('gamification.goal').call('update', [[parseInt(this.id)]]); - $.when(goal_update).done(function() { - $(".oe_user_sidebar").find(".oe_gamification_goal").html(QWeb.render('gamification.goal_list_to_do')); - }); - }, }); instance.mail.Widget.include({ -- cgit v1.2.3 From 02725e359daca7936b0b3a8109ecf1f16f98032b Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Sun, 24 Mar 2013 14:46:58 +0100 Subject: [FIX] call correct method for cron bzr revid: mat@openerp.com-20130324134658-0kx6v1st048gkm1r --- addons/gamification/static/src/js/gamification.js | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 485f18b67dd..cf6542b3456 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -24,6 +24,34 @@ openerp.gamification = function(instance) { var goal_id = parseInt(event.currentTarget.id); this.$el.find('.oe_type_description_'+goal_id).toggle(10); }, + 'click a.oe_goal_action': function(event) { + var self = this; + var goal_id = parseInt(event.currentTarget.id); + var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]); + + console.log(goal_action); + // var action = { + // name : 'Complete Profile', + // type: 'ir.actions.act_window', + // res_model: 'res.users', + // views: [[false, 'form']], + // res_id : event.data.uid, + // target: 'new', + // flags : { action_buttons: true }, + // }; + // var action_manager = new instance.web.ActionManager(this); + // action_manager.do_action(action); + // var form = action_manager.dialog_widget.views.form.controller; + // form.on('load_record', self, function(){ + // form.fields[$(self).attr('id')].$el.find("input").focus() + // }) + // form.on("on_button_cancel", action_manager.dialog, action_manager.dialog.close); + // form.on('save', self, function() { + // action_manager.dialog.close(); + // location.reload(); + // }); + + } }, renderElement: function() { var self = this; -- cgit v1.2.3 From 8a04406a28fb8a3a4b49c04a6bb9609fd8b9260e Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Sun, 24 Mar 2013 19:05:57 +0100 Subject: [IMP] action button (almost working) bzr revid: mat@openerp.com-20130324180557-ttos23t09uayh6zx --- addons/gamification/static/src/js/gamification.js | 31 +++++++---------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index cf6542b3456..d24e0b4159c 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -27,29 +27,16 @@ openerp.gamification = function(instance) { 'click a.oe_goal_action': function(event) { var self = this; var goal_id = parseInt(event.currentTarget.id); - var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]); + var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]).then(function(res) { + goal_action['action'] = res; + }); + $.when(goal_action).done(function() { + console.log(goal_action); + var action_manager = new instance.web.ActionManager(this); + action_manager.do_action(goal_action.action); - console.log(goal_action); - // var action = { - // name : 'Complete Profile', - // type: 'ir.actions.act_window', - // res_model: 'res.users', - // views: [[false, 'form']], - // res_id : event.data.uid, - // target: 'new', - // flags : { action_buttons: true }, - // }; - // var action_manager = new instance.web.ActionManager(this); - // action_manager.do_action(action); - // var form = action_manager.dialog_widget.views.form.controller; - // form.on('load_record', self, function(){ - // form.fields[$(self).attr('id')].$el.find("input").focus() - // }) - // form.on("on_button_cancel", action_manager.dialog, action_manager.dialog.close); - // form.on('save', self, function() { - // action_manager.dialog.close(); - // location.reload(); - // }); + //var form = action_manager.dialog_widget.views.form.controller; + }); } }, -- cgit v1.2.3 From 364612d0be52e6677a26f8a083d58b52d81c7f0a Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 25 Mar 2013 16:39:53 +0100 Subject: [IMP] use board view for sidebar bzr revid: mat@openerp.com-20130325153953-zch12sfx62s5i6xc --- addons/gamification/static/src/js/gamification.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index d24e0b4159c..28323b29421 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -1,5 +1,4 @@ openerp.gamification = function(instance) { - console.log("Debug statement: file loaded"); var QWeb = instance.web.qweb; instance.gamification.Sidebar = instance.web.Widget.extend({ @@ -31,7 +30,6 @@ openerp.gamification = function(instance) { goal_action['action'] = res; }); $.when(goal_action).done(function() { - console.log(goal_action); var action_manager = new instance.web.ActionManager(this); action_manager.do_action(goal_action.action); -- cgit v1.2.3 From 0aa973b9f024ebefaa2f2ec9f47060e721a5c54a Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 25 Mar 2013 17:15:27 +0100 Subject: [IMP] refresh button for plan bzr revid: mat@openerp.com-20130325161527-qes3lqpzevdmdsx6 --- addons/gamification/static/src/js/gamification.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 28323b29421..08b6155a4f1 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -19,6 +19,14 @@ openerp.gamification = function(instance) { self.get_goal_todo_info(); }); }, + 'click a.oe_update_plan': function(event) { + var self = this; + var plan_id = parseInt(event.currentTarget.id); + var goals_updated = new instance.web.Model('gamification.goal.plan').call('quick_update', [plan_id]); + $.when(goals_updated).done(function() { + self.get_goal_todo_info(); + }); + }, 'click a.oe_show_description': function(event) { var goal_id = parseInt(event.currentTarget.id); this.$el.find('.oe_type_description_'+goal_id).toggle(10); @@ -35,8 +43,7 @@ openerp.gamification = function(instance) { //var form = action_manager.dialog_widget.views.form.controller; }); - - } + }, }, renderElement: function() { var self = this; -- cgit v1.2.3 From bfcf26bf19610e70b41954ff4e2c3818c1e53a77 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 25 Mar 2013 17:52:35 +0100 Subject: [IMP] use help to show goal description bzr revid: mat@openerp.com-20130325165235-q0wwyrdfrak5utkr --- addons/gamification/static/src/js/gamification.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 08b6155a4f1..01004d94edd 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -27,10 +27,10 @@ openerp.gamification = function(instance) { self.get_goal_todo_info(); }); }, - 'click a.oe_show_description': function(event) { - var goal_id = parseInt(event.currentTarget.id); - this.$el.find('.oe_type_description_'+goal_id).toggle(10); - }, + // 'click a.oe_show_description': function(event) { + // var goal_id = parseInt(event.currentTarget.id); + // this.$el.find('.oe_type_description_'+goal_id).toggle(10); + // }, 'click a.oe_goal_action': function(event) { var self = this; var goal_id = parseInt(event.currentTarget.id); -- cgit v1.2.3 From 635df4028a8cf9d5185e31d21df67daf609506b3 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 26 Mar 2013 16:45:53 +0100 Subject: [ADD] monetary field bzr revid: mat@openerp.com-20130326154553-t8cacle6s1oll4r9 --- addons/gamification/static/src/js/gamification.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 01004d94edd..62de4835842 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -64,13 +64,31 @@ openerp.gamification = function(instance) { self.goals_info['info'] = res }); $.when(goals_info).done(function() { - console.log(self.goals_info.info); if(self.goals_info.info.length > 0){ self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do'); self.$el.find('.oe_type_description').hide(); + self.render_money_fields(self.goals_info.info[0].currency); } }); }, + render_money_fields: function(currency_id) { + var self = this; + + self.dfm = new instance.web.form.DefaultFieldManager(self); + self.$el.find(".oe_goal_field_monetary").each(function() { + money_field = new instance.web.form.FieldMonetary(self.dfm, { + attrs: { + modifiers: '{"readonly": true}' + } + }); + money_field.set('currency', currency_id); + money_field.get_currency_info(); + money_field.set('value', parseInt($(this).text())); + console.log(money_field.get('value')); + money_field.replace($(this)); + console.log(money_field.$el.html()); + }); + } }); instance.mail.Widget.include({ -- cgit v1.2.3 From b08a2f2bbc8f615b778ec75e4b8f410626c52800 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 27 Mar 2013 11:50:40 +0100 Subject: [ADD] user defined action for goal update bzr revid: mat@openerp.com-20130327105040-ezlg1ml0xvoe5z58 --- addons/gamification/static/src/js/gamification.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 62de4835842..dfd8b2f607b 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -75,6 +75,7 @@ openerp.gamification = function(instance) { var self = this; self.dfm = new instance.web.form.DefaultFieldManager(self); + // Generate a FieldMonetary for each .oe_goal_field_monetary self.$el.find(".oe_goal_field_monetary").each(function() { money_field = new instance.web.form.FieldMonetary(self.dfm, { attrs: { @@ -84,9 +85,7 @@ openerp.gamification = function(instance) { money_field.set('currency', currency_id); money_field.get_currency_info(); money_field.set('value', parseInt($(this).text())); - console.log(money_field.get('value')); money_field.replace($(this)); - console.log(money_field.$el.html()); }); } }); -- cgit v1.2.3 From 84b2b3411ac27aafc15c55c0d6c0c76416375df4 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 29 Mar 2013 12:52:15 +0100 Subject: [IMP] render progressbar bzr revid: mat@openerp.com-20130329115215-bpm450x04kp0os9z --- addons/gamification/static/src/js/gamification.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index dfd8b2f607b..d415d35a890 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -68,6 +68,7 @@ openerp.gamification = function(instance) { self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do'); self.$el.find('.oe_type_description').hide(); self.render_money_fields(self.goals_info.info[0].currency); + self.render_progress_bars(); } }); }, @@ -87,6 +88,21 @@ openerp.gamification = function(instance) { money_field.set('value', parseInt($(this).text())); money_field.replace($(this)); }); + }, + render_progress_bars: function() { + var self = this; + + dfm = new instance.web.form.DefaultFieldManager(self); + // Generate a FieldMonetary for each .oe_goal_field_monetary + self.$el.find(".oe_goal_progress").each(function() { + progress_field = new instance.web.form.FieldProgressBar(dfm, { + attrs: { + modifiers: '{"readonly": true}' + } + }); + progress_field.set('value', $(this).attr('value')); + progress_field.replace($(this)); + }); } }); -- cgit v1.2.3 From 1c52d7e3b9c3f514f719e644feb8d7efd7371aa6 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 29 Mar 2013 16:45:35 +0100 Subject: [ADD] change avatar function bzr revid: mat@openerp.com-20130329154535-a6v8shsc3igv2wiy --- addons/gamification/static/src/js/gamification.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index d415d35a890..7f49f66785f 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -39,7 +39,9 @@ openerp.gamification = function(instance) { }); $.when(goal_action).done(function() { var action_manager = new instance.web.ActionManager(this); - action_manager.do_action(goal_action.action); + action_manager.do_action(goal_action.action).done(function () { + self.get_goal_todo_info(); + }); //var form = action_manager.dialog_widget.views.form.controller; }); -- cgit v1.2.3 From a3c3a07d3ab4f316e0c1a0842744cf2d55f5b7e2 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 2 Apr 2013 14:15:14 +0200 Subject: [IMP] better goals bzr revid: mat@openerp.com-20130402121514-thl9b43jnbu12tr0 --- addons/gamification/static/src/js/gamification.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 7f49f66785f..dcee68197ae 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -13,7 +13,7 @@ openerp.gamification = function(instance) { events: { 'click a.oe_update_goal': function(event) { var self = this; - var goal_id = parseInt(event.currentTarget.id); + var goal_id = parseInt(event.currentTarget.id, 10); var goal_updated = new instance.web.Model('gamification.goal').call('update', [[goal_id]]); $.when(goal_updated).done(function() { self.get_goal_todo_info(); @@ -21,7 +21,7 @@ openerp.gamification = function(instance) { }, 'click a.oe_update_plan': function(event) { var self = this; - var plan_id = parseInt(event.currentTarget.id); + var plan_id = parseInt(event.currentTarget.id, 10); var goals_updated = new instance.web.Model('gamification.goal.plan').call('quick_update', [plan_id]); $.when(goals_updated).done(function() { self.get_goal_todo_info(); @@ -33,7 +33,7 @@ openerp.gamification = function(instance) { // }, 'click a.oe_goal_action': function(event) { var self = this; - var goal_id = parseInt(event.currentTarget.id); + var goal_id = parseInt(event.currentTarget.id, 10); var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]).then(function(res) { goal_action['action'] = res; }); @@ -45,7 +45,7 @@ openerp.gamification = function(instance) { //var form = action_manager.dialog_widget.views.form.controller; }); - }, + } }, renderElement: function() { var self = this; @@ -63,7 +63,7 @@ openerp.gamification = function(instance) { get_goal_todo_info: function() { var self = this; var goals_info = this.res_user.call('get_goals_todo_info', {}).then(function(res) { - self.goals_info['info'] = res + self.goals_info['info'] = res; }); $.when(goals_info).done(function() { if(self.goals_info.info.length > 0){ @@ -87,7 +87,7 @@ openerp.gamification = function(instance) { }); money_field.set('currency', currency_id); money_field.get_currency_info(); - money_field.set('value', parseInt($(this).text())); + money_field.set('value', parseInt($(this).text(), 10)); money_field.replace($(this)); }); }, -- cgit v1.2.3 From 32b523c1d6f52bfb13eff396cf329074ad6bb654 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 8 Apr 2013 15:17:29 +0200 Subject: [IMP] better UI bzr revid: mat@openerp.com-20130408131729-lhlv0mhss502j9m1 --- addons/gamification/static/src/js/gamification.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index dcee68197ae..4aa456964c5 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -27,13 +27,10 @@ openerp.gamification = function(instance) { self.get_goal_todo_info(); }); }, - // 'click a.oe_show_description': function(event) { - // var goal_id = parseInt(event.currentTarget.id); - // this.$el.find('.oe_type_description_'+goal_id).toggle(10); - // }, 'click a.oe_goal_action': function(event) { var self = this; var goal_id = parseInt(event.currentTarget.id, 10); + console.log("oe_goal_action"); var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]).then(function(res) { goal_action['action'] = res; }); @@ -62,13 +59,13 @@ openerp.gamification = function(instance) { }, get_goal_todo_info: function() { var self = this; + console.log("get_goal_todo_info"); var goals_info = this.res_user.call('get_goals_todo_info', {}).then(function(res) { self.goals_info['info'] = res; }); $.when(goals_info).done(function() { if(self.goals_info.info.length > 0){ self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do'); - self.$el.find('.oe_type_description').hide(); self.render_money_fields(self.goals_info.info[0].currency); self.render_progress_bars(); } @@ -116,6 +113,7 @@ openerp.gamification = function(instance) { start: function() { this._super(); var self = this; + console.log("start"); var sidebar = new instance.gamification.Sidebar(self); sidebar.appendTo($('.oe_mail_wall_aside')); } -- cgit v1.2.3 From 0f2dad413b0d0cd3325c7b880bce10a2f6e4a5c4 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 9 Apr 2013 16:23:02 +0200 Subject: [ADD] use gauge for kanbans bzr revid: mat@openerp.com-20130409142302-lsyye6g5cfl3wa90 --- addons/gamification/static/src/js/gamification.js | 36 +- addons/gamification/static/src/js/justgage.js | 885 ++++++++++++++++++++++ 2 files changed, 918 insertions(+), 3 deletions(-) create mode 100644 addons/gamification/static/src/js/justgage.js (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 4aa456964c5..34acb568026 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -30,7 +30,6 @@ openerp.gamification = function(instance) { 'click a.oe_goal_action': function(event) { var self = this; var goal_id = parseInt(event.currentTarget.id, 10); - console.log("oe_goal_action"); var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]).then(function(res) { goal_action['action'] = res; }); @@ -59,7 +58,6 @@ openerp.gamification = function(instance) { }, get_goal_todo_info: function() { var self = this; - console.log("get_goal_todo_info"); var goals_info = this.res_user.call('get_goals_todo_info', {}).then(function(res) { self.goals_info['info'] = res; }); @@ -113,9 +111,41 @@ openerp.gamification = function(instance) { start: function() { this._super(); var self = this; - console.log("start"); var sidebar = new instance.gamification.Sidebar(self); sidebar.appendTo($('.oe_mail_wall_aside')); } }); + + instance.web_kanban.KanbanRecord.include({ + start: function () { + var rendering = this._super(); + var self = this; + + $.when(rendering).done(function() { + if (self.view.dataset.model === 'gamification.goal' && self.$el.find('.oe_goal_gauge').length == 1) { + var unique_id = _.uniqueId("goal_gauge_"); + self.$el.find('.oe_goal_gauge').attr('id', unique_id); + console.log(self.$el.find('.oe_goal_gauge').empty().get(0)); + // debugger; + var g = new JustGage({ + id: unique_id, + node: self.$el.find('.oe_goal_gauge').empty().get(0), + value: self.record.current.raw_value, + min: 0, + max: self.record.target_goal.raw_value, + title: self.record.type_id.value, + relativeGaugeSize: true + }); + console.log(g); + } + }); + }, + on_card_clicked: function() { + if (this.view.dataset.model === 'gamification.goal.plan') { + this.$('.oe_kanban_project_list a').first().click(); + } else { + this._super.apply(this, arguments); + } + } + }); }; diff --git a/addons/gamification/static/src/js/justgage.js b/addons/gamification/static/src/js/justgage.js new file mode 100644 index 00000000000..b83e5cbdb1e --- /dev/null +++ b/addons/gamification/static/src/js/justgage.js @@ -0,0 +1,885 @@ +/** + * JustGage - this is work-in-progress, unreleased, unofficial code, so it might not work top-notch :) + * Check http://www.justgage.com for official releases + * Licensed under MIT. + * @author Bojan Djuricic (@Toorshia) + * + * LATEST UPDATES + + * ----------------------------- + * April 01, 2013. + * ----------------------------- + * fix - https://github.com/toorshia/justgage/issues/46 + + * ----------------------------- + * March 26, 2013. + * ----------------------------- + * customSectors - define specific color for value range (0-10 : red, 10-30 : blue etc.) + + * ----------------------------- + * March 23, 2013. + * ----------------------------- + * counter - option to animate value in counting fashion + * fix - https://github.com/toorshia/justgage/issues/45 + + * ----------------------------- + * March 13, 2013. + * ----------------------------- + * refresh method - added optional 'max' parameter to use when you need to update max value + + * ----------------------------- + * February 26, 2013. + * ----------------------------- + * decimals - option to define/limit number of decimals when not using humanFriendly or customRenderer to display value + * fixed a missing parameters bug when calling generateShadow() for IE < 9 + + * ----------------------------- + * December 31, 2012. + * ----------------------------- + * fixed text y-position for hidden divs - workaround for Raphael 'dy' bug - https://github.com/DmitryBaranovskiy/raphael/issues/491 + * 'show' parameters, like showMinMax are now 'hide' because I am lame developer - please update these in your setups + * Min and Max labels are now auto-off when in donut mode + * Start angle in donut mode is now 90 + * donutStartAngle - option to define start angle for donut + + * ----------------------------- + * November 25, 2012. + * ----------------------------- + * Option to define custom rendering function for displayed value + + * ----------------------------- + * November 19, 2012. + * ----------------------------- + * Config.value is now updated after gauge refresh + + * ----------------------------- + * November 13, 2012. + * ----------------------------- + * Donut display mode added + * Option to hide value label + * Option to enable responsive gauge size + * Removed default title attribute + * Option to accept min and max defined as string values + * Option to configure value symbol + * Fixed bad aspect ratio calculations + * Option to configure minimum font size for all texts + * Option to show shorthand big numbers (human friendly) + */ + + JustGage = function(config) { + + if (!config.id) {alert("Missing id parameter for gauge!"); return false;} + if (!config.node) { + if (!document.getElementById(config.id)) {alert("No element with id: \""+config.id+"\" found!"); return false;} + config.node = document.getElementById(config.id); + } + + var obj = this; + + // configurable parameters + obj.config = + { + // id : string + // this is container element id + id : config.id, + + // node : string + // the node to use instead of DOM + node : config.node, + + // title : string + // gauge title + title : (config.title) ? config.title : "", + + // titleFontColor : string + // color of gauge title + titleFontColor : (config.titleFontColor) ? config.titleFontColor : "#999999", + + // value : int + // value gauge is showing + value : (config.value) ? config.value : 0, + + + // valueFontColor : string + // color of label showing current value + valueFontColor : (config.valueFontColor) ? config.valueFontColor : "#010101", + + // symbol : string + // special symbol to show next to value + symbol : (config.symbol) ? config.symbol : "", + + // min : int + // min value + min : (config.min) ? parseFloat(config.min) : 0, + + // max : int + // max value + max : (config.max) ? parseFloat(config.max) : 100, + + // humanFriendlyDecimal : int + // number of decimal places for our human friendly number to contain + humanFriendlyDecimal : (config.humanFriendlyDecimal) ? config.humanFriendlyDecimal : 0, + + // textRenderer: func + // function applied before rendering text + textRenderer : (config.textRenderer) ? config.textRenderer : null, + + // gaugeWidthScale : float + // width of the gauge element + gaugeWidthScale : (config.gaugeWidthScale) ? config.gaugeWidthScale : 1.0, + + // gaugeColor : string + // background color of gauge element + gaugeColor : (config.gaugeColor) ? config.gaugeColor : "#edebeb", + + // label : string + // text to show below value + label : (config.label) ? config.label : "", + + // labelFontColor : string + // color of label showing label under value + labelFontColor : (config.labelFontColor) ? config.labelFontColor : "#b3b3b3", + + // shadowOpacity : int + // 0 ~ 1 + shadowOpacity : (config.shadowOpacity) ? config.shadowOpacity : 0.2, + + // shadowSize: int + // inner shadow size + shadowSize : (config.shadowSize) ? config.shadowSize : 5, + + // shadowVerticalOffset : int + // how much shadow is offset from top + shadowVerticalOffset : (config.shadowVerticalOffset) ? config.shadowVerticalOffset : 3, + + // levelColors : string[] + // colors of indicator, from lower to upper, in RGB format + levelColors : (config.levelColors) ? config.levelColors : [ + "#a9d70b", + "#f9c802", + "#ff0000" + ], + + // startAnimationTime : int + // length of initial animation + startAnimationTime : (config.startAnimationTime) ? config.startAnimationTime : 700, + + // startAnimationType : string + // type of initial animation (linear, >, <, <>, bounce) + startAnimationType : (config.startAnimationType) ? config.startAnimationType : ">", + + // refreshAnimationTime : int + // length of refresh animation + refreshAnimationTime : (config.refreshAnimationTime) ? config.refreshAnimationTime : 700, + + // refreshAnimationType : string + // type of refresh animation (linear, >, <, <>, bounce) + refreshAnimationType : (config.refreshAnimationType) ? config.refreshAnimationType : ">", + + // donutStartAngle : int + // angle to start from when in donut mode + donutStartAngle : (config.donutStartAngle) ? config.donutStartAngle : 90, + + // valueMinFontSize : int + // absolute minimum font size for the value + valueMinFontSize : config.valueMinFontSize || 16, + + // titleMinFontSize + // absolute minimum font size for the title + titleMinFontSize : config.titleMinFontSize || 10, + + // labelMinFontSize + // absolute minimum font size for the label + labelMinFontSize : config.labelMinFontSize || 10, + + // minLabelMinFontSize + // absolute minimum font size for the minimum label + minLabelMinFontSize : config.minLabelMinFontSize || 10, + + // maxLabelMinFontSize + // absolute minimum font size for the maximum label + maxLabelMinFontSize : config.maxLabelMinFontSize || 10, + + // hideValue : bool + // hide value text + hideValue : (config.hideValue) ? config.hideValue : false, + + // hideMinMax : bool + // hide min and max values + hideMinMax : (config.hideMinMax) ? config.hideMinMax : false, + + // hideInnerShadow : bool + // hide inner shadow + hideInnerShadow : (config.hideInnerShadow) ? config.hideInnerShadow : false, + + // humanFriendly : bool + // convert large numbers for min, max, value to human friendly (e.g. 1234567 -> 1.23M) + humanFriendly : (config.humanFriendly) ? config.humanFriendly : false, + + // noGradient : bool + // whether to use gradual color change for value, or sector-based + noGradient : (config.noGradient) ? config.noGradient : false, + + // donut : bool + // show full donut gauge + donut : (config.donut) ? config.donut : false, + + // relativeGaugeSize : bool + // whether gauge size should follow changes in container element size + relativeGaugeSize : (config.relativeGaugeSize) ? config.relativeGaugeSize : false, + + // counter : bool + // animate level number change + counter : (config.counter) ? config.counter : false, + + // decimals : int + // number of digits after floating point + decimals : (config.decimals) ? config.decimals : 0, + + // customSectors : [] of objects + // number of digits after floating point + customSectors : (config.customSectors) ? config.customSectors : [] + }; + + // variables + var + canvasW, + canvasH, + widgetW, + widgetH, + aspect, + dx, + dy, + titleFontSize, + titleX, + titleY, + valueFontSize, + valueX, + valueY, + labelFontSize, + labelX, + labelY, + minFontSize, + minX, + minY, + maxFontSize, + maxX, + maxY; + + // overflow values + if (this.config.value > this.config.max) this.config.value = this.config.max; + if (this.config.value < this.config.min) this.config.value = this.config.min; + this.originalValue = config.value; + + // canvas + this.canvas = Raphael(this.config.node, "100%", "100%"); + if (this.config.relativeGaugeSize === true) { + this.canvas.setViewBox(0, 0, 200, 150, true); + } + + // canvas dimensions + if (this.config.relativeGaugeSize === true) { + canvasW = 200; + canvasH = 150; + } else { + canvasW = getStyle(this.config.node, "width").slice(0, -2) * 1; + canvasH = getStyle(this.config.node, "height").slice(0, -2) * 1; + } + + // widget dimensions + if (this.config.donut === true) { + + // DONUT ******************************* + + // width more than height + if(canvasW > canvasH) { + widgetH = canvasH; + widgetW = widgetH; + // width less than height + } else if (canvasW < canvasH) { + widgetW = canvasW; + widgetH = widgetW; + // if height don't fit, rescale both + if(widgetH > canvasH) { + aspect = widgetH / canvasH; + widgetH = widgetH / aspect; + widgetW = widgetH / aspect; + } + // equal + } else { + widgetW = canvasW; + widgetH = widgetW; + } + + // delta + dx = (canvasW - widgetW)/2; + dy = (canvasH - widgetH)/2; + + // title + titleFontSize = ((widgetH / 8) > 10) ? (widgetH / 10) : 10; + titleX = dx + widgetW / 2; + titleY = dy + widgetH / 11; + + // value + valueFontSize = ((widgetH / 6.4) > 16) ? (widgetH / 5.4) : 18; + valueX = dx + widgetW / 2; + if(this.config.label !== '') { + valueY = dy + widgetH / 1.85; + } else { + valueY = dy + widgetH / 1.7; + } + + // label + labelFontSize = ((widgetH / 16) > 10) ? (widgetH / 16) : 10; + labelX = dx + widgetW / 2; + labelY = valueY + labelFontSize; + + // min + minFontSize = ((widgetH / 16) > 10) ? (widgetH / 16) : 10; + minX = dx + (widgetW / 10) + (widgetW / 6.666666666666667 * this.config.gaugeWidthScale) / 2 ; + minY = labelY; + + // max + maxFontSize = ((widgetH / 16) > 10) ? (widgetH / 16) : 10; + maxX = dx + widgetW - (widgetW / 10) - (widgetW / 6.666666666666667 * this.config.gaugeWidthScale) / 2 ; + maxY = labelY; + + } else { + // HALF ******************************* + + // width more than height + if(canvasW > canvasH) { + widgetH = canvasH; + widgetW = widgetH * 1.25; + //if width doesn't fit, rescale both + if(widgetW > canvasW) { + aspect = widgetW / canvasW; + widgetW = widgetW / aspect; + widgetH = widgetH / aspect; + } + // width less than height + } else if (canvasW < canvasH) { + widgetW = canvasW; + widgetH = widgetW / 1.25; + // if height don't fit, rescale both + if(widgetH > canvasH) { + aspect = widgetH / canvasH; + widgetH = widgetH / aspect; + widgetW = widgetH / aspect; + } + // equal + } else { + widgetW = canvasW; + widgetH = widgetW * 0.75; + } + + // delta + dx = (canvasW - widgetW)/2; + dy = (canvasH - widgetH)/2; + + // title + titleFontSize = ((widgetH / 8) > this.config.titleMinFontSize) ? (widgetH / 10) : this.config.titleMinFontSize; + titleX = dx + widgetW / 2; + titleY = dy + widgetH / 6.4; + + // value + valueFontSize = ((widgetH / 6.5) > this.config.valueMinFontSize) ? (widgetH / 6.5) : this.config.valueMinFontSize; + valueX = dx + widgetW / 2; + valueY = dy + widgetH / 1.275; + + // label + labelFontSize = ((widgetH / 16) > this.config.labelMinFontSize) ? (widgetH / 16) : this.config.labelMinFontSize; + labelX = dx + widgetW / 2; + labelY = valueY + valueFontSize / 2 + 5; + + // min + minFontSize = ((widgetH / 16) > this.config.minLabelMinFontSize) ? (widgetH / 16) : this.config.minLabelMinFontSize; + minX = dx + (widgetW / 10) + (widgetW / 6.666666666666667 * this.config.gaugeWidthScale) / 2 ; + minY = labelY; + + // max + maxFontSize = ((widgetH / 16) > this.config.maxLabelMinFontSize) ? (widgetH / 16) : this.config.maxLabelMinFontSize; + maxX = dx + widgetW - (widgetW / 10) - (widgetW / 6.666666666666667 * this.config.gaugeWidthScale) / 2 ; + maxY = labelY; + } + + // parameters + this.params = { + canvasW : canvasW, + canvasH : canvasH, + widgetW : widgetW, + widgetH : widgetH, + dx : dx, + dy : dy, + titleFontSize : titleFontSize, + titleX : titleX, + titleY : titleY, + valueFontSize : valueFontSize, + valueX : valueX, + valueY : valueY, + labelFontSize : labelFontSize, + labelX : labelX, + labelY : labelY, + minFontSize : minFontSize, + minX : minX, + minY : minY, + maxFontSize : maxFontSize, + maxX : maxX, + maxY : maxY + }; + + // var clear + canvasW, canvasH, widgetW, widgetH, aspect, dx, dy, titleFontSize, titleX, titleY, valueFontSize, valueX, valueY, labelFontSize, labelX, labelY, minFontSize, minX, minY, maxFontSize, maxX, maxY = null + + // pki - custom attribute for generating gauge paths + this.canvas.customAttributes.pki = function (value, min, max, w, h, dx, dy, gws, donut) { + + var alpha, Ro, Ri, Cx, Cy, Xo, Yo, Xi, Yi, path; + + if (donut) { + alpha = (1 - 2 * (value - min) / (max - min)) * Math.PI; + Ro = w / 2 - w / 7; + Ri = Ro - w / 6.666666666666667 * gws; + + Cx = w / 2 + dx; + Cy = h / 1.95 + dy; + + Xo = w / 2 + dx + Ro * Math.cos(alpha); + Yo = h - (h - Cy) + 0 - Ro * Math.sin(alpha); + Xi = w / 2 + dx + Ri * Math.cos(alpha); + Yi = h - (h - Cy) + 0 - Ri * Math.sin(alpha); + + path += "M" + (Cx - Ri) + "," + Cy + " "; + path += "L" + (Cx - Ro) + "," + Cy + " "; + if (value > ((max - min) / 2)) { + path += "A" + Ro + "," + Ro + " 0 0 1 " + (Cx + Ro) + "," + Cy + " "; + } + path += "A" + Ro + "," + Ro + " 0 0 1 " + Xo + "," + Yo + " "; + path += "L" + Xi + "," + Yi + " "; + if (value > ((max - min) / 2)) { + path += "A" + Ri + "," + Ri + " 0 0 0 " + (Cx + Ri) + "," + Cy + " "; + } + path += "A" + Ri + "," + Ri + " 0 0 0 " + (Cx - Ri) + "," + Cy + " "; + path += "Z "; + + return { path: path }; + + } else { + alpha = (1 - (value - min) / (max - min)) * Math.PI; + Ro = w / 2 - w / 10; + Ri = Ro - w / 6.666666666666667 * gws; + + Cx = w / 2 + dx; + Cy = h / 1.25 + dy; + + Xo = w / 2 + dx + Ro * Math.cos(alpha); + Yo = h - (h - Cy) + 0 - Ro * Math.sin(alpha); + Xi = w / 2 + dx + Ri * Math.cos(alpha); + Yi = h - (h - Cy) + 0 - Ri * Math.sin(alpha); + + path += "M" + (Cx - Ri) + "," + Cy + " "; + path += "L" + (Cx - Ro) + "," + Cy + " "; + path += "A" + Ro + "," + Ro + " 0 0 1 " + Xo + "," + Yo + " "; + path += "L" + Xi + "," + Yi + " "; + path += "A" + Ri + "," + Ri + " 0 0 0 " + (Cx - Ri) + "," + Cy + " "; + path += "Z "; + + return { path: path }; + } + + // var clear + alpha, Ro, Ri, Cx, Cy, Xo, Yo, Xi, Yi, path = null; + }; + + // gauge + this.gauge = this.canvas.path().attr({ + "stroke": "none", + "fill": this.config.gaugeColor, + pki: [this.config.max, this.config.min, this.config.max, this.params.widgetW, this.params.widgetH, this.params.dx, this.params.dy, this.config.gaugeWidthScale, this.config.donut] + }); + this.gauge.id = this.config.id+"-gauge"; + + // level + this.level = this.canvas.path().attr({ + "stroke": "none", + "fill": getColor(this.config.value, (this.config.value - this.config.min) / (this.config.max - this.config.min), this.config.levelColors, this.config.noGradient, this.config.customSectors), + pki: [this.config.min, this.config.min, this.config.max, this.params.widgetW, this.params.widgetH, this.params.dx, this.params.dy, this.config.gaugeWidthScale, this.config.donut] + }); + if(this.config.donut) { + this.level.transform("r" + this.config.donutStartAngle + ", " + (this.params.widgetW/2 + this.params.dx) + ", " + (this.params.widgetH/1.95 + this.params.dy)); + } + this.level.id = this.config.id+"-level"; + + // title + this.txtTitle = this.canvas.text(this.params.titleX, this.params.titleY, this.config.title); + this.txtTitle.attr({ + "font-size":this.params.titleFontSize, + "font-weight":"bold", + "font-family":"Arial", + "fill":this.config.titleFontColor, + "fill-opacity":"1" + }); + setDy(this.txtTitle, this.params.titleFontSize, this.params.titleY); + this.txtTitle.id = this.config.id+"-txttitle"; + + // value + this.txtValue = this.canvas.text(this.params.valueX, this.params.valueY, 0); + this.txtValue.attr({ + "font-size":this.params.valueFontSize, + "font-weight":"bold", + "font-family":"Arial", + "fill":this.config.valueFontColor, + "fill-opacity":"0" + }); + setDy(this.txtValue, this.params.valueFontSize, this.params.valueY); + this.txtValue.id = this.config.id+"-txtvalue"; + + // label + this.txtLabel = this.canvas.text(this.params.labelX, this.params.labelY, this.config.label); + this.txtLabel.attr({ + "font-size":this.params.labelFontSize, + "font-weight":"normal", + "font-family":"Arial", + "fill":this.config.labelFontColor, + "fill-opacity":"0" + }); + setDy(this.txtLabel, this.params.labelFontSize, this.params.labelY); + this.txtLabel.id = this.config.id+"-txtlabel"; + + // min + this.txtMinimum = this.config.min; + if( this.config.humanFriendly ) this.txtMinimum = humanFriendlyNumber( this.config.min, this.config.humanFriendlyDecimal ); + this.txtMin = this.canvas.text(this.params.minX, this.params.minY, this.txtMinimum); + this.txtMin.attr({ + "font-size":this.params.minFontSize, + "font-weight":"normal", + "font-family":"Arial", + "fill":this.config.labelFontColor, + "fill-opacity": (this.config.hideMinMax || this.config.donut)? "0" : "1" + }); + setDy(this.txtMin, this.params.minFontSize, this.params.minY); + this.txtMin.id = this.config.id+"-txtmin"; + + // max + this.txtMaximum = this.config.max; + if( this.config.humanFriendly ) this.txtMaximum = humanFriendlyNumber( this.config.max, this.config.humanFriendlyDecimal ); + this.txtMax = this.canvas.text(this.params.maxX, this.params.maxY, this.txtMaximum); + this.txtMax.attr({ + "font-size":this.params.maxFontSize, + "font-weight":"normal", + "font-family":"Arial", + "fill":this.config.labelFontColor, + "fill-opacity": (this.config.hideMinMax || this.config.donut)? "0" : "1" + }); + setDy(this.txtMax, this.params.maxFontSize, this.params.maxY); + this.txtMax.id = this.config.id+"-txtmax"; + + var defs = this.canvas.canvas.childNodes[1]; + var svg = "http://www.w3.org/2000/svg"; + + if (ie < 9) { + onCreateElementNsReady(function() { + this.generateShadow(svg, defs); + }); + } else { + this.generateShadow(svg, defs); + } + + // var clear + defs, svg = null; + + // execute on each animation frame + function onAnimate() { + if (obj.config.counter) { + var currentValue = obj.level.attr("pki"); + + if(obj.config.textRenderer) { + // this.originalValue = this.config.textRenderer(this.originalValue); + obj.txtValue.attr("text", obj.config.textRenderer(Math.floor(currentValue[0]))); + } else if(obj.config.humanFriendly) { + // this.originalValue = humanFriendlyNumber( this.originalValue, this.config.humanFriendlyDecimal ) + this.config.symbol; + obj.txtValue.attr("text", humanFriendlyNumber( Math.floor(currentValue[0]), obj.config.humanFriendlyDecimal ) + obj.config.symbol); + } else { + // this.originalValue += this.config.symbol; + obj.txtValue.attr("text", (currentValue[0] * 1).toFixed(obj.config.decimals) + obj.config.symbol); + } + + setDy(obj.txtValue, obj.params.valueFontSize, obj.params.valueY); + currentValue = null; + } + } + + if(!obj.config.counter) { + if(obj.config.textRenderer) { + obj.originalValue = obj.config.textRenderer(obj.originalValue); + } else if(obj.config.humanFriendly) { + obj.originalValue = humanFriendlyNumber( obj.originalValue, obj.config.humanFriendlyDecimal ) + obj.config.symbol; + } else { + obj.originalValue = (obj.originalValue * 1).toFixed(obj.config.decimals); + } + + obj.txtValue.attr("text", obj.originalValue + obj.config.symbol); + setDy(obj.txtValue, obj.params.valueFontSize, obj.params.valueY); + } + + //event fired on each animation frame + eve.on("raphael.anim.frame.*", onAnimate); + + // animate gauge level + this.level.animate({pki: [this.config.value, this.config.min, this.config.max, this.params.widgetW, this.params.widgetH, this.params.dx, this.params.dy, this.config.gaugeWidthScale, this.config.donut]}, this.config.startAnimationTime, this.config.startAnimationType); + + // animate value + this.txtValue.animate({"fill-opacity":"1"}, this.config.startAnimationTime, this.config.startAnimationType); + + // animate label + this.txtLabel.animate({"fill-opacity":"1"}, this.config.startAnimationTime, this.config.startAnimationType); +}; + +/** Refresh gauge level */ +JustGage.prototype.refresh = function(val, max) { + + var originalVal, displayVal, color, max = max || null; + + // set new max + if(max !== null) { + this.config.max = max; + + this.txtMaximum = this.config.max; + if( this.config.humanFriendly ) this.txtMaximum = humanFriendlyNumber( this.config.max, this.config.humanFriendlyDecimal ); + this.txtMax.attr({"text" : this.config.max}); + setDy(this.txtMax, this.params.maxFontSize, this.params.maxY); + } + + // overflow values + originalVal = val; + displayVal = val; + if ((val * 1) > (this.config.max * 1)) {val = (this.config.max * 1);} + if ((val * 1) < (this.config.min * 1)) {val = (this.config.min * 1);} + + color = getColor(val, (val - this.config.min) / (this.config.max - this.config.min), this.config.levelColors, this.config.noGradient, this.config.customSectors); + + if(this.config.textRenderer) { + displayVal = this.config.textRenderer(displayVal); + } else if( this.config.humanFriendly ) { + displayVal = humanFriendlyNumber( displayVal, this.config.humanFriendlyDecimal ) + this.config.symbol; + } else { + displayVal = (displayVal * 1).toFixed(this.config.decimals) + this.config.symbol; + } + + if(!this.config.counter) { + this.canvas.getById(this.config.id+"-txtvalue").attr({"text":displayVal}); + setDy(this.canvas.getById(this.config.id+"-txtvalue"), this.params.valueFontSize, this.params.valueY); + } + + this.canvas.getById(this.config.id+"-level").animate({pki: [val, this.config.min, this.config.max, this.params.widgetW, this.params.widgetH, this.params.dx, this.params.dy, this.config.gaugeWidthScale, this.config.donut], "fill":color}, this.config.refreshAnimationTime, this.config.refreshAnimationType); + this.config.value = val * 1; + + // var clear + originalVal, displayVal, color, max = null; +}; + +/** Generate shadow */ +JustGage.prototype.generateShadow = function(svg, defs) { + + var gaussFilter, feOffset, feGaussianBlur, feComposite1, feFlood, feComposite2, feComposite3; + + // FILTER + gaussFilter=document.createElementNS(svg,"filter"); + gaussFilter.setAttribute("id", this.config.id + "-inner-shadow"); + defs.appendChild(gaussFilter); + + // offset + feOffset = document.createElementNS(svg,"feOffset"); + feOffset.setAttribute("dx", 0); + feOffset.setAttribute("dy", this.config.shadowVerticalOffset); + gaussFilter.appendChild(feOffset); + + // blur + feGaussianBlur = document.createElementNS(svg,"feGaussianBlur"); + feGaussianBlur.setAttribute("result","offset-blur"); + feGaussianBlur.setAttribute("stdDeviation", this.config.shadowSize); + gaussFilter.appendChild(feGaussianBlur); + + // composite 1 + feComposite1 = document.createElementNS(svg,"feComposite"); + feComposite1.setAttribute("operator","out"); + feComposite1.setAttribute("in", "SourceGraphic"); + feComposite1.setAttribute("in2","offset-blur"); + feComposite1.setAttribute("result","inverse"); + gaussFilter.appendChild(feComposite1); + + // flood + feFlood = document.createElementNS(svg,"feFlood"); + feFlood.setAttribute("flood-color","black"); + feFlood.setAttribute("flood-opacity", this.config.shadowOpacity); + feFlood.setAttribute("result","color"); + gaussFilter.appendChild(feFlood); + + // composite 2 + feComposite2 = document.createElementNS(svg,"feComposite"); + feComposite2.setAttribute("operator","in"); + feComposite2.setAttribute("in", "color"); + feComposite2.setAttribute("in2","inverse"); + feComposite2.setAttribute("result","shadow"); + gaussFilter.appendChild(feComposite2); + + // composite 3 + feComposite3 = document.createElementNS(svg,"feComposite"); + feComposite3.setAttribute("operator","over"); + feComposite3.setAttribute("in", "shadow"); + feComposite3.setAttribute("in2","SourceGraphic"); + gaussFilter.appendChild(feComposite3); + + // set shadow + if (!this.config.hideInnerShadow) { + this.canvas.canvas.childNodes[2].setAttribute("filter", "url(#" + this.config.id + "-inner-shadow)"); + this.canvas.canvas.childNodes[3].setAttribute("filter", "url(#" + this.config.id + "-inner-shadow)"); + } + + // var clear + gaussFilter, feOffset, feGaussianBlur, feComposite1, feFlood, feComposite2, feComposite3 = null; + +}; + +/** Get color for value */ +function getColor(val, pct, col, noGradient, custSec) { + + var no, inc, colors, percentage, rval, gval, bval, lower, upper, range, rangePct, pctLower, pctUpper, color; + var noGradient = noGradient || custSec.length > 0; + + if(custSec.length > 0) { + for(var i = 0; i < custSec.length; i++) { + if(val > custSec[i].lo && val <= custSec[i].hi) { + return custSec[i].color; + } + } + } + + no = col.length; + if (no === 1) return col[0]; + inc = (noGradient) ? (1 / no) : (1 / (no - 1)); + colors = []; + for (var i = 0; i < col.length; i++) { + percentage = (noGradient) ? (inc * (i + 1)) : (inc * i); + rval = parseInt((cutHex(col[i])).substring(0,2),16); + gval = parseInt((cutHex(col[i])).substring(2,4),16); + bval = parseInt((cutHex(col[i])).substring(4,6),16); + colors[i] = { pct: percentage, color: { r: rval, g: gval, b: bval } }; + } + + if(pct === 0) { + return 'rgb(' + [colors[0].color.r, colors[0].color.g, colors[0].color.b].join(',') + ')'; + } + + for (var j = 0; j < colors.length; j++) { + if (pct <= colors[j].pct) { + if (noGradient) { + return 'rgb(' + [colors[j].color.r, colors[j].color.g, colors[j].color.b].join(',') + ')'; + } else { + lower = colors[j - 1]; + upper = colors[j]; + range = upper.pct - lower.pct; + rangePct = (pct - lower.pct) / range; + pctLower = 1 - rangePct; + pctUpper = rangePct; + color = { + r: Math.floor(lower.color.r * pctLower + upper.color.r * pctUpper), + g: Math.floor(lower.color.g * pctLower + upper.color.g * pctUpper), + b: Math.floor(lower.color.b * pctLower + upper.color.b * pctUpper) + }; + return 'rgb(' + [color.r, color.g, color.b].join(',') + ')'; + } + } + } + +} + +/** Fix Raphael display:none tspan dy attribute bug */ +function setDy(elem, fontSize, txtYpos) { + if ((!ie || ie > 9) && (elem.node.firstChild.attributes.dy)) { + elem.node.firstChild.attributes.dy.value = 0; + } +} + +/** Random integer */ +function getRandomInt (min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +/** Cut hex */ +function cutHex(str) { + return (str.charAt(0)=="#") ? str.substring(1,7):str; +} + +/** Human friendly number suffix - From: http://stackoverflow.com/questions/2692323/code-golf-friendly-number-abbreviator */ +function humanFriendlyNumber( n, d ) { + var p, d2, i, s; + + p = Math.pow; + d2 = p(10, d); + i = 7; + while( i ) { + s = p(10,i--*3); + if( s <= n ) { + n = Math.round(n*d2/s)/d2+"KMGTPE"[i]; + } + } + return n; +} + +/** Get style */ +function getStyle(oElm, strCssRule){ + var strValue = ""; + if(document.defaultView && document.defaultView.getComputedStyle){ + console.log(oElm); + strValue = document.defaultView.getComputedStyle(oElm).getPropertyValue(strCssRule); + console.log(strValue, strCssRule); + } + else if(oElm.currentStyle){ + strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ + return p1.toUpperCase(); + }); + strValue = oElm.currentStyle[strCssRule]; + } + return strValue; +} + +/** Create Element NS Ready */ +function onCreateElementNsReady(func) { + if (document.createElementNS !== undefined) { + func(); + } else { + setTimeout(function() { onCreateElementNsReady(func); }, 100); + } +} + +/** Get IE version */ +// ---------------------------------------------------------- +// A short snippet for detecting versions of IE in JavaScript +// without resorting to user-agent sniffing +// ---------------------------------------------------------- +// If you're not in IE (or IE version is less than 5) then: +// ie === undefined +// If you're in IE (>=5) then you can determine which version: +// ie === 7; // IE7 +// Thus, to detect IE: +// if (ie) {} +// And to detect the version: +// ie === 6 // IE6 +// ie > 7 // IE8, IE9 ... +// ie < 9 // Anything less than IE9 +// ---------------------------------------------------------- +// UPDATE: Now using Live NodeList idea from @jdalton +var ie = (function(){ + + var undef, + v = 3, + div = document.createElement('div'), + all = div.getElementsByTagName('i'); + + while ( + div.innerHTML = '', + all[0] + ); + return v > 4 ? v : undef; +}()); \ No newline at end of file -- cgit v1.2.3 From 5fe85f22782127e2f090d350353624b5ce22d386 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 9 Apr 2013 16:40:30 +0200 Subject: [IMP] better UI bzr revid: mat@openerp.com-20130409144030-rb609qteloq3vrgf --- addons/gamification/static/src/js/gamification.js | 11 +++++++---- addons/gamification/static/src/js/justgage.js | 2 -- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 34acb568026..220f69cdfd2 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -125,8 +125,7 @@ openerp.gamification = function(instance) { if (self.view.dataset.model === 'gamification.goal' && self.$el.find('.oe_goal_gauge').length == 1) { var unique_id = _.uniqueId("goal_gauge_"); self.$el.find('.oe_goal_gauge').attr('id', unique_id); - console.log(self.$el.find('.oe_goal_gauge').empty().get(0)); - // debugger; + var g = new JustGage({ id: unique_id, node: self.$el.find('.oe_goal_gauge').empty().get(0), @@ -134,9 +133,13 @@ openerp.gamification = function(instance) { min: 0, max: self.record.target_goal.raw_value, title: self.record.type_id.value, - relativeGaugeSize: true + relativeGaugeSize: true, + levelColors: [ + "#f9c802", + "#ff0000", + "#a9d70b" + ] }); - console.log(g); } }); }, diff --git a/addons/gamification/static/src/js/justgage.js b/addons/gamification/static/src/js/justgage.js index b83e5cbdb1e..7464e4120e1 100644 --- a/addons/gamification/static/src/js/justgage.js +++ b/addons/gamification/static/src/js/justgage.js @@ -831,9 +831,7 @@ function humanFriendlyNumber( n, d ) { function getStyle(oElm, strCssRule){ var strValue = ""; if(document.defaultView && document.defaultView.getComputedStyle){ - console.log(oElm); strValue = document.defaultView.getComputedStyle(oElm).getPropertyValue(strCssRule); - console.log(strValue, strCssRule); } else if(oElm.currentStyle){ strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ -- cgit v1.2.3 From f70b0017f63fa9baef330e05e67517d2127e798e Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 10 Apr 2013 12:14:54 +0200 Subject: [IMP] fixing and UI bzr revid: mat@openerp.com-20130410101454-nkt8mbt8qb13zrge --- addons/gamification/static/src/js/gamification.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 220f69cdfd2..87550914ecc 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -125,14 +125,14 @@ openerp.gamification = function(instance) { if (self.view.dataset.model === 'gamification.goal' && self.$el.find('.oe_goal_gauge').length == 1) { var unique_id = _.uniqueId("goal_gauge_"); self.$el.find('.oe_goal_gauge').attr('id', unique_id); - + console.log(self.record); var g = new JustGage({ id: unique_id, node: self.$el.find('.oe_goal_gauge').empty().get(0), value: self.record.current.raw_value, min: 0, max: self.record.target_goal.raw_value, - title: self.record.type_id.value, + // title: self.record.type_id.value, relativeGaugeSize: true, levelColors: [ "#f9c802", -- cgit v1.2.3 From 1e9805fbfd0936cd228fb7177cc8519d2554432f Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 10 Apr 2013 17:30:31 +0200 Subject: [IMP] use suffix in kanban and better view bzr revid: mat@openerp.com-20130410153031-s6op7d7wyfdzrcti --- addons/gamification/static/src/js/gamification.js | 17 +++++++++++++---- addons/gamification/static/src/js/justgage.js | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 87550914ecc..c743d39282a 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -38,8 +38,6 @@ openerp.gamification = function(instance) { action_manager.do_action(goal_action.action).done(function () { self.get_goal_todo_info(); }); - - //var form = action_manager.dialog_widget.views.form.controller; }); } }, @@ -132,13 +130,24 @@ openerp.gamification = function(instance) { value: self.record.current.raw_value, min: 0, max: self.record.target_goal.raw_value, - // title: self.record.type_id.value, relativeGaugeSize: true, + humanFriendly: true, + // add space between value and symbol + // textRenderer: function(value) { + // symbol = self.record.type_suffix.raw_value; + // humannbr = humanFriendlyNumber(value, 0) + // if ((humannbr + symbol).length > 6) { + // return humannbr; + // } else { + // return humannbr + " " + symbol; + // } + // }, + label: self.record.type_suffix.raw_value, levelColors: [ "#f9c802", "#ff0000", "#a9d70b" - ] + ], }); } }); diff --git a/addons/gamification/static/src/js/justgage.js b/addons/gamification/static/src/js/justgage.js index 7464e4120e1..52b5c6ea0c3 100644 --- a/addons/gamification/static/src/js/justgage.js +++ b/addons/gamification/static/src/js/justgage.js @@ -615,10 +615,10 @@ } else if(obj.config.humanFriendly) { obj.originalValue = humanFriendlyNumber( obj.originalValue, obj.config.humanFriendlyDecimal ) + obj.config.symbol; } else { - obj.originalValue = (obj.originalValue * 1).toFixed(obj.config.decimals); + obj.originalValue = (obj.originalValue * 1).toFixed(obj.config.decimals) + obj.config.symbol; } - obj.txtValue.attr("text", obj.originalValue + obj.config.symbol); + obj.txtValue.attr("text", obj.originalValue); setDy(obj.txtValue, obj.params.valueFontSize, obj.params.valueY); } -- cgit v1.2.3 From 28761467fc3c13f45f655b39b58cb233a7a1c1ea Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 11 Apr 2013 17:11:32 +0200 Subject: [IMP] better UI bzr revid: mat@openerp.com-20130411151132-vsk2cnff5uhqmzas --- addons/gamification/static/src/js/gamification.js | 1 - 1 file changed, 1 deletion(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index c743d39282a..44af26550a0 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -123,7 +123,6 @@ openerp.gamification = function(instance) { if (self.view.dataset.model === 'gamification.goal' && self.$el.find('.oe_goal_gauge').length == 1) { var unique_id = _.uniqueId("goal_gauge_"); self.$el.find('.oe_goal_gauge').attr('id', unique_id); - console.log(self.record); var g = new JustGage({ id: unique_id, node: self.$el.find('.oe_goal_gauge').empty().get(0), -- cgit v1.2.3 From 252365095a18b71ac0912ca2bc3f5262ffdd87b8 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 12 Apr 2013 10:54:52 +0200 Subject: [IMP] better badge views and checks bzr revid: mat@openerp.com-20130412085452-mnecqo80cgmo2ecs --- addons/gamification/static/src/js/gamification.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 44af26550a0..a856d057172 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -125,7 +125,7 @@ openerp.gamification = function(instance) { self.$el.find('.oe_goal_gauge').attr('id', unique_id); var g = new JustGage({ id: unique_id, - node: self.$el.find('.oe_goal_gauge').empty().get(0), + node: self.$('.oe_goal_gauge').empty().get(0), value: self.record.current.raw_value, min: 0, max: self.record.target_goal.raw_value, -- cgit v1.2.3 From b18bc579197837ddcc97d9f7292d8cec3bc05d49 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 12 Apr 2013 17:21:50 +0200 Subject: [ADD] use sparklines bzr revid: mat@openerp.com-20130412152150-8679huigt6cfmool --- addons/gamification/static/src/js/gamification.js | 15 ++++++++++++--- .../static/src/js/jquery.sparkline.2.1.1.min.js | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 addons/gamification/static/src/js/jquery.sparkline.2.1.1.min.js (limited to 'addons/gamification/static/src/js') diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index a856d057172..aafdcbf8659 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -64,6 +64,7 @@ openerp.gamification = function(instance) { self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do'); self.render_money_fields(self.goals_info.info[0].currency); self.render_progress_bars(); + self.render_piechars(); } }); }, @@ -72,7 +73,7 @@ openerp.gamification = function(instance) { self.dfm = new instance.web.form.DefaultFieldManager(self); // Generate a FieldMonetary for each .oe_goal_field_monetary - self.$el.find(".oe_goal_field_monetary").each(function() { + self.$(".oe_goal_field_monetary").each(function() { money_field = new instance.web.form.FieldMonetary(self.dfm, { attrs: { modifiers: '{"readonly": true}' @@ -89,7 +90,7 @@ openerp.gamification = function(instance) { dfm = new instance.web.form.DefaultFieldManager(self); // Generate a FieldMonetary for each .oe_goal_field_monetary - self.$el.find(".oe_goal_progress").each(function() { + self.$(".oe_goal_progress").each(function() { progress_field = new instance.web.form.FieldProgressBar(dfm, { attrs: { modifiers: '{"readonly": true}' @@ -98,6 +99,14 @@ openerp.gamification = function(instance) { progress_field.set('value', $(this).attr('value')); progress_field.replace($(this)); }); + }, + render_piechars: function() { + var self = this; + self.$(".oe_goal_sparkline_piechart").each(function() { + var completeness = parseInt( $(this).attr('data-completeness'), 10); + var values = [completeness, 100-completeness]; + $(this).sparkline(values, {type: 'pie', offset: 180, sliceColors: ['#01922D','#ff0000']}); + }); } }); @@ -143,8 +152,8 @@ openerp.gamification = function(instance) { // }, label: self.record.type_suffix.raw_value, levelColors: [ - "#f9c802", "#ff0000", + "#f9c802", "#a9d70b" ], }); diff --git a/addons/gamification/static/src/js/jquery.sparkline.2.1.1.min.js b/addons/gamification/static/src/js/jquery.sparkline.2.1.1.min.js new file mode 100644 index 00000000000..74187063f45 --- /dev/null +++ b/addons/gamification/static/src/js/jquery.sparkline.2.1.1.min.js @@ -0,0 +1,5 @@ +/* jquery.sparkline 2.1.1 - http://omnipotent.net/jquery.sparkline/ +** Licensed under the New BSD License - see above site for details */ + +(function(a){typeof define=="function"&&define.amd?define(["jquery"],a):a(jQuery)})(function(a){"use strict";var b={},c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I=0;c=function(){return{common:{type:"line",lineColor:"#00f",fillColor:"#cdf",defaultPixelsPerValue:3,width:"auto",height:"auto",composite:!1,tagValuesAttribute:"values",tagOptionsPrefix:"spark",enableTagOptions:!1,enableHighlight:!0,highlightLighten:1.4,tooltipSkipNull:!0,tooltipPrefix:"",tooltipSuffix:"",disableHiddenCheck:!1,numberFormatter:!1,numberDigitGroupCount:3,numberDigitGroupSep:",",numberDecimalMark:".",disableTooltips:!1,disableInteraction:!1},line:{spotColor:"#f80",highlightSpotColor:"#5f5",highlightLineColor:"#f22",spotRadius:1.5,minSpotColor:"#f80",maxSpotColor:"#f80",lineWidth:1,normalRangeMin:undefined,normalRangeMax:undefined,normalRangeColor:"#ccc",drawNormalOnTop:!1,chartRangeMin:undefined,chartRangeMax:undefined,chartRangeMinX:undefined,chartRangeMaxX:undefined,tooltipFormat:new e('● {{prefix}}{{y}}{{suffix}}')},bar:{barColor:"#3366cc",negBarColor:"#f44",stackedBarColor:["#3366cc","#dc3912","#ff9900","#109618","#66aa00","#dd4477","#0099c6","#990099"],zeroColor:undefined,nullColor:undefined,zeroAxis:!0,barWidth:4,barSpacing:1,chartRangeMax:undefined,chartRangeMin:undefined,chartRangeClip:!1,colorMap:undefined,tooltipFormat:new e('● {{prefix}}{{value}}{{suffix}}')},tristate:{barWidth:4,barSpacing:1,posBarColor:"#6f6",negBarColor:"#f44",zeroBarColor:"#999",colorMap:{},tooltipFormat:new e('● {{value:map}}'),tooltipValueLookups:{map:{"-1":"Loss",0:"Draw",1:"Win"}}},discrete:{lineHeight:"auto",thresholdColor:undefined,thresholdValue:0,chartRangeMax:undefined,chartRangeMin:undefined,chartRangeClip:!1,tooltipFormat:new e("{{prefix}}{{value}}{{suffix}}")},bullet:{targetColor:"#f33",targetWidth:3,performanceColor:"#33f",rangeColors:["#d3dafe","#a8b6ff","#7f94ff"],base:undefined,tooltipFormat:new e("{{fieldkey:fields}} - {{value}}"),tooltipValueLookups:{fields:{r:"Range",p:"Performance",t:"Target"}}},pie:{offset:0,sliceColors:["#3366cc","#dc3912","#ff9900","#109618","#66aa00","#dd4477","#0099c6","#990099"],borderWidth:0,borderColor:"#000",tooltipFormat:new e('● {{value}} ({{percent.1}}%)')},box:{raw:!1,boxLineColor:"#000",boxFillColor:"#cdf",whiskerColor:"#000",outlierLineColor:"#333",outlierFillColor:"#fff",medianColor:"#f00",showOutliers:!0,outlierIQR:1.5,spotRadius:1.5,target:undefined,targetColor:"#4a2",chartRangeMax:undefined,chartRangeMin:undefined,tooltipFormat:new e("{{field:fields}}: {{value}}"),tooltipFormatFieldlistKey:"field",tooltipValueLookups:{fields:{lq:"Lower Quartile",med:"Median",uq:"Upper Quartile",lo:"Left Outlier",ro:"Right Outlier",lw:"Left Whisker",rw:"Right Whisker"}}}}},B='.jqstooltip { position: absolute;left: 0px;top: 0px;visibility: hidden;background: rgb(0, 0, 0) transparent;background-color: rgba(0,0,0,0.6);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000)";color: white;font: 10px arial, san serif;text-align: left;white-space: nowrap;padding: 5px;border: 1px solid white;z-index: 10000;}.jqsfield { color: white;font: 10px arial, san serif;text-align: left;}',d=function(){var b,c;return b=function(){this.init.apply(this,arguments)},arguments.length>1?(arguments[0]?(b.prototype=a.extend(new arguments[0],arguments[arguments.length-1]),b._super=arguments[0].prototype):b.prototype=arguments[arguments.length-1],arguments.length>2&&(c=Array.prototype.slice.call(arguments,1,-1),c.unshift(b.prototype),a.extend.apply(a,c))):b.prototype=arguments[0],b.prototype.cls=b,b},a.SPFormatClass=e=d({fre:/\{\{([\w.]+?)(:(.+?))?\}\}/g,precre:/(\w+)\.(\d+)/,init:function(a,b){this.format=a,this.fclass=b},render:function(a,b,c){var d=this,e=a,f,g,h,i,j;return this.format.replace(this.fre,function(){var a;return g=arguments[1],h=arguments[3],f=d.precre.exec(g),f?(j=f[2],g=f[1]):j=!1,i=e[g],i===undefined?"":h&&b&&b[h]?(a=b[h],a.get?b[h].get(i)||i:b[h][i]||i):(k(i)&&(c.get("numberFormatter")?i=c.get("numberFormatter")(i):i=p(i,j,c.get("numberDigitGroupCount"),c.get("numberDigitGroupSep"),c.get("numberDecimalMark"))),i)})}}),a.spformat=function(a,b){return new e(a,b)},f=function(a,b,c){return ac?c:a},g=function(a,b){var c;return b===2?(c=Math.floor(a.length/2),a.length%2?a[c]:(a[c-1]+a[c])/2):a.length%2?(c=(a.length*b+b)/4,c%1?(a[Math.floor(c)]+a[Math.floor(c)-1])/2:a[c-1]):(c=(a.length*b+2)/4,c%1?(a[Math.floor(c)]+a[Math.floor(c)-1])/2:a[c-1])},h=function(a){var b;switch(a){case"undefined":a=undefined;break;case"null":a=null;break;case"true":a=!0;break;case"false":a=!1;break;default:b=parseFloat(a),a==b&&(a=b)}return a},i=function(a){var b,c=[];for(b=a.length;b--;)c[b]=h(a[b]);return c},j=function(a,b){var c,d,e=[];for(c=0,d=a.length;c0;h-=d)b.splice(h,0,e);return b.join("")},l=function(a,b,c){var d;for(d=b.length;d--;){if(c&&b[d]===null)continue;if(b[d]!==a)return!1}return!0},m=function(a){var b=0,c;for(c=a.length;c--;)b+=typeof a[c]=="number"?a[c]:0;return b},o=function(b){return a.isArray(b)?b:[b]},n=function(a){var b;document.createStyleSheet?document.createStyleSheet().cssText=a:(b=document.createElement("style"),b.type="text/css",document.getElementsByTagName("head")[0].appendChild(b),b[typeof document.body.style.WebkitAppearance=="string"?"innerText":"innerHTML"]=a)},a.fn.simpledraw=function(b,c,d,e){var f,g;if(d&&(f=this.data("_jqs_vcanvas")))return f;b===undefined&&(b=a(this).innerWidth()),c===undefined&&(c=a(this).innerHeight());if(a.fn.sparkline.hasCanvas)f=new F(b,c,this,e);else{if(!a.fn.sparkline.hasVML)return!1;f=new G(b,c,this)}return g=a(this).data("_jqs_mhandler"),g&&g.registerCanvas(f),f},a.fn.cleardraw=function(){var a=this.data("_jqs_vcanvas");a&&a.reset()},a.RangeMapClass=q=d({init:function(a){var b,c,d=[];for(b in a)a.hasOwnProperty(b)&&typeof b=="string"&&b.indexOf(":")>-1&&(c=b.split(":"),c[0]=c[0].length===0?-Infinity:parseFloat(c[0]),c[1]=c[1].length===0?Infinity:parseFloat(c[1]),c[2]=a[b],d.push(c));this.map=a,this.rangelist=d||!1},get:function(a){var b=this.rangelist,c,d,e;if((e=this.map[a])!==undefined)return e;if(b)for(c=b.length;c--;){d=b[c];if(d[0]<=a&&d[1]>=a)return d[2]}return undefined}}),a.range_map=function(a){return new q(a)},r=d({init:function(b,c){var d=a(b);this.$el=d,this.options=c,this.currentPageX=0,this.currentPageY=0,this.el=b,this.splist=[],this.tooltip=null,this.over=!1,this.displayTooltips=!c.get("disableTooltips"),this.highlightEnabled=!c.get("disableHighlight")},registerSparkline:function(a){this.splist.push(a),this.over&&this.updateDisplay()},registerCanvas:function(b){var c=a(b.canvas);this.canvas=b,this.$canvas=c,c.mouseenter(a.proxy(this.mouseenter,this)),c.mouseleave(a.proxy(this.mouseleave,this)),c.click(a.proxy(this.mouseclick,this))},reset:function(a){this.splist=[],this.tooltip&&a&&(this.tooltip.remove(),this.tooltip=undefined)},mouseclick:function(b){var c=a.Event("sparklineClick");c.originalEvent=b,c.sparklines=this.splist,this.$el.trigger(c)},mouseenter:function(b){a(document.body).unbind("mousemove.jqs"),a(document.body).bind("mousemove.jqs",a.proxy(this.mousemove,this)),this.over=!0,this.currentPageX=b.pageX,this.currentPageY=b.pageY,this.currentEl=b.target,!this.tooltip&&this.displayTooltips&&(this.tooltip=new s(this.options),this.tooltip.updatePosition(b.pageX,b.pageY)),this.updateDisplay()},mouseleave:function(){a(document.body).unbind("mousemove.jqs");var b=this.splist,c=b.length,d=!1,e,f;this.over=!1,this.currentEl=null,this.tooltip&&(this.tooltip.remove(),this.tooltip=null);for(f=0;f