Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

265 lines
10KB

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