2013-03-21 11:01:52 +00:00
|
|
|
openerp.gamification = function(instance) {
|
2013-03-22 15:18:03 +00:00
|
|
|
var QWeb = instance.web.qweb;
|
2013-03-21 11:01:52 +00:00
|
|
|
|
2013-03-22 15:18:03 +00:00
|
|
|
instance.gamification.Sidebar = instance.web.Widget.extend({
|
|
|
|
template: 'gamification.user_wall_sidebar',
|
2013-03-21 11:01:52 +00:00
|
|
|
init: function (parent, action) {
|
|
|
|
var self = this;
|
|
|
|
this._super(parent, action);
|
|
|
|
this.deferred = $.Deferred();
|
|
|
|
this.res_user = new instance.web.DataSetSearch(this, 'res.users');
|
|
|
|
this.goals_info = {};
|
2013-03-22 11:13:44 +00:00
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click a.oe_update_goal': function(event) {
|
|
|
|
var self = this;
|
2013-04-02 12:15:14 +00:00
|
|
|
var goal_id = parseInt(event.currentTarget.id, 10);
|
2013-03-22 11:13:44 +00:00
|
|
|
var goal_updated = new instance.web.Model('gamification.goal').call('update', [[goal_id]]);
|
|
|
|
$.when(goal_updated).done(function() {
|
|
|
|
self.get_goal_todo_info();
|
|
|
|
});
|
2013-03-22 16:05:20 +00:00
|
|
|
},
|
2013-03-25 16:15:27 +00:00
|
|
|
'click a.oe_update_plan': function(event) {
|
|
|
|
var self = this;
|
2013-04-02 12:15:14 +00:00
|
|
|
var plan_id = parseInt(event.currentTarget.id, 10);
|
2013-03-25 16:15:27 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
},
|
2013-03-24 13:46:58 +00:00
|
|
|
'click a.oe_goal_action': function(event) {
|
|
|
|
var self = this;
|
2013-04-02 12:15:14 +00:00
|
|
|
var goal_id = parseInt(event.currentTarget.id, 10);
|
2013-04-08 13:17:29 +00:00
|
|
|
console.log("oe_goal_action");
|
2013-03-24 18:05:57 +00:00
|
|
|
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() {
|
|
|
|
var action_manager = new instance.web.ActionManager(this);
|
2013-03-29 15:45:35 +00:00
|
|
|
action_manager.do_action(goal_action.action).done(function () {
|
|
|
|
self.get_goal_todo_info();
|
|
|
|
});
|
2013-03-24 13:46:58 +00:00
|
|
|
|
2013-03-24 18:05:57 +00:00
|
|
|
//var form = action_manager.dialog_widget.views.form.controller;
|
|
|
|
});
|
2013-04-02 12:15:14 +00:00
|
|
|
}
|
2013-03-21 11:01:52 +00:00
|
|
|
},
|
|
|
|
renderElement: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
self.get_goal_todo_info();
|
|
|
|
},
|
|
|
|
render_template: function(target,template) {
|
|
|
|
var self = this;
|
2013-03-22 15:18:03 +00:00
|
|
|
target.append(QWeb.render(template,{'widget': self}));
|
2013-03-21 11:01:52 +00:00
|
|
|
},
|
2013-03-22 08:51:51 +00:00
|
|
|
render_template_replace: function(target,template) {
|
|
|
|
var self = this;
|
2013-03-22 15:18:03 +00:00
|
|
|
target.html(QWeb.render(template,{'widget': self}));
|
2013-03-22 08:51:51 +00:00
|
|
|
},
|
2013-03-21 11:01:52 +00:00
|
|
|
get_goal_todo_info: function() {
|
|
|
|
var self = this;
|
2013-04-08 13:17:29 +00:00
|
|
|
console.log("get_goal_todo_info");
|
2013-03-21 11:01:52 +00:00
|
|
|
var goals_info = this.res_user.call('get_goals_todo_info', {}).then(function(res) {
|
2013-04-02 12:15:14 +00:00
|
|
|
self.goals_info['info'] = res;
|
2013-03-21 11:01:52 +00:00
|
|
|
});
|
|
|
|
$.when(goals_info).done(function() {
|
|
|
|
if(self.goals_info.info.length > 0){
|
2013-03-22 15:18:03 +00:00
|
|
|
self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do');
|
2013-03-26 15:45:53 +00:00
|
|
|
self.render_money_fields(self.goals_info.info[0].currency);
|
2013-03-29 11:52:15 +00:00
|
|
|
self.render_progress_bars();
|
2013-03-21 11:01:52 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2013-03-26 15:45:53 +00:00
|
|
|
render_money_fields: function(currency_id) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.dfm = new instance.web.form.DefaultFieldManager(self);
|
2013-03-27 10:50:40 +00:00
|
|
|
// Generate a FieldMonetary for each .oe_goal_field_monetary
|
2013-03-26 15:45:53 +00:00
|
|
|
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();
|
2013-04-02 12:15:14 +00:00
|
|
|
money_field.set('value', parseInt($(this).text(), 10));
|
2013-03-26 15:45:53 +00:00
|
|
|
money_field.replace($(this));
|
|
|
|
});
|
2013-03-29 11:52:15 +00:00
|
|
|
},
|
|
|
|
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));
|
|
|
|
});
|
2013-03-26 15:45:53 +00:00
|
|
|
}
|
2013-03-21 11:01:52 +00:00
|
|
|
});
|
2013-03-22 15:18:03 +00:00
|
|
|
|
|
|
|
instance.mail.Widget.include({
|
|
|
|
init: function (parent, action) {
|
|
|
|
var self = this;
|
|
|
|
this._super(parent, action);
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
2013-04-08 13:17:29 +00:00
|
|
|
console.log("start");
|
2013-03-22 15:18:03 +00:00
|
|
|
var sidebar = new instance.gamification.Sidebar(self);
|
|
|
|
sidebar.appendTo($('.oe_mail_wall_aside'));
|
|
|
|
}
|
|
|
|
});
|
2013-03-21 11:01:52 +00:00
|
|
|
};
|