module.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. registerController("getController", ['$api', '$scope', function($api, $scope) {
  2. getControls();
  3. getClientProfiles();
  4. $scope.messages = [];
  5. $scope.profiles = [];
  6. $scope.throbber = true;
  7. $scope.enabled = false;
  8. $scope.hidden = false;
  9. $scope.dbonsd = false;
  10. $scope.comments = "";
  11. $scope.workshopProfile = {id: "", hostname: "", info: "", mac: "", ip: "", comments: "", date: ""};
  12. $scope.handleControl = function(control) {
  13. control.throbber = true;
  14. switch (control.title) {
  15. /*
  16. case "Hidden iFrame":
  17. $api.request({
  18. module: "get",
  19. action: "handleIFrame",
  20. data: $scope.hidden
  21. }, function(response) {
  22. getControls();
  23. control.throbber = false;
  24. // based on the response from the module, we need to update the variable in the browser
  25. if ( response.hidden_status == "true" ) $scope.hidden = true;
  26. if ( response.hidden_status == "false" ) $scope.hidden = false;
  27. // write message to messages panel
  28. $scope.sendMessage(control.title, response.control_message ); // + " " + response.hidden_status);
  29. });
  30. break;
  31. */
  32. case "Enable Module":
  33. $api.request({
  34. module: "get",
  35. action: "handleInfoGetter",
  36. data: $scope.enabled
  37. }, function(response) {
  38. getControls();
  39. control.throbber = false;
  40. // based on the response from the module, we need to update the variable in the browser
  41. if ( response.enabled_status == "true" ) $scope.enabled = true;
  42. if ( response.enabled_status == "false" ) $scope.enabled = false;
  43. // write message to messages panel
  44. $scope.sendMessage(control.title, response.control_message ); // + " " + response.enabled_status);
  45. });
  46. break;
  47. case "Database on SD":
  48. //alert($scope.dbonsd);
  49. $api.request({
  50. module: "get",
  51. action: "handleDBLocation",
  52. data: $scope.dbonsd
  53. }, function(response) {
  54. getControls();
  55. control.throbber = false;
  56. // based on the response from the module, we need to update the variable in the browser
  57. if ( response.dbonsd_status == "true" ) $scope.dbonsd = true;
  58. if ( response.dbonsd_status == "false" ) $scope.dbonsd = false;
  59. // write message to messages panel
  60. $scope.sendMessage(control.title, response.control_message ); // + " " + response.dbonsd_status);
  61. });
  62. break;
  63. }
  64. }
  65. $scope.getComments = function(profile) {
  66. console.log("Getting comments for: " + profile.mac );
  67. $scope.workshopProfile = profile;
  68. $api.request({
  69. module: "get",
  70. action: "getComments",
  71. id: profile.id,
  72. mac: profile.mac
  73. }, function(response) {
  74. $scope.sendMessage("Retrieved comments ", response.message);
  75. console.log( $scope.workshopProfile );
  76. });
  77. }
  78. $scope.saveComments = function(profileid, mac, comments) {
  79. //console.log("Saving comments for: " + profileid + " Comments: " + comments);
  80. $api.request({
  81. module: "get",
  82. action: "saveComments",
  83. id: profileid,
  84. comments: comments,
  85. mac: mac
  86. }, function(response) {
  87. $scope.sendMessage("Comments Saved ", response.message);
  88. // we need to refresh the data for all records... This is not a good design, but ok for now..
  89. getClientProfiles();
  90. });
  91. }
  92. $scope.deleteProfile = function(profile) {
  93. //console.log( profile.mac );
  94. $api.request({
  95. module: "get",
  96. action: "deleteProfile",
  97. mac: profile.mac,
  98. id: profile.id
  99. }, function(response) {
  100. $scope.sendMessage("Record Deleted ", response.message);
  101. getClientProfiles();
  102. });
  103. }
  104. $scope.viewInformation = function(profile) {
  105. //console.log( profile.mac );
  106. $api.request({
  107. module: "get",
  108. action: "viewInformation",
  109. mac: profile.mac,
  110. id: profile.id
  111. }, function(response) {
  112. $scope.sendMessage("View information ", response.message);
  113. $scope.workshopProfile.info = response.info;
  114. });
  115. }
  116. $scope.sendMessage = function(t, m) {
  117. // Add a new message to the top of the list
  118. $scope.messages.unshift({title: t, msg: m});
  119. // if there are 4 items in the list remove the 4th item
  120. if ($scope.messages.length == 4) {
  121. $scope.dismissMessage(3);
  122. }
  123. }
  124. $scope.dismissMessage = function($index) {
  125. //var index = $scope.messages.indexOf(message);
  126. $scope.messages.splice($index, 1);
  127. }
  128. function getControls() {
  129. $scope.throbber = true;
  130. $api.request({
  131. module: "get",
  132. action: "getControlValues"
  133. }, function(response) {
  134. updateControls(response);
  135. });
  136. }
  137. function getClientProfiles() {
  138. $scope.throbber = true;
  139. $api.request({
  140. module: "get",
  141. action: "getClientProfiles"
  142. }, function (response) {
  143. $scope.profiles = [];
  144. $scope.throbber = false;
  145. for (var i = 0; i < response.length; i++) {
  146. $scope.profiles.unshift({id: response[i].id, mac: response[i].mac, ip: response[i].ip, hostname: response[i].hostname, date: response[i].date, comments: response[i].comments});
  147. //console.log( {id: response[i].id, mac: response[i].mac, ip: response[i].ip, hostname: response[i].hostname, date: response[i].date, comments: response[i].comments} );
  148. }
  149. });
  150. }
  151. function updateControls(response) {
  152. var hidden;
  153. var enabled;
  154. var dbonsd;
  155. if (response.hidden == false) {
  156. hidden = "Install";
  157. //$scope.sendMessage("iFrame not installed", "The get module requires the hidden frame to be installed");
  158. $scope.hidden = false;
  159. } else {
  160. hidden = "Uninstall";
  161. $scope.hidden = true;
  162. }
  163. if (response.enabled == false) {
  164. enabled = "Enable";
  165. $scope.enabled = false;
  166. } else {
  167. enabled = "Disable";
  168. $scope.enabled = true;
  169. }
  170. if (response.dbonsd == false) {
  171. dbonsd = "Enable";
  172. //$scope.sendMessage("Database location", "The database will be stored on the SD card");
  173. $scope.dbonsd = false;
  174. } else {
  175. dbonsd = "Disable";
  176. $scope.dbonsd = true;
  177. }
  178. // set parameters that are passed to the html
  179. $scope.controls = [
  180. /*
  181. {
  182. title: "Hidden iFrame",
  183. status: hidden,
  184. visible: true,
  185. throbber: false
  186. },
  187. */
  188. {
  189. title: "Enable Module",
  190. status: enabled,
  191. visible: true,
  192. throbber: false
  193. },
  194. {
  195. title: "Database on SD",
  196. status: dbonsd,
  197. visible: true,
  198. throbber: false
  199. }];
  200. $scope.throbber = false;
  201. }
  202. }]);