Skip to content

Commit

Permalink
add renderComponent + applyInverted for Ubiquity
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheron committed Jan 4, 2024
1 parent 2aef246 commit cbfe118
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
22 changes: 0 additions & 22 deletions Ajax/Semantic.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ class Semantic extends BaseGui {

private $language;

private $inverted;

public function __construct($autoCompile=true) {
parent::__construct($autoCompile);
}


public function setLanguage($language){
if($language!==$this->language){
$file=\realpath(dirname(__FILE__)."/semantic/components/validation/languages/".$language.".js");
Expand All @@ -33,23 +30,4 @@ public function setLanguage($language){
}
}
}

public function compileHtml(JsUtils $js = NULL, &$view = NULL) {
if($this->inverted==null){
parent::compileHtml($js,$view);
}else {
foreach ($this->htmlComponents as $htmlComponent) {
$htmlComponent->setInverted(true);
$htmlComponent->compile($js, $view);
}
}
}

public function setInverted($inverted='inverted'){
$this->inverted=$inverted;
}

public function getInverted(){
return $this->inverted;
}
}
22 changes: 22 additions & 0 deletions Ajax/php/ubiquity/JsUtils.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Ajax\php\ubiquity;

use Ajax\common\html\BaseHtml;
use Ajax\semantic\components\validation\Rule;
use Ubiquity\controllers\Startup;
use Ubiquity\utils\http\URequest;
Expand Down Expand Up @@ -81,6 +82,19 @@ public function renderView($viewName, $parameters = [], $asString = false) {
throw new \Exception(get_class() . " instance is not properly instancied : you omitted the second parameter \$controller!");
}

/**
* Compile and render a component.
*
* @param BaseHtml $component
* @param bool $asString
* @return mixed
* @throws \Exception
*/
public function renderComponent(BaseHtml $component, bool $asString = false) {
$component->setLibraryId('_compo_');
return $this->renderView('@framework/main/component.html',[],$asString);
}

/**
* Performs jQuery compilation and displays the default view
*
Expand Down Expand Up @@ -175,4 +189,12 @@ public function checkValidationRule($callback): void {
echo \json_encode($result);
}
}

public function applyInverted(){
$this->setParam('beforeCompileHtml', function ($elm) {
if (\method_exists($elm, 'setInverted')) {
$elm->setInverted(false);
}
});
}
}

0 comments on commit cbfe118

Please sign in to comment.