Re: more types stuff

Bo Daley <[email protected]>
Newsgroups gmane.comp.horde.whups
Message-ID <[email protected]>
Quoting Chuck Hagenbuch <[email protected]>:

> Also, could you submit a patch that adds a second step form, so that we don't
> get invalid state or priority data when this happens? Users should get a
> chance
> to make sure that the state/priority is still valid.

The more I look at this the more I tend to agree that types shouldn't change too
often. Given that states and priorities are different for each type there's no
really clean way to move between types (it would be nicer if states and
priorities
could be applied to types the same way that types can be applied to modules,
ie. many-to-many).

anyway for what it's worth here's a patch that adds the second step form
allowing users to select a new state and priority based on the new type.

thanks,

bo.


-- 
Whups mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]
details.php.diff (text/diff, 5 KB)
Index: details.php
===================================================================
RCS file: /repository/whups/details.php,v
retrieving revision 1.48
diff -u -r1.48 details.php
--- details.php	25 Jun 2003 19:54:33 -0000	1.48
+++ details.php	27 Jun 2003 08:59:25 -0000
@@ -30,6 +30,8 @@
 $RENDERER = &new Horde_Form_Renderer();
 $COMMENT = &new Comment();
 
+$showticketdetails = true;
+
 // Ticket actions.
 $ACTIONS = &new Actions();
 $ACTIONS->addAction(_("Add Comment"), 'details.php', 'ac');
@@ -202,13 +204,29 @@
 }
 
 //////// Set Type action
-if (Auth::isAdmin('whups:admin') && $form == 'settypeform') {
-    $settypeform = &Horde_Form::singleton('SetTypeForm', $vars);
+if (Auth::isAdmin('whups:admin') && $form == 'settypestep1form') {
+    $settypeform = &Horde_Form::singleton('SetTypeStep1Form', $vars);
+    $settypeform->validate($vars);
+
+    if ($settypeform->isValid()) {
+        if (Auth::isAdmin('whups:admin')) {
+            $action = 'st2';
+        } else {
+            $action = '';
+        }
+        
+    } else {
+        $action = 'st';
+    }
+}
+
+if (Auth::isAdmin('whups:admin') && $form == 'settypestep2form') {
+    $settypeform = &Horde_Form::singleton('SetTypeStep2Form', $vars);
     $settypeform->validate($vars);
 
     if ($settypeform->isValid()) {
         $settypeform->getInfo($vars, $info);
-        $comment_id = $whups->setTicketType($info);
+        $comment_id = $whups->setTicketType($info); 
         if (array_key_exists('group', $info)) {
             Whups::addCommentPerms($comment_id, $info['group']);
         }
@@ -266,12 +284,33 @@
 
  case 'st':
      if (Auth::isAdmin('whups:admin')) {
-         $form = &Horde_Form::singleton('SetTypeForm', $vars);
+         $form = &Horde_Form::singleton('SetTypeStep1Form', $vars);
      } else {
          $action = '';
      }
      break;
 
+case 'st2':
+    if (Auth::isAdmin('whups:admin')) {
+        $form1 = &Horde_Form::singleton('SetTypeStep1Form', $vars);
+        $form2 = &Horde_Form::singleton('SetTypeStep2Form', $vars);
+        $title = 'Set Type Step 2';
+        $showticketdetails = false;
+
+        $form1->preserve($vars);
+        $RENDERER->beginInactive('Set Type');
+        $RENDERER->renderFormInactive($form1, $vars);
+        $RENDERER->end();
+
+        $form2->open($RENDERER, $vars, 'details.php', 'post');
+        $RENDERER->beginActive('Set Type Step 2');
+        $RENDERER->renderFormActive($form2, $vars);
+        $RENDERER->submit();
+        $RENDERER->end();
+        $form2->close($RENDERER);
+    }
+    break;
+
  case 'at':
      if (Auth::getAuth()) {
          $form = &Horde_Form::singleton('AssignTicketForm', $vars);
@@ -287,7 +326,9 @@
  case 'gp': $form = &Horde_Form::singleton('GuestPriorityForm', $vars); break;
 }
 
-$title = $ACTIONS->getTitleFromAction($action);
+if (empty($title)) {
+    $title = $ACTIONS->getTitleFromAction($action);
+}
 
 if ($form != null) {
     $form->open($RENDERER, $vars, 'details.php', 'post');
@@ -298,32 +339,37 @@
     $form->close($RENDERER);
 }
 
-$ACTIONS->render($action);
+if ($showticketdetails) {
+
+    $ACTIONS->render($action);
 
-$form = &Horde_Form::singleton('TicketDetailsForm', $vars);
-$form->addAttributes($attributes);
-$details['user_id_requester'] = Whups::formatUser($details['user_id_requester']);
-$details['user_id_owner'] = Whups::getOwners($ticket);
-
-$RENDERER->beginInactive(sprintf(_("Ticket %s Details"), $ticket));
-$RENDERER->renderFormInactive($form, new Horde_Form_Vars($details));
-$RENDERER->end();
+    $form = &Horde_Form::singleton('TicketDetailsForm', $vars);
+    $form->addAttributes($attributes);
+    $details['user_id_requester'] = Whups::formatUser($details['user_id_requester']);
+    $details['user_id_owner'] = Whups::getOwners($ticket);
 
-$comments = Whups::permissionsFilter($whups->getComments($ticket),
+    $RENDERER->beginInactive(sprintf(_("Ticket %s Details"), $ticket));
+    $RENDERER->renderFormInactive($form, new Horde_Form_Vars($details));
+    $RENDERER->end();
+
+    $comments = Whups::permissionsFilter($whups->getComments($ticket),
                                      'comment', _PERMS_READ);
 
-$COMMENT->begin(sprintf(_("Ticket %s Comments"), $ticket));
-$cells = array();
-foreach ($comments as $key => $comment_values) {
-    $cells[] = $COMMENT->render(new Horde_Form_Vars($comment_values));
-}
-if ($prefs->getValue('comment_sort_dir')) {
-    $cells = array_reverse($cells);
-}
-echo implode('', $cells);
-$COMMENT->end();
+    $COMMENT->begin(sprintf(_("Ticket %s Comments"), $ticket));
+    $cells = array();
+    foreach ($comments as $key => $comment_values) {
+        $cells[] = $COMMENT->render(new Horde_Form_Vars($comment_values));
+    }
+    if ($prefs->getValue('comment_sort_dir')) {
+        $cells = array_reverse($cells);
+    }
+    echo implode('', $cells);
+    $COMMENT->end();
+    
+    if ($links->listLinkTypes()) {
+        $links->viewLinks(array('ticket_id' => $ticket));
+    }
 
-if ($links->listLinkTypes()) {
-    $links->viewLinks(array('ticket_id' => $ticket));
 }
+
 require WHUPS_TEMPLATES . '/common-footer.inc';
Search.php.diff (text/diff, 1.6 KB)
Index: Search.php
===================================================================
RCS file: /repository/whups/lib/Search.php,v
retrieving revision 1.53
diff -u -r1.53 Search.php
--- Search.php	25 Jun 2003 21:31:30 -0000	1.53
+++ Search.php	27 Jun 2003 09:00:44 -0000
@@ -337,9 +337,9 @@
 
 }
 
-class SetTypeForm extends Horde_Form {
+class SetTypeStep1Form extends Horde_Form {
 
-    function SetTypeForm(&$vars)
+    function SetTypeStep1Form(&$vars)
     {
         global $whups;
 
@@ -362,6 +362,37 @@
             }
             $this->addVariable(_("Viewable only by members of"), 'group', 'enum', true, false, null, array($grouplist));
         }
+    }
+
+    function validate(&$vars)
+    {
+        if (!Auth::getAuth()) {
+            $this->setError('_auth', _("Permission Denied."));
+        }
+
+        return parent::validate($vars);
+    }
+
+}
+
+class SetTypeStep2Form extends Horde_Form {
+
+    function SetTypeStep2Form(&$vars)
+    {
+        global $whups;
+
+        parent::Horde_Form($vars);
+
+        $this->addHidden('', 'id', 'int', true, true);
+        $this->addHidden('', 'group', 'int', true, true);
+        $this->addHidden('', 'type', 'int', true, true);
+        $this->addHidden('', 'newcomment', 'longtext', true, true);
+
+        /* Give user an opportunity to check that state and 
+        priority are still valid. */
+        $type = $vars->getVar('type');
+        $this->addVariable(_("State"), 'state', 'enum', true, false, null, array($whups->getStates($type)));
+        $this->addVariable(_("Priority"), 'priority', 'enum', true, false, null, array($whups->getPriorities($type)));
     }
 
     function validate(&$vars)
sql.php.diff (text/diff, 998 B)
Index: sql.php
===================================================================
RCS file: /repository/whups/lib/Driver/sql.php,v
retrieving revision 1.112
diff -u -r1.112 sql.php
--- sql.php	25 Jun 2003 21:31:31 -0000	1.112
+++ sql.php	27 Jun 2003 09:01:34 -0000
@@ -383,8 +383,14 @@
         $ticket_id = $info['id'];
         $newcomment = $info['newcomment'];
         $type = $info['type'];
+        $state = $info['state'];
+        $priority = $info['priority'];
 
-        $query = "UPDATE whups_tickets SET type_id = $type WHERE ticket_id = $ticket_id";
+        $query = "UPDATE whups_tickets 
+                  SET type_id = $type,
+                      state_id = $state, 
+                      priority_id = $priority 
+                  WHERE ticket_id = $ticket_id";
         Horde::logMessage('SQL Query by Whups_Driver_sql::setTicketType(): ' . $query, __FILE__, __LINE__, PEAR_LOG_DEBUG);
         $result = $this->_query($query);
         if (is_a($result, 'PEAR_Error')) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.