示例#1
0
文件: Basic.php 项目: atk4/atk4
 public function addMenuItem($page, $label = null)
 {
     if (!$label) {
         $label = ucwords(str_replace('_', ' ', $page));
     }
     $id = $this->name . '_i' . count($this->items);
     $label = $this->app->_($label);
     $js_page = null;
     if ($page instanceof jQuery_Chain) {
         $js_page = '#';
         $this->js('click', $page)->_selector('#' . $id);
         $page = $id;
     }
     $this->items[] = array('id' => $id, 'page' => $page, 'href' => $js_page ?: $this->app->url($page), 'label' => $label, $this->class_tag => $this->isCurrent($page) ? $this->current_menu_class : $this->inactive_menu_class);
     return $this;
 }
示例#2
0
文件: Basic.php 项目: atk4/atk4
 /**
  * Add column to grid.
  *
  * @param mixed  $formatters
  * @param string $name
  * @param string|array $descr
  *
  * @return $this|Controller_Grid_Format
  */
 public function addColumn($formatters, $name = null, $descr = null)
 {
     if ($name === null) {
         $name = $formatters;
         $formatters = 'text';
     }
     if ($descr === null) {
         $descr = ucwords(str_replace('_', ' ', $name));
     }
     if (is_array($descr)) {
         $descr['descr'] = $this->app->_($descr['descr']);
     } else {
         $descr = $this->app->_($descr);
     }
     $this->columns[$name] = array('type' => $formatters);
     if (is_array($descr)) {
         $this->columns[$name] = array_merge($this->columns[$name], $descr);
     } else {
         $this->columns[$name]['descr'] = $descr;
     }
     if ($this->columns[$name]['icon']) {
         if ($this->columns[$name]['icon'][0] != '<') {
             $this->columns[$name]['icon'] = '<i class="icon-' . $this->columns[$name]['icon'] . '"></i>&nbsp;';
         } else {
             throw $this->exception('obsolete way of using icon. Do not specify HTML code, but juts the icon');
         }
     }
     $this->last_column = $name;
     if (!is_string($formatters) && is_callable($formatters)) {
         $this->columns[$name]['fx'] = $formatters;
         return $this;
     }
     // TODO call addFormatter instead!
     $subtypes = explode(',', $formatters);
     foreach ($subtypes as $subtype) {
         if (strpos($subtype, '\\') || strpos($subtype, '/')) {
             // add-on functionality:
             // http://agiletoolkit.org/codepad/gui/grid#codepad_gui_grid_view_example_7_ex
             if (!$this->elements[$subtype . '_' . $name]) {
                 $addon = $this->app->normalizeClassName($subtype, 'Controller_Grid_Format');
                 $this->elements[$subtype . '_' . $name] = $this->add($addon);
             }
             $addon = $this->getElement($subtype . '_' . $name);
             if (!$addon instanceof Controller_Grid_Format) {
                 throw $this->exception('Grid formatter class should extend Controller_Grid_Format class')->addMoreInfo('formater', $subtype);
             }
             $addon->initField($name, $descr);
             return $addon;
         } elseif (!$this->hasMethod($m = 'init_' . $subtype)) {
             if (!$this->hasMethod($m = 'format_' . $subtype)) {
                 // exception if formatter doesn't exist
                 throw $this->exception('No such formatter')->addMoreInfo('formater', $subtype);
             }
         } else {
             // execute formatter init_*
             $this->{$m}($name, $descr);
         }
     }
     return $this;
 }
示例#3
0
文件: Field.php 项目: atk4/atk4
 /** Adds "X is a mandatory field" message */
 public function validateNotNULL($msg = null)
 {
     $this->setMandatory();
     if ($msg && $msg !== true) {
         $msg = $this->app->_($msg);
     } else {
         $msg = sprintf($this->app->_('%s is a mandatory field'), $this->caption);
     }
     $this->validateField(array($this, '_validateNotNull'), $msg);
     return $this;
 }
示例#4
0
文件: CRUD.php 项目: atk4/atk4
 /**
  * Configures necessary components when CRUD is in the adding mode.
  *
  * @param array $fields List of fields for add form
  *
  * @return void|Model If model, then bail out, no greed needed
  */
 protected function configureAdd($fields = null)
 {
     // We are actually in the frame!
     if ($this->isEditing('add')) {
         $this->model->unload();
         $m = $this->form->setModel($this->model, $fields);
         $this->form->addSubmit('Add');
         $this->form->onSubmit(array($this, 'formSubmit'));
         return $m;
     } elseif ($this->isEditing()) {
         return;
     }
     // Configure Add Button on Grid and JS
     $this->add_button->js('click')->univ()->frameURL($this->app->_($this->entity_name === false ? 'New Record' : 'Adding new ' . $this->entity_name), $this->virtual_page->getURL('add'), $this->frame_options);
     if ($this->entity_name !== false) {
         $this->add_button->setHTML('<i class="icon-plus"></i> Add ' . htmlspecialchars($this->entity_name));
     }
 }