1 dump('entering util/error.js\n');
3 if (typeof util == 'undefined') util = {};
4 util.error = function () {
7 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
9 .getService(Components.interfaces.nsIConsoleService);
11 this.consoleDump = false;
12 dump('util.error constructor: ' + E + '\n');
15 this.sdump_last_time = new Date();
19 JSAN.use('util.sound'); this.sound = new util.sound();
24 util.error.prototype = {
29 'arg_dump_full' : false,
31 'debug' : function(e){
32 dump('-----------------------------------------\n'
33 + e + '\n-----------------------------------------\n' );
38 'D_NONE' : false, 'D_ALL' : false, 'D_ERROR' : true, 'D_DEBUG' : true, 'D_TRACE' : true,
40 'D_TRACE_ENTER' : false, 'D_TRACE_EXIT' : false, 'D_TIMEOUT' : false, 'D_FILTER' : false,
41 'D_CONSTRUCTOR' : false, 'D_FIREFOX' : false, 'D_LEGACY' : false, 'D_DATA' : false,
43 'D_CLAM' : false, 'D_PAGED_TREE' : false, 'D_GRID_LIST' : false, 'D_HTML_TABLE' : false,
44 'D_TAB' : false, 'D_LIST' : false,
46 'D_AUTH' : true, 'D_OPAC' : true, 'D_CAT' : true,
48 'D_PATRON_SEARCH' : false, 'D_PATRON_SEARCH_FORM' : false, 'D_PATRON_SEARCH_RESULTS' : false,
50 'D_PATRON_DISPLAY' : false, 'D_PATRON_DISPLAY_STATUS' : false, 'D_PATRON_DISPLAY_CONTACT' : false,
52 'D_PATRON_ITEMS' : false, 'D_PATRON_CHECKOUT_ITEMS' : false, 'D_PATRON_HOLDS' : false,
53 'D_PATRON_BILLS' : false, 'D_PATRON_EDIT' : false,
55 'D_CHECKIN' : false, 'D_CHECKIN_ITEMS' : false,
57 'D_HOLD_CAPTURE' : false, 'D_HOLD_CAPTURE_ITEMS' : false,
59 'D_PATRON_UTILS' : false, 'D_CIRC_UTILS' : false,
61 'D_FILE' : true, 'D_EXPLODE' : false, 'D_FM_UTILS' : false, 'D_PRINT' : true, 'D_SES' : true,
62 'D_SES_FUNC' : false, 'D_SES_RESULT' : true, 'D_SPAWN' : false, 'D_STRING' : false,
63 'D_UTIL' : false, 'D_WIN' : false, 'D_WIDGETS' : false
66 'filter_console_init' : function (p) {
67 this.sdump('D_FILTER',this.arg_dump(arguments,{0:true}));
69 var filterConsoleListener = {
70 observe: function( msg ) {
77 QueryInterface: function (iid) {
78 if (!iid.equals(Components.interfaces.nsIConsoleListener) &&
79 !iid.equals(Components.interfaces.nsISupports)) {
80 throw Components.results.NS_ERROR_NO_INTERFACE;
86 this.consoleService.registerListener(filterConsoleListener);
91 this.sdump('D_TRACE_EXIT',this.arg_dump(arguments));
94 'sdump' : function (level,msg) {
97 var message = now.valueOf() + '\tdelta = ' + (now.valueOf() - this.sdump_last_time.valueOf()) + '\t' + level + '\n' + msg;
98 if (this.sdump_levels['D_NONE']) return null;
99 if (this.sdump_levels[level]||this.sdump_levels['D_ALL']) {
100 this.sdump_last_time = now;
103 if (this.consoleDump) {
104 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
105 this.consoleService.logStringMessage(message);
109 dump('Calling sdump but ' + E + '\n');
113 'arg_dump' : function (args,dump_these) {
114 var s = '*>*>*> Called function ';
118 s += args.callee.toString().match(/\w+/g)[1] + ' : ';
119 for (var i = 0; i < args.length; i++)
120 s += typeof(args[i]) + ' ';
122 for (var i = 0; i < args.length; i++)
126 //dump('dump_these[i] = ' + dump_these[i] + ' arg = ' + arg + '\n');
128 if (typeof(dump_these[i])=='string') {
130 if (dump_these[i].slice(0,1) == '.') {
131 var cmd = 'arg' + dump_these[i];
134 result = eval( cmd );
136 result = cmd + ' ==> ' + E;
138 s += '\targ #' + i + ': ' + cmd + ' = ' + result;
142 result = eval( dump_these[i] );
144 result = dump_these[i] + ' ==> ' + E;
146 s += '\targ #' + i + ': ' + result;
150 s += '\targ #' + i + ' = ';
152 //s += js2JSON( arg );
160 if (this.arg_dump_full)
161 s += 'Definition: ' + args.callee.toString() + '\n';
166 return s + '\nDEBUG ME: ' + js2JSON(E) + '\n';
170 'handle_error' : function (E,annoy) {
172 if (instanceOf(E,ex)) {
174 //s += '\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n';
175 //s += 'This error was anticipated.\n\n';
176 //s += js2JSON(E).substr(0,200) + '...\n\n';
177 if (snd_bad) snd_bad();
179 s += '\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n';
180 s += 'This is a bug that we will fix later.\n\n';
182 s += js2JSON(E).substr(0,1024) + '\n\n';
185 s += E.substr(0,1024) + '\n\n';
190 if (snd_really_bad) snd_really_bad();
199 's_alert' : function (s) { alert(s); },
201 'get_ilsevent' : function(status) {
202 JSAN.use('OpenILS.data');
203 this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
204 return this.OpenILS.data.entities['ilsevent.'+status];
207 'yns_alert' : function (s,title,b1,b2,b3,c) {
210 s = Message to display
211 title = Text in Title Bar
212 b1 = Text for button 1
213 b2 = Text for button 2
214 b3 = Text for button 3
215 c = Text for confirmation checkbox. null for no confirm
218 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
222 // get a reference to the prompt service component.
223 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
224 .getService(Components.interfaces.nsIPromptService);
226 // set the buttons that will appear on the dialog. It should be
227 // a set of constants multiplied by button position constants. In this case,
228 // three buttons appear, Save, Cancel and a custom button.
229 //var flags=promptService.BUTTON_TITLE_OK * promptService.BUTTON_POS_0 +
230 // promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 +
231 // promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
232 var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
233 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
234 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
236 // display the dialog box. The flags set above are passed
237 // as the fourth argument. The next three arguments are custom labels used for
238 // the buttons, which are used if BUTTON_TITLE_IS_STRING is assigned to a
239 // particular button. The last two arguments are for an optional check box.
241 var rv = promptService.confirmEx(window,title, s, flags, b1, b2, b3, c, check);
242 if (c && !check.value) {
243 return this.yns_alert(s,title,b1,b2,b3,c);
249 dump('exiting util/error.js\n');