From 453fdcc1bc17347201bcdcda2bf8d8677375f8cb Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 9 Apr 2014 18:10:36 -0500 Subject: [PATCH] forms: Add form management to organizations --- include/ajax.orgs.php | 43 ++++++++++++++++++++ include/ajax.tickets.php | 2 + include/class.organization.php | 8 ++++ include/staff/org-view.inc.php | 22 ++++++++++ include/staff/templates/form-manage.tmpl.php | 4 +- scp/ajax.php | 4 +- 6 files changed, 80 insertions(+), 3 deletions(-) diff --git a/include/ajax.orgs.php b/include/ajax.orgs.php index 3b187b18d..7737f57c1 100644 --- a/include/ajax.orgs.php +++ b/include/ajax.orgs.php @@ -252,5 +252,48 @@ class OrgsAjaxAPI extends AjaxController { return $resp; } + + function manageForms($org_id) { + $forms = DynamicFormEntry::forOrganization($org_id); + $info = array('action' => '#orgs/'.Format::htmlchars($org_id).'/forms/manage'); + include(STAFFINC_DIR . 'templates/form-manage.tmpl.php'); + } + + function updateForms($org_id) { + global $thisstaff; + + if (!$thisstaff) + Http::response(403, "Login required"); + elseif (!($org = Organization::lookup($org_id))) + Http::response(404, "No such ticket"); + elseif (!isset($_POST['forms'])) + Http::response(422, "Send updated forms list"); + + // Add new forms + $forms = DynamicFormEntry::forOrganization($org_id); + foreach ($_POST['forms'] as $sort => $id) { + $found = false; + foreach ($forms as $e) { + if ($e->get('form_id') == $id) { + $e->set('sort', $sort); + $e->save(); + $found = true; + break; + } + } + // New form added + if (!$found && ($new = DynamicForm::lookup($id))) { + $org->addForm($new, $sort); + } + } + + // Deleted forms + foreach ($forms as $idx => $e) { + if (!in_array($e->get('form_id'), $_POST['forms'])) + $e->delete(); + } + + Http::response(201, 'Successfully managed'); + } } ?> diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 75e43fc4c..016882de1 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -613,6 +613,8 @@ class TicketsAjaxAPI extends AjaxController { } function manageForms($ticket_id) { + $forms = DynamicFormEntry::forTicket($ticket_id); + $info = array('action' => '#tickets/'.Format::htmlchars($ticket_id).'/forms/manage'); include(STAFFINC_DIR . 'templates/form-manage.tmpl.php'); } diff --git a/include/class.organization.php b/include/class.organization.php index 3801bba3a..81937964e 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -185,6 +185,14 @@ class Organization extends OrganizationModel { } } + function addForm($form, $sort=1) { + $form = $form->instanciate(); + $form->set('sort', $sort); + $form->set('object_type', 'O'); + $form->set('object_id', $this->getId()); + $form->save(); + } + function to_json() { $info = array( diff --git a/include/staff/org-view.inc.php b/include/staff/org-view.inc.php index e866e4b5c..c19a42efa 100644 --- a/include/staff/org-view.inc.php +++ b/include/staff/org-view.inc.php @@ -9,8 +9,21 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($org)) die('Invalid path') title="Reload"><i class="icon-refresh"></i> <?php echo $org->getName(); ?></a></h2> </td> <td width="50%" class="right_align has_bottom_border"> + <span class="action-button" data-dropdown="#action-dropdown-more"> + <span ><i class="icon-cog"></i> More</span> + <i class="icon-caret-down"></i> + </span> <a id="org-delete" class="action-button org-action" href="#orgs/<?php echo $org->getId(); ?>/delete"><i class="icon-trash"></i> Delete Organization</a> + <div id="action-dropdown-more" class="action-dropdown anchor-right"> + <ul> + <li><a href="#ajax.php/orgs/<?php echo $org->getId(); + ?>/forms/manage" onclick="javascript: + $.dialog($(this).attr('href').substr(1), 201); + return false" + ><i class="icon-paste"></i> Manage Forms</a></li> + </ul> + </div> </td> </tr> </table> @@ -55,6 +68,8 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($org)) die('Invalid path') class="icon-list-alt"></i> Tickets</a></li> <li><a id="notes_tab" href="#notes"><i class="icon-pushpin"></i> Notes</a></li> + <li><a id="forms_tab" href="#fields"><i + class="icon-paste"></i> Fields</a></li> </ul> <div class="tab_content" id="users"> <?php @@ -66,6 +81,13 @@ include STAFFINC_DIR . 'templates/users.tmpl.php'; include STAFFINC_DIR . 'templates/tickets.tmpl.php'; ?> </div> +<div class="tab_content" id="fields" style="display:none"> + <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> +<?php foreach ($org->getDynamicData() as $form) { + $form->render(true, false, array('mode'=>'edit','width'=>160,'entry'=>$form)); +} ?> + </table> +</div> <div class="tab_content" id="notes" style="display:none"> <?php diff --git a/include/staff/templates/form-manage.tmpl.php b/include/staff/templates/form-manage.tmpl.php index 5e59011df..52f670e91 100644 --- a/include/staff/templates/form-manage.tmpl.php +++ b/include/staff/templates/form-manage.tmpl.php @@ -5,11 +5,11 @@ Sort the forms on this ticket by click and dragging on them. Use the box below the forms list to add new forms to the ticket. <br/> <br/> -<form method="post" action="#tickets/<?php echo $ticket_id; ?>/forms/manage"> +<form method="post" action="<?php echo $info['action']; ?>"> <div id="ticket-entries"> <?php $current_list = array(); -foreach (DynamicFormEntry::forTicket($ticket_id) as $e) { ?> +foreach ($forms as $e) { ?> <div class="sortable-row-item" data-id="<?php echo $e->get('id'); ?>"> <input type="hidden" name="forms[]" value="<?php echo $e->get('form_id'); ?>" /> <i class="icon-reorder"></i> <?php echo $e->getForm()->getTitle(); diff --git a/scp/ajax.php b/scp/ajax.php index 2dd902087..98dd7f132 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -112,7 +112,9 @@ $dispatcher = patterns('', url('^/(?P<id>\d+)/import-users$', 'importUsers'), url_get('^/(?P<id>\d+)/delete$', 'delete'), url_delete('^/(?P<id>\d+)/delete$', 'delete'), - url_post('^/(?P<id>\d+)/note$', 'createNote') + url_post('^/(?P<id>\d+)/note$', 'createNote'), + url_get('^/(?P<id>\d+)/forms/manage$', 'manageForms'), + url_post('^/(?P<id>\d+)/forms/manage$', 'updateForms') )), url('^/tickets/', patterns('ajax.tickets.php:TicketsAjaxAPI', url_get('^(?P<tid>\d+)/change-user$', 'changeUserForm'), -- GitLab