Example #1
0
 public function test_choices()
 {
     $blogs = Jam::all('test_blog')->load_fields(array(array('id' => 1, 'name' => 'Flowers blog', 'url' => 'http://flowers.wordpress.com'), array('id' => 2, 'name' => 'Awesome programming', 'url' => 'http://programming-blog.com'), array('id' => 3, 'name' => 'Tabless', 'url' => 'http://bobby-tables-ftw.com')));
     $select = $blogs->as_array(':primary_key', ':name_key');
     $choices = Jam_Form::list_choices($blogs);
     $this->assertEquals($select, $choices);
     $choices = Jam_Form::list_choices($select);
     $this->assertEquals($select, $choices);
 }
Example #2
0
 public function render()
 {
     $html = Tart::html($this, function ($h, $self) {
         $h('table', $self->attributes(), function ($h, $self) {
             $h('thead', function ($h, $self) {
                 if ($self->selected() !== NULL and $self->selected() !== FALSE) {
                     $h('th', array('width' => 10), function ($h, $self) {
                         $h('input', array('type' => 'checkbox', 'name' => 'all', 'value' => '1', 'checked' => array_diff($self->collection()->ids(), $self->selected()) ? NULL : 'checked'));
                     });
                 }
                 foreach ($self->columns() as $column) {
                     $attributes = array('width' => $column->width());
                     if ($column->sort()) {
                         $attributes['nowrap'] = 'nowrap';
                     }
                     $h('th', $attributes, $column->sort() ? $column->sort_anchor() : $column->label());
                 }
             });
             $h('tbody', function ($h, $self) {
                 foreach ($self->collection() as $item) {
                     $h('tr', array('class' => Tart_Table::item_class_name($item)), function ($h, $self) use($item) {
                         if ($self->selected() !== NULL and $self->selected() !== FALSE) {
                             $h('td', function ($h, $self) use($item) {
                                 $h('input', array('type' => 'checkbox', 'name' => 'id[]', 'value' => Jam_Form::list_id($item), 'checked' => in_array(Jam_Form::list_id($item), $self->selected()) ? TRUE : NULL));
                             });
                         }
                         foreach ($self->columns() as $column) {
                             $h('td', $column->item($item)->render());
                         }
                     });
                 }
             });
             if ($self->footer()) {
                 $h('tfoot', $self->footer());
             }
         });
     });
     return $html->render();
 }
Example #3
0
 public function render()
 {
     $html = Tart::html($this, function ($h, $self) {
         $h('div.thumbnails', function ($h, $self) {
             foreach ($self->collection() as $item) {
                 $h('div.media', function ($h, $self) use($item) {
                     if ($self->selected() !== NULL) {
                         $h('td', function ($h, $self) use($item) {
                             $h('input', array('type' => 'checkbox', 'name' => 'id[]', 'value' => Jam_Form::list_id($item), 'checked' => in_array(Jam_Form::list_id($item), $self->selected()) ? TRUE : NULL));
                         });
                     }
                     foreach ($self->columns() as $column) {
                         $h('td', $column->render($item, $self));
                     }
                 });
             }
             if ($self->footer()) {
                 $h('tfoot', $self->footer());
             }
         });
     });
     return $html->render();
 }
Example #4
0
 /**
  * Radios select, bootstrap style
  * @param  string $name
  * @param  array  $options
  * @param  array  $attributes
  * @return string
  */
 public function radios($name, array $options = array(), array $attributes = array())
 {
     $attributes = $this->default_attributes($name, $attributes);
     if (!isset($options['choices'])) {
         throw new Kohana_Exception('Radios tag widget requires a \'choices\' option');
     }
     $choices = Jam_Form::list_choices($options['choices']);
     if ($blank = Arr::get($options, 'include_blank')) {
         Arr::unshift($choices, '', $blank === TRUE ? __(" -- Select -- ") : $blank);
     }
     $radios = array();
     foreach ($choices as $key => $title) {
         $radio = $this->radio($name, array('value' => $key), array('id' => $attributes['id'] . '_' . $key));
         $radios[] = new Builder_Html('label', array('class' => 'radio'), $radio . $title);
     }
     return '<div ' . HTML::attributes($attributes) . '>' . join("\n", $radios) . '</div>';
 }
Example #5
0
File: Form.php Project: Konro1/pms
 /**
  * Create a nested form for a child association of the model, assigning the correct prefix
  *
  * @param string $name  of the association
  * @param int $index an index id of a collection (if the association if a colleciton)
  * @return  Jam_Form
  */
 public function fields_for($name, $index = NULL)
 {
     $object = $this->object()->{$name};
     if ($index !== NULL) {
         if (is_numeric($index) and $object[$index]) {
             $object = $object[$index];
         } else {
             $object = $object->build();
         }
     } elseif (!$object) {
         $object = $this->object()->build($name);
     }
     $new_prefix = Jam_Form::generate_prefix($this->prefix(), $name, $index);
     return Jam::form($object, get_class($this))->prefix($new_prefix);
 }
Example #6
0
 public function render()
 {
     if (!$this->item()) {
         throw new Kohana_Exception('You must assign an item before you render');
     }
     if ($callback = $this->callback()) {
         $content = call_user_func($callback, $this->item(), $this->name(), $this);
     } elseif ($field = $this->item()->meta()->field($this->name())) {
         $content = Tart_Column::render_field($this->item(), $field);
     } elseif ($association = $this->item()->meta()->association($this->name())) {
         $content = Tart_Column::render_association($this->item(), $association);
     } else {
         $content = (string) $this->item()->{$this->name()};
     }
     if ($content) {
         if ($this->_filter and $this->_filter_name and $this->_is_link) {
             $content = $this->_filter->anchor($this->_filter_name, Jam_Form::list_id($this->item()->{$this->name()}), $content, array('href' => Tart::uri($this->item()->{$this->name()})));
         }
         if ($this->_is_link) {
             $content = HTML::anchor(Tart::uri($this->item()->{$this->name()}), $content);
         }
         if ($this->_filter and $this->_filter_name) {
             $content = $this->_filter->anchor($this->_filter_name, Jam_Form::list_id($this->item()->{$this->name()}), $content);
         }
     }
     return $content;
 }
Example #7
0
 /**
  * HTML input select field
  * available options
  * 	- choices - this can be Jam_Query_Builder_Collection or a simple array
  * 	- include_blank - bool|string - include an empty option
  *
  * @param string $name       the name of the Jam_Model attribute
  * @param array  $options    set the options of the select with 'choices' and 'include_blank'
  * @param array  $attributes HTML attributes for the field
  * @return string
  */
 public function select($name, array $options = array(), array $attributes = array())
 {
     $attributes = $this->default_attributes($name, $attributes);
     if (!isset($options['choices'])) {
         throw new Kohana_Exception("Select tag widget requires a 'choices' option");
     }
     $choices = Jam_Form::list_choices($options['choices']);
     if ($blank = Arr::get($options, 'include_blank')) {
         Arr::unshift($choices, '', $blank === TRUE ? " -- Select -- " : $blank);
     }
     $selected = Jam_Form::list_id($this->object()->{$name});
     return Form::select($attributes['name'], $choices, $selected, $attributes);
 }