From 90d10c1c90a59efe5cb0a10a88d7b21ba5107c0b Mon Sep 17 00:00:00 2001 From: Tobias Sachs Date: Fri, 6 Jan 2017 22:00:14 +0100 Subject: [PATCH 1/2] ia7: prevent access of undefined property Enables adding objects at the root level of the collection. --- web/ia7/include/javascript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ia7/include/javascript.js b/web/ia7/include/javascript.js index 1340b8b1a..e6b6ce26d 100644 --- a/web/ia7/include/javascript.js +++ b/web/ia7/include/javascript.js @@ -1064,7 +1064,7 @@ var loadCollection = function(collection_keys) { var item = json_store.collections[collection].item; if (item !== undefined) { - if (json_store.objects[item] === undefined) { + if (json_store.objects === undefined || json_store.objects[item] === undefined) { var path_str = "/objects"; var arg_str = "fields=state,states,label,state_log,schedule,logger_status,&items="+item; $.ajax({ From 3c82128a544565eccf10b0c9e8505dd9eb94723f Mon Sep 17 00:00:00 2001 From: Tobias Sachs Date: Sat, 7 Jan 2017 19:18:55 +0100 Subject: [PATCH 2/2] ia7: enable direct_control and longclick for items in collection.json --- web/ia7/include/javascript.js | 43 +++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/web/ia7/include/javascript.js b/web/ia7/include/javascript.js index e6b6ce26d..f51ad7dac 100644 --- a/web/ia7/include/javascript.js +++ b/web/ia7/include/javascript.js @@ -1077,13 +1077,21 @@ var loadCollection = function(collection_keys) { } }); } else { + var btn_direct = ""; + if (json_store.ia7_config.objects !== undefined + && json_store.ia7_config.objects[item] !== undefined + && json_store.ia7_config.objects[item].direct_control !== undefined + && json_store.ia7_config.objects[item].direct_control == "yes") { + btn_direct = "btn-direct"; + } + var name = item; var color = getButtonColor(json_store.objects[item].state); if (json_store.objects[item].label !== undefined) name = json_store.objects[item].label; var dbl_btn = ""; if (name.length < 30) dbl_btn = "
"; var button_html = "
"; entity_arr.push(button_html); items += item+","; @@ -1143,10 +1151,35 @@ var loadCollection = function(collection_keys) { // if any items present, then create modals and activate updateItem... if (items !== "") { items = items.slice(0,-1); //remove last comma - $('.btn-state-cmd').click( function () { - var entity = $(this).attr("entity"); - create_state_modal(entity); - }); + $('.btn-state-cmd').click( function () { + var entity = $(this).attr("entity"); + if (json_store.ia7_config.objects !== undefined && json_store.ia7_config.objects[entity] !== undefined) { + if (json_store.ia7_config.objects[entity].direct_control !== undefined && json_store.ia7_config.objects[entity].direct_control == "yes") { + var new_state = ""; + var possible_states = 0; + 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 ((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; + $.get( url); + } else { + create_state_modal(entity); + } + } + else { + create_state_modal(entity); + } + } + ); + $(".btn-state-cmd").mayTriggerLongClicks().on( 'longClick', function() { + var entity = $(this).attr("entity"); + create_state_modal(entity); + }); + $('.btn-resp-modal').click( function () { var url = $(this).attr('href'); alert("resp-model. opening url="+url);