示例#1
0
文件: list.php 项目: rogeriocc/fabrik
 /**
  * Build the link (<a href..>) for viewing list data
  *
  * @param   bool    $popUp    is the link to generated a popup to show
  * @param   object  $element  27/06/2011
  * @param   object  $row      current list row data
  * @param   string  $key      28/06/2011 - do longer passed in with _raw appended (done in this method)
  * @param   string  $val      value
  * @param   int     $count    number of related records
  * @param   int     $f        ref to related data admin info 27/16/2011
  *
  * @return  string
  */
 public function viewDataLink($popUp = false, $element = null, $row = null, $key = '', $val = '', $count = 0, $f = null)
 {
     $elKey = $element->list_id . '-' . $element->form_id . '-' . $element->element_id;
     $listid = $element->list_id;
     $app = JFactory::getApplication();
     $params = $this->getParams();
     $factedLinks = $params->get('factedlinks');
     /* $$$ hugh - we are getting element keys that aren't in the linkedlisttext.
      * not sure why, so added this defensive code.  Should probably find out
      * why though!  I just needed to make this error go away NAO!
      */
     $linkedListText = isset($factedLinks->linkedlisttext->{$elKey}) ? $factedLinks->linkedlisttext->{$elKey} : '';
     $label = $this->parseMessageForRowHolder($linkedListText, JArrayHelper::fromObject($row));
     $Itemid = $app->isAdmin() ? 0 : @$app->getMenu('site')->getActive()->id;
     $action = $app->isAdmin() ? 'task' : 'view';
     $url = 'index.php?option=com_fabrik&';
     if (is_null($listid)) {
         $list = $this->getTable();
         $listid = $list->id;
     }
     $facetTable = $this->_facetedTable($listid);
     if (!$facetTable->canView()) {
         return '<div style="text-align:center"><a title="' . JText::_('COM_FABRIK_NO_ACCESS_PLEASE_LOGIN') . '"><img src="media/com_fabrik/images/login.png" alt="' . JText::_('COM_FABRIK_NO_ACCESS_PLEASE_LOGIN') . '" /></a></div>';
     }
     $tlabel = $label === '' ? JText::_('COM_FABRIK_NO_RECORDS') : '(0) ' . $label;
     if ($count === 0) {
         $aExisitngLinkedForms = (array) $params->get('linkedform');
         $linkedForm = JArrayHelper::getValue($aExisitngLinkedForms, $f, false);
         $addLink = $linkedForm == '0' ? $this->viewFormLink($popUp, $element, $row, $key, $val, false, $f) : '';
         return '<div style="text-align:center" class="related_data_norecords">' . $tlabel . '</div>' . $addLink;
     }
     $key .= '_raw';
     if ($label === '') {
         $label = JText::_('COM_FABRIK_VIEW');
     }
     $label = '(' . $count . ') ' . $label;
     if ($app->isAdmin()) {
         $bits[] = 'task=list.view';
         $bits[] = 'cid=' . $listid;
     } else {
         $bits[] = 'view=list';
         $bits[] = 'listid=' . $listid;
         $listLinks = $this->getTableLinks();
         // $$$ rob 01/03/2011 find at matching itemid in another menu item for the related data link
         foreach ($listLinks as $listLink) {
             if (strstr($listLink->link, 'index.php?option=com_fabrik&view=list&listid=' . $listid)) {
                 $bits[] = 'Itemid=' . $listLink->id;
                 $Itemid = $listLink->id;
                 break;
             }
         }
         $bits[] = 'Itemid=' . $Itemid;
     }
     if ($key != '') {
         $bits[] = $key . '=' . $val;
     }
     $bits[] = 'limitstart' . $listid . '=0';
     if ($popUp) {
         $bits[] = 'tmpl=component';
         $bits[] = 'ajax=1';
     }
     $bits[] = '&resetfilters=1';
     // Nope stops url filter form workin on related data :(
     // $bits[] = 'clearfilters=1';
     // Test for releated data, filter once, go backt o main list re-filter -
     $bits[] = '&fabrik_incsessionfilters=0';
     $url .= implode('&', $bits);
     $url = JRoute::_($url);
     if ($popUp) {
         FabrikHelperHTML::windows('a.popupwin');
         $opts = new stdClass();
         $opts->maximizable = 1;
         $opts->title = JText::_('COM_FABRIK_VIEW');
         $opts->evalScripts = 1;
         $opts = str_replace('"', "'", json_encode($opts));
         $url = '<a rel="' . $opts . '" href="' . $url . '" class="popupwin">' . $label . '</a>';
     } else {
         $url = '<a class="related_data" href="' . $url . '">' . $label . "</a>";
     }
     return $url;
 }
示例#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);
 }
示例#3
0
文件: html.php 项目: romuland/khparts
 /**
  * load up window code - should be run in ajax loaded pages as well
  * might be an issue in that we may be re-observing some links when loading in - need to check
  * @deprecated use windows() instead
  * @param string element select to auto create windows for  - was default = a.modal
  */
 public static function mocha($selector = '', $params = array())
 {
     FabrikHelperHTML::windows($selector, $params);
 }