Skip to content
Snippets Groups Projects
Commit 25d0fc22 authored by Peter Rotich's avatar Peter Rotich
Browse files

Add reopen settings for closed statuses.

This will allow administrator to indicate if end users are allowed to reopen
tickets in a particular closed status.
parent 31658ea6
Branches
Tags
No related merge requests found
...@@ -320,6 +320,16 @@ class FormField { ...@@ -320,6 +320,16 @@ class FormField {
return true; return true;
} }
/**
* FIXME: Temp
*
*/
function isEditable() {
return (($this->get('edit_mask') & 32) == 0);
}
/** /**
* parse * parse
* *
......
...@@ -554,7 +554,8 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { ...@@ -554,7 +554,8 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem {
$this->_form = DynamicForm::lookup( $this->_form = DynamicForm::lookup(
array('type'=>'L'.$this->get('list_id')))->getForm($source); array('type'=>'L'.$this->get('list_id')))->getForm($source);
if (!$source && $config) { if (!$source && $config) {
foreach ($this->_form->getFields() as $f) { $fields = $this->_form->getFields();
foreach ($fields as $f) {
$name = $f->get('id'); $name = $f->get('id');
if (isset($config[$name])) if (isset($config[$name]))
$f->value = $f->to_php($config[$name]); $f->value = $f->to_php($config[$name]);
...@@ -563,6 +564,7 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { ...@@ -563,6 +564,7 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem {
} }
} }
} }
return $this->_form; return $this->_form;
} }
...@@ -802,21 +804,81 @@ class TicketStatus extends VerySimpleModel implements CustomListItem { ...@@ -802,21 +804,81 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
return $this->_form; return $this->_form;
} }
function getExtraConfigOptions($source=null) {
$status_choices = array( 0 => __('System Default'));
if (($statuses=TicketStatusList::getStatuses(
array( 'enabled' => true, 'states' =>
array('open')))))
foreach ($statuses as $s)
$status_choices[$s->getId()] = $s->getName();
return array(
'allowreopen' => new BooleanField(array(
'label' =>__('Allow Reopen'),
'default' => isset($source['allowreopen'])
? $source['allowreopen']: true,
'id' => 'allowreopen',
'name' => 'allowreopen',
'configuration' => array(
'desc'=>__('Allow tickets on this status to be reopened by end users'),
),
'visibility' => new VisibilityConstraint(
new Q(array('state__eq'=>'closed')),
VisibilityConstraint::HIDDEN
),
)),
'reopenstatus' => new ChoiceField(array(
'label' => __('Reopen Status'),
'required' => false,
'default' => isset($source['reopenstatus'])
? $source['reopenstatus'] : 0,
'id' => 'reopenstatus',
'name' => 'reopenstatus',
'choices' => $status_choices,
'configuration' => array(
'widget' => 'dropdown',
'multiselect' =>false
),
'visibility' => new VisibilityConstraint(
new Q(array('allowreopen__eq'=> true)),
VisibilityConstraint::HIDDEN
),
))
);
}
function getConfigurationForm($source=null) { function getConfigurationForm($source=null) {
if ($form = $this->getForm()) { if (!($form = $this->getForm()))
$config = $this->getConfiguration(); return null;
$form = $form->getForm($source);
if (!$source && $config) { $config = $this->getConfiguration();
foreach ($form->getFields() as $f) { $form = $form->getForm($source);
$name = $f->get('id'); $fields = $form->getFields();
if (isset($config[$name])) foreach ($fields as $k => $f) {
$f->value = $f->to_php($config[$name]); if ($f->get('name') == 'state' //TODO: check if editable.
else if ($f->get('default')) && ($extras=$this->getExtraConfigOptions($source))) {
$f->value = $f->get('default'); foreach ($extras as $extra) {
$extra->setForm($form);
$fields->insert(++$k, $extra);
} }
break;
} }
} }
if (!$source && $config) {
foreach ($fields as $f) {
$name = $f->get('id');
if (isset($config[$name]))
$f->value = $f->to_php($config[$name]);
else if ($f->get('default'))
$f->value = $f->get('default');
}
}
return $form; return $form;
} }
...@@ -824,6 +886,34 @@ class TicketStatus extends VerySimpleModel implements CustomListItem { ...@@ -824,6 +886,34 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
return $this->hasFlag('mode', self::ENABLED); return $this->hasFlag('mode', self::ENABLED);
} }
function isReopenable() {
if (strcasecmp($this->get('state'), 'closed'))
return true;
if (($c=$this->getConfiguration())
&& $c['allowreopen']
&& isset($c['reopenstatus']))
return true;
return false;
}
function getReopenStatus() {
global $cfg;
$status = null;
if ($this->isReopenable()
&& ($c = $this->getConfiguration())
&& isset($c['reopenstatus']))
$status = TicketStatus::lookup(
$c['reopenstatus'] ?: $cfg->getDefaultTicketStatusId());
return ($status
&& !strcasecmp($status->getState(), 'open'))
? $status : null;
}
function enable() { function enable() {
// Ticket status without properties cannot be enabled! // Ticket status without properties cannot be enabled!
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
sort: 2 sort: 2
flags: 0 flags: 0
properties: properties:
allowreopen: true
reopenstatus: 0
description: > description: >
Closed tickets. Tickets will still be accessible on client and staff panels. Closed tickets. Tickets will still be accessible on client and staff panels.
......
...@@ -10,8 +10,12 @@ ...@@ -10,8 +10,12 @@
$internal = $item->isInternal(); $internal = $item->isInternal();
$form = $item->getConfigurationForm(); $form = $item->getConfigurationForm();
echo $form->getMedia(); echo $form->getMedia();
foreach ($form->getFields() as $f) { ?> foreach ($form->getFields() as $f) {
<div class="custom-field"> ?>
<div class="custom-field" id="field<?php
echo $f->getWidget()->id; ?>"
<?php
if (!$f->isVisible()) echo 'style="display:none;"'; ?>>
<div class="field-label"> <div class="field-label">
<label for="<?php echo $f->getWidget()->name; ?>" <label for="<?php echo $f->getWidget()->name; ?>"
style="vertical-align:top;padding-top:0.2em"> style="vertical-align:top;padding-top:0.2em">
......
...@@ -27,6 +27,10 @@ UPDATE `%TABLE_PREFIX%ticket_status` s ...@@ -27,6 +27,10 @@ UPDATE `%TABLE_PREFIX%ticket_status` s
ON(c.namespace = CONCAT('TS.', s.id) AND c.key='properties') ON(c.namespace = CONCAT('TS.', s.id) AND c.key='properties')
SET s.properties = c.value; SET s.properties = c.value;
-- add default reopen settings to existing closed state statuses
UPDATE `%TABLE_PREFIX%ticket_status`
SET `properties`= INSERT(`properties`, 2, 0, '"allowreopen":true,"reopenstatus":0,')
WHERE `state` = 'closed';
-- Set new schema signature -- Set new schema signature
UPDATE `%TABLE_PREFIX%config` UPDATE `%TABLE_PREFIX%config`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment