[IMP]icon change on button click in form view

bzr revid: dhr@tinyerp.com-20120502133411-7l0xlcda0j2wfydb
This commit is contained in:
Dharti Ratani (OpenERP) 2012-05-02 19:04:11 +05:30
parent b3999dee3e
commit 05fa2790ef
4 changed files with 54 additions and 23 deletions

View File

@ -130,8 +130,8 @@
<field name="coach_id" position="after">
<group colspan="2">
<field name="state"/>
<button name="attendance_action_change" states="present" string="Sign Out" type="object" icon="gtk-go-forward" context="{'type':'sign_out'}" groups="base.group_hr_user"/>
<button name="attendance_action_change" states="absent" string="Sign In" type="object" icon="gtk-go-back" context="{'type':'sign_in'}" groups="base.group_hr_user"/>
<button name="attendance_action_change" states="present" string="Sign Out" type="object" widget="att_button" icon="gtk-go-forward" context="{'type':'sign_out'}" groups="base.group_hr_user"/>
<button name="attendance_action_change" states="absent" string="Sign In" type="object" widget="att_button" icon="gtk-go-back" context="{'type':'sign_in'}" groups="base.group_hr_user"/>
</group>
</field>
</field>

View File

@ -1,18 +1,47 @@
openerp.hr_attendance = function(openerp) {
openerp.hr.Attrs_Button = openerp.web.form.WidgetButton.extend({
init: function(view, node) {
this._super(view, node);
},
on_click: function() {
var self=this;
this._super();
var state = this.node.attrs.states
if (this.string === 'Sign Out'){
openerp.webclient.user_menu.hr_sign_out.replace(openerp.webclient.$element.find('.oe_systray').children())
}
if (this.string === "Sign In"){
openerp.webclient.user_menu.hr_sign_in.replace(openerp.webclient.$element.find('.oe_systray').children());
}
}
});
openerp.web.form.tags.add('att_button', 'openerp.hr.Attrs_Button');
openerp.hr_attendance.SignIn = openerp.web.Widget.extend({
template: 'SignInNotifier',
init : function(parent, event){
this._super(parent)
this.event = event
},
start: function() {
this.$element.on('click', '.sign_in', this.getParent().on_sign_in_out);
}
this.$element.on('click', this.event);
},
});
openerp.hr_attendance.SignOut = openerp.web.Widget.extend({
template: 'SignOutNotifier',
start: function() {
this.$element.on('click', '.sign_out', this.getParent().on_sign_in_out);
}
init : function(parent, event){
this._super(parent)
this.event = event
},
start: function() {
this.$element.on('click', this.event);
},
});
openerp.hr_attendance.SignInOut = openerp.web.Widget.extend({
@ -27,16 +56,17 @@ openerp.hr_attendance = function(openerp) {
},
start: function() {
var self = this;
return this.dataset.read_slice(['state']).done(this.do_sign_in_out);
},
do_sign_in_out: function(user) {
if(_.isEmpty(user)) return;
if(user[0]['state'] === 'present') {
this.sign_out = new openerp.hr_attendance.SignOut(this);
this.sign_out = new openerp.hr_attendance.SignOut(this, this.on_sign_in_out);
this.sign_out.appendTo(this.$element);
} else {
this.sign_in = new openerp.hr_attendance.SignIn(this);
this.sign_in = new openerp.hr_attendance.SignIn(this, this.on_sign_in_out);
this.sign_in.appendTo(this.$element);
}
},
@ -52,18 +82,16 @@ openerp.hr_attendance = function(openerp) {
action = action[0];
action.context = JSON.parse(action.context);
var action_manager = new openerp.web.ActionManager(self);
action_manager.do_action(action, function() {
self.on_close($(evt.currentTarget).attr('class'));
});
action_manager.do_action(action, self.on_close);
});
},
on_close: function(target) {
if(target === 'sign_in') {
on_close: function() {
if(this.sign_in) {
this.sign_in.destroy();
this.sign_out = new openerp.hr_attendance.SignOut(this);
this.sign_out.appendTo(this.$element);
} else if(target === 'sign_out') {
} else if(this.sign_out) {
this.sign_out.destroy();
this.sign_in = new openerp.hr_attendance.SignIn(this);
this.sign_in.appendTo(this.$element);
@ -71,12 +99,16 @@ openerp.hr_attendance = function(openerp) {
}
});
openerp.web.UserMenu.include({
do_update: function() {
var self = this;
this._super();
this.update_promise.then(function() {
self.hr_sign_in_out = new openerp.hr_attendance.SignInOut(self);
self.hr_sign_in_out = new openerp.hr_attendance.SignInOut(self);
var event = self.hr_sign_in_out.on_sign_in_out
self.hr_sign_in = new openerp.hr_attendance.SignIn(self, event)
self.hr_sign_out = new openerp.hr_attendance.SignOut(self, event )
self.hr_sign_in_out.appendTo(openerp.webclient.$element.find('.oe_systray'))
});
}

View File

@ -7,7 +7,6 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Sign in / Sign out">
<separator colspan="4" string="Sign in / Sign out"/>
<label colspan="4" nolabel="1" string="If you need your staff to sign in when they arrive at work and sign out again at the end of the day, OpenERP allows you to manage this with this tool. If each employee has been linked to a system user, then they can encode their time with this action button."/>
<newline/>
<group colspan="4" col="6">
@ -18,8 +17,8 @@
<separator colspan="4"/>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="terp-gtk-jump-to-ltr" string="Sign in" name="si_check" type="object" attrs="{'invisible':[('state','=','present')]}"/>
<button icon="terp-gtk-jump-to-rtl" string="Sign out" name="so_check" type="object" attrs="{'invisible':[('state','=','absent')]}"/>
<button icon="terp-gtk-jump-to-ltr" string="Sign in" widget="att_button" name="si_check" type="object" attrs="{'invisible':[('state','=','present')]}"/>
<button icon="terp-gtk-jump-to-rtl" string="Sign out" widget="att_button" name="so_check" type="object" attrs="{'invisible':[('state','=','absent')]}"/>
</group>
</form>
</field>
@ -66,7 +65,7 @@
<separator colspan="4" />
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-go-back" string="Sign in" name="sign_in" type="object"/>
<button icon="gtk-go-back" string="Sign in" name="sign_in" widget="att_button" type="object"/>
</group>
</form>
</field>
@ -86,7 +85,7 @@
<separator colspan="4" />
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-go-back" string="Sign out" name="sign_out" type="object"/>
<button icon="gtk-go-back" string="Sign out" name="sign_out" widget="att_button" type="object"/>
</group>
</form>
</field>

View File

@ -91,8 +91,8 @@
</field>
<group col="4" colspan="1">
<field name="state_attendance"/>
<button name="sign_in" string="Sign In" type="object" icon="terp-gtk-jump-to-ltr"/>
<button name="sign_out" string="Sign Out" type="object" icon="terp-gtk-jump-to-rtl"/>
<button name="sign_in" string="Sign In" type="object" icon="terp-gtk-jump-to-ltr" widget="att_button"/>
<button name="sign_out" string="Sign Out" type="object" icon="terp-gtk-jump-to-rtl" widget="att_button"/>
<field name="total_attendance_day" widget="float_time" colspan="4"/>
</group>
<field colspan="4" context="{'date':date_current,'user_id':user_id}" domain="[('name','=',date_current)]" name="timesheet_ids" nolabel="1">