[ic] TIPS: Use [table-editor] + mv_metadata to take inches off your waist while you sleep!

Zack Johnson interchange-users@interchange.redhat.com
Fri Sep 28 16:19:00 2001


1. Create and configure mysql table
-----------------------------------

See my TIPS: Adding mysql tables for directions.

2. Open up a text editor.
-------------------------

This one ought to be easy.  If not, I'm sorry, but you'll have to put this
down.


3. Add the basics to make this page look like one of your other pages.
----------------------------------------------------------------------

Type, copy or paste into your text editor:

 [comment]
  ui_template: Yes
  ui_template_name: leftonly
 [/comment]

Please save.

4. Add the [table-editor] tag.
------------------------------

This tag makes your life easy by building the form, and updating the table
as needed.

 [table-editor
  href=process
  mv_nextpage=@@MV_PAGE@@

  table=foo
  key="bar"
  ui_data_fields="bar1 bar2 bar3..."

 ]

    You'll want to substitue your table name for 'foo'.  The key value
should be just that,

the key value.  This is how [table-editor] find the record your looking for.
In

ui_data_fields, you list the fields you want in the form.

    For example, let's suppose your new table is 'airport_codes'.  I has two
fields,

'airport_code' and 'name'.  We want to edit record for 'JAX':

 [table-editor
  href=process
  mv_nextpage=@@MV_PAGE@@

  table=airport_codes
  key="JAX"
  ui_data_fields="airport_code name"

 ]

    A page will then display which contains a form that lets us edit this
record.  When you

submit the form, IC will update the DB record.

5. Set data restrictions.
-------------------------

[table-editor] lets you perform data validation.  Let's require the 'name'
value.

 [table-editor
  href=process
  mv_nextpage=@@MV_PAGE@@

  table=airport_codes
  key="JAX"
  ui_data_fields="airport_code name"

  check.name = "required Please enter a location name"

 ]

6.  Customize the table layout.
-------------------------------

[table-editor] features some nifty features.  If your table includes more
than just a few

fields, it's going to start looking very unfriendly.

You can break up the table using ui_break_before.  This option inserts a
colored band

before a specified field.  And, using ui_break_before_label, you can insert
a nice section

heading.  In this example I will insert a break before each field:

 [table-editor
  href=process
  mv_nextpage=@@MV_PAGE@@

  table=airport_codes
  key="JAX"
  ui_data_fields="airport_code name"

  check.name = "required Please enter a location name"

  ui_break_before = "airport_code name"
  ui_break_before_label = "airport_code=Airport Code,name=Airport Name"

 ]

You will also notice a row of buttons at the TOP of your table.  This might
be unwanted.

To turn them off, use no_top:

 [table-editor
  href=process
  mv_nextpage=@@MV_PAGE@@

  table=airport_codes
  key="JAX"
  ui_data_fields="airport_code name"

  check.name = "required Please enter a location name"

  ui_break_before = "airport_code name"
  ui_break_before_label = "airport_code=Airport Code,name=Airport Name"

  no_top=1

  ui_display_only="property_id"

 ]

To turn off the display of the key field, use ui_hide_key:

 [table-editor
  href=process
  mv_nextpage=@@MV_PAGE@@

  table=airport_codes
  key="JAX"
  ui_data_fields="airport_code name"

  check.name = "required Please enter a location name"

  ui_break_before = "airport_code name"
  ui_break_before_label = "airport_code=Airport Code,name=Airport Name"

  no_top=1

  ui_display_only="property_id"

  ui_hide_key=1

 ]

You can also create wizards with [table-editor].  For information, take a
look at the

wizard directory under the admin pages.  step_company.html will get you
started.

At the end of this page you'll find all of the options for [table-editor].
Many of them

are self-explanatory.

7. Edit mv_metadata for your new table.
---------------------------------------

If you want your table to look nice, you'll need to forray into mv_metadata.
Don't groan,

it's not so bad.  We'll just do two things with it: one practical, the other
practical too.

 First, we'll apply labels to the fields.  This makes them look pretty.
Second, we'll use

the contents of a table to pull in options for a <select> HTML tag.

1.  Pretty Labels

If you haven't already, create a mv_metadata entry for your table.  Go to
Administration >

Tables > mv_metadata > New Entry.  In the first box, code (labelled
'Table::Column'), enter

the name of your table.  Under 'label', enter the label you would like for
this field.

 For example:

 Table::Column new_table
 Label  A New Table

2.  Happy Select Boxes

Let's say we want to let the user specify and airport_code in their userdb.
Assume we've

made the necessary modifications to userdb.  If we want to pull in the
values in our

airport_codes table for our select box, we would modify userdb::airport_code
in mv_metadata

like so:

 Table::Column userdb::airport_code
 Type  Select Box
 Lookup Table airport_codes
 Label  Preferred Airport
 Lookup Select airport_code,name

The last entry, Lookup Select, tells table_editor the values to pull out of
airport_code

for our select.  Remeber, select only takes two items: the "value" and the
"label".  The

value is what goes into the database, the label is what shows up in the
dropdown.  In the

Lookup Select field, the first item becomes the value, the second becomes
the label.  In

our example, the database records "JAX" when the user selects "Jacksonville,
FL".

Don't forget to "apply changes" after you made your modifications.
Otherwise, mv_metadata

will.

Good luck!

*******************************************

ALL OPTIONS:

  [table-editor
               table=ic_table
               cgi=1*
               item-id="key"
               across=n*
               noexport=1*

               wizard=1*
               next_text='Next -->'*
               cancel_text='Cancel'*
               back_text='<-- Back'*

               hidden.formvarname="value"

               item_id_left="keys remaining"
               mv_blob_field=column*
               mv_blob_nick=name*
               mv_blob_pointer="current name"*
               mv_blob_label="Label text"
               mv_blob_title="Title HTML"

               ui_break_before="field1 field2"
               ui_break_before_label="field1=Label 1, field2=Label 2"
               ui_data_fields="field1 field2 fieldn ..."*
               ui_data_fields_all=1*
               ui_display_only="no_set_field"*
               ui_hide_key=1*
               ui_meta_specific=1*
               ui_meta_view="viewname"
               ui_nextpage="next_destination"
               ui_prevpage="back_destination"
               ui_return_to="cancel_destination"
               ui_new_item=1*
               ui_sequence_edit=1*
               ui_clone_id="key"
               ui_clone_tables="table1 table2 ..."
               ui_delete_box=1*
               mv_update_empty=0*

               widget.field="select|text|any ic widget"
               label.field="Field Label"
               help.field="Help text"
               help-url.field="http://url/to/more/help"
               default.field="preset value"*
               override.field="forced value"*
               filter.field="filter1 filter2"
               pre-filter.field="filter1 filter2"
               error.field=1*
               height.field=N