示例#1
0
文件: Tab.php 项目: samsonos/cms_form
 /**
  * @param Container $parent Pointer to parent container
  */
 public function __construct(Container &$parent)
 {
     parent::__construct($parent->renderer, $parent);
     // Create header containers
     $this->header = new Container($parent->renderer, $this);
     $this->header->set('view', 'tab/header');
     $this->header->set('identifier', $this->identifier);
     // Create body containers
     $this->body = new Container($parent->renderer, $this);
     $this->body->set('view', 'tab/body');
     $this->body->set('identifier', $this->identifier);
     /**
      * Add nested tab to current tab.
      * This overloaded add method also connects current tab header & body
      * with added tab header & body which gives generic recursion and separate
      * rendering of inner tab headers and body inside current tab header and body
      * and so on.
      */
     if (is_a($parent, 'samsonos\\cms\\ui\\Tab')) {
         // Add nested tab header container to current header
         $parent->header->add($this->header);
         // Add nested tab body container to current body
         $parent->body->add($this->body);
     }
     // Fire event that tab has been created
     Event::fire('cms_ui.tab_created', array(&$this));
 }
示例#2
0
 public function init(array $params = array())
 {
     // Create top parent container
     $this->workspace = new Container($this);
     // Create main UI menu
     $menu = new Menu($this, $this->workspace);
     $menu->set('class', 'main-menu');
     // Create home item
     $homeItem = new MenuItem($menu);
     $homeItem->set('title', 'Home')->set('class', 'btn-home')->set('content', '<a href="/"><i class="sprite sprite-header_home" href="/"></i></a>');
     // Create site item
     $siteItem = new MenuItem($menu);
     $siteItem->set('title', t('Перейти на веб-сайт', true))->set('class', 'btn-site')->set('content', '<a href="/"><i class="sprite sprite-header_site" href="/"></i></a>');
     // Fire event that ui menu left container has been created
     Event::fire('cms_ui.mainmenu_leftcreated', array(&$menu, &$this));
     // Create exit item
     $exitItem = new MenuItem($menu);
     $exitItem->set('title', t('Выйти', true))->set('class', 'btn-icon-right btn-logout')->set('content', '<a href="signin/logout"><i class="sprite sprite-header_logout" href="/"></i></a>');
     // Create settings item
     $settingsItem = new MenuItem($menu);
     $settingsItem->set('title', t('Выйти', true))->set('class', 'btn-icon-right btn-settings')->set('content', '<a href="settings"><i class="sprite sprite-header_settings" href="/"></i></a>');
     // Create i18n menu
     $i18nMenu = new Menu($this, $menu);
     $i18nMenu->set('title', t('Выберите язык', true))->set('class', 'i18n-list');
     // Iterate all supported locales
     foreach (\samson\core\SamsonLocale::get() as $locale) {
         $localeItem = new MenuItem($i18nMenu);
         $url = $locale == DEFAULT_LOCALE ? '' : '/' . $locale;
         $localeItem->set('class', 'i18n_item-' . $locale . ' ' . ($locale == \samson\core\SamsonLocale::current() ? 'i18n-active' : ''))->set('content', '<a href="' . $url . '">' . $locale . '</a>');
     }
     // Fire event that ui menu container has been created
     Event::fire('cms_ui.mainmenu_created', array(&$menu, &$this));
     // Create main UI menu
     $subMenu = new Menu($this, $menu);
     $subMenu->set('class', 'sub-menu');
     // Fire event that ui sub-menu container has been created
     Event::fire('cms_ui.submenu_created', array(&$subMenu, &$this));
     // Create main-content panel
     $mainPanel = new Container($this, $this->workspace);
     $mainPanel->set('class', 'mainPanel ' . (sizeof($subMenu->children()) ? 'with-sub-menu' : ''));
     /*// Create form with tabs
             $form = new Form($this, $mainPanel);
     
             // Create form tab view
             $tabs = new TabView($form);
     
             // Add tab
             $tab = new Tab($tabs);
             $tab->header->set('content', '<span>Описание</span>');
     
             // Create localized tabs
             foreach (\samson\core\SamsonLocale::get() as $locale) {
                 (new Tab($tab))->header->set('content', '<span>'.$locale.'</span>');
             }*/
     // Fire event that ui workspace container has been created
     Event::fire('cms_ui.workspace_created', array(&$this->workspace, &$this));
     return parent::init($params);
 }
示例#3
0
 /** Test dynamic event callback handler */
 public function testSubscribeDynamic()
 {
     // Subscribe to event
     \samson\core\Event::subscribe('test.subscribe_dynamic', array($this, 'eventDynamicCallback'));
     // Fire event
     $result = null;
     \samson\core\Event::fire('test.subscribe_dynamic', array(&$result));
     // Perform test
     $this->assertEquals(2, $result);
 }
示例#4
0
 /**
  * Render tab HTML. Method calls all child tabs
  * rendering.
  * @return string TabView HTML
  */
 public function render()
 {
     $bodyHtml = '';
     $headerHtml = '';
     /** @var Tab $child Render separately child tabs body & headers */
     foreach ($this->children as $child) {
         $headerHtml .= $child->header->render();
         $bodyHtml .= $child->body->render();
     }
     // Render tab consisting of two parts
     $this->output = $this->renderer->view($this->view)->set('header_html', $headerHtml)->set('body_html', $bodyHtml)->output();
     // Fire event that tab has been rendering
     Event::fire('cms_ui.tab_rendered', array(&$this, &$this->output));
     return $this->output;
 }
示例#5
0
 /**
  * Switch active environment
  * @param string $environment Configuration environment identifier
  */
 public function change($environment = Scheme::BASE)
 {
     // Switch to configuration environment
     $this->active =& $this->schemes[$environment];
     // Subscribe active configuration scheme to core module configure event
     Event::subscribe('core.module.configure', array($this, 'configure'));
     // If we have successfully changed configuration scheme
     if (!isset($this->active)) {
         // Signal error
         Event::fire('error', array($this, 'Cannot change configuration scheme to [' . $environment . '] - Configuration scheme does not exists'));
         // Set global scheme as active
         $this->active =& $this->schemes[Scheme::BASE];
     }
 }
示例#6
0
 /**
  * Render container HTML. Method calls all child elements
  * rendering.
  * @return string Container HTML
  */
 public function render()
 {
     // Start rendering content with current content
     $html = $this->content;
     // Iterate all child containers
     foreach ($this->children as $child) {
         // Perform child container rendering
         $html .= $child->render();
     }
     // Render container view with child containers
     $this->output = $this->renderer->view($this->view)->set('title', $this->title)->set('class', $this->class)->set('identifier', $this->identifier)->set('content_html', $html)->output();
     // Fire event that container has been rendering
     Event::fire('cms_ui.container_rendered', array(&$this, &$this->output));
     return $this->output;
 }
示例#7
0
 /**
  * Configure object with configuration entity parameters.
  *
  * If now $identifier is passed - automatic identifier generation
  * will take place from object class name.
  *
  * If additional parameters key=>value collection is passed, they
  * will be used to configure object instead of entity configuration
  * class.
  *
  * @param mixed $object Object for configuration with entity
  * @param string $identifier Configuration entity name
  * @param array|null $params Collection of configuration parameters
  *
  * @return boolean True if we have successfully configured object
  */
 public function configure(&$object, $identifier = null, $params = null)
 {
     /** @var Entity $pointer Pointer to entity instance */
     $pointer = null;
     // If we have found this entity configuration, If no entity identifier is passed get it from object class
     if ($this->entity(isset($identifier) ? $identifier : get_class($object), $pointer)) {
         return $this->handleConfigure($object, $pointer, $params);
     } else {
         // Signal error
         Event::fire('error', array($this, 'Cannot configure entity[' . $identifier . '] - Entity configuration does not exists'));
         // We have failed
         return false;
     }
 }
示例#8
0
 /**
  * @param \samson\core\IViewable $renderer Renderer object
  * @param Container $parent Pointer to parent form container
  */
 public function __construct(IViewable &$renderer, Container &$parent = null)
 {
     // Fire event that form has been created
     Event::fire('cms_ui.form_created', array(&$this));
     parent::__construct($renderer, $parent);
 }