From c7a9812f0318dc21dd676a28765f9bf2e1e8136d Mon Sep 17 00:00:00 2001 From: "H.Plato" Date: Sun, 25 Sep 2016 14:49:49 -0600 Subject: [PATCH 1/6] Fixed jqCron needing 1-7 for DOW. added in conversion subroutine. Included Tobi's fixes for datepicker. --- web/ia7/include/javascript.js | 122 ++++++++++++++++++++++------------ web/ia7/include/jqCron.en.js | 4 +- 2 files changed, 82 insertions(+), 44 deletions(-) diff --git a/web/ia7/include/javascript.js b/web/ia7/include/javascript.js index 36c896fae..c06d61b55 100644 --- a/web/ia7/include/javascript.js +++ b/web/ia7/include/javascript.js @@ -1690,8 +1690,10 @@ var object_history = function(items,start,days,time) { $('.update_history').click(function() { console.log ("start="+$('.hist_start').val()+" end="+$('.hist_end').val()); - var new_start = new Date($('.hist_start').val()).getTime(); - var new_end = new Date($('.hist_end').val()).getTime(); +// var new_start = new Date($('.hist_start').val()).getTime(); +// var new_end = new Date($('.hist_end').val()).getTime(); + var new_start = new Date($('.hist_start').val().split('-')).getTime(); + var new_end = new Date($('.hist_end').val().split('-')).getTime(); var end_days = (new_start - new_end) / (24 * 60 * 60 * 1000) new_start = new_start / 1000; object_history(items,new_start,end_days); @@ -1722,15 +1724,18 @@ var object_history = function(items,start,days,time) { for (var i = 0; i < json.data.data.length; i++) { if (json.data.data[i].label == key) { data.push(json.data.data[i]); - return true; + return true; } } }); // take away the border so that it looks better and span the graph from start to end. json.data.options.grid.borderWidth = 0; - json.data.options.xaxis.min = new Date($('.hist_end').val()).getTime(); - json.data.options.xaxis.max = new Date($('.hist_start').val()).getTime() + (24 * 60 * 60 * 1000); +// json.data.options.xaxis.min = new Date($('.hist_end').val()).getTime(); +// json.data.options.xaxis.max = new Date($('.hist_start').val()).getTime() + (24 * 60 * 60 * 1000); + json.data.options.xaxis.min = new Date($('.hist_end').val().split('-')).getTime(); + json.data.options.xaxis.max = new Date($('.hist_start').val().split('-')).getTime() + (24 * 60 * 60 * 1000); + //console.log("data="+JSON.stringify(data)); //console.log("xmin="+json.data.options.xaxis.min+" xmax="+json.data.options.xaxis.max); $.plot($("#hist-graph"), data, json.data.options); @@ -1833,12 +1838,13 @@ var fp_display_height=0; // updated by fp_resize_floorplan_image var fp_scale = 100; // updated by fp_reposition_entities var fp_grabbed_entity = null; // store item for drag & drop var fp_icon_select_item_id = null; // store item id on right click for icon set selection +var fp_icon_image_size = 48; var noDragDrop = function() { return false; }; -var fp_getOrCreateIcon = function (json, entity, i, coords, show_pos){ +var fp_getOrCreateIcon = function (json, entity, i, coords){ var popover = 0; if ((json.data[entity].type === "FPCamera_Item") || (json_store.ia7_config.prefs.fp_state_popovers === "yes")) popover = 1; @@ -1853,7 +1859,7 @@ var fp_getOrCreateIcon = function (json, entity, i, coords, show_pos){ ''+ + '>'+ ''; if (coords !== ""){ $('#graphic').append(html); @@ -1866,7 +1872,7 @@ var fp_getOrCreateIcon = function (json, entity, i, coords, show_pos){ E.bind("dragstart", noDragDrop); var image = get_fp_image(json.data[entity]); E.attr('src',"/ia7/graphics/"+image); - if (show_pos) + if (developer) E.css("border","1px solid black"); return E; @@ -1884,7 +1890,8 @@ var fp_resize_floorplan_image = function(){ var fp_reposition_entities = function(){ var t0 = performance.now(); - var offset = $("#fp_graphic").offset(); + var fp_graphic_offset = $("#fp_graphic").offset(); + console.log("fp_graphic_offset: "+ JSON.stringify(fp_graphic_offset)); var width = fp_display_width; var hight = fp_display_height; var onePercentWidthInPx = width/100; @@ -1892,8 +1899,8 @@ var fp_reposition_entities = function(){ var fp_get_offset_from_location = function(item) { var y = item[0]; var x = item[1]; - var newy = offset.top + y * onePercentHeightInPx; - var newx = offset.left + x * onePercentWidthInPx; + var newy = fp_graphic_offset.top + y * onePercentHeightInPx; + var newx = fp_graphic_offset.left + x * onePercentWidthInPx; return { "top": newy, "left": newx @@ -1918,21 +1925,22 @@ var fp_reposition_entities = function(){ } else { nwidth = 790; } - - fp_scale = Math.round( width/nwidth * 100); + var fp_scale = width/nwidth; + var fp_scale_percent = Math.round( fp_scale * 100); - console.log("width="+width+" nwidth="+nwidth+" scale="+fp_scale); + console.log("width="+width+" nwidth="+nwidth+" scale="+fp_scale_percent); // update the location of all the objects... $(".floorplan_item").each(function(index) { var classstr = $(this).attr("class"); var coords = classstr.split(/coords=/)[1]; - $(this).width(fp_scale + "%"); + $(this).width(fp_scale_percent + "%"); if (coords.length === 0){ return; } var fp_location = coords.split(/x/); var fp_offset = fp_get_offset_from_location(fp_location); + console.log("coords="+coords); // this seems to make the repositioning slow // ~ 300+ms on my nexus7 firefox-beta vs <100ms with this code commented out @@ -1942,13 +1950,14 @@ var fp_reposition_entities = function(){ // } else { // $(this).attr('src',$(this).attr('src').replace('32.png','48.png')); // } - - var adjust = $(this).width()/2; + var element_id = $(this).attr('id'); + var adjust = fp_icon_image_size*fp_scale/2; + console.log("adjust="+adjust+" fp_offset.top="+fp_offset.top+" fp_offset.left="+fp_offset.left); var fp_off_center = { "top": fp_offset.top - adjust, "left": fp_offset.left - adjust }; - fp_set_pos($(this).attr('id'), fp_off_center); + fp_set_pos(element_id, fp_off_center); }); $('.icon_select img').each(function(){ @@ -1962,7 +1971,23 @@ var fp_set_pos = function(id, offset){ var item = $('#' + id); // do not move the span, this make the popup to narrow somehow // item.closest("span").offset(offset); + var left11 = item.css("left"); + var left12 = item[0].style.left; + var top11 = item.css("top"); + var top12 = item[0].style.top; + var before = item.offset(); + var init = false + if (item.css("left") == "auto") { + console.log("auto found, fixing left property"); + offset.left = 0 - fp_icon_image_size/2; + } item.offset(offset); + var after = item.offset(); + var left21 = item.css("left"); + var left22 = item[0].style.left; + console.log("offset.top="+offset.top+" offset.left="+offset.left+" before.top="+before.top+" before.left="+before.left+" after.top="+after.top+" after.left="+after.left); + console.log("top11="+top11+" top12="+top12); + console.log("left11="+left11+" left12="+left12+" left21="+left21+" left22="+left22); }; var fp_is_point_on_fp = function (p){ @@ -2002,7 +2027,7 @@ var floorplan = function(group,time) { $('#floorplan').append("
"); time = 0; $('#graphic').prepend('
'); - if (URLHash.show_pos){ + if (developer){ $('#fp_graphic').css("border","1px solid black"); $('#list_content').append("
"); $('#list_content').append("
");
@@ -2062,14 +2087,14 @@ var floorplan = function(group,time) {
             if (fp_grabbed_entity === null)
                 return;
 
-            set_set_coordinates_from_offset(fp_grabbed_entity.id);
+            set_coordinates_from_offset(fp_grabbed_entity.id);
             fp_reposition_entities();
             fp_grabbed_entity = null;
         });
 
     }
 
-    var set_set_coordinates_from_offset = function (id)
+    var set_coordinates_from_offset = function (id)
     {
         var E = $('#'+id);
         var offsetE = E.offset();
@@ -2166,7 +2191,7 @@ var floorplan = function(group,time) {
                 var t0 = performance.now();
                 JSONStore(json);
                 for (var entity in json.data) {
-                    if (URLHash.show_pos && requestTime === 0){
+                    if (developer && requestTime === 0){
                         perl_pos_coords = "";
                     }
                     for (var i=0 ; i < json.data[entity].fp_location.length-1; i=i+2){ //allow for multiple graphics
@@ -2174,7 +2199,7 @@ var floorplan = function(group,time) {
                         if ((json.data[entity].type === "FPCamera_Item") || (json_store.ia7_config.prefs.fp_state_popovers === "yes"))
                             popover = 1;
 
-                        if (URLHash.show_pos && requestTime === 0){
+                        if (developer && requestTime === 0){
                             if (perl_pos_coords.length !== 0){
                                 perl_pos_coords += ", ";
                             }
@@ -2182,9 +2207,9 @@ var floorplan = function(group,time) {
                         }
 
                         var coords= json.data[entity].fp_location[i]+'x'+json.data[entity].fp_location[i+1];
-                        var E = fp_getOrCreateIcon(json, entity, i, coords, URLHash.show_pos);
+                        var E = fp_getOrCreateIcon(json, entity, i, coords, developer);
 
-                        if (URLHash.show_pos === undefined)
+                        if (developer === false)
                         {
                             // create unique popovers for Camera items
                             if (json.data[entity].type === "FPCamera_Item") {
@@ -2271,10 +2296,10 @@ var floorplan = function(group,time) {
                         }
                     }
 
-                    if (URLHash.show_pos && requestTime === 0){
+                    if (developer && requestTime === 0){
                         if (perl_pos_coords.length===0)
                         {
-                            fp_getOrCreateIcon(json, entity, 0, "", URLHash.show_pos);
+                            fp_getOrCreateIcon(json, entity, 0, "");
                         }
                         else{
                             var oldCode = $('#fp_pos_perl_code').text();
@@ -2296,7 +2321,7 @@ var floorplan = function(group,time) {
                     }
                 }
                 fp_reposition_entities();
-                if (requestTime === 0 && URLHash.show_pos){
+                if (requestTime === 0 && developer){
                     $('#list_content').append("

 

"); $.ajax({ type: "GET", @@ -2392,7 +2417,7 @@ var floorplan = function(group,time) { 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) + if (developer === false) floorplan(group,requestTime); } } @@ -2403,14 +2428,13 @@ var get_fp_image = function(item,size,orientation) { var image_name; var image_color = getButtonColor(item.state); var baseimg_width = $(window).width(); - var image_size = "48"; - // if (baseimg_width < 500) image_size = "32" // iphone scaling - //kvar image_size = "32" + // if (baseimg_width < 500) fp_icon_image_size = "32" // iphone scaling + //kvar fp_icon_image_size = "32" if (item.fp_icons !== undefined) { if (item.fp_icons[item.state] !== undefined) return item.fp_icons[item.state]; } if (item.fp_icon_set !== undefined) { - return "fp_"+item.fp_icon_set+"_"+image_color+"_"+image_size+".png"; + return "fp_"+item.fp_icon_set+"_"+image_color+"_"+fp_icon_image_size+".png"; } // if item.fp_icons.return item.fp_icons[state]; if(item.type === "Light_Item" || item.type === "Fan_Light" || @@ -2422,25 +2446,25 @@ var get_fp_image = function(item,size,orientation) { item.type === "UIO_Item" || item.type === "X10_Item" || item.type === "xPL_Plugwise" || item.type === "X10_Appliance") { - return "fp_light_"+image_color+"_"+image_size+".png"; + return "fp_light_"+image_color+"_"+fp_icon_image_size+".png"; } if(item.type === "Motion_Item" || item.type === "X10_Sensor" || item.type === "Insteon::MotionSensor" ) { - return "fp_motion_"+image_color+"_"+image_size+".png"; + return "fp_motion_"+image_color+"_"+fp_icon_image_size+".png"; } if(item.type === "Door_Item" || item.type === "Insteon::IOLinc_door") { - return "fp_door_"+image_color+"_"+image_size+".png"; + return "fp_door_"+image_color+"_"+fp_icon_image_size+".png"; } if(item.type === "FPCamera_Item" ) { - return "fp_camera_default_"+image_size+".png"; + return "fp_camera_default_"+fp_icon_image_size+".png"; } - return "fp_unknown_info_"+image_size+".png"; + return "fp_unknown_info_"+fp_icon_image_size+".png"; }; var create_img_popover = function(entity) { @@ -2530,7 +2554,18 @@ var create_state_modal = function(entity) { $('#control').find('.modal-footer').find('.sched_submit').remove(); // Unique Schedule Data here if (json_store.objects[entity].schedule !== undefined) { - + + var modify_jqcon_dow = function(cronstr,offset) { + var cron = cronstr.split(/\s+/); + console.log("dow="+cron[cron.length-1]); + cron[cron.length-1] = cron[cron.length-1].replace(/\d/gi, function adjust(x) { + console.log("x="+x+" offset="+offset); + return parseInt(x) + parseInt(offset); + });; + console.log("dow="+cron[cron.length-1]); + return cron.join(" "); + } + var add_schedule = function(index,cron,label,state_sets) { if (cron === null) return; if (label == undefined) label = index; @@ -2609,7 +2644,7 @@ var create_state_modal = function(entity) { console.log("schedule.length="+json_store.objects[entity].schedule.length); for (var i = 1; i < json_store.objects[entity].schedule.length; i++){ var sched_index = json_store.objects[entity].schedule[i][0]; - var sched_cron = json_store.objects[entity].schedule[i][1]; + var sched_cron = modify_jqcon_dow(json_store.objects[entity].schedule[i][1],1); var sched_label = json_store.objects[entity].schedule[i][2]; console.log("si="+sched_index+",sc="+sched_cron+",sl="+sched_label+",ss="+sched_states); add_schedule(sched_index,sched_cron,sched_label,sched_states); @@ -2633,7 +2668,10 @@ var create_state_modal = function(entity) { if ($(this).hasClass("disabled")) return; var string = ""; $('.mhsched').each(function(index,value) { - string += $( this ).attr("id") + ',"' + $( this ).text() + '",' + $( this ).attr("label") + ','; + console.log("string="+string); +// string += $( this ).attr("id") + ',"' + $( this ).text() + '",' + $( this ).attr("label") + ','; + string += $( this ).attr("id") + ',"' + modify_jqcon_dow($(this).text(),"-1") + '",' + $( this ).attr("label") + ','; + console.log("string="+string); }); string = string.replace(/,\s*$/, ""); //remove the last comma var url="/SUB?ia7_update_schedule"+encodeURI("("+$(this).parents('.control-dialog').attr("entity")+","+string+")"); @@ -3019,4 +3057,4 @@ $(document).ready(function() { // // You should have received a copy of the GNU General Public License along with this program; // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// +// \ No newline at end of file diff --git a/web/ia7/include/jqCron.en.js b/web/ia7/include/jqCron.en.js index 779d36836..9823c5bd4 100644 --- a/web/ia7/include/jqCron.en.js +++ b/web/ia7/include/jqCron.en.js @@ -34,7 +34,7 @@ jqCronDefaultSettings.texts.en = { error2: 'Bad number of elements', error3: 'The jquery_element should be set into jqCron settings', error4: 'Unrecognized expression', - weekdays_short: ['M','Tu','W','Th','F','Sa','Su'], - weekdays: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'], + weekdays_short: ['Su','M','Tu','W','Th','F','Sa'], + weekdays: ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'], months: ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'] }; From f8ce00b3223bc8a2dc3a494dfa6f491d742e0972 Mon Sep 17 00:00:00 2001 From: "H.Plato" Date: Sun, 9 Oct 2016 16:58:54 -0600 Subject: [PATCH 2/6] IA7 v1.3.580 - workaround for floorplan initial icon locations --- web/ia7/house/main.shtml | 2 +- web/ia7/include/javascript.js | 70 +++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/web/ia7/house/main.shtml b/web/ia7/house/main.shtml index 7f917f592..001535670 100644 --- a/web/ia7/house/main.shtml +++ b/web/ia7/house/main.shtml @@ -82,7 +82,7 @@

MisterHouse was created by Bruce Winter. Ron Klinkien developed the v2.3 web interface. Kevin Robert Keegan - developed the v4 web interface, updates by H.Plato. IA7 v1.3.560 Font Awesome by Dave Gandy - http://fontawesome.io

+ designed the v4 web prototype, updates by H.Plato. IA7 v1.3.580 Font Awesome by Dave Gandy - http://fontawesome.io

diff --git a/web/ia7/include/javascript.js b/web/ia7/include/javascript.js index c06d61b55..5d365cd7c 100644 --- a/web/ia7/include/javascript.js +++ b/web/ia7/include/javascript.js @@ -1883,7 +1883,7 @@ var fp_resize_floorplan_image = function(){ $("#fp_graphic").attr("width", "1px"); fp_display_width = $("#graphic").width(); - console.log("FP: resize "+ floor_width + " => " + fp_display_width); +// console.log("FP: resize "+ floor_width + " => " + fp_display_width); $('#fp_graphic').attr("width",fp_display_width+"px"); fp_display_height = $("#fp_graphic").height(); }; @@ -1891,7 +1891,7 @@ var fp_resize_floorplan_image = function(){ var fp_reposition_entities = function(){ var t0 = performance.now(); var fp_graphic_offset = $("#fp_graphic").offset(); - console.log("fp_graphic_offset: "+ JSON.stringify(fp_graphic_offset)); +// console.log("fp_graphic_offset: "+ JSON.stringify(fp_graphic_offset)); var width = fp_display_width; var hight = fp_display_height; var onePercentWidthInPx = width/100; @@ -1928,7 +1928,7 @@ var fp_reposition_entities = function(){ var fp_scale = width/nwidth; var fp_scale_percent = Math.round( fp_scale * 100); - console.log("width="+width+" nwidth="+nwidth+" scale="+fp_scale_percent); +// console.log("width="+width+" nwidth="+nwidth+" scale="+fp_scale_percent); // update the location of all the objects... $(".floorplan_item").each(function(index) { var classstr = $(this).attr("class"); @@ -1940,7 +1940,7 @@ var fp_reposition_entities = function(){ } var fp_location = coords.split(/x/); var fp_offset = fp_get_offset_from_location(fp_location); - console.log("coords="+coords); +// console.log("coords="+coords); // this seems to make the repositioning slow // ~ 300+ms on my nexus7 firefox-beta vs <100ms with this code commented out @@ -1952,7 +1952,7 @@ var fp_reposition_entities = function(){ // } var element_id = $(this).attr('id'); var adjust = fp_icon_image_size*fp_scale/2; - console.log("adjust="+adjust+" fp_offset.top="+fp_offset.top+" fp_offset.left="+fp_offset.left); +// console.log("adjust="+adjust+" fp_offset.top="+fp_offset.top+" fp_offset.left="+fp_offset.left); var fp_off_center = { "top": fp_offset.top - adjust, "left": fp_offset.left - adjust @@ -1961,33 +1961,40 @@ var fp_reposition_entities = function(){ }); $('.icon_select img').each(function(){ - $(this).width(fp_scale + "%"); + $(this).width(fp_scale_percent + "%"); }); var t1 = performance.now(); console.log("FP: reposition and scale: " +Math.round(t1 - t0) + "ms "); }; +var fp_show_all_icons = function() { + + $(".floorplan_item").each(function(index) { + $(this).show(); + }); +}; + var fp_set_pos = function(id, offset){ var item = $('#' + id); // do not move the span, this make the popup to narrow somehow // item.closest("span").offset(offset); - var left11 = item.css("left"); - var left12 = item[0].style.left; - var top11 = item.css("top"); - var top12 = item[0].style.top; - var before = item.offset(); - var init = false - if (item.css("left") == "auto") { - console.log("auto found, fixing left property"); - offset.left = 0 - fp_icon_image_size/2; - } +// var left11 = item.css("left"); +// var left12 = item[0].style.left; +// var top11 = item.css("top"); +// var top12 = item[0].style.top; +// var before = item.offset(); +// var init = false +// if (item.css("left") == "auto") { + // console.log("auto found, fixing left property"); +// offset.left = 0 - fp_icon_image_size/2; +// } item.offset(offset); - var after = item.offset(); - var left21 = item.css("left"); - var left22 = item[0].style.left; - console.log("offset.top="+offset.top+" offset.left="+offset.left+" before.top="+before.top+" before.left="+before.left+" after.top="+after.top+" after.left="+after.left); - console.log("top11="+top11+" top12="+top12); - console.log("left11="+left11+" left12="+left12+" left21="+left21+" left22="+left22); +// var after = item.offset(); +// var left21 = item.css("left"); +// var left22 = item[0].style.left; +// console.log("offset.top="+offset.top+" offset.left="+offset.left+" before.top="+before.top+" before.left="+before.left+" after.top="+after.top+" after.left="+after.left); +// console.log("top11="+top11+" top12="+top12); +// console.log("left11="+left11+" left12="+left12+" left21="+left21+" left22="+left22); }; var fp_is_point_on_fp = function (p){ @@ -2033,7 +2040,7 @@ var floorplan = function(group,time) { $('#list_content').append("
");
         }
         $('#fp_graphic').bind("load", function () {
-            console.log("FP: background loaded.");
+//            console.log("FP: background loaded.");
             fp_resize_floorplan_image();
             floorplan(group, time);
         });
@@ -2165,7 +2172,7 @@ var floorplan = function(group,time) {
             return;
         }
 
-        console.log("FP: window resized");
+//        console.log("FP: window resized");
         fp_resize_floorplan_image();
         fp_reposition_entities();
     };
@@ -2328,10 +2335,10 @@ var floorplan = function(group,time) {
                         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)+'"');
+//                            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)+'"');
+//                            console.log('FP: request iconsets: "' + statusText + '" "'+JSON.stringify(jqXHR, undefined,2)+'"');
                             var requestTime = time;
                             if (jqXHR.status === 200) {
                                 var iconlist = '
diff --git a/web/ia7/include/javascript.js b/web/ia7/include/javascript.js index 4e3126d1c..5058dd93c 100644 --- a/web/ia7/include/javascript.js +++ b/web/ia7/include/javascript.js @@ -1803,13 +1803,15 @@ var object_history = function(items,start,days,time) { $('#hist-legend').find("li").eq(i).prepend('    '); }); } else { + // table var html = ""; html += ""; html += ""; if (json.data.data !== undefined) { //If no data, at least show the header + json.data.data.reverse(); for (var i = 0; i < json.data.data.length; i++){ html +=""; - html += ""; + html += ""; html += ""; html += ""; html += ""; From 39a395be125c82d4e792da7a31240850cbfa8cdd Mon Sep 17 00:00:00 2001 From: "H.Plato" Date: Thu, 20 Oct 2016 20:07:45 -0600 Subject: [PATCH 4/6] IA7 v1.3.600 -- updated staticpage to include direct control. Some cleanup of console.log's and comments --- web/ia7/house/main.shtml | 2 +- web/ia7/include/javascript.js | 90 +++++++++-------------------------- 2 files changed, 23 insertions(+), 69 deletions(-) diff --git a/web/ia7/house/main.shtml b/web/ia7/house/main.shtml index 8a28a6a19..d66a35d99 100644 --- a/web/ia7/house/main.shtml +++ b/web/ia7/house/main.shtml @@ -82,7 +82,7 @@

MisterHouse was created by Bruce Winter. Ron Klinkien developed the v2.3 web interface. Kevin Robert Keegan - designed the v4 web prototype, updates by H.Plato. IA7 v1.3.590 Font Awesome by Dave Gandy - http://fontawesome.io

+ designed the v4 web prototype, updates by H.Plato. IA7 v1.3.600 Font Awesome by Dave Gandy - http://fontawesome.io

diff --git a/web/ia7/include/javascript.js b/web/ia7/include/javascript.js index 5058dd93c..9090772de 100644 --- a/web/ia7/include/javascript.js +++ b/web/ia7/include/javascript.js @@ -1,4 +1,4 @@ -// v1.3 +// v1.3.600 var entity_store = {}; //global storage of entities var json_store = {}; @@ -202,7 +202,6 @@ function changePage (){ } else if (path.indexOf('prefs') === 0){ var pref_name = path.replace(/\prefs\/?/,''); - console.log("loadprefs() "+pref_name); loadPrefs(pref_name); } else if(URLHash._request == 'page'){ @@ -308,31 +307,20 @@ function loadPrefs (config_name){ //show ia7 prefs, args ia7_prefs, ia7_rrd_pref }); } html += "
"; - console.log(config_data); - console.log("in prefs="+config_data.length); for (var i in config_data){ if ( typeof config_data[i] === 'object') { console.log("i "+i+":"); html += ""; for (var j in config_data[i]) { if ( typeof config_data[i][j] === 'object') { - //console.log("j "+j+":"); html += ""; - for (var k in config_data[i][j]){ - //console.log("k "+k+" = "+json_store.ia7_config[i][j][k]); html += ""; } - //html +=""; } else { - //console.log("j "+j+" = "+json_store.ia7_config[i][j]); html += "" } } - //html +=""; - } else { - //console.log("i "+i+" : "+json_store.ia7_config[i]); - //html += ""; } } @@ -358,7 +346,6 @@ function parseLinkData (link,data) { data = data.replace(/.*?<\/a>/img,''); } if (link == "/bin/items.pl") { - console.log("items data="+data); var coll_key = window.location.href.substr(window.location.href.indexOf('_collection_key')) data = data.replace(/href=\/bin\/items.pl/img, 'onclick="changePage()"'); data = data.replace(/\(back to top<\/a>\)/img, ''); @@ -377,14 +364,11 @@ function parseLinkData (link,data) { } if (link == "/bin/triggers.pl") { //fix links in the triggers modules var coll_key = window.location.href.substr(window.location.href.indexOf('_collection_key')) - //data = data.replace(/href=\/bin\/triggers.pl/img, 'href=/ia7/#_request=page&link=/bin/triggers.pl&'+coll_key); data = data.replace(/href=\/bin\/triggers.pl/img, 'onclick="changePage()"'); data = data.replace(/\(back to top<\/a>\)/img, ''); data = data.replace(/Trigger Index:/img,''); data = data.replace(/.*?<\/a>/img,''); - //data = data.replace(/onChange=\'form.submit\(\)\'/img,'onChange=\'this\.form\.submit\(\)\''); data = data.replace(/input name='resp' value="\/bin\/triggers.pl"/img, 'input name=\'resp\' value=\"/ia7/#_request=page&link=/bin/triggers.pl&'+coll_key+'\"'); - //console.log(data); } if (link == "/ia5/news/main.shtml") { //fix links in the email module 1 var coll_key = window.location.href.substr(window.location.href.indexOf('_collection_key')) @@ -427,12 +411,6 @@ function parseLinkData (link,data) { if (btn.attr('name') !== undefined) { form_data.push({name : btn.attr('name'), value : btn.attr('value')}); } - console.log("MHResponse Custom submit function "+ form.attr('action')); - console.log( $(this).serializeArray() ); - console.log( "btn: "+btn.attr('name')+"="+btn.attr('value')); -// if (btn.attr('value') !== undefined) { -// console.log("executing data!"); -// unless the btn attribute has a name, then don't push the data (prevent text fields $.ajax({ type: "POST", url: form.attr('action'), @@ -448,12 +426,9 @@ function parseLinkData (link,data) { var end = data.toLowerCase().indexOf(''); if (form.attr('action') === "/bin/triggers.pl?add" && ! data.match(/Not authorized to make updates/)) { - //location.reload(); changePage(); } else if (form.attr('action') === "/bin/iniedit.pl") { -// var pdata = parseLinkData("/bin/iniedit.pl",data); parseLinkData("/bin/iniedit.pl",data); -// $('#row_page').html(pdata); //TODO parse data } else { $('#lastResponse').find('.modal-body').html(data.substring(start, end)); @@ -463,7 +438,6 @@ function parseLinkData (link,data) { } } }); -// } }); $('#mhresponse :input:not(:text)').change(function() { //TODO - don't submit when a text field changes @@ -911,7 +885,6 @@ var updateItem = function(item,link,time) { //URLHash.time = json_store.meta.time; if (updateSocket !== undefined && updateSocket.readyState != 4){ // Only allow one update thread to run at once - //console.log("updateItem: Aborting update. updateSocket="+updateSocket.readyState); updateSocket.abort(); } if (time === undefined) { @@ -1003,8 +976,26 @@ var updateStaticPage = function(link,time) { //don't run this if stategrp0 exists if (states_loaded == 0) { $(".btn-state-cmd").click( function () { - var entity = $(this).attr("entity"); - create_state_modal(entity); + 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); + } }); } } @@ -1028,7 +1019,6 @@ function authDetails() { alert("Warning, Collection ID 700: Authorize, is not defined in your collections.json!"); } else { if (json_store.collections[700].user !== undefined) { -// console.log ("user found "+json_store.collections[700].user+"."); if (json_store.collections[700].user == "0") { json_store.collections[700].name = "Log in"; json_store.collections[700].icon = "fa-lock"; @@ -1058,17 +1048,10 @@ var loadCollection = function(collection_keys) { if (entity_sort.length <= 0){ entity_arr.push("Childless Collection"); } -// if (json_store.collections[700] == undefined) { -// alert("Warning, Collection ID 700: Authorize, is not defined in your collections.json!"); -// } else { -// authDetails(); -// } for (var i = 0; i < entity_sort.length; i++){ var collection = entity_sort[i]; -// console.log ("col="+collection); if (!(collection in json_store.collections)) continue; -// console.log ("starting"); var link = json_store.collections[collection].link; var icon = json_store.collections[collection].icon; @@ -1199,7 +1182,6 @@ function fixIA7Nav() { var url = $(location).attr('href'); var collid = url.split("_collection_key="); - console.log("fixing nav..."+url+" "+collid[1]); $('a').each(function() { if ($(this).attr('href').match("^/ia7/")) { this.href += '&_collection_key='+collid[1]+','; @@ -1327,7 +1309,6 @@ var mobile_device = function() { function audio_play(audioElement,srcUrl) { - //console.log ("in audio_play:"+srcUrl); audioElement.pause(); audioElement.src=''; //force playback to stop and quit buffering. Not sure if this is strictly necessary. $("#sound_element2").attr("src", srcUrl); //needed for mobile @@ -1341,7 +1322,6 @@ function playWhenReady() {//wait for media element to be ready, then play audioElement=document.getElementById('sound_element'); var audioReady=audioElement.readyState; - //console.log("playWhenReady = "+audioReady); if(audioReady>2) { audioElement.play(); } else if(audioElement.error) { @@ -1689,9 +1669,6 @@ var object_history = function(items,start,days,time) { }); $('.update_history').click(function() { - console.log ("start="+$('.hist_start').val()+" end="+$('.hist_end').val()); -// var new_start = new Date($('.hist_start').val()).getTime(); -// var new_end = new Date($('.hist_end').val()).getTime(); var new_start = new Date($('.hist_start').val().split('-')).getTime(); var new_end = new Date($('.hist_end').val().split('-')).getTime(); var end_days = (new_start - new_end) / (24 * 60 * 60 * 1000) @@ -1731,13 +1708,9 @@ var object_history = function(items,start,days,time) { // take away the border so that it looks better and span the graph from start to end. json.data.options.grid.borderWidth = 0; -// json.data.options.xaxis.min = new Date($('.hist_end').val()).getTime(); -// json.data.options.xaxis.max = new Date($('.hist_start').val()).getTime() + (24 * 60 * 60 * 1000); json.data.options.xaxis.min = new Date($('.hist_end').val().split('-')).getTime(); json.data.options.xaxis.max = new Date($('.hist_start').val().split('-')).getTime() + (24 * 60 * 60 * 1000); -//console.log("data="+JSON.stringify(data)); -//console.log("xmin="+json.data.options.xaxis.min+" xmax="+json.data.options.xaxis.max); $.plot($("#hist-graph"), data, json.data.options); $('.legend').hide(); } @@ -1885,7 +1858,6 @@ var fp_resize_floorplan_image = function(){ $("#fp_graphic").attr("width", "1px"); fp_display_width = $("#graphic").width(); -// console.log("FP: resize "+ floor_width + " => " + fp_display_width); $('#fp_graphic').attr("width",fp_display_width+"px"); fp_display_height = $("#fp_graphic").height(); }; @@ -1930,8 +1902,6 @@ var fp_reposition_entities = function(){ var fp_scale = width/nwidth; var fp_scale_percent = Math.round( fp_scale * 100); -// console.log("width="+width+" nwidth="+nwidth+" scale="+fp_scale_percent); - // update the location of all the objects... $(".floorplan_item").each(function(index) { var classstr = $(this).attr("class"); @@ -1943,19 +1913,9 @@ var fp_reposition_entities = function(){ } var fp_location = coords.split(/x/); var fp_offset = fp_get_offset_from_location(fp_location); -// console.log("coords="+coords); - - // this seems to make the repositioning slow - // ~ 300+ms on my nexus7 firefox-beta vs <100ms with this code commented out - // var baseimg_width = $("#fp_graphic").width(); - // if (baseimg_width < 500) { - // $(this).attr('src',$(this).attr('src').replace('48.png','32.png')); - // } else { - // $(this).attr('src',$(this).attr('src').replace('32.png','48.png')); - // } + var element_id = $(this).attr('id'); var adjust = fp_icon_image_size*fp_scale/2; -// console.log("adjust="+adjust+" fp_offset.top="+fp_offset.top+" fp_offset.left="+fp_offset.left); var fp_off_center = { "top": fp_offset.top - adjust, "left": fp_offset.left - adjust @@ -2270,16 +2230,13 @@ var floorplan = function(group,time) { } } html += ""; - //console.log("html="+html) } return html; } }); } else { E.click( function () { - //var fp_entity = $(this).attr("id").split(/entity_/)[1]; // var fp_entity = $(this).attr("id").match(/entity_(.*)_\d+$/)[1]; //strip out entity_ and ending _X ... item names can have underscores in them. - //alert("entity="+fp_entity); create_state_modal(fp_entity); }); } @@ -2323,10 +2280,8 @@ var floorplan = function(group,time) { 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"; -# $form .= "\n"; + + # $form .= "\n"; return $form; } sub html_form_select_set_var { my ( $var, $default, @values ) = @_; - my ($mode) = ($Http{Referer} =~ /https?:\/\/\S+:?\D*\/(\S+)\//); + my ($mode) = ( $Http{Referer} =~ /https?:\/\/\S+:?\D*\/(\S+)\// ); my $id = ""; - #$id = "id='mhresponse'" if ($mode eq 'ia7'); + + #$id = "id='mhresponse'" if ($mode eq 'ia7'); my $html = "
TimeStateSet By
"+new Date(json.data.data[i][0]).toUTCString()+""+new Date(json.data.data[i][0]).toString().replace(/GMT-\d\d\d\d/,"")+""+String(json.data.data[i][1])+""+String(json.data.data[i][2])+"
"+ config_name + "_config.json
"+ i + "
"+ j + "
"+k+" = "+config_data[i][j][k]+"
"+j+" = "+config_data[i][j]+"
"+ String(json_store.ia7_config[i]) + "
\n|; $html .= qq|\n|; @@ -1596,9 +1613,10 @@ sub html_form_input_set_func { sub html_form_input_set_var { my ( $var, $resp, $default ) = @_; $default = HTML::Entities::encode($default); - my ($mode) = ($Http{Referer} =~ /https?:\/\/\S+:?\D*\/(\S+)\//); + my ($mode) = ( $Http{Referer} =~ /https?:\/\/\S+:?\D*\/(\S+)\// ); my $id = ""; - #$id = "id='mhresponse'" if ($mode eq 'ia7'); + + #$id = "id='mhresponse'" if ($mode eq 'ia7'); my $html .= qq|
\n|; $html .= qq|\n|; $html .= qq|\n|; @@ -1626,10 +1644,11 @@ sub html_form_select { sub html_form_select_set_func { my ( $func, $resp, $var1, $default, @values ) = @_; - my ($mode) = ($Http{Referer} =~ /https?:\/\/\S+:?\D*\/(\S+)\//); + my ($mode) = ( $Http{Referer} =~ /https?:\/\/\S+:?\D*\/(\S+)\// ); my $id = ""; + #$id = "id='mhresponse'" if ($mode eq 'ia7'); -# my $form .= qq|\n|; + # my $form .= qq|\n|; my $form .= qq|\n|; $form .= qq|\n|; $form .= qq|\n|; @@ -1643,15 +1662,17 @@ sub html_form_select_set_func { $form .= qq|\n|; } $form .= "
\n"; $html .= qq|\n|; $html .= qq|\n|;