Page 1 of 1

ajax vs triggers

PostPosted: Tue Oct 09, 2012 2:55 am
by Jean
Hi Steve and all of you,
I am building a timetable for agents with different desks in a library.

To be able to add someone somewhere at some time, I need to remove him/her from an other desk (if so) at the same time so that nobody be in two spots at the same time ;=)
The timetable is built first , so any delete or add action of an agent is just an update on the table in the good box.

So every time someone is added on a desk I need to scan the same column of time and remove him/her from the other desks before with a beforeUpdate() method.
Besides a unique index on the database table prevents someone to be in two premisses at the same time.

The problem here is that ajax prevents me from doing any action like adding someone if this agent is yet on an other desk at the same time, ignoring my beforeUpdate action of removing from any other desk because the update action only is checked up.

Do you follow me ?

Thank you for any help

Jean

Re: ajax vs triggers

PostPosted: Tue Oct 09, 2012 9:34 am
by silma
You could create a virtual user ?

BeforeUpdate :
Generate an unique Mister Virtual###
Look for your user old place in the same column of time, update it to "Mister Virtual###"

Re: ajax vs triggers

PostPosted: Wed Oct 10, 2012 1:04 am
by Jean
Thank you Silma, unfortunately, the problem is that the whole operation is checked up by ajax before executing it and so it returns false because it cannot save data in the table.

Jean

Re: ajax vs triggers

PostPosted: Wed Oct 10, 2012 1:52 am
by silma
Unless a technical solution from Steve to disable the ajax only fort this action, i can see nothing else to do but "to cheat " with the date.

=> add ten year to the date the user want with js

=> Save = Add the next one + 10 year
=> BeforeUpdate , update the old record (-10 year)
=> AfterUpdate, update the date - 10 year

I admit it is awful...

Re: ajax vs triggers

PostPosted: Wed Oct 10, 2012 5:13 am
by Jean
smart! thank you. I keep your solution in mind.

Jean

Re: ajax vs triggers

PostPosted: Tue Oct 23, 2012 12:29 am
by Jean
Steve,
I come back on this question. What would you do to delete a record in a column with a unique index before add it on an other line ? There is an opposition between ajax check-up and the beforeSave action.
Thank you

Jean

Re: ajax vs triggers

PostPosted: Fri Oct 26, 2012 8:52 am
by shannah
Hi Jean,

Which ajax action is being used to perform the save? Is this the "Ajax inline editing" feature?

Re: ajax vs triggers

PostPosted: Tue Oct 30, 2012 7:24 am
by Jean
Thank you Steve.
In fact I am building a timetable for librarians. I have a unique index on each time unit (30mns). To add someone at a desk at some time, I have to remove him/her of an other desk on the same time to be sure he/she is not at two spots at the same time.
I don't delete, I just update to add or remove.
I created a beforeUpdate trigger to remove the person from an other desk on the same time. In fact before executing the request, Ajax checks up the result which is false because each column has a unique index and cannot have the same data twice.
Jean

Re: ajax vs triggers

PostPosted: Tue Oct 30, 2012 9:03 am
by shannah
Are you using a custom action for updating these values, or a Xataface built-in action? If Xataface, which action?

Re: ajax vs triggers

PostPosted: Wed Oct 31, 2012 7:03 am
by Jean
Hi Steve,
I don't use a custom action but I use custom links in the list to access the edit form. I have a filter and had some problems with -skip and -cursor.
You think this could explain my problems ?

Jean

Re: ajax vs triggers

PostPosted: Wed Oct 31, 2012 7:44 am
by shannah
So to be clear. You are linking to the edit record form. Then when you make changes on this edit record form, it fails because the validation refuses to let you continue?

Where does AJAX come in?

Re: ajax vs triggers

PostPosted: Wed Oct 31, 2012 8:24 am
by Jean
ajax checks up the request and stops everything bacause the data is yet in the same column thant should be unique although my beforeUpdate remove it.

Code: Select all
function beforeUpdate(&$record){
$this->app =& Dataface_Application::getInstance();
$result= mysql_query("UPDATE quinzaines SET tranche12=NULL WHERE jour='$jour' AND tranche12='$tranche'" , $this->app->db());
}