DepartmentMinder.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. MWF.xApplication.Execution = MWF.xApplication.Execution || {};
  2. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  3. MWF.xDesktop.requireApp("Template", "Minder", null, false);
  4. MWF.xDesktop.requireApp("Report", "Common", null, false);
  5. MWF.xApplication.Report.DepartmentMinder = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "id" : "",
  10. "year" : "",
  11. "style": "default",
  12. "template" : "default",
  13. "theme": "fresh-blue-compat" //"fresh-blue"
  14. },
  15. initialize: function(node, app, actions, options){
  16. this.setOptions(options);
  17. this.app = app;
  18. this.path = "../x_component_Report/$DepartmentMinder/";
  19. this.cssPath = "../x_component_Report/$DepartmentMinder/"+this.options.style+"/css.wcss";
  20. this._loadCss();
  21. this.lp = this.app.lp;
  22. this.actions = actions;
  23. this.node = $(node);
  24. },
  25. load: function(){
  26. this.departmentCN = this.options.department.split("@")[0];
  27. this.app.setTitle( this.options.year + "年" + this.departmentCN + "工作汇报");
  28. this.data = {
  29. root : {
  30. data : {
  31. text : this.departmentCN,
  32. isRoot : true,
  33. watch : true
  34. },
  35. children : []
  36. }
  37. };
  38. this.app.strategyActions.listMeasureByYearDepartment( this.options.year, this.options.department, function( json ){
  39. var children = this.data.root.children;
  40. var arr = json.data || [];
  41. var loaded = 0;
  42. arr.each( function( d ){
  43. d.text = d.measuresinfotitle;
  44. d.note = " ";
  45. d.isMeasure = true;
  46. d.watch = true;
  47. var obj = {
  48. data : d,
  49. children : []
  50. };
  51. this.app.strategyActions.listPriorityByUnitMeasure( this.options.year, d.id, this.options.department, function( js ){
  52. if( !js.data )js.data = [];
  53. js.data.each( function( d ){
  54. if(d.keyworktitle ){
  55. d.text = d.keyworktitle;
  56. d.note = " ";
  57. d.isPriority = true;
  58. d.watch = true;
  59. obj.children.push( {
  60. data : d,
  61. children : [{
  62. data : { text : "加载中..." }
  63. }]
  64. })
  65. }
  66. });
  67. loaded++;
  68. if( loaded == arr.length ){
  69. this.createMinder( this.data );
  70. }
  71. }.bind(this));
  72. children.push( obj )
  73. }.bind(this));
  74. }.bind(this));
  75. this.refreshFun = this.refresh.bind(this);
  76. this.app.addEvent("resize", this.refreshFun);
  77. //new Element("button", {
  78. // text : "整理布局",
  79. // value : "整理布局",
  80. // events : {
  81. // click : function(){
  82. // //this.minder.km.execCommand('resetlayout')
  83. //
  84. // this.minder.km.refresh();
  85. // }.bind(this)
  86. //}}).inject( this.node )
  87. },
  88. destroy : function(){
  89. if(this.minder)this.minder.destroy() ;
  90. for( var key in this.tooltips ){
  91. this.tooltips[key].destroy();
  92. }
  93. if( this.refreshFun ){
  94. this.app.removeEvent("resize", this.refreshFun);
  95. }
  96. delete this;
  97. },
  98. refresh: function(){
  99. if(this.minder)this.minder.refresh();
  100. },
  101. reload: function(){
  102. if(this.minder)this.minder.destroy() ;
  103. this.node.empty();
  104. this.load();
  105. },
  106. createMinder: function( json ) {
  107. this.minder = new MWF.xApplication.Template.Minder(this.node, this.app, json, {
  108. "hasNavi" : false,
  109. "onPostLoad" : function(){
  110. this.minder.km.execCommand('ExpandToLevel', 2 ); //折叠到第一层
  111. this.minder.loadNavi( this.node );
  112. }.bind(this),
  113. "onPostLoadNode" : function( minderNode ){
  114. this.setMinderNode( minderNode );
  115. }.bind(this)
  116. });
  117. this.minder.load();
  118. },
  119. setMinderNode : function( minderNode ){
  120. var _self = this;
  121. if( !minderNode.getData().watch ){
  122. }else{
  123. var data = minderNode.getData();
  124. var iconRenderer = minderNode.getRenderer('NoteIconRenderer');
  125. if( iconRenderer && iconRenderer.getRenderShape() ){
  126. var icon = iconRenderer.getRenderShape();
  127. icon.addEventListener("mouseover", function ( ev ) {
  128. _self.tooltipTimer = setTimeout(function() {
  129. var c = this.getRenderBox('screen');
  130. _self.loadTooltip( this.getData(), c );
  131. }.bind(this), 300);
  132. }.bind(minderNode));
  133. icon.addEventListener("mouseout", function ( ev ) {
  134. clearTimeout(_self.tooltipTimer);
  135. _self.hideTooltip();
  136. }.bind(minderNode));
  137. }
  138. if( data.isPriority ){
  139. var expanderNode = minderNode.getRenderer('ExpanderRenderer').getRenderShape();
  140. if( expanderNode ){
  141. expanderNode.addEventListener("mousedown", function(ev){
  142. var data = this.getData();
  143. if( !data.loaded ){
  144. setTimeout( function(){
  145. _self.expendPriority( this, data, function(){
  146. }.bind(this))
  147. }.bind(this), 100 )
  148. }
  149. }.bind(minderNode));
  150. }
  151. }
  152. var cNode = minderNode.getRenderContainer().node;
  153. cNode.addEventListener("click", function(ev){
  154. var data = this.getData();
  155. if( data.isPriority ){
  156. if( !data.loaded ){
  157. setTimeout( function(){
  158. _self.expendPriority( this, data, function(){
  159. }.bind(this))
  160. }.bind(this), 100 )
  161. }else{
  162. var renderer = this.getRenderer('ExpanderRenderer');
  163. renderer.expander.fire("mousedown");
  164. }
  165. }else{
  166. //if( !data.isRoot ){
  167. // var renderer = this.getRenderer('ExpanderRenderer');
  168. // renderer.expander.fire("mousedown");
  169. //}
  170. }
  171. }.bind(minderNode));
  172. //cNode.addEventListener("dblclick", function ( ev ) {
  173. // _self.openWork( this, this.getData() );
  174. //}.bind(minderNode));
  175. }
  176. },
  177. expendPriority : function( minderNode, data, callback ){
  178. var _self = this;
  179. if( this.isLoaddingChildren )return;
  180. this.isLoaddingChildren = true;
  181. this.actions.listWithPriority( this.options.year, {
  182. "workIds":[data.id],"unitList":[ this.options.department ] //,"reportObjType":"UNIT"
  183. }, function( json ){
  184. data.loaded = true;
  185. var obj = {
  186. };
  187. var array = json.data;
  188. array.sort( function(a, b){
  189. return ( a.month ).localeCompare( b.month );
  190. });
  191. array.each( function( d ) {
  192. if (!obj[d.month])obj[d.month] = [];
  193. obj[d.month].push( d )
  194. });
  195. var j = {
  196. data : data,
  197. children : []
  198. };
  199. for( var key in obj ){
  200. var arr = [];
  201. obj[key].each( function( o ){
  202. var a = [];
  203. o.progList.each( function( prog ){
  204. a.push( this.app.common.splitWithLength( prog.targetPerson.split("@")[0] + ":" + prog.progressContent, 35 ) );
  205. }.bind(this));
  206. arr.push( a.join("\n") );
  207. }.bind(this));
  208. j.children.push( {
  209. data : {
  210. text : parseInt( key ) +"月"
  211. },
  212. children : [{
  213. data : { text : arr.join( "\n" ) }
  214. }]
  215. })
  216. }
  217. while (minderNode.getChildren().length){
  218. var node = minderNode.getChildren()[0];
  219. this.minder.km.removeNode(node)
  220. }
  221. this.minder.km.importNode(minderNode, j );
  222. //this.proiorityLoadedLength ++;
  223. //if( this.proiorityLoadedLength == this.proiorityLength ){
  224. minderNode.expand();
  225. this.minder.km.refresh();
  226. //var nodes = departmentNode.getChildren();
  227. //nodes.forEach(function (node) {
  228. // this.setMinderNode(node);
  229. //}.bind(this));
  230. this.isLoaddingChildren = false;
  231. //}
  232. }.bind(this))
  233. },
  234. loadTooltip: function( data, c ){
  235. if( !this.tooltips )this.tooltips = {};
  236. if( this.tooltips[ data.id ] ){
  237. var tooltip = this.currentTooltip = this.tooltips[ data.id ];
  238. tooltip.targetCoordinates = c;
  239. tooltip.load();
  240. }else{
  241. if( data.isRoot ){
  242. var tooltip = this.currentTooltip = new MWF.xApplication.Report.KeyWorkTooltip( this.node, null, this.app, data, {}, c);
  243. }else if( data.isMeasure ){
  244. var tooltip = this.currentTooltip = new MWF.xApplication.Report.MeasureTooltip( this.node, null, this.app, data, {}, c);
  245. }else if( data.isPriority ){
  246. var tooltip = this.currentTooltip = new MWF.xApplication.Report.PriorityTooltip( this.node, null, this.app, data, {}, c);
  247. }
  248. if( tooltip ){
  249. tooltip.load();
  250. this.tooltips[ data.id ] = tooltip;
  251. }
  252. }
  253. },
  254. hideTooltip: function(){
  255. if( this.currentTooltip ){
  256. this.currentTooltip.hide()
  257. }
  258. }
  259. });