zentaobiz.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. $(document).ready(function()
  2. {
  3. function saveOrders(orders)
  4. {
  5. $.post(createLink('doc','sortBookOrder'),
  6. {sort:orders},
  7. function(data)
  8. {
  9. if(data.result != "success")
  10. {
  11. bootbox.alert(data.message);
  12. }
  13. },'json');
  14. }
  15. function updateOrders(ele, parentOrder, orders)
  16. {
  17. var root = false;
  18. if(typeof ele === 'undefined')
  19. {
  20. ele = $('.books > dl, .books > .catalog > dl');
  21. root = true;
  22. orders = {};
  23. }
  24. if(typeof parentOrder === 'undefined')
  25. {
  26. parentOrder = '';
  27. var $parent = ele.closest('.catalog:not(".catalog-empty, .drag-shadow")');
  28. if($parent.length)
  29. {
  30. parentOrder = $parent.children('strong').find('.order').text();
  31. }
  32. }
  33. var index = 1;
  34. ele.children('.catalog:not(".catalog-empty, .drag-shadow")').each(function()
  35. {
  36. var $this = $(this);
  37. var order = (parentOrder === '' ? '' : (parentOrder + '.')) + (index++);
  38. orders[$this.data('id')] = order;
  39. $this.children('strong').find('.order').text(order);
  40. var $dl = $this.children('dl');
  41. if($dl.length)
  42. {
  43. updateOrders($dl, order, orders);
  44. }
  45. });
  46. if(root)
  47. {
  48. saveOrders(orders);
  49. }
  50. };
  51. $('.books dl').append('<dd class="catalog catalog-empty">&nbsp;</dd>');
  52. $('.books > .catalog .catalog, .books > dl .catalog').not('.catalog-empty').droppable(
  53. {
  54. trigger: function($e){return $e.children('.actions').find('.sort-handle')},
  55. target: function($e){return $e.siblings('.catalog');},
  56. container: '.books',
  57. nested: true,
  58. flex: true,
  59. sensorOffsetY: -10,
  60. start: function()
  61. {
  62. $('.books').addClass('show-empty-catalog');
  63. },
  64. drag: function(e)
  65. {
  66. if(e.target)
  67. {
  68. $('.drop-area').removeClass('drop-area');
  69. e.target.closest('dl').addClass('drop-area');
  70. }
  71. },
  72. drop: function(e)
  73. {
  74. e.target.before(e.element);
  75. updateOrders();
  76. },
  77. finish: function()
  78. {
  79. $('.drop-area').removeClass('drop-area');
  80. $('.books').removeClass('show-empty-catalog');
  81. }
  82. });
  83. });
  84. window.parent.$('#triggerModal').one('hide.zui.modal', function(){
  85. window.parent.location.reload();
  86. });