Skip to content

Commit

Permalink
Add support for "disabled" to upload widget
Browse files Browse the repository at this point in the history
  • Loading branch information
ivank committed Jul 17, 2015
1 parent d95d0ef commit f93d07c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions classes/Kohana/Jam/Form/Tart/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public function upload($name, array $options = array(), array $attributes = arra
if ( ! ($this->object()->{$name} instanceof Upload_File))
throw new Kohana_Exception('Upload widget is used for upload file fields only for name :name', array(':name' => $name));;

return Tart::html($this, function($h, $self) use ($name, $options){
$h('div', array('class' => 'fileupload '.(($self->object()->{$name}->is_empty()) ? 'fileupload-new' : 'fileupload-exists'), 'data-provides' => 'fileupload'), function($h, $self) use ($name, $options) {
return Tart::html($this, function($h, $self) use ($name, $options, $attributes){
$h('div', array('class' => 'fileupload '.(($self->object()->{$name}->is_empty()) ? 'fileupload-new' : 'fileupload-exists'), 'data-provides' => 'fileupload'), function($h, $self) use ($name, $options, $attributes) {
$h('div', array('class' => 'fileupload-new thumbnail', 'style' => 'width:100px; height:75px;line-height:75px;text-align:center;'), function($h) {
$h('img', array('src' => 'http://www.placehold.it/100x75/EFEFEF/AAAAAA&text=no+image'));
});
Expand All @@ -211,10 +211,12 @@ public function upload($name, array $options = array(), array $attributes = arra
}
});

$h('span.btn.btn-file', function($h, $self) use ($name){
$h('span.btn.btn-file', function($h, $self) use ($name, $attributes){
$disabled = Arr::get($attributes, 'disabled', null);

$h('span.fileupload-new', 'Select Image');
$h('span.fileupload-exists', 'Change Image');
$h->add($self->file($name, array('temp_source' => TRUE)));
$h->add($self->file($name, array('temp_source' => TRUE), array('disabled' => $disabled)));
});

$remove = Arr::get($options, 'remove');
Expand Down Expand Up @@ -310,6 +312,7 @@ public function remoteselect($name, array $options = array(), array $attributes
return Tart::html($this, function($h, $self) use ($name, $options, $attributes) {

$current = $self->object()->$name;
$disabled = Arr::get($attributes, 'disabled', null);
$model = isset($options['model']) ? $options['model'] : $self->object()->meta()->association($name)->foreign_model;
$template = Arr::get($options, 'template', 'tart/typeahead/remoteselect');

Expand All @@ -328,7 +331,7 @@ public function remoteselect($name, array $options = array(), array $attributes

$options['url'] = strtr($options['url'], array('{{name}}' => $attributes['name']));

$h('input', array('name' => $attributes['name'], 'type' => 'hidden', 'value' => ''));
$h('input', array('name' => $attributes['name'], 'type' => 'hidden', 'value' => '', 'disabled' => $disabled));

$label = Arr::get($options, 'label', __(Inflector::humanize($name)));
$default_placeholder = __('Search for :label', array(':label' => strtolower($label)));
Expand All @@ -342,6 +345,7 @@ public function remoteselect($name, array $options = array(), array $attributes
'data-container' => '#'.$options['container'],
'data-overwrite' => 1,
'data-url' => $options['url'],
'disabled' => $disabled,
));

$h('span', array('id' => $options['container'], 'class' => 'remoteselect-container'), function($h, $self) use ($current, $model, $options) {
Expand Down

0 comments on commit f93d07c

Please sign in to comment.