From fcb8af88459b1927bd03189073153d6e78e3c5ce Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 6 May 2015 16:04:19 -0500 Subject: [PATCH] oops: Fix field disable and form sorting on topic forms --- include/class.dynamic_forms.php | 21 ++++++++++++++++----- include/class.forms.php | 8 -------- include/staff/helptopic.inc.php | 33 ++++++++++++++++----------------- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 6709b7a75..43ae645c7 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -153,6 +153,14 @@ class DynamicForm extends VerySimpleModel { return $inst; } + function disableFields(array $ids) { + foreach ($this->getFields() as $F) { + if (in_array($F->get('id'), $ids)) { + $F->disable(); + } + } + } + function getTranslateTag($subtag) { return _H(sprintf('form.%s.%s', $subtag, $this->id)); } @@ -986,15 +994,18 @@ class DynamicFormEntry extends VerySimpleModel { function getForm() { if (!isset($this->_form)) { // XXX: Should source be $this? - $form = new SimpleForm($this->getFields(), $this->getSource(), + $fields = $this->getFields(); + if (isset($this->extra)) { + $x = JsonDataParser::decode($this->extra) ?: array(); + foreach ($x['disable'] ?: array() as $id) { + unset($fields[$id]); + } + } + $form = new SimpleForm($fields, $this->getSource(), array( 'title' => $this->getTitle(), 'instructions' => $this->getInstructions(), )); - if (isset($this->extra)) { - $x = JsonDataParser::decode($this->extra) ?: array(); - $form->disableFields($x['disable'] ?: array()); - } $this->_form = $form; } return $this->_form; diff --git a/include/class.forms.php b/include/class.forms.php index 602a5f4af..202948ed8 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -127,14 +127,6 @@ class Form { return $this->_clean; } - function disableFields(array $ids) { - foreach ($this->getFields() as $F) { - if (in_array($F->get('id'), $ids)) { - $F->disable(); - } - } - } - function errors($formOnly=false) { return ($formOnly) ? $this->_errors['form'] : $this->_errors; } diff --git a/include/staff/helptopic.inc.php b/include/staff/helptopic.inc.php index 834cc5a72..f6dbcfe7b 100644 --- a/include/staff/helptopic.inc.php +++ b/include/staff/helptopic.inc.php @@ -370,7 +370,7 @@ foreach ($forms as $F) { <th><?php echo __('Variable'); ?></th> </tr> <?php - foreach ($F->getFields() as $f) { ?> + foreach ($F->getDynamicFields() as $f) { ?> <tr> <td><input type="checkbox" name="fields[]" value="<?php echo $f->get('id'); ?>" <?php @@ -440,21 +440,20 @@ $(function() { } }); }); - + $('table#topic-forms').sortable({ + items: 'tbody', + handle: 'td.handle', + tolerance: 'pointer', + forcePlaceholderSize: true, + helper: function(e, ui) { + ui.children().each(function() { + $(this).children().each(function() { + $(this).width($(this).width()); + }); + }); + ui=ui.clone().css({'background-color':'white', 'opacity':0.8}); + return ui; + } + }).disableSelection(); }); -$('table#topic-forms').sortable({ - items: 'tbody', - handle: 'td.handle', - tolerance: 'pointer', - forcePlaceholderSize: true, - helper: function(e, ui) { - ui.children().each(function() { - $(this).children().each(function() { - $(this).width($(this).width()); - }); - }); - ui=ui.clone().css({'background-color':'white', 'opacity':0.8}); - return ui; - } -}).disableSelection(); </script> -- GitLab