Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * App eCommerce Add Product Script
  3. */
  4. 'use strict';
  5. //Javascript to handle the e-commerce product add page
  6. (function () {
  7. // Comment editor
  8. const commentEditor = document.querySelector('.comment-editor');
  9. if (commentEditor) {
  10. new Quill(commentEditor, {
  11. modules: {
  12. toolbar: '.comment-toolbar'
  13. },
  14. placeholder: 'Product Description',
  15. theme: 'snow'
  16. });
  17. }
  18. // previewTemplate: Updated Dropzone default previewTemplate
  19. // ! Don't change it unless you really know what you are doing
  20. const previewTemplate = `<div class="dz-preview dz-file-preview">
  21. <div class="dz-details">
  22. <div class="dz-thumbnail">
  23. <img data-dz-thumbnail>
  24. <span class="dz-nopreview">No preview</span>
  25. <div class="dz-success-mark"></div>
  26. <div class="dz-error-mark"></div>
  27. <div class="dz-error-message"><span data-dz-errormessage></span></div>
  28. <div class="progress">
  29. <div class="progress-bar progress-bar-primary" role="progressbar" aria-valuemin="0" aria-valuemax="100" data-dz-uploadprogress></div>
  30. </div>
  31. </div>
  32. <div class="dz-filename" data-dz-name></div>
  33. <div class="dz-size" data-dz-size></div>
  34. </div>
  35. </div>`;
  36. // ? Start your code from here
  37. // Basic Dropzone
  38. const dropzoneBasic = document.querySelector('#dropzone-basic');
  39. if (dropzoneBasic) {
  40. const myDropzone = new Dropzone(dropzoneBasic, {
  41. previewTemplate: previewTemplate,
  42. parallelUploads: 1,
  43. maxFilesize: 5,
  44. acceptedFiles: '.jpg,.jpeg,.png,.gif',
  45. addRemoveLinks: true,
  46. maxFiles: 1
  47. });
  48. }
  49. // Basic Tags
  50. const tagifyBasicEl = document.querySelector('#ecommerce-product-tags');
  51. const TagifyBasic = new Tagify(tagifyBasicEl);
  52. // Flatpickr
  53. // Datepicker
  54. const date = new Date();
  55. const productDate = document.querySelector('.product-date');
  56. if (productDate) {
  57. productDate.flatpickr({
  58. monthSelectorType: 'static',
  59. defaultDate: date
  60. });
  61. }
  62. })();
  63. //Jquery to handle the e-commerce product add page
  64. $(function () {
  65. // Select2
  66. var select2 = $('.select2');
  67. if (select2.length) {
  68. select2.each(function () {
  69. var $this = $(this);
  70. $this.wrap('<div class="position-relative"></div>').select2({
  71. dropdownParent: $this.parent(),
  72. placeholder: $this.data('placeholder') // for dynamic placeholder
  73. });
  74. });
  75. }
  76. var formRepeater = $('.form-repeater');
  77. // Form Repeater
  78. // ! Using jQuery each loop to add dynamic id and class for inputs. You may need to improve it based on form fields.
  79. // -----------------------------------------------------------------------------------------------------------------
  80. if (formRepeater.length) {
  81. var row = 2;
  82. var col = 1;
  83. formRepeater.on('submit', function (e) {
  84. e.preventDefault();
  85. });
  86. formRepeater.repeater({
  87. show: function () {
  88. var fromControl = $(this).find('.form-control, .form-select');
  89. var formLabel = $(this).find('.form-label');
  90. fromControl.each(function (i) {
  91. var id = 'form-repeater-' + row + '-' + col;
  92. $(fromControl[i]).attr('id', id);
  93. $(formLabel[i]).attr('for', id);
  94. col++;
  95. });
  96. row++;
  97. $(this).slideDown();
  98. $('.select2-container').remove();
  99. $('.select2.form-select').select2({
  100. placeholder: 'Placeholder text'
  101. });
  102. $('.select2-container').css('width', '100%');
  103. $('.form-repeater:first .form-select').select2({
  104. dropdownParent: $(this).parent(),
  105. placeholder: 'Placeholder text'
  106. });
  107. $('.position-relative .select2').each(function () {
  108. $(this).select2({
  109. dropdownParent: $(this).closest('.position-relative')
  110. });
  111. });
  112. }
  113. });
  114. }
  115. });