123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /* Authors : Carlos C. Corrada-Bravo
- David J. Ortiz-Rivera
-
- Organization : Centro de Desarrollo y Consultoria Computacional
- Project : OPASO Material Registry
- File : transactions.js
- Description : Generate transactions table */
-
- /* total transactions */
- var next = 0;
-
- /* fetch transactions */
- $(document).ready(fetch_transactions);
-
- /* table_gen(transactions: dictionary) - generate and append table row(s) */
- function table_gen(transactions){
- /* generate rows */
- for(var key in transactions){
- let tr = element_gen("tr",{class: "transaction-row",id: key});
- let fields = transactions[key];
- for(var field in fields){
- switch(field){
- case "material": /* generate material link */
- var href = `/materials?mat_id=${fields[field]["mat_id"]}`;
- var link = element_gen("a",{class: "mat-link",text: fields[field]["mat_name"],href: href,target: "_blank",rel: "noopener noreferrer"});
- var cell = element_gen("td",{class: "transaction-cell",value: "mat_name",childs: {link}});
- break;
-
- case "lab": /* generate lab link */
- var href = `/laboratory?lab_id=${fields[field]["lab_id"]}`;
- var link = element_gen("a",{class: "lab-link",text: fields[field]["lab_room"],href: href,target: "_blank",rel: "noopener noreferrer"});
- var cell = element_gen("td",{class: "transaction-cell",value: "lab_room",childs: {link}});
- break;
-
- default: /* default */
- var cell = element_gen("td",{class: "transaction-cell",text: fields[field],value: field});
- break;
-
- }
-
- tr.append(cell);
- }
-
- $("tbody").append(tr);
- }
-
- $(".processing").hide();
- setTimeout(function(){
- $(".main-wrapper").show();
- },250);
- }
-
- /* fetch_transactions() - fetch transactions */
- function fetch_transactions(){
- $.post("/scripts/opaso",{query: 22},function(data){
- console.log(data);
- /* extract response */
- let response = JSON.parse(data);
- let status = response["status"];
-
- /* handle by status */
- switch(status){
- case "success": /* on success, generate table */
- var date = new Date();
- date = date.toString().split(" ").splice(1,4).join(" ");
- $(".sub-header").text(`As of: ${date}`);
- next = Object.keys(response["transactions"]).length;
- $(".table-total").text(`Total: ${next}`);
- table_gen(response["transactions"]);
- break;
-
- case "expired": /* on expired, redirect to index */
- window.location.href = "/?error=session_expired";
- break;
-
- default: /* on error, display message */
- set_alert(status,response["message"]);
- break;
- }
- });
- }
|