1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\bootstrap\html; |
4
|
|
|
|
5
|
|
|
use Ajax\JsUtils; |
6
|
|
|
use Ajax\bootstrap\html\base\HtmlBsDoubleElement; |
7
|
|
|
use Ajax\bootstrap\html\base\CssRef; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Twitter Bootstrap HTML Inputgroup component |
11
|
|
|
* @author jc |
12
|
|
|
* @version 1.001 |
13
|
|
|
*/ |
14
|
|
|
class HtmlInputgroup extends HtmlInput { |
15
|
|
|
protected $addonLeft=null; |
16
|
|
|
protected $addonRight=null; |
17
|
|
|
protected $mClass="input-group"; |
18
|
|
|
|
19
|
|
|
public function __construct($identifier) { |
20
|
|
|
parent::__construct($identifier); |
21
|
|
|
$this->_template=include 'templates/tplInputgroup.php'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function createSpan($text, $position="left") { |
25
|
|
|
$id=$position."-".$this->identifier; |
26
|
|
|
$span=new HtmlBsDoubleElement($id); |
27
|
|
|
$span->setTagName("span"); |
28
|
|
|
$this->setProperty("aria-describedby", $id); |
29
|
|
|
$span->setContent($text); |
30
|
|
|
$span->setClass("input-group-addon"); |
31
|
|
|
if (strtolower($position)==="left") |
32
|
|
|
$this->addonLeft=$span; |
33
|
|
|
else |
34
|
|
|
$this->addonRight=$span; |
35
|
|
|
return $span; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function addInput_($input, $label="", $position="left") { |
39
|
|
|
$span=$this->createSpan("", $position); |
40
|
|
|
$span->setClass("input-group-addon"); |
41
|
|
|
$input->setProperty("aria-label", $label); |
42
|
|
|
$span->setContent($input); |
43
|
|
|
return $span; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function addButton_($button, $value="", $position="left") { |
47
|
|
|
$span=$this->createSpan("", $position); |
48
|
|
|
$span->setClass("input-group-btn"); |
49
|
|
|
$span->setTagName("div"); |
50
|
|
|
$button->setValue($value); |
51
|
|
|
$span->setContent($button); |
52
|
|
|
return $span; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function createRadio($identifier, $label="", $position="left") { |
56
|
|
|
return $this->addInput_(new HtmlInputRadio($identifier), $label, $position); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function createCheckbox($identifier, $label="", $position="left") { |
60
|
|
|
return $this->addInput_(new HtmlInputCheckbox($identifier), $label, $position); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function createButton($identifier, $value="", $position="left") { |
64
|
|
|
return $this->addButton_(new HtmlButton($identifier), $value, $position); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function createButtons($items, $position="left") { |
68
|
|
|
$span=$this->createSpan("", $position); |
69
|
|
|
$span->setClass("input-group-btn"); |
70
|
|
|
$span->setTagName("div"); |
71
|
|
|
$buttons=array(); |
72
|
|
|
$i=1; |
73
|
|
|
foreach ($items as $item){ |
74
|
|
|
$bt=NULL; |
75
|
|
|
if(is_string($item)){ |
76
|
|
|
$bt=new HtmlButton($this->identifier."-bt-".$i++,$item); |
77
|
|
|
}elseif ($item instanceof HtmlButton){ |
78
|
|
|
$bt=$item; |
79
|
|
|
} |
80
|
|
|
if(isset($bt)){ |
81
|
|
|
$buttons[]=$bt; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
$span->setContent($buttons); |
85
|
|
|
return $span; |
86
|
|
|
} |
87
|
|
|
protected function addDropdown_(HtmlDropdown $dropdown, $caption="", $position="left", $items=array()) { |
88
|
|
|
$dropdown->setBtnCaption($caption); |
89
|
|
|
$dropdown->fromArray($items); |
90
|
|
|
|
91
|
|
|
if (strtolower($position)==="left") |
92
|
|
|
$this->addonLeft=$dropdown; |
93
|
|
|
else |
94
|
|
|
$this->addonRight=$dropdown; |
95
|
|
|
return $dropdown; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
View Code Duplication |
public function createDropdown($identifier, $caption="", $position="left", $items=array()) { |
|
|
|
|
99
|
|
|
$dropdown=new HtmlDropdown($identifier); |
100
|
|
|
$dropdown->setMTagName("div"); |
101
|
|
|
$dropdown->setTagName("button"); |
102
|
|
|
$dropdown->setMClass("input-group-btn"); |
103
|
|
|
return $this->addDropdown_($dropdown, $caption, $position, $items); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
View Code Duplication |
public function createSplitButton($identifier, $caption="", $position="left", $items=array()) { |
|
|
|
|
107
|
|
|
$dropdown=new HtmlSplitbutton($identifier); |
108
|
|
|
$dropdown->setTagName("button"); |
109
|
|
|
$dropdown->setMClass("input-group-btn"); |
110
|
|
|
$dropdown->setMTagName("div"); |
111
|
|
|
return $this->addDropdown_($dropdown, $caption, $position, $items); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* define the elements size |
116
|
|
|
* available values : "input-group-lg","","input-group-sm","input-group-xs" |
117
|
|
|
* @param string|int $size |
118
|
|
|
* @return \Ajax\bootstrap\html\HtmlInputgroup default : "" |
119
|
|
|
*/ |
120
|
|
|
public function setSize($size) { |
121
|
|
|
if (is_int($size)) { |
122
|
|
|
return $this->addToMemberCtrl($this->mClass, CssRef::sizes("input-group")[$size],CssRef::sizes("input-group")); |
123
|
|
|
} |
124
|
|
|
return $this->addToMemberCtrl($this->mClass, $size, CssRef::sizes("input-group")); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function run(JsUtils $js) { |
128
|
|
|
parent::run($js); |
129
|
|
|
if (isset($this->addonLeft)) |
130
|
|
|
$this->addonLeft->run($js); |
131
|
|
|
if (isset($this->addonRight)) |
132
|
|
|
$this->addonRight->run($js); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.