Skip to content

Commit 92bd719

Browse files
committed
FormAccount widget added
1 parent fda645f commit 92bd719

File tree

10 files changed

+124
-17
lines changed

10 files changed

+124
-17
lines changed

Ajax/semantic/components/Popup.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ public function setInline($value){
5151
public function setPosition($value){
5252
return $this->setParam("position", $value);
5353
}
54+
55+
public function setSetFluidWidth($value){
56+
return $this->setParam("setFluidWidth", $value);
57+
}
5458
}

Ajax/semantic/html/base/constants/Social.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
namespace Ajax\semantic\html\base\constants;
33
use Ajax\common\BaseEnum;
44
abstract class Social extends BaseEnum {
5-
const FACEBOOK="facebook", TWITTER="twitter",GOOGLEPLUS="google plus",VK="vk",LINKEDIN="linkedin",INSTAGRAM="instagram",YOUTUBE="youtube";
5+
const FACEBOOK="facebook", TWITTER="twitter",GOOGLEPLUS="google plus",VK="vk",LINKEDIN="linkedin",INSTAGRAM="instagram",YOUTUBE="youtube",GITHUB="github";
66
}

Ajax/semantic/html/elements/HtmlButton.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class HtmlButton extends HtmlSemDoubleElement {
2525
* @param string $cssStyle btn-default, btn-primary...
2626
* @param string $onClick JS Code for click event
2727
*/
28-
public function __construct($identifier, $value="", $cssStyle=null, $onClick=null) {
28+
public function __construct($identifier, $value=null, $cssStyle=null, $onClick=null) {
2929
parent::__construct($identifier, "button", "ui button");
3030
$this->content=$value;
3131
if (isset($cssStyle)) {
@@ -109,7 +109,11 @@ public function addLabel($label, $before=false, $icon=NULL) {
109109
if($before)
110110
$prefix="left ";
111111
$this->addToProperty("class", $prefix."labeled");
112+
$isIcon=(isset($this->content[0]) && $this->content[0] instanceof HtmlIcon);
112113
$this->content=new HtmlButton("button-" . $this->identifier, $this->content);
114+
if($isIcon){
115+
$this->content->addClass("icon");
116+
}
113117
$this->content->setTagName("div");
114118
$label=new HtmlLabel("label-" . $this->identifier, $label, $icon,"a");
115119
$label->setBasic();
@@ -236,8 +240,9 @@ public static function icon($identifier, $icon) {
236240
* @see HtmlSemDoubleElement::asLink()
237241
*/
238242
public function asLink($href=NULL,$target=NULL) {
239-
$lnk=new HtmlLink("lnk-".$this->identifier,$href,$this->content,$target);
240-
$this->content=$lnk;
243+
parent::asLink($href,$target);
244+
/*$lnk=new HtmlLink("lnk-".$this->identifier,$href,$this->content,$target);
245+
$this->content=$lnk;*/
241246
return $this;
242247
}
243248
}

Ajax/semantic/html/modules/HtmlDropdown.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ public function __construct($identifier, $value="", $items=array(),$associative=
3030
$this->setProperty("class", "ui dropdown");
3131
$content=[];
3232
if(isset($value)){
33-
$text=new HtmlSemDoubleElement("text-".$this->identifier,"div");
34-
$text->setClass("text");
33+
if($value instanceof HtmlSemDoubleElement){
34+
$text=$value;
35+
}else{
36+
$text=new HtmlSemDoubleElement("text-".$this->identifier,"div");
37+
$text->setClass("text");
38+
$this->setValue($value);
39+
}
3540
$content=[$text];
36-
$this->setValue($value);
3741
}
3842
$content["arrow"]=new HtmlIcon("", "dropdown");
3943
$this->content=$content;

Ajax/semantic/traits/SemanticHtmlCollectionsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function htmlMessage($identifier, $content="",$styles=NULL) {
4343
*
4444
* @param string $identifier
4545
* @param array $items
46-
* @return Ajax\semantic\html\collections\HtmlMenu
46+
* @return HtmlMenu
4747
*/
4848
public function htmlMenu($identifier, $items=array()) {
4949
return $this->addHtmlComponent(new HtmlMenu($identifier, $items));

Ajax/semantic/traits/SemanticHtmlElementsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function addState($state, $elements) {
4141
* @param string $onClick
4242
* @return HtmlButton
4343
*/
44-
public function htmlButton($identifier, $value="", $cssStyle=null, $onClick=null) {
44+
public function htmlButton($identifier, $value=null, $cssStyle=null, $onClick=null) {
4545
return $this->addHtmlComponent(new HtmlButton($identifier, $value, $cssStyle, $onClick));
4646
}
4747

Ajax/semantic/traits/SemanticWidgetsTrait.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Ajax\semantic\widgets\dataform\DataForm;
77
use Ajax\semantic\widgets\business\user\FormLogin;
88
use Ajax\semantic\widgets\datatable\JsonDataTable;
9+
use Ajax\semantic\widgets\business\user\FormAccount;
910

1011
trait SemanticWidgetsTrait {
1112

@@ -49,15 +50,39 @@ public function dataForm($identifier, $instance){
4950
return $this->addHtmlComponent(new DataForm($identifier,$instance));
5051
}
5152

53+
/**
54+
* @param string $identifier
55+
* @param object $instance
56+
* @return FormLogin
57+
*/
5258
public function defaultLogin($identifier,$instance=null){
5359
return $this->addHtmlComponent(FormLogin::regular($identifier,$instance));
5460
}
5561

62+
/**
63+
* @param string $identifier
64+
* @param object $instance
65+
* @return FormLogin
66+
*/
5667
public function smallLogin($identifier,$instance=null){
5768
return $this->addHtmlComponent(FormLogin::small($identifier,$instance));
5869
}
5970

71+
/**
72+
* @param string $identifier
73+
* @param object $instance
74+
* @return FormLogin
75+
*/
6076
public function segmentedLogin($identifier,$instance=null){
6177
return $this->addHtmlComponent(FormLogin::attachedSegment($identifier,$instance));
6278
}
79+
80+
/**
81+
* @param string $identifier
82+
* @param object $instance
83+
* @return FormAccount
84+
*/
85+
public function defaultAccount($identifier,$instance=null){
86+
return $this->addHtmlComponent(FormAccount::regular($identifier,$instance));
87+
}
6388
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
namespace Ajax\semantic\widgets\business\user;
3+
use Ajax\semantic\widgets\business\BusinessForm;
4+
/**
5+
* Form for user Account
6+
* @author jc
7+
*/
8+
class FormAccount extends BusinessForm {
9+
/**
10+
* @param string $identifier
11+
* @param object $modelInstance
12+
*/
13+
public function __construct($identifier,$modelInstance=null,$fieldsOrder=[],$fieldsDefinition=[],$fields=[],$captions=[],$separators=[]) {
14+
parent::__construct($identifier,$modelInstance,$fieldsOrder,$fieldsDefinition,$fields,$captions,$separators);
15+
}
16+
17+
protected function getDefaultModelInstance(){
18+
return new UserModel();
19+
}
20+
21+
public static function regular($identifier,$modelInstance=null){
22+
return new FormAccount($identifier,$modelInstance,
23+
["message","login","password","passwordConf","email","submit","error"],
24+
["message"=>[["icon"=>"sign in"]],
25+
"input0"=>[["rules"=>"empty"]],
26+
"input1"=>[["inputType"=>"password","rules"=> ['minLength[6]', 'empty']]],
27+
"input2"=>[["inputType"=>"password","rules"=> ['minLength[6]', 'empty', 'match[password]']]],
28+
"input3"=>[["rules"=>"email"]],
29+
"submit"=>["green fluid"],
30+
"message2"=>[["error"=>true]]],
31+
["Account","login","password","passwordConf","email","submit","error"],
32+
["Please enter your account informations","Login","Password","Password confirmation","Email address","Creation"],
33+
[0,1,3,4,5,6]);
34+
}
35+
36+
public static function smallInline($identifier,$modelInstance=null){
37+
$result=new FormAccount($identifier,$modelInstance,
38+
["login","password","submit"],
39+
["input0"=>[["rules"=>"empty"]],"input1"=>[["inputType"=>"password","rules"=>"empty"]],"submit"=>["green basic"]],
40+
["login","password","submit"],
41+
["","","Connection"],
42+
[2]);
43+
$result->addDividerBefore(0, "Connection");
44+
return $result;
45+
}
46+
47+
public static function small($identifier,$modelInstance=null){
48+
$result=new FormAccount($identifier,$modelInstance,
49+
["login","password","submit"],
50+
["input0"=>[["rules"=>"empty"]],"input1"=>[["inputType"=>"password","rules"=>"empty"]],"submit"=>["green basic"]],
51+
["login","password","submit"],
52+
["Login","Password","Connection"],
53+
[1,2]);
54+
$result->addDividerBefore(0, "Connection");
55+
return $result;
56+
}
57+
58+
public static function attachedSegment($identifier,$modelInstance=null){
59+
$result=self::regular($identifier,$modelInstance);
60+
$result->fieldAsMessage("message",["icon"=>"sign in","attached"=>true]);
61+
$result->addWrapper("message",null,"<div class='ui attached segment'>");
62+
$result->addWrapper("error", null,"</div>");
63+
return $result;
64+
}
65+
}

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function run(JsUtils $js){
7070
protected function _generateBehavior($op,$params,JsUtils $js){
7171
if(isset($this->_urls[$op])){
7272
$params=\array_merge($params,["attr"=>"data-ajax"]);
73-
$js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params);
73+
$js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector($op),$params);
7474
}
7575
}
7676

@@ -206,7 +206,7 @@ protected function _generatePagination($table,$js=NULL){
206206

207207
protected function _associatePaginationBehavior(HtmlMenu $menu,JsUtils $js=NULL){
208208
if(isset($this->_urls["refresh"])){
209-
$menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith"]);
209+
$menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith","hasLoader"=>false]);
210210
}
211211
}
212212

@@ -355,19 +355,22 @@ public function asForm(){
355355

356356

357357

358-
protected function getTargetSelector() {
358+
protected function getTargetSelector($op) {
359359
$result=$this->_targetSelector;
360-
if(!isset($result))
360+
if(!isset($result[$op]))
361361
$result="#".$this->identifier;
362-
return $result;
362+
return $result[$op];
363363
}
364364

365365
/**
366366
* Sets the response element selector for Edit and Delete request with ajax
367-
* @param string $_targetSelector
367+
* @param string|array $_targetSelector string or associative array ["edit"=>"edit_selector","delete"=>"delete_selector"]
368368
* @return \Ajax\semantic\widgets\datatable\DataTable
369369
*/
370370
public function setTargetSelector($_targetSelector) {
371+
if(!\is_array($_targetSelector)){
372+
$_targetSelector=["edit"=>$_targetSelector,"delete"=>$_targetSelector];
373+
}
371374
$this->_targetSelector=$_targetSelector;
372375
return $this;
373376
}
@@ -393,7 +396,7 @@ public function setRefreshSelector($_refreshSelector) {
393396
*/
394397
public function show($modelInstance){
395398
if(\is_array($modelInstance)){
396-
if(\is_array(array_values($modelInstance)[0]))
399+
if(isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0]))
397400
$modelInstance=\json_decode(\json_encode($modelInstance), FALSE);
398401
}
399402
$this->_modelInstance=$modelInstance;

Ajax/semantic/widgets/datatable/Pagination.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public function getObjects($objects){
3131
if (0 === $row_count) {
3232
$this->visible=false;
3333
} else {
34-
$this->visible=true;
34+
3535
$this->page_count = (int)ceil($row_count / $this->items_per_page);
36+
$this->visible=$this->page_count>1;
3637
if($this->page > $this->page_count+1) {
3738
$this->page = 1;
3839
}

0 commit comments

Comments
 (0)