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