Skip to content

Commit

Permalink
ks filter: sync proxy value for text input; remove label from popover
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Oct 14, 2018
1 parent 1566922 commit b411ae1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,22 @@ protected function renderInputFieldWithContext(Template $input_tpl, Input $input
* a name source)?");
* } */
if ($input->getName()) {
$tpl->setVariable("NAME", $input->getName());
// $tpl->setVariable("NAME", $input->getName());
} else {
$tpl->setVariable("NAME", "");
// $tpl->setVariable("NAME", "");
}

$tpl->setVariable("LABEL", $input->getLabel());
// $tpl->setVariable("LABEL", $input->getLabel());
$tpl->setVariable("INPUT", $this->renderInputField($input_tpl, $input));

if ($input->getByline() !== null) {
$tpl->setCurrentBlock("byline");
$tpl->setVariable("BYLINE", $input->getByline());
$tpl->parseCurrentBlock();
// $tpl->setCurrentBlock("byline");
// $tpl->setVariable("BYLINE", $input->getByline());
// $tpl->parseCurrentBlock();
}

if ($input->isRequired()) {
$tpl->touchBlock("required");
// $tpl->touchBlock("required");
}


Expand All @@ -178,12 +178,24 @@ protected function renderInputFieldWithContext(Template $input_tpl, Input $input
*/
protected function renderInputField(Template $tpl, Input $input) {

$tpl->setVariable("NAME", $input->getName());

if ($input->getValue() !== null) {
$tpl->setCurrentBlock("value");
$tpl->setVariable("VALUE", $input->getValue());
$tpl->parseCurrentBlock();
switch (true) {
case ($input instanceof Text):
$tpl->setVariable("NAME", $input->getName());

if ($input->getValue() !== null) {
$tpl->setCurrentBlock("value");
$tpl->setVariable("VALUE", $input->getValue()."::");
$tpl->parseCurrentBlock();
}

$input = $input->withAdditionalOnLoadCode(function ($id) {
$code = "$('#$id').on('input', function(event) {
il.UI.filter.handleChange(event, '$id', $('#$id').val());
});";
return $code;
});
$this->maybeRenderId($input, $tpl);
break;
}

return $tpl->get();
Expand Down Expand Up @@ -217,15 +229,23 @@ protected function renderAddField(RendererInterface $default_renderer) {
* @param Component\JavascriptBindable $component
* @param Template $tpl
*/
protected function maybeRenderId(Component\Component $component, $tpl) {
protected function maybeRenderId(Component\JavascriptBindable $component, $tpl) {
$id = $this->bindJavaScript($component);
if ($id !== null) {
$tpl->setCurrentBlock("with_id");
$tpl->setCurrentBlock("id");
$tpl->setVariable("ID", $id);
$tpl->parseCurrentBlock();
}
}

/**
* @inheritdoc
*/
public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry) {
parent::registerResources($registry);
$registry->register('./src/UI/templates/js/Input/Container/filter.js');
}


/**
* @inheritdoc
Expand Down
4 changes: 4 additions & 0 deletions src/UI/Implementation/Component/Input/Field/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
namespace ILIAS\UI\Implementation\Component\Input\Field;

use ILIAS\UI\Component as C;
use ILIAS\UI\Implementation\Component\JavaScriptBindable;
use ILIAS\UI\Implementation\Component\Triggerer;

/**
* This implements the text input.
*/
class Text extends Input implements C\Input\Field\Text {
use JavaScriptBindable;
use Triggerer;

/**
* @inheritdoc
Expand Down
3 changes: 1 addition & 2 deletions src/UI/templates/default/Input/tpl.context_form.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<div class="form-group row">
<label for="{NAME}" class="control-label col-sm-3">{LABEL}<!-- BEGIN required --><span class="asterisk">*</span><!-- END required --></label>
<div class="col-sm-9">
<div class="col-sm-12">
{INPUT}
<!-- BEGIN byline --><div class="help-block">{BYLINE}</div><!-- END byline -->
<!-- BEGIN error --><div class="help-block alert alert-danger" role="alert">
Expand Down
2 changes: 1 addition & 1 deletion src/UI/templates/default/Input/tpl.filter_field.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<span role="button" tabindex="0" class="form-control il-filter-field" <!-- BEGIN with_id -->id="{ID}"<!-- END with_id --> data-placement="bottom"></span> {POPOVER}
<span role="button" tabindex="0" class="form-control il-filter-field" <!-- BEGIN id -->id="{ID}"<!-- END id --> data-placement="bottom"></span> {POPOVER}
2 changes: 1 addition & 1 deletion src/UI/templates/default/Input/tpl.text.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<input type="text"<!-- BEGIN value --> value="{VALUE}"<!-- END value --> name="{NAME}" class="form-control form-control-sm" />
<input <!-- BEGIN id --> id="{ID}"<!-- END id --> type="text"<!-- BEGIN value --> value="{VALUE}"<!-- END value --> name="{NAME}" class="form-control form-control-sm" />
32 changes: 32 additions & 0 deletions src/UI/templates/js/Input/Container/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Filter
*
* @author <[email protected]>
*/

var il = il || {};
il.UI = il.UI || {};

(function($, UI) {

UI.filter = (function ($) {
/**
*
* @param event
* @param id
* @param value_as_string
*/
var handleChange = function(event, id, value_as_string) {
var pop_id = $("#" + id).parents(".il-popover").attr("id");
$("span[data-target='" + pop_id + "']").html(value_as_string);
};

/**
* Public interface
*/
return {
handleChange: handleChange
};

})($);
})($, il.UI);

0 comments on commit b411ae1

Please sign in to comment.