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-04-18 10:32:29 +00:00
|
|
|
this.challenge_suggestions = {};
|
2013-03-22 11:13:44 +00:00
|
|
|
},
|
|
|
|
events: {
|
2013-04-23 13:03:51 +00:00
|
|
|
// update a plan and related goals
|
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-04-23 13:03:51 +00:00
|
|
|
// action to modify a goal
|
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-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-04-24 08:36:32 +00:00
|
|
|
var action = action_manager.do_action(goal_action.action);
|
|
|
|
$.when(action).done(function () {
|
|
|
|
new instance.web.Model('gamification.goal').call('update', [[goal_id]]).then(function(res) {
|
|
|
|
self.get_goal_todo_info();
|
|
|
|
});
|
2013-03-29 15:45:35 +00:00
|
|
|
});
|
2013-03-24 18:05:57 +00:00
|
|
|
});
|
2013-04-18 16:05:12 +00:00
|
|
|
},
|
2013-04-23 13:03:51 +00:00
|
|
|
// get more info about a challenge request
|
2013-04-18 16:05:12 +00:00
|
|
|
'click a.oe_challenge_reply': function(event) {
|
|
|
|
var self = this;
|
|
|
|
var plan_id = parseInt(event.currentTarget.id, 10);
|
|
|
|
var plan_action = new instance.web.Model('gamification.goal.plan').call('reply_challenge_wizard', [plan_id]).then(function(res) {
|
|
|
|
plan_action['action'] = res;
|
|
|
|
});
|
|
|
|
$.when(plan_action).done(function() {
|
|
|
|
var action_manager = new instance.web.ActionManager(this);
|
|
|
|
action_manager.do_action(plan_action.action).done(function () {
|
|
|
|
self.get_goal_todo_info();
|
|
|
|
});
|
|
|
|
});
|
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();
|
2013-04-18 10:32:29 +00:00
|
|
|
self.get_challenge_suggestions();
|
2013-03-21 11:01:52 +00:00
|
|
|
},
|
|
|
|
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;
|
|
|
|
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-04-18 16:05:12 +00:00
|
|
|
self.render_user_avatars();
|
2013-04-18 10:32:29 +00:00
|
|
|
} else {
|
|
|
|
self.$el.filter(".oe_gamification_goal").hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
get_challenge_suggestions: function() {
|
|
|
|
var self = this;
|
|
|
|
var challenge_suggestions = this.res_user.call('get_challenge_suggestions', {}).then(function(res) {
|
|
|
|
self.challenge_suggestions['info'] = res;
|
|
|
|
});
|
|
|
|
$.when(challenge_suggestions).done(function() {
|
|
|
|
if(self.challenge_suggestions.info.length > 0){
|
|
|
|
self.render_template_replace(self.$el.filter(".oe_gamification_suggestion"),'gamification.challenge_suggestions');
|
|
|
|
} else {
|
|
|
|
self.$el.filter(".oe_gamification_suggestion").hide();
|
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-04-12 15:21:50 +00:00
|
|
|
self.$(".oe_goal_field_monetary").each(function() {
|
2013-03-26 15:45:53 +00:00
|
|
|
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
|
|
|
},
|
2013-04-18 16:05:12 +00:00
|
|
|
render_user_avatars: function() {
|
|
|
|
var self = this;
|
|
|
|
self.$(".oe_user_avatar").each(function() {
|
|
|
|
var user_id = parseInt( $(this).attr('data-id'), 10);
|
|
|
|
var url = instance.session.url('/web/binary/image', {model: 'res.users', field: 'image_small', id: user_id});
|
|
|
|
$(this).attr("src", url);
|
|
|
|
});
|
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;
|
|
|
|
var sidebar = new instance.gamification.Sidebar(self);
|
|
|
|
sidebar.appendTo($('.oe_mail_wall_aside'));
|
|
|
|
}
|
|
|
|
});
|
2013-04-09 14:23:02 +00:00
|
|
|
|
|
|
|
instance.web_kanban.KanbanRecord.include({
|
|
|
|
start: function () {
|
|
|
|
var rendering = this._super();
|
|
|
|
var self = this;
|
|
|
|
|
2013-04-18 10:32:29 +00:00
|
|
|
// add gauge in goal kanban views
|
2013-04-09 14:23:02 +00:00
|
|
|
$.when(rendering).done(function() {
|
|
|
|
if (self.view.dataset.model === 'gamification.goal' && self.$el.find('.oe_goal_gauge').length == 1) {
|
|
|
|
var g = new JustGage({
|
2013-04-24 08:36:32 +00:00
|
|
|
parentNode: self.$('.oe_goal_gauge').empty().get(0),
|
2013-04-09 14:23:02 +00:00
|
|
|
value: self.record.current.raw_value,
|
|
|
|
min: 0,
|
|
|
|
max: self.record.target_goal.raw_value,
|
2013-04-09 14:40:30 +00:00
|
|
|
relativeGaugeSize: true,
|
2013-04-10 15:30:31 +00:00
|
|
|
humanFriendly: true,
|
|
|
|
label: self.record.type_suffix.raw_value,
|
2013-04-09 14:40:30 +00:00
|
|
|
levelColors: [
|
|
|
|
"#ff0000",
|
2013-04-12 15:21:50 +00:00
|
|
|
"#f9c802",
|
2013-04-09 14:40:30 +00:00
|
|
|
"#a9d70b"
|
2013-04-16 13:48:47 +00:00
|
|
|
]
|
2013-04-09 14:23:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2013-04-18 10:32:29 +00:00
|
|
|
// open related goals when clicking on challenge kanban view
|
2013-04-09 14:23:02 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-03-21 11:01:52 +00:00
|
|
|
};
|