custom form CrossOptionConnector

Hi there,

     I'm currently building my own custom form (which I've included a screenshot of for clarity purposes) and, for the most part, everything works fine. In my database, I have three tables like this:

tblUsers --------------->tblpmcc<------------------ tblpmtodo

Now most of the data goes straight into the tblpmtodo and it’s saved just fine by calling:

scheduler.endLightbox(true, html(“my_form”));

However, now I’m stuck trying to save the data located in the various CC zones… which of course, goes into the tblpmcc table. Back when I was still using the default lightbox, I was using a multiselect control along with a CrossOptionConnector to do the job… however now that I have my own set of personalized controls, I have to do this treatment myself (at least I think so).

So, the question I have is actually quite simple… where do I call my code to save the CC into the database?

Thanks in advance

Osu


Hello,

If you are using dhtmlxConnector then you can use one of it’s events, e.g. BeforeProcessing and in there do additional inserts/updates.

Best regards,
Ilya

I think it might make more sense in my case to use the AfterProcessing event since I need the Todo to be physically inserted before inserting the CC. That’s because I need the database TodoId, not the scheduler’s temporary ID in my query.

Still, how do I access my lightbox fields from my bound function? I figured the DataAction object the function receives might have something to do with it… but where do I do the mapping for it? How do I give my custom function the values of my lightbox fields?

Hi,

Your are right, in this case AfterProcessing makes more sense (actually CrossOptionConnector uses it itself).

Check out more information on the DataAction Object page.

Basic things which you will need:

$action->get_new_id(); // new id after insert operation $action->get_value('text'); // event properties (text, start_date, end_date and everything what is mapped to your lightbox) $action->get_status(); // inserted, updated, deleted
Best regards,
Ilya

Thanks a lot, I almost have everything figured out. There’s two things I’m still wondering about. First of all, is the DataAction object given to the function the equivalent of the object I receive with this line?

var ev = scheduler.getEvent(scheduler.getState().lightbox_id);

Next, since the CC fields aren’t meant to go into the same table as the rest of the Todo, I haven’t mapped them to anything as of yet. However, if the “ev” variable corresponds to the “$action” variable, I was thinking of doing the mapping myself in the save_form() by doing something like this:

ev.set_field("CC1", html("form_control"));
ev.set_field("CC2", html("form_control2"));
...

And then, once my afterProcessing() function is called, the $action object I received would have what I’m looking for and I would be able to insert my lines into the database with something like this:

$requete = "INSERT INTO tblpmcc (TodoId, NoPersonne) values(" . $action->get_new_id() . ", " . $action->get_value('CC1') . ")";
mysql_query($requete) or die(mysql_error());

Am I on the right track?

Thanks a lot for the quick responses by the way, you’re really a life saver :slight_smile:

the DataAction object given to the function the equivalent of the object I receive with this line
Not exactly , but you can use $action->get_value(“name”) and fetch any of properties, which “var ev” has.

I haven’t mapped them to anything as of yet
if you mean mapping in the client side configuration - it is necessary only for data loading. All custom properties of event will be available on server side, and you can fetch them in afterProcessing handler.

on client side

ev.cc1 = “123”;

on server side

$action->get_value(“cc1”); //will return 123

That’s what I thought :slight_smile:. However, my problem is that there is no ev.CC1 property, thus my need to make it exist one way or another. Furthermore, the number of CC fields there is will never be the same since as soon as the user clicks on the green “+” at the right of a line, it adds another set of controls. That’s why I thought of adding these fields to the “ev” variable in the save_form() function.

So how do I add the CC1 property to the ev variable? Or does it exists even if it hasn’t been specified by the $scheduler->render_table() statement?

Hello,

If property was assigned to the event object then it will be available on the server side. It doesn’t matter if it was listed in the render_table() statement.

So how can you add such property to the event?
For example:

scheduler.attachEvent("onEventSave",function(id,data,is_new_event){ var ev = scheduler.getEvent(id); // custom logic which will check and get all CC fields and their values // example only: ev.cc_length = 0; for(var i=0; i<cc_fields.length; i++) { ev['cc'+i] = cc_fields[i].value; ev.cc_length = i+1; } });
Now on the server side you can access ‘cc_length’ property which will tell you if there are any cc fields and with it you can do something with cc1…ccN through a loop. So if ‘cc_length’ == 0 then no cc fields were added, ‘cc_length’ == 1 — then there is a property cc0 and so on.

Best regards,
Ilya

Thanks a lot for your precious advice :slight_smile:. Thanks to that, I was able to successfully add the value of my field to the event object. However, now I have trouble figuring out if I correctly connected my function to the AfterProcessing event (well okay, I obviously did something wrong since otherwise I wouldn’t be asking he he he). Here’s what I did:

<?php
	require_once('js/scheduler/codebase/connector/scheduler_connector.php');
	//require_once('js/scheduler/codebase/connector/crosslink_connector.php');
	
	include ('include/connect.php');
	
	function insertCC($action)
	{
		//if ($action->get_status() == "update")
		//{
			$requete = "INSERT INTO tblpmcc (TodoId, NoPersonne) values(" . $action->get_id() . ", " . $action->get_value('lstCC1') . ")";
			mysql_query($requete) or die(mysql_error());
		//}
	}
	
	//include ('../../common/config.php');
	
	//$res=mysql_connect($server, $user, $pass);
	//$res=mysql_connect("localhost", "root", "flex2010");
	//mysql_select_db("flexgroup");
	$sqlEmployes = "SELECT NoPersonne as value, NomPersonne as label FROM tblcartetempspersonnes where Statut = 1 order by NomPersonne asc";
	$sqlClients = "SELECT NoClient as value, NomClient as label FROM tblcartetempsclients where Statut = 1 order by NomClient asc";
	$sqlDivisions = "select 0 as value, '' as label from tblcartetempsdivisions where 1 union SELECT NoDivision as value, NomDivision as label FROM tblcartetempsdivisions order by label asc";

	//$cross = new CrossOptionsConnector($conn);
	$scheduler = new schedulerConnector($conn);
	$listeEmployes = new OptionsConnector($conn);
	$listeClients = new OptionsConnector($conn);
	$listeDivisions = new OptionsConnector($conn);

	$listeEmployes->render_sql($sqlEmployes, "NoPersonne", "NoPersonne(value),NomPersonne(label)");
	$listeClients->render_sql($sqlClients, "NoClient", "NoClient(value), NomClient(label)");
	$listeDivisions->render_sql($sqlDivisions, "NoDivision", "NoDivision(value), NomDivision(label)");
	//$cross->options->render_sql($sqlEmployes,"NoPersonne","NoPersonne(value),NomPersonne(label)");
	//$cross->link->render_table("tblpmcc","TodoId", "NoPersonne,TodoId");
	
	$scheduler->set_encoding("iso-8859-1");
	$scheduler->enable_log("log.txt",true);
	$scheduler->set_options("listeEmployes", $listeEmployes);
	$scheduler->set_options("listeClients", $listeClients);
	$scheduler->set_options("listeDivisions", $listeDivisions);
	//$scheduler->set_options("listeCC", $cross->options);
	$scheduler->render_table("tblpmtodo","TodoId",
	"StartDateTime,EndDateTime,Etiquette,Description,Notes,ANoPersonne,Reminder,ADroitPersonne,ReminderDateTime,DeNoPersonne,NoClient,NoDivision,PrcComplete,Priorite,CalendrierStrategique");
	
	$scheduler->event->attach("afterProcessing", "insertCC");
	
?>

I activated the log in the hope that I would be able to discern what went wrong, but there’s absolutely no trace of it even trying to touch my tblpmcc table:



====================================
Log started, 08/11/2010 09:11:20
====================================

DataProcessor object initialized
23_id => 23
23_start_date => 2010-10-27 12:40
23_end_date => 2010-10-27 12:45
23_text => TODO - 1288970160373
23_Description => ggghg
23_Notes => ghghghggh
23_ANoPersonne => 5
23_Reminder => 1
23_ADroitPersonne => 3
23_ReminderDateTime => 1899-11-30 00:00
23_DeNoPersonne => 64
23_NoClient => 53
23_NoDivision => 
23_PrcComplete => 0
23_Priorite => 1
23_CalendrierStrategique => 0
23_lstCC1 => 64
23_!nativeeditor_status => updated
ids => 23

Row data [23]
TodoId => 23
StartDateTime => 2010-10-27 12:40
EndDateTime => 2010-10-27 12:45
Etiquette => TODO - 1288970160373
Description => ggghg
Notes => ghghghggh
ANoPersonne => 5
Reminder => 1
ADroitPersonne => 3
ReminderDateTime => 1899-11-30 00:00
DeNoPersonne => 64
NoClient => 53
NoDivision => 
PrcComplete => 0
Priorite => 1
CalendrierStrategique => 0
lstCC1 => 64
!nativeeditor_status => updated

UPDATE tblpmtodo SET StartDateTime='2010-10-27 12:40',EndDateTime='2010-10-27 12:45',Etiquette='TODO - 1288970160373',Description='ggghg',Notes='ghghghggh',ANoPersonne='5',Reminder='1',ADroitPersonne='3',ReminderDateTime='1899-11-30 00:00',DeNoPersonne='64',NoClient='53',NoDivision='',PrcComplete='0',Priorite='1',CalendrierStrategique='0' WHERE TodoId='23'

Edit operation finished
0 => action:updated; sid:23; tid:23;

Done in 0.013406038284302s

There is however the lstCC1 property appearing which at least confirms that I was successful in adding the property correctly. However, I’m curious as to why nothing’s happening in tblpmcc. The worst part is that there’s no way for me to tell whether my function was actually called or not.

Anyway, any help would be greatly appreciated. Thanks in advance :slight_smile:.

Osu

Never mind, I found out I should put the “attach” statement before the “render_table” one, now it works like a charm :slight_smile:.

Hello,

You won’t see anything in the log as you are executing SQL statement ‘by hand’, not scheduler connector does it.
To get new id you should use $action->get_new_id().

Also note that I was a bit incorrect before:
$action->get_status() returns ‘inserted’, ‘updated’, ‘deleted’

Best regards,
Ilya

Thanks, it’s working now :slight_smile:

Just out of curiosity, I’m currently trying to load my CC from the database when I double-clic on an event and I can’t figure out what event to bind my function to. I’ve checked the CrossOption connector’s code and discovered the BeforeRender event and tried the following:

.....

function loadCC($data)
	{
		$requete = "SELECT * FROM tblpmcc WHERE TodoId = 23"; //hardcoded for test purposes, should be $data->get_id()
		$resultat = mysql_query($requete);
		$indice = 1;
		
		while($ligne = mysql_fetch_array($resultat))
		{
			$data->set_value("lstCC" . $indice, $ligne['NoPersonne']);
			$data->set_value("txtDateNotificationCC" . $indice, $ligne['CCDateNotification']);
			$data->set_value("optDroitCC" . $indice, $ligne[CCDroitPersonne]);
			$indice++;
		}
	}


$scheduler = new schedulerConnector($conn);
$scheduler->event->attach("afterProcessing", "insertCC");
$scheduler->event->attach("beforeRender", "loadCC");

......

This does not generate any mistake. However, I would have expected that the “set_value()” calls I made in my function would have translated to something like this in javascript:

ev.lstCC1
ev.txtDateNotification1
ev.optDroitCC1

However, I don’t see my fields anywhere. Have I done something wrong? Thanks in advance.

Osu

Hello,

Try it like this:

[code]function loadCC($data)
{
$requete = “SELECT * FROM tblpmcc WHERE TodoId = 23”; //hardcoded for test purposes, should be $data->get_id()
$resultat = mysql_query($requete);
$indice = 1;

while($ligne = mysql_fetch_array($resultat))
{
	$data->set_value("lstCC" . $indice, $ligne['NoPersonne']);
	$data->set_value("txtDateNotificationCC" . $indice, $ligne['CCDateNotification']);
	$data->set_value("optDroitCC" . $indice, $ligne[CCDroitPersonne]);
	$indice++;
}

}

public function prepareConfig($conn, $res, $config){
$config->add_field(“lstCC”);
$config->add_field(“txtDateNotificationCC”);
$config->add_field(“optDroitCC”);
}

$scheduler = new schedulerConnector($conn);
$scheduler->event->attach(“afterProcessing”, “insertCC”);
$scheduler->event->attach(“beforeRender”, “loadCC”);
$scheduler->event->attach(“beforeRenderSet”, “prepareConfig”);[/code]
Notice that I have attached to the new event - beforeRenderSet (it will be documented soon) which occurs even before ‘beforeRender’. Here we are adding three new fields which will be available for events in the scheduler. And in the ‘beforeRender’ function for every event and every field we are adding their values.

Hope this helps.

Best regards,
Ilya

Thanks a lot, it’s working now :smiley:. I didn’t think you actually needed both events for the thing to work so I used only one of them at a time. Anyway, just out of plain curiosity, what sort of object is the $config parameter of the BeforeRenderSet event? Is it a DataAction object or a DataItem? Considering there’s actually a set_field() method, I would tend to believe it to be a DataAction, but in this particular case, the set_field() takes only one parameter instead of two so I’m sort wondering.

Anyway, thanks a lot for the info and keep up the great work guys :slight_smile:.

Osu

just out of plain curiosity, what sort of object is the $config parameter of the BeforeRenderSet event?

Actually this is DataConfig object, which is normally not accessible for operations. It stores db field configuration, which was taken from render_table or render_sql command.