odoo/addons/gamification/static/src/js/gamification.js

107 lines
4.4 KiB
JavaScript
Raw Normal View History

openerp.gamification = function(instance) {
var QWeb = instance.web.qweb;
instance.gamification.Sidebar = instance.web.Widget.extend({
template: 'gamification.user_wall_sidebar',
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 = {};
},
events: {
'click a.oe_update_goal': function(event) {
var self = this;
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();
});
},
'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);
// },
'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]).then(function(res) {
goal_action['action'] = res;
});
$.when(goal_action).done(function() {
var action_manager = new instance.web.ActionManager(this);
action_manager.do_action(goal_action.action);
//var form = action_manager.dialog_widget.views.form.controller;
});
},
},
renderElement: function() {
var self = this;
this._super.apply(this, arguments);
self.get_goal_todo_info();
},
render_template: function(target,template) {
var self = this;
target.append(QWeb.render(template,{'widget': self}));
},
render_template_replace: function(target,template) {
var self = this;
target.html(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() {
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({
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'));
}
});
};