diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 263850e0241efc86d4782a3ee19e9200af244654..c1b790ccb46410923fcd11364539bd0ed057ad4a 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -457,6 +457,10 @@ class DynamicFormEntry extends VerySimpleModel { var $_errors = false; var $_clean = false; + function getId() { + return $this->get('id'); + } + function getAnswers() { if (!isset($this->_values)) { $this->_values = DynamicFormEntryAnswer::objects() @@ -579,8 +583,8 @@ class DynamicFormEntry extends VerySimpleModel { ->filter(array('object_id'=>$org_id, 'object_type'=>'O')); } - function render($staff=true, $title=false) { - return $this->getForm()->render($staff, $title); + function render($staff=true, $title=false, $options=array()) { + return $this->getForm()->render($staff, $title, $options); } /** diff --git a/include/class.forms.php b/include/class.forms.php index 42f4651a1debd6fd0234244ef6f9f1f6aec10ea7..4eeed67e73c36e51ae944873698a701eb34b4a1e 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -99,11 +99,11 @@ class Form { return $this->_errors; } - function render($staff=true, $title=false, $instructions=false) { + function render($staff=true, $title=false, $options=array()) { if ($title) $this->title = $title; - if ($instructions) - $this->instructions = $instructions; + if (isset($options['instructions'])) + $this->instructions = $options['instructions']; $form = $this; if ($staff) include(STAFFINC_DIR . 'templates/dynamic-form.tmpl.php'); diff --git a/include/staff/templates/dynamic-form.tmpl.php b/include/staff/templates/dynamic-form.tmpl.php index a1fee6a9befab48c7cd801a36156432f0418defe..e6afae15a37d7b1ebb80eafa8fb1e341e6c98672 100644 --- a/include/staff/templates/dynamic-form.tmpl.php +++ b/include/staff/templates/dynamic-form.tmpl.php @@ -1,8 +1,35 @@ -<tr><td style="width:150px"></td><td></td></tr> +<?php +// If the form was removed using the trashcan option, and there was some +// other validation error, don't render the deleted form the second time +if (isset($options['entry']) && $options['mode'] == 'edit' + && $_POST + && ($_POST['forms'] && !in_array($options['entry']->getId(), $_POST['forms'])) +) + return; +?> +<tbody> +<?php +// Keep up with the entry id in a hidden field to decide what to add and +// delete when the parent form is submitted +if (isset($options['entry']) && $options['mode'] == 'edit') { ?> + <input type="hidden" name="forms[]" value="<?php + echo $options['entry']->getId(); ?>" /> +<?php } ?> <?php if ($form->getTitle()) { ?> <tr><th colspan="2"> <em><strong><?php echo Format::htmlchars($form->getTitle()); ?></strong>: - <?php echo Format::htmlchars($form->getInstructions()); ?></em> + <?php echo Format::htmlchars($form->getInstructions()); ?> +<?php if ($options['mode'] == 'edit') { ?> + <div class="pull-right"> + <?php if ($options['entry'] + && $options['entry']->getForm()->get('type') == 'G') { ?> + <a href="#" title="Delete Entry" onclick="javascript: + $(this).closest('tbody').remove(); + return false;"><i class="icon-trash"></i></a> + <?php } ?> + <i class="icon-sort" title="Drag to Sort"></i> + </div> +<?php } ?></em> </th></tr> <?php } @@ -13,7 +40,9 @@ <?php } else { ?> - <td class="multi-line <?php if ($field->get('required')) echo 'required'; ?>" style="min-width:120px;"> + <td class="multi-line <?php if ($field->get('required')) echo 'required'; + ?>" style="min-width:120px;" <?php if ($options['width']) + echo "width=\"{$options['width']}\""; ?>> <?php echo Format::htmlchars($field->get('label')); ?>:</td> <td><div style="position:relative"><?php } @@ -49,6 +78,5 @@ <?php } ?> </div></td> </tr> - <?php - } -?> + <?php } ?> +</tbody> diff --git a/include/staff/ticket-edit.inc.php b/include/staff/ticket-edit.inc.php index e60f275c2633c237a51f91eeab1b048bf0abf980..299835b3734d270cbd9e62a73d7fc73bf872c329 100644 --- a/include/staff/ticket-edit.inc.php +++ b/include/staff/ticket-edit.inc.php @@ -128,14 +128,16 @@ if ($_POST) <em>Time is based on your time zone (GMT <?php echo $thisstaff->getTZoffset(); ?>)</em> </td> </tr> - </tbody> - <tbody id="dynamic-form"> + </tbody> +</table> +<table class="form_table dynamic-forms" width="940" border="0" cellspacing="0" cellpadding="2"> <?php if ($forms) foreach ($forms as $form) { - $form->render(true); + $form->render(true, false, array('mode'=>'edit','width'=>160,'entry'=>$form)); } ?> - </tbody> - <tbody> +</table> +<table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> + <tbody> <tr> <th colspan="2"> <em><strong>Internal Note</strong>: Reason for editing the ticket (required) <font class="error"> <?php echo $errors['note'];?></font></em> @@ -159,3 +161,18 @@ if ($_POST) <div style="display:none;" class="dialog draggable" id="user-lookup"> <div class="body"></div> </div> +<script type="text/javascript"> +$('table.dynamic-forms').sortable({ + items: 'tbody', + handle: 'th', + 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; + } +}); +</script> diff --git a/scp/css/scp.css b/scp/css/scp.css index d94b3d0b48d49548c6ca0de48136f46bfc6916d4..55b706178234fb2d8a20134cbb55f35553176d2c 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -1592,7 +1592,7 @@ div.selected-signature .inner { .sortable-row-item { border: 1px solid rgba(0, 0, 0, 0.7); padding: 9px; - cursor: crosshair; + cursor: move; position: relative; } .sortable-row-item:hover { diff --git a/scp/tickets.php b/scp/tickets.php index f679f5035a2355ef80482f4a8084f09975c25427..2a8c9e6ee4938a4a19ea57812c0a5559499f4255 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -198,16 +198,30 @@ if($_POST && !$errors): case 'edit': case 'update': $forms=DynamicFormEntry::forTicket($ticket->getId()); - foreach ($forms as $form) - if (!$form->isValid()) + foreach ($forms as $form) { + // Don't validate deleted forms + if (!in_array($form->getId(), $_POST['forms'])) + continue; + elseif (!$form->isValid()) $errors = array_merge($errors, $form->errors()); + } if(!$ticket || !$thisstaff->canEditTickets()) $errors['err']='Permission Denied. You are not allowed to edit tickets'; elseif($ticket->update($_POST,$errors)) { $msg='Ticket updated successfully'; $_REQUEST['a'] = null; //Clear edit action - going back to view. //Check to make sure the staff STILL has access post-update (e.g dept change). - foreach ($forms as $f) $f->save(); + foreach ($forms as $f) { + // Drop deleted forms + $idx = array_search($f->getId(), $_POST['forms']); + if ($idx === false) { + $f->delete(); + } + else { + $f->set('sort', $idx); + $f->save(); + } + } if(!$ticket->checkStaffAccess($thisstaff)) $ticket=null; } elseif(!$errors['err']) {