|
1 | 1 | <?php
|
2 |
| - |
3 | 2 | namespace Ajax\php\ubiquity;
|
4 | 3 |
|
5 | 4 | use Ubiquity\controllers\Startup;
|
6 | 5 | use Ubiquity\utils\http\URequest;
|
7 | 6 |
|
8 |
| -class JsUtils extends \Ajax\JsUtils{ |
| 7 | +class JsUtils extends \Ajax\JsUtils { |
9 | 8 |
|
10 |
| - public function getUrl($url){ |
| 9 | + public function getUrl($url) { |
11 | 10 | return URequest::getUrl($url);
|
12 | 11 | }
|
13 | 12 |
|
14 |
| - public function addViewElement($identifier,$content,&$view){ |
15 |
| - $controls=$view->getVar("q"); |
| 13 | + public function addViewElement($identifier, $content, &$view) { |
| 14 | + $controls = $view->getVar("q"); |
16 | 15 | if (isset($controls) === false) {
|
17 |
| - $controls=array (); |
| 16 | + $controls = array(); |
18 | 17 | }
|
19 |
| - $controls[$identifier]=$content; |
| 18 | + $controls[$identifier] = $content; |
20 | 19 | $view->setVar("q", $controls);
|
21 | 20 | }
|
22 | 21 |
|
23 |
| - public function createScriptVariable(&$view,$view_var, $output){ |
24 |
| - $view->setVar($view_var,$output); |
| 22 | + public function createScriptVariable(&$view, $view_var, $output) { |
| 23 | + $view->setVar($view_var, $output); |
25 | 24 | }
|
26 | 25 |
|
27 |
| - public function forward($initialController,$controller,$action,$params=array()){ |
28 |
| - return $initialController->forward($controller,$action,$params,true,true,true); |
| 26 | + public function forward($initialController, $controller, $action, $params = array()) { |
| 27 | + return $initialController->forward($controller, $action, $params, true, true, true); |
29 | 28 | }
|
30 | 29 |
|
31 |
| - public function renderContent($initialControllerInstance,$viewName, $params=NULL) { |
32 |
| - return $initialControllerInstance->loadView($viewName,$params,true); |
| 30 | + public function renderContent($initialControllerInstance, $viewName, $params = NULL) { |
| 31 | + return $initialControllerInstance->loadView($viewName, $params, true); |
33 | 32 | }
|
34 | 33 |
|
35 |
| - public function fromDispatcher($dispatcher){ |
| 34 | + public function fromDispatcher($dispatcher) { |
36 | 35 | return Startup::$urlParts;
|
37 | 36 | }
|
38 |
| - |
| 37 | + |
39 | 38 | /**
|
40 | 39 | * Performs jQuery compilation and displays a view
|
| 40 | + * |
41 | 41 | * @param string $viewName
|
42 |
| - * @param mixed $parameters Variable or associative array to pass to the view <br> If a variable is passed, it will have the name <b> $ data </ b> in the view, <br> |
43 |
| - * If an associative array is passed, the view retrieves variables from the table's key names |
44 |
| - * @param boolean $asString If true, the view is not displayed but returned as a string (usable in a variable) |
| 42 | + * @param mixed $parameters |
| 43 | + * Variable or associative array to pass to the view <br> If a variable is passed, it will have the name <b> $ data </ b> in the view, <br> |
| 44 | + * If an associative array is passed, the view retrieves variables from the table's key names |
| 45 | + * @param boolean $asString |
| 46 | + * If true, the view is not displayed but returned as a string (usable in a variable) |
45 | 47 | */
|
46 |
| - public function renderView($viewName,$parameters=[],$asString=false){ |
47 |
| - if(isset($this->injected)){ |
48 |
| - $view=$this->injected->getView(); |
| 48 | + public function renderView($viewName, $parameters = [], $asString = false) { |
| 49 | + if (isset($this->injected)) { |
| 50 | + $view = $this->injected->getView(); |
49 | 51 | $this->compile($view);
|
50 | 52 | if (isset($parameters))
|
51 | 53 | $view->setVars($parameters);
|
52 | 54 | return $view->render($viewName, $asString);
|
53 | 55 | }
|
54 |
| - throw new \Exception(get_class()." instance is not properly instancied : you omitted the second parameter \$controller!"); |
| 56 | + throw new \Exception(get_class() . " instance is not properly instancied : you omitted the second parameter \$controller!"); |
55 | 57 | }
|
56 |
| - |
| 58 | + |
57 | 59 | /**
|
58 | 60 | * Performs jQuery compilation and displays the default view
|
59 |
| - * @param mixed $parameters Variable or associative array to pass to the view <br> If a variable is passed, it will have the name <b> $ data </ b> in the view, <br> |
60 |
| - * If an associative array is passed, the view retrieves variables from the table's key names |
61 |
| - * @param boolean $asString If true, the view is not displayed but returned as a string (usable in a variable) |
| 61 | + * |
| 62 | + * @param mixed $parameters |
| 63 | + * Variable or associative array to pass to the view <br> If a variable is passed, it will have the name <b> $ data </ b> in the view, <br> |
| 64 | + * If an associative array is passed, the view retrieves variables from the table's key names |
| 65 | + * @param boolean $asString |
| 66 | + * If true, the view is not displayed but returned as a string (usable in a variable) |
| 67 | + */ |
| 68 | + public function renderDefaultView($parameters = [], $asString = false) { |
| 69 | + return $this->renderView($this->injected->getDefaultViewName(), $parameters, $asString); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Loads and eventually executes a jsFile with php parameters, using the default template engine. |
| 74 | + * |
| 75 | + * @param string $jsFile |
| 76 | + * @param array $parameters |
| 77 | + * @param boolean $immediatly |
| 78 | + * @throws \Exception |
62 | 79 | */
|
63 |
| - public function renderDefaultView($parameters=[],$asString=false){ |
64 |
| - return $this->renderView($this->injected->getDefaultViewName(),$parameters,$asString); |
| 80 | + public function execJSFromFile($jsFile, $parameters = [], $immediatly = true) { |
| 81 | + if (isset($this->injected)) { |
| 82 | + $view = $this->injected->getView(); |
| 83 | + if (isset($parameters)) |
| 84 | + $view->setVars($parameters); |
| 85 | + $js = $view->render($jsFile . '.js', true); |
| 86 | + $this->exec($js, $immediatly); |
| 87 | + } |
| 88 | + throw new \Exception(get_class() . " instance is not properly instancied : you omitted the second parameter \$controller!"); |
65 | 89 | }
|
66 | 90 | }
|
0 commit comments