Data Entry Methods Using the cm_form_widget Package The CMS cm_form_widget package can be used to generate metadata forms for creating items or adding revisions to existing items. Registering Content Type Attributes to a Form Widget In order for CMS to be able to generate the metadata forms, it is necessary for each attribute of a content type to be registered to a form widget via the register_attribute_widget procedure. cm_form_widget.register_attribute_widget( content_type => 'book_report', attribute_name => 'summary', widget => 'textarea', is_required => 'f' ); content_type used to identify the appropriate form widget. attribute_name is the name of the attribute, used to identify the appropriate form widget. widget is the form widget used to input a value for a content type attribute. See documentation for ATS form widgets for more info. is_required is a flag indicating whether or not a value is required for the attribute form widget. By default, attribute form widgetes are not required. Customizing the Form Widget Using register_attribute_widget will use the default values for the form widget. Usually these default values will be sufficient, but sometimes it may be necessary to customize the form widget with the set_attribute_param_value procedure. cm_form_widget.set_attribute_param_value( content_type => 'book_report', attribute_name => 'summary', param => 'rows', param_type => 'onevalue', param_source => 'literal', value => 10 ); content_type used to identify the appropriate form widget. attribute_name is the name of the attribute, used to identify the appropriate form widget. param is one of the following: an HTML tag corresponding to a specific form widget (rows for textarea, size for select widgets, maxlength for text boxes, ...) an ATS form element tag (refer to the documentation for template::element::create for more info. param_type is one of the following: 'onevalue' - The parameter has one value. 'onelist' - The parameter is a list of values. 'multilist' - The parameter is a list of lists of values. param_source is one of the following: 'literal' - The value parameter is treated literally 'eval' - The value parameter is a block of Tcl code that will be evaluated to produce the actual value(s) for the form widget param. 'query' - The value parameter is a SQL query which returns a datasource corresponding to the actual value(s) for the form widget param. Example - Creating a MIME type pick list for content revisions To create a pick list of MIME types for the 'mime_type' attribute of the 'content revision' content type: begin -- register the attribute to a pick list cm_form_widget.register_attribute_widget( content_type => 'content_revision', attribute_name => 'mime_type', widget => 'select', is_required => 't' ); -- set the 'options' list cm_form_widget.set_attribute_param_value( content_type => 'content_revision', attribute_name => 'mime_type', param => 'options', param_type => 'multilist', param_source => 'query', value => 'select label, map.mime_type from cr_mime_types types, cr_content_mime_type_map map where types.mime_type = map.mime_type and content_type = :content_type order by label' ); -- set the 'size' param cm_form_widget.set_attribute_param_value( content_type => 'content_revision', attribute_name => 'mime_type', param => 'size', param_type => 'onevalue', param_source => 'eval', value => 'a_tcl_proc_that_gets_the_pick_list_size' ); end; / show errors Using Metadata Forms The CMS is able to generate and process metadata forms based on the form widgets registered to each attribute of a content type. If the metadata forms are not sufficient, custom forms can be supplied instead. Creating Auto-generated Metadata Forms Generating the metadata forms for creating content items and adding revisions is done by calling the Tcl procedure: content::get_revision_form db content_type item_id form_name The function generates a form based on form widgets associated with the content type's attributes. If the item_id is null, then an item_id will be generated automatically. Example: # a metadata form for creating new "book report" content types. form create create_book_report element create create_book_report item_id -datatype integer set db [ns_db gethandle] content::get_revision_form $db book_report $item_id create_book_report ns_db releasehandle $db if { [form is_request create_book_report] } { query item_id onevalue "select acs_object_id_seq.nextval from dual" element set_properties create_book_report item_id -value $item_id } Processing Metadata Forms Processing the metadata forms for creating content items and adding revisions is done by calling the Tcl function: set revision_id [content::process_revision_form form_name content_type item_id db] The function creates an instance of a basic revision, and then inserts rows into each extended attribute related to that content type. The function returns the ID of the revision that was just created. Example: # process a metadata form for adding a revision to "book report" content types if { [form is_valid add_revision] } { form get_values add_revision item_id set db [ns_db gethandle] set revision_id [content::process_revision_form add_revision book_report $item_id $db] ns_db releasehandle $db template::forward "view_book_report_revision.acs?revision_id=$revision_id" } Form Elements The function content::create_form_element may be used to automatically generate a form element based on the registered form widget for the element. This function is useful if you wish to create a custom form for your content type, while still relying on the automatically generated widgets (as discussed above) for some elements. The function signature is as follows: proc content::create_form_element { db form_name attribute_name args } { ... } The parameters to the function are as follows: Parameter Purpose db The database handle to be used for querying form_name The name of the form to which the element will be appended. The form must have been previously created with the form create statement. attribute_name The name of the attribute for which the form element is to be created. The form element will have the same name as the attribute. The function also accepts the following switches: Switch Value Purpose -revision_id A revision id, integer The id of the revision which will be used to determine the value for the attribute. This revision will also be used to discover the content type for the item. -item_id An item id, integer The id of the item whose live revision will be used to determine the value for the attribute. -content_type An object type The content type of the object to which the attribute belongs any other switch A value appropriate for the switch Any other switches will be passed directly to the element create statement. All the switches above are optional; however, at least one of the -content_type, -revision_id or -item_id must be specified (in order for the function to determine the content type of the object). If -revision_id or -item_id are specified, the value of the created form element will be selected from the specified revision in the database. Note that content::create_form_element will not automatically perform DML for you in order to update the database; the DML must be performed manually in your custom form. Example Usage: content::create_form_element $db my_form width -revision_id $revision_id The above code will append a new element, called "width" to the form named "my_form". It will use the database handle contained in $db and the revision id specified in $revision_id in order to display the default value for the element. Index Page The generic index page, located at /cms/modules/items/index is simply a skeleton layout that includes all available information components (see next section). (The released system will allow the administator to specify the components shown to each user of the system). In cases where the generic page is inadequate, you can define your own custom information page at /cms/modules/items/custom/<content_type>/index. Whenever the generic index page is requested, the system checks for the existence of a custom page and redirects to it if it is found. Note that from there you may link to any number of additional custom display pages, stored in the same directory or elsewhere. The only required parameter to your custom page should be item_id.