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.

custom.js 1.7KB

4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. jQuery(document).ready(function () {
  2. custom_switch_merchants();
  3. initLcSortableList();
  4. initLcCkEditor();
  5. initLcSortableProductsList();
  6. initLcSortableList();
  7. });
  8. function custom_switch_merchants() {
  9. $('#switch-merchant select').change(function () {
  10. $('#switch-merchant form').submit();
  11. });
  12. }
  13. function initLcSortableProductsList(){
  14. $('.lc-sortable-products tbody').sortable({
  15. placeholder: "ui-state-highlight"
  16. });
  17. $('.lc-sortable-products tbody').on("sortupdate", function (event, ui) {
  18. updateSortableProducts();
  19. });
  20. }
  21. function updateSortableProducts(){
  22. log('update');
  23. $('.lc-sortable-products tr.lc-draggable').each(function (index, li) {
  24. $(li).find('.field-position').val(index);
  25. });
  26. }
  27. function initLcSortableList() {
  28. $('.lc-sortable tbody').sortable({
  29. placeholder: "ui-state-highlight"
  30. });
  31. $('.lc-sortable tbody').on("sortupdate", function (event, ui) {
  32. prototype = $('#form_entities').data('prototype');
  33. $('.lc-sortable tr.lc-draggable').each(function (index, li) {
  34. // instead be a number based on how many items we have
  35. var newForm = prototype.replace(/__name__/g, index);
  36. // Replace '__name__' in the prototype's HTML to
  37. $(li).find('div:last-child').remove();
  38. $(li).append(newForm);
  39. $(li).find('#form_entities_' + index + '_id').val($(li).data('id'));
  40. if ($('.lc-sortable').data('parent-position') !=='') val = $('.lc-sortable').data('parent-position') + '_' + index
  41. else val = index;
  42. log($(li).find('#form_entities_' + index + '_position'));
  43. $(li).find('#form_entities_' + index + '_position').val(val);
  44. });
  45. });
  46. }