From 390842adc4e7cf7e22aa87b89267fff6fa66efff Mon Sep 17 00:00:00 2001 From: Tejas Tank Date: Mon, 21 May 2012 13:29:22 +0530 Subject: [PATCH] Code improvement. bzr revid: tta@openerp.com-20120521075922-o7nqzuhz67i62tzj --- addons/hr_attendance/__openerp__.py | 1 + .../hr_attendance/static/src/js/attendance.js | 169 +++++++----------- .../static/src/xml/attendance.xml | 20 +-- 3 files changed, 70 insertions(+), 120 deletions(-) diff --git a/addons/hr_attendance/__openerp__.py b/addons/hr_attendance/__openerp__.py index eec95887bb8..6be8f3c2021 100644 --- a/addons/hr_attendance/__openerp__.py +++ b/addons/hr_attendance/__openerp__.py @@ -57,5 +57,6 @@ actions(Sign in/Sign out) performed by them. #web "js": ["static/src/js/attendance.js"], 'qweb' : ["static/src/xml/attendance.xml"], + 'css' : ["static/src/css/slider.css"], } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_attendance/static/src/js/attendance.js b/addons/hr_attendance/static/src/js/attendance.js index ab2721f1d8b..2bb06f95014 100644 --- a/addons/hr_attendance/static/src/js/attendance.js +++ b/addons/hr_attendance/static/src/js/attendance.js @@ -1,109 +1,28 @@ openerp.hr_attendance = function(instance) { - /** var QWeb = instance.web.qweb; - instance.hr_attendance.attendancestatus = false, - instance.hr_attendance.checkstatus = function(){ - attendance = instance.hr_attendance.currentstatus; - if (!attendance){ - attendance = new instance.hr_attendance.AttendanceNotifier(self); - instance.hr_attendance.currentstatus = attendance; - } - attendance.renderElement(); - }, - instance.hr_attendance.callback = function(callback){ - var old_callback = callback; - callback = function(result){ - if(old_callback){old_callback(result);} - instance.hr_attendance.checkstatus(); - } - return callback; - }, - instance.hr_attendance.AttendanceNotifier = instance.web.Widget.extend({ - template: 'AttendanceNotifier', - renderElement: function() { - var self = this; - employee = new instance.web.DataSetSearch(this, 'hr.employee', this.session.user_context, [['user_id','=', this.session.uid]]); - employee.read_slice(['id','name','state']).done(function(employee) { - if(_.isEmpty(employee)) return; - self.employee = employee[0]; - self.do_update_notifier(); - }); - var el = $("div.presence_slider"); - el.click(function(){ - if(self.employee.state == 'present'){ - el.animate({"left": "48px"}, "slow"); - self.on_click(); - }else{ - el.animate({"left": "-8px"}, "slow"); - - } - }); + var QWeb = instance.web.qweb; + _t = instance.web._t; + + instance.web.currentform = false; + instance.web.attendanceslider = false; + + instance.hr_attendance.AttendanceSlider = instance.web.Widget.extend({ + template: 'AttendanceSlider', + init: function(parent){ + this.titles = {'present' :_t("Present"), + 'absent' :_t("Absent") + } + this._super(parent); + this.session = parent.session; + this.parent_element = parent.$element ; }, - do_update_notifier: function(){ - var self = this; - var el = $('img.oe_topbar_avatar'); - - - - - this.$element = $(QWeb.render(this.template, {'employee':this.employee})); - this.$element.click(self.on_click); - element = $('.oe_attendance_button') - if (element.length != 0){ - element.replaceWith(this.$element); - } - else{ - this.$element.appendTo($('.oe_systray')); - - } + renderElement: function(){ + this.$element = $(QWeb.render(this.template,this.titles)); + this.parent_element.prepend(this.$element); + this.$oe_attendance_slider = this.$element.find(".oe_attendance_slider"); + this.$oe_attendance_slider.click(this.do_update_attendance); }, - - on_click: function() { - var self = this; - hr_employee = new instance.web.DataSet(self, 'hr.employee'); - hr_employee.call('attendance_action_change', [[self.employee.id]]).done(function(result){ - //window.location.reload(); - self.renderElement() - }); - }, - }); - /* instance.web.DataSet.include({ - create: function(data, callback, error_callback) { - if (this._model.name == "hr.attendance"){ - callback = instance.hr_attendance.callback(callback); - } - return this._super(data, callback, error_callback); - }, - write: function (id, data, options, callback, error_callback) { - if (this._model.name == "hr.attendance"){ - callback = instance.hr_attendance.callback(callback); - } - return this._super(id, data, options, callback, error_callback); - }, - unlink: function(ids, callback, error_callback) { - if (this._model.name == "hr.attendance"){ - callback = instance.hr_attendance.callback(callback); - } - return this._super(ids, callback, error_callback); - }, - call_button: function (method, args, callback, error_callback) { - if (method == "attendance_action_change"){ - callback = instance.hr_attendance.callback(callback); - } - return this._super(method, args, callback, error_callback); - }, - callback: function() - { - this.__super(); - - ..... - } - - }); */ - - instance.web.UserMenu.include({ do_update_attendance: function() { var self = this; - console.log("click.........",self); hr_employee = new instance.web.DataSet(self, 'hr.employee'); hr_employee.call('attendance_action_change', [[self.employee.id]]).done(function(result){ if (!result) return; @@ -111,15 +30,20 @@ openerp.hr_attendance = function(instance) { self.employee.state = 'absent'; else self.employee.state = 'present'; - self.do_slide(self.employee.state); + self.do_slide(self.employee.state); + if(instance.web.currentform){ + instance.web.currentform.reload(); + + } }); }, do_slide:function(attendance_state) { if(attendance_state == 'present') - this.oe_attendance_slider.animate({"left": "48px"}, "slow"); + this.$oe_attendance_slider.animate({"left": "48px"}, "slow"); else - this.oe_attendance_slider.animate({"left": "-8px"}, "slow"); + this.$oe_attendance_slider.animate({"left": "-8px"}, "slow"); + }, check_attendance: function(){ var self = this; @@ -130,14 +54,41 @@ openerp.hr_attendance = function(instance) { self.do_slide(self.employee.state); }); }, + }); + + instance.web.ListView.include({ + init:function(parent, dataset, view_id, options) + { + this._super(parent, dataset, view_id, options); + if (this.model == 'hr.employee' || this.model == 'hr.attendance') + instance.web.currentform = this; + } + }); + + + instance.web.FormView.include({ + init: function(parent, dataset, view_id, options) { + this._super(parent, dataset, view_id, options); + if (this.model == 'hr.employee' || this.model == 'hr.attendance') + instance.web.currentform = this; + }, + reload: function(){ + var re = this._super(); + if (!instance.web.attendanceslider) return re; + if (this.model == 'hr.employee' || this.model == 'hr.attendance') + instance.web.attendanceslider.check_attendance(); + return re; + }, + }), + + instance.web.UserMenu.include({ do_update: function () { this._super(); var self = this; - var fct = function() { - self.oe_attendance_slider = self.$element.find('.oe_attendance_slider'); - self.oe_attendance_slider.click(self.do_update_attendance); - return self.check_attendance(); - + var fct = function() { + instance.web.attendanceslider = new instance.hr_attendance.AttendanceSlider(self); + instance.web.attendanceslider.renderElement(); + return instance.web.attendanceslider.check_attendance(); }; this.update_promise = this.update_promise.pipe(fct, fct); }, diff --git a/addons/hr_attendance/static/src/xml/attendance.xml b/addons/hr_attendance/static/src/xml/attendance.xml index a61bbb539f7..5670545e26c 100644 --- a/addons/hr_attendance/static/src/xml/attendance.xml +++ b/addons/hr_attendance/static/src/xml/attendance.xml @@ -1,16 +1,14 @@