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.

58 lines
1.7KB

  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. $('.lc-sortable-products tr.lc-draggable').each(function (index, li) {
  23. $(li).find('.field-position').val(index);
  24. });
  25. }
  26. function initLcSortableList() {
  27. $('.lc-sortable tbody').sortable({
  28. placeholder: "ui-state-highlight"
  29. });
  30. $('.lc-sortable tbody').on("sortupdate", function (event, ui) {
  31. prototype = $('#form_entities').data('prototype');
  32. $('.lc-sortable tr.lc-draggable').each(function (index, li) {
  33. // instead be a number based on how many items we have
  34. var newForm = prototype.replace(/__name__/g, index);
  35. // Replace '__name__' in the prototype's HTML to
  36. $(li).find('div:last-child').remove();
  37. $(li).append(newForm);
  38. $(li).find('#form_entities_' + index + '_id').val($(li).data('id'));
  39. if ($('.lc-sortable').data('parent-position') !=='') val = $('.lc-sortable').data('parent-position') + '_' + index
  40. else val = index;
  41. log($(li).find('#form_entities_' + index + '_position'));
  42. $(li).find('#form_entities_' + index + '_position').val(val);
  43. });
  44. });
  45. }