Skip to content
Snippets Groups Projects
Commit 03639c1b authored by Jared Hancock's avatar Jared Hancock Committed by Peter Rotich
Browse files

queue: Implement deleting columns

And also fixup custom data fields used in conditions
parent 8b9eb44f
No related branches found
No related tags found
No related merge requests found
...@@ -297,7 +297,7 @@ class SearchAjaxAPI extends AjaxController { ...@@ -297,7 +297,7 @@ class SearchAjaxAPI extends AjaxController {
list($label, $F) = $fields[$field]; list($label, $F) = $fields[$field];
$column = QueueColumn::create(array( $column = QueueColumn::create(array(
"id" => (int) $_GET['id'], "id" => (int) $_GET['id'],
"heading" => _S($field->getLabel()), "heading" => _S($F->getLabel()),
"primary" => $field, "primary" => $field,
"width" => 100, "width" => 100,
)); ));
...@@ -308,6 +308,7 @@ class SearchAjaxAPI extends AjaxController { ...@@ -308,6 +308,7 @@ class SearchAjaxAPI extends AjaxController {
// Send back the goodies // Send back the goodies
Http::response(200, $this->encode(array( Http::response(200, $this->encode(array(
'config' => $config, 'config' => $config,
'id' => $column->id,
'heading' => _S($F->getLabel()), 'heading' => _S($F->getLabel()),
'width' => $column->getWidth(), 'width' => $column->getWidth(),
)), 'application/json'); )), 'application/json');
......
...@@ -252,15 +252,22 @@ class CustomQueue extends SavedSearch { ...@@ -252,15 +252,22 @@ class CustomQueue extends SavedSearch {
// Update queue columns (but without save) // Update queue columns (but without save)
if (isset($vars['columns'])) { if (isset($vars['columns'])) {
foreach ($vars['columns'] as $sort=>$colid) { $new = $vars['columns'];
// Try and find the column in this queue, if it's a new one, foreach ($this->columns as $col) {
// add it to the columns list if (false === ($sort = array_search($col->id, $vars['columns']))) {
if (!($col = $this->columns->findFirst(array('id' => $colid)))) { $this->columns->remove($col);
$col = QueueColumn::create(array("id" => $colid, "queue" => $this)); continue;
$this->addColumn($col);
} }
$col->set('sort', $sort+1); $col->set('sort', $sort+1);
$col->update($vars, $errors); $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 // Re-sort the in-memory columns array
$this->columns->sort(function($c) { return $c->sort; }); $this->columns->sort(function($c) { return $c->sort; });
...@@ -477,7 +484,7 @@ class QueueColumnCondition { ...@@ -477,7 +484,7 @@ class QueueColumnCondition {
// Add the annotation to a QuerySet // Add the annotation to a QuerySet
function annotate($query) { function annotate($query) {
$Q = $this->getSearchQ(); $Q = $this->getSearchQ($query);
// Add an annotation to the query // Add an annotation to the query
return $query->annotate(array( return $query->annotate(array(
...@@ -506,12 +513,24 @@ class QueueColumnCondition { ...@@ -506,12 +513,24 @@ class QueueColumnCondition {
return $name; return $name;
} }
function getSearchQ() { function getSearchQ($query) {
list($name, $method, $value) = $this->config['crit']; 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 // Fetch a criteria Q for the query
if ($field = $this->getField($name)) if ($field = $this->getField($name))
return $field->getSearchQ($method, $value, $name); return $field->getSearchQ($method, $value, $name2 ?: $name);
} }
/** /**
......
...@@ -32,11 +32,10 @@ else { ...@@ -32,11 +32,10 @@ else {
<h2><a href="settings.php?t=tickets#queues"><?php echo __('Ticket Queues'); ?></a> <h2><a href="settings.php?t=tickets#queues"><?php echo __('Ticket Queues'); ?></a>
// <?php echo $title; ?> // <?php echo $title; ?>
<?php if (isset($queue->id)) { ?><small> <?php if (isset($queue->id)) { ?><small>
<?php echo $queue->getName(); ?></small> <?php echo $queue->getFullName(); ?></small>
<?php } ?> <?php } ?>
</h2> </h2>
<ul class="clean tabs"> <ul class="clean tabs">
<li class="active"><a href="#criteria"><i class="icon-filter"></i> <li class="active"><a href="#criteria"><i class="icon-filter"></i>
<?php echo __('Criteria'); ?></a></li> <?php echo __('Criteria'); ?></a></li>
...@@ -81,7 +80,7 @@ else { ...@@ -81,7 +80,7 @@ else {
?> ?>
<option value="<?php echo $cq->id; ?>" <option value="<?php echo $cq->id; ?>"
<?php if ($cq->getId() == $queue->parent_id) echo 'selected="selected"'; ?> <?php if ($cq->getId() == $queue->parent_id) echo 'selected="selected"'; ?>
><?php echo $cq->getName(); ?></option> ><?php echo $cq->getFullName(); ?></option>
<?php } ?> <?php } ?>
</select> </select>
...@@ -134,7 +133,8 @@ else { ...@@ -134,7 +133,8 @@ else {
var div = $('<div></div>') var div = $('<div></div>')
.addClass('column-header ui-resizable') .addClass('column-header ui-resizable')
.text(json.heading) .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>') .append($('<i>')
.addClass('icon-ellipsis-vertical ui-resizable-handle ui-resizable-handle-e') .addClass('icon-ellipsis-vertical ui-resizable-handle ui-resizable-handle-e')
) )
......
...@@ -40,8 +40,8 @@ require_once INCLUDE_DIR . 'class.queue.php'; ...@@ -40,8 +40,8 @@ require_once INCLUDE_DIR . 'class.queue.php';
<table class="list" border="0" cellspacing="1" cellpadding="0" width="940"> <table class="list" border="0" cellspacing="1" cellpadding="0" width="940">
<thead> <thead>
<tr> <tr>
<th width="4%">&nbsp;</th> <th width="3%">&nbsp;</th>
<th colspan="5" width="46%"><?php echo __('Name');?></th> <th colspan="5" width="47%"><?php echo __('Name');?></th>
<th width="12%"><?php echo __('Creator');?></th> <th width="12%"><?php echo __('Creator');?></th>
<th width="8%"><?php echo __('Status');?></th> <th width="8%"><?php echo __('Status');?></th>
<th width="10%" nowrap><?php echo __('Created');?></th> <th width="10%" nowrap><?php echo __('Created');?></th>
...@@ -62,7 +62,7 @@ $emitLevel = function($queues, $level=0) use ($all_queues, &$emitLevel) { ...@@ -62,7 +62,7 @@ $emitLevel = function($queues, $level=0) use ($all_queues, &$emitLevel) {
<input type="hidden" name="qsort[<?php echo $q->id; ?>]" <input type="hidden" name="qsort[<?php echo $q->id; ?>]"
value="<?php echo $q->sort; ?>"/> value="<?php echo $q->sort; ?>"/>
</td> </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 href="queues.php?id=<?php echo $q->getId(); ?>"><?php
echo Format::htmlchars($q->getFullName()); ?></a></td> echo Format::htmlchars($q->getFullName()); ?></a></td>
<td><?php echo Format::htmlchars($q->staff->getName()); ?></td> <td><?php echo Format::htmlchars($q->staff->getName()); ?></td>
......
...@@ -11,6 +11,11 @@ $data_form = $column->getDataConfigForm($_POST); ...@@ -11,6 +11,11 @@ $data_form = $column->getDataConfigForm($_POST);
<li class="active"><a href="#<?php echo $colid; ?>-data"><?php echo __('Data'); ?></a></li> <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; ?>-annotations"><?php echo __('Annotations'); ?></a></li>
<li><a href="#<?php echo $colid; ?>-conditions"><?php echo __('Conditions'); ?></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> </ul>
<div class="tab_content" id="<?php echo $colid; ?>-data"> <div class="tab_content" id="<?php echo $colid; ?>-data">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment