]>
git.argeo.org Git - gpl/argeo-slc.git/blob - components/Logger.js
2 * A modal window like console for the logs.
3 * Also opens a small alert window (qooxdoo, not native) on errors.
5 * @author : Charles du Jeu
7 qx
.Class
.define("org.argeo.ria.components.Logger",
10 extend
: qx
.ui
.window
.Window
,
12 construct : function(){
13 this.base(arguments
, "Logs", "resource/slc/help-contents.png");
20 this.setLayout(new qx
.ui
.layout
.Dock(0,5));
21 var buttonPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Canvas());
22 var closeButton
= new qx
.ui
.form
.Button("Close");
23 closeButton
.addListener("execute", function(e
){
26 buttonPane
.add(closeButton
, {width
:'20%',left
:'40%'});
27 this.add(buttonPane
, {edge
:'south'});
30 var layout
= new qx
.ui
.layout
.VBox(2);
31 this._logPane
= new qx
.ui
.container
.Composite(layout
);
32 var deco
= new qx
.ui
.decoration
.Single(1, 'solid', '#000000');
33 deco
.setBackgroundColor("#ffffff")
34 var scroller
= new qx
.ui
.container
.Scroll(this._logPane
);
35 scroller
.setDecorator(deco
);
36 this.add(scroller
, {edge
:'center', width
:'100%', height
:'100%'});
37 // Build style sheet content
40 '.messages{font-size:0.9em}',
41 '.messages div{padding:0px 4px;}',
42 '.messages .offset{font-weight:bold;}',
43 '.messages .object{font-style:italic;}',
45 '.messages .user-command{color:blue}',
46 '.messages .user-result{background:white}',
47 '.messages .user-error{background:#FFE2D5}',
48 '.messages .level-debug{background:white}',
49 '.messages .level-info{background:#DEEDFA}',
50 '.messages .level-warn{background:#FFF7D5}',
51 '.messages .level-error{background:#FFE2D5}',
52 '.messages .level-user{background:#E3EFE9}',
53 '.messages .type-string{color:black;font-weight:normal;}',
54 '.messages .type-number{color:#155791;font-weight:normal;}',
55 '.messages .type-boolean{color:#15BC91;font-weight:normal;}',
56 '.messages .type-array{color:#CC3E8A;font-weight:bold;}',
57 '.messages .type-map{color:#CC3E8A;font-weight:bold;}',
58 '.messages .type-key{color:#565656;font-style:italic}',
59 '.messages .type-class{color:#5F3E8A;font-weight:bold}',
60 '.messages .type-instance{color:#565656;font-weight:bold}',
61 '.messages .type-stringify{color:#565656;font-weight:bold}'
64 qx
.bom
.Stylesheet
.createElement(style
.join(""));
70 * Adds a log in the GUI component.
71 * @param entry {Map} A log entry
73 process : function(entry
){
74 var wrapper
= qx
.log
.appender
.Util
.toHtml(entry
);
75 var label
= new qx
.ui
.basic
.Label('<div class="messages"><div class="'+wrapper
.className
+'">'+wrapper
.innerHTML
.replace(",","<br/>")+'</div></div>');
77 if(entry
.level
== "error"){
78 var alert
= new org
.argeo
.ria
.components
.Modal("Error");
79 alert
.addContent(label
.clone());
80 alert
.attachAndShow();
81 }else if(entry
.level
== "info"){
82 this.showLogAsPopup(label
.clone());
84 this._logPane
.addAt(label
, 0);
87 * Shows the GUI console and center it.
95 * Show a given info log in a small popup right-top aligned.
96 * The popup will disappear after 5 seconds.
97 * @param content {qx.ui.basic.Label} The content of the popup to display
99 showLogAsPopup:function(content
){
101 this.popup
= new qx
.ui
.popup
.Popup(new qx
.ui
.layout
.Canvas()).set({
102 backgroundColor
: "#DFFAD3",
106 position
: "right-top"
109 this.popup
.removeAll();
110 this.popup
.add(content
);
111 var appRoot
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getApplicationRoot();
112 appRoot
.add(this.popup
);
114 this.popup
.moveTo((qx
.bom
.Viewport
.getWidth()-350), 0);
115 qx
.event
.Timer
.once(function(){this.popup
.hide();}, this, 5000);
119 destruct : function()
121 qx
.log
.Logger
.unregister(this);