first commit

This commit is contained in:
2025-04-02 22:15:22 +03:00
commit f17d62c9e5
9 changed files with 765 additions and 0 deletions

View File

@@ -0,0 +1,132 @@
<div class="b2b-group-switch">
{if $show_switch}
{* <p>{l s='Switch to:' mod='b2bpayments'}</p> *}
<label class="switch">
<input type="checkbox" id="b2b-switch" {if $current_group_is_postpaid}checked{/if}>
<span class="slider round"></span>
</label>
{if $current_group_is_postpaid}
{l s='Postpaid' d='Modules.B2bpayments.ShopSwitch'}
{else}
{l s='Prepaid' d='Modules.B2bpayments.ShopSwitch'}
{/if}
{/if}
</div>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
const b2bSwitch = document.getElementById('b2b-switch');
if (b2bSwitch) {
b2bSwitch.addEventListener('change', function() {
const xhr = new XMLHttpRequest();
xhr.open('POST', '{$switch_url}');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // Required for POST requests
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) {
try {
const response = JSON.parse(xhr.responseText);
if (response.success) {
location.reload(); // Refresh the page
} else {
alert('{$error_message|escape:'javascript'}'); // Use the error message, escaping it
}
} catch (e) {
console.error('JSON Parsing Error:', e);
alert('An error occurred while processing the response. Please try again.');
}
} else {
console.error('HTTP Error:', xhr.status, xhr.statusText);
alert('An error occurred while switching groups. Please try again.');
}
};
xhr.onerror = function() {
console.error('Request failed');
alert('An error occurred while switching groups. Please try again.');
};
const params = 'ajax=true&action=switchGroup'; // Build the query string
xhr.send(params);
});
} else {
console.warn('b2b-switch element not found.'); // Log a warning if the switch is not present
}
});
</script>
<style>
.b2b-group-switch {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.b2b-group-switch p {
margin-right: 10px;
}
/* The switch - the box around the slider */
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>