]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/WebControls/TJavascriptLogger.php
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / UI / WebControls / TJavascriptLogger.php
1 <?php
2 /**
3  * TJavascriptLogger class file.
4  *
5  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6  * @link https://github.com/pradosoft/prado
7  * @copyright Copyright &copy; 2005-2016 The PRADO Group
8  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9  * @package System.Web.UI.WebControls
10  */
11
12 /**
13  * TJavascriptLogger class.
14  *
15  * Provides logging for client-side javascript. Example: template code
16  * <code><com:TJavascriptLogger /></code>
17  *
18  * Client-side javascript code to log info, error, warn, debug
19  * <code>Logger.warn('A warning');
20  * Logger.info('something happend');
21  * </code>
22  *
23  * To see the logger and console, press ALT-D (or CTRL-D on OS X).
24  * More information on the logger can be found at
25  * http://web.archive.org/web/20060512041505/gleepglop.com/javascripts/logger/
26  *
27  * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
28  * @package System.Web.UI.WebControls
29  * @since 3.0
30  */
31 class TJavascriptLogger extends TWebControl
32 {
33         private static $_keyCodes = array(
34                 '0'=>48, '1'=>49, '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57,
35                 'a'=>65, 'b'=>66, 'c'=>67, 'd'=>68, 'e'=>69, 'f'=>70, 'g'=>71, 'h'=>72,
36                 'i'=>73, 'j'=>74, 'k'=>75, 'l'=>76, 'm'=>77, 'n'=>78, 'o'=>79, 'p'=>80,
37                 'q'=>81, 'r'=>82, 's'=>83, 't'=>84, 'u'=>85, 'v'=>86, 'w'=>87, 'x'=>88, 'y'=>89, 'z'=>90);
38
39         /**
40          * @return string tag name of the panel
41          */
42         protected function getTagName()
43         {
44                 return 'div';
45         }
46
47         /**
48          * @param string keyboard key for toggling the console, default is J.
49          */
50         public function setToggleKey($value)
51         {
52                 $this->setViewState('ToggleKey', $value, 'j');
53         }
54
55         /**
56          * @return string keyboard key for toggling the console.
57          */
58         public function getToggleKey()
59         {
60                 return $this->getViewState('ToggleKey', 'j');
61         }
62
63         /**
64          * Registers the required logger javascript.
65          * @param TEventParameter event parameter
66          */
67         public function onPreRender($param)
68         {
69                 $key = strtolower($this->getToggleKey());
70                 $code = isset(self::$_keyCodes[$key]) ? self::$_keyCodes[$key] : 74;
71                 $js = "var logConsole; jQuery(function() { logConsole = new LogConsole($code)}); ";
72                 $cs = $this->getPage()->getClientScript();
73                 $cs->registerBeginScript($this->getClientID(),$js);
74                 $cs->registerPradoScript('logger');
75         }
76
77         /**
78          * Register the required javascript libraries and
79          * display some general usage information.
80          * @param THtmlWriter the writer used for the rendering purpose
81          */
82         public function renderContents($writer)
83         {
84                 $code = strtoupper($this->getToggleKey());
85                 $info = '(<a href="http://web.archive.org/web/20060512041505/gleepglop.com/javascripts/logger/" target="_blank">more info</a>).';
86                 $link = '<a href="javascript:if(logConsole)logConsole.toggle()">toggle the javascript log console.</a>';
87                 $usage = 'Press ALT-'.$code.' (Or CTRL-'.$code.' on OS X) to';
88                 $writer->write("{$usage} {$link} {$info}");
89         }
90 }
91