You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Christopher Oliver <re...@verizon.net> on 2003/07/06 01:15:33 UTC

Woody + Flowscript

I just checked in a first try at adding Flowscript support to Woody. 
This consists of two JS classes and one function:

function woody(form_function, form_definition, form_attribute)

This is the entry point to the Woody Flowscript support.  You call the 
"woody" function from your sitemap to create a new form, for example:

   <map:match pattern="form1.flow">
           <map:call function="woody">
             <map:parameter name="function" value="form1"/>
             <map:parameter name="form-definition" value="forms/form1.xml"/>
             <map:parameter name="attribute-name" value="form1"/>
           </map:call>
     </map:match>

The "function" parameter specifies the name of a JS function that will 
provide the form's flow. The "form-definition" parameter specifies the 
location of the Woody form definition of the form. The "attribute-name" 
parameter specifies the name of a request attribute that will be used to 
store the form. The specified function will be called with one 
parameter, the newly created form.

class Form

The form itself will be an instance of the JS class Form. This class has 
methods to show the form and to access its underlying model, to get the 
id of the current submit button, and to destroy it:


function show([String] uri, [Function] validator);

This method repeatedly shows the form until validation is complete. If 
the validator function is supplied it will be called to do additional 
validation.  The function will be called with one argument containing a 
reference to the form.



function getSubmitId()
Returns the id of the selected Woody Button widget.


function finish();

Destroys this form and releases all of its resources.

function getModel()

Returns a JS wrapper of the Woody Form Widget.


class Widget

JS wrapper of Woody widgets. Provides access to the properties of the 
Woody form widgets. The widgets may be accessed by id. In addition, the 
"repeater" and "multivalue" widgets may be accessed as if they were JS 
arrays.

I've added a complete sample of using Flowscript with Woody to the 
 Woody samples.

Here's the Flowscript source code for that sample:

cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/woody.js");

function form1(form) {
    var model = form.getModel();
    model.email = "bar@www.foo.com";
    model.somebool = true;
    model.account = 2;
    model.cowheight = 4;
    model.number1 = 1;
    model.number2 = 3;
   
    model.contacts[0].firstname = "Jules";
    model.contacts[1].firstname =  "Lucien";
    model.contacts[2].firstname = "Chris";
    model.drinks = ["Jupiler", "Coca Cola"];
   
    form.show("form1-display-pipeline", function(form) {
        print("submitId="+form.getSubmitId());
        switch(form.getSubmitId()) {
        case "remove-selected-contacts":
            {
                for (var i = model.contacts.length-1; i >= 0; i--) {
                    if (model.contacts[i].select) {
                        model.contacts.remove(i);
                    }
                }
            }
            break;
        case "add-contact":
            {
                model.contacts.length++;
            }
            break;
        default:
            return true;
        }
        return false;
    });
    print("visa="+model.visa);
    sendPage("form1-success-pipeline");
    form.finish();

}


Regards,

Chris


Re: Woody + Flowscript

Posted by Bruno Dumon <br...@outerthought.org>.
On Sun, 2003-07-06 at 20:19, Christopher Oliver wrote:
> Bruno Dumon wrote:
> 
> >On Sun, 2003-07-06 at 01:15, Christopher Oliver wrote:
> >  
> >
> >>I just checked in a first try at adding Flowscript support to Woody. 
> >>This consists of two JS classes and one function:
> >>
> >>    
> >>
> ><snipped the explanation/>
> >  
> >
> >>Regards,
> >>
> >>Chris
> >>    
> >>
> >
> >Really great work Chris, exquisite! Thanks a lot.
> >
> >  
> >
> Thanks. Note that this code will need to be updated when we switch to 
> the FOM. Also I didn't implement automated back/next navigation using 
> continuations yet. I think it would be nice if we could automatically 
> handle the encoding of continuation ids in the form and the processing 
> by the sitemap. The former can be done by the Woody generator (as hidden 
> form fields or in the submit url) and the latter by a special Flowscript 
> function or action. This is already the case with XMLForm/JXForms. The 
> Woody user would never have to deal with continuation ids directly at 
> all. What do you think?
> 

Sounds good to me. (Unfortunately I can't make any promises yet as to
when I'll be able to look into this).

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: Woody + Flowscript

Posted by Christopher Oliver <re...@verizon.net>.
Bruno Dumon wrote:

>On Sun, 2003-07-06 at 01:15, Christopher Oliver wrote:
>  
>
>>I just checked in a first try at adding Flowscript support to Woody. 
>>This consists of two JS classes and one function:
>>
>>    
>>
><snipped the explanation/>
>  
>
>>Regards,
>>
>>Chris
>>    
>>
>
>Really great work Chris, exquisite! Thanks a lot.
>
>  
>
Thanks. Note that this code will need to be updated when we switch to 
the FOM. Also I didn't implement automated back/next navigation using 
continuations yet. I think it would be nice if we could automatically 
handle the encoding of continuation ids in the form and the processing 
by the sitemap. The former can be done by the Woody generator (as hidden 
form fields or in the submit url) and the latter by a special Flowscript 
function or action. This is already the case with XMLForm/JXForms. The 
Woody user would never have to deal with continuation ids directly at 
all. What do you think?

Chris


Re: Woody + Flowscript

Posted by Bruno Dumon <br...@outerthought.org>.
On Sun, 2003-07-06 at 01:15, Christopher Oliver wrote:
> I just checked in a first try at adding Flowscript support to Woody. 
> This consists of two JS classes and one function:
> 
<snipped the explanation/>
> 
> Regards,
> 
> Chris

Really great work Chris, exquisite! Thanks a lot.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: Woody + Flowscript

Posted by Marc Portier <mp...@outerthought.org>.
Wow,

this was on my todo-list for some weeks from now

will surely have a look at it
(hoping even to be able to make time ahead of my schedule for this)

many thx,
-marc=

Christopher Oliver wrote:
> I just checked in a first try at adding Flowscript support to Woody. 
> This consists of two JS classes and one function:
> 
> function woody(form_function, form_definition, form_attribute)
> 
> This is the entry point to the Woody Flowscript support.  You call the 
> "woody" function from your sitemap to create a new form, for example:
> 
>   <map:match pattern="form1.flow">
>           <map:call function="woody">
>             <map:parameter name="function" value="form1"/>
>             <map:parameter name="form-definition" value="forms/form1.xml"/>
>             <map:parameter name="attribute-name" value="form1"/>
>           </map:call>
>     </map:match>
> 
> The "function" parameter specifies the name of a JS function that will 
> provide the form's flow. The "form-definition" parameter specifies the 
> location of the Woody form definition of the form. The "attribute-name" 
> parameter specifies the name of a request attribute that will be used to 
> store the form. The specified function will be called with one 
> parameter, the newly created form.
> 
> class Form
> 
> The form itself will be an instance of the JS class Form. This class has 
> methods to show the form and to access its underlying model, to get the 
> id of the current submit button, and to destroy it:
> 
> 
> function show([String] uri, [Function] validator);
> 
> This method repeatedly shows the form until validation is complete. If 
> the validator function is supplied it will be called to do additional 
> validation.  The function will be called with one argument containing a 
> reference to the form.
> 
> 
> 
> function getSubmitId()
> Returns the id of the selected Woody Button widget.
> 
> 
> function finish();
> 
> Destroys this form and releases all of its resources.
> 
> function getModel()
> 
> Returns a JS wrapper of the Woody Form Widget.
> 
> 
> class Widget
> 
> JS wrapper of Woody widgets. Provides access to the properties of the 
> Woody form widgets. The widgets may be accessed by id. In addition, the 
> "repeater" and "multivalue" widgets may be accessed as if they were JS 
> arrays.
> 
> I've added a complete sample of using Flowscript with Woody to the Woody 
> samples.
> 
> Here's the Flowscript source code for that sample:
> 
> cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/woody.js");
> 
> function form1(form) {
>    var model = form.getModel();
>    model.email = "bar@www.foo.com";
>    model.somebool = true;
>    model.account = 2;
>    model.cowheight = 4;
>    model.number1 = 1;
>    model.number2 = 3;
>      model.contacts[0].firstname = "Jules";
>    model.contacts[1].firstname =  "Lucien";
>    model.contacts[2].firstname = "Chris";
>    model.drinks = ["Jupiler", "Coca Cola"];
>      form.show("form1-display-pipeline", function(form) {
>        print("submitId="+form.getSubmitId());
>        switch(form.getSubmitId()) {
>        case "remove-selected-contacts":
>            {
>                for (var i = model.contacts.length-1; i >= 0; i--) {
>                    if (model.contacts[i].select) {
>                        model.contacts.remove(i);
>                    }
>                }
>            }
>            break;
>        case "add-contact":
>            {
>                model.contacts.length++;
>            }
>            break;
>        default:
>            return true;
>        }
>        return false;
>    });
>    print("visa="+model.visa);
>    sendPage("form1-success-pipeline");
>    form.finish();
> 
> }
> 
> 
> Regards,
> 
> Chris
> 

-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at              http://radio.weblogs.com/0116284/
mpo@outerthought.org                              mpo@apache.org