added initial Event handling code
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 13 Apr 2008 13:07:53 +0000 (13:07 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 13 Apr 2008 13:07:53 +0000 (13:07 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@9323 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/Event.js [new file with mode: 0644]

diff --git a/Open-ILS/web/js/dojo/openils/Event.js b/Open-ILS/web/js/dojo/openils/Event.js
new file mode 100644 (file)
index 0000000..9e5b872
--- /dev/null
@@ -0,0 +1,62 @@
+/* ---------------------------------------------------------------------------
+ * Copyright (C) 2008  Georgia Public Library Service
+ * Bill Erickson <erickson@esilibrary.com>
+ *
+ * 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;
+    }
+}