";
+ echo "".$trs['Name'];
+ echo " ";
+
+ echo " ";
+ echo "".$trs["enabled"]." ";
+ echo "".$trs["disabled"]." ";
+ echo "
"; // srradio
+
+ // Conditions
+ echo "\n";
+ echo "".$trs["Conditions"];
+ echo " ";
+ echo " ";
+ echo " ";
+ echo " ";
+ echo " ";
+ echo " \n";
+ echo "";
+ echo " ".$trs["Address"]." ".$trs["Operator"]." ".$trs["Value"]."\n";
+ foreach ($srules[$selruleid]['conditions'] as $cond => $cval){getCondRow($sensorid, $cond, $cval);}
+ echo "
";
+ echo " \n";
+
+ // Actions
+ echo "".$trs["Actions"];
+ echo " ";
+ echo " ";
+ echo " ";
+ echo " ";
+ echo " ";
+ echo " \n";
+ echo "";
+ echo " ".$trs["Address"]." ".$trs["Method"]." ".$trs["Action"]."\n";
+ foreach ($srules[$selruleid]['actions'] as $act => $aval){getActRow($act, $aval);}
+ echo "
";
+ echo "".$trs["method_warning"]." ";
+ echo " \n";
+
+ // Management buttons (Add/Update+Delete)
+ echo " ";
+ echo "";
+ if ($selruleid == 0){// Create
+ echo $trs["Add"];
+ } else { // Update and Delete
+ echo $trs["Update"];
+ echo " ";
+
+ echo " ";
+ echo "".$trs["Delete"];
+ }
+ echo " ";
+
+ // Empty div for dialog
+ echo "
";
+}
+?>
+
diff --git a/include/text_en.json b/include/text_en.json
index cb8901d..01b9709 100644
--- a/include/text_en.json
+++ b/include/text_en.json
@@ -86,5 +86,27 @@
"Execution_trace" : "Execution trace",
"Close" : "Close",
"Running_please_wait" : "Running, please wait ...",
-"Rules" : "Rules"
+"Rules" : "Rules",
+"Rule" : "Rule",
+"Rules_management" : "Rules management by sensor",
+"Sensor":"Sensor",
+"CREATE_NEW_RULE":"CREATE NEW RULE",
+"Status":"Status",
+"enabled":"Enabled",
+"disabled":"Disabled",
+"Conditions":"Condition(s)",
+"Address":"Address",
+"Operator":"Operator",
+"op_dx":"changed",
+"Value":"Value",
+"Actions":"Action(s)",
+"Method":"Method",
+"Action":"Action",
+"method_warning":"Warning: unless you know what you do, don't play with the 'Method' parameter (default=PUT).",
+"Move_up":"Move up",
+"Move_down":"Move down",
+"Update":"Update",
+"Delete":"Delete",
+"Add":"Add",
+"":""
}
diff --git a/include/text_fr.json b/include/text_fr.json
index c068260..7d487e0 100644
--- a/include/text_fr.json
+++ b/include/text_fr.json
@@ -43,7 +43,7 @@
"Select" : "Sélectionner",
"or_create" : "ou créer",
"Fill_Group" : "Remplir gr",
-"Delete_selected_groups" : "Supprimer groupe(s) sélectionne(s)",
+"Delete_selected_groups" : "Supprimer groupe(s) sélectionné(s)",
"Delete_groups" : "Supprimer groupe(s)",
"Informations" : "Informations",
"Light_id":"Id lumière",
@@ -86,5 +86,27 @@
"Execution_trace" : "Trace d'exécution",
"Close" : "Fermer",
"Running_please_wait" : "Exécution en cours, attendre svp ...",
-"Rules" : "Règles"
+"Rules" : "Règles",
+"Rule" : "Règle",
+"Rules_management" : "Gestion règles par senseur",
+"Sensor":"Senseur",
+"CREATE_NEW_RULE":"CREER NOUVELLE REGLE",
+"Status":"Statut",
+"enabled":"Activé",
+"disabled":"Désactivé",
+"Conditions":"Condition(s)",
+"Address":"Adresse",
+"Operator":"Operateur",
+"op_dx":"changé",
+"Value":"Valeur",
+"Actions":"Action(s)",
+"Method":"Méthode",
+"Action":"Action",
+"method_warning":"Attention : à moins que vous sachiez ce que vous faites, ne jouez pas avec le paramètre 'Méthode' (défaut=PUT).",
+"Move_up":"Monter",
+"Move_down":"Descendre",
+"Update":"Mettre à jour",
+"Delete":"Supprimer",
+"Add":"Ajouter",
+"":""
}
diff --git a/index.php b/index.php
index f04779e..d0982a8 100644
--- a/index.php
+++ b/index.php
@@ -51,6 +51,7 @@
">
">
">
+ ">
">
diff --git a/js/functions.js b/js/functions.js
index 951ccc4..e22e64c 100644
--- a/js/functions.js
+++ b/js/functions.js
@@ -1,9 +1,17 @@
// Javascript Functions for phpMyHue
// F. Bardin 2015/02/10
-// -----------------------------------
-/*====================================
- Generic Functions
-=====================================*/
+//------------------------------------------------------------------------
+// Functions list :
+// isMobile returns true/false if navigator is used from a mobile device
+// uniqid generates a pseudo unique id of 13 char (+ prefix if supplied)
+// $.scrollbarWidth returns the scroll bar width of the navigator in pixels
+// scrollCurrentTab enables vertical scroll of a tab id if needed
+// msg displays a normal message or an error then fades it out
+// processReturnMsg processes return message send by the bridge and display it with msg()
+// getCurrentTabsID returns the current tab id of a given tab object
+// lightList manage list list event (for light tab or scene detail tab)
+// switchGroup switch on or off a group of lamps
+//------------------------------------------------------------------------
//----------------------------------------
// Create fonctions for mobiles detection
//----------------------------------------
diff --git a/js/lights.js b/js/lights.js
index b4ddcd6..b5473cf 100644
--- a/js/lights.js
+++ b/js/lights.js
@@ -199,6 +199,7 @@ function loadSelectedLightsDetail(tablights){
//---------------------------------------
// Execute action from lights detail tab
+// Parameters : action [,xy color value]
//---------------------------------------
function lightsDetailAction(tabaction,xy){
var type = "";
diff --git a/js/rules.js b/js/rules.js
new file mode 100644
index 0000000..6a8020a
--- /dev/null
+++ b/js/rules.js
@@ -0,0 +1,447 @@
+/*-------------------------
+ Functions for rules tab
+ F. Bardin 05/03/2016
+ -------------------------*/
+
+//---------------------------------------
+// Globals for rules details tab
+//---------------------------------------
+var nbcond, nbact; // number of rows for condition or action
+var nextcondid, nextactid; // next id for condition or action
+var selcond, selact; // selected row for condition or action
+var tabdetail = "#"+getCurrentTabsID("#detail");
+var rowmaxelem = 4; // Max number of elements in a row
+
+//=======================================
+// Function for rules tab
+//=======================================
+function rulesTab(){
+ scrollCurrentTab("#tabs");
+
+ // Get selector for Div ID of current tab
+ var tabrules = "#"+getCurrentTabsID("#tabs");
+
+ // Trigger sensor selection
+ $("#tabs td span.ui-icon input").click(function(){
+ $(this).change();
+ });
+ // Select sensor rules when a new selection occurs
+ $("#tabs input[type=radio][name=seradio]").change(function(){
+ $("#tabs span.ui-icon-arrow-1-e").each(function(){
+ $(this).removeClass("ui-icon-arrow-1-e");
+ $(this).addClass("ui-icon-radio-off");
+ $(this).parent("td").parent("tr").removeClass("ui-state-focus");
+ });
+ var cbspan = $(this).parent("span");
+ cbspan.parent("td").parent("tr").addClass("ui-state-focus");
+ cbspan.removeClass("ui-icon-radio-off");
+ cbspan.addClass("ui-icon-arrow-1-e");
+ // Load detail tab with sensor rules
+ var sensorid = $(this).attr("id");
+ $(tabdetail).load("details.php?rt=rules&sensor="+sensorid, function(){
+ $("#detail").show("slide");
+ scrollCurrentTab("#detail");
+ });
+ });
+} // rulesTab
+
+//=======================================
+// Functions for rules details tab
+//=======================================
+//---------------------------------------
+// Trigger row selection
+// Select a row for conditions or actions acts as a radio button
+// Row selection impacts button enable/disable
+//---------------------------------------
+function catchRowSelection(objectid){
+ $(objectid).change(function() {
+ var id=$(this).attr("id");
+ var selClass=$(this).attr("class");
+ var pref=selClass.substr(0,1); // get 'c' or 'a'
+ var buttonList="#"+pref+"del";
+ if (! $("#"+id).parent("span").hasClass("cbchecked")){ // if not checked, remove existing checked
+ $(tabdetail+" tbody span.cbchecked input."+selClass).prop("checked",false);
+ $(tabdetail+" tbody span.cbchecked input."+selClass).parent("span").removeClass("cbchecked");
+ // The current row is checked --> Enable buttons
+ $(buttonList).button("option", "disabled", false);
+
+ // Stored clicked row and disable up/down button if needed
+ var selrow = $(this).parent("span").parent("td").parent("tr").index();
+ var tableid;
+ if (pref == "c"){
+ selcond = selrow;
+ tableid = "condtable";
+ } else {
+ selact = selrow;
+ tableid = "acttable";
+ }
+ updateUpDownState(tableid);
+
+ } else { // The current row is unchecked --> disable buttons
+ buttonList="#"+pref+"mvup, #"+pref+"mvdn, "+buttonList;
+ $(buttonList).button("option", "disabled", true);
+ if (pref == "c"){selcond = "";}
+ else {selact = "";}
+ }
+ $("#"+id).parent("span").toggleClass("cbchecked");
+ });
+} // catchRowSelection
+
+//---------------------------------------
+// Trigger operator change
+//---------------------------------------
+function catchSelopeChange(objectid){
+ $(objectid).on("selectmenuchange", function (event,val) {
+ var condnum = $(this).attr("id").substr(7); // id = "sbcond_"+cond
+ var valope = $(this).val();
+ var valid = "cval"+condnum;
+ if (valope == "dx"){$("#"+valid).hide();}
+ else {$("#"+valid).show();}
+ });
+} // catchSelopeChange
+
+//--------------------------------------------------
+// Set the state (enable/disable) of the tables buttons
+// These buttons are : up, down, delete, add
+//--------------------------------------------------
+function setButtonsState(){
+ // Table conditions buttons
+ if (nbcond == 1){
+ $(tabdetail+" tbody input.csel").hide(0);
+ $("#cmvup, #cmvdn, #cdel").button("option", "disabled", true);
+ } else {
+ $(tabdetail+" tbody input.csel").filter(":first").show(0);
+ }
+ if (nbcond == rowmaxelem) {$("#cadd").button("option", "disabled", true);}
+ else {$("#cadd").button("option", "disabled", false);}
+
+ // Table actions buttons
+ if (nbact == 1){
+ $(tabdetail+" tbody input.asel").hide(0);
+ $("#amvup, #amvdn, #adel").button("option", "disabled", true);
+ } else {
+ $(tabdetail+" tbody input.asel").filter(":first").show(0);
+ }
+ if (nbact == rowmaxelem){$("#aadd").button("option", "disabled", true);}
+ else {$("#aadd").button("option", "disabled", false);}
+} // setButtonsState
+
+//----------------------------------------------------------
+// Update up and down button depending on the selected row
+// parameter : tableid = id of table buttons
+//----------------------------------------------------------
+function updateUpDownState(tableid){
+ var selrow, nbrow, pref;
+ // Init values
+ if (tableid == "condtable"){
+ selrow = selcond;
+ nbrow = nbcond;
+ pref = "c";
+ } else {
+ selrow = selact;
+ nbrow = nbact;
+ pref = "a";
+ }
+ if (selrow == 1){ // if 1st row : disable up button
+ $("#"+pref+"mvup").button("option","disabled", true);
+ if (nbrow > 1){
+ $("#"+pref+"mvdn").button("option","disabled", false);
+ }
+ } else {
+ $("#"+pref+"mvup").button("option","disabled", false);
+ if (selrow == nbrow){ // if last row : disable down button
+ $("#"+pref+"mvdn").button("option","disabled", true);
+ } else {
+ $("#"+pref+"mvdn").button("option","disabled", false);
+ }
+ }
+} // updateUpDownState
+
+//---------------------------------------
+// Initialize the rows count with displayed rule
+//---------------------------------------
+function InitRowsCount(){
+ nbcond = $(tabdetail+" tbody input.csel").length;
+ nbact = $(tabdetail+" tbody input.asel").length;
+ nextcondid = nbcond;
+ nextactid = nbact;
+ setButtonsState();
+} // InitRowsCount
+
+//---------------------------------------
+// Function for 'sensor' rules detail tab
+//---------------------------------------
+function sensorRulesDetail(){
+ InitRowsCount();
+
+ // Trigger rule display on selection
+ $("#srsel").on("selectmenuchange", function (event,val) {
+ var sensorid = $("#sensorid").val();
+ var ruleid = $(this).val();
+ $(tabdetail).load("details.php?rt=rules&nh=&sensor="+sensorid+"&rule="+ruleid, function(){
+ scrollCurrentTab("#detail");
+ });
+ // re-Initialize rows counters and buttons
+ InitRowsCount();
+ });
+
+ // Trigger row selection and operator change
+ $(tabdetail+" tbody input.csel,"+tabdetail+" tbody input.asel").each(function(){
+ catchRowSelection(this);
+ });
+ $(tabdetail+" .selope").each(function(){
+ catchSelopeChange(this);
+ });
+
+ // Manage buttons trigger for tables
+ $("#cmvup").click(function(){mvUpSelectedDetail("condtable");});
+ $("#cmvdn").click(function(){mvDownSelectedDetail("condtable");});
+ $("#cdel").click(function(){delSelectedDetail("condtable");});
+ $("#cadd").click(function(){addCond();});
+ $("#amvup").click(function(){mvUpSelectedDetail("acttable");});
+ $("#amvdn").click(function(){mvDownSelectedDetail("acttable");});
+ $("#adel").click(function(){delSelectedDetail("acttable");});
+ $("#aadd").click(function(){addAct();});
+
+ // Manage update of rule
+ $("#rupd").click(function(){updateRule();});
+ $("#rdel").click(function(){deleteRule();});
+} // sensorRulesDetail
+
+//-----------------------------------------------------
+// Move up a table row
+// parameter :
+// - tableid = id the table where the row is to move up
+//-----------------------------------------------------
+function mvUpSelectedDetail(tableid){
+ var rowcontent = $("#"+tableid+" tbody span.cbchecked").parent("TD").parent("TR").detach();
+ var rowindex;
+ if (tableid == "condtable") {
+ rowindex = selcond - 1;
+ selcond--;
+ } else {
+ rowindex = selact - 1;
+ selact--;
+ }
+ $("#"+tableid+" tr").eq(rowindex).before(rowcontent);
+ updateUpDownState(tableid);
+} // mvUpSelectedDetail
+
+//-----------------------------------------------------
+// Move down a table row
+// parameter :
+// - tableid = id the table where the row is to move down
+//-----------------------------------------------------
+function mvDownSelectedDetail(tableid){
+ var rowcontent = $("#"+tableid+" tbody span.cbchecked").parent("TD").parent("TR").detach();
+ var rowindex;
+ if (tableid == "condtable") {
+ rowindex = selcond;
+ selcond++;
+ } else {
+ rowindex = selact;
+ selact++;
+ }
+ $("#"+tableid+" tr").eq(rowindex).after(rowcontent);
+ updateUpDownState(tableid);
+} // mvDownSelectedDetail
+
+//-----------------------------------------------------
+// Delete selected row
+// parameters :
+// - tableid = id the table where the row is to delete
+//-----------------------------------------------------
+function delSelectedDetail(tableid){
+ $("#"+tableid+" tbody span.cbchecked").parent("TD").parent("TR").each(function(){
+ $(this).remove();
+ var pref;
+ if (tableid == "condtable"){
+ nbcond--;
+ pref = "c";
+ } else {
+ nbact--;
+ pref = "a";
+ }
+ // Row deleted = no selection --> disable buttions
+ var buttonList="#"+pref+"mvup, #"+pref+"mvdn, #"+pref+"del";
+ $(buttonList).button("option", "disabled", true);
+ setButtonsState();
+ });
+} // delSelectedDetail
+
+//-----------------------------------------------------
+// Add new condition row
+//-----------------------------------------------------
+function addCond(){
+ var sensorid = $("#sensorid").val();
+ $("#condtable").append("