diff --git a/lib/json_server.pl b/lib/json_server.pl index 3857bbfe9..8dc59fd71 100644 --- a/lib/json_server.pl +++ b/lib/json_server.pl @@ -626,6 +626,14 @@ sub json_get { } } + if ( $path[0] eq 'fp_icon_sets' ){ + my $p = "../web/ia7/graphics/*default_".$args{px}[0].".png"; + my @icons = glob($p); + s/^..\/web// for @icons; + $json_data{'icon_sets'} = []; + push( @{ $json_data{'fp_icon_sets'} }, @icons); + } + # List speak phrases if ( $path[0] eq 'print_speaklog' || $path[0] eq '' ) { my ( @log, @tmp ); diff --git a/web/ia7/include/javascript.js b/web/ia7/include/javascript.js index e481e6172..c9d31e840 100644 --- a/web/ia7/include/javascript.js +++ b/web/ia7/include/javascript.js @@ -597,7 +597,7 @@ var loadList = function() { // This is not an entity, likely a value of the root obj continue; } - if (json_store.objects[entity].hidden != undefined){ + if (json_store.objects[entity].hidden !== undefined){ // This is an entity with the hidden property, so skip it continue; } @@ -733,7 +733,8 @@ var loadList = function() { for (var i = 0; i < json_store.objects[entity].states.length; i++){ if (filterSubstate(json_store.objects[entity].states[i]) == 1) continue; possible_states++; - if (json_store.objects[entity].states[i] !== json_store.objects[entity].state) new_state = json_store.objects[entity].states[i] + if (json_store.objects[entity].states[i] !== json_store.objects[entity].state) new_state = json_store.objects[entity].states[i]; + } if ((possible_states > 2) || (new_state == "")) alert("Check configuration of "+entity+". "+possible_states+" states detected for direct control object. State is "+new_state); url= '/SET;none?select_item='+entity+'&select_state='+new_state; @@ -770,7 +771,8 @@ var getButtonColor = function (state) { } else if (state == "cooling" || state == "cool") { color = "info"; } - if (json_store.ia7_config.state_colors[state] !== undefined) { + if (json_store.ia7_config.state_colors !== undefined + && json_store.ia7_config.state_colors[state] !== undefined) { color = "purple"; if (json_store.ia7_config.state_colors[state] == "green") { color = "success"; @@ -1614,197 +1616,563 @@ var graph_rrd = function(start,group,time) { }); }; -var floorplan = function(group,time) { - var URLHash = URLToHash(); - var baseimg_width; - if (typeof time === 'undefined'){ - $('#list_content').html("
"); + $.ajax({ + type: "GET", + url: "/LONG_POLL?json('GET','fp_icon_sets','px=48')", + dataType: "json", + error: function(xhr, textStatus, errorThrown){ + console.log('FP: request iconsets failed: "' + textStatus + '" "'+JSON.stringify(errorThrown, undefined,2)+'"'); + }, + success: function( json, statusText, jqXHR ) { + console.log('FP: request iconsets: "' + statusText + '" "'+JSON.stringify(jqXHR, undefined,2)+'"'); + var requestTime = time; + if (jqXHR.status === 200) { + var iconlist = ' \n"; + $('#list_content').append(iconlist); + + // Trigger action when the contexmenu is about to be shown + $(".floorplan_item").bind("contextmenu", function (event) { + + event.preventDefault(); + + fp_icon_select_item_id = $(this).attr('id'); + $(".icon_select").finish().toggle(100); + $(".icon_select").offset({ + top: event.pageY, + left: event.pageX + }); + }); + + + // If the document is clicked somewhere + $(document).bind("mousedown", function (e) { + if ($(e.target).parents(".icon_select").length === 0) { + $(".icon_select").hide(100); + fp_icon_select_item_id = null; + } + }); + + + // If the menu element is clicked + $(".icon_select img").click(function(){ + var img = $(this).attr("src"); + $('#'+fp_icon_select_item_id).attr('src', img); + var name = fp_icon_select_item_id.match(/entity_(.*)_(\d)+$/)[1]; + + var codeLines = $("#fp_pos_perl_code").text().split('\n'); + var newCode = ""; + + var icon_set_name = img.match(/.*fp_(.*)_(.*)_48.png/)[1]; + var itemUpdated = false; + for (var i = 0; i< codeLines.length; i++) + { + var line = codeLines[i]; + if (line.startsWith("$"+name+"->set_fp_icon_set")) + { + var newline = "$" + name + '->set_fp_icon_set("'+ icon_set_name+ '");\n'; + newCode += newline; + itemUpdated = true; + } + else if (line !== "") + { + newCode += line + "\n"; + } + } + if (itemUpdated === false) + { + var newline = "$" + name + '->set_fp_icon_set("'+ icon_set_name +'");\n'; + newCode += newline; + } + newCode = newCode.split('\n').sort().join('\n'); + $("#fp_pos_perl_code").text(newCode); + $(".icon_select").hide(100); + fp_icon_select_item_id = null; + }); + } + } + }); + } + requestTime = json.meta.time; + var t1 = performance.now(); + console.log("FP: long poll " +Math.round(t1 - t0) + "ms"); + } + if (jqXHR.status === 200 || jqXHR.status === 204) { + //Call update again, if page is still here + //KRK best way to handle this is likely to check the URL hash + if ($('#floorplan').length !== 0){ + //If the floorplan page is still active request more data + // and we are not editing the fp + if (URLHash.show_pos === undefined) + floorplan(group,requestTime); + } + } + } + }); +}; var get_fp_image = function(item,size,orientation) { var image_name; - var image_color = getButtonColor(item.state) + var image_color = getButtonColor(item.state); var baseimg_width = $(window).width(); - var image_size = "48" - if (baseimg_width < 500) image_size = "32" // iphone scaling + var image_size = "48"; + // if (baseimg_width < 500) image_size = "32" // iphone scaling + //kvar image_size = "32" if (item.fp_icons !== undefined) { if (item.fp_icons[item.state] !== undefined) return item.fp_icons[item.state]; } @@ -1812,35 +2180,35 @@ var get_fp_image = function(item,size,orientation) { return "fp_"+item.fp_icon_set+"_"+image_color+"_"+image_size+".png"; } // if item.fp_icons.return item.fp_icons[state]; - if(item.type == "Light_Item" || item.type == "Fan_Light" || - item.type == "Insteon_Device" || item.type == "UPB_Link" || - item.type == "Insteon::SwitchLinc" || item.type == "Insteon::SwitchLincRelay" || - item.type == "Insteon::KeyPadLinc" || - item.type == "EIB_Item" || item.type == "EIB1_Item" || - item.type == "EIB2_Item" || item.type == "EIO_Item" || - item.type == "UIO_Item" || item.type == "X10_Item" || - item.type == "xPL_Plugwise" || item.type == "X10_Appliance") { + if(item.type === "Light_Item" || item.type === "Fan_Light" || + item.type === "Insteon_Device" || item.type === "UPB_Link" || + item.type === "Insteon::SwitchLinc" || item.type === "Insteon::SwitchLincRelay" || + item.type === "Insteon::KeyPadLinc" || + item.type === "EIB_Item" || item.type === "EIB1_Item" || + item.type === "EIB2_Item" || item.type === "EIO_Item" || + item.type === "UIO_Item" || item.type === "X10_Item" || + item.type === "xPL_Plugwise" || item.type === "X10_Appliance") { return "fp_light_"+image_color+"_"+image_size+".png"; } - if(item.type == "Motion_Item" || item.type == "X10_Sensor" || - item.type == "Insteon::MotionSensor" ) { + if(item.type === "Motion_Item" || item.type === "X10_Sensor" || + item.type === "Insteon::MotionSensor" ) { return "fp_motion_"+image_color+"_"+image_size+".png"; } - if(item.type == "Door_Item" || item.type == "Insteon::IOLinc_door") { + if(item.type === "Door_Item" || item.type === "Insteon::IOLinc_door") { return "fp_door_"+image_color+"_"+image_size+".png"; } - if(item.type == "FPCamera_Item" ) { + if(item.type === "FPCamera_Item" ) { return "fp_camera_default_"+image_size+".png"; } return "fp_unknown_info_"+image_size+".png"; -} +}; var create_img_popover = function(entity) { }