11<?php
22namespace Ajax \semantic \html \collections \table \traits ;
33
4-
54use Ajax \JsUtils ;
65
76/**
7+ *
88 * @author jc
99 * @property HtmlTable $_self
1010 */
11- trait TableTrait{
11+ trait TableTrait {
12+
13+ abstract public function addEvent ($ event , $ jsCode , $ stopPropagation = false , $ preventDefault = false );
1214
13- abstract public function addEvent ($ event , $ jsCode , $ stopPropagation =false , $ preventDefault =false );
14- abstract public function getOn ($ event , $ url , $ responseElement ="" , $ parameters =array ());
15-
16- protected function addToPropertyTable ($ property ,$ value ){
15+ abstract public function getOn ($ event , $ url , $ responseElement = "" , $ parameters = array ());
16+
17+ protected function addToPropertyTable ($ property , $ value ) {
1718 return $ this ->_self ->addToProperty ($ property , $ value );
1819 }
1920
2021 public function setCelled () {
2122 return $ this ->addToPropertyTable ("class " , "celled " );
2223 }
2324
24- public function setBasic ($ very= false ) {
25- $ table= $ this ->_self ;
25+ public function setBasic ($ very = false ) {
26+ $ table = $ this ->_self ;
2627 if ($ very )
27- $ table ->addToPropertyCtrl ("class " , "very " , array ("very " ));
28- return $ table ->addToPropertyCtrl ("class " , "basic " , array ("basic " ));
28+ $ table ->addToPropertyCtrl ("class " , "very " , array (
29+ "very "
30+ ));
31+ return $ table ->addToPropertyCtrl ("class " , "basic " , array (
32+ "basic "
33+ ));
2934 }
3035
31- public function setCompact ($ very= false ) {
32- $ table= $ this ->_self ;
36+ public function setCompact ($ very = false ) {
37+ $ table = $ this ->_self ;
3338 if ($ very )
34- $ table ->addToPropertyCtrl ("class " , "very " , array ("very " ));
35- return $ table ->addToPropertyCtrl ("class " , "compact " , array ("compact " ));
39+ $ table ->addToPropertyCtrl ("class " , "very " , array (
40+ "very "
41+ ));
42+ return $ table ->addToPropertyCtrl ("class " , "compact " , array (
43+ "compact "
44+ ));
3645 }
3746
3847 public function setCollapsing () {
@@ -47,8 +56,8 @@ public function setStructured() {
4756 return $ this ->addToPropertyTable ("class " , "structured " );
4857 }
4958
50- public function setSortable ($ colIndex= NULL ) {
51- $ table= $ this ->_self ;
59+ public function setSortable ($ colIndex = NULL ) {
60+ $ table = $ this ->_self ;
5261 if (isset ($ colIndex ) && $ table ->hasPart ("thead " )) {
5362 $ table ->getHeader ()->sort ($ colIndex );
5463 }
@@ -71,41 +80,49 @@ public function setStriped() {
7180 return $ this ->addToPropertyTable ("class " , "striped " );
7281 }
7382
74- public function onRowClick ($ jsCode , $ stopPropagation= false , $ preventDefault= false ){
75- return $ this ->onRow ("click " , $ jsCode ,$ stopPropagation ,$ preventDefault );
83+ public function onRowClick ($ jsCode , $ stopPropagation = false , $ preventDefault = false ) {
84+ return $ this ->onRow ("click " , $ jsCode , $ stopPropagation , $ preventDefault );
7685 }
7786
78- public function onRow ($ event ,$ jsCode , $ stopPropagation= false , $ preventDefault= false ){
79- return $ this ->_self ->addEvent ($ event. "{{tbody tr}} " ,$ jsCode ,$ stopPropagation ,$ preventDefault );
87+ public function onRow ($ event , $ jsCode , $ stopPropagation = false , $ preventDefault = false ) {
88+ return $ this ->_self ->addEvent ($ event . "{{tbody tr}} " , $ jsCode , $ stopPropagation , $ preventDefault );
8089 }
8190
82- public function getOnRow ($ event , $ url , $ responseElement ="" , $ parameters =array ()){
83- $ parameters =\array_merge ($ parameters ,["stopPropagation " =>false ,"preventDefault " =>false ,"jsCondition " =>'!$(this).closest("tr").hasClass("active") ' ]);
84- $ selector ="tbody tr " ;
85- if (isset ($ parameters ["selector " ])){
86- $ selector =$ parameters ["selector " ];
91+ public function getOnRow ($ event , $ url , $ responseElement = "" , $ parameters = array ()) {
92+ $ jsCondition = '!$(this).closest("tr").hasClass("active") ' ;
93+ if (isset ($ parameters ['jsCondition ' ])) {
94+ $ jsCondition = '( ' . $ parameters ['jsCondition ' ] . ' && ' . $ jsCondition . ') ' ;
95+ }
96+ $ parameters = \array_merge ($ parameters , [
97+ "stopPropagation " => false ,
98+ "preventDefault " => false ,
99+ "jsCondition " => $ jsCondition
100+ ]);
101+ $ selector = "tbody tr " ;
102+ if (isset ($ parameters ["selector " ])) {
103+ $ selector = $ parameters ["selector " ];
87104 }
88- return $ this ->_self ->getOn ($ event. "{{ " . $ selector. "}} " , $ url ,$ responseElement ,$ parameters );
105+ return $ this ->_self ->getOn ($ event . "{{ " . $ selector . "}} " , $ url , $ responseElement , $ parameters );
89106 }
90-
91- public function onPageChange ($ jsCode ){
107+
108+ public function onPageChange ($ jsCode ) {
92109 $ this ->_self ->_addEvent ("pageChange " , $ jsCode );
93110 return $ this ;
94111 }
95-
96- public function onSearchTerminate ($ jsCode ){
112+
113+ public function onSearchTerminate ($ jsCode ) {
97114 $ this ->_self ->_addEvent ("searchTerminate " , $ jsCode );
98115 return $ this ;
99116 }
100-
101- public function getEventsScript (){
117+
118+ public function getEventsScript () {
102119 return $ this ->_self ->getBsComponent ()->getScript ();
103120 }
104-
105- public function addEventsOnRun (JsUtils $ js= NULL ) {
106- $ script= parent ::addEventsOnRun ($ js );
107- $ innerScript= $ this ->_self ->getInnerScript ();
108- if (! isset ($ innerScript )){
121+
122+ public function addEventsOnRun (JsUtils $ js = NULL ) {
123+ $ script = parent ::addEventsOnRun ($ js );
124+ $ innerScript = $ this ->_self ->getInnerScript ();
125+ if (! isset ($ innerScript )) {
109126 $ this ->_self ->setInnerScript ($ script );
110127 }
111128 return $ script ;
0 commit comments