mirror of
https://github.com/processwire/processwire.git
synced 2025-08-24 15:23:11 +02:00
Fix issue processwire/processwire#1016 and some related minor optimizations
This commit is contained in:
@@ -163,14 +163,16 @@ class ProcessTemplate extends Process {
|
|||||||
|
|
||||||
$out = $this->getListFilterForm()->render() . "\n<div id='ProcessTemplateList'>\n";
|
$out = $this->getListFilterForm()->render() . "\n<div id='ProcessTemplateList'>\n";
|
||||||
$templatesByTag = array();
|
$templatesByTag = array();
|
||||||
$untaggedLabel = $this->_('Untagged');
|
$untaggedLabel = $this->_('Untagged'); // Tag applied to untagged fields
|
||||||
$hasFilters = $this->session->get('ProcessTemplateFilterField');
|
$systemLabel = $this->_x('System', 'tag'); // Tag applied to the group of built-in/system fields
|
||||||
|
$hasFilters = $this->session->getFor($this, 'filterField');
|
||||||
|
$showSystem = $this->session->getFor($this, 'filterSystem');
|
||||||
$collapsedTags = array();
|
$collapsedTags = array();
|
||||||
$caseTags = array(); // indexed by lowercase version of tag
|
$caseTags = array(); // indexed by lowercase version of tag
|
||||||
|
|
||||||
if(!$hasFilters) foreach($this->templates as $template) {
|
if(!$hasFilters) foreach($this->templates as $template) {
|
||||||
if($this->session->get('ProcessTemplateFilterSystem')) {
|
if($showSystem && ($template->flags & Template::flagSystem)) {
|
||||||
if($template->flags & Template::flagSystem) $template->tags .= " " . $this->_x('System', 'tag'); // Tag applied to the group of built-in/system fields
|
$template->tags .= " $systemLabel";
|
||||||
}
|
}
|
||||||
if(empty($template->tags)) {
|
if(empty($template->tags)) {
|
||||||
$tag = strtolower($untaggedLabel);
|
$tag = strtolower($untaggedLabel);
|
||||||
@@ -201,12 +203,14 @@ class ProcessTemplate extends Process {
|
|||||||
ksort($templatesByTag);
|
ksort($templatesByTag);
|
||||||
foreach($templatesByTag as $tag => $templates) {
|
foreach($templatesByTag as $tag => $templates) {
|
||||||
ksort($templates);
|
ksort($templates);
|
||||||
|
$table = $this->getListTable($templates);
|
||||||
|
if(!count($table->rows)) continue;
|
||||||
/** @var InputfieldMarkup $f */
|
/** @var InputfieldMarkup $f */
|
||||||
$f = $this->modules->get('InputfieldMarkup');
|
$f = $this->modules->get('InputfieldMarkup');
|
||||||
$f->entityEncodeLabel = false;
|
$f->entityEncodeLabel = false;
|
||||||
$f->label = $caseTags[$tag];
|
$f->label = $caseTags[$tag];
|
||||||
$f->icon = 'tags';
|
$f->icon = 'tags';
|
||||||
$f->value = $this->getListTable($templates)->render();
|
$f->value = $table->render();
|
||||||
if(in_array($tag, $collapsedTags)) $f->collapsed = Inputfield::collapsedYes;
|
if(in_array($tag, $collapsedTags)) $f->collapsed = Inputfield::collapsedYes;
|
||||||
$form->add($f);
|
$form->add($f);
|
||||||
}
|
}
|
||||||
@@ -243,8 +247,8 @@ class ProcessTemplate extends Process {
|
|||||||
$out .= $button->render();
|
$out .= $button->render();
|
||||||
|
|
||||||
if($this->input->get('nosave')) {
|
if($this->input->get('nosave')) {
|
||||||
$this->session->remove('ProcessTemplateFilterSystem');
|
$this->session->removeFor($this, 'filterSystem');
|
||||||
$this->session->remove('ProcessTemplateFilterField');
|
$this->session->removeFor($this, 'filterField');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
@@ -285,9 +289,9 @@ class ProcessTemplate extends Process {
|
|||||||
}
|
}
|
||||||
if($input->get('filter_field') !== null) {
|
if($input->get('filter_field') !== null) {
|
||||||
$filterField = $this->sanitizer->name($input->get('filter_field'));
|
$filterField = $this->sanitizer->name($input->get('filter_field'));
|
||||||
$this->session->set('ProcessTemplateFilterField', $filterField);
|
$this->session->setFor($this, 'filterField', $filterField);
|
||||||
} else {
|
} else {
|
||||||
$filterField = $this->session->get('ProcessTemplateFilterField');
|
$filterField = $this->session->getFor($this, 'filterField');
|
||||||
}
|
}
|
||||||
$field->attr('value', $filterField);
|
$field->attr('value', $filterField);
|
||||||
$field->collapsed = $filterField ? Inputfield::collapsedNo : Inputfield::collapsedYes;
|
$field->collapsed = $filterField ? Inputfield::collapsedNo : Inputfield::collapsedYes;
|
||||||
@@ -310,16 +314,20 @@ class ProcessTemplate extends Process {
|
|||||||
$field->icon = 'gear';
|
$field->icon = 'gear';
|
||||||
if($input->get('system') !== null) {
|
if($input->get('system') !== null) {
|
||||||
$filterSystem = (int) $input->get('system');
|
$filterSystem = (int) $input->get('system');
|
||||||
$this->session->set('ProcessTemplateFilterSystem', $filterSystem);
|
$this->session->setFor($this, 'filterSystem', $filterSystem);
|
||||||
} else {
|
} else {
|
||||||
$filterSystem = (int) $this->session->get('ProcessTemplateFilterSystem');
|
$filterSystem = (int) $this->session->getFor($this, 'filterSystem');
|
||||||
}
|
}
|
||||||
$field->attr('value', $filterSystem);
|
$field->attr('value', $filterSystem);
|
||||||
$field->collapsed = $filterSystem ? Inputfield::collapsedNo : Inputfield::collapsedYes;
|
$field->collapsed = $filterSystem ? Inputfield::collapsedNo : Inputfield::collapsedYes;
|
||||||
$fieldset->add($field);
|
$fieldset->add($field);
|
||||||
} else $filterSystem = 0;
|
} else {
|
||||||
|
$filterSystem = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if($filterSystem || $filterField) $fieldset->collapsed = Inputfield::collapsedNo;
|
if($filterSystem || $filterField) {
|
||||||
|
$fieldset->collapsed = Inputfield::collapsedNo;
|
||||||
|
}
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
@@ -408,8 +416,8 @@ class ProcessTemplate extends Process {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$filterField = $this->session->get('ProcessTemplateFilterField');
|
$filterField = $this->session->getFor($this, 'filterField');
|
||||||
$filterSystem = $this->session->get('ProcessTemplateFilterSystem');
|
$filterSystem = $this->session->getFor($this, 'filterSystem');
|
||||||
|
|
||||||
if($template->flags & Template::flagSystem) {
|
if($template->flags & Template::flagSystem) {
|
||||||
if(!$filterSystem && !$filterField) return array();
|
if(!$filterSystem && !$filterField) return array();
|
||||||
|
Reference in New Issue
Block a user