action.js 33.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 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
$("#upload_image").change(function() {
    loaderPage(true)
    readURL(this);

    const fileupload1 = $(this).prop('files')[0];

    var formData = new FormData();

    formData.append("id", $("#iduseredt").val());
    formData.append("inifile", fileupload1)

    $.ajax({
        url: "editpp",
        data: formData,
        dataType: 'json',
        type: 'POST',
        processData: false,
        contentType: false,
        success: function(data) {
            let response = data
            if (response.code == 0) {
                swal({
                    title: response.info,
                    text: response.data,
                    type: "success",
                    icon: "success",
                    confirmButtonColor: "#00BCD4"
                }).then((isConfirm) => {
                    location.reload()
                })
            } else {
                swal({
                    title: 'Error',
                    text: 'Hubungi Developer',
                    type: "warning",
                    icon: "error",
                    confirmButtonColor: "#00BCD4"
                })
            }

        }
    })
});

function getdetailper(id) {

    $.ajax({
Muhamad's avatar
Muhamad committed
48
        url: "get-detail-perbaikan",
49 50 51 52 53 54 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
        data: {
            'id': id
        },
        dataType: 'json',

        success: function(data) {

            var map_detail_perbaikan = L.map('map_detail_perbaikan_dash', {
                editable: true,
                zoomControl: false,
                drawControl: true
            }).setView([-4.125826277307029, 104.1881561279297], 10);

            L.tileLayer('https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}&s=Gal&apistyle=s.t:0|s.e:l|p.v:off', {
                maxZoom: 21,
                minZoom: 4,
            }).addTo(map_detail_perbaikan);


            setTimeout(function() {
                map_detail_perbaikan.invalidateSize();
            }, 500);


            if (data.length === 0) {
                $(".nama_detail_dash").text("Null");
                $(".type_detail_dash").html("Null");
                $(".tanggal_perbaikan_detail_dash").html("Null")
                $(".anggaran_detail_dash").html("Null")
                $(".penanggung_jawab_detail_dash").html("Null")
                $(".penanggung_jawab_lapangan_detail_dash").html("Null")
                $(".kontraktor_detail_dash").html("Null")
                $(".panjang_jalan_detail_dash").html("Null")
                $(".lebar_jalan_detail_dash").html("Null")
                $(".proposal_detail_dash").html(`
                        <a href="media/proposal/null" id="downloadproposal ">
                            <img src="{% static 'img/icon-1/proposal.svg' %} " alt=" " style="height: 65px;width: 65px; ">
                        </a>`);


                $(".bukti_detail_perbaikan_dash").html(`
                        <a href="media/bukti_penyelesaian/null" onclick="viewBukti() " id="view-bukti ">
                            <img src="{% static 'img/icon-1/bukti.svg' %} " alt=" " style="height: 70px;
                            width: 50px;">
                        </a>`);

            } else {
Muhamad's avatar
Muhamad committed
96

97 98 99 100 101 102 103 104 105 106 107
                $(".nama_detail_dash").html(data[0]['name']);
                $(".type_detail_dash").html(data[0]['type'])
                $(".tanggal_perbaikan_detail_dash").text(data[0]['tgl_perbaikan'])
                $(".anggaran_detail_dash").html(data[0]['anggaran'])
                $(".penanggung_jawab_detail_dash").html(data[0]['pj'])
                $(".penanggung_jawab_lapangan_detail_dash").html(data[0]['pj_lapangan'])
                $(".kontraktor_detail_dash").html(data[0]['kontraktor'])
                $(".panjang_jalan_detail_dash").html(data[0]['panjang'])
                $(".lebar_jalan_detail_dash").html(data[0]['lbr_jln_reno'])
                $(".proposal_detail_dash").html(`
                        <a href="media/proposal/` + data[0]['proposal'] + ` target="_blank" "id="downloadproposal">
Muhamad's avatar
Muhamad committed
108
                            <img src="static/img/icon-1/proposal.svg" alt=" " style="height: 65px;width: 65px; ">
109 110 111 112 113
                        </a>`);


                $(".bukti_detail_perbaikan_dash").html(`
                        <a href="media/bukti_penyelesaian/` + data[0].bukti_selesai + ` target="_blank" id="view-bukti">
Muhamad's avatar
Muhamad committed
114
                            <img src="static/img/icon-1/bukti.svg" alt=" " style="height: 70px;
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
                            width: 50px;">
                        </a>`);

                map_detail_perbaikan.setView([data[0]['geometry']['coordinates'][0][0][1], data[0]['geometry']['coordinates'][0][0][0]], 18)

                var myLines = [data[0]['geometry']];

                var geo_jalan_perbaikan = L.geoJson(data[0]['geometry'], {
                    style: function(feature) {
                        return {
                            color: "#FAFA00",
                            weight: 10,
                            opacity: 2,
                            zIndex: 1001
                        };
                    }
                }).addTo(map_detail_perbaikan);
            }



        }
    });
};

Muhamad's avatar
Muhamad committed
140 141 142 143 144 145 146 147
function load_manage() {
    // $("#pengaturan_btn").click(function() {
    $(".datatable-show-all.list_user").dataTable().fnDestroy();
    $(".datatable-show-all.list_point").dataTable().fnDestroy();
    $("#list_point").removeClass('list_point')
    $("#list_user").removeClass('list_user')


148 149 150 151 152 153
    $.ajax({
        url: "api/user-data",
        dataType: 'json',

        success: function(data) {
            var data_user = []
Muhamad's avatar
Muhamad committed
154
            var number = 0;
Muhamad's avatar
Muhamad committed
155 156
            var all_id = []
            var all_stat = []
157 158

            for (var i = 0; i < data['data'].length; i++) {
Muhamad's avatar
Muhamad committed
159 160
                $("#list_point").addClass('list_point')
                $("#list_user").addClass('list_user')
161

Muhamad's avatar
Muhamad committed
162
                number += 1;
163 164 165 166 167 168 169 170
                var id = data['data'][i]['id'];
                var name = data['data'][i]['name'];
                var username = data['data'][i]['username'];
                var group = data['data'][i]['group'];
                var email = data['data'][i]['email'];
                var last = data['data'][i]['last'];
                var isactive = data['data'][i]['isactive'];

Muhamad's avatar
Muhamad committed
171 172 173
                var no_telp = +6281234567890
                var jabatan = 'Support'

Muhamad's avatar
Muhamad committed
174
                if (isactive == true) {
Muhamad's avatar
Muhamad committed
175
                    var isac = 'checked'
Muhamad's avatar
Muhamad committed
176
                } else {
Muhamad's avatar
Muhamad committed
177
                    var isac = ''
Muhamad's avatar
Muhamad committed
178 179
                }

180 181 182 183
                var data_gab = `<tr>
                        <td>` + number + `</td>
                        <td>` + username + `</td>
                        <td>` + email + `</td>
Muhamad's avatar
Muhamad committed
184 185
                        <td>` + no_telp + `</td>
                        <td>` + jabatan + `</td>
186
                        <td>` + last + `</td>
Muhamad's avatar
Muhamad committed
187 188 189 190 191 192 193 194 195 196 197 198 199
                        <td class="text-center" style='padding:0px;'>
                        <div class='row'>
                        <div class='col-md-6 text-right' style='margin-top:5px'>
                            <a onclick="loaduserbyid('` + id + `')"><i class=" icon-pencil7"></i>Edit</a>
                        </div>
                        <div class='col-md-6 text-left'>
                            <div class="checkbox checkbox-switchery">
                                <label>
                                    <input type="checkbox" class="switchery-custom-x" id="checkbox` + id + `" onclick="switchuserstatus('` + id + `, ` + isactive + `','` + id + `')" ` + isac + ` >
                                </label>
                            </div>
                        </div>  
                    </div>
200
                        </td>
Muhamad's avatar
Muhamad committed
201

202
                    </tr>`;
Muhamad's avatar
Muhamad committed
203

204
                data_user.push(data_gab)
Muhamad's avatar
Muhamad committed
205 206
                all_id.push(id)
                all_stat.push(isactive)
207
            };
Muhamad's avatar
Muhamad committed
208

Muhamad's avatar
Muhamad committed
209
            $("#tbody_user_list").html(data_user)
210

Muhamad's avatar
Muhamad committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
            if (Array.prototype.forEach) {
                var elems = Array.prototype.slice.call(document.querySelectorAll('.switchery'));
                elems.forEach(function(html) {
                    var switchery = new Switchery(html);
                });
            } else {
                var elems = document.querySelectorAll('.switchery');
                for (var i = 0; i < elems.length; i++) {
                    var switchery = new Switchery(elems[i]);
                }
            }
            $(".switch").bootstrapSwitch();
            var primary_s = document.querySelectorAll("[class^=switchery-custom-x");

            for (var z = 0; z < primary_s.length; z++) {
                var switchery = new Switchery(primary_s[z], { color: '#5A9AFB', secondaryColor: '#3B3E47', jackColor: '#fff', jackSecondaryColor: '#fff' });
            }


230 231 232 233 234 235 236 237 238 239 240
            var data_point = []
            var number2 = 0;

            for (var i = 0; i < data['point'].length; i++) {

                number2 += 1;
                var id = data['point'][i]['id'];
                var nama_tempat = data['point'][i]['nama_tempat'];
                var alamat = data['point'][i]['alamat'];
                var luas = data['point'][i]['luas'];
                var pj = data['point'][i]['pj']
Muhamad's avatar
Muhamad committed
241
                var db = data['point'][i]['table']
242 243 244 245 246 247 248 249 250

                var data_gab = `<tr>
                        <td>` + number2 + `</td>
                        <td>` + nama_tempat + `</td>
                        <td>` + alamat + `</td>
                        <td>` + luas + `</td>
                        <td>` + pj + `</td>
                        <td class="text-center " style="padding: 0px;">
                            <div class="row">
Muhamad's avatar
Muhamad committed
251
                                    <a class="btn mdlFire " data-toggle="modal" onclick="modal_detail_point_pengaturan('` + id + `','` + db + `')" style="padding: 10px 12px 10px 12px;">
252
                                        <div>
Muhamad's avatar
Muhamad committed
253
                                            <img src="static/img/icon-1/detailpoi.svg" alt="" style="margin-top: -4px;"><span>&nbsp;Detail</span>
254
                                        </div>
Muhamad's avatar
Muhamad committed
255
                                        
256 257 258 259 260 261 262 263 264 265
                                    </a>
    
                            </div>
                        </td>
                    </tr>`;
                data_point.push(data_gab)
            };



Muhamad's avatar
Muhamad committed
266
            $("#tbody_point_list").html(data_point)
267 268 269 270 271

            $('.datatable-show-all.list_user').DataTable({
                autoWidth: false,
                columnDefs: [{
                    orderable: false,
Muhamad's avatar
Muhamad committed
272
                    width: '10%',
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
                    targets: [0],
                }, ],
                dom: '<"float-left "B>frtip',
                language: {
                    search: ' _INPUT_',
                    searchPlaceholder: 'Data User...',
                    lengthMenu: '<span>Show:</span><hr> _MENU_',
                    paginate: {
                        'first': 'First',
                        'last': 'Last',
                        'next': '&rarr;',
                        'previous': '&larr;'
                    }
                },
                drawCallback: function() {
                    $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').addClass('dropup');
                },
                preDrawCallback: function() {
                    $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').removeClass('dropup');
                }
            });

            $('.datatable-show-all.list_point').DataTable({
                autoWidth: false,
                columnDefs: [{
                    orderable: false,
Muhamad's avatar
Muhamad committed
299
                    width: '10%',
300 301 302 303
                    targets: [0],

                }, {
                    orderable: false,
Muhamad's avatar
Muhamad committed
304 305
                    width: '10%',
                    targets: [3],
306 307 308

                }, {
                    orderable: false,
Muhamad's avatar
Muhamad committed
309
                    width: '10%',
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
                    targets: [5],

                }, ],
                dom: '<"float-left "B>frtip',
                language: {
                    search: ' _INPUT_',
                    searchPlaceholder: 'Data Tempat Penting...',
                    lengthMenu: '<span>Show:</span><hr> _MENU_',
                    paginate: {
                        'first': 'First',
                        'last': 'Last',
                        'next': '&rarr;',
                        'previous': '&larr;'
                    }
                },
                drawCallback: function() {
                    $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').addClass('dropup');
                },
                preDrawCallback: function() {
                    $(this).find('tbody tr').slice(-3).find('.dropdown, .btn-group').removeClass('dropup');
                }
            });

        }
    });
Muhamad's avatar
Muhamad committed
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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

function btnuserclick(evt) {
    var i, tabcontent, tablinks;

    tablinks = document.getElementsByClassName("tab-user");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    evt.currentTarget.className += " active";
}

function download_user_list(type, fn, dl) {
    $.ajax({
        url: "api/user-data",
        dataType: 'json',

        success: function(data) {

            var thead = `<thead>
                            <tr>
                                <th>No.</th>
                                <th>Id user</th>
                                <th>Username</th>
                                <th>Nama</th>
                                <th>Email</th>
                                <th>Last Login</th>
                                <th>Status</th>
                            </tr>
                        </thead>`
            var data_user = []
            var number = 0;

            for (var i = 0; i < data['data'].length; i++) {

                number += 1;
                var id = data['data'][i]['id'];
                var name = data['data'][i]['name'];
                var username = data['data'][i]['username'];
                var group = data['data'][i]['group'];
                var email = data['data'][i]['email'];
                var last = data['data'][i]['last'];
                var isactive = data['data'][i]['isactive'];


                var data_gab = `<tr>
                    <td>` + number + `</td>
                    <td>` + id + `</td>
                    <td>` + username + `</td>
                    <td>` + name + `</td>
                    <td>` + email + `</td>
                    <td>` + last + `</td>
                    <td>` + isactive + `</td>
                </tr>`;
                data_user.push(data_gab)
            }

            var tbody = `<tbody>
                            ` + data_user + `
                        </tbody>`;

            $("#table_downloader").html(thead + tbody)

            var elt = document.getElementById('table_downloader');

            var wb = XLSX.utils.table_to_book(elt, {
                sheet: "sheet1"
            });
            return dl ?
                XLSX.write(wb, {
                    bookType: type,
                    bookSST: true,
                    type: 'base64'
                }) :
                XLSX.writeFile(wb, fn || ('data_user.' + (type || 'xlsx')));


        }
    })
}

function download_point_list(type, fn, dl) {
    $.ajax({
        url: "api/user-data",
        dataType: 'json',

        success: function(data) {

            var thead = `<thead>
                            <tr>
                                <th>No.</th>
                                <th>Nama Tempat</th>
                                <th>Alamat</th>
                                <th>Luas Bangunan</th>
                                <th>Penanggung Jawab</th>
                            </tr>
                        </thead>`


            var data_point = []
            var number2 = 0;

            for (var i = 0; i < data['point'].length; i++) {

                number2 += 1;
                var id = data['point'][i]['id'];
                var nama_tempat = data['point'][i]['nama_tempat'];
                var alamat = data['point'][i]['alamat'];
                var luas = data['point'][i]['luas'];
                var pj = data['point'][i]['pj']

                var data_gab = `<tr>
                        <td>` + number2 + `</td>
                        <td>` + nama_tempat + `</td>
                        <td>` + alamat + `</td>
                        <td>` + luas + `</td>
                        <td>` + pj + `</td>
                    </tr>`;
                data_point.push(data_gab)
            };

            var tbody = `<tbody>
                            ` + data_point + `
                        </tbody>`;

            $("#table_downloader").html(thead + tbody)

            var elt = document.getElementById('table_downloader');

            var wb = XLSX.utils.table_to_book(elt, {
                sheet: "sheet1"
            });
            return dl ?
                XLSX.write(wb, {
                    bookType: type,
                    bookSST: true,
                    type: 'base64'
                }) :
                XLSX.writeFile(wb, fn || ('data_point.' + (type || 'xlsx')));


        }
    })
Muhamad's avatar
Muhamad committed
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 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
}


function loadGroups(isSelect) {
    var isObject = {}
    console.log(isSelect)
    isObject.func_name = "loadGroups";

    $.ajax({
        url: "/getallGroups/",
        data: isObject,
        dataType: 'json',
        type: 'post',
        success: function(data) {

            let response = data;
            console.log(response)
            if (response.code == 0) {
                var groups = response.data;
                var html = `<option value="null" selected disabled>-- Pilih Group --</option>`;
                for (i in groups) {
                    if (isSelect) {
                        if (isSelect.length >= 1) {
                            for (j in isSelect) {
                                if (isSelect[j] == groups[i]) {
                                    html += `<option value="` + groups[i] + `" selected>` + groups[i] + `</option>`;
                                    console.log(groups[i])
                                } else {
                                    html += `<option value="` + groups[i] + `">` + groups[i] + `</option>`;
                                }
                            }
                        } else {
                            html += `<option value="` + groups[i] + `">` + groups[i] + `</option>`;
                        }



                    } else {
                        html += `<option value="` + groups[i] + `">` + groups[i] + `</option>`;
                    }

                }

                $("#select_group").html(html);
                $("#select_group_parent").html(html);
                console.log(html)
            } else {
                $("#select_group").html("group tidak tersedia");
                $("#select_group_parent").html("group tidak tersedia");
            }

        }
    });
}

Muhamad's avatar
Muhamad committed
534 535 536 537 538 539 540 541 542
function swal_switch(isConfirm) {
    if (isConfirm == true) {

        $.ajax({
            url: "/switchStatus/",
            data: isObject,
            dataType: 'json',
            type: 'post',
            success: function(data) {
Muhamad's avatar
Muhamad committed
543

Muhamad's avatar
Muhamad committed
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
                let response = data;

                if (isObject.stat == "True") {
                    var inf = "dinonaktifkan"
                } else {
                    var inf = "diaktifkan"
                }
                if (response.code == 0) {
                    swal({
                        title: "sukses",
                        text: "User berhasil " + inf,
                        type: "success",
                        icon: "success",
                        confirmButtonColor: "#00BCD4"
                    }, function(isok) {

                        if (inf == "diaktifkan") {
                            $(this).checked = true;
                        } else {
                            $(this).checked = false;
                        }
                    })
                } else {
                    alert("no data in database")
                }

            }
        });
    } else {
        swal("Dibatalkan", "User status tidak berubah", "error");
    }
}


function switchuserstatus(id, c) {
Muhamad's avatar
Muhamad committed
579 580
    var isObject = {}
    var params = id.split(",");
Muhamad's avatar
Muhamad committed
581 582
    var checkbox = document.getElementById("checkbox" + c);
    console.log(checkbox);
Muhamad's avatar
Muhamad committed
583 584 585 586 587 588 589 590 591 592 593 594

    isObject.id = params[0];
    isObject.stat = params[1].replace(" ", "");

    if (isObject.stat == "True") {
        var title = "Nonaktifkan";
        var text = "User tidak akan bisa login jika dinonaktifkan!";
    } else {
        var title = "Aktifkan";
        var text = "User dapat kembali login jika diaktifkan!";
    }

Muhamad's avatar
Muhamad committed
595

Muhamad's avatar
Muhamad committed
596 597 598 599 600 601 602 603 604 605
    swal({
        title: title + " user?",
        text: text,
        type: "warning",
        showCancelButton: true,
        confirmButtonClass: "btn-danger",
        confirmButtonText: "Ya!",
        cancelButtonText: "Tidak!",
        closeOnConfirm: false,
        closeOnCancel: false
Muhamad's avatar
Muhamad committed
606
    }, function(isConfirm) {
Muhamad's avatar
Muhamad committed
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
        swal_switch(isConfirm)

        // if (cb == 'b') {
        //     alert('b')
        //check it 
        // if (cb == true) {
        //     checkbox.checked = false;
        // } else {
        //     checkbox.checked = true
        // }

        // } else {
        //     alert('a')

        // if (cb == true) {
        //     checkbox.checked = true;
        // } else {
        //     checkbox.checked = false;
        // }
        // }
Muhamad's avatar
Muhamad committed
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
    });

}

function loaduserbyid(id) {
    var isObject = {};

    isObject.id = id;
    $("#iduser").val(id)

    $.ajax({
        url: "/loadUserbyId/",
        data: isObject,
        dataType: 'json',
        type: 'post',
        success: function(data) {
Muhamad's avatar
Muhamad committed
643 644 645 646
            $("#modal_edit_user").modal("show")
            $(".modstit").html("Update User")
            $("#inUsername").attr("disabled", true)

Muhamad's avatar
Muhamad committed
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671

            let response = data;

            if (response.code == 0) {
                var user = response.data;
                console.log(user)
                $("#inUsername").val(user.username);
                $("#inNameF").val(user.firstname);
                $("#inNameL").val(user.lastname);
                $("#inEmail").val(user.email);
                if (user.is_staff) {
                    $('input[name=isStaff][value=true]').attr('checked', true)
                } else {
                    $('input[name=isStaff][value=false]').attr('checked', true)
                }
                loadGroups(user.group)
                $("#modalAddButton").click()
            } else {

            }

        }
    });
}

Muhamad's avatar
Muhamad committed
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695

var map_poin_det = L.map('maps_detail_p', {
    editable: true,
    zoomControl: false,
    drawControl: true
});

mapss = L.tileLayer('https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}&s=Gal&apistyle=s.t:0|s.e:l|p.v:off', {
    maxZoom: 22,
    minZoom: 4,
}).addTo(map_poin_det);

var map_edit_p = L.map('map-for-edit', {
    editable: true,
    zoomControl: false,
    drawControl: true
}).setView([-2, 118], 5);

mapss_p = L.tileLayer('https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}&s=Gal&apistyle=s.t:0|s.e:l|p.v:off', {
    maxZoom: 22,
    minZoom: 4,
}).addTo(map_edit_p);


Muhamad's avatar
Muhamad committed
696
function modal_detail_point_pengaturan(id, db) {
Muhamad's avatar
Muhamad committed
697

Muhamad's avatar
Muhamad committed
698 699
    $("#modal_detail_point_pengaturan").modal("show")

Muhamad's avatar
Muhamad committed
700 701 702 703 704 705 706 707 708 709
    if (map_poin_det.hasLayer(marker)) {
        marker.clearLayers()
        marker.remove()
    }

    if (map_edit_p.hasLayer(marker)) {
        poinin.clearLayers()
        poinin.remove()
    }

Muhamad's avatar
Muhamad committed
710 711 712 713 714 715 716 717
    $.ajax({
        url: "/api/load_point_id",
        data: {
            'idx': id,
            'db': db
        },
        dataType: 'json',
        success: function(data) {
Muhamad's avatar
Muhamad committed
718 719 720 721 722
            setTimeout(function() {
                map_poin_det.invalidateSize();
            }, 1000);
            $("#id_adm_edit").val(id)

Muhamad's avatar
Muhamad committed
723 724 725 726 727 728


            $(".nama_point").html(data['result'][0][0]['properties']['f2'])
            $(".pj_bangunan").html(data['result'][0][0]['properties']['f5'])
            $(".luas_bangunan").html(data['result'][0][0]['properties']['f4'])

Muhamad's avatar
Muhamad committed
729 730 731 732 733 734 735 736 737

            $(".gambar_point").html(`<img src="/static/img/image/` + data['result'][0][0]['properties']['f6'] + `" alt="" style="width:100%;height:240px;border-top-left-radius: 10px;">`)

            $("#namobj_adm_edit").val(data['result'][0][0]['properties']['f2'])
            $("#alamat_adm_edit").val(data['result'][0][0]['properties']['f3'])
            $("#luas_tanah_adm_edit").val(data['result'][0][0]['properties']['f4'])
            $("#perangkat_adm_edit").val(data['result'][0][0]['properties']['f5'])
            $("#db_p").val(db)

Muhamad's avatar
Muhamad committed
738 739 740
            var marker = L.marker([data['result'][0][0]['geometry']['coordinates'][1], data['result'][0][0]['geometry']['coordinates'][0]]).addTo(map_poin_det);
            map_poin_det.setView([data['result'][0][0]['geometry']['coordinates'][1], data['result'][0][0]['geometry']['coordinates'][0]], 17)

Muhamad's avatar
Muhamad committed
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
            map_edit_p.setView([data['result'][0][0]['geometry']['coordinates'][1], data['result'][0][0]['geometry']['coordinates'][0]], 17);
            let dapoin = [data['result'][0][0]['geometry']['coordinates'][1], data['result'][0][0]['geometry']['coordinates'][0]]
            var poinin = L.marker(dapoin).addTo(map_edit_p)
            poinin.enableEdit();
            $('#saveedit_p').click(function() {
                var hasil = (JSON.stringify(poinin.toGeoJSON()))
                $("#coordinateZoneedit_p").val(hasil);
            })
            $("#edit_point_p").click(function() {
                setTimeout(function() {
                    map_edit_p.invalidateSize();
                }, 1000);
            })
        }
    });
}
Muhamad's avatar
Muhamad committed
757 758


Muhamad's avatar
Muhamad committed
759 760 761
$("#saveuser").on("click", function() {
    addUser()
})
Muhamad's avatar
Muhamad committed
762

Muhamad's avatar
Muhamad committed
763 764 765 766 767 768 769 770 771 772 773
// function destroyfade() {
//     $(".modal-backdrop").css("display", "none")
//     $(".modal-backdrop").removeClass('show');
//     $("body").css('padding-right', '0px !important')
// }

function addUser() {
    var isObject = {};
    var ars = ''
    var group = $("#select_group").val();
    var iduser = $("#iduser").val();
Muhamad's avatar
Muhamad committed
774

Muhamad's avatar
Muhamad committed
775 776 777
    if (iduser) {
        isObject.id = iduser;
    }
Muhamad's avatar
Muhamad committed
778

Muhamad's avatar
Muhamad committed
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
    // for(i in group){
    //     if(i < group.length-1){
    //         ars += group[i]+"~";
    //     }else{
    //         ars += group[i];
    //     }
    // }
    // return false
    isObject['username'] = $("#inUsername").val();
    isObject['first_name'] = $("#inNameF").val();
    isObject['last_name'] = $("#inNameL").val();
    isObject['email'] = $("#inEmail").val();
    isObject.group = group
    isObject.isStaff = $('input[name="isStaff"]:checked').val();

    $.ajax({
        url: "adduser/",
        data: isObject,
        dataType: 'json',
        type: 'post',
        success: function(data) {
            let response = data;

            if (response.code == 0) {
                $("#modal_edit_user").css('display', 'none');
                // destroyfade();

                swal({
                    title: response.info,
                    text: response.data + "reload untuk mendapatkan update",
                    type: "success",
                    icon: "success",
                    confirmButtonColor: "#00BCD4"
                })
            } else {
                swal({
                    title: response.info,
                    text: response.data,
                    type: "alert",
                    icon: "error",
                    confirmButtonColor: "#00BCD4"
                })

            }
        }
    });
}

$("#saveedit_p").click(function() {
    var idka = $('#id_adm_edit').val();
    var poi = $('#coordinateZoneedit_p').val();
    var data = new FormData();
    data.append("file", $("input[id^='fileadm']")[0].files[0]);

    data.append('id', idka)
    data.append('namobj', $('#namobj_adm_edit').val())
    data.append('luastanah', $('#luas_tanah_adm_edit').val())
    data.append('alamat', $('#alamat_adm_edit').val())
    data.append('perangkat', $('#perangkat_adm_edit').val())
    data.append('point', poi)
    data.append('db', $("#db_p").val())
    data.append('gambar', $('#gambar_adm_edit').val())

    $.ajax({
        url: "/api/edit_detail_poin",
        data: data,
        dataType: 'json',
        type: 'POST',
        processData: false,
        contentType: false,
        success: function(data) {
            let response = data
            if (response.status == 0) {
                swal({
                    title: response.info,
                    text: response.data,
                    type: "success",
                    icon: "success",
                    confirmButtonColor: "#00BCD4"
                }, function() {
                    $("#modal_adm").css('display', 'none');
                })
            } else {
                swal({
                    title: 'Error',
                    text: 'Hubungi Developer',
                    type: "warning",
                    icon: "error",
                    confirmButtonColor: "#00BCD4"
                })
            }
        }
    });
})
Muhamad's avatar
Muhamad committed
873

Muhamad's avatar
Muhamad committed
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
function changepassword() {
    var isObject = {};

    isObject.id = $("#iduseredt").val();
    isObject.currPass = $('#currentPass').val();
    isObject.newPass = $("#newPass").val();
    isObject.renewPass = $("#renewPass").val();
    isObject.username = $("#usernameedt").val();

    if (isObject.currPass == "" || isObject.newPass == "" || isObject.renewPass == "") {
        $("#notifications").css("display", "block")
        $("#notifications").html("Inputan tidak boleh kosong")

        return false;
    }

    $.ajax({
        url: "changepassword/",
        data: isObject,
        dataType: 'json',
        type: 'post',
        success: function(data) {
            let response = data;

            if (response.code == 0) {
                var datas = response.data
                swal({
                    title: response.info,
                    text: response.data,
                    type: "success",
                    icon: "success",
                    confirmButtonColor: "#00BCD4"
                }, function() {
                    $("#notifications").css("display", "none")
                })
            } else {
                $("#notifications").html(response.data)
                $("#notifications").css("display", "block")
            }
Muhamad's avatar
Muhamad committed
913 914
        }
    });
Muhamad's avatar
Muhamad committed
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017



}



function editprofile() {
    var isObject = {}

    isObject.id = $("#iduseredt").val();
    isObject.first_name = $("#firstnameedt").val();
    isObject.last_name = $("#lastnameedt").val();
    isObject.email = $("#emailedts").val()

    if (isObject.first_name == "" || isObject.last_name == "" || isObject.email == "") {
        $("#notificationsprop").css("display", "block");
        $("#notificationsprop").html("Inputan tidak boleh kosong")
        return false
    } else {
        var mail_format = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/;

        if (!isObject.email.match(mail_format)) {
            $("#notificationsprop").css("display", "block");
            $("#notificationsprop").html("Format email tidak valid, silahkan coba kembali.")
            return false
        }
    }

    $.ajax({
        url: "editprofile/",
        data: isObject,
        dataType: 'json',
        type: 'post',
        success: function(data) {
            let response = data;

            if (response.code == 0) {
                var datas = response.data
                swal({
                    title: response.info,
                    text: response.data,
                    type: "success",
                    icon: "success",
                    confirmButtonColor: "#00BCD4"
                }, function() {
                    $("#notificationsprop").css("display", "none")
                })

            } else {
                $("#notificationsprop").html(response.data)
                $("#notificationsprop").css("display", "block");
            }
        }
    });

}

function changecur() {
    var checkBox = document.getElementById("passcur");
    var typ = document.getElementById("currentPass");
    if (checkBox.checked == true) {

        $("#matachange").html(`<i class="icon-eye"></i>`)
        typ.type = 'text';
    } else {
        $("#matachange").html(`<i class="icon-eye-blocked"></i>`)
        typ.type = 'password';
    }
}

function changecur1() {
    var checkBox = document.getElementById("passcur1");
    var typ = document.getElementById("newPass");
    if (checkBox.checked == true) {

        $("#matachange1").html(`<i class="icon-eye"></i>`)
        typ.type = 'text';
    } else {
        $("#matachange1").html(`<i class="icon-eye-blocked"></i>`)
        typ.type = 'password';
    }
}

function changecur2() {
    var checkBox = document.getElementById("passcur2");
    var typ = document.getElementById("renewPass");
    if (checkBox.checked == true) {

        $("#matachange2").html(`<i class="icon-eye"></i>`)
        typ.type = 'text';
    } else {
        $("#matachange2").html(`<i class="icon-eye-blocked"></i>`)
        typ.type = 'password';
    }
}


$("#btnsaveuser").click(function() {
    editprofile()
    changepassword()
})

Muhamad's avatar
Muhamad committed
1018 1019
// function switchuserstatuss(id, isactive) {
//     var checkbox = $(this);
Muhamad's avatar
Muhamad committed
1020

Muhamad's avatar
Muhamad committed
1021 1022 1023 1024
//     if (checkbox.is(":checked")) {
//         e.preventDefault();
//         return false;
//     }else{
Muhamad's avatar
Muhamad committed
1025

Muhamad's avatar
Muhamad committed
1026 1027
//     }
// }
Muhamad's avatar
Muhamad committed
1028 1029 1030

document.querySelector("#map-create-all > div.leaflet-control-container > div.leaflet-bottom.leaflet-right > div").html(`Powered by <a href="https://khansia.co.id" target="_blank">Khansia</a> with <a href="https://leafletjs.com" target="_blank">Leaflet</a>`)
document.querySelector("#map-create-all > div.leaflet-control-container > div.leaflet-bottom.leaflet-right > div").css("right", "50px")