Skip to content
Snippets Groups Projects
Commit 24dc24db authored by aydreeihn's avatar aydreeihn
Browse files

Changes for saving Filter Actions:

- Save Filter Actions at the top of Filter::save
- Validate the Filter Actions before commiting the save

This is done to fix the issue where Depts/HT's said 'Unchanged' when initially saved. Now their configuration is set correctly before doing additional validations for active depts/hts
parent 3171aa0c
Branches
Tags
No related merge requests found
...@@ -471,24 +471,28 @@ class Filter { ...@@ -471,24 +471,28 @@ class Filter {
} }
function save($id,$vars,&$errors) { function save($id,$vars,&$errors) {
//get current filter actions (they're validated before saving)
self::save_actions($id, $vars, $errors);
if ($this) { if ($this) {
foreach ($this->getActions() as $A) { foreach ($this->getActions() as $A) {
$config = JsonDataParser::parse($A->configuration);
if ($A->type == 'dept') { if ($A->type == 'dept') {
$dept = Dept::lookup($A->parseConfiguration($vars)['dept_id']); $dept = Dept::lookup($config['dept_id']);
$dept_action = $A->getId(); $dept_action = $A->getId();
} }
if ($A->type == 'topic') { if ($A->type == 'topic') {
$topic = Topic::lookup($A->parseConfiguration($vars)['topic_id']); $topic = Topic::lookup($config['topic_id']);
$topic_action = $A->getId(); $topic_action = $A->getId();
} }
} }
} }
if($dept && !$dept->isActive() && !in_array('D' . $dept_action,$vars['actions'])) if($dept && !$dept->isActive() && (is_array($vars['actions']) && !in_array('D' . $dept_action,$vars['actions'])))
$errors['err'] = sprintf(__('%s selected for %s must be active'), __('Department'), __('Filter Action')); $errors['err'] = sprintf(__('%s selected for %s must be active'), __('Department'), __('Filter Action'));
if($topic && !$topic->isActive() && !in_array('D' . $topic_action,$vars['actions'])) if($topic && !$topic->isActive() && (is_array($vars['actions']) && !in_array('D' . $topic_action,$vars['actions'])))
$errors['err'] = sprintf(__('%s selected for %s must be active'), __('Help Topic'), __('Filter Action')); $errors['err'] = sprintf(__('%s selected for %s must be active'), __('Help Topic'), __('Filter Action'));
if(!$vars['execorder']) if(!$vars['execorder'])
...@@ -547,7 +551,6 @@ class Filter { ...@@ -547,7 +551,6 @@ class Filter {
# Don't care about errors stashed in $xerrors # Don't care about errors stashed in $xerrors
$xerrors = array(); $xerrors = array();
self::save_rules($id,$vars,$xerrors); self::save_rules($id,$vars,$xerrors);
self::save_actions($id, $vars, $errors);
return count($errors) == 0; return count($errors) == 0;
} }
...@@ -555,20 +558,31 @@ class Filter { ...@@ -555,20 +558,31 @@ class Filter {
function validate_actions($action) { function validate_actions($action) {
$errors = array(); $errors = array();
$config = json_decode($action->ht['configuration'], true); $config = json_decode($action->ht['configuration'], true);
if ($action->ht['type'] == 'dept') { switch ($action->ht['type']) {
$dept = Dept::lookup($config['dept_id']); case 'dept':
if (!$dept || !$dept->isActive()) { $dept = Dept::lookup($config['dept_id']);
$errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Department'); if (!$dept || !$dept->isActive()) {
return $errors; $errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Department');
} return $errors;
} }
break;
if ($action->ht['type'] == 'topic') { case 'topic':
$topic = Topic::lookup($config['topic_id']); $topic = Topic::lookup($config['topic_id']);
if (!$topic || !$topic->isActive()) { if (!$topic || !$topic->isActive()) {
$errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Help Topic'); $errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Help Topic');
return $errors; return $errors;
} }
break;
default:
foreach ($config as $key => $value) {
if (!$value) {
$errors['err'] = sprintf(__('Unable to save: Please insert a value for %s'), ucfirst($action->ht['type']));
return $errors;
}
}
break;
} }
return false; return false;
...@@ -597,7 +611,6 @@ class Filter { ...@@ -597,7 +611,6 @@ class Filter {
'sort' => (int) $sort, 'sort' => (int) $sort,
)); ));
$I->setConfiguration($errors, $vars); $I->setConfiguration($errors, $vars);
$config = json_decode($I->ht['configuration'], true);
$invalid = self::validate_actions($I); $invalid = self::validate_actions($I);
if ($invalid) { if ($invalid) {
...@@ -611,8 +624,6 @@ class Filter { ...@@ -611,8 +624,6 @@ class Filter {
if ($I = FilterAction::lookup($info)) { if ($I = FilterAction::lookup($info)) {
$I->setConfiguration($errors, $vars); $I->setConfiguration($errors, $vars);
$config = json_decode($I->ht['configuration'], true);
$invalid = self::validate_actions($I); $invalid = self::validate_actions($I);
if ($invalid) { if ($invalid) {
$errors['err'] = sprintf($invalid['err']); $errors['err'] = sprintf($invalid['err']);
......
...@@ -240,17 +240,16 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -240,17 +240,16 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
if ($filter) { foreach ($filter->getActions() as $A) { if ($filter) { foreach ($filter->getActions() as $A) {
$_warn = ''; $_warn = '';
$existing[] = $A->type; $existing[] = $A->type;
$config = JsonDataParser::parse($A->configuration);
if($A->type == 'dept') { if($A->type == 'dept') {
$errors['topic_id'] = ''; $errors['topic_id'] = '';
$dept_config = $A->parseConfiguration($_POST); $dept = Dept::lookup($config['dept_id']);
$dept = Dept::lookup($dept_config['dept_id']);
if($dept && !$dept->isActive()) if($dept && !$dept->isActive())
$_warn = sprintf(__('%s must be active'), __('Department')); $_warn = sprintf(__('%s must be active'), __('Department'));
} }
elseif($A->type == 'topic') { elseif($A->type == 'topic') {
$errors['dept_id'] = ''; $errors['dept_id'] = '';
$topic_config = $A->parseConfiguration($_POST); $topic = Topic::lookup($config['topic_id']);
$topic = Topic::lookup($topic_config['topic_id']);
if($topic && !$topic->isActive()) if($topic && !$topic->isActive())
$_warn = sprintf(__('%s must be active'), __('Help Topic')); $_warn = sprintf(__('%s must be active'), __('Help Topic'));
} }
......
...@@ -120,11 +120,12 @@ $tip_namespace = 'manage.filter'; ...@@ -120,11 +120,12 @@ $tip_namespace = 'manage.filter';
if($filter || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) { if($filter || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) {
if($filter) { if($filter) {
foreach ($filter->getActions() as $A) { foreach ($filter->getActions() as $A) {
$config = JsonDataParser::parse($A->configuration);
if($A->type == 'dept') if($A->type == 'dept')
$dept = Dept::lookup($A->parseConfiguration($_POST)['dept_id']); $dept = Dept::lookup($config['dept_id']);
if($A->type == 'topic') if($A->type == 'topic')
$topic = Topic::lookup($A->parseConfiguration($_POST)['topic_id']); $topic = Topic::lookup($config['topic_id']);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment