action-kelolaruang.js 15.1 KB
Newer Older
Indra Raja's avatar
Indra Raja committed
1 2 3 4 5 6 7 8 9 10

function reset() {
    document.getElementById("myForm").reset();

}
function reset() {
    document.getElementById("myFormedt").reset();

}

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
11 12 13
// function closeWin() {
//     myWindow.close();
// }
Indra Raja's avatar
Indra Raja committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53


function loadpoli() {
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadregisterpoli',

        success: function (result) {
            if (result['code'] == 0) {
                //console.log (result);
                var res = result['data'];

                optionseg = '';
                optionseg += '<option value="Pilih" disabled selected>Pilih</option>';
                for (var i = 0; i < res.length; i++) {
                    optionseg += '<option value="' + res[i].id_poli + '">' + res[i].nama_poli + '</option>';
                }

                $("select#poli").html(optionseg);
            } else {
                bootbox.dialog({
                    message: "<span class='bigger-110'>" + result['info'] + "</span>",
                    buttons:
                    {
                        "OK":
                        {
                            "label": "<i class='icon-ok'></i> OK ",
                            "className": "btn-sm btn-danger",
                            "callback": function () {
                                notifyCancel('ERROR: ' + result['info'] + '. Bila ada kesulitan dimohon untuk menghubungi Admin terkait');
                            }
                        }
                    }
                });
            }
        }
    });
}

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
54
Loadruang();
Indra Raja's avatar
Indra Raja committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
function Loadruang() {

    /* save data */
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadkelolaruang',

        success: function (result) {
            // console.log(result);
            $('table.table-bordered > tbody').empty();
            // console.log(result);

            if (result.code == 0) {

                let data = result.data;
                let counter = 1;


                for (x in data) {
                    var newRow = $("<tr>");
                    var cols = "";
                    cols += '<td class="">' + counter + '</td>';
                    // cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].id_poli + '</td>'
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].nama_poli + '</td>';
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
80
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].lantai + '</td>';
Indra Raja's avatar
Indra Raja committed
81 82
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].nama_ruang + '</td>';
                    cols += '<td class="tdCenterText bgtd1 tdBorder-left">' + data[x].condition + '</td>';
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
83

Indra Raja's avatar
Indra Raja committed
84

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
85
                    cols += '<td class="tdCenterText bgtd1 "> <div class="text-center" ><span style="padding: 7px;" class="btn btn-success btn-xs" data-toggle="modal" data-target="#Editdata" onClick="loadedit(' + data[x].id_ruang + ')">Edit</span> <span style="padding: 7px;"class="btn btn-danger btn-xs"  onclick="Delete(' + data[x].id_ruang + ')">Hapus</span><span style="padding: 7px;margin-top:10px; font-size: 14px;"class="btn btn-info btn-xs"  onclick="Update(' + data[x].id_ruang + "," + data[x].id_condition + ')">Update Kondisi</span></div></td>';
Indra Raja's avatar
Indra Raja committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

                    newRow.append(cols);
                    $("#tableruang").append(newRow);
                    counter++;

                }

            } else {
                bootbox.alert({ message: 'Data Kosong', centerVertical: true });
            }
            $('#dataTable').DataTable({
                "scrollY": '500px',
                "scrollX": true,
                fixedHeader: true,
                scrollCollapse: true,
                paging: true,
                columnDefs: [
                    { width: 30, targets: 0 },
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
104 105 106 107 108
                    { width: 180, targets: 1 },
                    { width: 140, targets: 2 },
                    { width: 140, targets: 3 },
                    { width: 140, targets: 4 },
                    { width: 100, targets: 5 },
Indra Raja's avatar
Indra Raja committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
                ],

            });
        },

        error: function (xhr) {
            alert(xhr.status + '-' + xhr.statusText);
        }

    });
}

$('#tambahmodal').on('click', function () {
    loadpoli()

})

$('#tambah').on('click', function () {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    let nama_ruang = $('#nama_ruang').val();
    let lantai = $('#lantai').val();

    if (nama_ruang == null || nama_ruang == "") {
        bootbox.alert({ message: 'Nama Ruang tidak boleh kosong', centerVertical: true });
        return false;
    }
    else if (lantai == null || lantai == "") {
        bootbox.alert({ message: 'Lantai tidak boleh kosong', centerVertical: true });
        return false;
    }
    else if (validasiruang(lantai, nama_ruang) == 3) {
        bootbox.alert({ message: 'Nama ruang  dan lantai sudah ada!', centerVertical: true });
    }
    else if (validasiruang(lantai, nama_ruang) == 2) {
        bootbox.alert({ message: 'Nama ruang  dan lantai sudah ada!', centerVertical: true });
    }
    else {
        saveruang()
    }
Indra Raja's avatar
Indra Raja committed
147
})
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
148

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
149

Indra Raja's avatar
Indra Raja committed
150 151
function saveruang() {
    let nama_ruang = $('#nama_ruang').val();
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
152
    let lantai = $('#lantai').val();
Indra Raja's avatar
Indra Raja committed
153 154 155 156 157 158 159 160 161 162 163
    let poli = $("#poli option:selected").attr("value");


    // let image = $('#kode_poli').val();

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/savekelolaruang',
        data: {
            inama_ruang: nama_ruang,
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
164
            ilantai: lantai,
Indra Raja's avatar
Indra Raja committed
165 166 167 168 169 170
            ipoli: poli,

        },

        success: function (result) {
            // console.log(result)
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
171 172 173



Indra Raja's avatar
Indra Raja committed
174
            if (result['code'] == 0) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
175
                $('#addData').modal('hide');
Indra Raja's avatar
Indra Raja committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
                swal({
                    title: "",
                    text: "Data Berhasil Ditambahkan!",
                    icon: "succes",
                    button: "ok",
                }, function () {
                    location.reload();
                });
            } else {
                swal({
                    title: "",
                    text: "Data Gagal Ditambahkan!",
                    icon: "succes",
                    button: "ok",
                });
            }
        },

        error: function (xhr) {

            if (xhr.status != 200) {
                //bootbox.alert(xhr.status + "-" + xhr.statusText + " <br>Silahkan coba kembali :) ");
            } else {
                alert('gagal error');
            }
        }


    });
}

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
// validasiruang()
function validasiruang(lantai, nama_ruang) {

    var exist = 0;

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadkelolaruang',
        async: false,
        data: {
            id: null,
        },
        success: function (result) {

            var data = result.data;
            console.log(data[0])
            var ruangcounter = 0

            for (x in data) {


                // if (lantai == data[x]['lantai']) {
                //     if (nama_ruang == data[x]['nama_ruang']) {

                //     }
                // }

                if (lantai == data[x]['lantai']) {
                    if (nama_ruang == data[x]['nama_ruang']) {
                        exist = 2;
                    }
                }
                if (lantai == data[x]['lantai']) {
                    if (nama_ruang == data[x]['nama_ruang']) {
                        ruangcounter += 1;
                        if (ruangcounter > 1) {
                            exist = 3;
                        }

                    }
                }


            }


        },

        error: function (xhr) {
            //alert(xhr.status+'-'+xhr.statusText);
        }
    });
    return exist;

}



Indra Raja's avatar
Indra Raja committed
266 267
$('#edit').on('click', function () {
    let id_ruang = $('#id_ruang').val();
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    let nama_ruang = $('#nama_ruangedt').val();
    let lantai = $('#lantaiedt').val();
    let poli = $("#poliedt option:selected").attr("value");
    // console.log(poli)

    if (nama_ruang == null || nama_ruang == "") {
        bootbox.alert({ message: 'Nama Ruang tidak boleh kosong', centerVertical: true });
        return false;
    }
    else if (lantai == null || lantai == "") {
        bootbox.alert({ message: 'Lantai tidak boleh kosong', centerVertical: true });
        return false;
    } else if (validasiruang(lantai, nama_ruang) == 3) {
        bootbox.alert({ message: 'Nama ruang dan lantai harus berbeda!', centerVertical: true });
    } else {
        editdataruang(id_ruang)
    }
Indra Raja's avatar
Indra Raja committed
285 286 287 288 289

})
function editdataruang(id_ruang) {
    let poli = $("#poliedt option:selected").attr("value");
    let nama_ruang = $('#nama_ruangedt').val();
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
290
    let lantai = $('#lantaiedt').val();
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
291

Indra Raja's avatar
Indra Raja committed
292 293 294 295 296 297 298 299 300

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/editkelolaruang',
        data: {
            id: id_ruang,
            inama_ruang: nama_ruang,
            ipoli: poli,
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
301
            ilantai: lantai,
Indra Raja's avatar
Indra Raja committed
302 303 304 305 306

        },

        success: function (response) {
            //console.log(respoonse);
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
307

Indra Raja's avatar
Indra Raja committed
308
            if (response['code'] == 0) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
309 310
                $('#Editdata').modal('hide');

Indra Raja's avatar
Indra Raja committed
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
                swal({
                    title: "",
                    text: "Data Berhasil DiUbah!",
                    icon: "succes",
                    button: "ok",
                }, function () {
                    location.reload();
                });

            } else {
                swal({
                    title: "",
                    text: "Data Gagal Ditambahkan!",
                    icon: "succes",
                    button: "ok",
                });

            }

        },
        error: function (xhr) {

            if (xhr.status != 200) {
                //bootbox.alert(xhr.status + "-" + xhr.statusText + " <br>Silahkan coba kembali :) ");
            } else {
                alert('gagal error');
            }
        }


    });
}




function loadedit(id_ruang) {


    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadkelolaruang',
        data: {
            id: id_ruang,
        },
        success: function (result) {
            // console.log(result);
            // $('.loaddata').empty();
            // console.log(result);

            if (result.code == 0) {
                var data = '';
                var data = result.data;

                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    url: baseURL + '/api/loadRegisterEdit',
                    async: false,
                    success: function (result) {



                        if (result['code'] == 0) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
376
                            // console.log(result);
Indra Raja's avatar
Indra Raja committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
                            var res = result['data'];

                            optionseg = '';
                            optionsegc = '';

                            for (var i = 0; i < res.poli.length; i++) { //POli
                                optionseg += '<option value="' + res.poli[i].id_poli + '">' + res.poli[i].nama_poli + '</option>';
                            }
                            $("select#poliedt").html(optionseg);

                            $(document).ready(function () {
                                $("select#poliedt").val(data[0].id_poli).change();
                            });



                        }
                    }
                });
                $('#id_ruang').val(data[0].id_ruang);
                $('#nama_ruangedt').val(data[0].nama_ruang);
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
398
                $('#lantaiedt').val(data[0].lantai);
Indra Raja's avatar
Indra Raja committed
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421

            } else {
                bootbox.alert({ message: 'Data Kosong', centerVertical: true });
            }
        },
        error: function (xhr) {
            alert(xhr.status + '-' + xhr.statusText);
        }
    });
}




function Delete(param) {
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/loadkelolaruang',
        data: {
            id: param,
        },
        success: function (result) {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
422
            // console.log(result);
Indra Raja's avatar
Indra Raja committed
423
            let nama_ruang = result.data[0].nama_ruang;
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
424
            let lantai = result.data[0].lantai;
Indra Raja's avatar
Indra Raja committed
425
            swal({
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
426
                title: "Apakah yakin mengahapus ruang '" + nama_ruang + " ' lantai '" + lantai + "'? ",
Indra Raja's avatar
Indra Raja committed
427
                type: "warning",
Indra Raja's avatar
Indra Raja committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
                confirmButtonClass: "btn-danger",
                confirmButtonText: "Yes!",
                showCancelButton: true,
            },
                function () {
                    $.ajax({
                        type: 'POST',
                        dataType: 'json',
                        url: baseURL + '/api/deletekelolaruang',
                        data: {
                            id: param,
                        },
                        success: function (result) {
                            // console.log(result)
                            if (result.code == 0) {
                                swal({
                                    title: "",
                                    text: "Data Berhasil Dihapus!",
                                    icon: "succes",
                                    button: "ok",
                                }, function () {
                                    location.reload();
                                });
                            } else {
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
452 453 454 455 456 457
                                swal({
                                    title: "",
                                    text: "Data Gagal Dihapus!",
                                    icon: "succes",
                                    button: "ok",
                                });
Indra Raja's avatar
Indra Raja committed
458 459
                            }
                        },
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
460 461
                        error: function () {
                            bootbox.alert({ message: 'Data ruang masih terdaftar dalam poli ', centerVertical: true });
Indra Raja's avatar
Indra Raja committed
462 463 464 465 466 467 468 469 470 471 472
                        }
                    });
                },


            );

        }
    });

}
Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503

function Update(id_ruang, id_condition) {

    // console.log(id_dokter)
    // console.log(id_condition)
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/updateconditionruang',
        data: {
            id_ruang: id_ruang,
            id_condition: id_condition,
        },
        success: function (result) {
            console.log(result);
            // console.log(result)
            if (result.code == 0) {
                location.reload();
            } else {
                bootbox.alert({ message: 'Gagal ', centerVertical: true });

            }


        },

        error: function () {
            bootbox.alert({ message: 'Data dokter masih terdaftar dalam poli ', centerVertical: true });
        }
    });

Indra Raja's avatar
Indra Raja committed
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
}

$('#update').on('click', function () {
    setruang()

})

function setruang() {
    param = null
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/api/updateconditionseluruhruang',
        data: {
            id: param,
        },
        success: function (result) {
            console.log(result);
            // console.log(result)
            if (result.code == 0) {
                location.reload();
            } else {
                bootbox.alert({ message: 'Gagal ', centerVertical: true });

            }


        },

        error: function () {
            bootbox.alert({ message: 'Data dokter masih terdaftar dalam poli ', centerVertical: true });
        }
    });

Azy Mushofy Anwary's avatar
Azy Mushofy Anwary committed
538
}