Skip to content

Commit 552305c

Browse files
committed
getField, getDataField refactoring
1 parent 22ba15a commit 552305c

17 files changed

+121
-30
lines changed

Ajax/semantic/html/collections/HtmlMessage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Ajax\JsUtils;
99
use Ajax\semantic\html\base\constants\Style;
1010
use Ajax\semantic\html\base\traits\AttachedTrait;
11+
use Ajax\common\html\HtmlDoubleElement;
1112
/**
1213
* Semantic Message component
1314
* @see http://semantic-ui.com/collections/message.html
@@ -95,4 +96,11 @@ public function setStyle($style){
9596
public function setError(){
9697
return $this->setStyle("error");
9798
}
99+
100+
public function setMessage($message){
101+
if(\is_array($this->content)){
102+
$this->content[\sizeof($this->content)-1]=$message;
103+
}else
104+
$this->setContent($message);
105+
}
98106
}

Ajax/semantic/html/collections/form/HtmlFormDropdown.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ public function addItem($item,$value=NULL,$image=NULL){
2020
public static function multipleDropdown($identifier,$items=array(), $label=NULL,$value=NULL){
2121
return new HtmlFormDropdown($identifier,$items,$label,$value,true);
2222
}
23+
24+
public function getDataField(){
25+
return $this->getField()->getInput();
26+
}
2327
}

Ajax/semantic/html/collections/form/HtmlFormField.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
use Ajax\semantic\html\base\constants\Direction;
99
use Ajax\semantic\html\elements\HtmlLabel;
1010
use Ajax\semantic\components\validation\FieldValidation;
11+
use Ajax\semantic\html\collections\form\traits\FieldTrait;
1112

1213
class HtmlFormField extends HtmlSemDoubleElement {
14+
use FieldTrait;
1315
protected $_container;
1416
protected $_validation;
1517
public function __construct($identifier, $field,$label=NULL) {
@@ -124,6 +126,9 @@ public function addRule($type,$prompt=NULL,$value=NULL){
124126
if(!isset($this->_validation)){
125127
$this->_validation=new FieldValidation($field->getIdentifier());
126128
}
129+
if($type==="empty"){
130+
$this->addToProperty("class","required");
131+
}
127132
$this->_validation->addRule($type,$prompt,$value);
128133
}
129134
return $this;

Ajax/semantic/html/collections/form/HtmlFormFields.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public static function checkeds($name, $items=array(), $label=NULL, $values=arra
119119
foreach ( $items as $val => $caption ) {
120120
$itemO=new HtmlFormCheckbox($name."-".$i++, $name, $caption, $val, $type);
121121
if (\array_search($val, $values)!==false) {
122-
$itemO->getField()->getField()->setProperty("checked", "");
122+
//TODO check getField
123+
$itemO->getField()->getDataField()->setProperty("checked", "");
123124
}
124125
$fields[]=$itemO;
125126
}

Ajax/semantic/html/collections/form/HtmlFormInput.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
namespace Ajax\semantic\html\collections\form;
44

55
use Ajax\semantic\html\collections\form\traits\TextFieldsTrait;
6-
use Ajax\semantic\html\collections\form\traits\FieldTrait;
76
use Ajax\semantic\html\elements\HtmlInput;
87

98
class HtmlFormInput extends HtmlFormField {
10-
use TextFieldsTrait,FieldTrait;
9+
use TextFieldsTrait;
1110

1211
public function __construct($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL) {
1312
if(!isset($placeholder) && $type==="text")
@@ -17,8 +16,9 @@ public function __construct($identifier, $label=NULL,$type="text",$value=NULL,$p
1716

1817
public function getDataField(){
1918
$field= $this->getField();
19+
//TODO check getField
2020
if($field instanceof HtmlInput)
21-
$field=$field->getField();
21+
$field=$field->getDataField();
2222
return $field;
2323
}
2424
}

Ajax/semantic/html/collections/form/HtmlFormTextarea.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ public function setRows($count){
2626
public function getDataField() {
2727
return $this->content["field"];
2828
}
29+
30+
public function setName($name){
31+
$this->getDataField()->setProperty("name",$name);
32+
}
2933
}

Ajax/semantic/html/collections/form/traits/CheckboxTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getDataField(){
4545
$field= $this->getField();
4646
if($field instanceof AbstractCheckbox)
4747
$field=$field->getField();
48-
return $field;
48+
return $field;
4949
}
5050

5151
/**

Ajax/semantic/html/collections/form/traits/FieldTrait.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99

1010
trait FieldTrait {
1111

12-
public abstract function addToProperty($name, $value, $separator=" ");
13-
public abstract function addLabel($caption, $style="label-default", $leftSeparator=" ");
14-
public abstract function addContent($content,$before=false);
12+
abstract public function addToProperty($name, $value, $separator=" ");
13+
abstract public function addLabel($caption, $style="label-default", $leftSeparator=" ");
14+
abstract public function addContent($content,$before=false);
15+
abstract public function getField();
1516
public function setFocus() {
16-
$this->addToProperty("class", State::FOCUS);
17+
$this->getField()->addToProperty("class", State::FOCUS);
1718
}
1819

1920
public function addLoading() {
@@ -24,8 +25,9 @@ public function addLoading() {
2425
}
2526

2627
public function labeled($label, $direction=Direction::LEFT, $icon=NULL) {
27-
$labelO=$this->addLabel($label,$direction===Direction::LEFT,$icon);
28-
$this->addToProperty("class", $direction . " labeled");
28+
$field=$this->getField();
29+
$labelO=$field->addLabel($label,$direction===Direction::LEFT,$icon);
30+
$field->addToProperty("class", $direction . " labeled");
2931
return $labelO;
3032
}
3133

@@ -34,14 +36,15 @@ public function labeledToCorner($icon, $direction=Direction::LEFT) {
3436
}
3537

3638
public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false) {
39+
$field=$this->getField();
3740
$actionO=$action;
3841
if (\is_object($action) === false) {
3942
$actionO=new HtmlButton("action-" . $this->identifier, $action);
4043
if (isset($icon))
4144
$actionO->addIcon($icon, true, $labeled);
4245
}
43-
$this->addToProperty("class", $direction . " action");
44-
$this->addContent($actionO, \strstr($direction, Direction::LEFT) !== false);
46+
$field->addToProperty("class", $direction . " action");
47+
$field->addContent($actionO, \strstr($direction, Direction::LEFT) !== false);
4548
return $actionO;
4649
}
4750

@@ -52,11 +55,15 @@ public function addDropdown($label="", $items=array(),$direction=Direction::RIGH
5255
}
5356

5457
public function setTransparent() {
55-
return $this->addToProperty("class", "transparent");
58+
return $this->getField()->addToProperty("class", "transparent");
5659
}
5760

5861
public function setReadonly(){
5962
$this->getDataField()->setProperty("readonly", "");
6063
}
6164

65+
public function setName($name){
66+
$this->getDataField()->setProperty("name",$name);
67+
}
68+
6269
}

Ajax/semantic/html/collections/form/traits/TextFieldsTrait.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
trait TextFieldsTrait {
66

7-
public abstract function getDataField();
7+
abstract public function getDataField();
8+
abstract public function addToProperty($name, $value, $separator=" ");
89
public function setPlaceholder($value){
910
$this->getDataField()->setPlaceholder($value);
1011
return $this;
@@ -14,4 +15,11 @@ public function setValue($value){
1415
$this->getDataField()->setValue($value);
1516
return $this;
1617
}
18+
19+
public function setInputType($type){
20+
if($type==="hidden")
21+
$this->addToProperty("style","display:none;");
22+
$this->getDataField()->setInputType($type);
23+
return $this;
24+
}
1725
}

Ajax/semantic/html/elements/HtmlInput.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ public function __construct($identifier, $type="text", $value="", $placeholder="
2020
}
2121

2222
public function getField() {
23-
return $this->content["field"];
23+
return $this;
24+
//return $this->content["field"];
2425
}
2526

2627
public function getDataField() {
27-
return $this->getField();
28+
return $this->content["field"];
2829
}
2930

3031
public static function outline($identifier, $icon, $value="", $placeholder="") {

0 commit comments

Comments
 (0)