Skip to content

Commit 411df4d

Browse files
committed
Behaviors...
1 parent 141d555 commit 411df4d

20 files changed

+454
-52
lines changed

Ajax/Semantic.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
namespace Ajax;
44

55
use Ajax\common\BaseGui;
6-
use Ajax\semantic\html\collections\menus\HtmlMenu;
76
use Ajax\semantic\html\modules\HtmlDropdown;
8-
use Ajax\semantic\html\collections\HtmlMessage;
97
use Ajax\semantic\html\modules\HtmlPopup;
108
use Ajax\common\html\BaseHtml;
11-
use Ajax\semantic\html\collections\HtmlGrid;
129
use Ajax\semantic\html\collections\menus\HtmlIconMenu;
1310
use Ajax\semantic\html\collections\menus\HtmlLabeledIconMenu;
1411
use Ajax\semantic\html\collections\HtmlBreadcrumb;
1512
use Ajax\semantic\html\modules\HtmlAccordion;
1613
use Ajax\semantic\components\Accordion;
1714
use Ajax\semantic\html\collections\menus\HtmlAccordionMenu;
18-
use Ajax\semantic\html\collections\form\HtmlForm;
1915
use Ajax\semantic\traits\SemanticComponentsTrait;
2016
use Ajax\semantic\traits\SemanticHtmlElementsTrait;
2117
use Ajax\semantic\html\modules\HtmlSticky;
@@ -31,15 +27,6 @@ public function __construct($autoCompile=true) {
3127
parent::__construct($autoCompile=true);
3228
}
3329

34-
/**
35-
*
36-
* @param string $identifier
37-
* @param array $items
38-
* @return Ajax\semantic\html\collections\HtmlMenu
39-
*/
40-
public function htmlMenu($identifier, $items=array()) {
41-
return $this->addHtmlComponent(new HtmlMenu($identifier, $items));
42-
}
4330

4431
/**
4532
* Adds an icon menu
@@ -69,16 +56,6 @@ public function htmlDropdown($identifier, $value="", $items=array()) {
6956
return $this->addHtmlComponent(new HtmlDropdown($identifier, $value, $items));
7057
}
7158

72-
/**
73-
* Adds a new message
74-
* @param string $identifier
75-
* @param string $content
76-
* @return HtmlMessage
77-
*/
78-
public function htmlMessage($identifier, $content="") {
79-
return $this->addHtmlComponent(new HtmlMessage($identifier, $content));
80-
}
81-
8259
/**
8360
*
8461
* @param string $identifier
@@ -89,19 +66,6 @@ public function htmlPopup(BaseHtml $container, $identifier, $content) {
8966
return $this->addHtmlComponent(new HtmlPopup($container, $identifier, $content));
9067
}
9168

92-
/**
93-
*
94-
* @param string $identifier
95-
* @param int $numRows
96-
* @param int $numCols
97-
* @param boolean $createCols
98-
* @param boolean $implicitRows
99-
* @return HtmlGrid
100-
*/
101-
public function htmlGrid($identifier, $numRows=1, $numCols=NULL, $createCols=true, $implicitRows=false) {
102-
return $this->addHtmlComponent(new HtmlGrid($identifier, $numRows, $numCols, $createCols, $implicitRows));
103-
}
104-
10569
/**
10670
* Returns a new Semantic Html Breadcrumb
10771
* @param string $identifier
@@ -132,15 +96,6 @@ public function htmlAccordionMenu($identifier, $items=array()) {
13296
return $this->addHtmlComponent(new HtmlAccordionMenu($identifier, $items));
13397
}
13498

135-
/**
136-
* Returns a new Semantic Form
137-
* @param string $identifier
138-
* @param array $elements
139-
* @return HtmlForm
140-
*/
141-
public function htmlForm($identifier, $elements=array()) {
142-
return $this->addHtmlComponent(new HtmlForm($identifier, $elements));
143-
}
14499

145100
/**
146101
* Returns a new Semantic Sticky

Ajax/common/components/BaseComponent.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,12 @@ public function setParams($params) {
8181
return $this;
8282
}
8383

84+
public function addParams($params){
85+
foreach ($params as $k=>$v){
86+
$this->setParam($k, $v);
87+
}
88+
return $this;
89+
}
90+
8491
abstract public function getScript();
8592
}

Ajax/common/html/BaseHtml.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,25 @@ public function setClick($jsCode) {
298298
return $this->onClick($jsCode);
299299
}
300300

301+
public function onCreate($jsCode){
302+
if(isset($this->_events["_create"])){
303+
$this->_events["_create"][]=$jsCode;
304+
}else{
305+
$this->_events["_create"]=[$jsCode];
306+
}
307+
return $this;
308+
}
309+
301310
public function addEventsOnRun(JsUtils $js) {
311+
if(isset($this->_events["_create"])){
312+
$create=$this->_events["_create"];
313+
if(\is_array($create)){
314+
$create=\implode("", $create);
315+
}
316+
if($create!=="")
317+
$js->exec($create,true);
318+
unset($this->_events["_create"]);
319+
}
302320
if (isset($this->_bsComponent)) {
303321
foreach ( $this->_events as $event => $jsCode ) {
304322
$code=$jsCode;

Ajax/semantic/components/Form.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
namespace Ajax\semantic\components;
3+
4+
use Ajax\common\components\SimpleExtComponent;
5+
use Ajax\JsUtils;
6+
use Ajax\semantic\components\validation\FieldValidation;
7+
use Ajax\semantic\components\validation\Rule;
8+
/**
9+
* @author jc
10+
* @version 1.001
11+
* Generates a JSON form validation string
12+
*/
13+
class Form extends SimpleExtComponent {
14+
15+
/**
16+
* @var array
17+
*/
18+
public function __construct(JsUtils $js=null) {
19+
parent::__construct($js);
20+
$this->uiName="form";
21+
$this->params["fields"]=[];
22+
}
23+
24+
public function addField($identifier){
25+
$this->params["fields"][$identifier]=new FieldValidation($identifier);
26+
}
27+
28+
public function setInline($value){
29+
return $this->setParam("inline", true);
30+
}
31+
32+
public function setOn($value){
33+
return $this->setParam("on", $value);
34+
}
35+
36+
37+
38+
/**
39+
* @param string $identifier
40+
* @param Rule|string $type
41+
* @param mixed $value
42+
* @param string|NULL $prompt
43+
*/
44+
public function addFieldRule($identifier,$type,$prompt=NULL,$value=NULL){
45+
if(isset($this->params["fields"][$identifier])===false){
46+
$this->addField($identifier);
47+
}
48+
$this->params["fields"][$identifier]->addRule($type,$prompt,$value);
49+
}
50+
51+
/**
52+
* @param FieldValidation $fieldValidation
53+
*/
54+
public function addFieldValidation($fieldValidation){
55+
$this->params["fields"][$fieldValidation->getIdentifier()]=$fieldValidation;
56+
}
57+
58+
public function setJs(JsUtils $js){
59+
$this->js=$js;
60+
}
61+
62+
public function getScript() {
63+
$allParams=$this->params;
64+
$this->jquery_code_for_compile=array ();
65+
$this->jquery_code_for_compile []="$( \"".$this->attachTo."\" ).{$this->uiName}(".$this->getParamsAsJSON($allParams).");";
66+
$this->compileEvents();
67+
return $this->compileJQueryCode();
68+
}
69+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
namespace Ajax\semantic\components\validation;
3+
/**
4+
* @author jc
5+
* @version 1.001
6+
* Generates a JSON field validator
7+
*/
8+
class FieldValidation implements \JsonSerializable{
9+
/**
10+
* @var string
11+
*/
12+
protected $identifier;
13+
/**
14+
* @var array array of Rules
15+
*/
16+
protected $rules;
17+
18+
/**
19+
* @var string
20+
*/
21+
protected $depends;
22+
23+
protected $optional;
24+
25+
public function __construct($identifier){
26+
$this->identifier=$identifier;
27+
$this->rules=[];
28+
}
29+
30+
public function getIdentifier() {
31+
return $this->identifier;
32+
}
33+
34+
public function setIdentifier($identifier) {
35+
$this->identifier=$identifier;
36+
return $this;
37+
}
38+
39+
public function getRules() {
40+
return $this->rules;
41+
}
42+
43+
public function addRule($type,$prompt=NULL,$value=NULL){
44+
if($type instanceof Rule)
45+
$this->rules[]=$type;
46+
else
47+
$this->rules[]=new Rule($type,$prompt,$value);
48+
}
49+
50+
public function jsonSerialize(){
51+
return ["identifier"=>$this->identifier,"rules"=>$this->rules];
52+
}
53+
54+
public function setDepends($depends) {
55+
$this->depends=$depends;
56+
return $this;
57+
}
58+
59+
public function setOptional($optional) {
60+
$this->optional=$optional;
61+
return $this;
62+
}
63+
64+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
namespace Ajax\semantic\components\validation;
3+
/**
4+
* @author jc
5+
* @version 1.001
6+
* Generates a JSON Rule for the validation of a field
7+
*/
8+
class Rule implements \JsonSerializable{
9+
/**
10+
* @var string
11+
*/
12+
private $type;
13+
/**
14+
* @var string
15+
*/
16+
private $prompt;
17+
18+
/**
19+
* @var string
20+
*/
21+
private $value;
22+
23+
public function __construct($type,$prompt=NULL,$value=NULL){
24+
$this->type=$type;
25+
$this->prompt=$prompt;
26+
$this->value=$value;
27+
}
28+
29+
public function getType() {
30+
return $this->type;
31+
}
32+
33+
public function setType($type) {
34+
$this->type=$type;
35+
return $this;
36+
}
37+
38+
public function getPrompt() {
39+
return $this->prompt;
40+
}
41+
42+
public function setPrompt($prompt) {
43+
$this->prompt=$prompt;
44+
return $this;
45+
}
46+
47+
public function getValue() {
48+
return $this->value;
49+
}
50+
51+
public function setValue($value) {
52+
$this->value=$value;
53+
return $this;
54+
}
55+
56+
public function jsonSerialize() {
57+
$result= ["type"=>$this->type];
58+
if(isset($this->prompt))
59+
$result["prompt"]=$this->prompt;
60+
if(isset($this->value))
61+
$result["value"]=$this->value;
62+
return $result;
63+
}
64+
65+
public static function match($name,$prompt=null){
66+
return new Rule("match[".$name."]",$prompt);
67+
}
68+
69+
public static function integer($min=0,$max=100,$prompt=null){
70+
return new Rule("integer[{$min}..{$max}]",$prompt);
71+
}
72+
73+
public static function decimal($prompt=null){
74+
return new Rule("decimal]",$prompt);
75+
}
76+
77+
public static function number($prompt=null){
78+
return new Rule("number",$prompt);
79+
}
80+
81+
}

Ajax/semantic/html/base/HtmlSemDoubleElement.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class HtmlSemDoubleElement extends HtmlDoubleElement {
2121
use BaseTrait;
2222
protected $_popup=NULL;
2323
protected $_dimmer=NULL;
24+
protected $_params=array ();
25+
2426

2527
public function __construct($identifier, $tagName="p", $baseClass="ui", $content=NULL) {
2628
parent::__construct($identifier, $tagName);
@@ -107,6 +109,7 @@ public function run(JsUtils $js) {
107109
}
108110
return $this->_bsComponent;
109111
}
112+
110113
/*
111114
* public function __call($name, $arguments){
112115
* $type=\substr($name, 0,3);

Ajax/semantic/html/base/traits/BaseTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public function addIcon($icon, $before=true) {
8686
return $this->addContent(new HtmlIcon("icon-" . $this->identifier, $icon), $before);
8787
}
8888

89+
public function addSticky($context="body"){
90+
$this->onCreate("$('#".$this->identifier."').sticky({ context: '".$context."'});");
91+
return $this;
92+
}
93+
8994
/**
9095
*
9196
* {@inheritDoc}

Ajax/semantic/html/collections/HtmlMessage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public function setStyle($style){
8686
return $this->addToPropertyCtrl("class", $style, Style::getConstants());
8787
}
8888

89+
public function setError(){
90+
return $this->setStyle("error");
91+
}
92+
8993
public function setAttached(HtmlDoubleElement $toElement=NULL){
9094
if(isset($toElement)){
9195
$toElement->addToProperty("class", "attached");

0 commit comments

Comments
 (0)