Source: index.js

  1. /**
  2. * Éste módulo es el encargado de controlar la funcionalidad de la página de inicio.
  3. *
  4. * @module module_index
  5. */
  6. var module_index = (function() {
  7. var _VERBOSE = true;
  8. _VERBOSE ? console.log("*** loading index... ***") : _VERBOSE;
  9. var _language_module_index;
  10. var _toastr = toastr;
  11. var _iTrans;
  12. var _tipo_modulo;
  13. var _link_val;
  14. var _url_front;
  15. var _url_api;
  16. var _url_nicho;
  17. var _url_comunidad;
  18. /**
  19. * Método encargado de asignar el direccionamiento del ambiente del sistema,
  20. * tanto para el ambiente gráfico del frontend, como la versión que será utilizada del backend.
  21. *
  22. * @function startModule
  23. *
  24. * @param {integer} tipo_modulo - Módulo inicial que sera configurado. 1. Nicho ecológico, 2. Redes de inferencia y 3. Inicio
  25. */
  26. function startModule(tipo_modulo) {
  27. _VERBOSE ? console.log("startModule Index") : _VERBOSE;
  28. _url_front = config.url_front
  29. _url_api = config.url_api
  30. _url_nicho = config.url_nicho
  31. _url_comunidad = config.url_comunidad
  32. _VERBOSE = config.verbose
  33. _tipo_modulo = 2; // index
  34. // Se cargan los archivos de idiomas y depsues son cargados los modulos subsecuentes
  35. _VERBOSE ? console.log(this) : _VERBOSE
  36. // _VERBOSE ? console.log("before language_module INDEX") : _VERBOSE;
  37. _language_module_index = language_module(_VERBOSE);
  38. _language_module_index.startLanguageModule(this, _tipo_modulo);
  39. }
  40. /**
  41. * Método de configuración e inicialización de componentes utilizados en la primera vista del sistema.
  42. *
  43. * @function _initializeComponents
  44. * @public
  45. */
  46. function _initializeComponents() {
  47. _VERBOSE ? console.log("_initializeComponents") : _VERBOSE;
  48. _toastr.options = {
  49. "debug": false,
  50. "onclick": null,
  51. "fadeIn": 300,
  52. "fadeOut": 1000,
  53. "timeOut": 2000,
  54. "extendedTimeOut": 2000,
  55. "positionClass": "toast-bottom-center",
  56. "preventDuplicates": true,
  57. "progressBar": true
  58. };
  59. $("#link_nicho").prop("href",_url_nicho)
  60. $("#link_redes").prop("href",_url_comunidad)
  61. $("#docs_front").prop("href",_url_front+"/frontend-documentation")
  62. $("#docs_front").text(_url_front+"/frontend-documentation")
  63. $("#api_docs").prop("href",_url_api+"/api-reference")
  64. $("#api_docs").text(_url_api+"/api-reference")
  65. $("#send_email_login").click(function() {
  66. _VERBOSE ? console.log("send_email_login") : _VERBOSE;
  67. _VERBOSE ? console.log("valido: " + $("#email_address")[0].validity["valid"]) : _VERBOSE;
  68. var regexp = /^(([A-Za-z]+[\-\']?)*([A-Za-z]+)?\s)+([A-Za-z]+[\-\']?)*([A-Za-z]+)?$/;
  69. if (!regexp.test($("#user_name").val())) {
  70. _toastr.error(_iTrans.prop("invalid_user"));
  71. $("#user_name").val("");
  72. $("#email_address").val("");
  73. return;
  74. }
  75. if ($("#email_address")[0].validity["valid"]) {
  76. var email = $("#email_address").val();
  77. var usuario = $("#user_name").val();
  78. _VERBOSE ? console.log("email: " + email) : _VERBOSE;
  79. _VERBOSE ? console.log("usuario: " + usuario) : _VERBOSE;
  80. $.ajax({
  81. url: _url_api + "/niche/especie/getUserReg",
  82. type: "post",
  83. data: {
  84. email: email
  85. },
  86. success: function(d) {
  87. var res = d.data;
  88. var count = parseInt(res[0].count);
  89. _VERBOSE ? console.log("count: " + count) : _VERBOSE;
  90. if (count === 0) {
  91. $.ajax({
  92. url: _url_api + "/niche/especie/setUserReg",
  93. type: "post",
  94. data: {
  95. email: email,
  96. usuario: usuario
  97. },
  98. success: function(d) {
  99. _VERBOSE ? console.log("registrado") : _VERBOSE;
  100. _VERBOSE ? console.log(d) : _VERBOSE;
  101. $("#modalLogin").modal("hide");
  102. window.location.replace(_link_val);
  103. },
  104. error: function(jqXHR, textStatus, errorThrown) {
  105. _VERBOSE ? console.log("error: " + jqXHR) : _VERBOSE;
  106. _VERBOSE ? console.log("error: " + textStatus) : _VERBOSE;
  107. _VERBOSE ? console.log("error: " + errorThrown) : _VERBOSE;
  108. $("#email_address").val("");
  109. $("#user_name").val("");
  110. $("#modalLogin").modal("hide");
  111. _toastr.error(_iTrans.prop("general_error"));
  112. // _module_toast.showToast_BottomCenter(_iTrans.prop('lb_correo_error'), "error")
  113. }
  114. });
  115. } else {
  116. _VERBOSE ? console.log("Ya registrado") : _VERBOSE;
  117. $("#modalLogin").modal("hide");
  118. window.location.replace(_link_val);
  119. }
  120. },
  121. error: function(jqXHR, textStatus, errorThrown) {
  122. _VERBOSE ? console.log("error: " + textStatus) : _VERBOSE;
  123. $("#email_address").val("");
  124. $("#user_name").val("");
  125. $("#modalLogin").modal("hide");
  126. _toastr.error(_iTrans.prop("general_error"));
  127. }
  128. });
  129. } else {
  130. $("#user_name").val("");
  131. $("#email_address").val("");
  132. _toastr.error(_iTrans.prop("invalid_user"));
  133. }
  134. });
  135. $("#btn_tutorial").click(function() {
  136. window.open(_url_front + "/docs/tutorial.pdf");
  137. });
  138. var timer = 5000;
  139. var names_nicho = ["lb_index_hist_decil", "lb_index_hist_score", "lb_index_map_pres"];
  140. var names_net = [ "lb_index_map_riq", "lb_index_tbl_rel", "lb_index_net"];
  141. var index_nicho = 0;
  142. var index_net = 0;
  143. $("#lb_ini_nicho").text(_iTrans.prop(names_nicho[names_nicho.length-1]));
  144. setInterval(function() {
  145. $("#lb_ini_nicho").text(_iTrans.prop(names_nicho[index_nicho]));
  146. index_nicho = index_nicho === 2 ? 0 : ++index_nicho;
  147. }, timer);
  148. $("#lb_ini_net").text(_iTrans.prop(names_net[names_net.length-1]));
  149. setInterval(function() {
  150. $("#lb_ini_net").text(_iTrans.prop(names_net[index_net]));
  151. index_net = index_net === 2 ? 0 : ++index_net;
  152. }, timer);
  153. $(".box_nicho").bgswitcher({
  154. images: [
  155. _url_front + "/images/mapa.png",
  156. _url_front + "/images/decil.png",
  157. _url_front + "/images/score_celda.png"],
  158. effect: "fade",
  159. interval: timer
  160. });
  161. $(".box_net").bgswitcher({
  162. images: [
  163. _url_front + "/images/red.png",
  164. _url_front + "/images/mapa_riqueza.png",
  165. _url_front + "/images/tabla_red.png"],
  166. effect: "fade",
  167. interval: timer
  168. });
  169. }
  170. /**
  171. * Este método inicializa el módulo de internacionalización del sistema
  172. * y la configuración e inicialización de la página de aterrizaje del sistema.
  173. *
  174. * @function loadModules
  175. */
  176. function loadModules() {
  177. _VERBOSE ? console.log("loadModules INDEX") : _VERBOSE;
  178. _iTrans = _language_module_index.getI18();
  179. _initializeComponents();
  180. }
  181. // retorna solamente un objeto con los miembros que son públicos.
  182. return {
  183. startModule: startModule,
  184. loadModules: loadModules
  185. };
  186. })();
  187. var modulo = 2
  188. module_index.startModule(modulo)