edit.js 0000644 00000005612 15024756716 0006050 0 ustar 00 (function(e){
"use strict";
var questionArr = [];
var url = "";
function submitTemplate(){
$('#template_save').on('click', function(e){
e.preventDefault();
questionArr = [];
$(this).attr('disabled',true);
$('input[type="checkbox"]:checked').each(function(){
questionArr.push(this.value);
}); //push the question id's into an array
var formData = new FormData();
formData.append('id',template.id);
url = "/templates/update";
formData.append('title',$('#template_name').val());
formData.append('questionArr',questionArr);
$.ajax({
type: "POST",
url: url,
dataType: 'json',
data: formData,
processData: false,
contentType: false,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(result){
toastRWithTime("success","success");
location.replace('/templates');
},
error: function(error){
toastRWithTime(error.responseJSON.message,"error")
}
});
});
}
$(function(){
var qs = template.q_id;
$('#template_name').val(template.title);
questions.forEach(function(item){
if(qs.includes(item.id.toString())){
$('.questions-list').append(`
\n
`);
} else {
$('.questions-list').append(`\n
`);
}
});
$('input[type="checkbox"]').change(function(){
questionArr = [];
});
$('#clear_selection').on('click', function(e){
e.preventDefault();
$('input[type="checkbox"]').each(function(){
this.checked = false;
});
toastRWithTime("Selection Cleared","info");
});
$('#select_all').on('click', function(e){
e.preventDefault();
$('input[type="checkbox"]').each(function(){
this.checked = true;
});
toastRWithTime("Selected all","info");
});
$('#template_cancel').on('click', function(e){
location.replace('/templates');
});
submitTemplate();
});
})(); create.js 0000644 00000004406 15024756716 0006366 0 ustar 00 (function(e){
"use strict";
var questionArr = [];
var id = null;
var url = null;
function submitTemplate(){
$('#template_save').on('click', function(e){
e.preventDefault();
questionArr = [];
// $(this).attr('disabled',true);
$('input[type="checkbox"]:checked').each(function(){
questionArr.push(this.value);
}); //push the question id's into an array
var id = $('[name="edit_id"]').val();
var formData = new FormData();
url = "/templates/store";
if(id){
formData.append('id',id);
url = "templates/update";
}
formData.append('title',$('#template_name').val());
formData.append('questionArr',questionArr);
$.ajax({
type: "POST",
url: url,
dataType: 'json',
data: formData,
processData: false,
contentType: false,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(result){
toastRWithTime("success","success");
window.location.href = '/templates';
},
error: function(error){
toastRWithTime(error.responseJSON.message,"error");
}
});
});
}
$(function(){
submitTemplate();
$('input[type="checkbox"]').change(function(){
questionArr = [];
});
$('#clear_selection').on('click', function(e){
e.preventDefault();
$('input[type="checkbox"]').each(function(){
this.checked = false;
});
toastRWithTime("Selection Cleared","info");
});
$('#select_all').on('click', function(e){
e.preventDefault();
$('input[type="checkbox"]').each(function(){
this.checked = true;
});
toastRWithTime("Selected all","info");
});
$('#template_back').on('click', function(e){
window.location.href = "/templates";
});
});
})(); template.js 0000644 00000021713 15024756716 0006736 0 ustar 00 (function(e){
"use strict";
var search_type_filter = [];
var templateList = null;
var id = null;
var url = null;
function delay(callback, ms) {
var timer = 0;
return function () {
var context = this,
args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
callback.apply(context, args);
}, ms || 0);
};
}
function initActionUpdate(){
$("[data-action-update]").each(function () {
$(this).on("click", function () {
var row = $(this).closest("tr");
id = templateList.row(row).data().id;
window.location.href = "/templates/" + id;
// var formData = new FormData();
// formData.append("id",id);
// $.ajax({
// type: "POST",
// url: "/templates/get",
// dataType: 'json',
// data: formData,
// processData: false,
// contentType: false,
// headers: {
// 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
// },
// success: function(result){
// console.log(result);
// $('#templateName').val(result.title);
// $('#templateModal').append(``);
// $('#templateModalTitle').text("EDIT");
// $('#templateModal').modal('show');
// },
// error: function(error){
// }
// });
});
});
}
function initActionRemove(){
$("[data-action-remove]").each(function () {
$(this).on("click", function () {
var row = $(this).closest("tr");
id = templateList.row(row).data().id;
swal.fire({
title: 'Are you sure you want to delete this item?',
icon: 'warning',
iconColor: 'red',
showDenyButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: 'Confirm',
denyButtonText: `Cancel`,
}).then((result) => {
var formData = new FormData();
formData.append("id",id);
if(result.isConfirmed){
$.ajax({
type: "POST",
url: "/templates/destroy",
dataType: 'json',
data: formData,
processData: false,
contentType: false,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(result){
toastRWithTime("success","success");
templateList.draw(false);
},
error: function(error){
toastRWithTime(error.responseJSON.message,"error")
}
});
} else if (result.isDenied){
toastRWithTime('changes not saved','info');
return;
}
});
});
});
}
function getDataTableData(){
var data = {};
return data;
}
function initList(){
$('.txt_search').on("keyup",delay(function(e){
templateList.search($('.txt_search').val()).draw()
},500));
const search_type_default = "Template Name";
const search_types = ["Template Name"];
$.each(search_types, function (i, n) {
$(".system-search-type").append(
`` +
n +
``
);
});
$(".system-search-type li").each(function () {
if ($(this).text() == search_type_default) {
$(this).removeClass("active").addClass("active");
var active_items_arr = [];
active_items_arr.push(search_type_default);
search_type_filter = JSON.stringify(active_items_arr);
}
$(this).on("click", function () {
//remove all selected menu
$(".system-search-type")
.find("li.active")
.map(function () {
$(this).removeClass("active");
});
$(this).toggleClass("active");
var active_items = $(".system-search-type")
.find("li.active")
.map(function () {
var item = {};
// item.id = this.value;
item.status = $(this).text();
return item;
});
var active_items_arr = [];
$.each(active_items, function (i, n) {
active_items_arr.push(n.status);
});
search_type_filter = JSON.stringify(active_items_arr);
// refreshOrcrPlateTable();
// if ($('#txt_search').val() != '') {
templateList.draw(false);
// }
});
});
var cols = [
{
title: "ID",
data: 'id',
className: 'align-middle p-1 dt-left',
orderable: true,
width: "5%",
},
{
title: "Template Name",
data: 'title',
className: 'align-middle p-1 dt-left',
orderable: true,
width: "40%",
},
{
title: "Action",
data: null,
orderable: false,
width: "20%",
className: "align-middle p-1 dt-center",
render: function (data, type, row, meta) {
return `
`;
},
},
];
templateList = $('#templateTable').DataTable({
fnDrawCallback: function () {
initActionRemove();
initActionUpdate();
},
order: [[0, "desc"]],
retrieve: true,
columns: cols,
paging: true,
lengthChange: false,
searching: true,
pageLength: 5,
info: true,
autoWidth: true,
responsive: true,
processing: true,
serverSide: true,
autoWidth: true,
columnDefs: [
{ width: '20%', targets: 0 }
],
fixedColumns: true,
ajax: {
url:'/templates/fetchall',
data: function (d){
return $.extend({},d,{
search_type: search_type_filter,
data: getDataTableData(),
})
}
},
sDom: "lrtip",
});
}
function submitTemplate(){
$('#template_save').on('click', function(e){
var id = $('[name="edit_id"]').val();
var formData = new FormData();
url = "/templates/store";
if(id){
formData.append('id',id);
url = "templates/update";
}
formData.append('title',$('#templateName').val());
$.ajax({
type: "POST",
url: url,
dataType: 'json',
data: formData,
processData: false,
contentType: false,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(result){
$('#templateModal').modal('hide');
toastRWithTime("success","success");
templateList.draw(false);
},
error: function(error){
}
});
});
}
$(function(){
initList();
submitTemplate();
$('#reload_list').on('click', function(e){
templateList.draw(false);
});
$('#t_create').on('click', function(e){
e.preventDefault();
window.location.href = "/templates/create";
});
});
})();