tree_sheet_controller.js 6.2 KB

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