diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 8685edf5714bd98d2caeeff5c29611e93b32ffbe..cb988f8a5cc4c9ea200396fa7400297bbd590b18 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -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)) diff --git a/include/class.http.php b/include/class.http.php index b2a9738e0c2a3d87ff75eadd82ee34ee6fc0b50e..e17839d5b73b600cca2b95969799ff0f29f9a109 100644 --- a/include/class.http.php +++ b/include/class.http.php @@ -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; diff --git a/scp/js/ticket.js b/scp/js/ticket.js index 897fafa8e261ecc1aba96e86426cb2a99aa3ea53..21ed2f415ba93a720603cab01cb17b2f1f222211 100644 --- a/scp/js/ticket.js +++ b/scp/js/ticket.js @@ -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) {