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

lock: Fix permanent error banner if locks are disabled

Also, fix submission without a lock and locks are disabled
parent a75eda1d
No related branches found
No related tags found
No related merge requests found
......@@ -103,7 +103,10 @@ class TicketsAjaxAPI extends AjaxController {
function acquireLock($tid) {
global $cfg, $thisstaff;
if(!$tid || !is_numeric($tid) || !$thisstaff || !$cfg || !$cfg->getLockTime())
if(!$cfg || !$cfg->getLockTime())
Http::response(418, $this->encode(array('id'=>0, 'retry'=>false)));
if(!$tid || !is_numeric($tid) || !$thisstaff)
return 0;
if (!($ticket = Ticket::lookup($tid)) || !$ticket->checkStaffPerm($thisstaff))
......
......@@ -27,6 +27,7 @@ class Http {
case 404: return '404 Not Found';
case 405: return '405 Method Not Allowed';
case 416: return '416 Requested Range Not Satisfiable';
case 418: return "418 I'm a teapot";
case 422: return '422 Unprocessable Entity';
default: return '500 Internal Server Error';
endswitch;
......
......@@ -22,7 +22,11 @@
this.objectId = this.$element.data('lockObjectId');
this.lockId = options.lockId || this.$element.data('lockId') || undefined;
this.fails = 0;
this.setup();
this.disabled = false;
getConfig().then(function(c) {
if (c.lock_time)
this.setup();
}.bind(this));
}
Lock.prototype = {
......@@ -49,7 +53,7 @@
return this.renew();
if (this.nextRenew && new Date().getTime() < this.nextRenew)
return this.locked;
if (this.ajaxActive)
if (this.disabled || this.ajaxActive)
return this.locked;
this.ajaxActive = $.ajax({
......@@ -69,7 +73,7 @@
return;
if (this.nextRenew && new Date().getTime() < this.nextRenew)
return this.locked;
if (this.ajaxActive)
if (this.disabled || this.ajaxActive)
return this.locked;
this.ajaxActive = $.ajax({
......@@ -94,6 +98,11 @@
retry: function(func, xhr, textStatus, response) {
var json = xhr ? xhr.responseJSON : response;
if (xhr.status == 418) {
this.disabled = true;
return this.destroy();
}
if ((typeof json == 'object' && !json.retry) || !this.options.retry)
return this.fail(json.msg);
if (typeof json == 'object' && json.retry == 'acquire') {
......@@ -133,6 +142,8 @@
this.shutdown();
delete this.lockId;
$(this.options.lockInput, this.$element).val('');
if (this.locked)
this.locked.reject();
},
update: function(lock) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment