/** * Get JS objects * * @param array $data list data * * @return void */ protected function getManagementJS($data = array()) { $input = $this->app->input; $itemId = FabrikWorker::itemId(); /** @var FabrikFEModelList $model */ $model = $this->getModel(); $params = $model->getParams(); $item = $model->getTable(); $listRef = $model->getRenderContext(); $listId = $model->getId(); $formModel = $model->getFormModel(); $elementsNotInTable = $formModel->getElementsNotInTable(); $toggleCols = (bool) $params->get('toggle_cols', false); $ajax = (int) $model->isAjax(); $ajaxLinks = (bool) $params->get('list_ajax_links', $ajax); $opts = new stdClass(); $pluginManager = FabrikWorker::getPluginManager(); if ($ajaxLinks) { $modalTitle = 'test'; $modalOpts = array('content' => '', 'id' => 'ajax_links', 'title' => JText::_($modalTitle), 'modal' => false, 'expandable' => true); FabrikHelperHTML::jLayoutJs('ajax_links', 'fabrik-modal', (object) $modalOpts); } // Advanced search if ($params->get('advanced-filter')) { $modalOpts = array('content' => '', 'id' => 'advanced-filter', 'title' => JText::_('COM_FABRIK_FIELD_ADVANCED_SEARCH_LABEL'), 'modal' => false, 'expandable' => true); FabrikHelperHTML::jLayoutJs('advanced-filter', 'fabrik-modal', (object) $modalOpts); } FabrikHelperHTML::jLayoutJs('modal-state-label', 'list.fabrik-filters-modal-state-label', $layoutData = (object) array('label' => '', 'displayValue' => '', 'key' => '')); $this->csvJS($opts, $model); if ($model->requiresSlimbox()) { FabrikHelperHTML::slimbox(); } if ($model->requiresSlideshow()) { FabrikHelperHTML::slideshow(); } $src = FabrikHelperHTML::framework(); $shim = array(); $dep = new stdClass(); $dep->deps = array(); $shim['fab/list'] = $dep; $src['FbList'] = FabrikHelperHTML::mediaFile('list.js'); $src['FbListFilter'] = FabrikHelperHTML::mediaFile('listfilter.js'); $src['ListPlugin'] = FabrikHelperHTML::mediaFile('list-plugin.js'); $src = $model->getPluginJsClasses($src, $shim); $pluginManager->runPlugins('loadJavascriptClassName', $model, 'list'); $pluginManager->data = array_filter($pluginManager->data, function ($v) { return $v !== ''; }); $model->getCustomJsAction($src); $tmpl = $model->getTmpl(); $this->tmpl = $tmpl; $model->getListCss(); // Check for a custom js file and include it if it exists $aJsPath = JPATH_SITE . '/components/com_fabrik/views/list/tmpl/' . $tmpl . '/javascript.js'; if (JFile::exists($aJsPath)) { $src['CustomJs'] = 'components/com_fabrik/views/list/tmpl/' . $tmpl . '/javascript.js'; } $origRows = $this->rows; $this->rows = array(array()); $tmpItemid = !isset($itemId) ? 0 : $itemId; $this->_row = new stdClass(); $script = array(); $params = $model->getParams(); $opts->admin = $this->app->isAdmin(); $opts->ajax = $ajax; $opts->ajax_links = $ajaxLinks; $opts->links = array('detail' => $params->get('detailurl', ''), 'edit' => $params->get('editurl', ''), 'add' => $params->get('addurl', '')); $opts->filterMethod = $this->filter_action; $opts->advancedFilters = $model->getAdvancedFilterValues(); $opts->resetFilters = (bool) FabrikWorker::getMenuOrRequestVar('resetfilters', 0, false, 'request'); $opts->form = 'listform_' . $listRef; $this->listref = $listRef; $opts->headings = $model->jsonHeadings(); $labels = $this->headings; foreach ($labels as &$l) { $l = strip_tags($l); } $opts->labels = $labels; $opts->primaryKey = $item->db_primary_key; $opts->Itemid = $tmpItemid; $opts->listRef = $listRef; $opts->formid = $model->getFormModel()->getId(); $opts->canEdit = $model->canEdit() ? '1' : '0'; $opts->canView = $model->canView() ? '1' : '0'; $opts->page = JRoute::_('index.php'); $opts->isGrouped = $this->isGrouped; $opts->toggleCols = $toggleCols; $opts->j3 = FabrikWorker::j3(); $opts->singleOrdering = (bool) $model->singleOrdering(); // Reset data back to original settings $this->rows = $origRows; $formEls = array(); foreach ($elementsNotInTable as $tmpElement) { $oo = new stdClass(); $oo->name = $tmpElement->name; $oo->label = $tmpElement->label; $formEls[] = $oo; } $opts->formels = $formEls; $opts->fabrik_show_in_list = $input->get('fabrik_show_in_list', array(), 'array'); $opts->popup_width = $params->get('popup_width', ''); $opts->popup_height = $params->get('popup_height', ''); $xOffset = $params->get('popup_offset_x', ''); $yOffset = $params->get('popup_offset_y', ''); if ($xOffset !== '') { $opts->popup_offset_x = (int) $xOffset; } if ($yOffset !== '') { $opts->popup_offset_y = (int) $yOffset; } /** * Added the $nodata object as we now weed something to pass in just to keep editLabel * and viewLabel happy, after adding placeholder replacement to the labels for a Pro user, * because the tooltips said we did that, which we never actually did. * * http://fabrikar.com/forums/index.php?threads/placeholders-in-list-links-and-labels.37726/#post-191081 * * However, this means that using placeholders will yield funky labels for the popups, as * this isn't per row. So we may need to not use editLabel / viewLabel here any more, * and just use the default COM_FABRIK_VIEW/EDIT. Or add YAFO's, ::sigh::. * * But for now, it's too corner case to worry about! */ $nodata = new stdClass(); $opts->popup_edit_label = $model->editLabel($nodata); $opts->popup_view_label = $model->viewLabel($nodata); $opts->popup_add_label = $model->addLabel(); $opts->limitLength = $model->limitLength; $opts->limitStart = $model->limitStart; $opts->tmpl = $tmpl; $opts->data = $data; $opts->groupByOpts = new stdClass(); $opts->groupByOpts->isGrouped = (bool) $this->isGrouped; $opts->groupByOpts->collapseOthers = (bool) $params->get('group_by_collapse_others', false); $opts->groupByOpts->startCollapsed = (bool) $params->get('group_by_start_collapsed', false); $opts->groupByOpts->bootstrap = FabrikWorker::j3(); // If table data starts as empty then we need the html from the row // template otherwise we can't add a row to the table ob_start(); $this->_row = new stdClass(); $this->_row->id = ''; $this->_row->class = 'fabrik_row'; echo $this->loadTemplate('row'); $opts->itemTemplate = ob_get_contents(); ob_end_clean(); // $$$rob if you are loading a table in a window from a form db join select record option // then we want to know the id of the window so we can set its showSpinner() method $opts->winid = $input->get('winid', ''); $this->jsText(); $script[] = "window.addEvent('domready', function () {"; $script[] = "\tvar list = new FbList('{$listId}',"; $script[] = "\t" . json_encode($opts); $script[] = "\t);"; $script[] = "\tFabrik.addBlock('list_{$listRef}', list);"; // Add in plugin objects $pluginManager->runPlugins('onLoadJavascriptInstance', $model, 'list'); $aObjs = $pluginManager->data; if (!empty($aObjs)) { $script[] = "list.addPlugins([\n"; $script[] = "\t" . implode(",\n ", $aObjs); $script[] = "]);"; } // @since 3.0 inserts content before the start of the list render (currently on f3 tmpl only) $pluginManager->runPlugins('onGetContentBeforeList', $model, 'list'); $this->pluginBeforeList = $pluginManager->data; $script[] = $model->filterJs; $script[] = $this->getModel()->getElementJs($src); // End domready wrapper $script[] = '})'; $script = implode("\n", $script); FabrikHelperHTML::iniRequireJS($shim); FabrikHelperHTML::script($src, $script); }
/** * Get JS objects * * @param array $data list data * * @return void */ protected function getManagementJS($data = array()) { $app = JFactory::getApplication(); $input = $app->input; $Itemid = FabrikWorker::itemId(); $model = $this->getModel(); $params = $model->getParams(); $item = $model->getTable(); $listref = $model->getRenderContext(); $listid = $model->getId(); $formModel = $model->getFormModel(); $elementsNotInTable = $formModel->getElementsNotInTable(); $toggleCols = (bool) $params->get('toggle_cols', false); if ($model->requiresSlimbox()) { FabrikHelperHTML::slimbox(); } if ($model->requiresSlideshow()) { FabrikHelperHTML::slideshow(); } $src = FabrikHelperHTML::framework(); $shim = array(); $dep = new stdClass(); $dep->deps = array('fab/fabrik', 'fab/listfilter', 'fab/advanced-search', 'fab/encoder'); if ($toggleCols) { $dep->deps[] = 'fab/list-toggle'; } $shim['fab/list'] = $dep; $src = $model->getPluginJsClasses($src, $shim); FabrikHelperHTML::addToFrameWork($src, 'media/com_fabrik/js/list'); $model->getCustomJsAction($src); $tmpl = $model->getTmpl(); $this->tmpl = $tmpl; $model->getListCss(); // Check for a custom js file and include it if it exists $aJsPath = JPATH_SITE . '/components/com_fabrik/views/list/tmpl/' . $tmpl . '/javascript.js'; if (JFile::exists($aJsPath)) { $src[] = 'components/com_fabrik/views/list/tmpl/' . $tmpl . '/javascript.js'; } $origRows = $this->rows; $this->rows = array(array()); $tmpItemid = !isset($Itemid) ? 0 : $Itemid; $this->_row = new stdClass(); $script = array(); $params = $model->getParams(); $opts = new stdClass(); $opts->admin = $app->isAdmin(); $opts->ajax = (int) $model->isAjax(); $opts->ajax_links = (bool) $params->get('list_ajax_links', $opts->ajax); $opts->links = array('detail' => $params->get('detailurl', ''), 'edit' => $params->get('editurl', ''), 'add' => $params->get('addurl', '')); $opts->filterMethod = $this->filter_action; $opts->advancedFilters = $model->getAdvancedFilterValues(); $opts->form = 'listform_' . $listref; $this->listref = $listref; $opts->headings = $model->jsonHeadings(); $labels = $this->headings; foreach ($labels as &$l) { $l = strip_tags($l); } $opts->labels = $labels; $opts->primaryKey = $item->db_primary_key; $opts->Itemid = $tmpItemid; $opts->listRef = $listref; $opts->formid = $model->getFormModel()->getId(); $opts->canEdit = $model->canEdit() ? "1" : "0"; $opts->canView = $model->canView() ? "1" : "0"; $opts->page = JRoute::_('index.php'); $opts->isGrouped = $this->isGrouped; $opts->toggleCols = $toggleCols; $opts->j3 = FabrikWorker::j3(); $opts->singleOrdering = (bool) $model->singleOrdering(); $formEls = array(); foreach ($elementsNotInTable as $tmpElement) { $oo = new stdClass(); $oo->name = $tmpElement->name; $oo->label = $tmpElement->label; $formEls[] = $oo; } $opts->formels = $formEls; $opts->fabrik_show_in_list = $input->get('fabrik_show_in_list', array(), 'array'); $opts->csvChoose = (bool) $params->get('csv_frontend_selection'); $opts->popup_width = $params->get('popup_width', ''); $opts->popup_height = $params->get('popup_height', ''); $xOffset = $params->get('popup_offset_x', ''); $yOffset = $params->get('popup_offset_y', ''); if ($xOffset !== '') { $opts->popup_offset_x = (int) $xOffset; } if ($yOffset !== '') { $opts->popup_offset_y = (int) $yOffset; } $opts->popup_edit_label = $model->editLabel(); $opts->popup_view_label = $model->viewLabel(); $opts->popup_add_label = $model->addLabel(); $opts->limitLength = $model->limitLength; $opts->limitStart = $model->limitStart; $opts->tmpl = $tmpl; $csvOpts = new stdClass(); $csvOpts->excel = (int) $params->get('csv_format'); $csvOpts->inctabledata = (int) $params->get('csv_include_data'); $csvOpts->incraw = (int) $params->get('csv_include_raw_data'); $csvOpts->inccalcs = (int) $params->get('csv_include_calculations'); $csvOpts->custom_qs = $params->get('csv_custom_qs', ''); $opts->csvOpts = $csvOpts; $opts->csvFields = $model->getCsvFields(); $csvOpts->incfilters = (int) $params->get('incfilters'); $opts->data = $data; $opts->groupByOpts = new stdClass(); $opts->groupByOpts->isGrouped = (bool) $this->isGrouped; $opts->groupByOpts->collapseOthers = (bool) $params->get('group_by_collapse_others', false); $opts->groupByOpts->startCollapsed = (bool) $params->get('group_by_start_collapsed', false); $opts->groupByOpts->bootstrap = FabrikWorker::j3(); // If table data starts as empty then we need the html from the row // template otherwise we can't add a row to the table ob_start(); $this->_row = new stdClass(); $this->_row->id = ''; $this->_row->class = 'fabrik_row'; echo $this->loadTemplate('row'); $opts->rowtemplate = ob_get_contents(); ob_end_clean(); // $$$rob if you are loading a table in a window from a form db join select record option // then we want to know the id of the window so we can set its showSpinner() method $opts->winid = $input->get('winid', ''); $opts = json_encode($opts); JText::script('COM_FABRIK_PREV'); JText::script('COM_FABRIK_SELECT_ROWS_FOR_DELETION'); JText::script('JYES'); JText::script('JNO'); JText::script('COM_FABRIK_SELECT_COLUMNS_TO_EXPORT'); JText::script('COM_FABRIK_INCLUDE_FILTERS'); JText::script('COM_FABRIK_INCLUDE_DATA'); JText::script('COM_FABRIK_INCLUDE_RAW_DATA'); JText::script('COM_FABRIK_INCLUDE_CALCULATIONS'); JText::script('COM_FABRIK_EXPORT'); JText::script('COM_FABRIK_START'); JText::script('COM_FABRIK_NEXT'); JText::script('COM_FABRIK_END'); JText::script('COM_FABRIK_PAGE'); JText::script('COM_FABRIK_OF'); JText::script('COM_FABRIK_LOADING'); JText::script('COM_FABRIK_RECORDS'); JText::script('COM_FABRIK_SAVING_TO'); JText::script('COM_FABRIK_CONFIRM_DROP'); JText::script('COM_FABRIK_CONFIRM_DELETE_1'); JText::script('COM_FABRIK_NO_RECORDS'); JText::script('COM_FABRIK_CSV_COMPLETE'); JText::script('COM_FABRIK_CSV_DOWNLOAD_HERE'); JText::script('COM_FABRIK_CONFIRM_DELETE'); JText::script('COM_FABRIK_CSV_DOWNLOADING'); JText::script('COM_FABRIK_FILE_TYPE'); JText::script('COM_FABRIK_ADVANCED_SEARCH'); JText::script('COM_FABRIK_FORM_FIELDS'); JText::script('COM_FABRIK_VIEW'); // Keyboard short cuts JText::script('COM_FABRIK_LIST_SHORTCUTS_ADD'); JText::script('COM_FABRIK_LIST_SHORTCUTS_EDIT'); JText::script('COM_FABRIK_LIST_SHORTCUTS_DELETE'); JText::script('COM_FABRIK_LIST_SHORTCUTS_FILTER'); $script[] = "window.addEvent('domready', function () {"; $script[] = "\tvar list = new FbList('{$listid}',"; $script[] = "\t" . $opts; $script[] = "\t);"; $script[] = "\tFabrik.addBlock('list_{$listref}', list);"; // Add in plugin objects $params = $model->getParams(); $pluginManager = FabrikWorker::getPluginManager(); $c = 0; $pluginManager->runPlugins('onLoadJavascriptInstance', $model, 'list'); $aObjs = $pluginManager->data; if (!empty($aObjs)) { $script[] = "list.addPlugins([\n"; $script[] = "\t" . implode(",\n ", $aObjs); $script[] = "]);"; } // @since 3.0 inserts content before the start of the list render (currently on f3 tmpl only) $pluginManager->runPlugins('onGetContentBeforeList', $model, 'list'); $this->pluginBeforeList = $pluginManager->data; $script[] = $model->filterJs; // Was separate but should now load in with the rest of the require js code $model = $this->getModel(); $script[] = $model->getElementJs($src); // End domready wrapper $script[] = '})'; $script = implode("\n", $script); FabrikHelperHTML::iniRequireJS($shim); FabrikHelperHTML::script($src, $script); // Reset data back to original settings $this->rows = $origRows; }
/** * 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 */ public function formJavascriptClass(&$srcs, $script = '', &$shim = array()) { $s = new stdClass(); $s->deps = array('fab/element'); $params = $this->getParams(); if ($params->get('ajax_upload')) { $runtimes = $params->get('ajax_runtime', 'html5'); $folder = 'element/fileupload/lib/plupload/js/'; $plupShim = new stdClass(); $plupShim->deps = array($folder . 'plupload'); $s->deps[] = $folder . 'plupload'; if (strstr($runtimes, 'html5')) { $s->deps[] = $folder . 'plupload.html5'; $shim[$folder . 'plupload.html5'] = $plupShim; } if (strstr($runtimes, 'html4')) { $s->deps[] = $folder . 'plupload.html4'; $shim[$folder . 'plupload.html4'] = $plupShim; } if (strstr($runtimes, 'flash')) { $s->deps[] = $folder . 'plupload.flash'; $shim[$folder . 'plupload.flash'] = $plupShim; } if (strstr($runtimes, 'silverlight')) { $s->deps[] = $folder . 'plupload.silverlight'; $shim[$folder . 'plupload.silverlight'] = $plupShim; } if (strstr($runtimes, 'browserplus')) { $s->deps[] = $folder . 'plupload.browserplus'; $shim[$folder . 'plupload.browserplus'] = $plupShim; } } if (array_key_exists('element/fileupload/fileupload', $shim) && isset($shim['element/fileupload/fileupload']->deps)) { $shim['element/fileupload/fileupload']->deps = array_values(array_unique(array_merge($shim['element/fileupload/fileupload']->deps, $s->deps))); } else { $shim['element/fileupload/fileupload'] = $s; } if ($this->requiresSlideshow()) { FabrikHelperHTML::slideshow(); } 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; }