area.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. $(document).ready(
  2. function() {
  3. $('.sortable').sortable({
  4. connectWith : 'connected',
  5. hoverClass : 'is-hovered'
  6. }).bind(
  7. 'sortupdate',
  8. function(e, ui) {
  9. function request(ui, block, action) {
  10. var blocks = ui.find('li').map(function() {
  11. return $(this).data("block");
  12. }).get();
  13. var url = updateBlocksUrl;
  14. if (action && action != "swap") {
  15. url = updateBlocksUrl.replace("update-blocks","update-blocks" + "-" + action);
  16. }
  17. $.post(url, {
  18. id : ui.data("domain"),
  19. blocks : blocks,
  20. block : block
  21. }, function(msg) {
  22. if (action == "swap") // 交换的时候会返回两条信息
  23. {
  24. return;
  25. }
  26. $.modal.msg(msg.msg, msg.status);
  27. });
  28. }
  29. // 同一个area下的改变
  30. if (ui.startparent.data("domain") == ui.endparent.data("domain")
  31. && ui.endparent.data("domain") != 0) {
  32. request(ui.startparent);
  33. return;
  34. }
  35. // 区域间交换..或者删除
  36. if (ui.startparent.data("domain") != 0) {
  37. if (ui.endparent.data('domain') != 0) // 区域间交换
  38. {
  39. request(ui.startparent, null, "swap");
  40. request(ui.endparent);
  41. } else // 删除
  42. {
  43. request(ui.startparent, ui.item.data("block"),
  44. "delete");
  45. }
  46. } else // 增加到area
  47. {
  48. request(ui.endparent, ui.item.data("block"),
  49. "create");
  50. }
  51. });
  52. $('.sortable').bind('sortstop', function(e, ui) {
  53. $(".sortable").css("border", "none")
  54. });
  55. $('.sortable').bind('sortstart', function(e, ui) {
  56. $(".sortable").css("border", "dashed 1px #ddd")
  57. });
  58. });