project.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var PROJECT = {
  5. createNew: function () {
  6. // 定义private方法
  7. var tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. var project = function () {
  10. this.mainTree = cacheTree.createNew(this);
  11. this.Bills = Bills.createNew(this);
  12. this.Rations = Rations.createNew(this);
  13. this.GLJ = GLJs.createNew(this);
  14. this.masterField = {ration: 'BillsID'};
  15. };
  16. // prototype用于定义public方法
  17. project.prototype.modify = function (modifyDatas, callback) {
  18. // To Do
  19. };
  20. project.prototype.loadMainTree = function () {
  21. var that = this;
  22. var loadRationNode = function (rations, cacheNode) {
  23. var newNode;
  24. rations.forEach(function (ration) {
  25. if (ration[that.masterField.ration] && ration[that.masterField.ration] === cacheNode.source.getID()) {
  26. newNode = that.mainTree.addNode(cacheNode);
  27. newNode.source = ration;
  28. newNode.sourceType = that.Rations.getSourceType();
  29. newNode.data = ration;
  30. }
  31. });
  32. };
  33. var loadIdTreeNode = function (nodes, parent) {
  34. var newNode, i;
  35. for (i = 0; i < nodes.length; i++) {
  36. newNode = that.mainTree.addNode(parent);
  37. newNode.source = nodes[i];
  38. newNode.sourceType = that.Bills.getSourceType();
  39. newNode.data = nodes[i].data;
  40. if (nodes[i].children.length === 0) {
  41. loadRationNode(that.Rations.datas, newNode);
  42. } else {
  43. loadIdTreeNode(nodes[i].children, newNode);
  44. }
  45. }
  46. };
  47. loadIdTreeNode(this.Bills.tree.roots, null);
  48. this.mainTree.sortTreeItems();
  49. }
  50. return new project();
  51. }
  52. };