Esempio n. 1
0
 /**
  * Get the class to manage the form element
  * to ensure that the file is loaded only once
  *
  * @param   array   &$srcs   Scripts previously loaded
  * @param   string  $script  Script to load once class has loaded
  * @param   array   &$shim   Dependant class names to load before loading the class - put in requirejs.config shim
  *
  * @return void|boolean
  */
 public function formJavascriptClass(&$srcs, $script = '', &$shim = array())
 {
     $key = FabrikHelperHTML::isDebug() ? 'element/tags/tags' : 'element/tags/tags-min';
     $s = new stdClass();
     // Even though fab/element is now an AMD defined module we should still keep it in here
     // otherwise (not sure of the reason) jQuery.mask is not defined in field.js
     // Seems OK now - reverting to empty array
     $s->deps = array();
     $folder = 'media/jui/js/';
     $s->deps[] = $folder . 'ajax-chosen';
     if (array_key_exists($key, $shim)) {
         $shim[$key]->deps = array_merge($shim[$key]->deps, $s->deps);
     } else {
         $shim[$key] = $s;
     }
     parent::formJavascriptClass($srcs, $script, $shim);
     // $$$ hugh - added this, and some logic in the view, so we will get called on a per-element basis
     return false;
 }
Esempio n. 2
0
 /**
  * Determines the value for the element in the form view
  *
  * @param   array $data          form data
  * @param   int   $repeatCounter when repeating joined groups we need to know what part of the array to access
  * @param   array $opts          options
  *
  * @return  string    value
  */
 public function getValue($data, $repeatCounter = 0, $opts = array())
 {
     if ($this->getListModel()->importingCSV) {
         return parent::getValue($data, $repeatCounter, $opts);
     }
     $input = $this->app->input;
     // Kludge for 2 scenarios
     if (array_key_exists('rowid', $data)) {
         // When validating the data on form submission
         $key = 'rowid';
     } else {
         // When rendering the element to the form
         $key = '__pk_val';
     }
     /*
      * empty(data) when you are saving a new record and this element is in a joined group
      * $$$ hugh - added !array_key_exists(), as ... well, rowid doesn't always exist in the query string
      */
     if (empty($data) || !array_key_exists($key, $data)) {
         // $$$ rob - added check on task to ensure that we are searching and not submitting a form
         // as otherwise not empty validation failed on user element
         if (!in_array($input->get('task'), array('processForm', 'view', '', 'form.process', 'process'))) {
             return '';
         }
         return $this->getDefaultOnACL($data, $opts);
     }
     return parent::getValue($data, $repeatCounter, $opts);
 }
Esempio n. 3
0
 /**
  * Cache method to populate auto-complete options
  *
  * @param   PlgFabrik_ElementDatabasejoin  $elementModel  element model
  * @param   string                         $search        search string
  * @param   array                          $opts          options, 'label' => field to use for label (db join)
  *
  * @since   3.0.7
  *
  * @return string  json encoded search results
  */
 public static function cacheAutoCompleteOptions($elementModel, $search, $opts = array())
 {
     $params = $elementModel->getParams();
     $c = $elementModel->getLabelOrConcatVal();
     if (!strstr($c, 'CONCAT')) {
         $c = FabrikString::safeColName($c);
     }
     $filterMethod = $elementModel->getFilterBuildMethod();
     if ($filterMethod == 1) {
         $join = $elementModel->getJoin();
         $joinTable = $join->table_join_alias;
         $opts = array();
         if (!strstr($c, 'CONCAT')) {
             $opts['label'] = strstr($c, '.') ? $c : $joinTable . '.' . $c;
         } else {
             $opts['label'] = $c;
         }
         return parent::cacheAutoCompleteOptions($elementModel, $search, $opts);
     }
     // $$$ hugh - added 'autocomplete_how', currently just "starts_with" or "contains"
     // default to "contains" for backward compat.
     $elementModel->autocomplete_where = $elementModel->_autocompleteWhere($params->get('dbjoin_autocomplete_how', 'contains'), $c, $search);
     $opts = array('mode' => 'filter');
     $tmp = $elementModel->_getOptions(array(), 0, true, $opts);
     return json_encode($tmp);
 }