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.

256 lines
10.0KB

  1. jQuery(document).ready(function () {
  2. custom_switch_merchants();
  3. initLcSortableList();
  4. initLcCkEditor();
  5. initLcSortableProductsList();
  6. initLcSortableList();
  7. initDataTable();
  8. initAdminLtePlugin();
  9. // generateNotice('success', '<i class="fa fa-store"></i> NICHE');
  10. });
  11. function initLcNoty() {
  12. $('.lc-noty').each(function () {
  13. generateNotice($(this).data('type'), $(this).html());
  14. });
  15. }
  16. function initAdminLtePlugin(){
  17. $('[data-toggle="tooltip"]').tooltip()
  18. if($('.select2').length) {
  19. $('.select2').select2({
  20. /*theme: 'bootstrap4'*/
  21. })
  22. }
  23. if($('.select2-no-search').length) {
  24. $('.select2-no-search').select2({
  25. minimumResultsForSearch: Infinity
  26. });
  27. }
  28. }
  29. function custom_switch_merchants() {
  30. $('#switch-merchant select').change(function () {
  31. $('#switch-merchant form').submit();
  32. });
  33. }
  34. function initLcSortableProductsList() {
  35. if ($('.lc-sortable-products').length > 0) {
  36. $('.lc-sortable-products tbody').sortable({
  37. placeholder: "ui-state-highlight"
  38. });
  39. $('.lc-sortable-products tbody').on("sortupdate", function (event, ui) {
  40. updateSortableProducts();
  41. });
  42. }
  43. }
  44. function updateSortableProducts() {
  45. if ($('.lc-sortable-products').length > 0) {
  46. $('.lc-sortable-products tr.lc-draggable').each(function (index, li) {
  47. $(li).find('.field-position').val(index);
  48. });
  49. }
  50. }
  51. function initLcSortableList() {
  52. if ($('.lc-sortable').length > 0) {
  53. $('.lc-sortable tbody').sortable({
  54. placeholder: "ui-state-highlight"
  55. });
  56. $('.lc-sortable tbody').on("sortupdate", function (event, ui) {
  57. prototype = $('#form_entities').data('prototype');
  58. $('.lc-sortable tr.lc-draggable').each(function (index, li) {
  59. // instead be a number based on how many items we have
  60. var newForm = prototype.replace(/__name__/g, index);
  61. // Replace '__name__' in the prototype's HTML to
  62. $(li).find('div:last-child').remove();
  63. $(li).append(newForm);
  64. $(li).find('#form_entities_' + index + '_id').val($(li).data('id'));
  65. if ($('.lc-sortable').data('parent-position') !== '') val = $('.lc-sortable').data('parent-position') + '_' + index
  66. else val = index;
  67. log($(li).find('#form_entities_' + index + '_position'));
  68. $(li).find('#form_entities_' + index + '_position').val(val);
  69. });
  70. });
  71. }
  72. }
  73. function initDataTable() {
  74. $(".checkbox-switch input").each(function(){
  75. $(this).bootstrapSwitch('state', $(this).prop('checked'));
  76. });
  77. if ($(".table.datatable-simple").length > 0) {
  78. //$(".table.datatable-simple thead tr").clone(true).appendTo( '.table.datatable-simple tfoot' );
  79. $(".table.datatable-simple thead tr").clone(true).appendTo('.table.datatable-simple thead');
  80. $(".table.datatable-simple thead tr:eq(1) th").each(function (i) {
  81. if ($(this).data('searchable') == "input") {
  82. var title = $(this).text();
  83. var cssClass = '';
  84. if($(this).text().trim().toLowerCase() =='id')cssClass = 'small'
  85. $(this).html('<input type="text" placeholder="" class="datatable-field-search '+cssClass+'" />');
  86. $('input', this).on('keyup change', function () {
  87. if(this.value === "") {
  88. $('.table.datatable-simple thead tr:eq(0) th:eq(' + i + ')').removeClass('filtered')
  89. }else{
  90. $('.table.datatable-simple thead tr:eq(0) th:eq('+i+')').addClass('filtered')
  91. }
  92. if (table.column(i).search() !== this.value) {
  93. table
  94. .column(i)
  95. .search(this.value)
  96. .draw();
  97. var searchVal = this.value;
  98. var body = $( table.table().body() );
  99. body.unhighlight();
  100. body.highlight(searchVal);
  101. }
  102. });
  103. } else if ($(this).data('searchable') == 'select' ){
  104. $(this).html('<select class="list"><option value="all">Tout afficher</option></select>'); //LC_TRAD
  105. } else if ($(this).data('searchable') == 'select-text') {
  106. $(this).html('<select class="list-text"><option value="all">Tout afficher</option></select>'); //LC_TRAD
  107. } else if ($(this).data('searchable') == 'toggle') {
  108. $(this).html('<select class="toggle">' +
  109. '<option value="all">Tout afficher</option>' +
  110. '<option value="checked">Oui</option>' +
  111. '<option value="unchecked"> Non</option>' +
  112. '</select>'); //LC_TRAD
  113. } else {
  114. $(this).html('')
  115. }
  116. });
  117. var table = $(".table.datatable-simple").DataTable({
  118. orderCellsTop: true,
  119. fixedHeader: {
  120. header: true,
  121. headerOffset: $('.main-header').outerHeight(),
  122. },
  123. paging: true,
  124. //responsive: true,
  125. initComplete: function () {
  126. this.api().columns().every( function (i) {
  127. var column = this;
  128. var select = false;
  129. toggle = $('.table.datatable-simple thead tr:eq(1) th:eq('+i+') select.toggle')
  130. if(toggle.length) {
  131. toggle.select2({
  132. 'placeholder': 'Filtrer'//LC_TRAD['search']
  133. });
  134. toggle.on( 'change', function () {
  135. var val = $.fn.dataTable.util.escapeRegex($(this).val());
  136. if(val=="all"){
  137. column.search('').draw();
  138. }else {
  139. var niche = table.column('2');
  140. log(column.cell('4').data());
  141. /*
  142. val = "bootstrap-switch-on";
  143. column.data().each(function(d){
  144. log(d)
  145. });
  146. //filter in column 5, with an regex, no smart filtering, not case sensitive
  147. column.search( val ? '^'+val+'$' : '', true, false ).draw();*/
  148. }
  149. } );
  150. }
  151. if($('.table.datatable-simple thead tr:eq(1) th:eq('+i+') select.list-text').length) {
  152. select = $('.table.datatable-simple thead tr:eq(1) th:eq(' + i + ') select.list-text');
  153. }
  154. if(select.length) {
  155. column.data().unique().sort().each(function (d, j) {
  156. values = d.split('\n');
  157. for(k=0; k< values.length; k++) {
  158. val = values[k];
  159. select.append('<option value="' + val.trim() + '">' + val.trim() + '</option>')
  160. }
  161. });
  162. }
  163. if(!select) select = $('.table.datatable-simple thead tr:eq(1) th:eq('+i+') select.list')
  164. if(select.length) {
  165. column.data().unique().sort().each(function (d, j) {
  166. $(d).each(function (k, val) {
  167. select.append('<option value="' + $(val).text().trim() + '">' + $(val).text().trim() + '</option>')
  168. });
  169. });
  170. select.select2({
  171. 'placeholder': 'Filtrer'//LC_TRAD['search']
  172. });
  173. select.on( 'change', function () {
  174. var val = $(this).val();
  175. if(val=="all"){
  176. $('.table.datatable-simple thead tr:eq(0) th:eq('+i+')').removeClass('filtered')
  177. column.search('').draw();
  178. }else {
  179. log($(this).val());
  180. $('.table.datatable-simple thead tr:eq(0) th:eq('+i+')').addClass('filtered')
  181. column.search(val, false).draw();
  182. }
  183. } );
  184. }
  185. } );
  186. },
  187. language: {
  188. "sEmptyTable": "Aucune donnée disponible dans le tableau",
  189. "sInfo": "Affichage de l'élément _START_ à _END_ sur _TOTAL_ éléments",
  190. "sInfoEmpty": "Affichage de l'élément 0 à 0 sur 0 élément",
  191. "sInfoFiltered": "(filtré à partir de _MAX_ éléments au total)",
  192. "sInfoPostFix": "",
  193. "sInfoThousands": ",",
  194. "sLengthMenu": "Afficher _MENU_ éléments",
  195. "sLoadingRecords": "Chargement...",
  196. "sProcessing": "Traitement...",
  197. "sSearch": "Rechercher :",
  198. "sZeroRecords": "Aucun élément correspondant trouvé",
  199. "oPaginate": {
  200. "sFirst": "Premier",
  201. "sLast": "Dernier",
  202. "sNext": "Suivant",
  203. "sPrevious": "Précédent"
  204. },
  205. "oAria": {
  206. "sSortAscending": ": activer pour trier la colonne par ordre croissant",
  207. "sSortDescending": ": activer pour trier la colonne par ordre décroissant"
  208. },
  209. "select": {
  210. "rows": {
  211. "_": "%d lignes sélectionnées",
  212. "0": "Aucune ligne sélectionnée",
  213. "1": "1 ligne sélectionnée"
  214. }
  215. }
  216. },
  217. });
  218. }
  219. }