/**
  * Load default decorators
  *
  * @return \Zend_Form_Element
  */
 public function loadDefaultDecorators()
 {
     parent::loadDefaultDecorators();
     if (\MUtil_Bootstrap::enabled() === true) {
         $this->addDecorator('Description', array('tag' => 'p', 'class' => 'help-block'))->addDecorator('HtmlTag', array('tag' => 'div', 'id' => array('callback' => array(get_class($this), 'resolveElementId')), 'class' => 'element-container'))->addDecorator('Label')->addDecorator('BootstrapRow');
     }
     return $this;
 }
 /**
  *
  * @param mixed $options
  * @return \Gems_Form
  */
 protected function createForm($options = array())
 {
     if (\MUtil_Bootstrap::enabled()) {
         if (!isset($options['class'])) {
             $options['class'] = 'form-horizontal';
         }
         if (!isset($options['role'])) {
             $options['role'] = 'form';
         }
     }
     $form = new \Gems_Form($options);
     return $form;
 }
 /**
  * Load default decorators
  *
  * @return void
  */
 public function loadDefaultDecorators()
 {
     if ($this->loadDefaultDecoratorsIsDisabled()) {
         return $this;
     }
     $decorators = $this->getDecorators();
     if (empty($decorators)) {
         $this->addDecorator('FormElements');
         if (\MUtil_Bootstrap::enabled() !== true) {
             $this->addDecorator(array('table' => 'HtmlTag'), array('tag' => 'table', 'class' => 'formTable'));
         }
         $this->addDecorator(array('tab' => 'HtmlTag'), array('tag' => 'div', 'class' => 'displayGroup'))->addDecorator('TabPane', array('jQueryParams' => array('containerId' => 'mainForm', 'title' => $this->getAttrib('title')), 'class' => $this->getAttrib('class')));
     }
     return $this;
 }
 public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $post = $this->request->getPost();
     $export = $this->loader->getExport();
     $exportTypes = $export->getExportClasses();
     if (isset($post['type'])) {
         $currentType = $post['type'];
     } else {
         reset($exportTypes);
         $currentType = key($exportTypes);
     }
     if (\MUtil_Bootstrap::enabled()) {
         $form = new \Gems_Form(array('id' => 'exportOptionsForm', 'class' => 'form-horizontal'));
     } else {
         $form = new \Gems_Form_TableForm();
     }
     $url = $view->url() . '/step/batch';
     $form->setAction($url);
     $elements = array();
     $elements['type'] = $form->createElement('select', 'type', array('label' => $this->_('Export to'), 'multiOptions' => $exportTypes, 'class' => 'autosubmit'));
     $form->addElements($elements);
     $exportClass = $export->getExport($currentType);
     $exportName = $exportClass->getName();
     $exportFormElements['firstCheck'] = $form->createElement('hidden', $currentType);
     $exportFormElements = $exportClass->getFormElements($form, $data);
     if ($exportFormElements) {
         $form->addElements($exportFormElements);
     }
     if (!isset($post[$currentType])) {
         $post[$exportName] = $exportClass->getDefaultFormValues();
     }
     $element = $form->createElement('submit', 'export_submit', array('label' => $this->_('Export')));
     $form->addElement($element);
     if ($post) {
         $form->populate($post);
     }
     $container = \MUtil_Html::div(array('id' => 'export-form'));
     $container->append($form);
     $form->setAttrib('id', 'autosubmit');
     $form->setAutoSubmit(\MUtil_Html::attrib('href', array('action' => $this->request->getActionName(), 'RouteReset' => true)), 'export-form', true);
     return $container;
 }
 /**
  * Create the snippets content
  *
  * This is a stub function either override getHtmlOutput() or override render()
  *
  * @param \Zend_View_Abstract $view Just in case it is needed here
  * @return \MUtil_Html_HtmlInterface Something that can be rendered
  */
 public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $tabs = $this->getTabs();
     if ($tabs && ($this->displaySingleTab || count($tabs) > 1)) {
         // Set the correct parameters
         $this->getCurrentTab($tabs);
         // Let loose
         if (is_array($this->baseUrl)) {
             $this->href = $this->href + $this->baseUrl;
         }
         if (\MUtil_Bootstrap::enabled()) {
             $tabRow = \MUtil_Html::create()->ul();
             foreach ($tabs as $tabId => $content) {
                 $li = $tabRow->li(array('class' => $this->tabClass));
                 $li->a($this->getParameterKeysFor($tabId) + $this->href, $content);
                 if ($this->currentTab == $tabId) {
                     $li->appendAttrib('class', $this->tabActiveClass);
                 }
             }
         } else {
             $tabRow = \MUtil_Html::create()->div();
             foreach ($tabs as $tabId => $content) {
                 $div = $tabRow->div(array('class' => $this->tabClass));
                 $div->a($this->getParameterKeysFor($tabId) + $this->href, $content);
                 if ($this->currentTab == $tabId) {
                     $div->appendAttrib('class', $this->tabActiveClass);
                 }
             }
         }
         return $tabRow;
     } else {
         return null;
     }
 }
 protected function _getTracks($trackType, $pageRef, $trackTypeDescription)
 {
     switch ($trackType) {
         case 'tracks':
             $action = 'create';
             break;
         case 'respondents':
         case 'staff':
             $action = 'insert';
             break;
     }
     $orgId = intval($this->request->getParam(\MUtil_Model::REQUEST_ID2));
     $cacheId = strtr(__CLASS__ . '_' . $trackType . '_' . $orgId, '\\/', '__');
     $tracks = $this->cache->load($cacheId);
     if (!$tracks) {
         switch ($trackType) {
             case 'tracks':
                 $sql = "SELECT gtr_id_track, gtr_track_name\n                        FROM gems__tracks\n                        WHERE gtr_date_start < CURRENT_TIMESTAMP AND\n                            (gtr_date_until IS NULL OR gtr_date_until > CURRENT_TIMESTAMP) AND\n                            gtr_active = 1 AND\n                            gtr_organizations LIKE '%|{$orgId}|%'\n                         ORDER BY gtr_track_name";
                 break;
             case 'respondents':
                 $sql = "SELECT gsu_id_survey, gsu_survey_name\n                        FROM gems__surveys INNER JOIN gems__groups ON gsu_id_primary_group = ggp_id_group\n                        WHERE gsu_surveyor_active = 1 AND\n                            gsu_active = 1 AND\n                            ggp_group_active = 1 AND\n                            ggp_respondent_members = 1 AND\n                            gsu_insertable = 1 AND\n                            gsu_insert_organizations LIKE '%|{$orgId}|%'\n                        ORDER BY gsu_survey_name";
                 break;
             case 'staff':
                 $sql = "SELECT gsu_id_survey, gsu_survey_name\n                        FROM gems__surveys INNER JOIN gems__groups ON gsu_id_primary_group = ggp_id_group\n                        WHERE gsu_surveyor_active = 1 AND\n                            gsu_active = 1 AND\n                            ggp_group_active = 1 AND\n                            ggp_staff_members = 1 AND\n                            gsu_insertable = 1 AND\n                            gsu_insert_organizations LIKE '%|{$orgId}|%'\n                        ORDER BY gsu_survey_name";
                 break;
         }
         $tracks = $this->db->fetchPairs($sql);
         $this->cache->save($tracks, $cacheId, array('surveys', 'tracks'));
     }
     $div = \MUtil_Html::create()->div(array('class' => 'toolbox btn-group'));
     $menuIndex = $this->menu->findController('track', 'index');
     if ($tracks) {
         $menuCreate = $this->menu->findController('track', $action);
         if (!$menuCreate->isAllowed()) {
             return null;
         }
         if (\MUtil_Bootstrap::enabled()) {
             $div->button($trackTypeDescription, array('class' => 'toolanchor btn', 'data-toggle' => 'dropdown', 'type' => 'button'));
             $dropdownButton = $div->button(array('class' => 'btn dropdown-toggle', 'data-toggle' => 'dropdown', 'type' => 'button'));
             $dropdownButton->span(array('class' => 'caret', 'renderClosingTag' => true));
         } else {
             $div->a($menuIndex->toHRefAttribute($this->request), $trackTypeDescription, array('class' => 'toolanchor'));
         }
         $data = new \MUtil_Lazy_RepeatableByKeyValue($tracks);
         if ($trackType == 'tracks') {
             $menuView = $this->menu->findController('track', 'view');
             $params = array('gtr_id_track' => $data->key);
         } else {
             $menuView = $this->menu->findController('track', 'view-survey');
             $params = array('gsu_id_survey' => $data->key);
         }
         if (\MUtil_Bootstrap::enabled()) {
             if (count($tracks) > $this->scrollTreshold) {
                 // Add a header and scroll class so we keep rounded corners
                 $top = $div->ul(array('class' => 'dropdown-menu', 'role' => 'menu'));
                 $link = $top->li(array('class' => 'disabled'))->a('#');
                 $link->i(array('class' => 'fa fa-chevron-down fa-fw pull-left', 'renderClosingTag' => true));
                 $link->i(array('class' => 'fa fa-chevron-down fa-fw pull-right', 'renderClosingTag' => true));
                 // Add extra scroll-menu class
                 $li = $top->li()->ul(array('class' => 'dropdown-menu scroll-menu', 'role' => 'menu'), $data)->li();
             } else {
                 $li = $div->ul(array('class' => 'dropdown-menu', 'role' => 'menu'), $data)->li();
             }
             $link = $li->a($menuView->toHRefAttribute($this->request, $params), array('class' => 'rightFloat info'));
             $link->i(array('class' => 'fa fa-info-circle'))->raw('&nbsp;');
             if (count($tracks) > $this->scrollTreshold) {
                 // Add a footer so we keep rounded corners
                 $link = $top->li(array('class' => 'disabled'))->a('#');
                 $link->i(array('class' => 'fa fa-chevron-up fa-fw pull-left', 'renderClosingTag' => true));
                 $link->i(array('class' => 'fa fa-chevron-up fa-fw pull-right', 'renderClosingTag' => true));
             }
         } else {
             $li = $div->ul($data)->li();
             $li->a($menuView->toHRefAttribute($this->request, $params), array('class' => 'rightFloat'))->img(array('src' => 'info.png', 'width' => 12, 'height' => 12, 'alt' => $this->_('info')));
         }
         $toolboxRowAttributes = array('class' => 'add');
         $li->a($menuCreate->toHRefAttribute($this->request, $params), $data->value, $toolboxRowAttributes);
     } else {
         if (\MUtil_Bootstrap::enabled()) {
             $div->button($trackTypeDescription, array('class' => 'toolanchor btn disabled', 'data-toggle' => 'dropdown', 'type' => 'button'));
             $dropdownButton = $div->button(array('class' => 'disabled btn dropdown-toggle', 'data-toggle' => 'dropdown', 'type' => 'button'));
             $dropdownButton->span(array('class' => 'caret', 'renderClosingTag' => true));
             $options = array('class' => 'dropdown-menu disabled', 'role' => 'menu');
         } else {
             $div->a($menuIndex->toHRefAttribute($this->request), $trackTypeDescription, array('class' => 'toolanchor disabled'));
             $options = array('class' => 'disabled');
         }
         $div->ul($this->_('None available'), $options);
     }
     return $div;
 }
 /**
  * Load default decorators
  *
  * @return \Zend_Form_Element
  */
 public function loadDefaultDecorators()
 {
     if ($this->loadDefaultDecoratorsIsDisabled()) {
         return $this;
     }
     $htmlTagOptions = array('tag' => 'div', 'id' => array('callback' => array(get_class($this), 'resolveElementId')));
     $labelOptions = array();
     if (\MUtil_Bootstrap::enabled()) {
         $htmlTagOptions['class'] = 'element-container';
     }
     $decorators = $this->getDecorators();
     if (empty($decorators)) {
         $this->addDecorator('ViewHelper')->addDecorator('Errors')->addDecorator('Description', array('tag' => 'p', 'class' => 'help-block'))->addDecorator('HtmlTag', $htmlTagOptions)->addDecorator('Label')->addDecorator('BootstrapRow');
     }
     return $this;
 }
 /**
  * Creates from the model a \Zend_Form using createForm and adds elements
  * using addFormElements().
  *
  * @param int $step The current step
  * @return \Zend_Form
  */
 protected function getFormFor($step)
 {
     $model = $this->getModel();
     $baseform = $this->createForm();
     if (\MUtil_Bootstrap::enabled() !== true && $baseform instanceof \MUtil_Form) {
         $table = new \MUtil_Html_TableElement();
         $table->setAsFormLayout($baseform, true, true);
         // There is only one row with formLayout, so all in output fields get class.
         $table['tbody'][0][0]->appendAttrib('class', $this->labelClass);
     }
     $baseform->setAttrib('class', $this->class);
     $bridge = $model->getBridgeFor('form', $baseform);
     $this->_items = null;
     $this->initItems();
     $this->addFormElementsFor($bridge, $model, $step);
     return $baseform;
 }
 /**
  * Render TabsContainer with all the currently registered tabs.
  *
  * Render all tabs to the given $id. If no arguments are given the
  * tabsContainer view helper object is returned and can be used
  * for chaining {@link addPane()} for tab pane adding.
  *
  * Only change to the normal helper is that we filter out which tab is selected
  * and add a class to tabs with errors
  *
  * @link   http://docs.jquery.com/UI/Tabs
  * @param  string $id
  * @param  array  $params
  * @param  array  $attribs
  * @return string|\ZendX_JQuery_View_Helper_TabsContainer
  */
 public function tabContainer($id = null, $params = array(), $attribs = array())
 {
     if (func_num_args() === 0) {
         return $this;
     }
     $useBootstrap = \MUtil_Bootstrap::enabled();
     if (!isset($attribs['id'])) {
         $attribs['id'] = $id;
     }
     //Inserted: take care of the selected tab
     $selected = false;
     $firstSelected = true;
     if (isset($attribs['selected'])) {
         $selected = $attribs['selected'];
         unset($attribs['selected']);
         $firstSelected = false;
     }
     $content = "";
     if (isset($this->_tabs[$id])) {
         if ($useBootstrap) {
             $list = '<ul class="nav nav-tabs">' . PHP_EOL;
         } else {
             $list = '<ul class="ui-tabs-nav">' . PHP_EOL;
         }
         $html = '<div class="tab-content">';
         $fragment_counter = 1;
         $tabIndex = 0;
         foreach ($this->_tabs[$id] as $k => $v) {
             $frag_name = sprintf('%s-frag-%d', $attribs['id'], $fragment_counter++);
             $opts = $v['options'];
             $class = '';
             if (!$useBootstrap) {
                 $class = 'ui-tabs-nav-item ';
             }
             $active = '';
             if (isset($opts['class'])) {
                 $class .= $opts['class'];
             }
             if ($firstSelected || $tabIndex == $selected) {
                 $class .= ' active';
                 $active = ' active';
                 $firstSelected = false;
             }
             $tabIndex++;
             if ($class) {
                 $class = ' class="' . $class . '"';
             }
             if (isset($opts['contentUrl'])) {
                 $list .= '<li' . $class . '><a role="tab" data-toggle="tab" href="' . $opts['contentUrl'] . '"><span>' . $v['name'] . '</span></a></li>' . PHP_EOL;
             } else {
                 $list .= '<li' . $class . '><a role="tab" data-toggle="tab" href="#' . $frag_name . '"><span>' . $v['name'] . '</span></a></li>' . PHP_EOL;
                 $html .= '<h3 class="print-only">' . $v['name'] . '</h3>';
                 /* For printing of tab forms */
                 $html .= '<div id="' . $frag_name . '" class="tab-pane' . $active . '">' . $v['content'] . '</div>' . PHP_EOL;
             }
         }
         $list .= '</ul>' . PHP_EOL;
         $html .= '</div>' . PHP_EOL;
         $content = $list . $html;
         unset($this->_tabs[$id]);
     }
     if (count($params)) {
         $params = \ZendX_JQuery::encodeJson($params);
     } else {
         $params = '{}';
     }
     $html = '<div' . $this->_htmlAttribs($attribs) . '>' . PHP_EOL . $content . '</div>' . PHP_EOL;
     //Load the selected tab if jQuery UI tabs
     if (!$useBootstrap) {
         $js = sprintf('%s("#%s").tabs(%s);', \ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), $attribs['id'], $params);
         if (isset($selected)) {
             $js .= sprintf('
                 %s("#%s").tabs("option", "active", %d);', \ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), $attribs['id'], $selected);
         }
         $this->jquery->addOnLoad($js);
     }
     return $html;
 }
 /**
  * Perform some actions on the form, right before it is displayed but already populated
  *
  * Here we add the table display to the form.
  *
  * @return \Zend_Form
  */
 public function beforeDisplay()
 {
     if ($this->_csrf) {
         $this->_csrf->initCsrfToken();
     }
     $links = $this->getMenuList();
     if (\MUtil_Bootstrap::enabled()) {
         if ($links) {
             $element = $this->_form->createElement('html', 'menuLinks');
             $element->setValue($links);
             $element->setOrder(999);
             $this->_form->addElement($element);
         }
     } else {
         $table = new \MUtil_Html_TableElement(array('class' => $this->class));
         $table->setAsFormLayout($this->_form, true, true);
         // There is only one row with formLayout, so all in output fields get class.
         $table['tbody'][0][0]->appendAttrib('class', $this->labelClass);
         if ($links) {
             $table->tf();
             // Add empty cell, no label
             $table->tf($links);
         }
     }
 }
 /**
  * Creates an empty form. Allows overruling in sub-classes.
  *
  * @param mixed $options
  * @return \Zend_Form
  */
 protected function createForm($options = null)
 {
     $form = new \MUtil_Form($options);
     if (MUtil_Bootstrap::enabled()) {
         $form->activateBootstrap();
     }
     return $form;
 }
Exemple #12
0
 public function addToggleCheckboxes($name, $arrayOrKey1 = null, $value1 = null, $key2 = null, $value2 = null)
 {
     $options = $this->_mergeOptions($name, \MUtil_Ra::pairs(func_get_args(), 1), self::DISPLAY_OPTIONS, array('selector', 'selectorName'));
     if (!isset($options['label'])) {
         if (isset($options['selectorName']) && $this->model->has($options['selectorName'], 'label')) {
             $options['label'] = sprintf('Toggle %s', $this->model->get($options['selectorName'], 'label'));
         } else {
             $options['label'] = 'Toggle';
         }
     }
     if (isset($options['selectorName'])) {
         $options['selector'] = sprintf('input[name^=%s]', $options['selectorName']);
         unset($options['selectorName']);
     }
     $this->form->activateJQuery();
     if (\MUtil_Bootstrap::enabled() || !class_exists('Gems_JQuery_Form_Element_ToggleCheckboxes')) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes($name, $options);
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes($name, $options);
     }
     $this->form->addElement($element);
     return $element;
 }
 /**
  * Hook 3: Called in $this->setRequest.
  *
  * All resources have been loaded and the $request object is created.
  * Theoretically this event can be triggered multiple times, but this does
  * not happen in a standard Zend application.
  *
  * Not initialized are the $response and $controller objects.
  *
  * Previous hook: beforeRun()
  * Actions since: $this->request object created
  * Actions after: $this->response object created
  * Next hook: responseChanged()
  *
  * @param \Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function requestChanged(\Zend_Controller_Request_Abstract $request)
 {
     if ($this->project->isMultiLocale()) {
         // Get the choosen language
         $localeId = \Gems_Cookies::getLocale($request);
         // Change when $localeId exists and is different from session
         if ($localeId && $this->locale->getLanguage() !== $localeId) {
             // \MUtil_Echo::r('On cookie ' . $localeId . ' <> ' . $this->locale->getLanguage());
             // Does the locale exist?
             if (isset($this->project->locales[$localeId])) {
                 // Add and implement the choosen locale
                 $this->session->user_locale = $localeId;
                 $this->locale->setLocale($localeId);
                 if (!$this->translate->isAvailable($localeId)) {
                     $languageFilename = APPLICATION_PATH . '/languages/default-' . $localeId . '.mo';
                     if (file_exists($languageFilename)) {
                         $this->translate->addTranslation($languageFilename, $localeId);
                     }
                 }
                 $this->translate->setLocale($localeId);
                 $this->translateAdapter = $this->translate->getAdapter();
             }
         }
     }
     // Set the base path, the route is now fixed
     $this->basepath->setBasePath($request->getBasePath());
     // Set the jQuery version and other information needed
     // by classes using jQuery
     $jquery = \MUtil_JQuery::jQuery();
     $jqueryVersion = '1.11.1';
     $jqueryUiVersion = '1.11.1';
     $jquery->setVersion($jqueryVersion);
     $jquery->setUiVersion($jqueryUiVersion);
     if ($this->project->isJQueryLocal()) {
         $jqueryDir = $request->getBasePath() . $this->project->getJQueryLocal();
         $jquery->setLocalPath($jqueryDir . 'jquery-' . $jqueryVersion . '.js');
         $jquery->setUiLocalPath($jqueryDir . 'jquery-ui-' . $jqueryUiVersion . '.js');
     } else {
         if (\MUtil_Https::on()) {
             $jquery->setCdnSsl(true);
         }
     }
     if (\MUtil_Bootstrap::enabled() && $this->project->isBootstrapLocal()) {
         $bootstrap = \MUtil_Bootstrap::bootstrap();
         $basePath = $request->getBasePath();
         $bootstrap->setBootstrapScriptPath($basePath . '/bootstrap/js/bootstrap.min.js');
         $bootstrap->setBootstrapStylePath($basePath . '/bootstrap/css/bootstrap.min.css');
         $bootstrap->setFontAwesomeStylePath($basePath . '/bootstrap/css/font-awesome.min.css');
     }
 }
 protected function beforeDisplay()
 {
     if (!\MUtil_Bootstrap::enabled()) {
         $table = new \MUtil_Html_TableElement(array('class' => $this->formClass));
         $table->setAsFormLayout($this->form, true, true);
         // There is only one row with formLayout, so all in output fields get class.
         $table['tbody'][0][0]->appendAttrib('class', $this->labelClass);
     }
 }
 public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $post = $this->request->getPost();
     $currentTrack = null;
     if (isset($post['gto_id_track'])) {
         $currentTrack = $post['gto_id_track'];
     }
     $currentRound = null;
     if (isset($post['gto_round_description'])) {
         $currentRound = $post['gto_round_description'];
     }
     $export = $this->loader->getExport();
     $exportTypes = $export->getExportClasses();
     if (isset($post['type'])) {
         $currentType = $post['type'];
     } else {
         reset($exportTypes);
         $currentType = key($exportTypes);
     }
     $dbLookup = $this->util->getDbLookup();
     $translated = $this->util->getTranslated();
     $noRound = array(self::NoRound => $this->_('No round description'));
     $empty = $translated->getEmptyDropdownArray();
     $tracks = $empty + $this->util->getTrackData()->getAllTracks();
     $rounds = $empty + $noRound + $dbLookup->getRoundsForExport($currentTrack);
     $surveys = $dbLookup->getSurveysForExport($currentTrack, $currentRound, true);
     $organizations = $this->currentUser->getRespondentOrganizations();
     if (\MUtil_Bootstrap::enabled()) {
         $this->form = new \Gems_Form(array('class' => 'form-horizontal'));
     } else {
         $this->form = new \Gems_Form_TableForm();
     }
     $url = \MUtil_Html::attrib('href', array('action' => 'index', 'step' => 'batch'));
     $this->form->setAction($url);
     $elements = array();
     $elements['gto_id_track'] = $this->form->createElement('select', 'gto_id_track', array('label' => $this->_('Track'), 'multiOptions' => $tracks, 'class' => 'autosubmit'));
     if (isset($post['gto_id_track']) && $post['gto_id_track']) {
         $element = $this->form->createElement('checkbox', 'add_track_fields');
         $element->setLabel($this->_('Track fields'));
         $element->setDescription($this->_('Add track fields to export'));
         $elements['add_track_fields'] = $element;
         if (!array_key_exists('add_track_fields', $post)) {
             $post['add_track_fields'] = 1;
         }
     }
     $elements['gto_round_description'] = $this->form->createElement('select', 'gto_round_description', array('label' => $this->_('Round'), 'multiOptions' => $rounds, 'class' => 'autosubmit'));
     $elements['gto_id_survey'] = $this->form->createElement('multiCheckbox', 'gto_id_survey', array('label' => $this->_('Survey'), 'multiOptions' => $surveys));
     $elements['gto_id_survey']->setRequired(true);
     $elements['gto_id_survey']->setSeparator('');
     if (\MUtil_Bootstrap::enabled()) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gto_id_survey]'));
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gto_id_survey]'));
     }
     $element->setLabel($this->_('Toggle'));
     $elements[] = $element;
     if (count($organizations) > 1) {
         $elements['gto_id_organization'] = $this->form->createElement('multiCheckbox', 'gto_id_organization', array('label' => $this->_('Organizations'), 'multiOptions' => $organizations));
         if (\MUtil_Bootstrap::enabled()) {
             $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gto_id_organization]'));
         } else {
             $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gto_id_organization]'));
         }
         $element->setLabel($this->_('Toggle'));
         $elements[] = $element;
     }
     $dates = array('gto_start_date' => $this->_('Track start'), 'gto_end_date' => $this->_('Track end'), 'gto_valid_from' => $this->_('Valid from'), 'gto_valid_until' => $this->_('Valid until'));
     // $dates = 'gto_valid_from';
     $periodElements = $this->getPeriodSelectors($dates, 'gto_valid_from');
     $elements += $periodElements;
     $element = $this->form->createElement('textarea', 'ids');
     $element->setLabel($this->_('Respondent id\'s'))->setAttrib('cols', 60)->setAttrib('rows', 4)->setDescription($this->_("Not respondent nr, but respondent id as exported here. Separate multiple id's with , or ;"));
     $elements[] = $element;
     $element = $this->form->createElement('checkbox', 'column_identifiers');
     $element->setLabel($this->_('Column Identifiers'));
     $element->setDescription($this->_('Prefix the column labels with an identifier. (A) Answers, (TF) Trackfields, (D) Description'));
     $elements['column_identifiers'] = $element;
     $element = $this->form->createElement('checkbox', 'show_parent');
     $element->setLabel($this->_('Show parent'));
     $element->setDescription($this->_('Show the parent column even if it doesn\'t have answers'));
     $elements['show_parent'] = $element;
     $element = $this->form->createElement('checkbox', 'prefix_child');
     $element->setLabel($this->_('Prefix child'));
     $element->setDescription($this->_('Prefix the child column labels with parent question label'));
     $elements['prefix_child'] = $element;
     $elements['type'] = $this->form->createElement('select', 'type', array('label' => $this->_('Export to'), 'multiOptions' => $exportTypes, 'class' => 'autosubmit'));
     $this->form->addElements($elements);
     $exportClass = $export->getExport($currentType);
     $exportName = $exportClass->getName();
     $exportFormElements = $exportClass->getFormElements($this->form, $data);
     if ($exportFormElements) {
         $exportFormElements['firstCheck'] = $this->form->createElement('hidden', $currentType);
         $exportFormElements['firstCheck']->setBelongsTo($exportName);
         $this->form->addElements($exportFormElements);
     }
     if (!isset($post[$currentType])) {
         $post[$exportName] = $exportClass->getDefaultFormValues();
     }
     $element = $this->form->createElement('submit', 'export_submit', array('label' => $this->_('Export')));
     $this->form->addElement($element);
     if ($post) {
         $this->form->populate($post);
     }
     $container = \MUtil_Html::div(array('id' => 'export-surveys-form'));
     $container->append($this->form);
     $this->form->setAttrib('id', 'autosubmit');
     $this->form->setAutoSubmit(\MUtil_Html::attrib('href', array('action' => 'index', 'RouteReset' => true)), 'export-surveys-form', true);
     return $container;
 }
 /**
  * Creates an empty form. Allows overruling in sub-classes.
  *
  * @param mixed $options
  * @return \Zend_Form
  */
 protected function createForm($options = null)
 {
     if ($this->useTabbedForm) {
         return new \Gems_TabForm($options);
     }
     if (\MUtil_Bootstrap::enabled()) {
         if (!isset($options['class'])) {
             $options['class'] = 'form-horizontal';
         }
         if (!isset($options['role'])) {
             $options['role'] = 'form';
         }
     }
     return new \Gems_Form($options);
 }
 public function patchAction()
 {
     $this->html->h3($this->_('Patch maintenance'));
     $patcher = new \Gems_Util_DatabasePatcher($this->db, 'patches.sql', $this->escort->getDatabasePaths());
     $tableSql = sprintf('SELECT gpa_level AS `%s`, gpa_location AS `%s`, COUNT(*) AS `%s`, COUNT(*) - SUM(gpa_executed) AS `%s`, SUM(gpa_executed) AS `%s`, SUM(gpa_completed) AS `%s`, MAX(gpa_changed) AS `%s` FROM gems__patches GROUP BY gpa_level, gpa_location ORDER BY gpa_level DESC, gpa_location', $this->_('Level'), $this->_('Subtype'), $this->_('Patches'), $this->_('To be executed'), $this->_('Executed'), $this->_('Finished'), $this->_('Changed on'));
     $form = $this->createForm();
     $form->setName('database_patcher');
     $form->addElement($form->createElement('exhibitor', 'app_level', array('label' => $this->_('Gems build'))));
     $form->addElement($form->createElement('exhibitor', 'db_level', array('label' => $this->_('Database build'))));
     $level = $form->createElement('text', 'level', array('label' => $this->_('Execute level')));
     $level->addValidator(new \Zend_Validate_Digits());
     $form->addElement($level);
     $form->addElement($form->createElement('checkbox', 'completed', array('label' => $this->_('Ignore finished'))));
     $form->addElement($form->createElement('checkbox', 'executed', array('label' => $this->_('Ignore executed'))));
     $form->addElement($form->createElement('submit', 'show_button', array('label' => $this->_('Show patches'), 'class' => 'button')));
     // $execute = new \Zend_Form_Element_Submit('save_button',   array('label' => $this->_('Execute'), 'class' => 'button'));
     // $form->addElement($execute);
     if ($this->request->isPost()) {
         $data = $this->request->getPost();
         if ($form->isValid($data)) {
             $batch = $this->loader->getTaskRunnerBatch(__CLASS__ . $data['level']);
             $batch->setFormId($form->getId());
             if (!$batch->isLoaded()) {
                 $patcher->loadPatchBatch($data['level'], $data['completed'], $data['executed'], $batch);
             }
             $this->_helper->batchRunner($batch, sprintf($this->_('Executing patch level %d'), $data['level']), $this->accesslog);
             $data['db_level'] = $data['level'];
             $form->getElement('db_level')->setValue($data['db_level']);
             $tableSql = sprintf('SELECT gpa_id_patch AS `%s`, gpa_level AS `%s`, gpa_location AS `%s`, gpa_name AS `%s`, gpa_sql AS `%s`, gpa_executed AS `%s`, gpa_completed AS `%s`, gpa_result AS `%s`, gpa_changed AS `%s` FROM gems__patches WHERE gpa_level = ? ORDER BY gpa_level, gpa_changed DESC, gpa_location, gpa_name, gpa_order', $this->_('Patch'), $this->_('Level'), $this->_('Subtype'), $this->_('Name'), $this->_('Query'), $this->_('Executed'), $this->_('Finished'), $this->_('Result'), $this->_('Changed on'));
             $tableSql = $this->db->quoteInto($tableSql, $data['level']);
             // Hide the form: it is needed for the batch post, but we do not want it visible
             $form->setAttrib('style', 'display: none;');
             if ($this->getMessenger()->getCurrentMessages()) {
                 $this->accesslog->logChange($this->_request);
             }
         }
     } else {
         $changed = $patcher->uploadPatches($this->loader->getVersions()->getBuild());
         if ($changed == -1) {
             $this->addMessage($this->_('Create the patch table!'));
         } elseif ($changed) {
             $this->addMessage(sprintf($this->_('%d new or changed patch(es).'), $changed));
             $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('sess_' . session_id()));
         }
         $data['app_level'] = $this->loader->getVersions()->getBuild();
         $data['db_level'] = $this->db->fetchOne('SELECT gpl_level FROM gems__patch_levels ORDER BY gpl_level DESC');
         $data['level'] = min($data['db_level'] + 1, $data['app_level']);
         $data['completed'] = 1;
         $data['executed'] = 0;
         $form->populate($data);
     }
     if (!\MUtil_Bootstrap::enabled()) {
         $table = new \MUtil_Html_TableElement(array('class' => 'formTable'));
         $table->setAsFormLayout($form, true, true);
         $table['tbody'][0][0]->class = 'label';
         // Is only one row with formLayout, so all in output fields get class.
         if ($links = $this->createMenuLinks(1)) {
             $table->tf();
             // Add empty cell, no label
             $linksCell = $table->tf($links);
         }
     }
     $this->html[] = $form;
     if ($data = $this->db->fetchAll($tableSql)) {
         $table = \MUtil_Html_TableElement::createArray($data, $this->_('Patch overview'), true);
         $table->class = 'browser table table-striped table-bordered table-hover table-condensed';
         $this->html[] = $table;
     }
 }
 /**
  * Preparations for creating and editing
  */
 protected function createEditPrepare()
 {
     $this->createEditSnippets = $this->getTrackEngine()->getRoundEditSnippetNames();
     \MUtil_JQuery::enableView($this->view);
     $this->view->headScript()->appendFile($this->basepath->getBasePath() . '/gems/js/jquery.showOnChecked.js');
     if (\MUtil_Bootstrap::enabled()) {
         $this->view->headScript()->appendScript("jQuery(document).ready(function(\$) {\n                \$('input[name=\"organizations[]\"]').closest('div').showOnChecked( { showInput: \$('#org_specific_round-1') });\n            });");
     } else {
         $this->view->headScript()->appendScript("jQuery(document).ready(function(\$) {\n                \$('input[name=\"organizations[]\"]').closest('tr').showOnChecked( { showInput: \$('#org_specific_round-1') });\n            });");
     }
 }
 /**
  * Creates from the model a \Zend_Form using createForm and adds elements
  * using addFormElements().
  *
  * @param int $step The current step
  * @return \Zend_Form
  */
 protected function getFormFor($step)
 {
     $baseform = $this->createForm();
     if ($this->trackEngine && $step == 4 && \MUtil_Bootstrap::enabled() !== true && $baseform instanceof \MUtil_Form) {
         $model = $this->getModel();
         $table = new \MUtil_Html_DivFormElement();
         $table->setAsFormLayout($baseform);
         $baseform->setAttrib('class', $this->class);
         $bridge = $model->getBridgeFor('form', $baseform);
         $this->_items = null;
         $this->initItems();
         $this->addFormElementsFor($bridge, $model, $step);
         return $baseform;
     } else {
         return parent::getFormFor($step);
     }
 }
 /**
  * Create a page panel
  *
  * @param mixed $paginator \MUtil_Ra::args() arguements
  * @param mixed $request
  * @param mixed $translator
  * @param mixed $args
  * @return \MUtil_Html_PagePanel
  */
 public static function pagePanel($paginator = null, $request = null, $translator = null, $args = null)
 {
     $types = array('paginator' => 'Zend_Paginator', 'request' => 'Zend_Controller_Request_Abstract', 'translator' => 'Zend_Translate', 'view' => 'Zend_View');
     $args = \MUtil_Ra::args(func_get_args(), $types, null, \MUtil_Ra::STRICT);
     $panel_args = array();
     foreach (array('baseUrl', 'paginator', 'request', 'scrollingStyle', 'view', 'itemCount') as $var) {
         if (isset($args[$var])) {
             $panel_args[$var] = $args[$var];
             unset($args[$var]);
         }
     }
     if (isset($args['translator'])) {
         $translator = $args['translator'];
         unset($args['translator']);
     } else {
         $translator = \Zend_Registry::get('Zend_Translate');
     }
     if (isset($args['class'])) {
         if ($args['class'] instanceof \MUtil_Html_AttributeInterface) {
             $args['class']->add('browselink');
         } else {
             $args['class'] = new \MUtil_Html_ClassArrayAttribute('browselink', $args['class']);
         }
     } else {
         $args['class'] = new \MUtil_Html_ClassArrayAttribute('browselink');
     }
     // \MUtil_Echo::track($args);
     // \MUtil_Echo::track($panel_args['baseUrl']);
     if (\MUtil_Bootstrap::enabled()) {
         $pager = new \MUtil_Bootstrap_Html_PagePanel($panel_args);
     } else {
         $pager = new \MUtil_Html_PagePanel($panel_args);
     }
     $pager[] = $pager->pageLinks(array($translator->_('<< First'), 'class' => new \MUtil_Html_ClassArrayAttribute('browselink', 'keyHome')), array($translator->_('< Previous'), 'class' => new \MUtil_Html_ClassArrayAttribute('browselink', 'keyPgUp')), array($translator->_('Next >'), 'class' => new \MUtil_Html_ClassArrayAttribute('browselink', 'keyPgDn')), array($translator->_('Last >>'), 'class' => new \MUtil_Html_ClassArrayAttribute('browselink', 'keyEnd')), $translator->_(' | '), $args);
     $pager->div($pager->uptoOffDynamic($translator->_('to'), $translator->_('of'), array('-', 'class' => new \MUtil_Html_ClassArrayAttribute('browselink btn btn-xs', 'keyCtrlUp')), array('+', 'class' => new \MUtil_Html_ClassArrayAttribute('browselink btn btn-xs', 'keyCtrlDown')), null, ' ', $args), array('class' => 'pagination-index rightFloat pull-right'));
     return $pager;
 }
 public function activateBootstrap()
 {
     if (\MUtil_Bootstrap::enabled() === true) {
         parent::activateBootstrap();
     }
 }
 /**
  * Render the element
  *
  * @param  string $content Content to decorate
  * @return string
  */
 public function render($content)
 {
     $useBootstrap = \MUtil_Bootstrap::enabled();
     if (null === ($element = $this->getElement()) || null === ($view = $element->getView())) {
         return $content;
     }
     $cellDecorators = $this->getCellDecorators();
     $containerDiv = \MUtil_Html::create()->div(array('id' => 'tabElement'));
     if ($element instanceof \MUtil_Form_Element_Table) {
         $containerDiv->appendAttrib('class', $element->getAttrib('class'));
         $subforms = $element->getSubForms();
     } elseif ($element instanceof \Zend_Form) {
         $cellDecorators = null;
         $subforms = array($element);
     }
     if ($subforms) {
         $activeTabs = false;
         if (count($subforms) > 1) {
             $activeTabs = true;
             if (!$useBootstrap) {
                 $jquery = $view->jQuery();
                 $js = sprintf('%1$s("#tabElement").tabs();', \ZendX_JQuery_View_Helper_JQuery::getJQueryHandler());
                 if ($selectedTabElement = $this->getOption('selectedTabElement')) {
                     $js .= sprintf('%1$s("#tabElement").on("tabsactivate", function(event, ui) { console.log(ui.newTab.text()); %1$s("#%2$s").val(ui.newTab.text()) });', \ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), $selectedTabElement);
                 }
                 $jquery->addOnLoad($js);
             } else {
                 $jquery = $view->jQuery();
                 if ($selectedTabElement = $this->getOption('selectedTabElement')) {
                     $js = sprintf('%1$s(\'a[data-toggle="tab"]\').on(\'shown.bs.tab\', function (e) {
                         var tabtext = $(e.target).text();
                         %1$s("#%2$s").val(tabtext);
                 })', \ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), $selectedTabElement);
                     $jquery->addOnLoad($js);
                 }
             }
             $list = $containerDiv->ul(array('class' => 'nav nav-tabs', 'role' => 'tablist'));
         }
         $tabNumber = 0;
         $tabContainerDiv = $containerDiv->div(array('class' => 'tab-content'));
         //\MUtil_Html::create()->div(array('class' => 'tab-content'));
         $active = $this->getOption('active');
         foreach ($subforms as $subform) {
             if ($activeTabs) {
                 if ($tabcolumn = $this->getOption('tabcolumn')) {
                     $tabName = $subform->getElement($tabcolumn)->getValue();
                 } else {
                     $elements = $subform->getElements();
                     $element = reset($elements);
                     $tabName = $element->getValue();
                 }
                 $tabId = $tabName . '-tab';
                 $liOptions = array();
                 $tabPaneOptions = array('id' => $tabId, 'class' => 'tab-pane');
                 if ($active && $active == $tabName) {
                     // If a tab is active, select it
                     if (!$useBootstrap) {
                         $js = sprintf('%1$s("#tabElement").tabs({ selected: %2$d});', \ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), $tabNumber);
                         $jquery->addOnLoad($js);
                     } else {
                         $js = sprintf('%1$s(\'a[data-toggle="tab"]\').eq(%2$d).tab(\'show\');', \ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), $tabNumber);
                         $jquery->addOnLoad($js);
                     }
                     $liOptions['class'] = 'active';
                     $tabPaneOptions['class'] .= ' active';
                 }
                 $tabNumber++;
                 $list->li($liOptions)->a('#' . $tabId, $tabName, array('role' => 'tab', 'data-toggle' => 'tab'));
                 if ($useBootstrap) {
                     $subContainer = $tabContainerDiv->div($tabPaneOptions);
                 } else {
                     $subContainer = $tabContainerDiv->div($tabPaneOptions)->table(array('class' => 'formTable'));
                 }
             } else {
                 if ($useBootstrap) {
                     $subContainer = $tabContainerDiv;
                 } else {
                     $subContainer = $tabContainerDiv->table(array('class' => 'formTable'));
                 }
             }
             foreach ($subform->getElements() as $subelement) {
                 if ($subelement instanceof \Zend_Form_Element_Hidden) {
                     $this->applyDecorators($subelement, array(array('ViewHelper')));
                     $subContainer[] = $subelement;
                 } else {
                     if ($useBootstrap) {
                         $subgroup = $subContainer->div(array('class' => 'form-group'));
                         $label = $subgroup->div(array('class' => 'label-container'))->label(array('for' => $subelement->getId()));
                         $label[] = $subelement->getLabel();
                         $divContainer = $subgroup->div(array('class' => 'element-container'));
                         $divContainer[] = $subelement;
                     } else {
                         $row = $subContainer->tr();
                         $label = $row->td()->label(array('for' => $subelement->getId()));
                         $label[] = $subelement->getLabel();
                         $column = $row->td();
                         $column[] = $subelement;
                     }
                 }
             }
         }
     }
     $containerDiv->view = $view;
     $html = $containerDiv;
     return $html;
 }
 /**
  * Get form elements for the specific Export
  * @param  \Gems_Form $form existing form type
  * @param  array data existing options set in the form
  * @return array of form elements
  */
 public function getFormElements(\Gems_Form $form, &$data)
 {
     $form->activateJQuery();
     $dbLookup = $this->util->getDbLookup();
     $translated = $this->util->getTranslated();
     $noRound = array(self::NoRound => $this->_('No round description'));
     $empty = $translated->getEmptyDropdownArray();
     $dateOptions = array();
     \MUtil_Model_Bridge_FormBridge::applyFixedOptions('date', $dateOptions);
     $organizations = $this->currentUser->getRespondentOrganizations();
     $tracks = $empty + $this->util->getTrackData()->getAllTracks();
     $rounds = $empty + $noRound + $dbLookup->getRoundsForExport(isset($data['tid']) ? $data['tid'] : null);
     $surveys = $dbLookup->getSurveysForExport(isset($data['tid']) ? $data['tid'] : null, isset($data['rounds']) ? $data['rounds'] : null);
     $yesNo = $translated->getYesNo();
     $elements = array();
     $element = $form->createElement('textarea', 'ids');
     $element->setLabel($this->_('Respondent id\'s'))->setAttrib('cols', 60)->setAttrib('rows', 4)->setDescription($this->_('Not respondent nr, but respondent id as exported here.'));
     $elements[] = $element;
     $element = $form->createElement('select', 'tid');
     $element->setLabel($this->_('Tracks'))->setMultiOptions($tracks);
     $elements[] = $element;
     if (isset($data['tid']) && $data['tid']) {
         $element = $form->createElement('radio', 'tid_fields');
         $element->setLabel($this->_('Export fields'))->setMultiOptions($yesNo);
         $elements[] = $element;
         if (!array_key_exists('tid_fields', $data)) {
             $data['tid_fields'] = 1;
         }
     }
     $element = $form->createElement('select', 'rounds');
     $element->setLabel($this->_('Round description'))->setMultiOptions($rounds);
     $elements[] = $element;
     $element = $form->createElement('multiselect', 'sid');
     $element->setLabel($this->_('Survey'))->setMultiOptions($surveys)->setDescription($this->_('Use CTRL or Shift to select more'));
     $elements[] = $element;
     $element = $form->createElement('multiCheckbox', 'oid');
     $element->setLabel($this->_('Organization'))->setMultiOptions($organizations);
     $elements[] = $element;
     if (\MUtil_Bootstrap::enabled()) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=oid]'));
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=oid]'));
     }
     $element->setLabel($this->_('Toggle'));
     $elements[] = $element;
     $element = $form->createElement('datePicker', 'valid_from', $dateOptions);
     $element->setLabel($this->_('Valid from'));
     $elements[] = $element;
     $element = $form->createElement('datePicker', 'valid_until', $dateOptions);
     $element->setLabel($this->_('Valid until'));
     $elements[] = $element;
     if (\MUtil_Bootstrap::enabled()) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=oid]'));
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=oid]'));
     }
     $element = $form->createElement('checkbox', 'column_identifiers');
     $element->setLabel($this->_('Column Identifiers'));
     $element->setDescription($this->_('Prefix the column labels with an identifier. (A) Answers, (TF) Trackfields, (D) Description'));
     $elements[] = $element;
     //unset($data['records']);
     if (!empty($data['sid'])) {
         $filters = $this->getFilters($data);
         foreach ($filters as $key => $filter) {
             unset($data['records_' . $key]);
             $model = $this->getModel($filter, $data);
             $survey = $this->loader->getTracker()->getSurvey(intval($filter['gto_id_survey']));
             $recordCount = $model->loadPaginator($filter)->getTotalItemCount();
             $element = $form->createElement('exhibitor', 'records_' . $key);
             $element->setValue($survey->getName() . ': ' . sprintf($this->_('%s records found.'), $recordCount));
             //$element->setValue($survey->getName());
             $elements[] = $element;
         }
     }
     if ($this->project->hasResponseDatabase()) {
         $this->addResponseDatabaseForm($form, $data, $elements);
     }
     return $elements;
 }
 /**
  * Makes sure there is a form.
  */
 protected function loadForm()
 {
     if (!$this->_form) {
         $options = array();
         if (\MUtil_Bootstrap::enabled()) {
             $options['class'] = 'form-horizontal';
             $options['role'] = 'form';
         }
         $this->_form = $this->createForm($options);
         $this->addFormElements($this->_form);
     }
 }
Exemple #25
0
 /**
 * jQuery-enable a form instance
 *
 * @param  \Zend_Form $form
 * @return void
 * /
     public static function enableForm(\Zend_Form $form)
     {
    $form->addPrefixPath('MUtil_Bootstrap_Form_Decorator', 'MUtil/Bootstrap/Form/Decorator', 'decorator')
         ->addPrefixPath('MUtil_Bootstrap_Form_Element', 'MUtil/Bootstrap/Form/Element', 'element')
         ->addElementPrefixPath('MUtil_Bootstrap_Form_Decorator', 'MUtil/Bootstrap/Form/Decorator', 'decorator')
         ->addDisplayGroupPrefixPath('MUtil_Bootstrap_Form_Decorator', 'MUtil/Bootstrap/Form/Decorator');
 
    foreach ($form->getSubForms() as $subForm) {
        self::enableForm($subForm);
    }
 
    if (null !== ($view = $form->getView())) {
        self::enableView($view);
    }
     }
 
     /**
 * Bootstrap-enable a view instance
 *
 * @param  \Zend_View_Interface $view
 * @return void
 */
 public static function enableView(\Zend_View_Interface $view)
 {
     if (!\MUtil_JQuery::usesJQuery($view)) {
         \MUtil_JQuery::enableView($view);
     }
     if (false === $view->getPluginLoader('helper')->getPaths('MUtil_Bootstrap_View_Helper')) {
         $view->addHelperPath('MUtil/Bootstrap/View/Helper', 'MUtil_Bootstrap_View_Helper');
     }
     self::$_bootstrap = $view->bootstrap();
 }
 /**
  * Perform some actions on the form, right before it is displayed but already populated
  *
  * Here we add the table display to the form.
  *
  * @param \Zend_Form $form
  * @param bool      $isNew
  * @return \Zend_Form
  */
 public function beforeFormDisplay($form, $isNew)
 {
     if ($this->useTabbedForms || $form instanceof \Gems_Form_TableForm) {
         //If needed, add a row of link buttons to the bottom of the form
         if ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) {
             $linkContainer = \MUtil_Html::create()->div(array('class' => 'element-container-labelless'));
             $linkContainer[] = $links;
             $element = $form->createElement('html', 'formLinks');
             $element->setValue($linkContainer);
             $element->setOrder(999);
             if ($form instanceof \Gems_TabForm) {
                 $form->resetContext();
             }
             $form->addElement($element);
             $form->addDisplayGroup(array('formLinks'), 'form_buttons');
         }
     } else {
         if (\MUtil_Bootstrap::enabled() !== true) {
             $table = new \MUtil_Html_TableElement(array('class' => 'formTable'));
             $table->setAsFormLayout($form, true, true);
             $table['tbody'][0][0]->class = 'label';
             // Is only one row with formLayout, so all in output fields get class.
             if ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) {
                 $table->tf();
                 // Add empty cell, no label
                 $linksCell = $table->tf($links);
             }
         } elseif ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) {
             $element = $form->createElement('html', 'menuLinks');
             $element->setValue($links);
             $element->setOrder(999);
             $form->addElement($element);
         }
     }
     return $form;
 }
Exemple #27
0
 /**
  * Load the default decorators
  *
  * @return void
  */
 public function loadDefaultDecorators()
 {
     if ($this->loadDefaultDecoratorsIsDisabled()) {
         return;
     }
     $decorators = $this->getDecorators();
     if (empty($decorators)) {
         $this->addDecorator('AutoFocus')->addDecorator('FormElements');
         if (!\MUtil_Bootstrap::enabled()) {
             $this->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'));
         }
         $this->addDecorator('Form');
     }
 }
 /**
  * Adds elements from the model to the bridge that creates the form.
  *
  * Overrule this function to add different elements to the browse table, without
  * having to recode the core table building code.
  *
  * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge
  * @param \MUtil_Model_ModelAbstract $model
  */
 protected function addFormElements(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model)
 {
     if (!$this->createData) {
         $bridge->addHidden('gtr_id_track');
     }
     $bridge->addText('gtr_track_name');
     // gtr_track_class
     if ($this->trackEngine) {
         $options = $model->get('gtr_track_class', 'multiOptions');
         $alternatives = $this->trackEngine->getConversionTargets($options);
         if (count($alternatives) > 1) {
             $options = $alternatives;
             $bridge->addHidden($this->_oldClassName);
             if (!isset($this->formData[$this->_oldClassName])) {
                 $this->formData[$this->_oldClassName] = $this->formData['gtr_track_class'];
             }
             $classEdit = true;
         } else {
             $classEdit = false;
         }
     } else {
         $tracker = $this->loader->getTracker();
         $options = $tracker->getTrackEngineList(true, true);
         $classEdit = true;
     }
     $model->set('gtr_track_class', 'multiOptions', $options, 'escape', false);
     if ($classEdit) {
         $bridge->addRadio('gtr_track_class');
     } else {
         $bridge->addExhibitor('gtr_track_class');
     }
     $bridge->addDate('gtr_date_start');
     $bridge->addDate('gtr_date_until');
     if (!$this->createData) {
         $bridge->addCheckbox('gtr_active');
     }
     if ($model->has('gtr_code')) {
         $bridge->addText('gtr_code');
     }
     if ($model->has('gtr_calculation_event', 'label')) {
         $bridge->add('gtr_calculation_event');
     }
     if ($model->has('gtr_completed_event', 'label')) {
         $bridge->add('gtr_completed_event');
     }
     if ($model->has('gtr_beforefieldupdate_event', 'label')) {
         $bridge->add('gtr_beforefieldupdate_event');
     }
     if ($model->has('gtr_fieldupdate_event', 'label')) {
         $bridge->add('gtr_fieldupdate_event');
     }
     $bridge->add('gtr_organizations');
     if (\MUtil_Bootstrap::enabled()) {
         $element = new \MUtil_Bootstrap_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gtr_organizations]'));
     } else {
         $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector' => 'input[name^=gtr_organizations]'));
     }
     $element->setLabel($this->_('Toggle'));
     $bridge->addElement($element);
 }
 /**
  * Retrieve the form
  *
  * @param array $data
  * @return \Gems_Form
  */
 public function getForm(&$data)
 {
     // \MUtil_Echo::track($data);
     $types = $this->export->getExportClasses();
     $elements = array();
     // $exportModelSources = $this->export->getExportModelSources();
     //Create the basic form
     if (\MUtil_Bootstrap::enabled()) {
         $form = new \Gems_Form(array('class' => 'form-horizontal'));
     } else {
         $form = new \Gems_Form_TableForm();
     }
     /*$element = $form->createElement('select', 'exportmodelsource');
       $element->setLabel($this->_('Export'))
           ->setMultiOptions($exportModelSources);
       $elements[] = $element;*/
     if ($this->exportModelSource) {
         $exportModelSource = $this->loader->getExportModelSource($this->exportModelSource);
         $exportFormElements = $exportModelSource->getFormElements($form, $data);
         $elements = array_merge($elements, $exportFormElements);
     }
     $form->getDecorator('AutoFocus')->setSelectall(false);
     $element = $form->createElement('select', 'type');
     $element->setLabel($this->_('Export to'))->setMultiOptions($types);
     $elements[] = $element;
     //Add all elements to the form
     $form->addElements($elements);
     unset($elements);
     //Now make a change for the selected export type
     if (isset($data['type'])) {
         $exportClass = $this->export->getExport($data['type']);
         $formFields = $exportClass->getFormElements($form, $data);
         $exportName = $exportClass->getName();
         //Now add a hidden field so we know that when this is present in the $data
         //we don't need to set the defaults
         $formFields[] = new \Zend_Form_Element_Hidden($exportName);
         foreach ($formFields as $formField) {
             $formField->setBelongsTo($exportName);
             $form->addElement($formField);
         }
         if (!isset($data[$exportName])) {
             $data[$exportName] = $exportClass->getDefaultFormValues();
         }
     }
     //Finally create a submit button and add to the form
     $element = $form->createElement('submit', 'export');
     $element->setLabel('Export');
     $form->addElement($element);
     return $form;
 }