Skip to content

Commit

Permalink
add setPropertyValues for DataForm and HtmlForm
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheron committed Apr 29, 2021
1 parent fffd2d9 commit cc86277
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 28 deletions.
80 changes: 52 additions & 28 deletions Ajax/php/ubiquity/JsUtils.php
Original file line number Diff line number Diff line change
@@ -1,66 +1,90 @@
<?php

namespace Ajax\php\ubiquity;

use Ubiquity\controllers\Startup;
use Ubiquity\utils\http\URequest;

class JsUtils extends \Ajax\JsUtils{
class JsUtils extends \Ajax\JsUtils {

public function getUrl($url){
public function getUrl($url) {
return URequest::getUrl($url);
}

public function addViewElement($identifier,$content,&$view){
$controls=$view->getVar("q");
public function addViewElement($identifier, $content, &$view) {
$controls = $view->getVar("q");
if (isset($controls) === false) {
$controls=array ();
$controls = array();
}
$controls[$identifier]=$content;
$controls[$identifier] = $content;
$view->setVar("q", $controls);
}

public function createScriptVariable(&$view,$view_var, $output){
$view->setVar($view_var,$output);
public function createScriptVariable(&$view, $view_var, $output) {
$view->setVar($view_var, $output);
}

public function forward($initialController,$controller,$action,$params=array()){
return $initialController->forward($controller,$action,$params,true,true,true);
public function forward($initialController, $controller, $action, $params = array()) {
return $initialController->forward($controller, $action, $params, true, true, true);
}

public function renderContent($initialControllerInstance,$viewName, $params=NULL) {
return $initialControllerInstance->loadView($viewName,$params,true);
public function renderContent($initialControllerInstance, $viewName, $params = NULL) {
return $initialControllerInstance->loadView($viewName, $params, true);
}

public function fromDispatcher($dispatcher){
public function fromDispatcher($dispatcher) {
return Startup::$urlParts;
}

/**
* Performs jQuery compilation and displays a view
*
* @param string $viewName
* @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>
* If an associative array is passed, the view retrieves variables from the table's key names
* @param boolean $asString If true, the view is not displayed but returned as a string (usable in a variable)
* @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>
* If an associative array is passed, the view retrieves variables from the table's key names
* @param boolean $asString
* If true, the view is not displayed but returned as a string (usable in a variable)
*/
public function renderView($viewName,$parameters=[],$asString=false){
if(isset($this->injected)){
$view=$this->injected->getView();
public function renderView($viewName, $parameters = [], $asString = false) {
if (isset($this->injected)) {
$view = $this->injected->getView();
$this->compile($view);
if (isset($parameters))
$view->setVars($parameters);
return $view->render($viewName, $asString);
}
throw new \Exception(get_class()." instance is not properly instancied : you omitted the second parameter \$controller!");
throw new \Exception(get_class() . " instance is not properly instancied : you omitted the second parameter \$controller!");
}

/**
* Performs jQuery compilation and displays the default view
* @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>
* If an associative array is passed, the view retrieves variables from the table's key names
* @param boolean $asString If true, the view is not displayed but returned as a string (usable in a variable)
*
* @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>
* If an associative array is passed, the view retrieves variables from the table's key names
* @param boolean $asString
* If true, the view is not displayed but returned as a string (usable in a variable)
*/
public function renderDefaultView($parameters = [], $asString = false) {
return $this->renderView($this->injected->getDefaultViewName(), $parameters, $asString);
}

/**
* Loads and eventually executes a jsFile with php parameters, using the default template engine.
*
* @param string $jsFile
* @param array $parameters
* @param boolean $immediatly
* @throws \Exception
*/
public function renderDefaultView($parameters=[],$asString=false){
return $this->renderView($this->injected->getDefaultViewName(),$parameters,$asString);
public function execJSFromFile($jsFile, $parameters = [], $immediatly = true) {
if (isset($this->injected)) {
$view = $this->injected->getView();
if (isset($parameters))
$view->setVars($parameters);
$js = $view->render($jsFile . '.js', true);
$this->exec($js, $immediatly);
}
throw new \Exception(get_class() . " instance is not properly instancied : you omitted the second parameter \$controller!");
}
}
21 changes: 21 additions & 0 deletions Ajax/semantic/widgets/base/FieldAsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ abstract protected function _getFieldCaption($index);

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

private $_speProperties;

/**
*
* @param HtmlFormField $element
Expand Down Expand Up @@ -98,6 +100,10 @@ protected function _fieldAs($elementCallback, &$index, $attributes = NULL, $pref
unset($attributes["name"]);
}
$element = $elementCallback($id, $name, $value, $caption);
if (isset($this->_speProperties[$index])) {
$attributes ??= [];
$attributes += $this->_speProperties[$index];
}
if (\is_array($attributes)) {
$this->_applyAttributes($element, $attributes, $index, $instance);
}
Expand All @@ -107,6 +113,21 @@ protected function _fieldAs($elementCallback, &$index, $attributes = NULL, $pref
return $this;
}

/**
* Defines the values for the fields for a property (or html attribute).
*
* @param int|string $property
* the property to update
* @param array $indexValues
* array of field=>value
*/
public function setPropertyValues($property, $indexValues) {
foreach ($indexValues as $index => $value) {
$ind = $this->_getIndex($index);
$this->_speProperties[$ind][$property] = $value;
}
}

public function fieldAsProgress($index, $label = NULL, $attributes = array()) {
$this->setValueFunction($index, function ($value) use ($label, $attributes) {
$pb = new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes);
Expand Down

0 comments on commit cc86277

Please sign in to comment.