PDA

View Full Version : Unable to save window co-ordinates from subviews


akdwivedi
09-21-2007, 02:20 AM
Hi All,
I am trying to save the co-ordinates of the window and retrive them on a load. I follow the procedure as follows :

1) Click a button which will traverse all the visible "subview" and take their x,y,width, height parameters, then calls a function
2) Method called ::

<method name="sendData_win" param="x,y,width,height">

var ds = canvas.datasets.dssave;
var query = new LzParam();
query.addValue( 'x', x, false );
query.addValue( 'y', y, false );
query.addValue( 'width', width, false );
query.addValue( 'width', height, false );
ds.setQueryString( query );
ds.doRequest();

</method>
<!-- Button which calls the method -->
<button y="140" x="10" width="100">Save

<handler name="onclick">
<![CDATA[

var x_save=10;
var y_save=10;
var subs_act = canvas.scr.panel.subviews;

for(var i = 0; i < subs_act.length; i++) {
if(subs_act[i].visible ){
x_save = subs_act[i].x;
y_save = subs_act[i].y;
Debug.write( "Subs for Panel ::"+subs_act[i] +" -- X ::" + x_save + " -- Y ::" + y_save + "W ::"+ subs_act[i].width
+ " H ::" + subs_act[i].height + " ID ::" + subs_act[i].activity_name );
// if class instance in myclass
if(subs_act[i] = "myclass" ) {
canvas.sendData_win(x_save,y_save,50,50);
}
}
}

]]>
</handler>
</button>



My problem is that if there are 3 windows I get only the last one saved in the database. Moreover if I move the windows click the button again, I don't save anything.

Please advice me if my approach is correct or I need to do it any other way.

Thanks and Regards,
Abhi.

dabdala
09-21-2007, 11:12 AM
I'm not versed over Laszlo, but some comments that arises from your code:

- You are sending allways the same data (x,y,w,h) without identifying each window, so depending of how you implemented the backend, you are "overwriting" the same data over and over (resulting in only one registry of data).
- How do you know (on initialization) wich data corresponds to wich view?
- In the if(subs_act[i] = "myclass") you are making an asignment, it should be if(subs_act[i] == "myclass"), and I think that that won't work. Won't subs_act[i] return an object, how can you compare that to a class name??

Well, hope this help.
Bye.

akdwivedi
09-21-2007, 11:19 AM
=dabdala;33927
- You are sending allways the same data (x,y,w,h) without identifying each window, so depending of how you implemented the backend, you are "overwriting" the same data over and over (resulting in only one registry of data).
- How do you know (on initialization) wich data corresponds to wich view?e.
I have an ID attribute which I forgot to place here in the code. The strange thing is when I click the button for the below code, I get the values populated, but on subsequent click, the values for attributes come as "undefined" even though I get the Class name.


<button y="140" x="10" width="100">Save
<method event="onclick">

<![CDATA[
var x_save=10;
var y_save=10;
var subs_act = canvas.scr.panel.subviews;
for(var i = 0; i < subs_act.length; i++) {
var class_name=subs_act[i];
var what_vis = class_name.getAttribute('visible');
Debug.write("What is Class name :: " + class_name);
Debug.write("What is visible :: " + what_vis);
Debug.write("What is ID :: " + class_name.id);
Debug.write("What is X :: " + class_name.x);
Debug.write("What is Y :: " + class_name.y);

if((class_name instanceof Activity) && (what_vis == true )){
x_save = subs_act[i].x;
y_save = subs_act[i].y;

Debug.write( "Subs for Panel ::"+subs_act[i] +" -- X ::" + x_save + " -- Y ::" + y_save + "W ::"+ subs_act[i].width
+ " H ::" + subs_act[i].height );

}
}
]]>
</method>
</button>

notzippy
09-21-2007, 12:51 PM
Does the dataset used set "queuerequests"=true ?
In your second response change the following : , Can you debug the object ? (ie click on it ?)
Debug.write("What is Class name :: " , class_name);

akdwivedi
09-21-2007, 12:57 PM
Does the dataset used set "queuerequests"=true ?

I have it set to false.

In your second response change the following : Can you debug the object ? (ie click on it ?)
Debug.write("What is Class name :: " , class_name);

I can click the object and debug it but only on first click not on subsequent clicks. But as my code for button above, I get the results in Debug for all the vaules, but if I click again I get this ::

What is Class name :: Activity
What is visible :: undefined
What is ID :: undefined
What is ID :: undefined
What is ID :: undefined
What is ID :: undefined

I also get the following warning :
WARNING: test_ver1.lzx:201: reference to undefined property 'x'

Please advice

akdwivedi
09-22-2007, 11:45 AM
Anyone please guide me, I have searched in the forum, but did not get any clue.
If my approach is incorrect, please point me to the correct approach I can follow.

Thanks,
Abhi.

dabdala
09-24-2007, 09:45 AM
I test this:
<canvas>
<view name="scr">
<view name="panel">
<window name="w1" x="10" y="20" width="100" height="80"/>
<window name="w2" x="20" y="80" width="200" height="40"/>
<window name="w3" x="40" y="100" width="300" height="180"/>
</view>
</view>
<button y="140" x="10" width="100">Save
<method event="onclick">

<![CDATA[
var x_save=10;
var y_save=10;
var subs_act = canvas.scr.panel.subviews;
for(var i = 0; i < subs_act.length; i++) {
var class_name=subs_act[i];
var what_vis = class_name.getAttribute('visible');
Debug.write("What is Class name :: " + class_name);
Debug.write("What is visible :: " + what_vis);
Debug.write("What is ID :: " + class_name.id);
Debug.write("What is X :: " + class_name.x);
Debug.write("What is Y :: " + class_name.y);

if((what_vis == true )){
x_save = subs_act[i].x;
y_save = subs_act[i].y;

Debug.write( "Subs for Panel ::"+subs_act[i] +" -- X ::" + x_save + " -- Y ::" + y_save + "W ::"+ subs_act[i].width
+ " H ::" + subs_act[i].height );

}
}
]]>
</method>
</button>
</canvas>
and works just fine, so your problem is somewhere else:
- the class?
- the subviews?

don't know, but is not in this code.

akdwivedi
09-24-2007, 09:48 AM
Hi Dabdala,
Thanks for the reply , I also tried the same thing by removing class_name instanceof Activity from the code and its works for me too. I am not sure why this strange behavior is comming into picture.

Any idea.

Abhi.

akdwivedi
09-24-2007, 02:05 PM
Hi Dabdala,
Thanks for the reply , I also tried the same thing by removing class_name instanceof Activity from the code and its works for me too. I am not sure why this strange behavior is comming into picture.

Any idea.

Abhi.

May I request someone to guide me is this a bug or something, as when I use the "instanceof" it does not work. Ultimately I had to add an attribute to the class to find out what is the base class.

Abhi.

senshi
09-25-2007, 11:48 AM
Do you have any reproducible testcase for your "instanceof" problems?

This works for me so far:

<canvas debug="true" >

<class name="class1" extends="node" />
<class name="class2" extends="node" />
<class name="class11" extends="class1" />
<class name="class111" extends="class11" />

<class1 id="inst1" />
<class2 id="inst2" />
<class11 id="inst11" />
<class111 id="inst111" />

<handler name="oninit" ><![CDATA[
Debug.write("inst1 instanceof lz.node", inst1 instanceof lz.node);
Debug.write("inst1 instanceof class1", inst1 instanceof class1);

Debug.write("inst2 instanceof lz.node", inst2 instanceof lz.node);
Debug.write("inst2 instanceof class2", inst2 instanceof class2);

Debug.write("inst11 instanceof lz.node", inst11 instanceof lz.node);
Debug.write("inst11 instanceof class1", inst11 instanceof class1);
Debug.write("inst11 instanceof class11", inst11 instanceof class11);

Debug.write("inst111 instanceof lz.node", inst111 instanceof lz.node);
Debug.write("inst111 instanceof class1", inst111 instanceof class1);
Debug.write("inst111 instanceof class11", inst111 instanceof class11);
Debug.write("inst111 instanceof class111", inst111 instanceof class111);
]]></handler>

</canvas>

akdwivedi
09-25-2007, 01:30 PM
Hi Senshi,
I am not having the code currently, but will post it tomorrow, so that you can have an idea.

Abhi.