From: erickson Date: Sun, 13 Apr 2008 13:07:53 +0000 (+0000) Subject: added initial Event handling code X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3fff7b1eee153f4eddd3202c7e3f1f29f1e291b5;p=Evergreen.git added initial Event handling code git-svn-id: svn://svn.open-ils.org/ILS/trunk@9323 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/js/dojo/openils/Event.js b/Open-ILS/web/js/dojo/openils/Event.js new file mode 100644 index 0000000000..9e5b872341 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/Event.js @@ -0,0 +1,62 @@ +/* --------------------------------------------------------------------------- + * Copyright (C) 2008 Georgia Public Library Service + * Bill Erickson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * --------------------------------------------------------------------------- + */ + +if(!dojo._hasResource["openils.Event"]) { + + dojo._hasResource["openils.Event"] = true; + dojo.provide("openils.Event"); + dojo.declare('openils.Event', null, { + + constructor : function(kwargs) { + this.code = kwargs.ilsevent; + this.textcode = kwargs.textcode; + this.desc = kwargs.desc; + this.payload = kwargs.payload; + this.debug = kwargs.stacktrace; + this.servertime = kwargs.servertime; + this.ilsperm = kwargs.ilsperm; + this.ilspermloc = kwargs.ilspermloc; + }, + + toString : function() { + var s = 'Event: ' + this.code + ':' + this.textcode + ' -> ' + new String(this.desc); + if(this.ilsperm) + s += ' ' + this.ilsperm + '@' + this.ilspermloc; + return s; + } + }); + + /** + * Parses a proposed event object. If this object is an + * event, a new openils.Event is returned. Otherwise, + * null is returned + */ + openils.Event.parse = function(evt) { + if(evt && 'ilsevent' in evt && 'textcode' in evt) + return new openils.Event(evt); + return null; + } + + /** + * If the provided object is a non-success event, the + * event is thrown as an exception. + */ + openils.Event.parse_and_raise = function(evt) { + var e = openils.Event.parse(evt); + if(e && e.ilsevent != 0) + throw e; + } +}