tree_sheet_controller.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. this.event = {
  11. treeSelectedChanged: null
  12. }
  13. };
  14. controller.prototype.showTreeData = function () {
  15. var that = this;
  16. TREE_SHEET_HELPER.loadSheetHeader(this.setting, this.sheet);
  17. TREE_SHEET_HELPER.showTreeData(this.setting, this.sheet, this.tree);
  18. this.sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e, info) {
  19. that.tree.selected = that.tree.findNode(info.sheet.getTag(info.newSelections[0].row, info.newSelections[0].col));
  20. if (that.event.treeSelectedChanged) {
  21. that.event.treeSelectedChanged(that.tree.selected);
  22. }
  23. });
  24. //willdel
  25. /* this.sheet.bind(GC.Spread.Sheets.Events.EditEnded, function (sender, args) {
  26. if(args.sheet.getTag(args.row, args.col)){
  27. var result = tree.editedData(setting.cols[args.col].data.field, args.sheet.getTag(args.row, args.col), args.editingText);
  28. if (result.allow) {
  29. TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, result.nodes, false);
  30. } else {
  31. TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [tree.findNode(args.sheet.getTag(args.row, args.col))], false);
  32. };
  33. }
  34. else {
  35. args.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).text('');
  36. }
  37. });*/
  38. };
  39. controller.prototype.insert = function () {
  40. var newNode = null, that = this;
  41. if (this.tree) {
  42. if (this.tree.selected) {
  43. newNode = this.tree.insert(this.tree.selected.getParentID(), this.tree.selected.getNextSiblingID());
  44. } else {
  45. newNode = this.tree.insert();
  46. }
  47. if (newNode) {
  48. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  49. var sels = that.sheet.getSelections();
  50. var iRow = sels[0].row, newNodeRow = that.tree.selected ? iRow + that.tree.selected.posterityCount() + 1 : iRow;
  51. that.sheet.addRows(newNodeRow, 1);
  52. TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [newNode], false);
  53. that.tree.selected = newNode;
  54. that.sheet.setSelection(newNode.serialNo(), sels[0].col, 1, 1);
  55. that.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center)
  56. })
  57. }
  58. }
  59. };
  60. controller.prototype.delete = function () {
  61. var that = this;
  62. if (this.tree.selected) {
  63. if (this.tree.delete(this.tree.selected)) {
  64. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  65. var sels = that.sheet.getSelections();
  66. var iRow = sels[0].row;
  67. that.sheet.deleteRows(iRow, that.tree.selected.posterityCount() + 1);
  68. that.tree.selected = that.tree.findNode(that.sheet.getTag(iRow, 0, GC.Spread.Sheets.SheetArea.viewport));
  69. });
  70. }
  71. }
  72. };
  73. controller.prototype.upLevel = function () {
  74. var that = this;
  75. if (this.tree.selected) {
  76. if (this.tree.selected.upLevel()) {
  77. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  78. TREE_SHEET_HELPER.refreshNodesVisible([that.tree.selected], that.sheet, true);
  79. that.sheet.showRow(that.tree.selected.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  80. });
  81. }
  82. }
  83. };
  84. controller.prototype.downLevel = function () {
  85. var that = this;
  86. if (this.tree.selected) {
  87. if (this.tree.selected.downLevel()) {
  88. TREE_SHEET_HELPER.massOperationSheet(that.sheet, function () {
  89. TREE_SHEET_HELPER.refreshNodesVisible([that.tree.selected.parent], that.sheet, true);
  90. that.sheet.showRow(that.tree.selected.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  91. });
  92. }
  93. }
  94. };
  95. controller.prototype.upMove = function () {
  96. var that = this;
  97. if (this.tree.selected) {
  98. if (this.tree.selected.upMove()) {
  99. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  100. var sels = that.sheet.getSelections();
  101. var iRow = sels[0].row;
  102. TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [that.tree.selected, that.tree.selected.nextSibling], true);
  103. that.sheet.setSelection(that.tree.selected.serialNo(), sels[0].col, 1, 1);
  104. });
  105. }
  106. }
  107. };
  108. controller.prototype.downMove = function () {
  109. var that = this;
  110. if (this.tree.selected) {
  111. if (this.tree.selected.downMove()) {
  112. TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
  113. var sels = that.sheet.getSelections();
  114. var iRow = sels[0].row;
  115. TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [that.tree.selected, that.tree.selected.preSibling], true);
  116. that.sheet.setSelection(that.tree.selected.serialNo(), sels[0].col, 1, 1);
  117. });
  118. }
  119. }
  120. };
  121. controller.prototype.bind = function (eventName, eventFun) {
  122. this.event[eventName] = eventFun;
  123. };
  124. return new controller();
  125. }
  126. };