OrgExplorer_bak.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. MWF.require("MWF.widget.MWFRaphael", null, false);
  2. MWF.xApplication.Organization.OrgExplorer = new Class({
  3. Extends: MWF.widget.Common,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default"
  7. },
  8. initialize: function(node, actions, options){
  9. this.setOptions(options);
  10. this.path = "/x_component_Organization/$OrgExplorer/";
  11. this.cssPath = "/x_component_Organization/$OrgExplorer/"+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.actions = actions;
  14. this.node = $(node);
  15. },
  16. load: function(){
  17. this.loadLayout();
  18. this.loadChart();
  19. },
  20. loadLayout: function(){
  21. this.propertyAreaNode = new Element("div", {"styles": this.css.propertyAreaNode}).inject(this.node);
  22. this.chartAreaNode = new Element("div", {"styles": this.css.chartAreaNode}).inject(this.node);
  23. this.resizeBarNode = new Element("div", {"styles": this.css.resizeBarNode}).inject(this.propertyAreaNode);
  24. this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.propertyAreaNode);
  25. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  26. this.propertyContentNode = new Element("div", {"styles": this.css.propertyContentNode}).inject(this.propertyNode);
  27. this.resizePropertyContentNode();
  28. this.app.addEvent("resize", function(){this.resizePropertyContentNode();}.bind(this));
  29. this.chartNode = new Element("div", {"styles": this.css.chartNode}).inject(this.chartAreaNode);
  30. this.propertyResize = new Drag(this.resizeBarNode,{
  31. "snap": 1,
  32. "onStart": function(el, e){
  33. var x = e.event.clientX;
  34. var y = e.event.clientY;
  35. el.store("position", {"x": x, "y": y});
  36. var size = this.propertyAreaNode.getSize();
  37. el.store("initialWidth", size.x);
  38. }.bind(this),
  39. "onDrag": function(el, e){
  40. var x = e.event.clientX;
  41. // var y = e.event.y;
  42. var bodySize = this.node.getSize();
  43. var position = el.retrieve("position");
  44. var initialWidth = el.retrieve("initialWidth").toFloat();
  45. var dx = position.x.toFloat()-x.toFloat();
  46. var width = initialWidth+dx;
  47. if (width> bodySize.x/1.5) width = bodySize.x/1.5;
  48. if (width<40) width = 40;
  49. this.chartAreaNode.setStyle("margin-right", width+1);
  50. this.propertyAreaNode.setStyle("width", width);
  51. }.bind(this)
  52. });
  53. },
  54. resizePropertyContentNode: function(){
  55. var size = this.node.getSize();
  56. var tSize = this.propertyTitleNode.getSize();
  57. var mtt = this.propertyTitleNode.getStyle("margin-top").toFloat();
  58. var mbt = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  59. var mtc = this.propertyContentNode.getStyle("margin-top").toFloat();
  60. var mbc = this.propertyContentNode.getStyle("margin-bottom").toFloat();
  61. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  62. this.propertyContentNode.setStyle("height", height);
  63. },
  64. loadChart: function(){
  65. this.actions.listTopCompany(function(json){
  66. MWFRaphael.load(function(){
  67. this.paper = Raphael(this.chartNode, "100%", "99%");
  68. this.paper.container = this.chartNode;
  69. this.loadChartContent(json.data, "company");
  70. }.bind(this));
  71. }.bind(this));
  72. },
  73. loadChartContent: function(data, type){
  74. var tmpItem = null;
  75. data.each(function(itemData){
  76. var item = new MWF.xApplication.Organization.OrgExplorer.Company(itemData, this);
  77. if (tmpItem) item.prevItem = tmpItem;
  78. item.load();
  79. tmpItem = item;
  80. }.bind(this));
  81. }
  82. // this.shap = this.createShap();
  83. // // this.shadow = this.careteShadow();
  84. // this.text = this.createText();
  85. // this.icon = this.createIcon();
  86. // this.set.push(this.shadow, this.shap, this.text, this.icon);
  87. });
  88. MWF.xApplication.Organization.OrgExplorer.Item = new Class({
  89. initialize: function(data, explorer){
  90. this.data = data;
  91. this.explorer = explorer;
  92. this.paper = this.explorer.paper;
  93. this.prevItem = null;
  94. this.nextItem = null;
  95. this.parentItem = null;
  96. this.children = [];
  97. this.position = {
  98. x: 0,
  99. y: 0,
  100. maxY: 0,
  101. center: {
  102. x: 0,
  103. y: 0
  104. }
  105. };
  106. this.initStyles();
  107. },
  108. initStyles: function(){
  109. // this.width = 150;
  110. // this.margin = 50;
  111. this.style = this.explorer.css.chart.company;
  112. },
  113. load: function(){
  114. this.getItemPostion();
  115. this.shap = this.createShap();
  116. this.text = this.createText();
  117. this.icon = this.createIcon();
  118. if (!this.set) this.set = this.paper.set();
  119. this.set.push(this.shap, this.text, this.icon);
  120. },
  121. getItemPostion: function(){
  122. var x = this.style.width*(this.data.level-1)+20;
  123. var y = 0;
  124. if (this.prevItem){
  125. y = this.prevItem.position.maxY+20;
  126. }else if (this.parentItem){
  127. y = this.parentItem.position.y;
  128. }else{
  129. y = 20;
  130. }
  131. this.position.x = x;
  132. this.position.y = y;
  133. this.position.maxY = y+this.style.height;
  134. this.setParentMaxY();
  135. },
  136. setParentMaxY: function(){
  137. var item = this.parentItem;
  138. if (item){
  139. if (item.position.maxY<this.position.maxY){
  140. item.position.maxY = this.position.maxY;
  141. item.setParentMaxY();
  142. }
  143. }
  144. },
  145. createShap: function(){
  146. var shap;
  147. shap = this.paper.rectPath(this.position.x, this.position.y, this.style.width, this.style.height, this.style.radius);
  148. shap.attr(this.style.shap);
  149. shap.data("bind", this);
  150. return shap;
  151. },
  152. createText: function(){
  153. var atts = this.getTextIconPoint();
  154. text = this.paper.text(atts.tatt.x, atts.tatt.y, this.data.name);
  155. text.attr(this.style.text);
  156. if (this.style.text.display=="none"){
  157. text.hide();
  158. }
  159. return text;
  160. },
  161. createIcon: function(){
  162. var atts = this.getTextIconPoint();
  163. var icon = this.paper.image(this.style.src, atts.iatt.x, atts.iatt.y, 48, 48);
  164. icon.attr(this.style.icon);
  165. return icon;
  166. },
  167. getTextIconPoint: function(){
  168. var t_att = {x: this.position.x, y: this.position.y+(this.style.height/2)};
  169. var i_att = {x: this.position.x+6, y: this.position.y+6};
  170. return {"tatt": t_att, "iatt": i_att};
  171. },
  172. });
  173. MWF.xApplication.Organization.OrgExplorer.Company = new Class({
  174. Extends: MWF.xApplication.Organization.OrgExplorer.Item
  175. });
  176. MWF.xApplication.Organization.OrgExplorer.Department = new Class({
  177. Extends: MWF.xApplication.Organization.OrgExplorer.Item,
  178. initStyles: function(){
  179. this.style = this.explorer.css.chart.department;
  180. },
  181. });