1 | <?php |
||
14 | trait BaseHtmlEventsTrait{ |
||
15 | |||
16 | protected $_events=array (); |
||
17 | |||
18 | /** |
||
19 | * @param string $event |
||
20 | * @param string|AjaxCall $jsCode |
||
21 | * @param boolean $stopPropagation |
||
22 | * @param boolean $preventDefault |
||
23 | * @return \Ajax\common\html\BaseHtml |
||
24 | */ |
||
25 | public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
||
26 | if ($stopPropagation === true) { |
||
27 | $jsCode=Javascript::$stopPropagation . $jsCode; |
||
28 | } |
||
29 | if ($preventDefault === true) { |
||
30 | $jsCode=Javascript::$preventDefault . $jsCode; |
||
31 | } |
||
32 | return $this->_addEvent($event, $jsCode); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param string $event |
||
37 | * @param string|AjaxCall $jsCode |
||
38 | * @return BaseHtml |
||
39 | */ |
||
40 | public function _addEvent($event, $jsCode) { |
||
41 | if (array_key_exists($event, $this->_events)) { |
||
42 | if (\is_array($this->_events[$event])) { |
||
43 | $this->_events[$event][]=$jsCode; |
||
44 | } else { |
||
45 | $this->_events[$event]=array ($this->_events[$event],$jsCode ); |
||
46 | } |
||
47 | } else { |
||
48 | $this->_events[$event]=$jsCode; |
||
49 | } |
||
50 | return $this; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param string $event |
||
55 | * @param string $jsCode |
||
56 | * @param boolean $stopPropagation |
||
57 | * @param boolean $preventDefault |
||
58 | * @return \Ajax\common\html\BaseHtml |
||
59 | */ |
||
60 | public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
||
61 | return $this->addEvent($event, $jsCode, $stopPropagation, $preventDefault); |
||
62 | } |
||
63 | |||
64 | public function onClick($jsCode, $stopPropagation=false, $preventDefault=true) { |
||
65 | return $this->on("click", $jsCode, $stopPropagation, $preventDefault); |
||
66 | } |
||
67 | |||
68 | public function setClick($jsCode) { |
||
69 | return $this->onClick($jsCode); |
||
70 | } |
||
71 | |||
72 | public function onCreate($jsCode){ |
||
73 | if(isset($this->_events["_create"])){ |
||
74 | $this->_events["_create"][]=$jsCode; |
||
75 | }else{ |
||
76 | $this->_events["_create"]=[$jsCode]; |
||
77 | } |
||
78 | return $this; |
||
79 | } |
||
80 | |||
81 | public function addEventsOnRun(JsUtils $js=NULL) { |
||
82 | $this->_eventsOnCreate($js); |
||
83 | if (isset($this->_bsComponent)) { |
||
84 | foreach ( $this->_events as $event => $jsCode ) { |
||
85 | $code=$jsCode; |
||
86 | if (\is_array($jsCode)) { |
||
87 | $code=""; |
||
88 | foreach ( $jsCode as $jsC ) { |
||
89 | if ($jsC instanceof AjaxCall) { |
||
90 | $code.="\n" . $jsC->compile($js); |
||
91 | } else { |
||
92 | $code.="\n" . $jsC; |
||
93 | } |
||
94 | } |
||
95 | } elseif ($jsCode instanceof AjaxCall) { |
||
96 | $code=$jsCode->compile($js); |
||
97 | } |
||
98 | $this->_bsComponent->addEvent($event, $code); |
||
99 | } |
||
100 | $this->_events=array (); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | protected function _eventsOnCreate(JsUtils $js=NULL){ |
||
115 | |||
116 | /** |
||
117 | * @param string $operation |
||
118 | * @param string $event |
||
119 | * @param string $url |
||
120 | * @param string $responseElement |
||
121 | * @param array $parameters |
||
122 | * @return BaseHtml |
||
123 | */ |
||
124 | public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) { |
||
130 | |||
131 | public function getOn($event, $url, $responseElement="", $parameters=array()) { |
||
134 | |||
135 | public function getOnClick($url, $responseElement="", $parameters=array()) { |
||
138 | |||
139 | public function postOn($event, $url, $params="{}", $responseElement="", $parameters=array()) { |
||
143 | |||
144 | public function postOnClick($url, $params="{}", $responseElement="", $parameters=array()) { |
||
147 | |||
148 | public function postFormOn($event, $url, $form, $responseElement="", $parameters=array()) { |
||
152 | |||
153 | public function postFormOnClick($url, $form, $responseElement="", $parameters=array()) { |
||
156 | |||
157 | public function jsDoJquery($jqueryCall, $param="") { |
||
160 | |||
161 | public function executeOnRun($jsCode) { |
||
164 | |||
165 | public function jsHtml($content="") { |
||
168 | |||
169 | public function jsShow() { |
||
172 | |||
173 | public function jsHide() { |
||
176 | |||
177 | public function jsToggle($value) { |
||
180 | } |
||
181 |