Forum OpenACS Q&A: Re: Any xowiki demo?

Collapse
4: Re: Any xowiki demo? (response to 3)
Posted by Gustaf Neumann on
The xowiki-tutorial contains a CRUD example for xowiki, and after all, an xowiki::Form is a subclass of xowiki::Page.

To which "repo" for "xotcl" are you referring?

-g

Collapse
5: Re: Any xowiki demo? (response to 4)
Posted by Gustaf Neumann on
btw, i have added an additional page containing the basic steps for creating a custom form field.
Collapse
6: Re: Any xowiki demo? (response to 4)
Posted by Antonio Pisano on
This one: git://alice.wu-wien.ac.at/xotcl-demo-note
Collapse
7: Re: Any xowiki demo? (response to 6)
Posted by Antonio Pisano on
Let me explain what I think I have understood:

- One creates a ::xowiki::Form, which should be the 'specification' of our object. In plain xotcl, this was done in the data model + ::Generic::Form definition.

- Once defined the ::xowiki::Form, one calls http://myserver/xowiki/<form-INSTANCE-NAME-HERE>>?m=create-new to create the object, and ...?m=edit to edit. The instances we are creating are of class ::xowiki::FormPage

This instead is what I still can't grasp:

how do I define a form suitable for an object like the one in xotcl demo? It's the bare sintax that I am missing...

...
...Xotcl demo snippets
...
...xotcl data model
::xo::db::CrClass create Note -superclass ::xo::db::CrItem \
-pretty_name "Demo Note" -pretty_plural "Demo Notes" \
-slots {
::xo::db::CrAttribute create number -datatype integer -default 0
}

...xotcl form
::Generic::Form create form1 -volatile \
-data $item \
-with_categories true \
-fields {
{item_id:key}
{name:text {label Name}}
{number:text {label Number}}
{text:richtext(richtext),nospell,optional {label Content} {options {editor xinha}}}
{description:text(textarea),nospell,optional {label Description} {html {cols 60 rows 2}}}
}

Collapse
8: Re: Any xowiki demo? (response to 7)
Posted by Gustaf Neumann on
An xowiki::Form is not a "specification" of an object, but a user-interface for an object (data container), defining its "edit" and "view" behavior. As implemented, the object containing the data has to be a an xowiki::FormPage (xowiki::PageInstance), which receives the data as a dict. The page containing the data knows the form via the attribute template. By using xowf, one can relax the 1:n relationship between data-container and to form to a n:n relationship, where one can associate the data-container with various xowiki::Forms depending on state, user, etc.

The xowiki::Form is part of xowiki and integrated with the xowiki infrastructure. I have invested no effort to interface xowiki::Forms to generic acs objects (non cr objects) like the one you have sketched above.

Collapse
9: Re: Any xowiki demo? (response to 8)
Posted by Antonio Pisano on
Ok, so ipotetically I could define some logic into a ::xowiki::PageInstance or ::xowiki::FormPage, maybe subclassing, then obtain a gui from that by ::xowiki::Form?

Maybe that is too much for me... but could ease a lot of stuff in the future!

Snippets above come from the very xotcl-demo, and the object there is subclass of CrItem. Can I connect CrItems to ::xowiki::Form or maybe something like CrItem -> FormPage -> Form? If yes, how?

Thanks for your help

Collapse
10: Re: Any xowiki demo? (response to 9)
Posted by Gustaf Neumann on
Separating xowiki::Form from and xowiki::FormPage is a certain challenge. When i have some more resources free, i can try to address this problem, maybe together with the xotcl 2.* transition. But as a first step, we need the release of a non-beta version of xotcl 2.

Trying to subclass the Note demo under e.g. xowiki::FormPage does not make much sense. It is much easier to define the fields you want for the Note example in a xowiki::Form, configure away the fields that you do not want, and use "fill-out" to create instances. If you need fast access to the form fields from the database, use hstore. One drawback is that you get this way the semantics of the content-repository (with e.g. revisions, search integration, etc), which you might not want. If you want more control over the submit-buttons, actions, etc., use xowf.

Collapse
11: Re: Any xowiki demo? (response to 10)
Posted by Antonio Pisano on
Ok, I am getting something more now...

My problem now is that I can't find any example of instantiation of ::xowiki::Form by code, and I can't figure out which parameters supply... Is there any snippet from some code?

I could put it into docs

Collapse
12: Re: Any xowiki demo? (response to 11)
Posted by Antonio Pisano on
I had already found some exported forms here: http://openacs.org/file/1440073/form.export.export . Alas, they are not working on current XoWiki.

Looking further, I finally found this: http://alice.wu-wien.ac.at:8000/xowiki/download/file/xowiki-forms.examples

This was exactly what I was looking for! I've linked the examples in XoWiki doc page to ease the struggle for the posterity.

Collapse
13: Re: Any xowiki demo? (response to 12)
Posted by Gustaf Neumann on
Hi Antonio.

These are exports of xowiki instances, and not thought for humans! In applications, you will have different IDs, but most of these are provided as well automatically. Please look at the following example. I've added this as well to

http://alice.wu-wien.ac.at:8000/s5-xowiki-tutorial/slides#listing-form-create

all the best
-g

#
# Sample snippet to show, how to create an 
# ::xowiki::Form programmatically
#

# Get package_id by initializing the package
::xo::Package initialize -url /xowiki

set template {
  @listing@
}
set fc {
  listing:code_listing
}

# Create a form instance in memory
set form_id [::xowiki::Form new -destroy_on_cleanup \
             -package_id $package_id \
             -parent_id [$package_id folder_id] \
             -name "en:sample.form" \
             -anon_instances "f" \
             -form {} \
             -text [list $template text/html] \
             -form_constraints $fc]

# save the form to the root folder of the package
$form_id save_new

Collapse
14: Re: Any xowiki demo? (response to 13)
Posted by Antonio Pisano on
Thanks for the example!

Don't worry, I've stated clearly that those forms are meant to be imported into xowiki, rather than being used in code directly. I've found them useful to show some advanced form specification.