]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/dojo/openils/Event.js
Merge branch 'master' of git.evergreen-ils.org:Evergreen-DocBook into doc_consolidati...
[working/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             this.note = kwargs.note;
33         },
34
35         toString : function() {
36             var s = 'Event: ' + (this.code || '') + ':' + this.textcode + ' -> ' + new String(this.desc);
37             if(this.ilsperm)
38                 s += ' ' + this.ilsperm + '@' + this.ilspermloc;
39             if(this.note)
40                 s += '\n' + this.note;
41             return s;
42         }
43     });
44
45     /**
46      * Parses a proposed event object.  If this object is an
47      * event, a new openils.Event is returned.  Otherwise,
48      * null is returned
49      */
50     openils.Event.parse = function(evt) {
51         if(evt && typeof evt == 'object' && 'ilsevent' in evt && 'textcode' in evt)
52             return new openils.Event(evt);
53         return null;
54     }
55
56     /**
57      * If the provided object is a non-success event, the
58      * event is thrown as an exception.
59      */
60     openils.Event.parse_and_raise = function(evt) {
61         var e = openils.Event.parse(evt);
62         if(e && e.ilsevent != 0)    
63             throw e;
64     }
65 }