Page.Log = new Class({ Extends: PageBase, name: 'log', title: 'Show recent logs.', indexAction: function(){ var self = this; self.getLogs(0); }, getLogs: function(nr){ var self = this; if(self.log) self.log.destroy(); self.log = new Element('div.container.loading', { 'text': 'loading...' }).inject(self.el); Api.request('logging.get', { 'data': { 'nr': nr }, 'onComplete': function(json){ self.log.set('html', self.addColors(json.log)); self.log.removeClass('loading'); new Fx.Scroll(window, {'duration': 0}).toBottom(); var nav = new Element('ul.nav').inject(self.log, 'top'); for (var i = 0; i < json.total; i++) { new Element('li', { 'text': i+1, 'class': nr == i ? 'active': '', 'events': { 'click': function(e){ self.getLogs(e.target.get('text')-1); } } }).inject(nav); }; new Element('li', { 'text': 'clear', 'events': { 'click': function(){ Api.request('logging.clear', { 'onComplete': function(){ self.getLogs(0); } }); } } }).inject(nav) } }); }, addColors: function(text){ var self = this; text = text.replace(/\u001b\[31m\u001b\[31m/gi, '') text = text.replace(/\u001b\[36m\u001b\[36m/gi, '') text = text.replace(/\u001b\[0m\u001b\[0m\n/gi, '') text = text.replace(/\u001b\[0m\u001b\[0m/gi, '') return '' + text + ''; } })