Beispiel #1
0
 /**
  * Return the generated form output.
  * @return Form HTML.
  */
 public static function get_form($args, $node)
 {
     data_entry_helper::$website_id = $args['website_id'];
     if (!empty($args['high_volume']) && $args['high_volume']) {
         // node level caching for most page hits
         $cached = data_entry_helper::cache_get(array('node' => $node->nid), HIGH_VOLUME_CACHE_TIMEOUT);
         if ($cached !== false) {
             $cached = explode('|!|', $cached);
             data_entry_helper::$javascript = $cached[1];
             data_entry_helper::$late_javascript = $cached[2];
             data_entry_helper::$onload_javascript = $cached[3];
             data_entry_helper::$required_resources = json_decode($cached[4], true);
             return $cached[0];
         }
     }
     self::$node = $node;
     self::$called_class = 'iform_' . $node->iform;
     // Convert parameter, defaults, into structured array
     self::parse_defaults($args);
     // Supply parameters that may be missing after form upgrade
     if (method_exists(self::$called_class, 'getArgDefaults')) {
         $args = call_user_func(array(self::$called_class, 'getArgDefaults'), $args);
     }
     // Get authorisation tokens to update and read from the Warehouse. We allow child classes to generate this first if subclassed.
     if (self::$auth) {
         $auth = self::$auth;
     } else {
         $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']);
         self::$auth = $auth;
     }
     // Determine how the form was requested and therefore what to output
     $mode = method_exists(self::$called_class, 'getMode') ? call_user_func(array(self::$called_class, 'getMode'), $args, $node) : '';
     self::$mode = $mode;
     if ($mode === self::MODE_GRID) {
         // Output a grid of existing records
         $r = call_user_func(array(self::$called_class, 'getGrid'), $args, $node, $auth);
     } else {
         if (($mode === self::MODE_EXISTING || $mode === self::MODE_EXISTING_RO || $mode === self::MODE_CLONE) && is_null(data_entry_helper::$entity_to_load)) {
             // only load if not in error situation.
             call_user_func_array(array(self::$called_class, 'getEntity'), array(&$args, $auth));
         }
         // attributes must be fetched after the entity to load is filled in - this is because the id gets filled in then!
         $attributes = method_exists(self::$called_class, 'getAttributes') ? call_user_func(array(self::$called_class, 'getAttributes'), $args, $auth) : array();
         $r = call_user_func(array(self::$called_class, 'get_form_html'), $args, $auth, $attributes);
     }
     if (!empty($args['high_volume']) && $args['high_volume']) {
         $c = $r . '|!|' . data_entry_helper::$javascript . '|!|' . data_entry_helper::$late_javascript . '|!|' . data_entry_helper::$onload_javascript . '|!|' . json_encode(data_entry_helper::$required_resources);
         data_entry_helper::cache_set(array('node' => $node->nid), $c, HIGH_VOLUME_CACHE_TIMEOUT);
     }
     return $r;
 }
 /**
  * Helper function to collect javascript code in a single location. Should be called at the end of each HTML
  * page which uses the data entry helper so output all JavaScript required by previous calls.
  *
  * @return string JavaScript to insert into the page for all the controls added to the page so far.
  *
  * @link http://code.google.com/p/indicia/wiki/TutorialBuildingBasicPage#Build_a_data_entry_page
  */
 public static function dump_javascript()
 {
     // Add the default stylesheet to the end of the list, so it has highest CSS priority
     if (self::$default_styles) {
         self::add_resource('defaultStylesheet');
     }
     self::setup_jquery_validation_js();
     $dump = self::internal_dump_javascript(self::$javascript, self::$late_javascript, self::$onload_javascript, self::$required_resources);
     // ensure scripted JS does not output again if recalled.
     self::$javascript = "";
     self::$late_javascript = "";
     self::$onload_javascript = "";
     return $dump;
 }
 /**
  * Helper function to collect javascript code in a single location. Should be called at the end of each HTML
  * page which uses the data entry helper so output all JavaScript required by previous calls.
  *
  * @return string JavaScript to insert into the page for all the controls added to the page so far.
  *
  * @link http://code.google.com/p/indicia/wiki/TutorialBuildingBasicPage#Build_a_data_entry_page
  */
 public static function dump_javascript()
 {
     global $indicia_resources, $indicia_templates;
     // Add the default stylesheet to the end of the list, so it has highest CSS priority
     if (self::$default_styles) {
         self::add_resource('defaultStylesheet');
     }
     // If required, setup jQuery validation. We can't prep this JavaScript earlier since we would
     // not know all the control messages.
     // In the following block, we set the validation plugin's error class to our template.
     // We also define the error label to be wrapped in a <p> if it is on a newline.
     if (self::$validated_form_id) {
         self::$javascript .= "\$('#" . self::$validated_form_id . "').validate({\n        errorClass: \"" . $indicia_templates['error_class'] . "\",\n        " . (in_array('inline', self::$validation_mode) ? "\n      " : "errorElement: 'p',\n      ") . "highlight: function(element, errorClass) {\n           // Don't highlight the actual control, as it could be hidden anyway\n        },\n        messages: " . json_encode(self::$validation_messages) . "\n      });\n";
     }
     $dump = self::internal_dump_javascript(self::$javascript, self::$late_javascript, self::$onload_javascript, $indicia_resources);
     // ensure scripted JS does not output again if recalled.
     self::$javascript = "";
     self::$late_javascript = "";
     self::$onload_javascript = "";
     return $dump;
 }