Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gallery/gallery3-vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat committed Apr 28, 2013
2 parents 6f13dd4 + 30bcee9 commit f72ff94
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 43 deletions.
16 changes: 15 additions & 1 deletion formo/README
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CURRENT INFO -- 2013/04/06
--------------------------
Formo -- master branch last revised 2013/03/26
Formo -- master branch last revised 2013/04/26
- project homepage: http://github.com/bmidget/kohana-formo
- current dl link : http://github.com/bmidget/kohana-formo/zipball/master

Expand All @@ -20,3 +20,17 @@ $ git push

$ cd ../../gallery3
$ git commit -m "Updated upstream to Formo <VERSION_NUMBER>" modules/formo

VERIFYING PATCHES
-----------------

We have some patches in our version of the Kohana code. After every
update, you should verify that every one of our deviations is tracked
by a Kohana ticket.

To see the differences you can run a diff command
$ diff --exclude=bootstrap.php -r modified ../../gallery3 | egrep -v '^Only in'

Expected differences:
* http://github.com/bmidget/kohana-formo/pull/194
Allow can_be_empty to be set on a per-field basis. This is useful for CSRF.
2 changes: 0 additions & 2 deletions formo/modified/classes/Formo/Core/Driver/Checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public static function get_title( array $array)
return ($label !== Formo::NOTSET)
? $label
: $field->alias();

return $label;
}

public static function get_val( array $array)
Expand Down
7 changes: 6 additions & 1 deletion formo/modified/classes/Formo/Core/Driver/Radios.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public static function get_opts_template( array $array)
public static function get_title( array $array)
{
$field = $array['field'];
return $field->alias();

$label = $field->get('label');

return ($label !== Formo::NOTSET)
? $label
: $field->alias();
}

}
18 changes: 10 additions & 8 deletions formo/modified/classes/Formo/Core/Formo.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ public function __invoke()
}

$str = $this->open();

$opts = $this->driver('get_opts');
$str.= implode("\n", $opts);
$str.= $this->html();
$str.= $this->render_opts();

foreach ($this->_fields as $field)
{
Expand Down Expand Up @@ -872,7 +871,7 @@ public function order($field, $new_order = NULL, $relative_field = NULL)
{
foreach($field as $alias => $values)
{
$this->order($alias, $values[0], $values[1]);
$this->order($alias, Arr::get($values, 0), Arr::get($values, 1));
}
}
else
Expand Down Expand Up @@ -1052,7 +1051,7 @@ public function remove_rules_fields($array)
* @access public
* @return string
*/
public function render()
public function render($template = NULL)
{
if (Kohana::$profiling === TRUE)
{
Expand All @@ -1065,8 +1064,11 @@ public function render()
return NULL;
}

$template = $this->driver('get_template');
$template = $this->config('template_dir').$template;
if ($template == NULL)
{
$template = $this->driver('get_template');
$template = $this->config('template_dir').$template;
}

$view = View::factory($template)
->set('field', $this)
Expand Down Expand Up @@ -1481,4 +1483,4 @@ public function validation_errors( Kohana_Validation $validation)
}
}

}
}
37 changes: 34 additions & 3 deletions formo/modified/classes/Formo/Core/Innards.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ protected function _load( array $array)
{
$field->driver('load', array('val' => $value));
}
elseif ($field->driver('can_be_empty') === TRUE)
elseif ($field->get('can_be_empty', $field->driver('can_be_empty')) === TRUE)
{
$field->val(null);
}
Expand Down Expand Up @@ -773,7 +773,7 @@ protected function _set_driver($driver)
*/
protected function _set_id( array & $array)
{
if ($this->config('auto_id') === TRUE AND empty($array['attr']['id']))
if ($this->config('auto_id') === TRUE AND Arr::path($array, 'attr.id') === NULL)
{
if (empty($array['attr']))
{
Expand Down Expand Up @@ -861,4 +861,35 @@ protected function _resolve_construct_aliases($array)

return $_array;
}
}

/**
* Validation method that properly validates for html5 range
*
* @access public
* @static
* @param mixed $field
* @param mixed $form
* @return boolean
*/
public static function range($field, $form)
{
$value = $form->$field->val();
$attr = $form->$field->get('attr');

$max = Arr::get($attr, 'max');
$min = Arr::get($attr, 'min');
$step = Arr::get($attr, 'step');

if ($min AND $value <= $min)
return FALSE;

if ($max AND $value >= $max)
return FALSE;

// Use the default step of 1
( ! $step AND $step = 1);

return strpos(($value - $min) / $step, '.') === FALSE;
}

}
4 changes: 2 additions & 2 deletions formo/modified/views/formo_bootstrap/checkbox_template.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="field control-group formo-<?=$field->get('driver')?><?php if ($error = $field->error()) echo ' error'; ?>" id="field-container-<?=$field->alias()?>">
<label><?=$field->open().$field->html().$field->render_opts().$field->close()?> <span class="checkbox-label"><?=$field->label()?></span></label>
<label class="checkbox"><?=$field->open().$field->html().$field->render_opts().$field->close()?> <span class="checkbox-label"><?=$field->label()?></span></label>

<?php if ($msg = $field->error()): ?>
<span class="help-block"><?=$msg?></span>
<?php elseif ($msg = $field->get('message')): ?>
<span class="help-block"><?=$msg?></span>
<?php endif; ?>
</div>
</div>
6 changes: 3 additions & 3 deletions formo/modified/views/formo_bootstrap/field_template.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="field control-group formo-<?=$field->get('driver')?><?php if ($error = $field->error()) echo ' error'; ?>" id="field-container-<?=$field->alias()?>">
<?php if ($label = $field->label()): ?>
<label for="<?=$field->attr('id')?>"><?=$label?></label>
<?php elseif ($title): ?>
<?php if ($title): ?>
<span class="title"><?=$title?></span>
<?php elseif ($label = $field->label()): ?>
<label for="<?=$field->attr('id')?>"><?=$label?></label>
<?php endif; ?>

<?=$field->open().$field->html().$field->render_opts().$field->close()?>
Expand Down
2 changes: 1 addition & 1 deletion formo/upstream/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Formo is a form module for Kohana 3 that lets you work with forms as objects.

http://bmidget.github.com/kohana-formo/
http://bmidget.github.io/kohana-formo/
2 changes: 0 additions & 2 deletions formo/upstream/classes/Formo/Core/Driver/Checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public static function get_title( array $array)
return ($label !== Formo::NOTSET)
? $label
: $field->alias();

return $label;
}

public static function get_val( array $array)
Expand Down
7 changes: 6 additions & 1 deletion formo/upstream/classes/Formo/Core/Driver/Radios.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public static function get_opts_template( array $array)
public static function get_title( array $array)
{
$field = $array['field'];
return $field->alias();

$label = $field->get('label');

return ($label !== Formo::NOTSET)
? $label
: $field->alias();
}

}
18 changes: 10 additions & 8 deletions formo/upstream/classes/Formo/Core/Formo.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ public function __invoke()
}

$str = $this->open();

$opts = $this->driver('get_opts');
$str.= implode("\n", $opts);
$str.= $this->html();
$str.= $this->render_opts();

foreach ($this->_fields as $field)
{
Expand Down Expand Up @@ -872,7 +871,7 @@ public function order($field, $new_order = NULL, $relative_field = NULL)
{
foreach($field as $alias => $values)
{
$this->order($alias, $values[0], $values[1]);
$this->order($alias, Arr::get($values, 0), Arr::get($values, 1));
}
}
else
Expand Down Expand Up @@ -1052,7 +1051,7 @@ public function remove_rules_fields($array)
* @access public
* @return string
*/
public function render()
public function render($template = NULL)
{
if (Kohana::$profiling === TRUE)
{
Expand All @@ -1065,8 +1064,11 @@ public function render()
return NULL;
}

$template = $this->driver('get_template');
$template = $this->config('template_dir').$template;
if ($template == NULL)
{
$template = $this->driver('get_template');
$template = $this->config('template_dir').$template;
}

$view = View::factory($template)
->set('field', $this)
Expand Down Expand Up @@ -1481,4 +1483,4 @@ public function validation_errors( Kohana_Validation $validation)
}
}

}
}
37 changes: 34 additions & 3 deletions formo/upstream/classes/Formo/Core/Innards.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ protected function _load( array $array)
{
$field->driver('load', array('val' => $value));
}
elseif ($field->driver('can_be_empty') === TRUE)
elseif ($field->get('can_be_empty', $field->driver('can_be_empty')) === TRUE)
{
$field->val(null);
}
Expand Down Expand Up @@ -773,7 +773,7 @@ protected function _set_driver($driver)
*/
protected function _set_id( array & $array)
{
if ($this->config('auto_id') === TRUE AND empty($array['attr']['id']))
if ($this->config('auto_id') === TRUE AND Arr::path($array, 'attr.id') === NULL)
{
if (empty($array['attr']))
{
Expand Down Expand Up @@ -861,4 +861,35 @@ protected function _resolve_construct_aliases($array)

return $_array;
}
}

/**
* Validation method that properly validates for html5 range
*
* @access public
* @static
* @param mixed $field
* @param mixed $form
* @return boolean
*/
public static function range($field, $form)
{
$value = $form->$field->val();
$attr = $form->$field->get('attr');

$max = Arr::get($attr, 'max');
$min = Arr::get($attr, 'min');
$step = Arr::get($attr, 'step');

if ($min AND $value <= $min)
return FALSE;

if ($max AND $value >= $max)
return FALSE;

// Use the default step of 1
( ! $step AND $step = 1);

return strpos(($value - $min) / $step, '.') === FALSE;
}

}
6 changes: 3 additions & 3 deletions formo/upstream/config/formo.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
'month' => array(array('regex', array(':value', '/^\d{4}-(?:0[1-9]|1[0-2])$/'))),
'range' => array(
array('digit'),
array('Formo_Validator::range', array(':field', ':form')),
array('Formo::range', array(':field', ':form')),
),
'number' => array(
array('digit'),
array('Formo_Validator::range', array(':field', ':form')),
array('Formo::range', array(':field', ':form')),
),
),
);
);
4 changes: 2 additions & 2 deletions formo/upstream/views/formo_bootstrap/checkbox_template.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="field control-group formo-<?=$field->get('driver')?><?php if ($error = $field->error()) echo ' error'; ?>" id="field-container-<?=$field->alias()?>">
<label><?=$field->open().$field->html().$field->render_opts().$field->close()?> <span class="checkbox-label"><?=$field->label()?></span></label>
<label class="checkbox"><?=$field->open().$field->html().$field->render_opts().$field->close()?> <span class="checkbox-label"><?=$field->label()?></span></label>

<?php if ($msg = $field->error()): ?>
<span class="help-block"><?=$msg?></span>
<?php elseif ($msg = $field->get('message')): ?>
<span class="help-block"><?=$msg?></span>
<?php endif; ?>
</div>
</div>
6 changes: 3 additions & 3 deletions formo/upstream/views/formo_bootstrap/field_template.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="field control-group formo-<?=$field->get('driver')?><?php if ($error = $field->error()) echo ' error'; ?>" id="field-container-<?=$field->alias()?>">
<?php if ($label = $field->label()): ?>
<label for="<?=$field->attr('id')?>"><?=$label?></label>
<?php elseif ($title): ?>
<?php if ($title): ?>
<span class="title"><?=$title?></span>
<?php elseif ($label = $field->label()): ?>
<label for="<?=$field->attr('id')?>"><?=$label?></label>
<?php endif; ?>

<?=$field->open().$field->html().$field->render_opts().$field->close()?>
Expand Down

0 comments on commit f72ff94

Please sign in to comment.