2013-04-25 00:22:36 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class extends Kohana's HTML
|
|
|
|
*
|
2013-10-08 23:24:11 +00:00
|
|
|
* @package lnApp
|
|
|
|
* @category Modifications
|
2013-04-25 00:22:36 +00:00
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
|
|
|
abstract class lnApp_Form extends Kohana_Form {
|
|
|
|
/**
|
|
|
|
* Render our control group form attributes
|
|
|
|
*
|
|
|
|
* @return array((string) control group wrapper,(array) attributes to exclude
|
|
|
|
*/
|
|
|
|
private static function _controlgroup($name,array &$attributes=NULL) {
|
|
|
|
if (isset($attributes['nocg'])) {
|
|
|
|
unset($attributes['nocg']);
|
|
|
|
return '%s';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
$output .= '<div class="control-group">';
|
|
|
|
|
|
|
|
if (isset($attributes['label'])) {
|
|
|
|
$output .= Form::label($name,$attributes['label'],array('class'=>'control-label'));
|
|
|
|
unset($attributes['label']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($attributes['help-block'])) {
|
|
|
|
$help = $attributes['help-block'];
|
|
|
|
unset($attributes['help-block']);
|
|
|
|
}
|
|
|
|
|
2013-06-20 05:55:47 +00:00
|
|
|
if (isset($attributes['add-on'])) {
|
|
|
|
$addon = $attributes['add-on'];
|
|
|
|
unset($attributes['add-on']);
|
|
|
|
}
|
|
|
|
|
2013-04-25 00:22:36 +00:00
|
|
|
$output .= '<div class="controls">';
|
|
|
|
$output .= '%s';
|
|
|
|
|
|
|
|
if (isset($help))
|
|
|
|
$output .= sprintf('<span class="help-block">%s</span>',$help);
|
|
|
|
|
2013-06-20 05:55:47 +00:00
|
|
|
if (isset($addon))
|
|
|
|
$output .= sprintf('<span class="add-on">%s</span>',$addon);
|
|
|
|
|
2013-04-25 00:22:36 +00:00
|
|
|
$output .= '</div>';
|
|
|
|
$output .= '</div>';
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2013-05-14 13:55:30 +00:00
|
|
|
public static function button($name,$body,array $attributes=NULL) {
|
|
|
|
return sprintf(static::_controlgroup($name,$attributes),parent::button($name,$body,$attributes));
|
|
|
|
}
|
|
|
|
|
2013-04-25 00:22:36 +00:00
|
|
|
/**
|
|
|
|
* Wrap our Form() functions with boostrap HTML
|
|
|
|
*
|
|
|
|
* @usedby Form::hidden
|
|
|
|
* @usedby Form::password
|
|
|
|
* @usedby Form::file
|
|
|
|
* @usedby Form::checkbox
|
|
|
|
* @usedby Form::radio
|
|
|
|
* @usedby Form::submit
|
|
|
|
* @usedby Form::image
|
|
|
|
*/
|
|
|
|
public static function input($name,$value=NULL,array $attributes=NULL) {
|
2013-06-20 05:55:47 +00:00
|
|
|
return (isset($attributes['type']) AND $attributes['type'] == 'hidden') ? parent::input($name,$value,$attributes) : sprintf(static::_controlgroup($name,$attributes),parent::input($name,$value,$attributes));
|
2013-04-25 00:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function select($name,array $options=NULL,$selected=NULL,array $attributes=NULL) {
|
|
|
|
// If only 1 record, dont show select, but a hidden attribute and a displayed value.
|
|
|
|
if (isset($attributes['oneonly']) AND $attributes['oneonly']) {
|
|
|
|
$attributes['disabled'] = 'disabled';
|
|
|
|
unset($attributes['oneonly']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(static::_controlgroup($name,$attributes),parent::select($name,$options,$selected,$attributes));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function textarea($name,$body='',array $attributes=NULL,$double_encode=TRUE) {
|
|
|
|
if (! isset($attributes['id']))
|
|
|
|
$attributes['id'] = preg_replace('/[\[\]]/','_',$name);
|
|
|
|
|
2013-09-04 12:51:01 +00:00
|
|
|
if (! isset($attributes['nowysihtml']))
|
|
|
|
Script::factory()
|
|
|
|
->type('stdin')
|
|
|
|
->data('$("#'.$attributes['id'].'").wysihtml5();');
|
|
|
|
else
|
|
|
|
unset($attributes['wysihtml']);
|
2013-04-25 00:22:36 +00:00
|
|
|
|
|
|
|
return sprintf(static::_controlgroup($name,$attributes),parent::textarea($name,$body,$attributes,$double_encode));
|
|
|
|
}
|
2013-11-08 11:26:58 +00:00
|
|
|
|
|
|
|
public static function textarea_rows($textarea,$min=10,$char="\n") {
|
|
|
|
return ($x=count(explode($char,$textarea))) < $min ? $min : $x;
|
|
|
|
}
|
2013-04-25 00:22:36 +00:00
|
|
|
}
|
|
|
|
?>
|