Skip to content

Commit ab06fe6

Browse files
committed
ajaxTrait complete refactoring
1 parent a91c54f commit ab06fe6

File tree

16 files changed

+184
-162
lines changed

16 files changed

+184
-162
lines changed

Ajax/common/Widget.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ public function insertInField($index,$field){
194194
return $this;
195195
}
196196

197+
/**
198+
* Defines the function which displays the field value
199+
* @param $index index or name of the field to display
200+
* @param callable $callback function parameters are : $value : the field value ,$index : the field index, $instance : the active instance of model
201+
* @return Widget
202+
*/
197203
public function setValueFunction($index,$callback){
198204
$index=$this->_getIndex($index);
199205
$this->_instanceViewer->setValueFunction($index, $callback);

Ajax/common/html/BaseHtml.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ protected function compile_once(JsUtils $js=NULL, &$view=NULL) {
202202
$pc=$this->_preCompile;
203203
$pc($this);
204204
}
205+
unset($this->properties["jsCallback"]);
205206
$this->_compiled=true;
206207
}
207208
}
@@ -214,7 +215,10 @@ public function compile(JsUtils $js=NULL, &$view=NULL) {
214215
if (\is_array($value)) {
215216
$v=PropertyWrapper::wrap($value, $js);
216217
} else {
217-
$v=$value;
218+
if($value instanceof \stdClass)
219+
$v=\print_r($value,true);
220+
else
221+
$v=$value;
218222
}
219223
$result=str_ireplace("%" . $key . "%", $v, $result);
220224
}

Ajax/common/html/BaseWidget.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Ajax\common\html;
44

5+
use Ajax\service\JString;
6+
57
/**
68
* BaseWidget for Twitter Bootstrap, jQuery UI or Semantic rich components
79
* @author jc
@@ -23,11 +25,11 @@ public function getIdentifier() {
2325
}
2426

2527
public function setIdentifier($identifier) {
26-
$this->identifier=$identifier;
28+
$this->identifier=$this->cleanIdentifier($identifier);
2729
return $this;
2830
}
2931

3032
protected function cleanIdentifier($id) {
31-
return preg_replace('/[^a-zA-Z0-9\-.]/s', '', $id);
33+
return JString::cleanIdentifier($id);
3234
}
3335
}

Ajax/common/traits/JsUtilsAjaxTrait.php

Lines changed: 134 additions & 130 deletions
Large diffs are not rendered by default.

Ajax/semantic/html/base/HtmlSemDoubleElement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ public function run(JsUtils $js) {
167167
return $this->_bsComponent;
168168
}
169169

170-
public function addList($elements,$ordered=false){
171-
$list=new HtmlList("list-".$this->identifier,$elements);
170+
public function addList($items,$ordered=false){
171+
$list=new HtmlList("list-".$this->identifier,$items);
172172
$list->setOrdered($ordered);
173173
$list->setClass("ui list");
174174
$this->addContent($list);

Ajax/semantic/html/base/constants/icons/webContent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
use Ajax\common\BaseEnum;
66

7-
abstract class WebContent extends BaseEnum {
7+
abstract class webContent extends BaseEnum {
88
const ALARM="alarm", ALARM_SLASH="alarm slash", ALARM_OUTLINE="alarm outline", ALARM_SLASH_OUTLINE="alarm slash outline", AT="at", BROWSER="browser", BUG="bug", CALENDAR_OUTLINE="calendar outline", CALENDAR="calendar", CLOUD="cloud", CODE="code", COMMENT="comment", COMMENTS="comments", COMMENT_OUTLINE="comment outline", COMMENTS_OUTLINE="comments outline", COPYRIGHT="copyright", DASHBOARD="dashboard", DROPDOWN="dropdown", EXTERNAL_SQUARE="external square", EXTERNAL="external", EYEDROPPER="eyedropper", FEED="feed", FIND="find", HEARTBEAT="heartbeat", HISTORY="history", HOME="home", IDEA="idea", INBOX="inbox", LAB="lab", MAIL="mail", MAIL_OUTLINE="mail outline", MAIL_SQUARE="mail square", MAP="map", OPTIONS="options", PAINT_BRUSH="paint brush", PAYMENT="payment", PHONE="phone", PHONE_SQUARE="phone square", PRIVACY="privacy", PROTECT="protect", SEARCH="search", SETTING="setting", SETTINGS="settings", SHOP="shop", SIDEBAR="sidebar", SIGNAL="signal", SITEMAP="sitemap", TAG="tag", TAGS="tags", TASKS="tasks", TERMINAL="terminal", TEXT_TELEPHONE="text telephone", TICKET="ticket", TROPHY="trophy", WIFI="wifi";
99
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ public static function checkeds($name, $items=array(), $label=NULL, $values=arra
124124
}
125125
$fields[]=$itemO;
126126
}
127-
$checkeds=new HtmlFormFields("fields-".$name, $fields);
127+
$radios=new HtmlFormFields("fields-".$name, $fields);
128128
if (isset($label))
129-
$checkeds->setLabel($label)->setProperty("for", $name);
130-
return $checkeds;
129+
$radios->setLabel($label)->setProperty("for", $name);
130+
return $radios;
131131
}
132132

133133
public function setEqualWidth($_equalWidth) {

Ajax/semantic/html/elements/HtmlButtonGroups.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ protected function createItem($value){
2626
return new HtmlButton("", $value);
2727
}
2828

29-
/**
30-
* @param array $items
31-
* @param boolean $asCombo
32-
* @return HtmlDropdown
33-
*/
3429
public function addDropdown($items,$asCombo=false){
3530
$dd= new HtmlDropdown("dd-".$this->identifier,null,$items);
3631
$dd->asButton();

Ajax/semantic/html/modules/HtmlModal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function setActions($actions) {
5757
public function addAction($action){
5858
if(!$action instanceof BaseHtml){
5959
$class="";
60-
if(\array_search($action, ["Okay","Yes"])!==false){
60+
if(\array_search($action, ["Okay","Yes","Validate"])!==false){
6161
$class="approve";
6262
}
6363
if(\array_search($action, ["Close","Cancel","No"])!==false){

Ajax/semantic/widgets/base/FieldAsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function _applyAttributes(BaseHtml $element,&$attributes,$index){
4646
$callback=$attributes["jsCallback"];
4747
if(\is_callable($callback)){
4848
$callback($element,$this->_modelInstance,$index);
49-
unset($attributes["jsCallback"]);
49+
//unset($attributes["jsCallback"]);
5050
}
5151
}
5252
unset($attributes["rules"]);

Ajax/semantic/widgets/base/InstanceViewer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ protected function _getValue($property,$index){
9999
if($property instanceof \ReflectionProperty){
100100
$value=$this->_getPropertyValue($property, $index);
101101
$propertyName=$property->getName();
102-
}elseif(\is_array($property)){
102+
}elseif(\is_callable($property))
103+
$value=$property($this->instance);
104+
elseif(\is_array($property)){
103105
$values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property);
104106
$value=\implode("", $values);
105107
}elseif(\is_string($property)){
@@ -109,8 +111,6 @@ protected function _getValue($property,$index){
109111
}elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){
110112
$value=JReflection::callMethod($this->instance, $getter, []);
111113
}
112-
}elseif(\is_callable($property)){
113-
$value=$property($this->instance);
114114
}
115115
return $this->_postGetValue($index, $propertyName, $value);
116116
}

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,21 @@ protected function _generateRow($instance,&$table,$checkedClass=null){
172172
InstanceViewer::$index++;
173173
$values= $this->_instanceViewer->getValues();
174174
$id=$this->_instanceViewer->getIdentifier();
175+
$dataAjax=$id;
176+
$id=$this->cleanIdentifier($id);
175177
if($this->_hasCheckboxes){
176178
$ck=new HtmlCheckbox("ck-".$this->identifier."-".$id,"");
177179
$ck->setOnChange("event.stopPropagation();");
178180
$field=$ck->getField();
179-
$field->setProperty("value",$id);
181+
$field->setProperty("value",$dataAjax);
180182
$field->setProperty("name", "selection[]");
181183
if(isset($checkedClass))
182184
$field->setClass($checkedClass);
183185
\array_unshift($values, $ck);
184186
}
185187
$result=$table->newRow();
186188
$result->setIdentifier($this->identifier."-tr-".$id);
187-
$result->setProperty("data-ajax",$id);
189+
$result->setProperty("data-ajax",$dataAjax);
188190
$result->setValues($values);
189191
$result->addToProperty("class",$this->_rowClass);
190192
return $result;

Ajax/semantic/widgets/datatable/DataTableFieldAsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private function getCallable($thisCallback,$parameters,$callback=null){
6161
* @return HtmlButton
6262
*/
6363
private function getFieldButton($caption,$visibleHover=true){
64-
$bt= new HtmlButton("",$caption);
64+
$bt= new HtmlButton($this->cleanIdentifier($caption),$caption);
6565
if($visibleHover)
6666
$this->_visibleOver($bt);
6767
return $bt;

Ajax/service/AjaxCall.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,22 @@ public function compile(JsUtils $js=null) {
1818
return;
1919
$params="{}";
2020
$jsCallback=NULL;
21-
$attr="id";
22-
$validation=false;
2321
$stopPropagation=true;
2422
$preventDefault=true;
25-
$jqueryDone="html";
26-
$ajaxTransition=null;
27-
$hasLoader=true;
2823
$method="get";
2924
$rowClass="_json";
25+
$this->parameters["immediatly"]=false;
3026
extract($this->parameters);
3127
$result=$this->_eventPreparing($preventDefault, $stopPropagation);
3228
switch($this->method) {
3329
case "get":
34-
$result.=$js->getDeferred($url, $responseElement, $params, $jsCallback, $attr,$jqueryDone,$ajaxTransition);
30+
$result.=$js->getDeferred($url, $responseElement, $this->parameters);
3531
break;
3632
case "post":
37-
$result.=$js->postDeferred($url, $responseElement, $params, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition);
33+
$result.=$js->postDeferred($url, $params,$responseElement, $this->parameters);
3834
break;
3935
case "postForm":
40-
$result.=$js->postFormDeferred($url, $form, $responseElement, $params,$validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition);
36+
$result.=$js->postFormDeferred($url, $form, $responseElement, $this->parameters);
4137
break;
4238
case "json":
4339
$result.=$js->jsonDeferred($url,$method,$params,$jsCallback);

Ajax/service/JString.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ public static function getValueBetween(&$str,$before="{{",$after="}}"){
6262
}
6363
return $result;
6464
}
65+
66+
public static function cleanIdentifier($id) {
67+
return preg_replace('/[^a-zA-Z0-9\-]/s', '', $id);
68+
}
6569
}

Ajax/ui/components/DialogButton.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ public static function cancelButton($caption="Annuler") {
4242
return new DialogButton($caption, "$( this ).dialog( 'close' );");
4343
}
4444

45-
public static function submitButton(JsUtils $js, $url, $form, $responseElement, $caption="Okay") {
46-
return new DialogButton($caption, $js->postForm($url, $form, $responseElement) . ";$( this ).dialog( 'close' );");
45+
/**
46+
* @param JsUtils $js
47+
* @param string $url
48+
* @param string $form
49+
* @param unknown $responseElement
50+
* @param string $caption
51+
* @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null)
52+
* @return DialogButton
53+
*/
54+
public static function submitButton(JsUtils $js, $url, $form, $responseElement, $caption="Okay",$parameters=[]) {
55+
return new DialogButton($caption, $js->postFormDeferred($url, $form, $responseElement,$parameters) . ";$( this ).dialog( 'close' );");
4756
}
4857
}

0 commit comments

Comments
 (0)