<style>
    #mira-application-update1{
        border: 2px solid #dddddd;
    }
    #mira-application-update1 > thead > tr > th,
    #mira-application-update1 > tbody > tr > th,
    #mira-application-update1 > tfoot > tr > th,
    #mira-application-update1 > thead > tr > td,
    #mira-application-update1 > tbody > tr > td,
    #mira-application-update1 > tfoot > tr > td {
        border: 2px solid #dddddd;

    }
    #mira-application-update{
        width: 100%;
        overflow-x: scroll;
    } 
</style>
<div class="panel"> 
    <div class="panel-body">

        <table id="mira-application-update1" class="table table-bordred table-striped">
            <thead>
                <tr>
                    <th colspan="7"><h4 class="text-center"> <strong>Mapped Application List For Update</strong></h4></th>
            </tr>
            <tr>
                <th class="text-center">Application Name</th>
                <th class="text-center">Admin Name</th>
                <th class="text-center">Mapped Date</th>
                <th class="text-center">Current Status</th>
                <th class="text-center">Activate Date</th>
                <th class="text-center">Expire Date</th>
                <th class="text-center"><span><strong>Update</strong></span></th>
            </tr>
            </thead>
            <tbody>
                <?php for ($i = 0; $i < count($mapped_app_list); $i++) { ?>
                    <?php if ($mapped_app_list[$i]['activate_status']) { ?>
                        <tr id="<?= "tr".$mapped_app_list[$i]['app_id']?>" class="text-success">
                            <td class="text-center"><?= $mapped_app_list[$i]['app_name'] ?></td>
                            <td class="text-center"><?= $mapped_app_list[$i]['admin_name'] ?></td>
                            <td class="text-center"><?= date('d-m-Y', strtotime($mapped_app_list[$i]['mapping_date'])); ?></td>
                            <td class="text-center"><span class="label label-success" id=<?="current".$mapped_app_list[$i]['app_id']?>>Application Running...</span></td>
                            <td class="text-center"><span id=<?="activate".$mapped_app_list[$i]['app_id']?>><?= date('d-m-Y', strtotime($mapped_app_list[$i]['activate_date'])); ?></span></td>
                            <td class="text-center"><span id=<?="expire".$mapped_app_list[$i]['app_id']?>><?= date('d-m-Y', strtotime($mapped_app_list[$i]['expire_date'])); ?></span></td>
                            <td class="text-center"><p id="<?="title".$mapped_app_list[$i]['app_id']?>" data-placement="top" data-toggle="tooltip" title="Update for Deactivation"><button id="<?= "button".$mapped_app_list[$i]['app_id']?>" class="btn btn-success btn-xs update-application" data-title="applicationUpdate" data-toggle="modal" data-target="#applicationUpdate" value=<?= $mapped_app_list[$i]['app_id'].":0" ?>><span class="glyphicon glyphicon-refresh" id=<?= $mapped_app_list[$i]['app_id']?>>&nbsp;Deactivation</span></button></p></td>
                        </tr>
                    <?php } else { ?>
                        <tr id="<?= "tr".$mapped_app_list[$i]['app_id']?>" class="text-info">
                            <td class="text-center"><?= $mapped_app_list[$i]['app_name'] ?></td>
                            <td class="text-center"><?= $mapped_app_list[$i]['admin_name'] ?></td>
                            <td class="text-center"><span><?= date('d-m-Y', strtotime($mapped_app_list[$i]['mapping_date'])); ?></span></td>
                            <td class="text-center"><span class="label label-info" id=<?="current".$mapped_app_list[$i]['app_id']?>>Activation Pending..</span></td>
                            <td class="text-center"><span id=<?="activate".$mapped_app_list[$i]['app_id']?>>-----------</span></td>
                            <td class="text-center"><span id=<?="expire".$mapped_app_list[$i]['app_id']?>>-----------</span></td>
                            <td class="text-center"><p id="<?= "title".$mapped_app_list[$i]['app_id']?>" data-placement="top" data-toggle="tooltip" title="Update for Activation"><button id="<?= "button".$mapped_app_list[$i]['app_id']?>" class="btn btn-danger btn-xs update-application" data-title="applicationUpdate" data-toggle="modal" data-target="#applicationUpdate" value=<?= $mapped_app_list[$i]['app_id'].":1" ?>><span class="glyphicon glyphicon-refresh" id=<?= $mapped_app_list[$i]['app_id']?>>&nbsp;Activation</span></button></p></td>
                        </tr>

                    <?php }
                }
                ?>

            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
    $('.update-application').click(function (){
        var app_id=$(this).val();   
        $(this).prop('disabled', true);
        $.ajax({
                url: '<?= base_url('update_current_status') ?>',
                data: {
                    app_id: app_id
                },
                type: "POST",
                success: function (json) {
                    $('#button'+app_id.substring(0, 1)).prop('disabled', false);
                    var current_status_app = $.parseJSON(json);
                    if(current_status_app['status']){
                        if(parseInt(current_status_app['current'])==0){
                            $('#tr'+app_id.substring(0, 1)).removeClass('text-info').addClass('text-success');
                            $('#button'+app_id.substring(0, 1)).val(current_status_app['app_id']);
                            $('#button'+app_id.substring(0, 1)).removeClass("btn-danger").addClass("btn-success");
                            $('#'+app_id.substring(0, 1)).text(' Deactivation');
                            $('#title'+app_id.substring(0, 1)).attr("title", "Update for Deactivation");
                            $('#current'+app_id.substring(0, 1)).text('Application Running...');
                            $('#activate'+app_id.substring(0, 1)).text(current_status_app['activate_date']);
                            $('#expire'+app_id.substring(0, 1)).text(current_status_app['expire_date']);
                            $('#current'+app_id.substring(0, 1)).removeClass('label-info').addClass('label-success');
                        }else{
                            $('#activate'+app_id.substring(0, 1)).text('-----------');
                            $('#expire'+app_id.substring(0, 1)).text('------------');
                            $('#tr'+app_id.substring(0, 1)).removeClass('text-success').addClass('text-info');
                            $('#button'+app_id.substring(0, 1)).val(current_status_app['app_id']);
                            $('#button'+app_id.substring(0, 1)).removeClass("btn-success").addClass("btn-danger");
                            $('#'+app_id.substring(0, 1)).text(' Activation');
                            $('#title'+app_id.substring(0, 1)).attr("title", "Update for Activation");
                            $('#current'+app_id.substring(0, 1)).text('Activation Pending');
                            $('#current'+app_id.substring(0, 1)).removeClass('label-success').addClass('label-info');                  }
                    }
      
                },
                error: function (xhr, status, errorThrown) {
                    $('#button'+app_id.substring(0, 1)).prop('disabled', false);
                },
                complete: function (xhr, status) {
                   $('#button'+app_id.substring(0, 1)).prop('disabled', false);
                }
            });
//        $( this ).removeClass("btn-danger").addClass("btn-success");
//        $("#"+$(this).val()).text('Deactivation');
//        $("#title"+$(this).val()).prop('title', 'Update for Deactivation');
    });
});
</script>

