2013-03-21 11:01:52 +00:00
|
|
|
openerp.gamification = function(instance) {
|
|
|
|
console.log("Debug statement: file loaded");
|
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-03-22 15:18:03 +00:00
|
|
|
var goal_id = parseInt(event.currentTarget.id);
|
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
|
|
|
},
|
|
|
|
'click a.oe_show_description': function(event) {
|
|
|
|
var goal_id = parseInt(event.currentTarget.id);
|
|
|
|
this.$el.find('.oe_type_description_'+goal_id).toggle(10);
|
|
|
|
},
|
2013-03-24 13:46:58 +00:00
|
|
|
'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();
|
|
|
|
// });
|
|
|
|
|
|
|
|
}
|
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;
|
|
|
|
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){
|
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-22 16:05:20 +00:00
|
|
|
self.$el.find('.oe_type_description').hide();
|
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-03-21 11:01:52 +00:00
|
|
|
};
|