Example #1
0
 /**
  * Create a new Tab Collection
  * @param id $collectionId
  * @param array $configuration
  * @return UIs\Tabs
  */
 public function create($collectionId, $configuration)
 {
     $configuration['type'] = $this->_type;
     $ui = UIs\Ui::factory($configuration);
     if (!empty($this->tabs[$collectionId])) {
         throw new Exceptions\DuplicateIdException('Collection with the same id: ' . $collectionId . ' already exists.');
     }
     return $this->tabs[$collectionId] = $ui;
 }
Example #2
0
 /**
  * Element Factory
  * @param array $configuration
  * @return \Zbase\Ui\Form\Element
  */
 public static function factory($configuration)
 {
     /**
      * Load a widget
      */
     if (!empty($configuration['widget'])) {
         if (!empty($configuration['validations'])) {
             $widget = zbase()->widget($configuration['widget'], [], true)->setAttribute('validations', $configuration['validations']);
         } else {
             $widget = zbase()->widget($configuration['widget'], [], true);
         }
         return $widget;
     }
     if (!empty($configuration['ui'])) {
         $ui = \Zbase\Ui\Ui::factory($configuration['ui']);
         if ($ui->enabled()) {
             return $ui;
         }
         return null;
     }
     $type = !empty($configuration['type']) ? $configuration['type'] : 'text';
     $id = !empty($configuration['id']) ? $configuration['id'] : null;
     if (is_null($id)) {
         throw new Exceptions\ConfigNotFoundException('Index:id is not set on Form Element Factory');
     }
     if (!empty($type)) {
         $className = zbase_model_name(null, 'class.ui.form.type.' . strtolower($type), '\\Zbase\\Ui\\Form\\Type\\' . ucfirst($type));
         $element = new $className($configuration);
         if ($element->enabled()) {
             $element->prepare();
             return $element;
         }
     }
     return null;
 }
Example #3
0
 /**
  * Create an action button
  * @param string $actionName The Action index name update|create|delete|ddelete|restore
  * @param \Zbase\Interfaces\EntityInterface $row
  * @param array $actionConfig Action config
  * @param boolean $template If we will have to generate a template
  * @return \Zbase\Ui\UiInterface
  */
 public function createActionBtn($actionName, $row, $actionConfig, $template = false)
 {
     if (!$row instanceof \Zbase\Interfaces\EntityInterface && !$template) {
         return null;
     }
     if (empty($actionConfig)) {
         return null;
     }
     $rowTrashed = false;
     if ($this->_entity->hasSoftDelete() && !empty($row)) {
         $rowTrashed = $row->trashed();
     }
     if ($actionName == 'delete' || $actionName == 'update') {
         if ($rowTrashed) {
             return null;
         }
     }
     if ($actionName == 'restore' || $actionName == 'ddelete') {
         if (empty($rowTrashed)) {
             return null;
         }
     }
     $label = !empty($actionConfig['label']) ? $actionConfig['label'] : ucfirst($actionName);
     if (strtolower($label) == 'ddelete') {
         $label = _zt('Forever Delete');
     }
     $actionConfig['type'] = 'component.button';
     $actionConfig['size'] = 'extrasmall';
     $actionConfig['label'] = _zt($label);
     $actionConfig['tag'] = 'a';
     if (!empty($actionConfig['route']['name'])) {
         if (!empty($actionConfig['route']['params'])) {
             foreach ($actionConfig['route']['params'] as $paramName => $paramValue) {
                 if (preg_match('/row::/', $paramValue)) {
                     $rowIndex = str_replace('row::', '', $paramValue);
                     if (!empty($row)) {
                         $id = $actionConfig['route']['params'][$paramName] = zbase_data_get($row, $rowIndex);
                     } else {
                         if (!empty($template)) {
                             $id = $actionConfig['route']['params'][$paramName] = '__' . $rowIndex . '__';
                         }
                     }
                 }
             }
         }
         $actionConfig['routeParams'] = $actionConfig['route']['params'];
         $actionConfig['route'] = $actionConfig['route']['name'];
     }
     $actionConfig['id'] = $this->getWidgetPrefix() . 'Action' . $actionName . (!empty($id) ? $id : null);
     if ($actionName == 'create') {
         $actionConfig['color'] = 'blue';
     }
     if ($actionName == 'update') {
         $actionConfig['color'] = 'green';
     }
     if ($actionName == 'view') {
         $actionConfig['color'] = 'blue';
     }
     if ($actionName == 'delete') {
         $actionConfig['color'] = 'red';
     }
     if ($actionName == 'restore') {
         $actionConfig['color'] = 'warning';
     }
     if ($actionName == 'ddelete') {
         $actionConfig['color'] = 'red';
     }
     $btn = \Zbase\Ui\Ui::factory($actionConfig);
     if ($actionName == 'create') {
         if (!$this->_actionCreateButton instanceof \Zbase\Ui\UiInterface) {
             $this->_actionCreateButton = $btn;
         }
     }
     return $btn;
 }
Example #4
0
 /**
  * Return the Wrapper Attributes
  * @return array
  */
 public function wrapperAttributes()
 {
     $attr = parent::wrapperAttributes();
     $attr['class'][] = 'zbase-ui-' . $this->_type;
     return $attr;
 }
Example #5
0
 /**
  * Extract value from row
  */
 protected function _value()
 {
     if (!empty($this->_templateMode)) {
         return;
     }
     $noUiDataTypes = ['integer', 'string'];
     /**
      * Classname and will call className::columnValue
      */
     $dataCallback = zbase_data_get($this->data, 'callback', null);
     $dataType = $this->getDataType();
     $valueIndex = $this->getValueIndex();
     if (!empty($dataCallback)) {
         $value = $dataCallback::entityDataValue($this->getRow(), $this);
     } else {
         $value = zbase_data_get($this->getRow(), $valueIndex);
     }
     if (in_array($dataType, $noUiDataTypes)) {
         $this->_value = $value;
     } else {
         $dataTypeConfiguration = ['id' => $dataType, 'type' => 'data.' . $dataType, 'enable' => true, 'value' => $value, 'hasAccess' => true, 'options' => $this->getAttribute('options')];
         $this->_value = \Zbase\Ui\Ui::factory($dataTypeConfiguration);
     }
 }
Example #6
0
 /**
  * Prepare
  * return void
  */
 protected function _pre()
 {
     $this->_tabs = $this->sortPosition($this->_tabs);
     if (empty($this->_hasActiveTab) && !empty($this->_tabs)) {
         zbase_collection($this->_tabs)->first()->setActive(true);
     }
     parent::_pre();
 }
Example #7
0
 /**
  * To String
  * @return string
  */
 public function __toString()
 {
     $content = parent::__toString();
     if (zbase_is_angular_template()) {
         $serviceName = zbase_angular_module_servicename($this->getModule(), $this);
         $scopeName = zbase_angular_module_scopename($this->getModule(), $this);
         $content = str_replace('ANGULAR_WIDGET_MODULE_SERVICENAME', $serviceName, $content);
         $content = str_replace('ANGULAR_WIDGET_MODULE_SCOPENAME', $scopeName, $content);
     }
     return $content;
 }
Example #8
0
/**
 * Create a UI Element
 * @param array $configuration
 * @return Ui\UiInterface
 */
function zbase_ui($configuration)
{
    return \Zbase\Ui\Ui::factory($configuration);
}
Example #9
0
 /**
  * Return the Wrapper Attributes
  * @return array
  */
 public function wrapperAttributes()
 {
     $attr = parent::wrapperAttributes();
     $attr['class'][] = 'zbase-ui-' . $this->_type;
     $attr['class'][] = 'tab-pane';
     $attr['class'][] = 'fade';
     if ($this->isActive()) {
         $attr['class'][] = 'active';
         $attr['class'][] = 'in';
     }
     $attr['id'] = $this->getHtmlId();
     return $attr;
 }
Example #10
0
 /**
  * Prepare the Actions
  */
 protected function _actions()
 {
     if (!empty($this->_actions)) {
         foreach ($this->_actions as $actionName => $action) {
             $enable = !empty($action['enable']) ? true : false;
             if (!empty($enable)) {
                 $label = !empty($action['label']) ? $action['label'] : ucfirst($actionName);
                 $action['type'] = 'component.button';
                 $action['id'] = $this->id() . 'Action' . $actionName;
                 $action['size'] = 'extrasmall';
                 $action['label'] = _zt($label);
                 $action['tag'] = 'a';
                 if (!empty($action['route']['name'])) {
                     if (!empty($action['route']['params'])) {
                         foreach ($action['route']['params'] as $paramName => $paramValue) {
                             if (preg_match('/row::/', $paramValue)) {
                                 $rowIndex = str_replace('row::', '', $paramValue);
                                 if (!empty($row)) {
                                     $action['route']['params'][$paramName] = zbase_data_get($row, $rowIndex);
                                 }
                             }
                         }
                     }
                     $action['routeParams'] = $action['route']['params'];
                     $action['route'] = $action['route']['name'];
                 }
                 $btn = \Zbase\Ui\Ui::factory($action);
                 if ($actionName == 'create') {
                     if (!$this->_actionCreateButton instanceof \Zbase\Ui\UiInterface) {
                         $this->_actionCreateButton = $btn;
                     }
                     continue;
                 }
             }
         }
     }
 }