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() {
|
2014-06-27 09:03:34 +00:00
|
|
|
var $sign_in_out_icon = this.$('#oe_attendance_sign_in_out_icon');
|
|
|
|
$sign_in_out_icon.toggleClass("fa-sign-in", ! this.get("signed_in"));
|
|
|
|
$sign_in_out_icon.toggleClass("fa-sign-out", this.get("signed_in"));
|
2012-09-06 14:21:43 +00:00
|
|
|
};
|
|
|
|
this.on("change:signed_in", this, tmp);
|
|
|
|
_.bind(tmp, this)();
|
2014-06-27 09:03:34 +00:00
|
|
|
this.$(".oe_attendance_sign_in_out").click(function(ev) {
|
|
|
|
ev.preventDefault();
|
2012-09-06 13:57:45 +00:00
|
|
|
self.do_update_attendance();
|
2012-09-06 14:16:46 +00:00
|
|
|
});
|
2014-04-17 09:05:15 +00:00
|
|
|
this.$el.tooltip({
|
2012-09-07 11:51:20 +00:00
|
|
|
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
|
|
|
},
|
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-10-31 10:31:48 +00:00
|
|
|
return employee.read_slice(['id', 'name', 'state', 'last_sign', 'attendance_access']).then(function (res) {
|
2012-09-21 13:44:05 +00:00
|
|
|
if (_.isEmpty(res) )
|
2012-09-06 10:40:12 +00:00
|
|
|
return;
|
2012-12-13 16:13:51 +00:00
|
|
|
if (res[0].attendance_access === false){
|
2012-09-21 13:44:05 +00:00
|
|
|
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-12-13 16:13:51 +00:00
|
|
|
this.update_promise.done(function () {
|
2012-12-14 15:52:25 +00:00
|
|
|
if (!_.isUndefined(self.attendanceslider)) {
|
2012-12-14 15:24:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// check current user is an employee
|
|
|
|
var Users = new instance.web.Model('res.users');
|
|
|
|
Users.call('has_group', ['base.group_user']).done(function(is_employee) {
|
|
|
|
if (is_employee) {
|
|
|
|
self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self);
|
|
|
|
self.attendanceslider.prependTo(instance.webclient.$('.oe_systray'));
|
|
|
|
} else {
|
|
|
|
self.attendanceslider = null;
|
2012-12-13 16:13:51 +00:00
|
|
|
}
|
|
|
|
});
|
2012-09-06 10:36:44 +00:00
|
|
|
});
|
2012-05-18 13:44:39 +00:00
|
|
|
},
|
2012-05-07 13:47:44 +00:00
|
|
|
});
|
2012-12-13 16:13:51 +00:00
|
|
|
};
|