2012-09-06 10:27:21 +00:00
|
|
|
|
|
|
|
openerp.hr_attendance = function (instance) {
|
|
|
|
|
2012-05-21 07:59:22 +00:00
|
|
|
var QWeb = instance.web.qweb;
|
2012-09-06 10:37:13 +00:00
|
|
|
var _t = instance.web._t;
|
2012-09-06 14:16:46 +00:00
|
|
|
var _lt = instance.web._lt;
|
2012-09-06 10:27:21 +00:00
|
|
|
|
2012-05-21 07:59:22 +00:00
|
|
|
instance.hr_attendance.AttendanceSlider = instance.web.Widget.extend({
|
|
|
|
template: 'AttendanceSlider',
|
2012-09-06 10:27:21 +00:00
|
|
|
init: function (parent) {
|
2012-05-21 07:59:22 +00:00
|
|
|
this._super(parent);
|
2012-09-06 14:16:46 +00:00
|
|
|
this.set({"signed_in": false});
|
2012-05-11 05:47:11 +00:00
|
|
|
},
|
2012-09-06 13:57:45 +00:00
|
|
|
start: function() {
|
|
|
|
var self = this;
|
2012-09-06 14:21:43 +00:00
|
|
|
var tmp = function() {
|
2012-09-06 13:57:45 +00:00
|
|
|
this.$el.toggleClass("oe_attendance_nosigned", ! this.get("signed_in"));
|
|
|
|
this.$el.toggleClass("oe_attendance_signed", this.get("signed_in"));
|
2012-09-06 14:21:43 +00:00
|
|
|
};
|
|
|
|
this.on("change:signed_in", this, tmp);
|
|
|
|
_.bind(tmp, this)();
|
2012-09-06 13:57:45 +00:00
|
|
|
this.$(".oe_attendance_signin").click(function() {
|
|
|
|
self.do_update_attendance();
|
2012-09-06 14:16:46 +00:00
|
|
|
});
|
2012-09-06 13:57:45 +00:00
|
|
|
this.$(".oe_attendance_signout").click(function() {
|
|
|
|
self.do_update_attendance();
|
2012-09-06 14:16:46 +00:00
|
|
|
});
|
2012-09-07 11:51:20 +00:00
|
|
|
this.$el.tipsy({
|
|
|
|
title: function() {
|
2012-09-07 12:23:37 +00:00
|
|
|
var last_text = instance.web.format_value(self.last_sign, {type: "datetime"});
|
|
|
|
var current_text = instance.web.format_value(new Date(), {type: "datetime"});
|
2012-09-10 10:01:52 +00:00
|
|
|
var duration = self.last_sign ? $.timeago(self.last_sign) : "none";
|
2012-09-07 11:51:20 +00:00
|
|
|
if (self.get("signed_in")) {
|
2012-09-07 12:23:37 +00:00
|
|
|
return _.str.sprintf(_t("Last sign in: %s,<br />%s.<br />Click to sign out."), last_text, duration);
|
2012-09-07 11:51:20 +00:00
|
|
|
} else {
|
2012-09-07 12:23:37 +00:00
|
|
|
return _.str.sprintf(_t("Click to Sign In at %s."), current_text);
|
2012-09-07 11:51:20 +00:00
|
|
|
}
|
2012-09-07 12:23:37 +00:00
|
|
|
},
|
|
|
|
html: true,
|
2012-09-07 11:51:20 +00:00
|
|
|
});
|
2012-09-06 13:57:45 +00:00
|
|
|
return this.check_attendance();
|
2012-05-11 05:47:11 +00:00
|
|
|
},
|
2012-09-06 10:27:21 +00:00
|
|
|
do_update_attendance: function () {
|
2012-05-07 13:47:44 +00:00
|
|
|
var self = this;
|
2012-09-06 10:40:12 +00:00
|
|
|
var hr_employee = new instance.web.DataSet(self, 'hr.employee');
|
2012-09-06 10:27:21 +00:00
|
|
|
hr_employee.call('attendance_action_change', [
|
|
|
|
[self.employee.id]
|
|
|
|
]).done(function (result) {
|
2012-09-07 12:23:37 +00:00
|
|
|
self.last_sign = new Date();
|
2012-09-06 13:57:45 +00:00
|
|
|
self.set({"signed_in": ! self.get("signed_in")});
|
2012-05-07 13:47:44 +00:00
|
|
|
});
|
|
|
|
},
|
2012-09-06 10:27:21 +00:00
|
|
|
check_attendance: function () {
|
2012-05-18 13:44:39 +00:00
|
|
|
var self = this;
|
2012-05-25 08:57:59 +00:00
|
|
|
self.employee = false;
|
2012-09-06 13:57:45 +00:00
|
|
|
this.$el.hide();
|
2012-09-06 10:27:21 +00:00
|
|
|
var employee = new instance.web.DataSetSearch(self, 'hr.employee', self.session.user_context, [
|
|
|
|
['user_id', '=', self.session.uid]
|
|
|
|
]);
|
2012-09-21 13:44:05 +00:00
|
|
|
return employee.read_slice(['id', 'name', 'state', 'last_sign', 'attendance_access']).pipe(function (res) {
|
|
|
|
if (_.isEmpty(res) )
|
2012-09-06 10:40:12 +00:00
|
|
|
return;
|
2012-09-21 13:44:05 +00:00
|
|
|
if (res['attendance_access'] == false){
|
|
|
|
return;
|
|
|
|
}
|
2012-09-06 13:57:45 +00:00
|
|
|
self.$el.show();
|
2012-05-18 13:44:39 +00:00
|
|
|
self.employee = res[0];
|
2012-09-07 12:23:37 +00:00
|
|
|
self.last_sign = instance.web.str_to_datetime(self.employee.last_sign);
|
2012-09-06 13:57:45 +00:00
|
|
|
self.set({"signed_in": self.employee.state !== "absent"});
|
2012-05-18 13:44:39 +00:00
|
|
|
});
|
|
|
|
},
|
2012-05-21 07:59:22 +00:00
|
|
|
});
|
2012-09-06 10:27:21 +00:00
|
|
|
|
2012-05-21 07:59:22 +00:00
|
|
|
instance.web.UserMenu.include({
|
2012-05-18 13:44:39 +00:00
|
|
|
do_update: function () {
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
2012-09-06 10:36:44 +00:00
|
|
|
this.update_promise = this.update_promise.then(function () {
|
|
|
|
if (self.attendanceslider)
|
|
|
|
return;
|
|
|
|
self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self);
|
2012-09-06 10:27:21 +00:00
|
|
|
|
2012-09-06 10:36:44 +00:00
|
|
|
self.attendanceslider.prependTo(instance.webclient.$('.oe_systray'));
|
|
|
|
});
|
2012-05-18 13:44:39 +00:00
|
|
|
},
|
2012-05-07 13:47:44 +00:00
|
|
|
});
|
|
|
|
}
|