DataProcessor doesn´t work

Hello everybody,

I tried to code an own RIA, basend on the demo “WebAppsToday”, but the dataprocessor will not work. I try to understand, how does it work, but I am a newbee in coding javascript. This is my code
JavaScript

dhxWins = new dhtmlXWindows();

// Layout
ablLayout = new dhtmlXLayoutObject(document.body, "1C");
ablLayout.cells("a").setText("Auftragsbestandsliste");

// Grid Master
ablGridMaster = ablLayout.cells("a").attachGrid();
ablGridMaster.setImagePath("../../dhtmlx/imgs/");
ablGridMaster.setHeader("Kommission,NeubauNr,Kunde,Liefertermin,KW,Auftragsart,Bestellung,Beschreibung");
ablGridMaster.attachHeader("#text_filter,#text_filter,#select_filter,#text_filter,#select_filter,#select_filter, ,, ");
ablGridMaster.setInitWidths("75,120,150,80,90,150,*,*");
ablGridMaster.setColAlign("right,left,left,right,right,left,left,left");
ablGridMaster.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro");
ablGridMaster.setColSorting("int,str,str,date,str,str,str,str");
ablGridMaster.enableMultiline(true);
ablGridMaster.init();
ablGridMaster.loadXML("master.xml");
ablGridMaster.attachEvent("onRowDblClicked", function (rID,cInd){
	if(!dhxWins.window("ablDetailsWin")){
		win = dhxWins.createWindow("ablDetailsWin",20,20,900,600);
		win.center();
		win.attachEvent("onClose",function(){
			win.hide;
			return true;
		});	
	}
	else
	win.show("ablDetailsWin");
	dhxWins.window("ablDetailsWin").setText("Auftrag "+rID);
	ablAccordion = win.attachAccordion(rID,cInd);
	ablAccordion.addItem("a1", "Auftrag");
	ablAccordion.addItem("a2", "Vertrieb");
	ablAccordion.addItem("a3", "Vertriebsabwicklung");
	ablAccordion.addItem("a4", "m. Konstruktion");
	ablAccordion.addItem("a5", "e. Konstruktion");
	ablAccordion.openItem("a1");
	
	// Form Auftrag
	auftragForm = ablAccordion.cells("a1").attachForm();
	auftragForm.loadStruct("auftragForm.xml");
	auftragForm.load("auftragDetails.php?id="+rID);
	
	// Form Vertrieb
	vertriebForm = ablAccordion.cells("a2").attachForm();
	vertriebForm.loadStruct("vertriebForm.xml");
	vertriebForm.load("vertriebDetails.php?id="+rID);

	// Form Vertriebsabwicklung
	vertriebsabwicklungForm = ablAccordion.cells("a3").attachForm();
	vertriebsabwicklungForm.loadStruct("vertriebsabwicklungForm.xml");
	vertriebsabwicklungForm.load("vertriebsabwicklungDetails.php?id="+rID);	
	
	// DP Auftrag
	var dpf_auftrag = new dataProcessor("auftragDetails.php");
	dpf_vertrieb.init(auftragForm);
	
	// DP Vertriebsabwicklung
	var dpf_vertriebsabwicklung = new dataProcessor("vertriebsabwicklungDetails.php");
	dpf_vertriebsabwicklung.init(vertriebsabwicklungForm);
	vertriebsabwicklungForm.attachEvent("onButtonClick", function(name, command){
		dpfs_vertriebsabwicklung.sendData();
	});
});

PHP

<?php
	require("../../dhtmlx/connector/form_connector.php");
	$res=mysql_connect("localhost","root","xxxxxxxxxx");
  mysql_select_db("besinet");
	$formConn = new FormConnector($res);
	$formConn->render_table("ablvertriebsabwicklung","BelegNummer","Auftragswert,geliefert,bezahlt,Restwert,Kuerzel,Art,Bemerkungen");
?>

xml Form

<?xml version="1.0"?>
<items>
	<item type="input" name="Auftragswert" bind="Auftragswert" label="Auftragswert" width="150" rows="3"/>
	<item type="input" name="geliefert" bind="geliefert" label="geliefert" width="150" rows="3"/>
	<item type="input" name="bezahlt" bind="bezahlt" label="bezahlt" width="150" rows="3"/>
	<item type="input" name="Restwert" bind="Restwert" label="Restwert" width="65"/>
	<item type="input" name="Kuerzel" bind="Kuerzel" label="Kuerzel" width="55"/>
	<item type="input" name="Art" bind="Art" label="Art" width="20"/>
	<item type="input" name="Bemerkungen" bind="Bemerkungen" label="Bemerkungen" width="400" rows="5"/>
	<item type="button" xcommand="save" value="Submit" />
</items>

Loading data from db to form works fine, but it is not possible to make an update. I think the form data will not send but I am not sure. Can anybody help me?
Kindly regards,
Daniel

a) try to enable log in the php file, it will give you some more info about loading|updating

in php
$formConn = new FormConnector($res);
$formConn->enable_log(“log.txt”);

b) your client side code works correctly, but if it still not sending anything to server side, try to add the next line before sendData command

vertriebsabwicklungForm.resetDataProcessor(“updated”);
dpfs_vertriebsabwicklung.sendData();

Hi Stanislav,

thanks for your answere. This is the code of the logfile

====================================
Log started, 30/06/2011 11:06:47
====================================

SELECT BelegNummer,Auftragswert,geliefert,bezahlt,Restwert,Kuerzel,Art,Bemerkungen FROM ablvertriebsabwicklung WHERE BelegNummer = '2001731'

Done in 0.0018389225006104s

I see, there is a select statement only, but no update code. I am sorry, but I don´t know why. In addition i modified my code with

vertriebsabwicklungForm.resetDataProcessor("updated");

to

// DP Vertriebsabwicklung
var dpf_vertriebsabwicklung = new dataProcessor("vertriebsabwicklungDetails.php");
dpf_vertriebsabwicklung.init(vertriebsabwicklungForm);
vertriebsabwicklungForm.attachEvent("onButtonClick", function(name, command){
vertriebsabwicklungForm.resetDataProcessor("updated");
dpfs_vertriebsabwicklung.sendData();
});

but it will not work, sorry

In your original code you have 2 form, but only 1 dataprocessor.
If you need to send both of them to server side, you need to have dataprocessors for each form.

also, in your code

dpf_vertriebsabwicklung = new dataProcessor(“vertriebsabwicklungDetails.php”);
but
dpfs_vertriebsabwicklung.sendData();

names are different ( second one has dpfs )

Hi Stanislav,

You are right, I played with some parameters to solve my problem and posted wrong code. But in this case, I know my mistake. After compare my code with code from the Tutorial “WebAppsToday” I found, why I got a select statement only in the logfile. After fixing, my logfile looks like this

====================================
Log started, 01/07/2011 08:07:59
====================================

SELECT BelegNummer,Auftragswert,geliefert,bezahlt,Restwert,Kuerzel,Art,Bemerkungen FROM ablvertriebsabwicklung WHERE BelegNummer = '2001731'

Done in 0.0026650428771973s



====================================
Log started, 01/07/2011 08:07:16
====================================

DataProcessor object initialized
1309502219147_Auftragswert => 20.000 EUR
1309502219147_geliefert => 1st part
1309502219147_bezahlt => 
1309502219147_Restwert => 
1309502219147_Kuerzel => 
1309502219147_Art => 0
1309502219147_Bemerkungen => Hello World
1309502219147_!nativeeditor_status => inserted
ids => 1309502219147

Row data [1309502219147]
Auftragswert => 20.000 EUR
geliefert => 1st part
bezahlt => 
Restwert => 
Kuerzel => 
Art => 0
Bemerkungen => Hello World
!nativeeditor_status => inserted

INSERT INTO ablvertriebsabwicklung(Auftragswert,geliefert,bezahlt,Restwert,Kuerzel,Art,Bemerkungen) VALUES ('20.000 EUR','1st part','','','','0','Hello World')

Edit operation finished
0 => action:error; sid:1309502219147; tid:1309502219147;

Done in 0.0056531429290771s

Now I get an INSERT statement, but how to tell him, that I need a database UPDATE? This is my edited code.

			function buildInterface(){
				dhxWins = new dhtmlXWindows();
		
				// Layout
				ablLayout = new dhtmlXLayoutObject(document.body, "1C");
				ablLayout.cells("a").setText("Auftragsbestandsliste");
		
				// Grid Master
				ablGridMaster = ablLayout.cells("a").attachGrid();
				ablGridMaster.setImagePath("../../dhtmlx/imgs/");
ablGridMaster.setHeader("Kommission,NeubauNr,Kunde,Liefertermin,KW,Auftragsart,Bestellung,Beschreibung");
				ablGridMaster.attachHeader("#text_filter,#text_filter,#select_filter,#text_filter,#select_filter,#select_filter,&nbsp;,,&nbsp;");
				ablGridMaster.setInitWidths("75,120,150,80,90,150,*,*");
				ablGridMaster.setColAlign("right,left,left,right,right,left,left,left");
				ablGridMaster.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro");
				ablGridMaster.setColSorting("int,str,str,date,str,str,str,str");
				ablGridMaster.enableMultiline(true);
				ablGridMaster.init();
				ablGridMaster.loadXML("xml/master.xml");
				ablGridMaster.attachEvent("onRowDblClicked", function (rID,cInd){
					if(!dhxWins.window("ablDetailsWin")){
						win = dhxWins.createWindow("ablDetailsWin",20,20,900,600);
						win.center();
						win.attachEvent("onClose",function(){
							win.hide;
							return true;
						});	
					}
					else
						win.show("ablDetailsWin");
						dhxWins.window("ablDetailsWin").setText("Auftrag "+rID);
			
					// Accordion 
					ablAccordion = win.attachAccordion(rID,cInd);
					ablAccordion.addItem("a1", "Auftrag");
					ablAccordion.addItem("a2", "Vertrieb");
					ablAccordion.addItem("a3", "Vertriebsabwicklung");
					ablAccordion.addItem("a4", "m. Konstruktion");
					ablAccordion.addItem("a5", "e. Konstruktion");
					ablAccordion.openItem("a1");
			
					// Form Auftrag
					auftragForm = ablAccordion.cells("a1").attachForm();
					auftragForm.loadStruct("xml/auftragForm.xml");
					auftragForm.load("xml/auftragDetails.php?id="+rID);
			
					// Form Auftrag
					vertriebForm = ablAccordion.cells("a2").attachForm();
					vertriebForm.loadStruct("xml/vertriebForm.xml");
					vertriebForm.load("xml/vertriebDetails.php?id="+rID);
			
					// Form Vertriebsabwicklung
					vertriebsabwicklungForm = ablAccordion.cells("a3").attachForm();
					vertriebsabwicklungForm.loadStruct("xml/vertriebsabwicklungForm.xml");
					vertriebsabwicklungForm.load("xml/vertriebsabwicklungDetails.php?id="+rID);		
			
					// DataProcessor Form Auftrag
					var dpf_auftrag = new dataProcessor("xml/auftragDetails.php");
					dpf_auftrag.init(auftragForm);
			
					// DataProcessor Form Vertrieb
					var dpf_vertrieb = new dataProcessor("xml/vertriebDetails.php");
					dpf_vertrieb.init(vertriebForm);
	
					// DataProcessor Form Vertriebsabwicklung
					var dpf_vertriebsabwicklung = new dataProcessor("xml/vertriebsabwicklungDetails.php");
					dpf_vertriebsabwicklung.init(vertriebsabwicklungForm);	
			
					// DataProcessor Form Send Vertriebsabwicklung
					var dpfs_vertriebsabwicklung = new dataProcessor("xml/vertriebsabwicklungDetails.php");
					dpfs_vertriebsabwicklung.init(vertriebsabwicklungForm);
					vertriebsabwicklungForm.attachEvent("onButtonClick", function(name, command){
						dpfs_vertriebsabwicklung.sendData();
					});
				});
			}
			dhtmlxEvent(window,"load", buildInterface);

The code for the form

<?xml version="1.0"?>
<items>
	<item type="input" name="Auftragswert" bind="Auftragswert" label="Auftragswert" width="150" rows="3"/>
	<item type="input" name="geliefert" bind="geliefert" label="geliefert" width="150" rows="3"/>
	<item type="input" name="bezahlt" bind="bezahlt" label="bezahlt" width="150" rows="3"/>
	<item type="input" name="Restwert" bind="Restwert" label="Restwert" width="65"/>
	<item type="input" name="Kuerzel" bind="Kuerzel" label="Kuerzel" width="55"/>
	<item type="input" name="Art" bind="Art" label="Art" width="20"/>
	<item type="input" name="Bemerkungen" bind="Bemerkungen" label="Bemerkungen" width="400" rows="5"/>
	<item type="button" xcommand="save" value="Submit" />
</items>

and the php code

<?php
	require("../../../dhtmlx/connector/form_connector.php");
	$res=mysql_connect("localhost","root","XXXXXXXX");
  mysql_select_db("besinet");
	$formConn = new FormConnector($res);
	$formConn->enable_log("log.txt");
	$formConn->render_table("ablvertriebsabwicklung","BelegNummer","Auftragswert,geliefert,bezahlt,Restwert,Kuerzel,Art,Bemerkungen");
?>

Can you tell me, why I don´t get an UPDATE statement, but an INSERT?
Kindly regards from Germany

Just change the order of loading and move

vertriebsabwicklungForm.load(“xml/vertriebsabwicklungDetails.php?id=”+rID);

after

dpfs_vertriebsabwicklung.init(vertriebsabwicklungForm);

in such case dataprocessor will known about data loading, and will correctly set status to updated

Great, that´s it. Thank you very much for your help.