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() { $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 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 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(); }
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(); }
/** * 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 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(); }
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']); }); } }); } }