/** * Returns javascript which creates an instance of the class defined in formJavascriptClass() * * @param int $repeatCounter Repeat group counter * * @return array */ public function elementJavascript($repeatCounter) { $input = $this->app->input; $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); if ($this->getDisplayType() === 'auto-complete') { $autoOpts = array(); $autoOpts['observerid'] = $this->getWatchId($repeatCounter); $autoOpts['formRef'] = $this->getFormModel()->jsKey(); $autoOpts['storeMatchedResultsOnly'] = true; FabrikHelperHTML::autoComplete($id, $this->getElement()->id, $this->getFormModel()->getId(), 'cascadingdropdown', $autoOpts); } $opts = $this->getElementJSOptions($repeatCounter); $opts->showPleaseSelect = $this->showPleaseSelect(); $opts->watch = $this->getWatchId($repeatCounter); $watchElementModel = $this->getWatchElement(); $opts->watchChangeEvent = $watchElementModel->getChangeEvent(); $opts->displayType = $params->get('cdd_display_type', 'dropdown'); $opts->id = $this->getId(); $opts->listName = $this->getListModel()->getTable()->db_table_name; $opts->lang = FabrikWorker::getMultiLangURLCode(); // This bizarre chunk of code handles the case of setting a CDD value on the QS on a new form $rowId = $input->get('rowid', '', 'string'); $fullName = $this->getFullName(); $watchName = $this->getWatchFullName(); // If returning from failed posted validation data can be in an array $qsValue = $input->get($fullName, array(), 'array'); $qsValue = FArrayHelper::getValue($qsValue, 0, null); $qsWatchValue = $input->get($watchName, array(), 'array'); $qsWatchValue = FArrayHelper::getValue($qsWatchValue, 0, null); $useQsValue = $this->getFormModel()->hasErrors() && $this->isEditable() && $rowId === '' && !empty($qsValue) && !empty($qsWatchValue); $opts->def = $useQsValue ? $qsValue : $this->getValue(array(), $repeatCounter); // $$$ hugh - for reasons utterly beyond me, after failed validation, getValue() is returning an array. if (is_array($opts->def) && !empty($opts->def)) { $opts->def = $opts->def[0]; } $watchGroup = $this->getWatchElement()->getGroup()->getGroup(); $group = $this->getGroup()->getGroup(); $opts->watchInSameGroup = $watchGroup->id === $group->id; $opts->editing = $this->isEditable() && $rowId !== ''; $opts->showDesc = $params->get('cdd_desc_column', '') === '' ? false : true; $opts->advanced = $this->getAdvancedSelectClass() != ''; $formId = $this->getFormModel()->getId(); $opts->autoCompleteOpts = $opts->displayType == 'auto-complete' ? FabrikHelperHTML::autoCompleteOptions($opts->id, $this->getElement()->id, $formId, 'cascadingdropdown') : null; $this->elementJavascriptJoinOpts($opts); $data = $this->getFormModel()->data; // Was otherwise using the none-raw value. $opts->value = $this->getValue($data, $repeatCounter, array('raw' => true)); $opts->optsPerRow = (int) $params->get('dbjoin_options_per_row', 1); if (is_array($opts->value) && count($opts->value) > 0) { $opts->value = ArrayHelper::getValue($opts->value, 0); } return array('FbCascadingdropdown', $id, $opts); }
/** * Get element JS options * * @param int $repeatCounter Group repeat counter * * @return array Options */ protected function elementJavascriptOpts($repeatCounter) { $params = $this->getParams(); $element = $this->getElement(); $opts = $this->_getOptionVals(); $data = $this->getFormModel()->data; $arSelected = $this->getValue($data, $repeatCounter); $arVals = $this->getSubOptionValues(); $arTxt = $this->getSubOptionLabels(); $table = $params->get('join_db_name'); $opts = $this->getElementJSOptions($repeatCounter); $forms = $this->getLinkedForms(); $popupform = (int) $params->get('databasejoin_popupform'); $popuplistid = empty($popupform) || !isset($forms[$popupform]) ? '' : $forms[$popupform]->listid; $opts->id = $this->id; $opts->fullName = $this->getFullName(true, false); $opts->key = $table . '___' . $params->get('join_key_column'); $opts->label = $table . '___' . $this->getLabelParamVal(); $opts->formid = $this->getForm()->getForm()->id; $opts->listid = $popuplistid; $opts->listRef = '_com_fabrik_' . $opts->listid; $opts->value = $arSelected; $opts->defaultVal = $this->getDefaultValue($data); $opts->popupform = $popupform; $opts->windowwidth = $params->get('join_popupwidth', 360); $opts->displayType = $this->getDisplayType(); $opts->show_please_select = $params->get('database_join_show_please_select') === "1"; $opts->showDesc = $params->get('join_desc_column', '') === '' ? false : true; $opts->autoCompleteOpts = $opts->displayType == 'auto-complete' ? FabrikHelperHTML::autoCompleteOptions($opts->id, $this->getElement()->id, $this->getFormModel()->getId(), 'databasejoin') : null; $opts->allowadd = $params->get('fabrikdatabasejoin_frontend_add', 0) == 0 ? false : true; $opts->listName = $this->getListModel()->getTable()->db_table_name; $this->elementJavascriptJoinOpts($opts); $opts->isJoin = $this->isJoin(); return $opts; }
/** * Get element JS options * * @param int $repeatCounter Group repeat counter * * @return array Options */ protected function elementJavascriptOpts($repeatCounter = 0) { $params = $this->getParams(); $modalId = 'dbjoin_popupform'; $opts = $this->_getOptionVals(); $data = $this->getFormModel()->data; $arSelected = $this->getValue($data, $repeatCounter); $table = $params->get('join_db_name'); $opts = $this->getElementJSOptions($repeatCounter); $forms = $this->getLinkedForms(); $popupForm = (int) $params->get('databasejoin_popupform'); $popupListId = empty($popupForm) || !isset($forms[$popupForm]) ? '' : $forms[$popupForm]->listid; $opts->id = $this->id; $opts->modalId = $modalId; $opts->fullName = $this->getFullName(true, false); $opts->key = $table . '___' . $params->get('join_key_column'); $opts->label = $table . '___' . $this->getLabelParamVal(); $opts->formid = $this->getFormModel()->getForm()->get('id'); $opts->listid = $popupListId; $opts->listRef = '_com_fabrik_' . $opts->listid; $opts->value = $arSelected; $opts->defaultVal = $this->getDefaultValue($data); $opts->popupform = $popupForm; $opts->windowwidth = $params->get('join_popupwidth', 360); $opts->displayType = $this->getDisplayType(); $opts->show_please_select = $params->get('database_join_show_please_select') === '1'; $opts->showDesc = $params->get('join_desc_column', '') === '' ? false : true; $opts->autoCompleteOpts = $opts->displayType == 'auto-complete' ? FabrikHelperHTML::autoCompleteOptions($opts->id, $this->getElement()->get('id'), $this->getFormModel()->getId(), 'databasejoin') : null; $opts->allowadd = $params->get('fabrikdatabasejoin_frontend_add', 0) == 0 ? false : true; $opts->listName = $this->getListModel()->getTable()->db_table_name; $this->elementJavascriptJoinOpts($opts); $opts->isJoin = $this->isJoin(); $opts->advanced = $this->getAdvancedSelectClass() != ''; /* * Testing watching placeholders used in the where, and AJAX reloading the join when changed */ $obs = array(); if ($params->get('databasejoin_where_ajax', '0') === '1') { $whereSql = $params->get('database_join_where_sql', ''); if (preg_match_all("/{[^}\\s]+}/i", $whereSql, $matches) !== 0) { $obs = $matches[0]; } $obs = array_unique($obs); foreach ($obs as $key => &$m) { if (empty($m)) { unset($obs[$key]); continue; } $m = str_replace(array('{', '}'), '', $m); // $$$ hugh - we need to knock any _raw off, so JS can match actual element ID $m = preg_replace('#_raw$#', '', $m); } // remove any placeholders we don't want $obs = array_diff($obs, array('thistable')); } $opts->observe = array_values($obs); return $opts; }