Proyecto en colaboración con OPASO

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Authors : Carlos C. Corrada-Bravo
  2. David J. Ortiz-Rivera
  3. Organization : Centro de Desarrollo y Consultoria Computacional
  4. Project : OPASO Material Registry
  5. File : menu.js
  6. Description : Generate user menu */
  7. /* fetch authorized labs */
  8. $(document).ready(menu);
  9. /* menu() - generate user menu */
  10. function menu(){
  11. /* query server */
  12. $.post("/scripts/opaso",{query: 2},function(data){
  13. // console.log(data);
  14. /* extract response */
  15. let response = JSON.parse(data);
  16. let status = response["status"];
  17. /* handle by status */
  18. switch(status){
  19. case "success": /* on success, generate menu */
  20. /* extract authorized laboratories */
  21. let auth = response["authorized"];
  22. let r = element_gen("div",{class: "lab-row"});
  23. /* generate laboratory links */
  24. for(var lab in auth){
  25. /* generate elements */
  26. let room = element_gen("div",{class: "lab-room",text: auth[lab]["lab_room"]});
  27. let p = `(${auth[lab]["access_level"].charAt()})`;
  28. let privileges = element_gen("p",{class: "privileges-indicator",text: p});
  29. /* set lab link */
  30. let href = `/laboratory?lab_id=${auth[lab]["lab_id"]}`;
  31. let link = element_gen("a",{class: "lab-link",href: href,childs:{room,privileges}});
  32. let w = element_gen("div",{class: "col-lg-3 laboratory-wrapper"});
  33. w.append(link);
  34. r.append(w);
  35. }
  36. $(".laboratories").append(r);
  37. /* display menu */
  38. $(".processing").hide();
  39. setTimeout(function(){
  40. $(".main-wrapper").show();
  41. },250);
  42. break;
  43. case "expired": /* on expired, redirect to index */
  44. window.location.href = "/?error=session_expired";
  45. break;
  46. default: /* on error, display message */
  47. set_alert(status,response["message"]);
  48. break;
  49. }
  50. });
  51. }