Re: [fw-general] Question regarding dojo forms rendered in templates called via xhr.

2009-01-09 Thread Mustafa A. Hashmi
On Thu, Jan 8, 2009 at 5:50 PM, Matthew Weier O'Phinney
matt...@zend.com wrote:
 On Thursday 08 January 2009 12:22:31 Mustafa A. Hashmi wrote:
 I am in the process of switching our application to make use of dojo
 forms, however, am having some issues with forms which are rendered
 via xhr requests. In a nutshell:

 a) Layout is rendered and the index action renders a dojo form which
 works perfectly fine.
 b) After submitting the form, the user manually follows a link which
 calls a JS function and loads the required action template in a
 specified div.
 c) The loaded dojo form in the resulting div however doesn't seem to
 be 'dojo enabled'. The form does render, albeit without any styles or
 dijit functionality.

 When using XHR to retrieve (X)HTML content that will be injected into
 the DOM, you need to do two things:

  1) Any dojo modules that the new content uses must already be loaded
 (i.e., the dojo.require calls should already have occurred).
 Because of how Zend_Dojo works, anything aggregated in the dojo
 view helper will not be sent in the payload (unless you explicitly
 include it). Additionally, HTML content pulled by XHR ignores any
 scripts attached -- which means even if you did return the dojo
 view helper payload, it wouldn't be executed. So your initial
 payload must have all the requisite dojo.require statements.

As you demonstrate in your pastebin app, I too am gearing the app for
a light js library build, hence all required modules that the app
needs are specified explicitly for loading. The front controller is
initialized with the installer module plugin which instantiates the
view and sets required modules / paths / view helpers, etc.

dojo.provide(installer.layer);
(function() {
dojo.require(dijit.layout.ContentPane);
dojo.require(dijit.layout.BorderContainer);
...

 For this reason, it's also best to turn on declarative markup for
 any XHR payloads -- since the programmatic elements will not be
 present. You can do this with the following:

Zend_Dojo_View_Helper_Dojo::setUseDeclarative(true);

Also done during front controller initialization of the view obj.

  2) You need to run the dojo parser over the returned content. If
 you're pulling the content into a ContentPane, you can do this by
 setting the parseOnLoad property of that pane to true. Otherwise,
 make sure you have the dojo.parser module loaded, and call:

dojo.parser.parse(dom node containing retrieved content);

I was doing every one of the things you recommended, barring the
dojo.parser.parse bit. Once the response is injected into the relevant
dom node, I simply ran the parser over said node and everything came
alive.

Thank you Matthew, much appreciated!
--
Mustafa A. Hashmi


Re: [fw-general] Question regarding dojo forms rendered in templates called via xhr.

2009-01-08 Thread Benjamin Eberlei
that is a javascript specific problem. If you load stuff via XHR
you have to reattach all the events to it, because they have not been 
registered.

all the content inside the loaded div has not been dojo eventized lets call 
it, so no javascript is happening there. you have to reattach all events to 
that specific elements.

greetings,
Benjamin

On Thursday 08 January 2009 12:22:31 Mustafa A. Hashmi wrote:
 Hi all,

 I am in the process of switching our application to make use of dojo
 forms, however, am having some issues with forms which are rendered
 via xhr requests. In a nutshell:

 a) Layout is rendered and the index action renders a dojo form which
 works perfectly fine.
 b) After submitting the form, the user manually follows a link which
 calls a JS function and loads the required action template in a
 specified div.
 c) The loaded dojo form in the resulting div however doesn't seem to
 be 'dojo enabled'. The form does render, albeit without any styles or
 dijit functionality.

 Please note: initialization of application is based on Matthew Weier
 O'Phinney's excellent pastebin app.

 I pasted the relevant sections @: http://www.pastebin.ca/1303381

 The entire application source can be viewed at:

 http://bazaar.launchpad.net/~mhashmi/zivios/devel/files  (please
 see the 'installer' module).

 Also: I had made quite a few attempts to selectively load the required
 dojo modules (with dojo.addOnLoad), but for some reason I am not
 getting it right. I am also confused about setting dojo to
 declarative mode in the view template when we have already done so
 in the predispatch action...

 Any help would be much appreciated.

 Thanks,
 --
 Mustafa A. Hashmi

-- 
Benjamin Eberlei
http://www.beberlei.de


Re: [fw-general] Question regarding dojo forms rendered in templates called via xhr.

2009-01-08 Thread Mustafa A. Hashmi
On Thu, Jan 8, 2009 at 4:25 PM, Benjamin Eberlei kont...@beberlei.de wrote:
 that is a javascript specific problem. If you load stuff via XHR
 you have to reattach all the events to it, because they have not been
 registered.

 all the content inside the loaded div has not been dojo eventized lets call
 it, so no javascript is happening there. you have to reattach all events to
 that specific elements.

Many thanks for the speedy response. I actually did try the
addOnLoad calls and requireModule calls from within the template,
however, I am obviously missing more of the required glue. Will try
again and share my attempts if I can't go further.

Also: noticed that pastebin is up to 1.3.0 (i was referencing 1.0.0),
so will look there for pointers as well.

Thanks again.


 On Thursday 08 January 2009 12:22:31 Mustafa A. Hashmi wrote:
 Hi all,

 I am in the process of switching our application to make use of dojo
 forms, however, am having some issues with forms which are rendered
 via xhr requests. In a nutshell:

 a) Layout is rendered and the index action renders a dojo form which
 works perfectly fine.
 b) After submitting the form, the user manually follows a link which
 calls a JS function and loads the required action template in a
 specified div.
 c) The loaded dojo form in the resulting div however doesn't seem to
 be 'dojo enabled'. The form does render, albeit without any styles or
 dijit functionality.

 Please note: initialization of application is based on Matthew Weier
 O'Phinney's excellent pastebin app.

 I pasted the relevant sections @: http://www.pastebin.ca/1303381

 The entire application source can be viewed at:

 http://bazaar.launchpad.net/~mhashmi/zivios/devel/files  (please
 see the 'installer' module).

 Also: I had made quite a few attempts to selectively load the required
 dojo modules (with dojo.addOnLoad), but for some reason I am not
 getting it right. I am also confused about setting dojo to
 declarative mode in the view template when we have already done so
 in the predispatch action...

 Any help would be much appreciated.

 Thanks,
 --
 Mustafa A. Hashmi

 --
 Benjamin Eberlei
 http://www.beberlei.de



Re: [fw-general] Question regarding dojo forms rendered in templates called via xhr.

2009-01-08 Thread Matthew Weier O'Phinney
On Thursday 08 January 2009 12:22:31 Mustafa A. Hashmi wrote:
 I am in the process of switching our application to make use of dojo
 forms, however, am having some issues with forms which are rendered
 via xhr requests. In a nutshell:

 a) Layout is rendered and the index action renders a dojo form which
 works perfectly fine.
 b) After submitting the form, the user manually follows a link which
 calls a JS function and loads the required action template in a
 specified div.
 c) The loaded dojo form in the resulting div however doesn't seem to
 be 'dojo enabled'. The form does render, albeit without any styles or
 dijit functionality.

When using XHR to retrieve (X)HTML content that will be injected into
the DOM, you need to do two things:

  1) Any dojo modules that the new content uses must already be loaded
 (i.e., the dojo.require calls should already have occurred).
 Because of how Zend_Dojo works, anything aggregated in the dojo
 view helper will not be sent in the payload (unless you explicitly
 include it). Additionally, HTML content pulled by XHR ignores any
 scripts attached -- which means even if you did return the dojo
 view helper payload, it wouldn't be executed. So your initial
 payload must have all the requisite dojo.require statements.

 For this reason, it's also best to turn on declarative markup for
 any XHR payloads -- since the programmatic elements will not be
 present. You can do this with the following:

Zend_Dojo_View_Helper_Dojo::setUseDeclarative(true);

  2) You need to run the dojo parser over the returned content. If
 you're pulling the content into a ContentPane, you can do this by
 setting the parseOnLoad property of that pane to true. Otherwise,
 make sure you have the dojo.parser module loaded, and call:

dojo.parser.parse(dom node containing retrieved content);


-- 
Matthew Weier O'Phinney
Software Architect   | matt...@zend.com
Zend Framework   | http://framework.zend.com/