refactoring brapi json responses
[sgn.git] / js / CXGN / SGNLoggingPane.js
blob0064113726a2ecefad2a6204f66a918c96c624c5
3 JSAN.use('MochiKit.LoggingPane');
5 MochiKit.LoggingPane.LoggingPane.prototype.colorTable = {
6     DEBUG: "#151",
7     INFO: "black",
8     WARNING: "blue",
9     ERROR: "red",
10     FATAL: "darkred"
13 JSAN.use('CXGN.Effects');
15 SGNLoggingPane = window.SGNLoggingPane || {};
17 SGNLoggingPane = {
18         inline_create_link_id : 'MKLPinline_create',
19         inline_destroy_link_id : 'MKLPinline_destroy',
20         window_create_link_id: 'MKLPwindow_create',
21         window_destroy_link_id: 'MKLPwindow_destroy',
22         LP: '',
23         
24         create: function (inline) {
25                 var uid = '_MochiKit_LoggingPane';
26                 if(!inline){ //determine height of window
27                         var messages = MochiKit.Logging.logger.getMessages();
28                         var cr_count = 0;
29                         for(i = 0; i < messages.length; i++){
30                                 var message = messages[i].info.join(" ");
31                                 cr_count += message.search("\\n"); //count cr's in message
32                                 cr_count++; //implicit cr for message
33                         }
34                         var height = cr_count*20; //20 pixels is approximate line-height?
35                         if(height<200) height=200;
36                         if(height>500) height=500;
37                         SGNLoggingPane.LP = MochiKit.LoggingPane.createLoggingPane(false, height);
38                         //Effects.swapElements(SGNLoggingPane.window_create_link_id, SGNLoggingPane.window_destroy_link_id);    
39                 }
40                 else { //Open an Inline Logging Pane
41                         SGNLoggingPane.LP = MochiKit.LoggingPane.createLoggingPane(true);
42                         
43                         //redefine closePane() to perform SGN-related tasks when the 
44                         //pane is closed using the native button
45                         SGNLoggingPane.LP.closePane = MochiKit.Base.bind(
46                                 function () {
47                                 if (this.closed) {
48                                 return;
49                                 }
50                                 this.closed = true;
51                                 if (MochiKit.LoggingPane._loggingPane == this) {
52                                     MochiKit.LoggingPane._loggingPane = null;
53                                 }
54                                 this.logger.removeListener(uid+'_Listener');
55                                 try {
56                                     try {
57                                       debugPane.loggingPane = null;
58                                     } 
59                                                 catch(e) { logFatal("Bookmarklet was closed incorrectly."); }
60                                     if (inline) {
61                                         debugPane.parentNode.removeChild(debugPane);
63                                                         //This is the stuff we added
64                                                         if(Effects){
65                                                                 Effects.swapElements(SGNLoggingPane.inline_destroy_link_id, SGNLoggingPane.inline_create_link_id);
66                                                         }
67                                                         if(DeveloperSettings){
68                                                                 DeveloperSettings.setValue('logging_pane_open', 0);
69                                                                 DeveloperSettings.save();
70                                                         }
71                                                         ////
72                                     
73                                                 } 
74                                                 else {
75                                         this.win.close();
76                                     }
77                                 } 
78                                         catch(e) {
79                                         }
80                         }, SGNLoggingPane.LP);
81         
82                         var debugPane = window.document.getElementById(uid);
83                         var closeButton = debugPane.getElementsByTagName('button')[3];
84                         var divBody = debugPane.getElementsByTagName('div')[0];
85                         closeButton.onclick = SGNLoggingPane.LP.closePane;      
87                         if(Effects && typeof(Effects.swapElements) == "function"){
88                                 Effects.swapElements(SGNLoggingPane.inline_create_link_id, SGNLoggingPane.inline_destroy_link_id);
89                         }
90                         if(DeveloperSettings){
91                                 DeveloperSettings.setValue('logging_pane_open', 1);
92                                 DeveloperSettings.save();
93                         }
94                 }
95         
96         },
98         destroy: function () {
99                 SGNLoggingPane.LP.closePane();
100                 if(Effects && typeof(Effects.swapElements) == "function") {
101                         Effects.swapElements(SGNLoggingPane.inline_destroy_link_id, SGNLoggingPane.inline_create_link_id);
102                 //      Effects.swapElements(SGNLoggingPane.window_destroy_link_id, SGNLoggingPane.window_create_link_id);      
103                 }
104                 if(DeveloperSettings){
105                         DeveloperSettings.setValue('logging_pane_open', 0);
106                         DeveloperSettings.save();
107                 }
108         },
110         //redefine link handles:
111         handles: function (ic, id, wc, wd) {
112                 if(ic){
113                         SGNLoggingPane.inline_create_link_id = ic;
114                 }
115                 if(id){
116                         SGNLoggingPane.inline_destroy_link_id = id;
117                 }
118                 if(wc){
119                         SGNLoggingPane.window_create_link_id = wc;
120                 }
121                 if(wd){
122                         SGNLoggingPane.window_destroy_link_id = wd;
123                 }
124         }