phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
FieldTrait.php
Go to the documentation of this file.
1 <?php
2 
4 
13 
14 
20 trait FieldTrait {
21 
22  abstract public function addToProperty($name, $value, $separator=" ");
23  abstract public function addLabel($caption, $style="label-default", $leftSeparator="&nbsp;");
24  abstract public function addContent($content,$before=false);
25  abstract public function getField();
26  abstract public function getDataField();
27 
28  public function setFocus() {
29  $this->getField()->addToProperty("class", State::FOCUS);
30  }
31 
32  public function addLoading() {
33  if ($this->_hasIcon === false) {
34  throw new \Exception("Input must have an icon for showing a loader, use addIcon before");
35  }
36  return $this->addToProperty("class", State::LOADING);
37  }
38 
45  public function labeled($label, $direction=Direction::LEFT, $icon=NULL) {
46  $field=$this->getField();
47  $labelO=$field->addLabel($label,$direction===Direction::LEFT,$icon);
48  $field->addToProperty("class", $direction . " labeled");
49  return $labelO;
50  }
51 
59  public function labeledCheckbox($direction=Direction::LEFT,$caption="",$value=NULL,$checkboxType=NULL){
60  return $this->labeled(new HtmlCheckbox("lbl-ck-".$this->getField()->getIdentifier(),$caption,$value,$checkboxType),$direction);
61  }
62 
68  public function labeledToCorner($icon, $direction=Direction::LEFT) {
69  return $this->labeled("", $direction . " corner", $icon)->toCorner($direction);
70  }
71 
79  public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false) {
80  $field=$this->getField();
81  $actionO=$action;
82  if (\is_object($action) === false) {
83  $actionO=new HtmlButton("action-" . $this->identifier, $action);
84  if (isset($icon))
85  $actionO->addIcon($icon, true, $labeled);
86  }
87  $field->addToProperty("class", $direction . " action");
88  $field->addContent($actionO, \strstr($direction, Direction::LEFT) !== false);
89  return $actionO;
90  }
91 
98  public function addDropdown($label="", $items=array(),$direction=Direction::RIGHT){
99  $labelO=new HtmlDropdown("dd-".$this->identifier,$label,$items);
100  $labelO->asSelect("select-".$this->identifier,false,true);
101  return $this->labeled($labelO,$direction);
102  }
103 
104  public function setTransparent() {
105  return $this->getField()->addToProperty("class", "transparent");
106  }
107 
108  public function setReadonly(){
109  $this->getDataField()->setProperty("readonly", "");
110  return $this;
111  }
112 
113  public function setName($name){
114  $this->getDataField()->setProperty("name",$name);
115  return $this;
116  }
117 
118  public function setFluid(){
119  $this->getField()->addToProperty("class","fluid");
120  return $this;
121  }
122 
123  public function setDisabled($disable=true) {
124  $field=$this->getField();
125  if($disable)
126  $field->addToProperty("class", "disabled");
127  return $this;
128  }
129 
130  public function setJsContent($content){
131  $id="";
132  $field=$this->getDataField();
133  if(isset($field)){
134  $id=$field->getIdentifier();
135  }
136  if($id!==''){
137  return '$("#'.$id.'").val('.$content.')';
138  }
139  }
140 
141  public function getJsContent(){
142  return $this->setJsContent("");
143  }
144 
145  public function asFile($caption='', $direction=Direction::RIGHT, $icon='cloud upload alternate', $labeled=false){
146  $field=$this->getField();
147  $field->getDataField()->setProperty('readonly', 'readonly');
148  $file=new HtmlInput5($this->identifier.'-file','file');
149  $file->setProperty('style','display: none!important;');
150  $field->getField()->content['file']=$file;
151  $this->addAction($caption,$direction,$icon,$labeled);
152  }
153 }
asFile($caption='', $direction=Direction::RIGHT, $icon='cloud upload alternate', $labeled=false)
Definition: FieldTrait.php:145
labeled($label, $direction=Direction::LEFT, $icon=NULL)
Definition: FieldTrait.php:45
addLabel($caption, $style="label-default", $leftSeparator="&nbsp;")
Semantic Button component.
Definition: HtmlButton.php:18
addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false)
Definition: FieldTrait.php:79
addDropdown($identifier, $items=array(), $label=NULL, $value=NULL, $multiple=false)
Adds a new dropdown element.
labeledToCorner($icon, $direction=Direction::LEFT)
Definition: FieldTrait.php:68
labeledCheckbox($direction=Direction::LEFT, $caption="", $value=NULL, $checkboxType=NULL)
Definition: FieldTrait.php:59