diff --git a/include/ajax.search.php b/include/ajax.search.php index 2d9b3cea814a70f9ffa323cba7ebbf4020c69527..f886875b71ec6acf6649babf361ee86ffbdc28ea 100644 --- a/include/ajax.search.php +++ b/include/ajax.search.php @@ -297,7 +297,7 @@ class SearchAjaxAPI extends AjaxController { list($label, $F) = $fields[$field]; $column = QueueColumn::create(array( "id" => (int) $_GET['id'], - "heading" => _S($field->getLabel()), + "heading" => _S($F->getLabel()), "primary" => $field, "width" => 100, )); @@ -308,6 +308,7 @@ class SearchAjaxAPI extends AjaxController { // Send back the goodies Http::response(200, $this->encode(array( 'config' => $config, + 'id' => $column->id, 'heading' => _S($F->getLabel()), 'width' => $column->getWidth(), )), 'application/json'); diff --git a/include/class.queue.php b/include/class.queue.php index 05f0c75eaa173c471e29fdcffcccd93636d595af..f3c2b772166253b62dbc52708bf04401bf136cf6 100644 --- a/include/class.queue.php +++ b/include/class.queue.php @@ -252,15 +252,22 @@ class CustomQueue extends SavedSearch { // Update queue columns (but without save) if (isset($vars['columns'])) { - foreach ($vars['columns'] as $sort=>$colid) { - // Try and find the column in this queue, if it's a new one, - // add it to the columns list - if (!($col = $this->columns->findFirst(array('id' => $colid)))) { - $col = QueueColumn::create(array("id" => $colid, "queue" => $this)); - $this->addColumn($col); + $new = $vars['columns']; + foreach ($this->columns as $col) { + if (false === ($sort = array_search($col->id, $vars['columns']))) { + $this->columns->remove($col); + continue; } $col->set('sort', $sort+1); $col->update($vars, $errors); + unset($new[$sort]); + } + // Add new columns + foreach ($new as $sort=>$colid) { + $col = QueueColumn::create(array("id" => $colid, "queue" => $this)); + $col->set('sort', $sort+1); + $col->update($vars, $errors); + $this->addColumn($col); } // Re-sort the in-memory columns array $this->columns->sort(function($c) { return $c->sort; }); @@ -477,7 +484,7 @@ class QueueColumnCondition { // Add the annotation to a QuerySet function annotate($query) { - $Q = $this->getSearchQ(); + $Q = $this->getSearchQ($query); // Add an annotation to the query return $query->annotate(array( @@ -506,12 +513,24 @@ class QueueColumnCondition { return $name; } - function getSearchQ() { + function getSearchQ($query) { list($name, $method, $value) = $this->config['crit']; + // XXX: Move getOrmPath to be more of a utility + // Ensure the special join is created to support custom data joins + $name = @QueueColumn::getOrmPath($name, $query); + + $name2 = null; + if (preg_match('/__answers!\d+__/', $name)) { + // Ensure that only one record is returned from the join through + // the entry and answers joins + $name2 = $this->getAnnotationName().'2'; + $query->annotate(array($name2 => SqlAggregate::MAX($name))); + } + // Fetch a criteria Q for the query if ($field = $this->getField($name)) - return $field->getSearchQ($method, $value, $name); + return $field->getSearchQ($method, $value, $name2 ?: $name); } /** diff --git a/include/staff/queue.inc.php b/include/staff/queue.inc.php index 9a23e1f3ed81f1bd6c19b04d1f56c062a6a2a926..ff03e04d2a29b2ffc4a8b14cb018cc5b733b7fb7 100644 --- a/include/staff/queue.inc.php +++ b/include/staff/queue.inc.php @@ -32,11 +32,10 @@ else { <h2><a href="settings.php?t=tickets#queues"><?php echo __('Ticket Queues'); ?></a> // <?php echo $title; ?> <?php if (isset($queue->id)) { ?><small> - — <?php echo $queue->getName(); ?></small> + — <?php echo $queue->getFullName(); ?></small> <?php } ?> </h2> - <ul class="clean tabs"> <li class="active"><a href="#criteria"><i class="icon-filter"></i> <?php echo __('Criteria'); ?></a></li> @@ -81,7 +80,7 @@ else { ?> <option value="<?php echo $cq->id; ?>" <?php if ($cq->getId() == $queue->parent_id) echo 'selected="selected"'; ?> - ><?php echo $cq->getName(); ?></option> + ><?php echo $cq->getFullName(); ?></option> <?php } ?> </select> @@ -134,7 +133,8 @@ else { var div = $('<div></div>') .addClass('column-header ui-resizable') .text(json.heading) - .data({id: nextId, colId: 'colconfig-'+nextId, width: json.width}) + .attr({'data-id': nextId}) + .data({colId: 'colconfig-'+nextId, width: json.width}) .append($('<i>') .addClass('icon-ellipsis-vertical ui-resizable-handle ui-resizable-handle-e') ) diff --git a/include/staff/queues-ticket.inc.php b/include/staff/queues-ticket.inc.php index dfbfbf8b5360cef73786e3041fc759d5c3b175df..33cb32a2a308ef5bb6621d7745a5e728fe60ddaf 100644 --- a/include/staff/queues-ticket.inc.php +++ b/include/staff/queues-ticket.inc.php @@ -40,8 +40,8 @@ require_once INCLUDE_DIR . 'class.queue.php'; <table class="list" border="0" cellspacing="1" cellpadding="0" width="940"> <thead> <tr> - <th width="4%"> </th> - <th colspan="5" width="46%"><?php echo __('Name');?></th> + <th width="3%"> </th> + <th colspan="5" width="47%"><?php echo __('Name');?></th> <th width="12%"><?php echo __('Creator');?></th> <th width="8%"><?php echo __('Status');?></th> <th width="10%" nowrap><?php echo __('Created');?></th> @@ -62,7 +62,7 @@ $emitLevel = function($queues, $level=0) use ($all_queues, &$emitLevel) { <input type="hidden" name="qsort[<?php echo $q->id; ?>]" value="<?php echo $q->sort; ?>"/> </td> - <td colspan="<?php echo max(1, 5-$level); ?>"><a + <td width="63%" colspan="<?php echo max(1, 5-$level); ?>"><a href="queues.php?id=<?php echo $q->getId(); ?>"><?php echo Format::htmlchars($q->getFullName()); ?></a></td> <td><?php echo Format::htmlchars($q->staff->getName()); ?></td> diff --git a/include/staff/templates/queue-column.tmpl.php b/include/staff/templates/queue-column.tmpl.php index 65b2513389bacb51e5e808bdb5d6fbce8d8abd7c..6d1d54520d604f10275e48571ee098f20adb2404 100644 --- a/include/staff/templates/queue-column.tmpl.php +++ b/include/staff/templates/queue-column.tmpl.php @@ -11,6 +11,11 @@ $data_form = $column->getDataConfigForm($_POST); <li class="active"><a href="#<?php echo $colid; ?>-data"><?php echo __('Data'); ?></a></li> <li><a href="#<?php echo $colid; ?>-annotations"><?php echo __('Annotations'); ?></a></li> <li><a href="#<?php echo $colid; ?>-conditions"><?php echo __('Conditions'); ?></a></li> + <a onclick="javascript: + $(this).closest('.column-configuration').hide(); + $('#resizable-columns').find('div[data-id=<?php echo $colid; ?>]').hide() + .find('input[name^=columns]').remove(); + " class="button red pull-right"><?php echo __("Delete Column"); ?></a> </ul> <div class="tab_content" id="<?php echo $colid; ?>-data">