282 lines
9.0 KiB
PHP
282 lines
9.0 KiB
PHP
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css"
|
|
integrity="sha512-vKMx8UnXk60zUwyUnUPM3HbQo8QfmNx7+ltw8Pm5zLusl1XIfwcxo8DbWCqMGKaWeNxWA8yrx5v3SaVpMvR3CA=="
|
|
crossorigin="anonymous"/>
|
|
<style>
|
|
.onoffswitch {
|
|
position: relative;
|
|
width: 90px;
|
|
-webkit-user-select: none;
|
|
-moz-user-select: none;
|
|
-ms-user-select: none;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.onoffswitch-checkbox {
|
|
position: absolute;
|
|
opacity: 0;
|
|
pointer-events: none;
|
|
}
|
|
|
|
.onoffswitch-label {
|
|
display: block;
|
|
overflow: hidden;
|
|
cursor: pointer;
|
|
border: 2px solid #999999;
|
|
border-radius: 20px;
|
|
}
|
|
|
|
.onoffswitch-inner {
|
|
display: block;
|
|
width: 200%;
|
|
margin-left: -100%;
|
|
transition: margin 0.3s ease-in 0s;
|
|
}
|
|
|
|
.onoffswitch-inner:before, .onoffswitch-inner:after {
|
|
display: block;
|
|
float: left;
|
|
width: 50%;
|
|
height: 30px;
|
|
padding: 0;
|
|
line-height: 30px;
|
|
font-size: 14px;
|
|
color: white;
|
|
font-family: Trebuchet, Arial, sans-serif;
|
|
font-weight: bold;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.onoffswitch-inner:before {
|
|
content: "ON";
|
|
padding-left: 10px;
|
|
background-color: #3F51B5;
|
|
color: #FFFFFF;
|
|
}
|
|
|
|
.onoffswitch-inner:after {
|
|
content: "OFF";
|
|
padding-right: 10px;
|
|
background-color: #EEEEEE;
|
|
color: #999999;
|
|
text-align: right;
|
|
}
|
|
|
|
.onoffswitch-switch {
|
|
display: block;
|
|
width: 18px;
|
|
margin: 6px;
|
|
background: #FFFFFF;
|
|
position: absolute;
|
|
top: 0;
|
|
bottom: 0;
|
|
right: 56px;
|
|
border: 2px solid #999999;
|
|
border-radius: 20px;
|
|
transition: all 0.3s ease-in 0s;
|
|
}
|
|
|
|
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
|
|
margin-left: 0;
|
|
}
|
|
|
|
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
|
|
right: 0px;
|
|
}
|
|
|
|
label.error {
|
|
color: red;
|
|
}
|
|
</style>
|
|
<div class="modal fade" id="modalCRUD" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
|
|
</button>
|
|
<h4 class="modal-title" id="myModalLabel">Add new screen card</h4>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form action="/Screen_Cards/create_or_update" method="post" id="frmCRUD">
|
|
<input type="hidden" name="id" id="id" value="0">
|
|
<div class="form-group">
|
|
<label for="screen_name">Screen Name</label>
|
|
<?= $screen_name_ddl ?? '' ?>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="trigger_id">Trigger ID</label>
|
|
<?= $trigger_id_ddl ?? '' ?>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="onoffswitch">
|
|
<input type="checkbox" name="status" class="onoffswitch-checkbox" checked value="1"
|
|
id="status">
|
|
<label class="onoffswitch-label" for="status">
|
|
<span class="onoffswitch-inner"></span>
|
|
<span class="onoffswitch-switch"></span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<div class="text-right">
|
|
<button type="submit" class="btn btn-primary">Save</button>
|
|
<button type="submit" class="btn btn-default" data-dismiss="modal">Close</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading">Screen Cards</div>
|
|
<div class="panel-body">
|
|
<button type="button" class="btn btn-primary pull-right" onclick="fnShowCreate();">
|
|
Add new Screen Card
|
|
</button>
|
|
<div class="clearfix"></div>
|
|
<div class="text-right" style="margin-top: 10px">
|
|
<?= $links ?>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<?= $screen_cards_table ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"
|
|
integrity="sha512-VEd+nq25CkR676O+pLBnDW09R7VQX9Mdiij052gVCp5yVH3jGtH70Ho/UUv4mJDsEdTvqRCFZg0NKGiojGnUCw=="
|
|
crossorigin="anonymous"></script>
|
|
<script>
|
|
$(document).ready(function () {
|
|
<?php if($this->session->flashdata('msg')){ ?>
|
|
toastr['success']('<?php echo $this->session->flashdata('msg'); ?>');
|
|
<?php } ?>
|
|
|
|
<?php if($this->session->flashdata('error')){ ?>
|
|
toastr['error']('<?php echo $this->session->flashdata('error'); ?>');
|
|
<?php } ?>
|
|
});
|
|
</script>
|
|
<script>
|
|
const $modal = $("#modalCRUD");
|
|
const $myModalLabel = $("#myModalLabel");
|
|
const $frmCRUD = $("#frmCRUD");
|
|
const $id = $frmCRUD.find("#id");
|
|
const $screen_name = $frmCRUD.find("#screen_name");
|
|
const $trigger_id = $frmCRUD.find("#trigger_id");
|
|
const $status = $frmCRUD.find("#status");
|
|
const $submits = $frmCRUD.find("[type='submit']");
|
|
$frmCRUD.validate({
|
|
rules: {
|
|
screen_name: {
|
|
required: true
|
|
},
|
|
trigger_id: {
|
|
required: true
|
|
},
|
|
},
|
|
submitHandler: function (form) {
|
|
const id = parseInt($id.val());
|
|
const screen_name = $screen_name.val();
|
|
const trigger_id = $trigger_id.val();
|
|
const settings = {
|
|
url: '/Screen_Cards/is_exists',
|
|
method: "POST",
|
|
data: {
|
|
id, screen_name, trigger_id
|
|
},
|
|
timeout: 0,
|
|
dataType: "json",
|
|
beforeSend: function (){
|
|
fnDisSubmits();
|
|
}
|
|
};
|
|
$.ajax(settings).done(function (response) {
|
|
if (response) { //exists
|
|
toastr['error']('Screen Name & Trigger ID already exist, please try again!');
|
|
} else {
|
|
form.submit();
|
|
}
|
|
}).always(function () {
|
|
fnUnDisSubmits();
|
|
});
|
|
}
|
|
});
|
|
|
|
function fnDisSubmits(){
|
|
$submits.attr('disabled','disabled');
|
|
}
|
|
function fnUnDisSubmits(){
|
|
$submits.removeAttr('disabled');
|
|
}
|
|
function fnShowCreate() {
|
|
$frmCRUD.validate().resetForm();
|
|
$myModalLabel.html('Add new screen card');
|
|
$id.val(0);
|
|
$screen_name.val('');
|
|
$trigger_id.val('');
|
|
$status.prop('checked', true);
|
|
$modal.modal('show');
|
|
}
|
|
|
|
function fnShowEdit(id) {
|
|
$frmCRUD.validate().resetForm();
|
|
$id.val(id);
|
|
$.getJSON('/Screen_Cards/get_by_id?id=' + id, function (data) {
|
|
$myModalLabel.html('Update screen card: #' + data.id);
|
|
$screen_name.val(data.screen_name);
|
|
$trigger_id.val(data.trigger_id);
|
|
$status.prop('checked', data.status == 1);
|
|
$modal.modal('show');
|
|
});
|
|
}
|
|
|
|
function fnDelete(id) {
|
|
if (!confirm('Confirm delete item?')) {
|
|
return false;
|
|
}
|
|
var settings = {
|
|
url: '/Screen_Cards/delete',
|
|
method: "POST",
|
|
data: {
|
|
id
|
|
},
|
|
timeout: 0,
|
|
dataType: "json",
|
|
};
|
|
$.ajax(settings).done(function (response) {
|
|
if (!response) {
|
|
toastr['error']('Something went wrong, please try again!');
|
|
} else {
|
|
toastr['success']('deleted item!');
|
|
}
|
|
}).fail(function (jqXHR, textStatus) {
|
|
toastr['error']('Something went wrong Please try again! [' + textStatus + ']');
|
|
}).always(function () {
|
|
setTimeout(function () {
|
|
window.location.reload();
|
|
}, 1500);
|
|
});
|
|
}
|
|
|
|
function fnToggle(id, cur_status) {
|
|
var settings = {
|
|
url: '/Screen_Cards/ajax_toggle',
|
|
method: "POST",
|
|
data: {
|
|
id, cur_status
|
|
},
|
|
timeout: 0,
|
|
dataType: "json",
|
|
};
|
|
$.ajax(settings).done(function (response) {
|
|
if (!response) {
|
|
toastr['error']('Something went wrong Please try again!');
|
|
window.location.reload();
|
|
} else {
|
|
toastr['success']('Update status successful!');
|
|
}
|
|
}).fail(function (jqXHR, textStatus) {
|
|
toastr['error']('Something went wrong Please try again! [' + textStatus + ']');
|
|
})
|
|
}
|
|
</script>
|