yaahm.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //########################################################################################
  2. // yaahm.js
  3. // Version 1.0
  4. // See 95_YAAHM for licensing
  5. //########################################################################################
  6. //# Prof. Dr. Peter A. Henning
  7. function encodeParm(oldval) {
  8. var newval;
  9. newval = oldval.replace(/\+/g, '%2B');
  10. newval = newval.replace(/#/g, '%23');
  11. newval = newval.replace(/"/g, '%27');
  12. return newval;
  13. }
  14. // Tool Tips
  15. // $( function() {
  16. // $( document ).tooltip();
  17. // } );
  18. // Expand Text box
  19. $(function () {
  20. $(".expand").focus(function () {
  21. $(this).animate({
  22. width: '200px'
  23. },
  24. "slow"
  25. )
  26. });
  27. });
  28. $(function () {
  29. $(".expand").blur(function () {
  30. $(this).animate({
  31. width: '100px'
  32. },
  33. "slow"
  34. )
  35. });
  36. });
  37. //------------------------------------------------------------------------------------------------------
  38. // Write the Attribute Value
  39. //------------------------------------------------------------------------------------------------------
  40. function yaahm_setAttribute(name, attr, val) {
  41. //set Yaahm Attribute
  42. var location = document.location.pathname;
  43. if (location.substr(location.length -1, 1) == '/') {
  44. location = location.substr(0, location.length -1);
  45. }
  46. var url = document.location.protocol + "//" + document.location.host + location;
  47. FW_cmd(url + '?XHR=1&cmd.' + name + '=attr ' + name + ' ' + encodeParm(attr) + ' ' + encodeParm(val));
  48. }
  49. //------------------------------------------------------------------------------------------------------
  50. // Change mode and state, set next time
  51. //------------------------------------------------------------------------------------------------------
  52. function yaahm_mode(name,targetmode) {
  53. var location = document.location.pathname;
  54. if (location.substr(location.length -1, 1) == '/') {
  55. location = location.substr(0, location.length -1);
  56. }
  57. var url = document.location.protocol + "//" + document.location.host + location;
  58. FW_cmd(url + '?XHR=1&cmd.' + name + '={main::YAAHM_mode("' + name + '","' + targetmode + '")}');
  59. }
  60. function yaahm_state(name,targetstate) {
  61. var location = document.location.pathname;
  62. if (location.substr(location.length -1, 1) == '/') {
  63. location = location.substr(0, location.length -1);
  64. }
  65. var url = document.location.protocol + "//" + document.location.host + location;
  66. FW_cmd(url + '?XHR=1&cmd.' + name + '={main::YAAHM_state("' + name + '","' + targetstate + '")}');
  67. }
  68. function yaahm_setnext(name,i) {
  69. var location = document.location.pathname;
  70. if (location.substr(location.length -1, 1) == '/') {
  71. location = location.substr(0, location.length -1);
  72. }
  73. var url = document.location.protocol + "//" + document.location.host + location;
  74. var nval;
  75. if (document.getElementById('wt' + i + '_n') !== null) {
  76. nval = document.getElementById('wt' + i + '_n').value;
  77. } else {
  78. nval = "undef";
  79. }
  80. FW_cmd(url + '?XHR=1&cmd.' + name + '={main::YAAHM_nextWeeklyTime("' + name + '","next_' + i + '","' + nval + '")}');
  81. }
  82. //------------------------------------------------------------------------------------------------------
  83. // Start the daily timer
  84. //------------------------------------------------------------------------------------------------------
  85. function yaahm_startDayTimer(name) {
  86. var location = document.location.pathname;
  87. if (location.substr(location.length -1, 1) == '/') {
  88. location = location.substr(0, location.length -1);
  89. }
  90. var url = document.location.protocol + "//" + document.location.host + location;
  91. // saving start and end times
  92. for (var i = 0; i < dailyno; i++) {
  93. var sval, eval, xval, aval1, aval2;
  94. if ( (dailykeys[i] != 'wakeup') && (dailykeys[i] != 'sleep') ) {
  95. if (document.getElementById('dt' + dailykeys[i] + '_s') !== null) {
  96. sval = document.getElementById('dt' + dailykeys[i] + '_s').value;
  97. } else {
  98. sval = "undef"
  99. }
  100. if (document.getElementById('dt' + dailykeys[i] + '_e') !== null) {
  101. eval = document.getElementById('dt' + dailykeys[i] + '_e').value;
  102. } else {
  103. eval = "undef"
  104. }
  105. if (document.getElementById('dt' + dailykeys[i] + '_x') !== null) {
  106. xval = encodeParm(document.getElementById('dt' + dailykeys[i] + '_x').value);
  107. } else {
  108. xval = "undef"
  109. }
  110. aval1 = $("input[name='actim" + dailykeys[i] + "']:checked").map(function(){
  111. return $(this).val();
  112. }).get();
  113. aval2 = $("input[name='actid" + dailykeys[i] + "']:checked").map(function(){
  114. return $(this).val();
  115. }).get();
  116. FW_cmd(url + '?XHR=1&cmd.' + name + '={main::YAAHM_setParm("' + name + '","dt","' + dailykeys[i] + '",' + '"' + sval + '","' + eval + '","' + xval + '","' + aval1 + ';' + aval2 + '")}');
  117. }
  118. }
  119. // really start it now
  120. FW_cmd(url+'?XHR=1&cmd.' + name + ' ={main::YAAHM_startDayTimer("' + name + '")}');
  121. // change link
  122. $('#dtlink').html('<a href="/fhem?detail='+name+'.dtimer.IF">'+name+'.dtimer.IF</a>');
  123. }
  124. //------------------------------------------------------------------------------------------------------
  125. // Weekly profile
  126. //------------------------------------------------------------------------------------------------------
  127. function yaahm_startWeeklyTimer(name) {
  128. var location = document.location.pathname;
  129. if (location.substr(location.length -1, 1) == '/') {
  130. location = location.substr(0, location.length -1);
  131. }
  132. var url = document.location.protocol + "//" + document.location.host + location;
  133. // saving start weekly times
  134. // iterate over different weekly tables
  135. for (var i = 0; i < weeklyno; i++) {
  136. var xval;
  137. var nval;
  138. var aval1,aval2;
  139. var sval =[ "", "", "", "", "", "", ""];
  140. //action
  141. if (document.getElementById('wt' + i + '_x') !== null) {
  142. xval = encodeParm(document.getElementById('wt' + i + '_x').value);
  143. } else {
  144. xval = "undef"
  145. }
  146. //next time - attention, field is in toptable
  147. if (document.getElementById('wt' + i + '_n') !== null) {
  148. nval = document.getElementById('wt' + i + '_n').value;
  149. } else {
  150. nval = "undef"
  151. }
  152. //activity
  153. aval1 = $("input[name='acti_" + i + "_m']:checked").map(function(){
  154. return $(this).val();
  155. }).get();
  156. aval2 = $("input[name='acti_" + i + "_d']:checked").map(function(){
  157. return $(this).val();
  158. }).get();
  159. //iterate over days of week
  160. for (var j = 0; j < 7; j++) {
  161. if (document.getElementById('wt' + weeklykeys[j] + i +'_s') !== null) {
  162. sval[j] = document.getElementById('wt' + weeklykeys[j] + i + '_s').value;
  163. } else {
  164. sval[j] = "undef";
  165. }
  166. }
  167. FW_cmd(url + '?XHR=1&cmd.' + name + '={main::YAAHM_setParm("' + name + '","wt","' + i + '","' + xval + '","' + nval + '","' + aval1 + '","' + aval2 + '","'+ sval.join('","') + '")}');
  168. }
  169. // really start it now
  170. FW_cmd(url+'?XHR=1&cmd.' + name + ' ={main::YAAHM_startWeeklyTimer("' + name + '")}');
  171. // change links
  172. for (var i = 0; i < weeklyno; i++) {
  173. $('#wt'+i+'link').html('<a href="fhem?detail=' + name + '.wtimer_' + i + '.IF">' + name + '.wtimer_' + i + '.IF</a>');
  174. }
  175. }