Chapter 7. Toolkits for the user interface

Table of Contents

Auto forms
tk_autoform_init ()
tk_autoform_create_widget ()
tk_autoform_create_form ()
tk_autoform_list_results ()
tk_autoform_list_search_results ()
List move
Range editor
tk_range_edit_select ()
tk_range_edit_call ()
tk_range_edit_all_selected ()
An example widget
Editor for records without references
tk_record_edit_init ()
tk_record_edit ()
dbi search
tk_dbisearch_init ()
form_dbisearch ()
File selector box
tk_fsb_init ()
tk_fsb ()
dbconf editor
tk_dbconf_init ()
tk_dbconf ()
Tree editor
Tree lister
tk_dbobj_ls_init ()
tk_dbobj_ls ()
HTML template toolkit
Tags
Extensions

Toolkits are modules for the user interface. They contain an initialisation function that must be called from your applications' init() function. Each toolkit function or page function starts with 'tk_', to distinguish them from the user's modules, followed by the module name and the function name. Initialisation functions always end with '_init'. So the name of the init function of the autoform toolkit is tk_autoform_init. All init functions take a reference to the application class as the first and only parameter and need a reference to the user interface in $this->ui.

  function init ()
  {
    $this->define_my_tables ();
    $this->ui = admin_panel ($this, 'My admin title');
    tk_autoform_init ($this);
    $this->add_my_views ();
  }
    

Auto forms

The autoform toolkit creates form based on SQL table definitions stored in dbdepend.class objects. autoform cannot be used with other interfaces than dbi.

The table definitions might contain an entry with key 'auto_form'. If it contains the keyword 'hide', the field is never listed or used in forms.

  $def->define_table (
    'locations',
    array (array ('n' => 'id',
                  # Do not show id in autoform widgets.
                  'auto_form' => array ('hide' => true),
                  'd' => 'ID',
                  't' => 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY'),
           array ('n' => 'id_parent',
                  'i' => true,
                  't' => 'INT NOT NULL'),
           array ('n' => 'name',
                  'i' => true,
                  't' => 'VARCHAR(255) NOT NULL'),
    )
  );
  $def->set_primary ('locations', 'id');
      

tk_autoform_init ()

void tk_autoform_init (&$this);
	

tk_autoform_create_widget ()

void tk_autoform_create_widget (&$this, $table, $field);
	

Print a row with a label and input widget for a field in a table.

tk_autoform_create_form ()

void tk_autoform_create_form (&$this, $source = '');
	

Calls tk_autoform_create-widget() for all fields in a table.

tk_autoform_list_results ()

void tk_autoform_list_results (&$this, $config);
	

This function display a table of all results specified by a former call to admin_panel::query(). Array $config contains the following entries:

  • $fields is an array of field names that should be displayed. If its not set, all fields are listed.

  • $call is the name of the view to call when selecting a record with argument named $id containing the records primary key.

  • If an entry called head_fields exists, it must contain one or more table header strings keyed by field name. If a header string is not specified for a particular field, itis taken from the database description.

  • If an array called 'cell_functions' exists, it must contain an array of one or more functions keyed by field name, which display the according fields. If no function is specified for a field, it is just printed with label().

tk_autoform_list_search_results ()

void tk_autoform_list_search_results (&$this, $config);
	

This function calls tk_autoform_list_results() to display the last search results from form function form_dbisearch().