tree_sheet_controller.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var TREE_SHEET_CONTROLLER = {
  5. createNew: function (tree, sheet, setting) {
  6. var controller = function () {
  7. this.tree = tree;
  8. this.sheet = sheet;
  9. this.setting = setting;
  10. };
  11. controller.prototype.showTreeData = function () {
  12. var that = this;
  13. TREE_SHEET_HELPER.loadSheetHeader(this.setting, this.sheet);
  14. TREE_SHEET_HELPER.showTreeData(this.setting, this.sheet, this.tree);
  15. this.sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e, info) {
  16. that.tree.selected = that.tree.findNode(info.sheet.getTag(info.newSelections[0].row, info.newSelections[0].col));
  17. });
  18. };
  19. controller.prototype.insert = function () {
  20. var newNode = null, that = this;
  21. if (this.tree && this.tree.selected) {
  22. newNode = this.tree.insert(this.tree.selected.getParentID(), this.tree.selected.getNextSiblingID());
  23. if (newNode) {
  24. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  25. var sels = that.sheet.getSelections();
  26. var iRow = sels[0].row, newNodeRow = iRow + that.tree.selected.posterityCount() + 1;
  27. that.sheet.addRows(newNodeRow, 1);
  28. TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [newNode], false);
  29. that.tree.selected = newNode;
  30. that.sheet.setSelection(newNode.serialNo(), sels[0].col, 1, 1);
  31. that.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center)
  32. })
  33. }
  34. }
  35. };
  36. controller.prototype.delete = function () {
  37. var that = this;
  38. if (this.tree.selected) {
  39. if (this.tree.delete(this.tree.selected)) {
  40. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  41. var sels = that.sheet.getSelections();
  42. var iRow = sels[0].row;
  43. that.sheet.deleteRows(iRow, that.tree.selected.posterityCount() + 1);
  44. that.tree.selected = that.tree.findNode(that.sheet.getTag(iRow, 0, GC.Spread.Sheets.SheetArea.viewport));
  45. });
  46. }
  47. }
  48. };
  49. controller.prototype.upLevel = function () {
  50. var that = this;
  51. if (this.tree.selected) {
  52. if (this.tree.selected.upLevel()) {
  53. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  54. TREE_SHEET_HELPER.refreshNodesVisible([that.tree.selected], that.sheet, true);
  55. that.sheet.showRow(that.tree.selected.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  56. });
  57. }
  58. }
  59. };
  60. controller.prototype.downLevel = function () {
  61. var that = this;
  62. if (this.tree.selected) {
  63. if (this.tree.selected.downLevel()) {
  64. TREE_SHEET_HELPER.massOperationSheet(that.sheet, function () {
  65. TREE_SHEET_HELPER.refreshNodesVisible([that.tree.selected.parent], that.sheet, true);
  66. that.sheet.showRow(that.tree.selected.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  67. });
  68. }
  69. }
  70. };
  71. controller.prototype.upMove = function () {
  72. var that = this;
  73. if (this.tree.selected) {
  74. if (this.tree.selected.upMove()) {
  75. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  76. var sels = that.sheet.getSelections();
  77. var iRow = sels[0].row;
  78. TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [that.tree.selected, that.tree.selected.nextSibling], true);
  79. that.sheet.setSelection(that.tree.selected.serialNo(), sels[0].col, 1, 1);
  80. });
  81. }
  82. }
  83. };
  84. controller.prototype.downMove = function () {
  85. var that = this;
  86. if (this.tree.selected) {
  87. if (this.tree.selected.downMove()) {
  88. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  89. var sels = that.sheet.getSelections();
  90. var iRow = sels[0].row;
  91. TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [that.tree.selected, that.tree.selected.preSibling], true);
  92. that.sheet.setSelection(that.tree.selected.serialNo(), sels[0].col, 1, 1);
  93. });
  94. }
  95. }
  96. };
  97. return new controller();
  98. }
  99. };