tree_sheet_controller.js 5.8 KB

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