169 lines
6.5 KiB
JavaScript
169 lines
6.5 KiB
JavaScript
var url = '/';
|
|
var id;
|
|
|
|
$(function () {
|
|
id = $('#id').val();
|
|
// event click for radio box
|
|
$(".questions").click(function (event) {
|
|
var total = 0;
|
|
if (event.target.type !== "radio") {
|
|
$(":radio", this).trigger("click");
|
|
}
|
|
});
|
|
|
|
// sum points
|
|
$(".dynamic-question-radio").click(function (event) {
|
|
var total = 0;
|
|
$('.score :checked').each(function (index, element) {
|
|
total += parseInt($(element).val());
|
|
})
|
|
$('#total_points').val(total)
|
|
});
|
|
|
|
// init date now
|
|
$("#date").val(moment().format('jYYYY/jMM/jDD'))
|
|
|
|
//realtime validation selects
|
|
$('input[type="radio"]').on('change', function () {
|
|
formValid()
|
|
})
|
|
|
|
$('input[type="text"]').on('input', function (event) {
|
|
formValid()
|
|
})
|
|
|
|
// validation
|
|
function formValid() {
|
|
var isRequire = true;
|
|
|
|
|
|
$('.dynamic-question').each(function (index, question) {
|
|
if (typeof $('input[name="question' + $(question).data('idQuestion') + '"]:checked').val() === "undefined")
|
|
isRequire = false
|
|
})
|
|
|
|
if ($('input[name="fullname"]').val() == '')
|
|
isRequire = false
|
|
|
|
if (isRequire) {
|
|
$('#send').removeAttr('disabled');
|
|
$('#send').text('ارسال')
|
|
$('#send').removeClass('btn-warning');
|
|
$('#send').addClass('btn-primary');
|
|
} else {
|
|
$('#send').attr('disabled', 'disabled');
|
|
$('#send').text('فرم را پر کنید')
|
|
$('#send').addClass('btn-warning');
|
|
$('#send').removeClass('btn-primary');
|
|
}
|
|
}
|
|
|
|
// send all data
|
|
$("#send").on("click", function () {
|
|
$('#send').attr('disabled', 'disabled');
|
|
$('#send').text('در حال ارسال');
|
|
|
|
var isRequire = true;
|
|
var data = new FormData();
|
|
var questionsArr = [];
|
|
|
|
$('.dynamic-question').each(function (index, question) {
|
|
if (typeof $('input[name="question' + $(question).data('idQuestion') + '"]:checked').val() !== "undefined") {
|
|
const question_temp = {
|
|
q_id: $(question).data('idQuestion'),
|
|
q_fa: $(question).find('.dynamic-question-title').text(),
|
|
score: $('input[name="question' + $(question).data('idQuestion') + '"]:checked').val(),
|
|
type: $('input[name="question' + $(question).data('idQuestion') + '"]:checked').data('type')
|
|
};
|
|
questionsArr[index] = question_temp
|
|
} else
|
|
isRequire = false
|
|
})
|
|
|
|
if (questionsArr)
|
|
data.append('questions', JSON.stringify(questionsArr));
|
|
|
|
if ($('input[name="fullname"]').val() != '')
|
|
data.append("fullname", $('input[name="fullname"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
data.append("desc", $('textarea[name="description"]').val());
|
|
|
|
if (isRequire) {
|
|
Swal.fire({
|
|
icon: "info",
|
|
title: "امتیازدهی",
|
|
text: "اطلاعات برای ثبت امتیازدهی ارسال شود؟",
|
|
showDenyButton: true,
|
|
showCancelButton: false,
|
|
denyButtonText: 'خیر',
|
|
confirmButtonText: "بله، ارسال کن",
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.ajax({
|
|
url: url + "webapi/randd/voting/" + id + "/store",
|
|
type: "POST",
|
|
headers: {
|
|
accept: "application/json",
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
data: data,
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
success: function (res) {
|
|
if (res.endVoting) {
|
|
$('#vote-content').remove()
|
|
$('#msgError').text(res.message)
|
|
$('#expire-modal').modal({
|
|
backdrop: "static"
|
|
})
|
|
} else {
|
|
$('#send').removeClass('btn-primary');
|
|
$('#send').addClass('btn-success');
|
|
$('#send').text('ارسال شد');
|
|
$('#msg').removeClass('d-none')
|
|
var count = 5;
|
|
var x = setInterval(function () {
|
|
count--;
|
|
if (count < 0) {
|
|
clearInterval(x);
|
|
window.location = url + 'RandDSecond';
|
|
} else {
|
|
document.getElementById("msg").innerHTML = `امتیاز شما با موفقیت ثبت شد. تا ${count} ثانیه به صفحه قبل باز میگردید.`;
|
|
}
|
|
}, 1000)
|
|
}
|
|
},
|
|
error: function (xhr) {
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا سرور",
|
|
text: "مشکل در ثبت اطلاعات",
|
|
showCancelButton: true,
|
|
showConfirmButton: false,
|
|
cancelButtonText: "بستن",
|
|
})
|
|
$('#send').removeAttr('disabled');
|
|
$('#send').text('ارسال');
|
|
},
|
|
});
|
|
} else if (result.isDenied) {
|
|
$('#send').removeAttr('disabled');
|
|
$('#send').text('ارسال');
|
|
}
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "لطفا اطلاعات صحیح وارد نمایید",
|
|
showConfirmButton: false,
|
|
cancelButtonText: "بستن",
|
|
})
|
|
$('#send').removeAttr('disabled');
|
|
$('#send').text('ارسال');
|
|
}
|
|
})
|
|
}) |