Skip to content

Commit 468e47b

Browse files
committed
Fix DataTable Json pagination +...
Add visibility compo HtmlList suitePoints
1 parent 42337f3 commit 468e47b

File tree

21 files changed

+419
-75
lines changed

21 files changed

+419
-75
lines changed

Ajax/JsUtils.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ public function compile(&$view=NULL, $view_var='script_foot', $script_tags=TRUE)
294294
$script=$this->defer($script);
295295
}
296296
$script.=";";
297+
297298
$this->jquery_code_for_compile=array();
298299
if($this->params["debug"]===false){
299300
$script=$this->minify($script);
@@ -303,6 +304,7 @@ public function compile(&$view=NULL, $view_var='script_foot', $script_tags=TRUE)
303304
if ($view!==NULL){
304305
$this->createScriptVariable($view,$view_var, $output);
305306
}
307+
306308
return $output;
307309
}
308310

Ajax/common/Widget.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,19 @@ public function setFields($fields){
162162
return $this;
163163
}
164164

165-
public function addField($field){
166-
$this->_instanceViewer->addField($field);
165+
public function addField($field,$key=null){
166+
$this->_instanceViewer->addField($field,$key);
167167
return $this;
168168
}
169169

170170
public function addFields($fields){
171171
$this->_instanceViewer->addFields($fields);
172172
return $this;
173173
}
174+
175+
public function countFields(){
176+
return $this->_instanceViewer->visiblePropertiesCount();
177+
}
174178

175179
public function addMessage($attributes=NULL,$fieldName="message"){
176180
$this->_instanceViewer->addField($fieldName);
@@ -182,15 +186,15 @@ public function addErrorMessage(){
182186
return $this->addMessage(["error"=>true],"message");
183187
}
184188

185-
public function insertField($index,$field){
189+
public function insertField($index,$field,$key=null){
186190
$index=$this->_getIndex($index);
187-
$this->_instanceViewer->insertField($index, $field);
191+
$this->_instanceViewer->insertField($index, $field,$key);
188192
return $this;
189193
}
190194

191-
public function insertInField($index,$field){
195+
public function insertInField($index,$field,$key=null){
192196
$index=$this->_getIndex($index);
193-
$this->_instanceViewer->insertInField($index, $field);
197+
$this->_instanceViewer->insertInField($index, $field,$key);
194198
return $this;
195199
}
196200

Ajax/common/html/BaseHtml.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ abstract class BaseHtml extends BaseWidget {
2222
protected $_wrapAfter=array ();
2323
protected $_bsComponent;
2424
protected $_compiled=false;
25+
protected $_runned=false;
2526
protected $_postCompile;
2627
protected $_preCompile;
2728

Ajax/common/html/HtmlCollection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,15 @@ public function asLinks($hrefs=[],$target=NUll) {
227227
}
228228
return $this;
229229
}
230+
231+
/**
232+
* Remove a portion of the items array and replace it with something else
233+
* @param int $offset
234+
* @param int $length If length is omitted, removes everything from offset to the end of the array. If length is specified and is positive, then that many elements will be removed. If length is specified and is negative then the end of the removed portion will be that many elements from the end of the array. If length is specified and is zero, no elements will be removed. Tip: to remove everything from offset to the end of the array when replacement is also specified, use count($input) for length.
235+
* @return $this
236+
*/
237+
public function splice($offset,$length=null){
238+
$this->content=array_slice($this->content, $offset,$length);
239+
return $this;
240+
}
230241
}

Ajax/common/html/traits/BaseHtmlEventsTrait.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
* @author jc
10-
* @property SimpleExtComponent $_bsComponent
10+
* @property \Ajax\common\components\SimpleExtComponent $_bsComponent
1111
* @property string identifier
1212
* @property BaseHtml _self
1313
*/
@@ -100,7 +100,9 @@ public function addEventsOnRun(JsUtils $js=NULL) {
100100
$this->_bsComponent->addEvent($event, $code);
101101
}
102102
$this->_events=array ();
103+
return $this->_bsComponent->getScript();
103104
}
105+
return "";
104106
}
105107

106108
protected function _eventsOnCreate(JsUtils $js=NULL){
@@ -239,4 +241,11 @@ public function jsHide() {
239241
public function jsToggle($value) {
240242
return $this->jsDoJquery("toggle",$value);
241243
}
244+
/**
245+
* @return multitype:
246+
*/
247+
public function getEvents() {
248+
return $this->_events;
249+
}
250+
242251
}

Ajax/common/traits/JsUtilsAjaxTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,12 @@ private function _jsonArray($maskSelector, $url, $method="get", $parameters=[])
313313
}
314314
$appendTo="\t\tnewElm.appendTo(".$parent.");\n";
315315
$retour=$parent.".find('.{$rowClass}').remove();";
316-
$retour.="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\n$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone();
316+
$retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone();
317317
newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n";
318318
$retour.= $appendTo;
319319
$retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('__'+key+'__')>-1){\n"."\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n";
320320
$retour.="\t$(document).trigger('jsonReady',[data]);\n";
321+
$retour.="\t".$jsCallback;
321322
$parameters["jsCallback"]=$retour;
322323
return $this->_ajax($method, $url,null,$parameters);
323324
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Ajax\semantic\components;
4+
5+
use Ajax\JsUtils;
6+
7+
/**
8+
* Visibility provides a set of callbacks for when a content appears in the viewport
9+
* @see https://semantic-ui.com/behaviors/visibility.html
10+
* @author jc
11+
*
12+
*/
13+
class Visibility extends SimpleSemExtComponent{
14+
15+
public function __construct(JsUtils $js) {
16+
parent::__construct($js);
17+
$this->uiName="visibility";
18+
$this->params=["once"=>false,"observeChanges"=>true];
19+
}
20+
21+
public function setOnce($value=false) {
22+
return $this->setParam("once", $value);
23+
}
24+
25+
public function setObserveChanges($value=true) {
26+
return $this->setParam("observeChanges", $value);
27+
}
28+
29+
public function setOnTopVisible($value) {
30+
$this->params["onTopVisible"]="%function(){".$value."}%";
31+
}
32+
33+
public function setOnBottomVisible($value) {
34+
$this->params["onBottomVisible"]="%function(){".$value."}%";
35+
}
36+
}

Ajax/semantic/html/collections/menus/HtmlMenu.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function setActiveItem($index) {
5555
private function getItemToInsert($item) {
5656
if ($item instanceof HtmlInput || $item instanceof HtmlImg || $item instanceof HtmlIcon || $item instanceof HtmlButtonGroups || $item instanceof HtmlButton || $item instanceof HtmlLabel) {
5757
$itemO=new HtmlMenuItem("item-" . $this->identifier . "-" . \sizeof($this->content) , $item);
58+
$itemO->addClass("no-active");
5859
$item=$itemO;
5960
}
6061
return $item;

Ajax/semantic/html/collections/menus/HtmlPaginationMenu.php

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

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

5-
use Ajax\semantic\html\collections\menus\HtmlMenu;
65
use Ajax\JsUtils;
76

87
use Ajax\semantic\html\elements\HtmlIcon;
98

109
class HtmlPaginationMenu extends HtmlMenu{
1110
private $_page;
11+
private $_pages;
12+
private $_max;
1213
public function __construct( $identifier, $items=array() ){
1314
parent::__construct( $identifier,$items);
15+
$this->_pages=$items;
1416
}
1517
/**
1618
* {@inheritDoc}
1719
* @see \Ajax\common\html\BaseHtml::compile()
1820
*/
1921
public function compile(JsUtils $js=NULL,&$view=NULL){
20-
$max=\sizeof($this->content);
22+
$max=$this->_max;//\sizeof($this->content);
23+
foreach ($this->content as $item){
24+
$item->addClass("pageNum");
25+
}
2126
$this->insertItem(new HtmlIcon("", "left chevron"))->setProperty("data-page", \max([1,$this->_page-1]))->addToProperty("class","_firstPage no-active");
2227
$this->addItem(new HtmlIcon("", "right chevron"))->setProperty("data-page", \min([$max,$this->_page+1]))->setProperty("data-max", $max)->addToProperty("class","_lastPage no-active");
2328
$this->asPagination();
2429
return parent::compile($js,$view);
2530
}
2631

27-
public function setActiveItem($index) {
28-
$result=parent::setActiveItem($index);
29-
$this->_page=$index+1;
30-
return $result;
32+
public function setActivePage($page){
33+
$index=$page-$this->_pages[0];
34+
$item=$this->setActiveItem($index);
35+
$this->_page=$page;
36+
return $this;
3137
}
3238

3339
public function getPage() {
3440
return $this->_page;
3541
}
42+
/**
43+
* @param mixed $_max
44+
*/
45+
public function setMax($_max) {
46+
$this->_max = $_max;
47+
}
48+
3649

3750
}

Ajax/semantic/html/collections/table/ActiveRow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function setMultiple($multiple) {
5555
return $this;
5656
}
5757

58-
public function compile(){
58+
public function run(){
5959
$multiple="";
6060
if(!$this->multiple){
6161
$multiple="$(this).closest('tbody').children('tr').removeClass('".$this->class."');";

0 commit comments

Comments
 (0)