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 render() { $amounts = $this->retrieve($this->range()->start(), $this->range()->end()); return Tart::html($this, function ($h, $self) use($amounts) { $h('div', array('class' => 'caption'), function ($h, $self) use($amounts) { $h('h4', $self->title()); $total = array_sum($amounts); $h('p', function ($h) use($self, $amounts, $total) { $classes = array(0 => 'label-success', 1 => 'label-info', 2 => 'label-warning', 3 => 'label-danger'); foreach (array_keys($amounts) as $i => $title) { $h('div', function ($h) use($self, $amounts, $i, $title, $total, $classes) { $h('span', array('class' => 'label ' . $classes[$i]), number_format($self::to_percent($amounts[$title], $total), 2) . '%'); $h->add(ucfirst($title)); }); } }); $classes = array(0 => 'bar-success', 1 => 'bar-info', 2 => 'bar-warning', 3 => 'bar-danger'); $h('div.progress', function ($h) use($self, $amounts, $total, $classes) { foreach (array_values($amounts) as $i => $amount) { $h('div', array('class' => 'bar ' . $classes[$i], 'style' => 'width:' . ($self::to_percent($amount, $total) . '%'))); } }); }); })->render(); }
public function render() { return Tart::form($this, function ($h, $self) { $h('label', __($self->label())); $h->add($self->parent()->form()->radios($self->name(), array('choices' => $self->params(), 'include_blank' => $self->all()))); }); }
public function render() { $content = $this->retrieve($this->range() ? $this->range()->start() : NULL, $this->range() ? $this->range()->end() : NULL); return Tart::html($this, function ($h, $self) use($content) { $h('div.caption', function ($h, $self) use($content) { $h('h4', $self->title()); $h->add($content); }); })->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 render() { $amount = $this->retrieve($this->range()->start(), $this->range()->end()); $previous_amount = $this->retrieve($this->range()->previous_start(), $this->range()->previous_end()); $diff = Stats_Widget::percent_diff($amount, $previous_amount); return Tart::html($this, function ($h, $self) use($amount, $diff) { $h('div', array('class' => 'caption ' . ($diff > 0 ? 'success' : 'warning')), function ($h, $self) use($amount, $diff) { $h('h4', $self->title()); $h('strong', $self->format($amount) . ' '); $trend = $diff == 0 ? 'icon-minus' : ($diff > 0 ? 'icon-chevron-up' : 'icon-chevron-down'); $h('span.difference', "<i class='{$trend}'></i> " . number_format($diff, 2) . ' %'); }); })->render(); }
public function render() { return Tart::form($this, function ($h, $self) { $h('label', __($self->label())); $h('p', function ($h, $self) { $h('div', array('class' => 'btn-group' . ($self->vertical() ? ' btn-group-vertical' : ''), 'data-toggle' => 'buttons-radio'), function ($h, $self) { if ($self->all()) { $h('a', array('class' => 'btn ' . ($self->parent()->form()->object()->{$self->name()} ? '' : ' active'), 'href' => Request::current()->url() . URL::query(array($self->name() => ''))), __('All')); } foreach ($self->params() as $value => $label) { $h('a', array('class' => 'btn ' . ($self->parent()->form()->object()->{$self->name()} == $value ? ' active' : ''), 'href' => Request::current()->url() . URL::query(array($self->name() => $value))), $label); } }); }); }); }
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() { $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(); }
/** * Test Basic getters and setters */ public function test_getters_setters() { $collection = Jam::all('test_city'); $columns = array('name' => new Tart_Column()); $table = new Tart_Table($collection, $columns); $this->assertSame($collection, $table->collection()); $this->assertEquals($columns, $table->columns()); $this->assertEquals('name', Arr::get($table->columns(), 'name')->name()); $this->assertEquals('Name', Arr::get($table->columns(), 'name')->label()); $table->columns(array('id' => new Tart_Column(), 'size' => Tart::column()->name('population')->label('Big Size'))); $this->assertEquals('id', Arr::get($table->columns(), 'id')->name()); $this->assertEquals('Id', Arr::get($table->columns(), 'id')->label()); $this->assertEquals('population', Arr::get($table->columns(), 'size')->name()); $this->assertEquals('Big Size', Arr::get($table->columns(), 'size')->label()); $collection2 = Jam::all('test_country'); $table->collection($collection2); $table->selected(array(10, 12)); $this->assertSame($collection2, $table->collection()); $this->assertSame(array(10, 12), $table->selected()); $table->selected(FALSE); $this->assertSame(FALSE, $table->selected()); }
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 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(); }
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 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>'); }
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 static function notifications() { if ($notifications = Session::instance()->get_once('tart.notifications')) { return Tart::html(NULL, function ($h) use($notifications) { foreach ($notifications as $notification) { $h('div', array('class' => 'alert alert-' . $notification['label']), function ($h) use($notification) { $h('button', array('type' => 'button', 'class' => 'close', 'data-dismiss' => 'alert'), '×'); $h('strong', ucfirst($notification['label'])); $h->add($notification['message']); }); } }); } }
public static function uri($item = NULL, $action = NULL) { $route_name = 'tart'; if ($item instanceof Jam_Validated) { $params = array('controller' => Inflector::plural($item->meta()->model())); if ($item->loaded()) { $params['id'] = $item->id(); } if (is_array($action)) { $params = Arr::merge($params, $action); } elseif ($action) { $params['action'] = $action; } if (!$action or is_array($action) and !isset($action['action'])) { $params['action'] = $item->loaded() ? 'edit' : 'new'; } $params['category'] = Arr::get($params, 'category', Tart::category($params['controller'])); if ($params['category']) { $route_name = 'tart_category'; } return Route::url($route_name, $params); } else { $params = array('controller' => $item); if (is_array($action)) { $params = Arr::merge($params, $action); } elseif ($action) { $params['action'] = $action; } $params['category'] = Arr::get($params, 'category', Tart::category($params['controller'])); if ($params['category']) { $route_name = 'tart_category'; } return Route::url($route_name, $params); } }
public static function to_modifications(array $modified) { foreach ($modified as $key => &$value) { $value = Inflector::humanize($key) . (is_array($value) ? ': ' . Tart_Request::to_modifications($value) : ($value ? ' set to "' . $value . '"' : ' cleared')); } return Tart::to_sentence(array_values($modified)); }
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(); }