This commit is contained in:
sayliraut
2024-08-16 12:58:45 +05:30
parent 7083252e5c
commit f310428fd6
4 changed files with 216 additions and 223 deletions

View File

@@ -0,0 +1,107 @@
$(document).ready(function () {
// Initialize Quill editors
var quillTitle = new Quill('#referral-rules-quill-edit-title', {
theme: 'snow'
});
var quillMessage = new Quill('#referral-rules-quill-edit-message', {
theme: 'snow'
});
var quillReferral = new Quill('#referral-rules-quill-edit-what_is_referral', {
theme: 'snow'
});
// Set initial content for Quill editors
quillTitle.clipboard.dangerouslyPasteHTML($('#stored-title-message').val());
quillMessage.clipboard.dangerouslyPasteHTML($('#stored-message-message').val());
quillReferral.clipboard.dangerouslyPasteHTML($('#stored-referral-message').val());
// Form submission logic
$('#referral_update_rules').on("click", function (e) {
e.preventDefault();
$('#referral_rules_form').validate({
ignore: [],
debug: false,
rules: {
how_it_works: {
required: true,
minlength: 10,
},
rules: {
required: true,
minlength: 10,
},
what_is_referral: {
required: true,
minlength: 10,
}
},
messages: {
how_it_works: {
required: "Please enter How it works",
minlength: "Please enter at least 10 characters"
},
rules: {
required: "Please enter the Rules",
minlength: "Please enter at least 10 characters"
},
what_is_referral: {
required: "Please enter What is referral",
minlength: "Please enter at least 10 characters"
}
},
errorClass: 'error-message',
submitHandler: function (form) {
function base64Encode(str) {
return btoa(unescape(encodeURIComponent(str)));
}
// Encode the content from Quill editors
var encodedTitle = base64Encode(quillTitle.root.innerHTML);
var encodedMessage = base64Encode(quillMessage.root.innerHTML);
var encodedReferral = base64Encode(quillReferral.root.innerHTML);
// Update hidden inputs with the encoded content
$('input[name="how_it_works"]').val(encodedTitle);
$('input[name="rules"]').val(encodedMessage);
$('input[name="what_is_referral"]').val(encodedReferral);
let base_url = url_path;
var formData = new FormData(form);
$.ajax({
url: base_url + '/update_referral_rules',
type: 'POST',
data: formData,
processData: false,
contentType: false,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr(
'content')
},
success: function (response) {
if (response.status == 200) {
toastr.success(
'Rules Data Updated Successfully');
setTimeout(function () {
window.location.href =
base_url + '/manage_referral_rules';
}, 1000);
} else {
toastr.error("Something went wrong");
}
},
error: function (xhr, status, error) {
console.error('AJAX Error: ', status, error);
toastr.error(
"An error occurred while updating the rules"
);
}
});
}
});
// Trigger form validation
$('#referral_rules_form').submit();
});
});

View File

@@ -0,0 +1,106 @@
$(document).ready(function() {
// Initialize Quill editors
var quillTitle = new Quill('#rules-quill-edit-title', {
theme: 'snow'
});
var quillMessage = new Quill('#rules-quill-edit-message', {
theme: 'snow'
});
// Set initial content for Quill editors
var storedTitle = $('textarea[name="whats_inside"]').val();
quillTitle.clipboard.dangerouslyPasteHTML(storedTitle);
var storedMessage = $('textarea[name="rules"]').val();
quillMessage.clipboard.dangerouslyPasteHTML(storedMessage);
// Form submission logic
$('#update_rules').on("click", function(e) {
e.preventDefault();
$.validator.addMethod("quillNotEmpty", function(value, element) {
var editorData = quillTitle.root.innerHTML;
return editorData.trim().length > 0;
}, "Please enter What's Inside");
$.validator.addMethod("quillNotEmptyMessage", function(value, element) {
var editorData = quillMessage.root.innerHTML;
return editorData.trim().length > 0;
}, "Please enter Rules");
$('#rules_form').validate({
ignore: [],
debug: false,
rules: {
whats_inside: {
required: true,
quillNotEmpty: true
},
rules: {
required: true,
quillNotEmptyMessage: true
}
},
messages: {
whats_inside: {
required: "Please enter What's Inside"
},
rules: {
required: "Please enter Rules"
}
},
errorClass: 'error-message',
submitHandler: function(form) {
function base64Encode(str) {
return btoa(unescape(encodeURIComponent(str)));
}
var article_des_title = base64Encode(quillTitle.root.innerHTML);
var article_des_message = base64Encode(quillMessage.root.innerHTML);
// Update the hidden textareas with encoded content
$('textarea[name="whats_inside"]').val(article_des_title);
$('textarea[name="rules"]').val(article_des_message);
let base_url = url_path;
var formData = new FormData(form);
$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr(
"content"),
},
});
$.ajax({
url: base_url + '/update_rules',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
if (response.status == 200) {
toastr.success(
'Rules Data Updated Successfully');
setTimeout(function() {
window.location.href =
base_url + '/manage_rules';
}, 1000);
} else {
toastr.error("Something went wrong");
}
},
error: function(response) {
toastr.error(
"An error occurred while updating the rules"
);
}
});
}
});
// Trigger form validation
$('#rules_form').submit();
});
});

View File

@@ -41,8 +41,7 @@
<div class="tab-pane fade show active" id="home-tab-pane" role="tabpanel"
aria-labelledby="home-tab" tabindex="0">
<div class="row">
<form id="referral_rules_form" method="POST"
action="{{ route('update_referral_rules') }}">
<form id="referral_rules_form" method="POST">
@csrf
<meta name="csrf-token" content="{{ csrf_token() }}">
@@ -100,111 +99,5 @@
@endsection
@section('section_script')
<script>
$(document).ready(function() {
// Initialize Quill editors
var quillTitle = new Quill('#referral-rules-quill-edit-title', {
theme: 'snow'
});
var quillMessage = new Quill('#referral-rules-quill-edit-message', {
theme: 'snow'
});
var quillReferral = new Quill('#referral-rules-quill-edit-what_is_referral', {
theme: 'snow'
});
// Set initial content for Quill editors
quillTitle.clipboard.dangerouslyPasteHTML($('#stored-title-message').val());
quillMessage.clipboard.dangerouslyPasteHTML($('#stored-message-message').val());
quillReferral.clipboard.dangerouslyPasteHTML($('#stored-referral-message').val());
// Form submission logic
$('#referral_update_rules').on("click", function(e) {
e.preventDefault();
$('#referral_rules_form').validate({
ignore: [],
debug: false,
rules: {
how_it_works: {
required: true,
minlength: 10,
},
rules: {
required: true,
minlength: 10,
},
what_is_referral: {
required: true,
minlength: 10,
}
},
messages: {
how_it_works: {
required: "Please enter How it works",
minlength: "Please enter at least 10 characters"
},
rules: {
required: "Please enter the Rules",
minlength: "Please enter at least 10 characters"
},
what_is_referral: {
required: "Please enter What is referral",
minlength: "Please enter at least 10 characters"
}
},
errorClass: 'error-message',
submitHandler: function(form) {
function base64Encode(str) {
return btoa(unescape(encodeURIComponent(str)));
}
// Encode the content from Quill editors
var encodedTitle = base64Encode(quillTitle.root.innerHTML);
var encodedMessage = base64Encode(quillMessage.root.innerHTML);
var encodedReferral = base64Encode(quillReferral.root.innerHTML);
// Update hidden inputs with the encoded content
$('input[name="how_it_works"]').val(encodedTitle);
$('input[name="rules"]').val(encodedMessage);
$('input[name="what_is_referral"]').val(encodedReferral);
var formData = new FormData(form);
$.ajax({
url: form.action,
type: 'POST',
data: formData,
processData: false,
contentType: false,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr(
'content')
},
success: function(response) {
if (response.status == 200) {
toastr.success(
'Rules Data Updated Successfully');
setTimeout(function() {
window.location.href =
"{{ route('manage_referral') }}";
}, 1000);
} else {
toastr.error("Something went wrong");
}
},
error: function(xhr, status, error) {
console.error('AJAX Error: ', status, error);
toastr.error(
"An error occurred while updating the rules"
);
}
});
}
});
// Trigger form validation
$('#referral_rules_form').submit();
});
});
</script>
<script src="{{ asset('public/assets/js/manage_Referral/edit.js') }}"></script>
@endsection

View File

@@ -89,118 +89,5 @@
</div>
@endsection
@section('section_script')
<!-- <script>
var quill = new Quill('#terms-quill-edit', {
theme: 'snow'
});
</script> -->
{{-- <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"></script>
<script src="{{ asset('public/assets/js/admin/manage_cms/manage_terms_cond/manage_terms_condition.js')}}"></script> --}}
<script>
$(document).ready(function() {
// Initialize Quill editors
var quillTitle = new Quill('#rules-quill-edit-title', {
theme: 'snow'
});
var quillMessage = new Quill('#rules-quill-edit-message', {
theme: 'snow'
});
// Set initial content for Quill editors
var storedTitle = $('textarea[name="whats_inside"]').val();
quillTitle.clipboard.dangerouslyPasteHTML(storedTitle);
var storedMessage = $('textarea[name="rules"]').val();
quillMessage.clipboard.dangerouslyPasteHTML(storedMessage);
// Form submission logic
$('#update_rules').on("click", function(e) {
e.preventDefault();
$.validator.addMethod("quillNotEmpty", function(value, element) {
var editorData = quillTitle.root.innerHTML;
return editorData.trim().length > 0;
}, "Please enter What's Inside");
$.validator.addMethod("quillNotEmptyMessage", function(value, element) {
var editorData = quillMessage.root.innerHTML;
return editorData.trim().length > 0;
}, "Please enter Rules");
$('#rules_form').validate({
ignore: [],
debug: false,
rules: {
whats_inside: {
required: true,
quillNotEmpty: true
},
rules: {
required: true,
quillNotEmptyMessage: true
}
},
messages: {
whats_inside: {
required: "Please enter What's Inside"
},
rules: {
required: "Please enter Rules"
}
},
errorClass: 'error-message',
submitHandler: function(form) {
function base64Encode(str) {
return btoa(unescape(encodeURIComponent(str)));
}
var article_des_title = base64Encode(quillTitle.root.innerHTML);
var article_des_message = base64Encode(quillMessage.root.innerHTML);
// Update the hidden textareas with encoded content
$('textarea[name="whats_inside"]').val(article_des_title);
$('textarea[name="rules"]').val(article_des_message);
var formData = new FormData(form);
$.ajaxSetup({
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr(
"content"),
},
});
$.ajax({
url: '{{ url('/update_rules') }}',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
if (response.status == 200) {
toastr.success(
'Rules Data Updated Successfully');
setTimeout(function() {
window.location.href =
'{{ url('/manage_rules') }}';
}, 1000);
} else {
toastr.error("Something went wrong");
}
},
error: function(response) {
toastr.error(
"An error occurred while updating the rules"
);
}
});
}
});
// Trigger form validation
$('#rules_form').submit();
});
});
</script>
<script src="{{ asset('public/assets/js/redemption_rule/edit.js') }}"></script>
@endsection