Code improvement.

bzr revid: tta@openerp.com-20120521075922-o7nqzuhz67i62tzj
This commit is contained in:
Tejas Tank 2012-05-21 13:29:22 +05:30
parent 3a3a10ef46
commit 390842adc4
3 changed files with 70 additions and 120 deletions

View File

@ -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:

View File

@ -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);
},

View File

@ -1,16 +1,14 @@
<template>
<t t-extend="UserMenu">
<t t-jquery="li.oe_dropdown" t-operation="before" >
<li>
<div class="oe_attendance_status" style="height:20px;width:100px;background-color:white;padding: 5px 10px 7px;margin:3px;">
<div class="oe_attendance_present" style="float:left;">Present</div>
<div class="oe_attendance_absent" style="float:right">Absent</div>
<div class="oe_attendance_slider" style="cursor:pointer;width: 60px;background-color: gray;position: relative;top: -4px;left: -8px;height: 30px;-webkit-border-radius:4px;"><span style="visibility:hidden;">slider</span></div>
</div>
</li>
</t>
</t>
<t t-name="AttendanceSlider">
<li>
<div class="oe_attendance_status">
<div class="oe_attendance_present"><t t-esc="present"/></div>
<div class="oe_attendance_absent"><t t-esc="absent"/></div>
<div class="oe_attendance_slider"><span class="oe_attendance_text">slider</span></div>
</div>
</li>
</t>
</template>