Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * Append the form javascript into the document head
  *
  * @param   int $listId table id
  *
  * @return  void|boolean
  */
 protected function _addJavascript($listId)
 {
     $pluginManager = FabrikWorker::getPluginManager();
     /** @var FabrikFEModelForm $model */
     $model = $this->getModel();
     $aLoadedElementPlugins = array();
     $jsActions = array();
     $bKey = $model->jsKey();
     $srcs = FabrikHelperHTML::framework();
     $shim = array();
     if (!defined('_JOS_FABRIK_FORMJS_INCLUDED')) {
         define('_JOS_FABRIK_FORMJS_INCLUDED', 1);
         FabrikHelperHTML::slimbox();
         $dep = new stdClass();
         $dep->deps = array('fab/element', 'lib/form_placeholder/Form.Placeholder', 'fab/encoder');
         $shim['fabrik/form'] = $dep;
         $deps = new stdClass();
         $deps->deps = array('fab/fabrik', 'fab/element', 'fab/form-submit');
         $framework['fab/elementlist'] = $deps;
         $srcs[] = 'media/com_fabrik/js/lib/form_placeholder/Form.Placeholder.js';
         FabrikHelperHTML::addToFrameWork($srcs, 'media/com_fabrik/js/form');
         FabrikHelperHTML::addToFrameWork($srcs, 'media/com_fabrik/js/form-submit');
         FabrikHelperHTML::addToFrameWork($srcs, 'media/com_fabrik/js/element');
     }
     $aWYSIWYGNames = array();
     // $$$ hugh - yet another one where if we =, the $groups array pointer get buggered up and it
     // skips a group
     $groups = $model->getGroupsHiarachy();
     foreach ($groups as $groupModel) {
         $elementModels = $groupModel->getPublishedElements();
         foreach ($elementModels as $elementModel) {
             $res = $elementModel->useEditor();
             if ($res !== false && $elementModel->canUse() && $model->isEditable()) {
                 $aWYSIWYGNames[] = $res;
             }
             // Load in once the element js class files
             $element = $elementModel->getElement();
             if (!in_array($element->plugin, $aLoadedElementPlugins)) {
                 /* $$$ hugh - certain elements, like file-upload, need to load different JS files
                  * on a per-element basis, so as a test fix, I modified the file-upload's formJavaScriptClass to return false,
                  * and test for that here, so as to not add it to aLoadedElementPlugins[].  The existing 'static' tests in
                  * formJavascriptClass() should still prevent scripts being added twice.
                  */
                 if ($elementModel->formJavascriptClass($srcs, '', $shim) !== false) {
                     $aLoadedElementPlugins[] = $element->plugin;
                 }
             }
             $eventMax = $groupModel->repeatTotal == 0 ? 1 : $groupModel->repeatTotal;
             for ($c = 0; $c < $eventMax; $c++) {
                 $jsAct = $elementModel->getFormattedJSActions($bKey, $c);
                 if (!empty($jsAct)) {
                     $jsActions[] = $jsAct;
                 }
             }
         }
     }
     FabrikHelperHTML::iniRequireJS($shim);
     $actions = trim(implode("\n", $jsActions));
     FabrikHelperHTML::windows('a.fabrikWin');
     FabrikHelperHTML::tips('.hasTip', array(), "\$('{$bKey}')");
     $model->getFormCss();
     $opts = $this->jsOpts();
     $model->jsOpts = $opts;
     $pluginManager->runPlugins('onJSOpts', $model);
     $opts = json_encode($model->jsOpts);
     if (!FabrikHelperHTML::inAjaxLoadedPage()) {
         JText::script('COM_FABRIK_VALIDATING');
         JText::script('COM_FABRIK_SUCCESS');
         JText::script('COM_FABRIK_NO_REPEAT_GROUP_DATA');
         JText::script('COM_FABRIK_VALIDATION_ERROR');
         JText::script('COM_FABRIK_CONFIRM_DELETE_1');
     }
     JText::script('COM_FABRIK_FORM_SAVED');
     // $$$ rob don't declare as var $bKey, but rather assign to window, as if loaded via ajax window the function is wrapped
     // inside an anonymous function, and therefore $bKey wont be available as a global var in window
     $script = array();
     $script[] = "\t\tvar {$bKey} = Fabrik.form('{$bKey}', " . $model->getId() . ", {$opts});";
     // Instantiate js objects for each element
     $vstr = "\n";
     $groups = $model->getGroupsHiarachy();
     $script[] = "\tFabrik.blocks['{$bKey}'].addElements(";
     $groupedJs = new stdClass();
     foreach ($groups as $groupModel) {
         $groupId = $groupModel->getGroup()->id;
         $groupedJs->{$groupId} = array();
         if (!$groupModel->canView('form')) {
             continue;
         }
         $elementJs = array();
         $elementModels = $groupModel->getPublishedElements();
         // $$$ rob if repeatTotal is 0 we still want to add the js objects as the els are only hidden
         $max = $groupModel->repeatTotal > 0 ? $groupModel->repeatTotal : 1;
         foreach ($elementModels as $elementModel) {
             $element = $elementModel->getElement();
             if ($element->published == 0) {
                 continue;
             }
             // If the view is a form then we should always add the js as long as the element is editable or viewable
             // if the view is details then we should only add the js if the element is viewable.
             if ($elementModel->canUse() && $model->isEditable() || $elementModel->canView()) {
                 for ($c = 0; $c < $max; $c++) {
                     $ref = $elementModel->elementJavascript($c);
                     if (!empty($ref)) {
                         $elementJs[] = $ref;
                     }
                     $validations = $elementModel->validator->findAll();
                     if (!empty($validations) && $elementModel->isEditable()) {
                         $watchElements = $elementModel->getValidationWatchElements($c);
                         foreach ($watchElements as $watchElement) {
                             $vstr .= "\tFabrik.blocks['{$bKey}'].watchValidation('" . $watchElement['id'] . "', '" . $watchElement['triggerEvent'] . "');\n";
                         }
                     }
                 }
             }
         }
         $groupedJs->{$groupId} = $elementJs;
     }
     $script[] = json_encode($groupedJs);
     $script[] = "\t);";
     $script[] = $actions;
     $script[] = $vstr;
     // Placeholder
     $script[] = "\tnew Form.Placeholder('.fabrikForm input');";
     $this->_addJavascriptSumbit($script, $listId, $aWYSIWYGNames);
     if (FabrikHelperHTML::inAjaxLoadedPage()) {
         $tipOpts = FabrikHelperHTML::tipOpts();
         $script[] = "new FloatingTips('#" . $bKey . " .fabrikTip', " . json_encode($tipOpts) . ");";
     }
     $res = $pluginManager->runPlugins('onJSReady', $model);
     if (in_array(false, $res)) {
         return false;
     }
     $str = implode("\n", $script);
     $model->getCustomJsAction($srcs);
     $pluginManager->runPlugins('onAfterJSLoad', $model);
     // 3.1 call form js plugin code within main require method
     $srcs = array_merge($srcs, $model->formPluginShim);
     $str .= $model->formPluginJS;
     FabrikHelperHTML::script($srcs, $str);
 }