0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.191.205.149


Current Path : /proc/thread-self/root/var/www/oasis/js/
Upload File :
Current File : //proc/thread-self/root/var/www/oasis/js/rommcreationnew.js

function callEnableroomdeclarationnew() {
  $("#page_main_div").load("../html_modules/roomcreationnew.html?v=1001", {
    function() {
      document.getElementById("display_module_name").innerHTML =
        "Room Creation (new)";
      document.getElementById("module_name_for_save").value =
        "Room Creation (new)";
      getDefaultHeadFooterLinks("Room Creation (new)");
      gettable();
    },
  });
}

let roomdata = [];
let value = 0;
function gettable() {
  roomdata = [];
  $.ajax({
    type: "GET",
    url: $host_url + "roomcreation",
    success: function (res) {
      let response = JSON.parse(res);
      if (response.error_code == 0) {
        value = response.data.length;
        var table = "";
        table += `<table class="tables">`;
        table += `<tr class='tr_table'>
              <th align="center" class='column'>SI.NO</th>
              <th align="center" class='column'id="roomno">Room No</th>
              <th align="center" class='column' id="roomname">Room Name</th>
              <th align="center" class='column' id="roomcapacity">Capacity</th>
              <th align="center" class='column' id="roomorder">Order</th>
              <th align="center" class='column' id="noofqp">No of QP</th>
              <th>Action</th>
              </tr>`;
        for (let i = 0; i < response.data.length; i++) {
          var getdatavalue = response.data[i];
          roomdata.push(getdatavalue);

          table += `<tr align='center' id='row_${i}'>
          <td class='column'>${i + 1}</td>
               <td class='column'><input class='tables' value="${
                 response.data[i].froomno
               }" id="roomno_${i}" onblur="editRoomvalue(${i}, 'roomno_', 'froomno')"></td>

                 <td class='column'><input class='tables' value="${
                   response.data[i].froomname
                 }" id="roomname_${i}" onblur="editRoomvalue(${i}, 'roomname_', 'froomname')"></td>

                 <td class='column'> <input class='tables' value="${
                   response.data[i].fcapacity
                 }" id="roomcapacity_${i}" onblur="editRoomvalue(${i}, 'roomcapacity_', 'fcapacity')"> </td>

                 <td class='column'><input class='tables' value="${
                   response.data[i].forder
                 }" id="order_${i}" onblur="editRoomvalue(${i}, 'order_', 'forder')"></td>

                 <td class='column'><input class='tables' value="${
                   response.data[i].fnoofqp
                 }" id="noofqp_${i}" onblur="editRoomvalue(${i}, 'noofqp_', 'fnoofqp')"></td>

                 <td class='column'>
                 <button onclick="deletedata(event, ${i})" id="deletes_${i}" onkeydown="addRow(${
            parseInt(i) + 1
          })"
                style="
               background-color: #990F02;
               border: none;
               color: white;
               padding: 5px 10px;
               text-align: center;
               text-decoration: none;
               display: inline-block;
               font-size: 12px;
               cursor: pointer;
               border-radius: 3px;
             ">Delete</button>
           
             </td>
              </tr>`;
        }
        table += `</table>`;
        document.getElementById("datatable").innerHTML = table;
      } else {
        alert("no data");
      }
    },
  });
}

function deletedata(event, index) {
  event.preventDefault();
  let i = index + 1;
  console.log(i, "i");
  console.log(roomdata[i], "roomindex");
  let roomdatas = roomdata.filter((_, j) => j !== i);
  console.log(roomdatas, "console");
  roomdata = roomdatas;
}

function saveroomdeclaration() {
  let formdata = new FormData();
  formdata.append("data", JSON.stringify(roomdata));
  console.log(roomdata);
  $.ajax({
    type: "POST",
    url: $host_url + "roomallotsave",
    data: formdata,
    contentType: false,
    processData: false,
    cache: false,
    success: function (res) {
      console.log(res);
    },
  });
}

function addRow(count) {
  let lastRowIsEmpty =
    $("#datatable table tr:last td input").filter(function () {
      return $(this).val().trim() !== "";
    }).length === 0;
  console.log(value, count);

  if (count == 0) {
    count = value;
  }
  if (value == count) {
    if (lastRowIsEmpty == false) {
      let addRow = `<tr align='center' id='row_${count}'>
      <td  class='column'>${parseInt(count) + 1}</td>
                    <td class='column'><input class='tables' value='' id="roomno_${count}" onblur="editRoomvalue(${count}, 'roomno_', 'froomno')"></td>
                    <td class='column'><input class='tables' value='' id="roomname_${count}" onblur="editRoomvalue(${count}, 'roomname_', 'froomname')"> </td>
                    <td class='column'> <input class='tables' value='' id="roomcapacity_${count}" onblur="editRoomvalue(${count}, 'roomcapacity_', 'fcapacity')"> </td>
                    <td class='column'><input class='tables' value='' id="order_${count}" onblur="editRoomvalue(${count}, 'order_', 'forder')"></td>
                    <td class='column'><input class='tables' value="" id="noofqp_${count}" onblur="editRoomvalue(${count}, 'noofqp_', 'fnoofqp')"></td>
                    <td class='column'>
                  <button onclick="deletedata(event,${
                    parseInt(count) - 1
                  })"  id="deletes_${count}" onkeydown="addRow('${
        parseInt(count) + 1
      }')" 
                  style="
                  background-color: #990F02;
                  border: none;
                  color: white;
                  padding: 5px 10px;
                  text-align: center;
                  text-decoration: none;
                  display: inline-block;
                  font-size: 12px;
                  cursor: pointer;
                  border-radius: 3px;
                  ">Delete</button>

                  </td>
                </tr>`;
      $("#datatable table").append(addRow);
      let obj = {};
      obj.froomno = "";
      obj.froomname = "";
      obj.fcapacity = "";
      obj.forder = "";
      obj.fnoofqp = "";
      roomdata.push(obj);
      value = parseInt(count) + 1;
      console.log(roomdata, "roomno");
    } else {
      alert("Fill value");
    }
  }
}

function editRoomvalue(index, id, objname) {
  let value = document.getElementById(id + index).value;
  roomdata[index][objname] = value;
}