168 lines
8.2 KiB
PHP
168 lines
8.2 KiB
PHP
@extends('backend.template')
|
|
@section('content')
|
|
<!-- start page title -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
|
|
<h4 class="mb-sm-0">Add Banner</h4>
|
|
|
|
|
|
<div class="page-title-right">
|
|
<ol class="breadcrumb m-0">
|
|
<li class="breadcrumb-item"><a href="javascript: void(0);">Dashboards</a></li>
|
|
<li class="breadcrumb-item active">Add Banner</li>
|
|
</ol>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- end page title -->
|
|
<form action="{{ route('banner.store') }}" id="storeCustomForm" method="POST">
|
|
@csrf
|
|
<div class="row">
|
|
<div class="col-xl-9">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="col-lg-12">{{ createText('title', 'title', 'Title') }}
|
|
</div>
|
|
<div class="border mt-3 border-dashed"></div>
|
|
<div class="col-lg-12 pb-2">{{ createTextarea('text', 'text ckeditor-classic', 'Description') }}
|
|
</div>
|
|
<div class="border mt-3 border-dashed"></div>
|
|
<div class="card mt-3">
|
|
<h4>Custom Details</h4>
|
|
<div id="repeater-container"></div>
|
|
<div id="add-button-container"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php createButton('btn-primary btn-store', '', 'Submit'); ?>
|
|
<?php createButton('btn-danger btn-cancel', '', 'Cancel', route('banner.index')); ?>
|
|
</div>
|
|
<div class="col-xl-3">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h4 class="card-title mb-0">
|
|
Images
|
|
</h4>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="col-lg-12 pb-2">{{ createImageInput('cover', 'Cover Photo') }}
|
|
</div>
|
|
<div class="border mb-3 border-dashed"></div>
|
|
<div class="col-lg-12 pb-2">{{ createImageInput('image_thumb', 'Image Thumb') }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php createButton('btn-primary btn-store', '', 'Submit'); ?>
|
|
<?php createButton('btn-danger btn-cancel', '', 'Cancel', route('banner.index')); ?>
|
|
</div>
|
|
</div>
|
|
|
|
</form>
|
|
@endsection
|
|
@push('js')
|
|
<script>
|
|
createFormFieldsRepeater();
|
|
// addFormField();
|
|
// const addButtonContainer = document.getElementById('add-button-container');
|
|
function createFormFieldsRepeater() {
|
|
const repeaterContainer = document.getElementById('repeater-container');
|
|
const addButtonContainer = document.getElementById('add-button-container');
|
|
// Add button
|
|
const addButton = document.createElement('button');
|
|
addButton.textContent = 'Add Fields';
|
|
addButton.addEventListener('click', addFormField);
|
|
addButtonContainer.appendChild(addButton);
|
|
// Repeater fields
|
|
let fieldCount = 0;
|
|
|
|
function addFormField() {
|
|
event.preventDefault();
|
|
fieldCount++;
|
|
const fieldContainer = document.createElement('div');
|
|
fieldContainer.classList.add('form-field');
|
|
fieldContainer.classList.add('row');
|
|
|
|
const fieldInputContainer = document.createElement('div');
|
|
fieldInputContainer.classList.add("col");
|
|
fieldInputContainer.innerHTML = (
|
|
"<label for=\"fieldName\" class=\"form-label col-form-label\"> Icon </label>");
|
|
const fieldTitleInput = document.createElement('input');
|
|
fieldTitleInput.setAttribute('type', 'text');
|
|
fieldTitleInput.setAttribute('name', `fieldTitles[]`);
|
|
fieldTitleInput.setAttribute('placeholder', 'Icon');
|
|
fieldInputContainer.classList.add('col');
|
|
fieldTitleInput.classList.add('form-control');
|
|
fieldInputContainer.appendChild(fieldTitleInput);
|
|
fieldContainer.appendChild(fieldInputContainer);
|
|
|
|
const fieldInputContainer2 = document.createElement('div');
|
|
fieldInputContainer2.classList.add("col");
|
|
fieldInputContainer2.innerHTML = (
|
|
"<label for=\"fieldName\" class=\"form-label col-form-label\"> Title </label>");
|
|
const fieldHeaderInput = document.createElement('input');
|
|
fieldHeaderInput.setAttribute('type', 'text');
|
|
fieldHeaderInput.setAttribute('name', `fieldHeader[]`);
|
|
fieldHeaderInput.setAttribute('placeholder', 'Title')
|
|
fieldHeaderInput.classList.add('form-control');
|
|
fieldInputContainer2.appendChild(fieldHeaderInput);
|
|
fieldContainer.appendChild(fieldInputContainer2);
|
|
|
|
const fieldInputContainer3 = document.createElement('div');
|
|
fieldInputContainer3.classList.add("col");
|
|
fieldInputContainer3.innerHTML = (
|
|
"<label for=\"fieldName\" class=\"form-label col-form-label\"> Description </label>");
|
|
const fieldDescriptionsInput = document.createElement('input');
|
|
fieldDescriptionsInput.setAttribute('type', 'text');
|
|
fieldDescriptionsInput.setAttribute('name', `fieldDescriptions[]`);
|
|
fieldDescriptionsInput.setAttribute('placeholder', 'Description')
|
|
fieldDescriptionsInput.classList.add('form-control');
|
|
fieldInputContainer3.appendChild(fieldDescriptionsInput);
|
|
fieldContainer.appendChild(fieldInputContainer3);
|
|
|
|
// Remove button
|
|
const fieldInputContainer4 = document.createElement('div');
|
|
fieldInputContainer4.classList.add("col");
|
|
fieldInputContainer4.innerHTML = (
|
|
"<label for=\"fieldName\" class=\"form-label col-form-label\">   <span class=\"row-selector-handle\">☰</span></label>"
|
|
);
|
|
const removeButton = document.createElement('button');
|
|
removeButton.textContent = 'Remove Field';
|
|
removeButton.classList.add('btn');
|
|
removeButton.classList.add('btn-danger');
|
|
removeButton.classList.add('col');
|
|
removeButton.classList.add('form-control');
|
|
removeButton.addEventListener('click', () => {
|
|
repeaterContainer.removeChild(fieldContainer);
|
|
});
|
|
fieldInputContainer4.appendChild(removeButton);
|
|
fieldContainer.appendChild(fieldInputContainer4);
|
|
repeaterContainer.appendChild(fieldContainer);
|
|
makeSortable();
|
|
}
|
|
}
|
|
</script>
|
|
<script>
|
|
function makeSortable() {
|
|
$(document).ready(function() {
|
|
// Make the repeater-container sortable
|
|
$("#repeater-container").sortable({
|
|
axis: "y", // Allow sorting only vertically
|
|
handle: ".row-selector-handle", // Define the handle element for dragging (form-field class)
|
|
containment: "parent", // Keep the sorting within the repeater-container
|
|
});
|
|
// Disable text selection while dragging to avoid text highlighting
|
|
$("#repeater-container").disableSelection();
|
|
});
|
|
}
|
|
</script>
|
|
<!-- jQuery library -->
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<!-- jQuery UI Sortable library -->
|
|
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
|
|
<!-- Add the CSS for jQuery UI Sortable (optional, but recommended for styling) -->
|
|
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
|
|
@endpush
|