1 <?php
2 3 4 5 6 7
8
9 namespace Hawk;
10
11 12 13 14 15
16 class ButtonInput extends FormInput{
17
18 const TYPE = "button";
19
20 const INDEPENDANT = true;
21
22 23 24 25 26
27 private static $defaultIcons = array(
28 'valid' => 'save',
29 'save' => 'save',
30 'cancel' => 'ban',
31 'close' => 'times',
32 'delete' => 'times',
33 'back' => 'reply',
34 'next' => 'step-forward',
35 'previous' => 'step-backward',
36 'send' => 'mail-closed'
37 );
38
39 40 41 42 43
44 public $nl = false;
45
46 47 48 49 50
51 public function display(){
52 if(!empty($this->notDisplayed)) {
53 return '';
54 }
55
56 $param = get_object_vars($this);
57 $param["class"] .= " form-button";
58 if(empty($param['icon']) && isset(self::$defaultIcons[$this->name]))
59 $param['icon'] = self::$defaultIcons[$this->name];
60
61 $param = array_filter(
62 $param, function ($v) {
63 return !empty($v);
64 }
65 );
66
67 if(!isset($param['label'])) {
68 $param['label'] = $this->value;
69 }
70 $param['type'] = static::TYPE;
71
72 $param = array_intersect_key($param, array_flip(array('id', 'class', 'icon', 'label', 'type', 'name', 'onclick', 'style', 'href', 'target', 'title')));
73 $param = array_merge($param, $this->attributes);
74
75
76 if(!preg_match("!\bbtn-\w+\b!", $param['class'])) {
77 $param['class'] .= " btn-default";
78 }
79
80
81 $param = array_map(
82 function ($v) {
83 return htmlentities($v, ENT_QUOTES);
84 }, $param
85 );
86
87 return View::make(
88 Theme::getSelected()->getView('button.tpl'), array(
89 'class' => isset($param['class']) ? $param['class'] : '',
90 'param' => $param,
91 'icon' => isset($param['icon']) ? $param['icon'] : '',
92 'label' => isset($param['label']) ? $param['label'] : '',
93 'textStyle' => isset($param['textStyle']) ? $param['textStyle'] : '',
94 )
95 );
96 }
97
98
99 100 101 102 103 104 105
106 public function check(&$form = null){
107 return true;
108 }
109 }
110