Example #1
0
 public function render()
 {
     View::addCoreLib(array('style.css', 'view:alert.js'));
     $params = array('title' => $this->_obj->getTitle(), 'level' => 'error', 'buttons' => array('confirm' => true), 'labels' => array('confirm' => "Afficher mes livraisons"), 'callbacks' => array('confirm' => "document.location.replace('/livraisons/livraison/validation')"));
     $event = sprintf('new t41.view.alert("%s",%s)', implode('<br/>', $this->_obj->getContent()), \Zend_Json::encode($params));
     View::addEvent($event, 'js');
 }
Example #2
0
 protected function _render()
 {
     $content = null;
     $elems = View::getObjects(View::PH_DEFAULT);
     if (is_array($elems)) {
         foreach ($elems as $elem) {
             $object = $elem[0];
             $params = $elem[1];
             if (!is_object($object)) {
                 continue;
             }
             /* @var $object t41\View\ViewObject */
             switch (get_class($object)) {
                 case 't41\\View\\ListComponent':
                 case 't41\\View\\TableComponent':
                     $object->setDecorator();
                     $decorator = Decorator::factory($object);
                     $content .= $decorator->render();
                     break;
                 default:
                     break;
             }
         }
     }
     return $content;
 }
Example #3
0
 protected function _renderField($name, $value = null, $prefix = null, $boundaries = true)
 {
     $id = str_replace(array('[', ']'), array('_', ''), $name);
     $dispField = 'disp_' . $id;
     $pickerArgs = array('dateFormat' => 'dd/mm/yy', 'firstDay' => 1, 'changeYear' => true, 'changeMonth' => true, 'altField' => '#' . $id, 'altFormat' => 'yy-mm-dd', 'monthNames' => array('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'), 'monthNamesShort' => array('Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Aoû', 'Sept', 'Oct', 'Nov', 'Déc'), 'dayNames' => array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'), 'dayNamesMin' => array('Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'));
     if ($boundaries) {
         if (is_numeric($this->_obj->getConstraint(Property::CONSTRAINT_DATEMIN))) {
             $pickerArgs['minDate'] = $this->_obj->getConstraint(Property::CONSTRAINT_DATEMIN);
         }
         if (is_numeric($this->_obj->getConstraint(Property::CONSTRAINT_DATEMAX))) {
             $pickerArgs['maxDate'] = (string) $this->_obj->getConstraint(Property::CONSTRAINT_DATEMAX);
         }
     }
     View::addEvent(sprintf('jQuery(function() { jQuery("#%s").datepicker(%s); });', $dispField, \Zend_Json::encode($pickerArgs)), 'js');
     $html = sprintf('%s<input type="hidden" name="%s" id="%s" value="%s"/>', $prefix ? htmlspecialchars($prefix) . '&nbsp;' : null, $name, $id, $value);
     $dispValue = $value ? $this->_obj->formatValue($value, (bool) $this->getParameter(Property::CONSTRAINT_PROTECTED)) : null;
     $html .= sprintf('<input type="text" id="%s" value="%s" size="10" maxlength="10" readonly="readonly" style="color:grey;"/>', $dispField, $dispValue);
     if ($this->_obj->getParameter('enable_quickset') && $this->getParameter('mode') != View\FormComponent::SEARCH_MODE) {
         $buttons = array(array('title' => 'Hier', 'value' => '-1', 'icon' => 'left-arrow'), array('title' => 'Aujourd\'hui', 'value' => '+0d', 'icon' => 'valid'), array('title' => 'Demain', 'value' => '+1', 'icon' => 'right-arrow'));
         foreach ($buttons as $k => $v) {
             $html .= sprintf('<a class="element small icon" title="%s" href="javascript:" onclick="jQuery(\'#%s\').datepicker(\'setDate\', \'%s\'); return false;"><span class="%s"></span></a>', $v['title'], $dispField, $v['value'], $v['icon']);
         }
     }
     return $html;
 }
Example #4
0
 /**
  * Factory pattern used to instanciate a proper decorator for the given object extended from t41\View\ViewObject
  *
  * @param t41\View\ViewObject $object disabled for now because of legacy problems
  * @param array $params
  * @return t41\View\AbstractDecorator
  */
 public static function factory($object, array $params = null)
 {
     $decoratorData = $object->getDecorator();
     if (is_null($params) && isset($decoratorData['params'])) {
         $params = $decoratorData['params'];
     } elseif (!is_null($params) && isset($decoratorData['params'])) {
         $params = array_merge($params, $decoratorData['params']);
     }
     // class name without the first component of the namespace
     $class = substr(get_class($object), strpos(get_class($object), '\\') + 1);
     if (View::getViewType() != Adapter\WebAdapter::ID) {
         $decoratorData['name'] = 'Default';
     }
     if (!isset($decoratorData['name']) || trim($decoratorData['name']) == '') {
         $decoratorData['name'] = 'Default';
     }
     // decorator name
     $deconame = View::getContext() . ucfirst($decoratorData['name']);
     foreach (self::$_paths as $library) {
         $file = $library['path'] . str_replace('\\', '/', $class) . '/' . $deconame . '.php';
         if (file_exists($file)) {
             require_once $file;
             $fullclassname = '\\' . $library['ns'] . '\\' . $class . '\\' . $deconame;
             if (class_exists($fullclassname)) {
                 try {
                     $decorator = new $fullclassname($object, $params);
                 } catch (Exception $e) {
                     throw new Exception("Error instanciating '{$fullclassname}' decorator.", $e->getCode(), $e);
                 }
                 return $decorator;
             }
         }
     }
     throw new Exception("The decorator class '{$class}' doesn't exist or was not found");
 }
Example #5
0
 public function render()
 {
     /* bind optional action to field */
     if ($this->_obj->getAction()) {
         $this->_bindAction($this->_obj->getAction());
         View::addEvent(sprintf("jQuery('#%s').focus()", $this->_id), 'js');
     }
     $name = $this->getId();
     if ($this->getParameter('mode') == View\FormComponent::SEARCH_MODE) {
         $name = ViewUri::getUriAdapter()->getIdentifier('search') . '[' . $this->_nametoDomId($name) . ']';
     }
     $extraArgs = '';
     if ($this->getParameter('args')) {
         foreach ($this->getParameter('args') as $argKey => $argVal) {
             $extraArgs .= sprintf(' %s="%s"', $argKey, $argVal);
         }
     }
     $size = $this->getParameter('length');
     $max = $this->_obj->getConstraint(Property::CONSTRAINT_MAXLENGTH);
     if ($this->_obj->getValue()) {
         $html = sprintf('<input type="text" name="%s" id="%s" placeholder="%s" size="%s"%s value="********"%s/>', $name, $this->_obj->getId(), $this->_obj->getHelp(), $max > $size || $max == 0 ? $size : $max, $max ? ' maxlength="' . $max . '"' : null, $extraArgs);
         $html .= sprintf(' <a href="#" onclick="jQuery(\'#%s\').val(\'%s\').focus();this.remove()">Regénérer</a>', $this->_obj->getId(), self::password());
     } else {
         $html = sprintf('<input type="text" name="%s" id="%s" placeholder="%s" size="%s"%s value="%s"%s/>', $name, $this->_obj->getId(), $this->_obj->getHelp(), $max > $size || $max == 0 ? $size : $max, $max ? ' maxlength="' . $max . '"' : null, $this->_obj->getValue(), $extraArgs);
     }
     $this->addConstraintObserver(array(Property::CONSTRAINT_UPPERCASE, Property::CONSTRAINT_LOWERCASE));
     return $html;
 }
Example #6
0
 /**
  * Load the template file $filename
  * 
  * If path is relative (not starting with a "/"), the base path is prefixed
  * 
  * @param string $filename
  * @param string $module
  * @return t41\View\TemplateComponent $this instance
  */
 public function load($filename, $module = null)
 {
     $file = View::getAdapter()->loadTemplate($filename, $module);
     if (($this->_template = file_get_contents($file)) === false) {
         throw new Exception(array("ERROR_LOADING_FILE", $filename));
     }
     return $this;
 }
Example #7
0
 public function render()
 {
     View::addCoreLib(array('view:action:upload.js'));
     $id = $this->_nametoDomId($this->_obj->getId());
     $event = sprintf("t41.view.registry['%s'] = new t41.view.action.uploader(%s,'%s')", $this->_obj->getId(), \Zend_Json::encode($this->_obj->reduce(array('params' => array()))), $this->_obj->getObject()->getId());
     View::addEvent($event, 'js');
     View::addEvent(sprintf("t41.view.registry['%s'].init()", $id), 'js');
 }
Example #8
0
 public function render()
 {
     View::addCoreLib(array('view:table2.js', 'view:action:autocomplete.js'));
     $id = $this->_nametoDomId($this->_obj->getBoundObject()->getId());
     $event = sprintf("t41.view.register('%s', new t41.view.action.autocomplete(%s,'%s'))", $id, \Zend_Json::encode($this->_obj->reduce(array('params' => array(), 'collections' => 1))), $id);
     View::addEvent($event, 'js');
     View::addEvent(sprintf("t41.view.get('%s').init()", $id), 'js');
 }
Example #9
0
 public function render()
 {
     View::addCoreLib('style.css');
     $html = '';
     foreach ($this->_obj->getMenu()->getItems() as $moduleKey => $module) {
         $menu = '';
         foreach ($module->getItems() as $item) {
             $menu .= $this->_renderMenu($item, $moduleKey);
         }
         if ($menu) {
             // top level menu
             $html .= sprintf('<ul><li class="head" data-help="%s"><a class="head">%s</a><div class="drop">%s</div></li></ul>', $this->_escape($module->getHelp()), $this->_escape($module->getLabel()), $menu);
         }
     }
     return '<div class="t41 component menu">' . "\n" . $html . "</div>\n";
 }
Example #10
0
 protected function _contentRendering()
 {
     $p = '<fieldset id="form_fields">';
     $p .= '<legend></legend>';
     $altDecorators = (array) $this->_obj->getParameter('decorators');
     /* @var $val t41_View_Element_Abstract */
     foreach ($this->_obj->getColumns() as $key => $element) {
         $field = $element;
         /* hidden fields treatment */
         if ($element->getConstraint(Element\AbstractElement::CONSTRAINT_HIDDEN) === true) {
             $p .= sprintf('<input type="hidden" name="%s" id="%s" value="%s" />', $field->getAltId(), $field->getAltId(), $field->getValue());
             continue;
         }
         if (!isset($focus) && $element instanceof Element\FieldElement) {
             View::addEvent(sprintf("jQuery('#%s').focus()", $element->getAltId()), 'js');
             $focus = $element;
         }
         $label = '&nbsp;';
         $label = $this->_escape($element->getTitle());
         if ($element->getConstraint(Property::CONSTRAINT_MANDATORY) == true) {
             $class = ' mandatory';
             $mandatory = ' mandatory';
         } else {
             $class = '';
             $mandatory = '';
         }
         $line = sprintf('<div class="clear"></div><div id="label_%s" class="label%s"><label for="%s" data-help="%s">%s</label></div>', $field->getAltId(), $class, $field->getAltId(), $field->getHelp(), $label);
         // value is already defined and can't be changed
         if ($field->getConstraint(Property::CONSTRAINT_PROTECTED) == true && $field->getValue()) {
             if (!is_object($field->getValue()) || $field->getValue() instanceof BaseObject && $field->getValue()->getUri()) {
                 $p .= $line . '<div class="field">' . $field->formatValue($field->getValue()) . '</div>';
                 continue;
             }
         }
         /* look for a required decorator */
         if (isset($altDecorators[$element->getId()])) {
             $element->setDecorator($altDecorators[$element->getId()]);
         }
         $deco = View\Decorator::factory($element);
         $line .= sprintf('<div class="field" id="elem_%s">%s</div>', $element->getId(), $deco->render());
         $p .= $line . "\n";
     }
     $p .= '</fieldset>';
     return $p;
 }
Example #11
0
 public function render()
 {
     if (($value = $this->_obj->getValue()) !== false) {
         if (($value instanceof ObjectModel\BaseObject || $value instanceof ObjectModel\DataObject) && $value->getUri()) {
             $value = $this->_obj->getParameter('altkey') ? $value->getProperty($this->_obj->getParameter('altkey'))->getValue() : $value->getUri()->getIdentifier();
         } else {
             if ($value instanceof ObjectModel\ObjectUri) {
                 $value = $value->getIdentifier();
             } else {
                 $value = null;
             }
         }
     }
     $name = $this->_obj->getId();
     // set correct name for field name value depending on 'mode' parameter value
     if ($this->getParameter('mode') == View\FormComponent::SEARCH_MODE) {
         $name = ViewUri::getUriAdapter()->getIdentifier('search') . '[' . $name . ']';
     }
     View::addCoreLib(array('core.js', 'locale.js', 'view.js', 'view:table.js', 'view:action:autocomplete.js'));
     $acfield = new View\FormComponent\Element\FieldElement('_' . $this->_nametoDomId($name));
     $acfield->setValue($value);
     $action = new AutocompleteAction($this->_obj->getCollection());
     $objsearchprops = $this->_obj->getParameter('search') ? $this->_obj->getParameter('search') : $this->_obj->getParameter('display');
     $action->setParameter('searchprops', explode(',', $this->getParameter('searchprops') ? $this->getParameter('searchprops') : $objsearchprops));
     $action->setParameter('searchmode', $this->getParameter('searchmode'));
     $action->setParameter('display', explode(',', $this->_obj->getParameter('display')));
     $action->setParameter('sdisplay', explode(',', $this->_obj->getParameter('sdisplay') ? $this->_obj->getParameter('sdisplay') : $this->_obj->getParameter('display')));
     $action->setParameter('event', 'keyup');
     // if a list of properties to be returned exists, pass it to the action
     if ($this->getParameter('retprops')) {
         $action->setParameter('member_reduce_params', array('props' => explode(',', $this->getParameter('retprops'))));
     }
     $action->setContextData('onclick', 't41.view.element.autocomplete.close');
     $action->setContextData('target', $this->_nametoDomId($name));
     $action->bind($acfield);
     $deco = View\Decorator::factory($acfield);
     $html = $deco->render();
     $deco = View\Decorator::factory($action);
     $deco->render();
     $html .= sprintf('<input type="hidden" name="%s" id="%s" value="%s"/>', $name, $this->_nametoDomId($name), $value);
     return $html . "\n";
 }
Example #12
0
 public function render()
 {
     /* bind optional action to field */
     if ($this->_obj->getAction()) {
         $this->_bindAction($this->_obj->getAction());
         View::addEvent(sprintf("jQuery('#%s').focus()", $this->_id), 'js');
     }
     $name = $this->getId();
     if ($this->getParameter('mode') == View\FormComponent::SEARCH_MODE) {
         $name = ViewUri::getUriAdapter()->getIdentifier('search') . '[' . $this->_nametoDomId($name) . ']';
     }
     $html = sprintf('<input type="hidden" name="%s" id="%s" value="%s"/>', $name, $this->_obj->getId(), $this->_obj->getValue());
     $zv = new \Zend_View();
     $options = array(null => $this->getParameter('defaultlabel')) + $this->_obj->getEnumValues(TimeProperty::HOUR_PART);
     $html .= $zv->formSelect($name . '_hour', $this->_obj->getValue(TimeProperty::HOUR_PART), null, $options);
     $options = array(null => $this->getParameter('defaultlabel')) + $this->_obj->getEnumValues(TimeProperty::MIN_PART);
     $html .= ' : ' . $zv->formSelect($name . '_minute', $this->_obj->getValue(TimeProperty::MIN_PART), null, $options);
     View::addCoreLib('view:form.js');
     View::addEvent(sprintf("new t41.view.form.timeElement('%s')", $this->_obj->getId()), 'js');
     return $html;
 }
Example #13
0
 public function render()
 {
     /* bind optional action to field */
     if ($this->_obj->getAction()) {
         $this->_bindAction($this->_obj->getAction());
         View::addEvent(sprintf("jQuery('#%s').focus()", $this->_id), 'js');
     }
     $name = $this->getId();
     $value = explode('.', $this->_obj->getValue());
     if ($this->getParameter('mode') == View\FormComponent::SEARCH_MODE) {
         $name = ViewUri::getUriAdapter()->getIdentifier('search') . '[' . $this->_nametoDomId($name) . ']';
     }
     $html = sprintf('<input type="hidden" name="%s" id="%s" value="%s"/>', $name, $this->_obj->getId(), $this->_obj->getValue());
     $html .= sprintf('<input type="text" id="%s_number" size="3" maxlength="4"/>', $this->_obj->getId());
     $options = array('2' => 'Bis', '3' => 'Ter', '4' => 'Quater', 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D');
     $options = array(null => $this->getParameter('defaultlabel')) + $options;
     $zv = new \Zend_View();
     $html .= $zv->formSelect(null, null, array('id' => $this->_obj->getId() . '_ext'), $options);
     View::addCoreLib('view:form.js');
     View::addEvent(sprintf("new t41.view.form.streetNumber('%s')", $this->_obj->getId()), 'js');
     return $html;
 }
Example #14
0
 public function init()
 {
     // Just in cas something goes wrong before the end
     // @todo replace with a setTemplate() in t41\Exception
     View::setTemplate('default.html');
     // get page identifiers (module, controller and action)
     Layout::$module = $this->_getParam('module');
     Layout::$controller = $this->_getParam('controller');
     Layout::$action = $this->_getParam('action');
     // provide controller with basic information about the current module
     foreach (Module::getConfig() as $vendor => $modules) {
         foreach ($modules as $key => $module) {
             if (isset($module['controller']) && Layout::$module == $module['controller']['base']) {
                 $this->_module = 'app/' . $vendor . '/' . $key;
                 Layout::$vendor = $vendor;
                 Layout::$moduleKey = $key;
                 $resource = Layout::$controller;
                 if (Layout::$action) {
                     $resource .= '/' . Layout::$action;
                 }
                 if (isset($module['controller']['items'])) {
                     foreach ($module['controller']['items'] as $controller) {
                         if ($this->_getCurrentItem($resource, $controller) == true) {
                             break;
                         }
                     }
                 }
                 if (isset($module['controllers_extends'])) {
                     foreach ($module['controllers_extends'] as $controller) {
                         if ($this->_getCurrentItem($resource, $controller['items']) == true) {
                             break;
                         }
                     }
                 }
                 break;
             }
         }
     }
 }
Example #15
0
 public function render()
 {
     // set correct name for field name value depending on 'mode' parameter value
     $name = $this->_obj->getId();
     $prefix = Core::getController('medias');
     if (!$prefix) {
         $prefix = '/t41/medias/';
     }
     $uri = $prefix . 'upload';
     View::addCoreLib(array('core.js', 'locale.js', 'view.js', 'uploader.css', 'view:action:upload.js'));
     View::addEvent(sprintf("t41.view.register('%s_ul', new t41.view.action.upload(jQuery('#%s_ul'),'%s'))", $name, $name, $uri), 'js');
     $html = '';
     // @todo code media deletion JS
     if ($this->_obj->getValue() != null) {
         $html .= sprintf('<span><a href="%s" target="_blank">%s %s</a> | <a href="#" onclick="t41.view.get(\'%s_ul\').reset(this)">%s</a></span>', MediaElement::getDownloadUrl($this->_obj->getValue()->getUri()), 'Télécharger', $this->_obj->getValue()->getLabel(), $name, 'Supprimer');
     }
     $html .= sprintf('<div id="%s_ul" class="qq-upload-list"></div>', $this->_nametoDomId($name));
     $html .= sprintf('<input type="hidden" name="%s" id="%s" value="%s" class="hiddenfilename"/>', $name, $this->_nametoDomId($name), $this->_obj->getValue() ? $this->_obj->getValue()->getIdentifier() : null);
     return $html;
     $action = new UploadAction($this->_obj);
     $deco = View\Decorator::factory($action);
     $deco->render();
     return $html . "\n";
 }
Example #16
0
 protected function _headlineRendering()
 {
     $sort = null;
     // build header line
     $line = '<tr>';
     $sortIdentifiers = isset($this->_env[$this->_sortIdentifier]) && is_array($this->_env[$this->_sortIdentifier]) ? $this->_env[$this->_sortIdentifier] : array();
     if ($this->_obj->getParameter('selectable') !== false) {
         $cbid = 'toggler_' . $this->_id;
         $line .= sprintf('<td><input type="checkbox" id="%s"/></td>', $cbid);
         View::addEvent(sprintf('t41.view.bindLocal(jQuery("#%s"), "change", function() { t=jQuery("#%s").attr("checked");jQuery("#%s").find(\':checkbox[id=""]\').each(function(i,o){o.checked=t});})', $cbid, $cbid, $this->_id), 'js');
     }
     foreach ($this->_obj->getColumns() as $val) {
         $line .= sprintf('<th class="tb-%s"><strong>', $val->getId());
         if ($val->getParameter('sortable') == false) {
             $line .= $this->_escape($val->getTitle()) . '</strong></th>';
             continue;
         }
         if (is_object($val) && array_key_exists($val->getId(), $sortIdentifiers)) {
             $by = $sortIdentifiers[$val->getId()] == 'ASC' ? 'DESC' : 'ASC';
             // save correct sorting field reference to re-inject in uri after column construction
             // @todo think twice ! this is crappy as hell!
             $sort = array($val->getId(), $sortIdentifiers[$val->getId()]);
         } else {
             $by = 'ASC';
         }
         if (is_object($val)) {
             $this->_uriAdapter->setArgument($val->getId(), $by, $this->_sortIdentifier);
         }
         $line .= sprintf('<a href="%s">%s</a></strong></th>', $this->_uriAdapter->makeUri(), $this->_escape($val->getTitle()));
         $this->_uriAdapter->unsetArgument(null, $this->_sortIdentifier);
     }
     if (is_array($sort)) {
         $this->_uriAdapter->setArgument($sort[0], $sort[1], $this->_sortIdentifier);
     }
     if (count($this->_obj->getEvents('row')) > 0) {
         $line .= '<th class="tb-actions">&nbsp;</th>';
     } else {
         $line .= '<th class="tb-actions">&nbsp;</th>';
     }
     return $line . "</tr>\n";
 }
Example #17
0
 public function _contentRendering()
 {
     $p = '<fieldset>';
     foreach ($this->_obj->getColumns() as $key => $element) {
         $field = $element;
         $p .= '<span class="field">';
         $p .= sprintf('<span class="label"><label for="%s[%s]">%s</label></span>', $this->_searchIdentifier, $field->getId(), $field->getTitle() ? $field->getTitle() : 'ID');
         // get current field value from env
         if (isset($this->_env[$this->_searchIdentifier][$field->getId()])) {
             $field->setValue($this->_env[$this->_searchIdentifier][$field->getId()]);
         }
         // Reset default value to empty
         $field->setDefaultValue('');
         $data = isset($this->_env[$this->_searchIdentifier]) ? $this->_env[$this->_searchIdentifier] : null;
         $deco = Decorator::factory($field, array('mode' => FormComponent::SEARCH_MODE, 'data' => $data));
         $p .= '&nbsp;' . $deco->render();
         $p .= '</span>';
     }
     if ($this->_obj->getParameter('buttons') != false) {
         View::addCoreLib(array('buttons.css', 'sprites.css'));
         $p .= sprintf('<div class="clear"><a class="element button medium icon" onclick="jQuery(\'#t41sf\').submit()"><span class="search-blue"></span>Rechercher</a>' . '<a class="element button medium icon" onclick="jQuery(\'#t41sf\').find(\':input\').each(function() {jQuery(this).val(null)})"><span class="refresh"></span>RAZ</a></div>', $this->_obj->getParameter('baseurl'));
     }
     $p .= '</fieldset></form>';
     return $p;
 }
Example #18
0
 /**
  * 
  * Register the object in the view with the given placeholder and optional decorator parameters
  * 
  * @param string $placeHolder
  * @param array $params
  * @param boolean $clone
  * @return boolean
  */
 public function register($placeHolder = View::PH_DEFAULT, array $params = null, $clone = false)
 {
     $obj = $clone ? clone $this : $this;
     return View::addObject($obj, $placeHolder, $params);
 }
Example #19
0
 public function render()
 {
     // add CSS libraries
     View::addCoreLib(array('sprites.css', 'buttons.css'));
     $extraHtml = array();
     $class = explode(' ', $this->getParameter('css'));
     if ($this->getParameter('nolabel') != true) {
         $class[] = 'button';
     }
     if ($this->getParameter('size')) {
         $class[] = $this->getParameter('size');
     }
     if ($this->getParameter('color')) {
         $class[] = $this->getParameter('color');
     }
     /* bind optional action to button */
     if ($this->_obj->getAction()) {
         $this->_bindAction($this->_obj->getAction());
     } else {
         if ($this->_obj->getLink()) {
             $link = $this->_obj->getLink();
             $uri = $this->_obj->getParameter('uri');
             if ($uri instanceof ObjectUri && substr($link, 0, 1) == '/') {
                 $link .= '/id/' . rawurlencode($uri->getIdentifier());
             }
             if (substr($link, 0, 4) == 't41.') {
                 $extraHtml[] = sprintf("onclick=\"%s\"", $link);
             } else {
                 $extraHtml[] = sprintf("onclick=\"t41.view.link('%s', jQuery('#%s'))\"", $link, $this->getId());
             }
         } else {
             $data = $this->getParameter('data');
             $adapter = ViewUri::getUriAdapter();
             $args = array();
             foreach ((array) $this->_obj->getParameter('identifiers') as $key => $identifier) {
                 $identifierKey = is_numeric($key) ? $identifier : $key;
                 $args[$identifierKey] = $data[$identifier];
             }
             $onclick = "document.location='" . "/";
             //$this->_obj->getUri();
             $onclick .= count($args) > 0 ? $adapter->makeUri($args, true) . "'" : "'";
         }
     }
     if ($this->_obj->getParameter('disabled')) {
         $class[] = 'disabled';
     }
     if ($this->getParameter('pairs')) {
         foreach ($this->getParameter('pairs') as $key => $val) {
             $extraHtml[] = sprintf('%s="%s"', $key, $val);
         }
     }
     if ($this->getParameter('icon')) {
         $class[] = 'icon';
     }
     $value = $this->getParameter('nolabel') ? '' : $this->_escape($this->_obj->getTitle());
     foreach ((array) $this->getParameter('data') as $key => $val) {
         $extraHtml[] = sprintf('data-%s="%s"', $key, $val);
     }
     $html = sprintf('<a class="%s" id="%s" data-help="%s" %s><span class="%s"></span>%s</a>', implode(' ', $class), $this->_id, '', implode(' ', $extraHtml), $this->getParameter('icon') ? $this->getParameter('icon') : null, $value);
     return $html;
 }
Example #20
0
 /**
  * Add a Javascript observer and a callback function to the element if the given constraint is setted
  * @param string $constraints
  */
 protected function addConstraintObserver($constraints)
 {
     $constraints = (array) $constraints;
     foreach ($constraints as $constraint) {
         if (!$this->_obj->getConstraint($constraint)) {
             continue;
         }
         switch ($constraint) {
             case Property::CONSTRAINT_UPPERCASE:
                 View::addEvent(sprintf("t41.view.bindLocal('%s','blur', function() { var f = jQuery('#%s'); f.val(f.val().toUpperCase())})", $this->getId(), $this->getId()), 'js');
                 break;
             case Property::CONSTRAINT_LOWERCASE:
                 View::addEvent(sprintf("t41.view.bindLocal('%s','blur', function() { var f = jQuery('#%s'); f.val(f.val().toLowerCase())})", $this->getId(), $this->getId()), 'js');
                 break;
             case Property::CONSTRAINT_URLSCHEME:
                 break;
             case Property::CONSTRAINT_EMAILADDRESS:
                 break;
         }
     }
 }
Example #21
0
 /**
  * Returns current color from decorator parameter or
  * the one defined by the view, and requires that file
  * to be called in the rendered view
  * 
  * @param string $view
  * @return string
  */
 protected function _getColor($view = 'all')
 {
     if ($this->_obj->getParameter('color')) {
         View::addRequiredLib($this->_obj->getParameter('color'), 'css', 't41');
         return $this->_obj->getParameter('color');
     } else {
         return View::getColor($view);
     }
 }
Example #22
0
 public function init()
 {
     parent::init();
     View::addRequiredLib('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', 'js');
     View::addCoreLib('core.js');
 }
Example #23
0
 public function render()
 {
     View::addCoreLib(array('style.css'));
     return $this->_headerRendering() . $this->_contentRendering() . $this->_footerRendering();
 }
Example #24
0
 /**
  * Parse given tags against current template
  * 
  * @param array $tags
  */
 protected function _parseTags($tags)
 {
     foreach ($tags as $tag) {
         $value = null;
         switch ($tag[1]) {
             case 'var':
                 $keys = explode('.', $tag[2]);
                 $value = $this->_obj->getVariable($keys[0]);
                 if (count($keys) > 1) {
                     $value = $value[$keys[1]];
                 }
                 break;
             case 'env':
                 $value = View::getEnvData($tag[2]);
                 break;
             case 'container':
                 if (($templates = $this->_obj->getSubtemplates($tag[2])) !== false) {
                     $value = '';
                     foreach ($templates as $template) {
                         $deco = Decorator::factory($template);
                         $value .= $deco->render();
                     }
                 }
                 break;
             default:
                 // obj:
                 $tmp = explode('.', $tag[2]);
                 $obj = $this->_obj->getVariable($tmp[0]);
                 if ($obj instanceof MediaObject && isset($tmp[1])) {
                     // meta properties handling
                     switch ($tmp[1]) {
                         case '_base64':
                             $value = sprintf('data:%s;base64,%s', $obj->getMime(), base64_encode($obj->loadBlob('media')));
                             break;
                         case '_icon':
                             $value = 'file-' . $obj->getExtension();
                             break;
                         case '_size':
                             $value = MediaElement::getDisplaySize($obj->getSize());
                             break;
                         case '_url':
                             $value = MediaElement::getDownloadUrl($obj->getUri());
                         default:
                             break;
                     }
                 }
                 if (!$value) {
                     if ($obj instanceof BaseObject) {
                         $value = isset($tmp[1]) && $tmp[1] == ObjectUri::IDENTIFIER ? $obj->getIdentifier() : $obj->getProperty($tmp[1]);
                         $value = $value instanceof AbstractProperty ? $value->getDisplayValue() : $value;
                     } else {
                         $value = Core::$env == Core::ENV_DEV ? sprintf("Can't substitute any value to '%s'", $tag[0]) : null;
                     }
                 }
                 break;
         }
         if ($value instanceof ViewObject) {
             $deco = Decorator::factory($value);
             $value = $deco->render();
         } else {
             //$value = $this->_escape($value);
         }
         $this->_template = str_replace($tag[0], $value, $this->_template);
     }
 }
Example #25
0
 /**
  * environment builder
  *
  * @var string $env forced env value
  */
 public static function init($envKey = null)
 {
     if (!is_null($envKey) && !in_array($envKey, array(self::ENV_DEV, self::ENV_STAGE, self::ENV_PROD))) {
         throw new \Exception(sprintf("'%s' is not a recognized environment", $envKey));
     }
     // enable garbage collection
     gc_enable();
     // enable t41 error handler (notices are not catched until we get a proper logger)
     set_error_handler(array('t41\\Core', 'userErrorHandler'), (E_ALL | E_STRICT) ^ E_NOTICE);
     self::preInit();
     // never cached, shall it be ?
     $config = Config\Loader::loadConfig('application.xml');
     self::$_config = $config['application'];
     if (!is_null($envKey)) {
         self::$env = $envKey;
         self::$appId = $envKey;
     } else {
         /* CLI Mode */
         if (php_sapi_name() == 'cli') {
             self::$mode = self::$_config['environments']['mode'] = 'cli';
             $opts = new \Zend_Console_Getopt(array('env=s' => 'Environment value', 'controller=s' => "Controller", 'module=s' => "Module", 'action=s' => "Action", 'params=s' => "Action parameters", 'simulate' => "Simulate execution"));
             try {
                 $opts->parse();
             } catch (\Zend_Console_GetOpt_Exception $e) {
                 exit($e->getUsageMessage());
             }
             $match = trim($opts->env);
             /* temporary */
             define('CLI_CONTROLLER', trim($opts->controller));
             define('CLI_MODULE', trim($opts->module));
             define('CLI_ACTION', trim($opts->action));
             define('CLI_PARAMS', $opts->params);
             define('CLI_SIMULATE', (bool) $opts->simulate);
         } else {
             View::setDisplay(View\Adapter\WebAdapter::ID);
             /* array of mode / $_SERVER data key value */
             $envMapper = array('hostname' => 'SERVER_NAME');
             $match = isset($_SERVER[$envMapper[self::$_config['environments']['mode']]]) ? $_SERVER[$envMapper[self::$_config['environments']['mode']]] : null;
         }
         /* define which environment matches current mode value */
         if (is_null($match)) {
             throw new Config\Exception("environment value not detected");
         }
         self::$appId = str_replace(array('.', '-'), '_', $match);
         $envKey = null;
         switch (self::$_config['environments']['mode']) {
             case 'cli':
                 foreach (self::$_config['environments'] as $key => $value) {
                     if (!is_array($value)) {
                         continue;
                     }
                     if ($key == $match) {
                         $envKey = self::$env = $key;
                         break;
                     }
                 }
                 break;
             case 'hostname':
             default:
                 foreach (self::$_config['environments'] as $key => $value) {
                     if (!is_array($value)) {
                         continue;
                     }
                     if (isset($value['hostname']) && in_array($match, (array) $value['hostname'])) {
                         $envKey = self::$env = $key;
                         break;
                     }
                 }
                 break;
         }
         if (is_null($envKey)) {
             throw new Config\Exception("No matching environment found");
         }
     }
     self::$_env += self::$_config['environments'][$envKey];
     if (self::getEnvData('cache_backend')) {
         self::$cache = self::getEnvData('cache_backend');
     }
     self::$_env['version'] = self::$_config['versions'][self::$_config['versions']['default']];
     /* define app name */
     self::$name = isset(self::$_config['name']) ? self::$_config['name'] : 'Untitled t41-based application';
     /* set PHP env */
     setlocale(E_ALL, self::$_env['version']['locale']);
     setlocale(LC_MONETARY, self::$_env['version']['currency']);
     date_default_timezone_set(isset(self::$_env['version']['timezone']) ? self::$_env['version']['timezone'] : 'Europe/Paris');
     if (isset(self::$_env['php'])) {
         foreach (self::$_env['php'] as $directive => $value) {
             ini_set($directive, $value);
         }
     }
     // define logger
     if (isset(self::$_env['log']) && self::$_env['log'] != false) {
         self::enableLogger(self::$_env['log']);
     }
     /* define lang - can be overwritten anywhere */
     self::$lang = self::$_config['versions']['default'];
     // load modules
     Core\Module::init(self::$basePath);
     // load ACL
     Core\Acl::init(self::$basePath);
     /* load configuration files if lazy mode is off */
     if (self::$lazy !== true) {
         // get backends configuration
         Backend::loadConfig();
         // get mappers configuration
         Mapper::loadConfig();
         // get object model configuration
         ObjectModel::loadConfig();
     }
     // configure error reporting according to env
     if (in_array(self::$env, array(self::ENV_STAGE, self::ENV_PROD))) {
         error_reporting(E_ERROR);
         //(E_ALL | E_STRICT) ^ E_NOTICE);
         ini_set('display_errors', 1);
     } else {
         error_reporting(E_ERROR);
         // E_ALL & ~E_STRICT);
         ini_set('display_errors', 1);
     }
     // define some basic view data
     View::setEnvData('t41.version', self::VERSION);
     if (class_exists('Zend_Version')) {
         View::setEnvData('zf.version', \Zend_Version::VERSION);
     }
     View::setEnvData('app.name', self::$_config['name']);
     View::setEnvData('app.version', self::getVersion());
     // set a cache adapter
     if (!isset(self::$_adapters['registry'])) {
         self::$_adapters['registry'] = new \Zend_Registry();
     }
     // (re-)init data session
     if (!isset(self::$_adapters['session'])) {
         self::$_adapters['session'] = new \Zend_Session_Namespace('data');
     }
     // to be done at the very end to avoid empty stack on exception
     if (self::$_fancyExceptions === true) {
         //set_exception_handler(array('t41\Core', 'exceptionHandler'));
     }
 }
Example #26
0
 protected function _render()
 {
     $template = file_get_contents($this->_template);
     $tagPattern = "/%([a-z0-9]+)\\:([a-z0-9.]*)\\{*([a-zA-Z0-9:,\\\"']*)\\}*%/";
     $tagPattern = "/%([a-z0-9]+)\\:([a-z0-9_.]*)\\{*([a-zA-Z0-9:_,\\\"']*)\\}*%/";
     $tags = array();
     preg_match_all($tagPattern, $template, $tags, PREG_SET_ORDER);
     // PHASE 1: analyse et parsing of content-generating tags
     foreach ($tags as $tag) {
         $content = false;
         switch ($tag[1]) {
             case 'helper':
                 $tmp = explode('.', $tag[2]);
                 $class = sprintf('%s\\View\\Web\\%s', $tmp[0], ucfirst($tmp[1]));
                 try {
                     $helper = new $class();
                     $content = $helper->render();
                 } catch (Exception $e) {
                     if (Core::$env == Core::ENV_DEV) {
                         $content = $e->getMessage();
                     }
                 }
                 break;
             case 'container':
                 $elems = View::getObjects($tag[2]);
                 if (is_array($elems)) {
                     foreach ($elems as $elem) {
                         $object = $elem[0];
                         $params = $elem[1];
                         if (!is_object($object)) {
                             continue;
                         }
                         // look for a custom decorator
                         $decorator = View\Decorator::factory($object, $params);
                         $content .= $decorator->render();
                     }
                 }
                 break;
         }
         if ($content !== false) {
             $template = str_replace($tag[0], $content, $template);
         }
     }
     preg_match_all($tagPattern, $template, $tags, PREG_SET_ORDER);
     // PHASE 2: analyze & parsing of other tags (components linking & env variables)
     foreach ($tags as $tag) {
         $content = null;
         switch ($tag[1]) {
             case 'components':
                 $content = $this->_renderComponents($tag[2], $tag[3]);
                 break;
             case 'env':
             case 'var':
                 $content = View::getEnvData($tag[2]);
                 break;
             case 'obj':
                 // obj:
                 $tmp = explode('.', $tag[2]);
                 $obj = View::getEnvData($tmp[0]);
                 if ($obj instanceof MediaObject && isset($tmp[1])) {
                     // meta properties handling
                     switch ($tmp[1]) {
                         case '_base64':
                             $content = sprintf('data:%s;base64,%s', $obj->getMime(), base64_encode($obj->loadBlob('media')));
                             break;
                         case '_icon':
                             $content = 'file-' . $obj->getExtension();
                             break;
                         case '_size':
                             $content = MediaElement::getDisplaySize($obj->getSize());
                             break;
                         case '_url':
                             $content = MediaElement::getDownloadUrl($obj->getUri());
                             break;
                         default:
                             break;
                     }
                 }
                 if (!$content) {
                     if ($obj instanceof BaseObject) {
                         $content = isset($tmp[1]) && $tmp[1] == ObjectUri::IDENTIFIER ? $obj->getIdentifier() : $obj->getProperty($tmp[1]);
                         $content = $content instanceof AbstractProperty ? $content->getDisplayValue() : $content;
                     } else {
                         $content = Core::$env == Core::ENV_DEV ? sprintf("Can't substitute any value to '%s'", $tag[0]) : null;
                     }
                 }
                 break;
         }
         $template = str_replace($tag[0], $content, $template);
     }
     // PHASE 3: actions attachment
     $this->actionAttach();
     // PHASE 4: events attachment
     $template = str_replace('</body>', $this->eventAttach() . '</body>', $template);
     // PHASE 5: display logged errors in dev mode
     if (Core::$env == Core::ENV_DEV) {
         $errors = View::getErrors();
         if (count($errors) > 0) {
             $str = "\n";
             foreach ($errors as $errorCode => $errorbloc) {
                 $str .= $errorCode . "\n";
                 foreach ($errorbloc as $error) {
                     $str .= "\t" . $error[0] . "\n";
                 }
             }
             $template = str_replace('</body>', '</body><!--' . $str . ' -->', $template);
         }
     }
     return $template;
 }
Example #27
0
 protected function _()
 {
     $template = file_get_contents($this->_template);
     // transform some characters
     $template = str_replace("\t", str_repeat("&nbsp;", 15), $template);
     $template = str_replace("\n", "<br/>", $template);
     $tagPattern = "/%([a-z0-9]+)\\:([a-z0-9.]*)\\{*([a-zA-Z0-9:,\\\"']*)\\}*%/";
     $tags = array();
     preg_match_all($tagPattern, $template, $tags, PREG_SET_ORDER);
     // PHASE 1
     foreach ($tags as $key => $tag) {
         $content = '';
         if ($tag[1] == 'env') {
             $content = \t41\Core::htmlEncode(\t41\View::getEnvData($tag[2]));
             unset($tag[$key]);
         }
         if (isset($tag[0])) {
             $template = str_replace($tag[0], $content, $template);
         }
     }
     $this->_document->writeHTML($template);
     // PHASE 2 - other tags
     foreach ($tags as $tag) {
         $content = '';
         switch ($tag[1]) {
             case 'container':
                 $elems = \t41\View::getObjects($tag[2]);
                 if (is_array($elems)) {
                     foreach ($elems as $elem) {
                         $object = $elem[0];
                         $params = $elem[1];
                         if (!is_object($object)) {
                             continue;
                         }
                         /* @var $object t41_Form_Abstract */
                         switch (get_class($object)) {
                             case 't41_Form_List':
                             case 't41_View_Table':
                             case 't41_View_Image':
                             case 't41_View_Component':
                             case 't41_View_Error':
                             case 't41_View_Spacer':
                                 $decorator = \t41\View\Decorator::factory($object, $params);
                                 $decorator->render($this->_document, $this->_width);
                                 break;
                             default:
                                 break;
                         }
                     }
                 }
                 break;
         }
     }
 }