Skip to content
Snippets Groups Projects
Commit f826189b authored by Jared Hancock's avatar Jared Hancock
Browse files

lock: Add option of old semantics — lock on view

parent 49b9658f
Branches
Tags
No related merge requests found
......@@ -38,7 +38,7 @@ class ConfigAjaxAPI extends AjaxController {
list($primary_sl, $primary_locale) = explode('_', $primary);
$config=array(
'lock_time' => ($cfg->getLockTime()*60),
'lock_time' => $cfg->getTicketLockMode() == Lock::MODE_DISABLED ? 0 : ($cfg->getLockTime()*60),
'html_thread' => (bool) $cfg->isRichTextEnabled(),
'date_format' => $cfg->getDateFormat(true),
'lang' => $lang,
......
......@@ -92,7 +92,7 @@ class TicketsAjaxAPI extends AjaxController {
function acquireLock($tid) {
global $cfg, $thisstaff;
if(!$cfg || !$cfg->getLockTime())
if(!$cfg || !$cfg->getLockTime() || $cfg->getTicketLockMode() == Lock::MODE_DISABLED)
Http::response(418, $this->encode(array('id'=>0, 'retry'=>false)));
if(!$tid || !is_numeric($tid) || !$thisstaff)
......
......@@ -176,6 +176,7 @@ class OsticketConfig extends Config {
'verify_email_addrs' => 1,
'client_avatar' => 'gravatar.mm',
'agent_avatar' => 'gravatar.mm',
'ticket_lock' => 2, // Lock on activity
);
function OsticketConfig($section=null) {
......@@ -424,6 +425,10 @@ class OsticketConfig extends Config {
return $this->get('autolock_minutes');
}
function getTicketLockMode() {
return $this->get('ticket_lock');
}
function getAgentNameFormat() {
return $this->get('agent_name_format');
}
......@@ -1204,6 +1209,7 @@ class OsticketConfig extends Config {
'show_related_tickets'=>isset($vars['show_related_tickets'])?1:0,
'hide_staff_name'=>isset($vars['hide_staff_name'])?1:0,
'allow_client_updates'=>isset($vars['allow_client_updates'])?1:0,
'ticket_lock' => $vars['ticket_lock'],
));
}
......
......@@ -38,6 +38,10 @@ class Lock extends VerySimpleModel {
),
);
const MODE_DISABLED = 0;
const MODE_ON_VIEW = 1;
const MODE_ON_ACTIVITY = 2;
function getId() {
return $this->lock_id;
}
......
......@@ -145,6 +145,23 @@ if(!($maxfileuploads=ini_get('max_file_uploads')))
<span class="error"><?php echo $errors['default_help_topic']; ?></span>
</td>
</tr>
<tr>
<td width="180"><?php echo __('Lock Semantics'); ?>:</td>
<td>
<select name="ticket_lock" <?php if ($cfg->getLockTime() == 0) echo 'disabled="disabled"'; ?>>
<?php foreach (array(
Lock::MODE_DISABLED => __('Disabled'),
Lock::MODE_ON_VIEW => __('Lock on view'),
Lock::MODE_ON_ACTIVITY => __('Lock on activity'),
) as $v => $desc) { ?>
<option value="<?php echo $v; ?>" <?php
if ($config['ticket_lock'] == $v) echo 'selected="selected"';
?>><?php echo $desc; ?></option>
<?php } ?>
</select>
<div class="error"><?php echo $errors['ticket_lock']; ?></div>
</td>
</tr>
<tr>
<td><?php echo __('Maximum <b>Open</b> Tickets');?>:</td>
<td>
......
......@@ -16,6 +16,8 @@ $user = $ticket->getOwner(); //Ticket User (EndUser)
$team = $ticket->getTeam(); //Assigned team.
$sla = $ticket->getSLA();
$lock = $ticket->getLock(); //Ticket lock obj
if (!$lock && $cfg->getTicketLockMode() == Lock::MODE_ON_VIEW)
$lock = $ticket->acquireLock($thisstaff->getId());
$mylock = ($lock && $lock->getStaffId() == $thisstaff->getId()) ? $lock : null;
$id = $ticket->getId(); //Ticket ID.
......
......@@ -20,30 +20,29 @@
if (!this.$element.data('lockObjectId'))
return;
this.objectId = this.$element.data('lockObjectId');
this.lockId = options.lockId || this.$element.data('lockId') || undefined;
this.fails = 0;
this.disabled = false;
getConfig().then(function(c) {
if (c.lock_time)
this.setup();
this.setup(options.lockId || this.$element.data('lockId') || undefined);
}.bind(this));
}
Lock.prototype = {
constructor: Lock,
registry: [],
setup: function() {
setup: function(lockId) {
// When something inside changes or is clicked which requires a lock,
// attempt to fetch one (lazily)
$(':input', this.$element).on('keyup, change', this.acquire.bind(this));
$(':submit', this.$element).click(this.ensureLocked.bind(this));
$(document).on('pjax:start', this.shutdown.bind(this));
// If lock already held, assume full time of lock remains, but warn
// user about pending expiration
if (this.lockId) {
if (lockId) {
getConfig().then(function(c) {
this.lockTimeout(c.lock_time - 20);
this.update({id: lockId, time: c.lock_time - 10});
}.bind(this));
}
},
......@@ -126,12 +125,20 @@
type: 'POST',
url: 'ajax.php/lock/{0}/release'.replace('{0}', this.lockId),
data: 'delete',
async: false,
cache: false,
success: this.clearAll.bind(this),
complete: this.destroy.bind(this)
});
},
clearAll: function() {
// Clear all other current locks with the same ID as this
$.each(Lock.prototype.registry, function(i, l) {
if (l.lockId && l.lockId == this.lockId)
l.shutdown();
}.bind(this));
},
shutdown: function() {
clearTimeout(this.warning);
clearTimeout(this.retryTimer);
......@@ -159,6 +166,7 @@
// Set up release on away navigation
$(document).off('.exclusive');
$(document).on('pjax:click.exclusive', $.proxy(this.release, this));
Lock.prototype.registry.push(this);
}
this.lockId = lock.id;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment