NAME

RDF::Base::Widget::Handler

DESCRIPTION

For parsing and acting on HTML forms and HTML widgets, or just the CGI query.

update_by_query

  $class->update_by_query( \%args )

Calls /session_history_add if base node is given.

Overall plan:

update_by_query maps through all parameters in the current request. It sorts into 4 groups, depending on what the parameter begins with:

 1. Add / update properties  (arc/prop/image)
 2. Complemnt those props with second order atributes (row)
 3. Check if some props should be removed (check)
 4. Add new resources (newsubj)
 5. Let classes handle themselves

Returns: the number of changes

1. Add / update

Parameters beginning with arc_ or prop_

select

Used when there are several versions of an arc, to activate selected version (by value) and remove the rest. Eg: arc_select => 1234567 will activate arc 1234567 and remove all other versions of that arc.

Example tt-code: [% hidden("version_${arc.id}", version.id); radio("arc_${arc.id}__pred_${arc.pred.name}", version.id, 0, { id = version.id, }) %]

files / images

Images are to be uploaded as a filefield, and are saved to the "logos"-folder

The image can be scaled proportianally to fit within certain max-dimensions in pixels by having parameters maxw and maxh. A typical image-parameter would be:

 arc_singular__file_image__pred_logo_small__maxw_400__maxh_300__row_12

Filenames are made of name (or id) on subj and a counter (first free number). Suffix is preserved.

TODO: Add possibility of using a row to set other filename.

parameter_in_value

The parameter_in_value is a way to to extract parameters from values. Eg in select, you could use:

<select name="parameter_in_value"> <option value="arc___subj_12335__pred_is=5412354">Set is for 12345</option> <option value="arc___subj_54321__pred_is=5412354">Set is for 54321</option> </select>

2. Complemnt those props with second order atributes (row)

Parameters beginning with row_

This is for adding propertis with the arc as subj or obj, or the arcs subj as subj or obj or the arcs obj as subj or obj.

row_#__subj_arc__...

row_#__subj_subj__...

row_#__subj_obj__...

4. Add new resources

To create a new resource and add arcs to it, the parameters should be in the format "newsubj_$key__pred_$pred", where $key is used to group parameters together. $key can be prefixed with "main_". At least one $key should have the main-prefix set for the new resource to be created. $pred can be prefixed with "rev_".

Example1: Adding a new node if certain values are set

 Params
 newsubj_main_contact__pred_contact_next => 2006-10-05
 newsubj_contact__pred_is => C.contact_info.id
 newsubj_contact__pred_rev_contact_info => org.id

...where 'contact' is the key for the newsubj, regarding all with the same key as the same node. A new resource is created IF at least one main-parameter is supplied (no 1 above). There can be several main-parameters. If no main-parameter is set, the other newsubj-parameters with that number are ignored.

5. Let classes handle themselves

Existing resources

Class-resources that wish to handle their own update_by_query can be specified with:

 hidden('class_update_by_query', my_node.id)

Then that resource will be called by:

 my_node->class_update_by_query( $q );

New class resources

For new class-resources to be created, a key property can be specified with:

 hidden('class_new_by_query', my_class.id)

Then that class will be called by:

 my_class->class_new_by_query( $q );

The class then has to check for it's own parameters to see if a new resource is to be created or not etc.

Parameter naming-convention

To easily handle many classes etc at the same time, it is preferrable if you follow those naming conventions:

 1. For existing class resources, prefix all parameters with
    class_[% class.label %]__subj_[% resource.id %]__
 2. For new class resources, prefix with
    class_[% class.label %]__newsubj_[% key %]__

Supported args are:

  res

Field props:

arc desig file if unless is lang newsubj parse pred revpred row select scof subj type vnode

lang

A language-code; Set the language on this value (as an arc to the value-node).

if

Examples:

  if_subj

  if_obj

  if_subj_obj

  if_12345

  if_12345_methodname

You may have multipple if arguments, in which case all must be true in order to process the field.

subj : true if subj is not empty()

obj : true if obj is not empty()

12345 : looks up the node with given id. If it's an arc, we check if it's active. If its a nother type of node, we check if its not empty.

12345_methodname : methodname must be a method that doesn't take any arguments. It checks that the method returns a true value. Example of methods are; submitted, inactive, active, old, etc.

unless

Works like /if but checks for falsehood instead.

handle_query_arc

  $class->handle_query_arc( $param, \%args )

Returns the number of changes

handle_query_arc_value

  $n->handle_query_arc_value( $param, $value, \%args )

Default subj is $args->{'node'} or 'new_node'.

If this is a reverse arc, the subj will be handled as an obj.

Returns: the number of changes

handle_query_prop

  $class->handle_query_prop( $param, \%args )

Return number of changes

handle_query_prop_value

  $class->handle_query_prop_value( $param, $value, \%args )

Return number of changes

TODO: translate this to a call to handle_query_arc

handle_query_row

  $n->handle_query_row( $param, \%args )

Return number of changes

handle_query_row_value

  $class->handle_query_row_value( $param, $value, \%args )

Return number of changes

This sub is mainly about setting properties for arcs. The subjct is an arc id. This can be used for saying that an arc is inactive.

handle_query_check_row

  $class->handle_query_check_row( $param, \%args )

Return number of changes

handle_query_check_arc

  $class->handle_query_check_arc( $param, $arc_id, \%args )

Return number of changes

handle_query_check_node

  $class->handle_query_check_node( $param, $node_id, \%args )

Return number of changes

handle_query_check_require

  $class->handle_query_check_require( $param, \%args )

Return number of changes

handle_query_check_prop

  $class->handle_query_check_prop( $param, $pred_in, \%args )

handle_query_check_revprop

  $n->handle_query_check_revprop( $param, $pred_name, \%args )

Return number of changes

handle_query_newsubjs

  handle_query_newsubjs( $q, $param, \%args )

Return number of changes

SEE ALSO

RDF::Base, RDF::Base::Arc, RDF::Base::Pred, RDF::Base::List, RDF::Base::Search, RDF::Base::Literal::Time