public function test_render() { $pagination = new Tart_Pagination(1000, 100); $pagination->per_page(100); $pagination->controller('test_cities'); $controller_url = Tart::uri('test_cities'); $expected = <<<HTML <form action="{$controller_url}" method="GET" class="form-inline" enctype="multipart/form-data"> <ul class="pager"> <li class="previous"> <a href="{$controller_url}?offset=0">« Previous</a> </li> <li class="next"> <a href="{$controller_url}?offset=200">Next »</a> </li> <li class="pagination-control"> <label> Showing: 100 - 200 of 1000 </label> <span style="display:none"> <input type="range" id="pagination-slider" value="100" class="input-large" min="0" step="100" max="1000"/> <input type="number" id="pagination-input" name="offset" value="100" class="input-mini" min="0" step="100" max="1000"/> <button type="submit" class="btn">Go</button> </span> </li> </ul> </form> HTML; $this->assertSame($expected, (string) $pagination->render()); }
public function action_batch() { $ids = $this->request->post('id') ?: $this->request->query('id'); $action = $this->request->post('action') ?: $this->request->query('action'); if (!$ids) { $this->notify('error', 'No items selected'); $this->redirect($this->request->referrer() ?: Tart::uri($this->request->controller())); } $this->{'batch_' . $action}($ids); }
public function test_actions() { $city = Jam::build('test_city')->load_fields(array('id' => 1, 'name' => 'First Name', 'population' => 300)); $actions = new Tart_Column_Actions(function ($item) { return HTML::anchor(Tart::uri($item), 'Edit') . '<span> info </span>'; }); $rendered = $actions->item($city)->render(); $this->assertSelectEquals('a[href="' . Tart::uri($city) . '"]', 'Edit', TRUE, $rendered); $this->assertSelectEquals('span', 'info', TRUE, $rendered); }
public function render() { return Tart::html($this)->form(Tart::uri($this->controller()), array('method' => 'GET', 'class' => 'tart-filter'), function ($h, $self) { $tabindex = 1; foreach ($self->items() as $index => $item) { $h->add($item->tabindex($tabindex++)->render()); } $h('div.form-actions', function ($h, $self) { $h('button', array('class' => 'btn', 'tabindex' => count($self->items())), __('Go')); }); })->render(); }
public function default_callback() { $self = $this; return function ($item) use($self) { return Tart::html($item, function ($h, $item) use($self) { if ($self->sortable()) { $h->add($self->sortable_controls($item)); } $params = array(); if ($self->controller()) { $params['controller'] = $self->controller(); } $h->add(Tart_Html::anchor(Tart::uri($item, Arr::merge($params, array('action' => 'edit'))), __('Edit'), array('class' => 'btn btn-small'))); $h->add(Tart_Html::anchor(Tart::uri($item, Arr::merge($params, array('action' => 'delete'))), __('Delete'), array('class' => 'btn btn-small btn-danger', 'data-confirm' => __('Are you sure you want to delete this :item?', array(':item' => Inflector::humanize($item->meta()->model())))))); }); }; }
public function render() { if ($this->total() <= $this->per_page()) { return NULL; } return Tart::html($this)->form(Tart::uri($this->controller()), array('class' => 'form-inline', 'method' => 'GET'), function ($h, $self) { $h('ul.pager', function ($h, $self) { $h('li.previous', $self->previous()); $h('li.next', $self->next()); $h('li.pagination-control', function ($h, $self) { $h('label', function ($h, $self) { $h->add("Showing: " . $self->offset() . ' - ' . min($self->offset() + $self->per_page(), $self->total()) . ' of ' . $self->total()); }); $h('span', array('style' => 'display:none'), function ($h, $self) { $h('input', array('id' => 'pagination-slider', 'type' => 'range', 'class' => 'input-large', 'min' => 0, 'step' => $self->per_page(), 'value' => $self->offset(), 'max' => $self->total())); $h('input', array('id' => 'pagination-input', 'type' => 'number', 'name' => 'offset', 'class' => 'input-mini', 'min' => 0, 'step' => $self->per_page(), 'value' => $self->offset(), 'max' => $self->total())); $h('button', array('type' => 'submit', 'class' => 'btn'), __('Go')); }); }); }); }); }
public function test_render() { $filter = new Tart_Filter(array('name' => 'nn', 'test' => 'ttt')); $filter->entries(array('name' => Tart::entry('search', NULL, function () { return 'Name Active'; }), 'test' => Tart::entry('select', array('1' => 'test 1', '2' => 'test 2'), function () { return 'Test Active'; }))); $filter->apply(Jam::all('test_city')); $base = Tart::uri(); $expected = <<<HTML <form action="{$base}/test_cities" method="GET" class="tart-filter" enctype="multipart/form-data"> <div class="control-group control-group-input"> <label class="control-label" for="name">Search</label> <div class="controls"> <input type="text" id="name" name="name" value="nn" tabindex="1" class="search" /> </div> </div> <div class="control-group control-group-select"> <label class="control-label" for="test">Test</label> <div class="controls"> <select id="test" name="test" tabindex="2"> <option value=""> -- Select -- </option> <option value="1">test 1</option> <option value="2">test 2</option> </select> </div> </div> <div class="form-actions"> <button tabindex="2" class="btn">Go</button> </div> </form> HTML; $this->assertSame($expected, $filter->render()); }
/** * A widget to enter collection associations. * * For adding new items you have two options. Using a typeahead to search for an existing item, or with a button to add a totaly new item (or both). * To use either you can set up the 'new' option, which is a url for the action, used to render the new item. * You will have 'model', 'name', 'count' and 'id' as query parameter fillers. E.g. /admin/images/build?model={{model}}&id={{id}} * To display existing items, you'll use 'template' option, which gets 'name', 'item', 'form' and 'index' as variables * * Options: * - model: string, defaults to the foreign_model of the association, can be comma separated * - template: string, the path for the view that is used to render an existing item * - new: string, a url to render a new item * - new_button: string, the label of the "add new" button * - list: string, add a link to a list of all the elements in this multiselect * - source: string, the url used to retrieve the typeahead data. Defaults to the builtin typeahead action * - placeholder: the placeholder for the typeahead search input * - sortable: boolean, set to TRUE to enable sortable javascript plugin * * @param string $name * @param array $options * @param array $attributes * @return string */ public function multiselect($name, array $options = array(), array $attributes = array()) { $attributes = $this->default_attributes($name, $attributes); return Tart::html($this, function ($h, $self) use($name, $options, $attributes) { $model = isset($options['model']) ? $options['model'] : $self->object()->meta()->association($name)->foreign_model; $template = Arr::get($options, 'template', 'tart/typeahead/multiselect'); $options = Arr::merge(array('model' => $model, 'container' => $attributes['id'] . '_container', 'source' => Tart::uri('typeahead') . '?model=' . $model, 'new' => Tart::uri('typeahead', 'remoteselect_template') . '?model=' . $model . '&name={{name}}[]&id={{id}}&template=' . $template, 'new_button' => NULL, 'search' => TRUE, 'template' => $template, 'templatestring' => Arr::get($options, 'templatestring', ''), 'list' => NULL, 'sortable' => NULL, 'label' => strtolower(Inflector::humanize($name))), $options); $options['new'] = strtr($options['new'], array('{{name}}' => $attributes['name'])); $h('input', array('name' => $attributes['name'] . '[]', 'type' => 'hidden', 'value' => '')); $h('p', function ($h) use($name, $options, $attributes) { $h('input', array('id' => $attributes['id'], 'type' => 'text', 'placeholder' => Arr::get($options, 'placeholder', __('Search for :label', array(':label' => $options['label']))), 'data-provide' => Arr::get($options, 'provide', 'remoteselect'), 'data-source' => $options['source'], 'data-container' => '#' . $options['container'], 'data-url' => $options['new'], 'data-templatestring' => $options['templatestring'], 'style' => $options['search'] ? '' : 'display:none')); if ($options['new_button']) { $h('button', array('type' => 'button', 'class' => 'btn', 'data-ignore-submit', 'data-remoteselect-new' => $options['model']), $options['new_button']); } if ($options['list']) { $h('a', array('href' => $options['list'], 'class' => 'btn btn-link'), __('List :item', array(':item' => $options['label']))); } }); $h('ul', array('class' => 'thumbnails', 'data-provide' => $options['sortable'] ? 'sortable' : NULL, 'data-items' => $options['sortable'] ? '> li.' . $options['sortable'] : NULL, 'data-tolerance' => 'pointer', 'data-placeholder' => 'sortable-placeholder thumbnail ' . $options['sortable'], 'id' => $options['container']), function ($h, $self) use($name, $options, $attributes) { if ($self->object()->{$name} and count($self->object()->{$name})) { foreach ($self->object()->{$name} as $index => $item) { $h->add(View::factory($options['template'], array('name' => $attributes['name'] . '[]', 'item' => $item, 'index' => $index, 'form' => $self->fields_for($name, $index)))); } } }); })->render(); }
public function action_destroy() { Auth::instance()->logout(TRUE, TRUE); $this->redirect(Tart::uri('session', 'new')); }
<link href="<?php echo URL::site('jam-tart/css/bootstrap.min.css'); ?> " rel="stylesheet" media="screen"> <link href="<?php echo URL::site('jam-tart/css/bootstrap-responsive.min.css'); ?> " rel="stylesheet" media="screen"> <link href="<?php echo URL::site('jam-tart/css/general.css'); ?> " rel="stylesheet" media="all"> </head> <body> <?php echo Tart_Html::navigation(array(Tart::uri('session', 'new') => 'Login')); ?> <div class="visible-desktop nav-offseter"></div> <div class="container-fluid"> <div class="row-fluid"> <?php echo Tart_Html::notifications(); ?> <?php echo $content; ?> </div> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="<?php
<?php $form = Jam::form($session, 'tart_general'); ?> <div class="fluid-row"> <div class="span6 offset3"> <?php echo Form::open(Tart::uri('session', 'new'), array('class' => 'form-horizontal')); ?> <div class="control-group"> <div class="controls"> <h3>Login</h3> </div> </div> <?php echo $form->row('input', 'email'); ?> <?php echo $form->row('password', 'password'); ?> <div class="control-group"> <div class="controls"> <label class="checkbox"> <?php echo $form->checkbox('remember_me'); ?> Remember me </label> </div> </div> <div class="form-actions">
public function test_uri() { $base = Tart::uri(); $city_loaded = Jam::build('test_city')->load_fields(array('id' => 1, 'name' => 'test_city')); $city_new = Jam::build('test_city'); $uri = Tart::uri($city_loaded); $this->assertEquals($base . '/test_cities/edit/1', $uri); $uri = Tart::uri($city_loaded, 'delete'); $this->assertEquals($base . '/test_cities/delete/1', $uri); $uri = Tart::uri($city_loaded, array('action' => 'build', 'id' => 5)); $this->assertEquals($base . '/test_cities/build/5', $uri); $uri = Tart::uri($city_loaded, array('action' => 'build', 'controller' => 'tests')); $this->assertEquals($base . '/tests/build/1', $uri); $uri = Tart::uri($city_new, array('action' => 'build', 'id' => 5)); $this->assertEquals($base . '/test_cities/build/5', $uri); $uri = Tart::uri('test_cities'); $this->assertEquals($base . '/test_cities', $uri); $uri = Tart::uri('test_cities', 'index'); $this->assertEquals($base . '/test_cities', $uri); $uri = Tart::uri('test_cities', array('action' => 'remove', 'id' => 1)); $this->assertEquals($base . '/test_cities/remove/1', $uri); }
<span class="thumbnail span3 remoteselect-item"> <input type="hidden" name="<?php echo $name; ?> " value="<?php echo $item->id(); ?> "> <div> <a href="<?php echo Tart::uri($item); ?> " class="btn btn-link"><?php echo $item->name(); ?> </a> </div> <a href="#" data-dismiss="remoteselect" class="btn">Remove</a> </span>
public function render() { $this->pagination()->apply($this->collection()); $content = $this->content()->collection($this->collection()); if ($this->batch_actions()) { $content->selected(array()); } else { $content->selected(FALSE); } $content = $content->render(); $html = Tart::html($this, function ($h, $self) use($content) { if (!$this->batch_actions()) { $h->add($content); } else { $h->form(Tart::uri($self->controller(), 'batch'), array('method' => 'get'), function ($h, $self) use($content) { if ($self->batch_position() == Kohana_Tart_Index::BATCH_POSITION_BOTH or $self->batch_position() == Kohana_Tart_Index::BATCH_POSITION_TOP) { $h->add($self->render_batch_actions()); } $h->add($content); if ($self->batch_position() == Kohana_Tart_Index::BATCH_POSITION_BOTH or $self->batch_position() == Kohana_Tart_Index::BATCH_POSITION_BOTTOM) { $h->add($self->render_batch_actions()); } }); } $h->add($self->pagination()->render()); }); return $html->render(); }
/** * Display a pills submenu * * @param string $controller * @param string $current * @param array $items * @return string */ public static function submenu($controller, $current, array $items = array()) { return Tart::html(NUll, function ($h) use($controller, $current, $items) { $h('ul.nav.nav-pills', function ($h) use($controller, $current, $items) { foreach ($items as $item => $title) { $h('li', array('class' => $current == $item ? 'active' : NULL), function ($h) use($title, $item, $controller) { $h('a', array('href' => Tart::uri($controller, array('category' => $item))), $title); }); } }); }); }
public function sort_anchor() { $direction = 'asc'; if ($sort = Arr::get(Request::initial()->query(), 'sort')) { list($column, $current_direction) = explode(':', $sort); } if (isset($column) and $column == $this->name()) { $direction = $current_direction == 'asc' ? 'desc' : 'asc'; } else { $current_direction = NULL; } $class = $current_direction ? 'icon icon-chevron-' . ($current_direction == 'asc' ? 'up' : 'down') : ''; return HTML::anchor(Tart::uri($this->controller()) . URL::query(array('sort' => $this->name() . ':' . $direction)), $this->label() . ' ' . '<i class="' . $class . '"></i>'); }