diff --git a/scp/js/ticket.js b/scp/js/ticket.js index 8cb792d1..4967cf99 100644 --- a/scp/js/ticket.js +++ b/scp/js/ticket.js @@ -50,9 +50,12 @@ var autoLock = { autoLock.renewLock(e); } - if(!autoLock.lasteventTime) //I hate nav away warnings..but - autoLock.addEvent(window,'beforeunload',autoLock.discardWarning,true); - + if(!autoLock.lasteventTime) { //I hate nav away warnings..but + $(window).bind('beforeunload', function(e) { + return "Any changes or info you've entered will be discarded!"; + }); + } + autoLock.lasteventTime=new Date().getTime(); }, @@ -126,7 +129,7 @@ var autoLock = { onSubmit: function(e) { if(e.type=='submit') { //Submit. double check! //remove nav away warning if any. - autoLock.removeEvent(window,'beforeunload',autoLock.discardWarning,true); + $(window).unbind('beforeunload'); //Only warn if we had a failed lock attempt. if(autoLock.warn && !autoLock.lockId && autoLock.lasteventTime) { var answer=confirm('Unable to acquire a lock on the ticket. Someone else could be working on the same ticket. \ diff --git a/scp/js/ticket.min.js b/scp/js/ticket.min.js deleted file mode 100644 index cd7c0b6a..00000000 --- a/scp/js/ticket.min.js +++ /dev/null @@ -1,15 +0,0 @@ -/********************************************************************* - ticket.js - - Ticket utility loaded on ticket view! - - Useful for UI config settings, ticket locking ...etc - - Peter Rotich - Copyright (c) 2006-2012 osTicket - http://www.osticket.com - - Released under the GNU General Public License WITHOUT ANY WARRANTY. - - vim: expandtab sw=4 ts=4 sts=4: -**********************************************************************/var autoLock={addEvent:function(e,t,n,r){if(e.addEventListener){e.addEventListener(t,n,r);return!0}if(e.attachEvent)return e.attachEvent("on"+t,n);e["on"+t]=n},removeEvent:function(e,t,n,r){if(e.removeEventListener){e.removeEventListener(t,n,r);return!0}if(e.detachEvent)return e.detachEvent("on"+t,n);e["on"+t]=null},handleEvent:function(e){if(!autoLock.lockId){var t=(new Date).getTime();if(autoLock.retry&&(!autoLock.lastattemptTime||t-autoLock.lastattemptTime>5e3)){autoLock.acquireLock(e,autoLock.warn);autoLock.lastattemptTime=(new Date).getTime()}}else autoLock.renewLock(e);autoLock.lasteventTime||autoLock.addEvent(window,"beforeunload",autoLock.discardWarning,!0);autoLock.lasteventTime=(new Date).getTime()},watchForm:function(e,t){if(!e||!e.length)return;autoLock.addEvent(e,"submit",autoLock.onSubmit,!0);for(var n=0;n=autoLock.renewFreq*1e3)&&$.ajax({type:"POST",url:"ajax.php/tickets/"+autoLock.tid+"/lock/"+autoLock.lockId+"/renew",dataType:"json",cache:!1,success:function(e){autoLock.setLock(e,"renew",autoLock.warn)}}).done(function(){}).fail(function(){})},releaseLock:function(e){if(!autoLock.tid)return!1;$.ajax({type:"POST",url:"ajax.php/tickets/"+autoLock.tid+"/lock/"+autoLock.lockId+"/release",data:"delete",cache:!1,success:function(){}}).done(function(){}).fail(function(){})},setLock:function(t,n,r){var r=r||!1;if(!t)return!1;if(t.id){autoLock.renewFreq=t.time?t.time/2:30;autoLock.lastcheckTime=(new Date).getTime()}autoLock.lockId=t.id;switch(n){case"renew":if(!t.id&&t.retry){autoLock.lockAttempts=1;autoLock.acquireLock(e,!1)}break;case"acquire":if(!t.id){autoLock.lockAttempts++;if(r&&(!t.retry||autoLock.lockAttempts>=autoLock.maxattempts)){autoLock.retry=!1;alert("Unable to lock the ticket. Someone else could be working on the same ticket.")}}}},discardWarning:function(e){e.returnValue="Any changes or info you've entered will be discarded!"},monitorEvents:function(){},clearTimer:function(){clearTimeout(autoLock.timerId)},resetTimer:function(){clearTimeout(autoLock.timerId);autoLock.timerId=setTimeout(function(){autoLock.monitorEvents()},3e4)}};jQuery(function(e){e("#response_options form").hide();e("#ticket_notes").hide();if(location.hash!=""&&e("#response_options "+location.hash).length){e("#response_options "+location.hash+"_tab").addClass("active");e("#response_options "+location.hash).show()}else if(location.hash=="#notes"&&e("#ticket_notes").length){e("#response_options #note_tab").addClass("active");e("#response_options form").hide();e("#response_options #note").show();e("#ticket_thread").hide();e("#ticket_notes").show();e("#toggle_ticket_thread").removeClass("active");e("#toggle_notes").addClass("active")}else{e("#response_options ul li:first a").addClass("active");e("#response_options "+e("#response_options ul li:first a").attr("href")).show()}e("#reply_tab").click(function(){e(this).removeClass("tell")});e("#note_tab").click(function(){e("#response").val()!=""&&e("#reply_tab").addClass("tell")});e("#response_options ul li a").click(function(t){t.preventDefault();e("#response_options ul li a").removeClass("active");e(this).addClass("active");e("#response_options form").hide();e("#response_options "+e(this).attr("href")).show();e("#msg_error, #msg_notice, #msg_warning").fadeOut()});e("#toggle_ticket_thread, #toggle_notes, .show_notes").click(function(t){t.preventDefault();e("#threads a").removeClass("active");if(e(this).attr("id")=="toggle_ticket_thread"){e("#ticket_notes").hide();e("#ticket_thread").show();e("#toggle_ticket_thread").addClass("active");e("#reply_tab").removeClass("tell").click()}else{e("#ticket_thread").hide();e("#ticket_notes").show();e("#toggle_notes").addClass("active");e("#note_tab").click();e("#response").val()!=""&&e("#reply_tab").addClass("tell")}});e("#print-options").css({top:e(window).height()/5,left:e(window).width()/2-300});e("a#ticket-print").click(function(t){t.preventDefault();e("#overlay").show();e("#print-options").show();return!1});e("#print-options").delegate("a.close, input.close","click",function(t){t.preventDefault();e("#print-options").hide();e("#overlay").hide()});autoLock.Init()}); \ No newline at end of file