function _param2hash(p) { var h = {}; p = p.substring(1); var tokval = p.split("&"); for (var idx=0; idx 0) { return s.split(" ")[0]; } return s; } function _create_pass_row(dat) { var pass_table = document.getElementById("manage_card:list_passes"); var _cb = ""; while (pass_table.firstChild) { pass_table.removeChild(pass_table.lastChild); } var row = document.createElement("div"); row.classList.add("row"); row.classList.add("rowpop"); row.classList.add("row-shade"); var fields_width = [1,1,1,1,2,2,2,2]; //var fields = ["x", "Type", "Original", "Remain", "Exp.", "Issued", "First Used", "Last Used"]; var fields = ['', "Type", "Original", "Remain", "Exp.", "Issued", "First Used", "Last Used"]; for (var idx=0; idx= 0) { pass_type = "NRide"; pass_orig = pass_data["nrides_orig"]; pass_remain = pass_data["nrides_remain"]; pass_exp = ""; } else if (pass_rule.search(/NDAY/) >= 0) { pass_type = "NDay"; pass_orig = pass_data["nday_orig"]; pass_remain = ""; pass_exp = pass_data["nday_expiration"]; } else { pass_type = "Other"; } var pass_firstused = ""; var pass_lastused = ""; if ( (typeof pass_data["firstused"] !== "undefined") && (pass_data["firstused"]) ) { pass_firstused = pass_data["firstused"]; } if ( (typeof pass_data["lastused"] !== "undefined") && (pass_data["lastused"]) ) { pass_lastused = pass_data["lastused"]; } row = document.createElement("div"); row.classList.add("row"); row.classList.add("rowpop"); if ((idx%2)==1) { row.classList.add("row-shade"); } //var cell = document.createElement("div"); //cell.innerHTML = "x"; var cell = document.createElement("input"); cell.setAttribute('type', 'checkbox'); cell.setAttribute('value', ''); cell.setAttribute('id', "manage_card:cb_" + idx + "_pass"); cell.classList.add("col-" + fields_width[0]); row.appendChild(cell); //cell.classList.add("col-" + fields_width[0]); //row.appendChild(cell); cell = document.createElement("div"); cell.innerHTML = pass_type; cell.classList.add("col-" + fields_width[1]); row.appendChild(cell); cell = document.createElement("div"); cell.innerHTML = pass_orig; cell.classList.add("col-" + fields_width[2]); row.appendChild(cell); cell = document.createElement("div"); cell.innerHTML = pass_remain; cell.classList.add("col-" + fields_width[3]); row.appendChild(cell); cell = document.createElement("div"); //cell.innerHTML = pass_exp; cell.innerHTML = _date_only(pass_exp); cell.classList.add("col-" + fields_width[4]); row.appendChild(cell); cell = document.createElement("div"); //cell.innerHTML = pass_data["issued"]; cell.innerHTML = _date_only(pass_data["issued"]); cell.classList.add("col-" + fields_width[5]); row.appendChild(cell); cell = document.createElement("div"); //cell.innerHTML = pass_firstused; cell.innerHTML = _date_only(pass_firstused); cell.classList.add("col-" + fields_width[6]); row.appendChild(cell); cell = document.createElement("div"); cell.innerHTML = pass_lastused; cell.classList.add("col-" + fields_width[7]); row.appendChild(cell); cell = document.createElement("div"); cell.innerHTML = passid; cell.setAttribute('id', "manage_card:row_" + idx + "_pass"); cell.style.display = "none"; row.appendChild(cell); pass_table.appendChild(row); } } function manage_card_find_fill(data) { var fields = [ "logical_card_id", "group", "mag_token", "rfid_token"]; console.log("manage_card_find_fill:", data); for (var idx=0; idx" + cardid + ""; cell.classList.add("col-4"); row.appendChild(cell); cell = document.createElement("div"); cell.innerHTML = "" + magid + ""; cell.classList.add("col-4"); row.appendChild(cell); cell = document.createElement("div"); cell.innerHTML = "" + rfid + ""; cell.classList.add("col-4"); row.appendChild(cell); card_table.appendChild(row); console.log("card", idx, card_data[idx]["logical_card_id"], card_data[idx]["mag_token"], card_data[idx]["rfid_token"] ); } } window.history.replaceState({}, document.title, "/manage_user"); } function api_resp(xhr,extra) { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { var dat = JSON.parse(xhr.responseText); console.log(dat); if (extra["ui_function"] === "manage_card.find") { console.log("manage_card.find", dat); if (("cards"in dat) && (dat.cards.length>0)) { manage_card_find_fill(dat.cards[0]); } } else if (extra["ui_function"] === "manage_card.findone") { console.log("... manage_card.findone", dat); manage_card_find_fill(dat); } else if (extra["ui_function"] === "manage_card.update") { console.log("issuing 'manage_card.update'"); var cardid = _get_input_field("manage_card:logical_card_id"); api_req({"api_function":"CardInfo", "ui_function":"manage_card.findone", "data":[["logical_card_id",cardid]]}); } else if (extra["ui_function"] === "create_user.finish") { _redirect( "manage_user?" + "action=get&userid=" + dat["userid"]) } else if (extra["ui_function"] === "manage_user.find") { console.log("manage_user.find:", dat); manage_user_find_fill(dat); } else if (extra["ui_function"] === "manage_user.update") { var userid = _get_input_field("manage_user:userid"); console.log("manage_user.update resp:", dat); // After we've associated the card to the user, re-get user information to re-fill // page // api_req({"api_function":"UserInfo", "ui_function":"manage_user.find", "data":[["userid",userid]]}); } else if (extra["ui_function"] === "group") { } //else if (extra["ui_function"] === "manage_card.find") { manage_card_find_fill(dat); } } else { console.log("xhr error:", xhr); } } } // example usage: // // api_req({"ui_function":"manage_card.find", "api_function":"CardInfo", "data":[ ["action","search"],["mag_token","370000000007015"]]}) // function api_req(ctx) { var xhr; xhr = new XMLHttpRequest(); if (!xhr) { return false; } var param_val = []; for (var idx=0; idx