]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/dojo/openils/Event.js
OO-ify openils.User
[Evergreen.git] / Open-ILS / web / js / dojo / openils / Event.js
1 /* ---------------------------------------------------------------------------
2  * Copyright (C) 2008  Georgia Public Library Service
3  * Bill Erickson <erickson@esilibrary.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * ---------------------------------------------------------------------------
15  */
16
17 if(!dojo._hasResource["openils.Event"]) {
18
19     dojo._hasResource["openils.Event"] = true;
20     dojo.provide("openils.Event");
21     dojo.declare('openils.Event', null, {
22
23         constructor : function(kwargs) {
24             this.code = kwargs.ilsevent;
25             this.textcode = kwargs.textcode;
26             this.desc = kwargs.desc;
27             this.payload = kwargs.payload;
28             this.debug = kwargs.stacktrace;
29             this.servertime = kwargs.servertime;
30             this.ilsperm = kwargs.ilsperm;
31             this.ilspermloc = kwargs.ilspermloc;
32         },
33
34         toString : function() {
35             var s = 'Event: ' + this.code + ':' + this.textcode + ' -> ' + new String(this.desc);
36             if(this.ilsperm)
37                 s += ' ' + this.ilsperm + '@' + this.ilspermloc;
38             return s;
39         }
40     });
41
42     /**
43      * Parses a proposed event object.  If this object is an
44      * event, a new openils.Event is returned.  Otherwise,
45      * null is returned
46      */
47     openils.Event.parse = function(evt) {
48         if(evt && typeof evt == 'object' && 'ilsevent' in evt && 'textcode' in evt)
49             return new openils.Event(evt);
50         return null;
51     }
52
53     /**
54      * If the provided object is a non-success event, the
55      * event is thrown as an exception.
56      */
57     openils.Event.parse_and_raise = function(evt) {
58         var e = openils.Event.parse(evt);
59         if(e && e.ilsevent != 0)    
60             throw e;
61     }
62 }