Skip to content

Commit cc86277

Browse files
committed
add setPropertyValues for DataForm and HtmlForm
1 parent fffd2d9 commit cc86277

File tree

2 files changed

+73
-28
lines changed

2 files changed

+73
-28
lines changed

Ajax/php/ubiquity/JsUtils.php

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,90 @@
11
<?php
2-
32
namespace Ajax\php\ubiquity;
43

54
use Ubiquity\controllers\Startup;
65
use Ubiquity\utils\http\URequest;
76

8-
class JsUtils extends \Ajax\JsUtils{
7+
class JsUtils extends \Ajax\JsUtils {
98

10-
public function getUrl($url){
9+
public function getUrl($url) {
1110
return URequest::getUrl($url);
1211
}
1312

14-
public function addViewElement($identifier,$content,&$view){
15-
$controls=$view->getVar("q");
13+
public function addViewElement($identifier, $content, &$view) {
14+
$controls = $view->getVar("q");
1615
if (isset($controls) === false) {
17-
$controls=array ();
16+
$controls = array();
1817
}
19-
$controls[$identifier]=$content;
18+
$controls[$identifier] = $content;
2019
$view->setVar("q", $controls);
2120
}
2221

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);
2524
}
2625

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);
2928
}
3029

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);
3332
}
3433

35-
public function fromDispatcher($dispatcher){
34+
public function fromDispatcher($dispatcher) {
3635
return Startup::$urlParts;
3736
}
38-
37+
3938
/**
4039
* Performs jQuery compilation and displays a view
40+
*
4141
* @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)
4547
*/
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();
4951
$this->compile($view);
5052
if (isset($parameters))
5153
$view->setVars($parameters);
5254
return $view->render($viewName, $asString);
5355
}
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!");
5557
}
56-
58+
5759
/**
5860
* 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
6279
*/
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!");
6589
}
6690
}

Ajax/semantic/widgets/base/FieldAsTrait.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ abstract protected function _getFieldCaption($index);
4646

4747
abstract protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement = NULL, $parameters = NULL);
4848

49+
private $_speProperties;
50+
4951
/**
5052
*
5153
* @param HtmlFormField $element
@@ -98,6 +100,10 @@ protected function _fieldAs($elementCallback, &$index, $attributes = NULL, $pref
98100
unset($attributes["name"]);
99101
}
100102
$element = $elementCallback($id, $name, $value, $caption);
103+
if (isset($this->_speProperties[$index])) {
104+
$attributes ??= [];
105+
$attributes += $this->_speProperties[$index];
106+
}
101107
if (\is_array($attributes)) {
102108
$this->_applyAttributes($element, $attributes, $index, $instance);
103109
}
@@ -107,6 +113,21 @@ protected function _fieldAs($elementCallback, &$index, $attributes = NULL, $pref
107113
return $this;
108114
}
109115

116+
/**
117+
* Defines the values for the fields for a property (or html attribute).
118+
*
119+
* @param int|string $property
120+
* the property to update
121+
* @param array $indexValues
122+
* array of field=>value
123+
*/
124+
public function setPropertyValues($property, $indexValues) {
125+
foreach ($indexValues as $index => $value) {
126+
$ind = $this->_getIndex($index);
127+
$this->_speProperties[$ind][$property] = $value;
128+
}
129+
}
130+
110131
public function fieldAsProgress($index, $label = NULL, $attributes = array()) {
111132
$this->setValueFunction($index, function ($value) use ($label, $attributes) {
112133
$pb = new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes);

0 commit comments

Comments
 (0)