| 1 | <?php |
||
| 7 | class AjaxCall { |
||
| 8 | private $method; |
||
| 9 | private $parameters; |
||
| 10 | |||
| 11 | public function __construct($method, $parameters) { |
||
| 15 | |||
| 16 | public function compile(JsUtils $js=null) { |
||
| 17 | if ($js==null) |
||
| 18 | return; |
||
| 19 | $result=""; |
||
| 20 | $params="{}"; |
||
| 21 | $callback=NULL; |
||
| 22 | $attr="id"; |
||
| 23 | $validation=false; |
||
| 24 | $stopPropagation=true; |
||
| 25 | $preventDefault=true; |
||
| 26 | extract($this->parameters); |
||
| 27 | if ($preventDefault===true) { |
||
| 28 | $result.="\nevent.preventDefault();\n"; |
||
| 29 | } |
||
| 30 | if ($stopPropagation===true) { |
||
| 31 | $result.="event.stopPropagation();\n"; |
||
| 32 | } |
||
| 33 | switch($this->method) { |
||
| 34 | case "get": |
||
| 35 | $result.=$js->getDeferred($url, $responseElement, $params, $callback, $attr); |
||
| 36 | break; |
||
| 37 | case "post": |
||
| 38 | $result.=$js->postDeferred($url, $responseElement, $params, $callback, $attr); |
||
| 39 | break; |
||
| 40 | case "postForm": |
||
| 41 | $result.=$js->postFormDeferred($url, $form, $responseElement, $validation, $callback, $attr); |
||
| 42 | break; |
||
| 43 | } |
||
| 44 | return $result; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getMethod() { |
||
| 48 | return $this->method; |
||
| 49 | } |
||
| 50 | |||
| 51 | public function setMethod($method) { |
||
| 52 | $this->method=$method; |
||
| 53 | return $this; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function getParameters() { |
||
| 57 | return $this->parameters; |
||
| 58 | } |
||
| 59 | |||
| 60 | public function setParameters($parameters) { |
||
| 64 | } |