Skip to content

Commit 848ec54

Browse files
committed
fields reorganization
1 parent 49f42f1 commit 848ec54

File tree

6 files changed

+74
-60
lines changed

6 files changed

+74
-60
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function setName($_name) {
9595
return $this;
9696
}
9797

98+
9899
public static function radios($name, $items=array(), $label=NULL, $value=null, $type=NULL) {
99100
$fields=array ();
100101
$i=0;

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22

33
namespace Ajax\semantic\html\collections\form;
44

5+
use Ajax\common\html\html5\HtmlInput;
56
use Ajax\semantic\html\collections\form\traits\TextFieldsTrait;
6-
use Ajax\semantic\html\elements\HtmlInput;
7+
use Ajax\semantic\html\collections\form\traits\FieldTrait;
78

89
class HtmlFormInput extends HtmlFormField {
9-
use TextFieldsTrait;
10+
use TextFieldsTrait,FieldTrait;
1011

1112
public function __construct($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL) {
1213
if(!isset($placeholder) && $type==="text")
1314
$placeholder=$label;
1415
parent::__construct("field-".$identifier, new HtmlInput($identifier,$type,$value,$placeholder), $label);
1516
}
16-
17-
public function setReadonly(){
18-
$this->getField()->setProperty("readonly", "");
19-
}
2017
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public function setType($checkboxType) {
1212
return $this->getHtmlCk()->addToPropertyCtrl("class", $checkboxType, CheckboxType::getConstants());
1313
}
1414

15+
1516
/**
1617
* Attach $this to $selector and fire $action
1718
* @param string $selector jquery selector of the associated element
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Ajax\semantic\html\collections\form\traits;
4+
5+
use Ajax\semantic\html\modules\HtmlDropdown;
6+
use Ajax\semantic\html\elements\HtmlButton;
7+
use Ajax\semantic\html\base\constants\Direction;
8+
use Ajax\semantic\html\base\constants\State;
9+
10+
trait FieldTrait {
11+
12+
public abstract function addToProperty($name, $value, $separator=" ");
13+
public abstract function addLabel($caption, $style="label-default", $leftSeparator="&nbsp;");
14+
public abstract function addContent($content,$before=false);
15+
public function setFocus() {
16+
$this->addToProperty("class", State::FOCUS);
17+
}
18+
19+
public function addLoading() {
20+
if ($this->_hasIcon === false) {
21+
throw new \Exception("Input must have an icon for showing a loader, use addIcon before");
22+
}
23+
return $this->addToProperty("class", State::LOADING);
24+
}
25+
26+
public function labeled($label, $direction=Direction::LEFT, $icon=NULL) {
27+
$labelO=$this->addLabel($label,$direction===Direction::LEFT,$icon);
28+
$this->addToProperty("class", $direction . " labeled");
29+
return $labelO;
30+
}
31+
32+
public function labeledToCorner($icon, $direction=Direction::LEFT) {
33+
return $this->labeled("", $direction . " corner", $icon)->toCorner($direction);
34+
}
35+
36+
public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false) {
37+
$actionO=$action;
38+
if (\is_object($action) === false) {
39+
$actionO=new HtmlButton("action-" . $this->identifier, $action);
40+
if (isset($icon))
41+
$actionO->addIcon($icon, true, $labeled);
42+
}
43+
$this->addToProperty("class", $direction . " action");
44+
$this->addContent($actionO, \strstr($direction, Direction::LEFT) !== false);
45+
return $actionO;
46+
}
47+
48+
public function addDropdown($label="", $items=array(),$direction=Direction::RIGHT){
49+
$labelO=new HtmlDropdown("dd-".$this->identifier,$label,$items);
50+
$labelO->asSelect("select-".$this->identifier,false,true);
51+
return $this->labeled($labelO,$direction);
52+
}
53+
54+
public function setTransparent() {
55+
return $this->addToProperty("class", "transparent");
56+
}
57+
58+
public function setReadonly(){
59+
$this->getField()->setProperty("readonly", "");
60+
}
61+
62+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ trait TextFieldsTrait {
66

77
public abstract function getField();
88
public function setPlaceholder($value){
9-
return $this->getField()->setPlaceholder($value);
9+
$this->getField()->setPlaceholder($value);
10+
return $this;
1011
}
1112

1213
public function setValue($value){
13-
return $this->getField()->setValue($value);
14+
$this->getField()->setValue($value);
15+
return $this;
1416
}
1517
}

Ajax/semantic/html/elements/HtmlInput.php

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<?php
2-
32
namespace Ajax\semantic\html\elements;
43

54
use Ajax\semantic\html\base\HtmlSemDoubleElement;
65
use Ajax\semantic\html\base\constants\State;
7-
use Ajax\semantic\html\base\constants\Direction;
86
use Ajax\semantic\html\base\constants\Variation;
97
use Ajax\semantic\html\base\traits\IconTrait;
10-
use Ajax\semantic\html\modules\HtmlDropdown;
8+
use Ajax\semantic\html\collections\form\traits\TextFieldsTrait;
9+
use Ajax\semantic\html\collections\form\traits\FieldTrait;
1110

1211
class HtmlInput extends HtmlSemDoubleElement {
13-
use IconTrait;
12+
use IconTrait,TextFieldsTrait,FieldTrait;
1413

1514
public function __construct($identifier, $type="text", $value="", $placeholder="") {
1615
parent::__construct("div-" . $identifier, "div", "ui input");
@@ -19,58 +18,10 @@ public function __construct($identifier, $type="text", $value="", $placeholder="
1918
$this->_variations=[ Variation::TRANSPARENT ];
2019
}
2120

22-
public function setFocus() {
23-
$this->addToProperty("class", State::FOCUS);
24-
}
25-
26-
public function addLoading() {
27-
if ($this->_hasIcon === false) {
28-
throw new \Exception("Input must have an icon for showing a loader, use addIcon before");
29-
}
30-
return $this->addToProperty("class", State::LOADING);
31-
}
32-
33-
public function labeled($label, $direction=Direction::LEFT, $icon=NULL) {
34-
$labelO=$this->addLabel($label,$direction===Direction::LEFT,$icon);
35-
$this->addToProperty("class", $direction . " labeled");
36-
return $labelO;
37-
}
38-
39-
public function labeledToCorner($icon, $direction=Direction::LEFT) {
40-
return $this->labeled("", $direction . " corner", $icon)->toCorner($direction);
41-
}
42-
43-
public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false) {
44-
$actionO=$action;
45-
if (\is_object($action) === false) {
46-
$actionO=new HtmlButton("action-" . $this->identifier, $action);
47-
if (isset($icon))
48-
$actionO->addIcon($icon, true, $labeled);
49-
}
50-
$this->addToProperty("class", $direction . " action");
51-
$this->addContent($actionO, \strstr($direction, Direction::LEFT) !== false);
52-
return $actionO;
53-
}
54-
55-
public function addDropdown($label="", $items=array(),$direction=Direction::RIGHT){
56-
$labelO=new HtmlDropdown("dd-".$this->identifier,$label,$items);
57-
$labelO->asSelect("select-".$this->identifier,false,true);
58-
return $this->labeled($labelO,$direction);
59-
}
60-
6121
public function getField() {
6222
return $this->content["field"];
6323
}
6424

65-
public function setPlaceholder($value) {
66-
$this->getField()->setPlaceholder($value);
67-
return $this;
68-
}
69-
70-
public function setTransparent() {
71-
return $this->addToProperty("class", "transparent");
72-
}
73-
7425
public static function outline($identifier, $icon, $value="", $placeholder="") {
7526
$result=new HtmlInput($identifier, "text", $value, $placeholder);
7627
$result->addToProperty("class", "transparent");

0 commit comments

Comments
 (0)