diff --git a/web/includes/Monitor.php b/web/includes/Monitor.php index abc39859b..4575d2ab6 100644 --- a/web/includes/Monitor.php +++ b/web/includes/Monitor.php @@ -89,7 +89,7 @@ class Monitor extends ZM_Object { 'DefaultScale' => 100, 'SignalCheckPoints' => 0, 'SignalCheckColour' => '#0000BE', - 'WebColour' => 'red', + 'WebColour' => '#ff0000', 'Exif' => array('type'=>'boolean','default'=>0), 'Sequence' => null, 'TotalEvents' => array('type'=>'integer', 'default'=>null, 'do_not_update'=>1), diff --git a/web/includes/functions.php b/web/includes/functions.php index c4853a7dc..42dc56c30 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -2610,12 +2610,12 @@ function html_radio($name, $values, $selected=null, $options=array(), $attrs=arr return $html; } # end sub html_radio -function random_color_part() { - return str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT); -} -function random_color() { - return random_color_part() . random_color_part() . random_color_part(); +function random_colour() { + return '#'. + str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT). + str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT). + str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT); } ?> diff --git a/web/skins/classic/js/skin.js b/web/skins/classic/js/skin.js index 5ccddf96b..a85281d2d 100644 --- a/web/skins/classic/js/skin.js +++ b/web/skins/classic/js/skin.js @@ -175,12 +175,13 @@ window.addEventListener("DOMContentLoaded", function onSkinDCL() { }); // 'data-on-click' calls the global function in the attribute value with no arguments when a click happens. - document.querySelectorAll("a[data-on-click], button[data-on-click], input[data-on-click]").forEach(function attachOnClick(el) { + document.querySelectorAll("i[data-on-click], a[data-on-click], button[data-on-click], input[data-on-click]").forEach(function attachOnClick(el) { var fnName = el.getAttribute("data-on-click"); if ( !window[fnName] ) { console.error("Nothing found to bind to " + fnName + " on element " + el.name); return; - } + } + el.onclick = function() { window[fnName](); }; diff --git a/web/skins/classic/views/js/monitor.js b/web/skins/classic/views/js/monitor.js index 9d1fc7d7b..b24f6a1b3 100644 --- a/web/skins/classic/views/js/monitor.js +++ b/web/skins/classic/views/js/monitor.js @@ -131,9 +131,36 @@ function initPage() { document.querySelectorAll('select[name="newMonitor[ControlId]"]').forEach(function(el) { el.onchange = window['loadLocations'].bind(el, el); }); + document.querySelectorAll('input[name="newMonitor[WebColour]"]').forEach(function(el) { + el.onchange = window['change_WebColour'].bind(el); + }); $j('.chosen').chosen(); } // end function initPage() +function change_WebColour() { + $j('#WebSwatch').css( + 'backgroundColor', + $j('input[name="newMonitor[WebColour]"]').val() + ); +} + +function getRandomColour() { + var letters = '0123456789ABCDEF'; + var colour = '#'; + for (var i = 0; i < 6; i++) { + colour += letters[Math.floor(Math.random() * 16)]; + } + return colour; +} + +function random_WebColour() { + var new_colour = getRandomColour(); + $j('input[name="newMonitor[WebColour]"]').val(new_colour); + $j('#WebSwatch').css( + 'backgroundColor', new_colour + ); +} + window.addEventListener('DOMContentLoaded', initPage); diff --git a/web/skins/classic/views/monitor.php b/web/skins/classic/views/monitor.php index df3718735..63089dd51 100644 --- a/web/skins/classic/views/monitor.php +++ b/web/skins/classic/views/monitor.php @@ -54,6 +54,7 @@ if ( !$monitor ) { $monitor = new ZM\Monitor(); } # end if $_REQUEST['dupID'] $monitor->Name(translate('Monitor').'-'.$nextId); + $monitor->WebColour(random_colour()); } # end if $_REQUEST['mid'] if ( ZM_OPT_X10 && empty($x10Monitor) ) { @@ -1112,15 +1113,17 @@ if ( canEdit('Control') ) { - +      - +      + sync +