KeyWorkMinder.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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.KeyWorkMinder = 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/$KeyWorkMinder/";
  19. this.cssPath = "../x_component_Report/$KeyWorkMinder/"+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.data = {
  27. root : {
  28. data : {},
  29. children : []
  30. }
  31. };
  32. this.app.strategyActions.getKeyWorkById( this.options.id, function( json ){
  33. this.app.setTitle(json.data.strategydeploytitle);
  34. json.data.text = json.data.strategydeploytitle;
  35. json.data.note = " ";
  36. json.data.isRoot = true;
  37. json.data.watch = true;
  38. this.data.root.data = json.data;
  39. this.app.strategyActions.listMeasuresWidthKeyWork( this.options.id, function(j){
  40. var children = this.data.root.children;
  41. j.data.each( function( d ){
  42. d.text = d.measuresinfotitle;
  43. d.note = " ";
  44. d.isMeasure = true;
  45. d.watch = true;
  46. var obj = {
  47. data : d,
  48. children : []
  49. };
  50. d.deptlist.each( function( dept ){
  51. obj.children.push({
  52. data : {
  53. text : dept.split("@")[0],
  54. department : dept,
  55. measureId : d.id,
  56. isDepartment : true,
  57. watch : true
  58. },
  59. children : [{
  60. data : { text : "加载中..." }
  61. }]
  62. })
  63. });
  64. children.push( obj )
  65. });
  66. this.createMinder( this.data );
  67. }.bind(this))
  68. }.bind(this));
  69. this.refreshFun = this.refresh.bind(this);
  70. this.app.addEvent("resize", this.refreshFun);
  71. //new Element("button", {
  72. // text : "整理布局",
  73. // value : "整理布局",
  74. // events : {
  75. // click : function(){
  76. // //this.minder.km.execCommand('resetlayout')
  77. //
  78. // this.minder.km.refresh();
  79. // }.bind(this)
  80. //}}).inject( this.node )
  81. },
  82. destroy : function(){
  83. if(this.minder)this.minder.destroy() ;
  84. for( var key in this.tooltips ){
  85. this.tooltips[key].destroy();
  86. }
  87. if( this.refreshFun ){
  88. this.app.removeEvent("resize", this.refreshFun);
  89. }
  90. delete this;
  91. },
  92. refresh: function(){
  93. if(this.minder)this.minder.refresh();
  94. },
  95. reload: function(){
  96. if(this.minder)this.minder.destroy() ;
  97. this.node.empty();
  98. this.load();
  99. },
  100. createMinder: function( json ) {
  101. this.minder = new MWF.xApplication.Template.Minder(this.node, this.app, json, {
  102. "hasNavi" : false,
  103. "onPostLoad" : function(){
  104. this.minder.km.execCommand('ExpandToLevel', 2 ); //折叠到第一层
  105. this.minder.loadNavi( this.node );
  106. }.bind(this),
  107. "onPostLoadNode" : function( minderNode ){
  108. this.setMinderNode( minderNode );
  109. }.bind(this)
  110. });
  111. this.minder.load();
  112. },
  113. setMinderNode : function( minderNode ){
  114. var _self = this;
  115. //alert("title="+minderNode.getData().title)
  116. //alert("watch="+minderNode.getData().watch)
  117. if( !minderNode.getData().watch ){
  118. //km.select([minderNode],true);
  119. //km.execCommand('Background', "#dcdcdc");
  120. //km.execCommand('ForeColor', "#fff");
  121. }else{
  122. var data = minderNode.getData();
  123. var iconRenderer = minderNode.getRenderer('NoteIconRenderer');
  124. if( iconRenderer && iconRenderer.getRenderShape() ){
  125. var icon = iconRenderer.getRenderShape();
  126. icon.addEventListener("mouseover", function ( ev ) {
  127. _self.tooltipTimer = setTimeout(function() {
  128. var c = this.getRenderBox('screen');
  129. _self.loadTooltip( this.getData(), c );
  130. }.bind(this), 300);
  131. }.bind(minderNode));
  132. icon.addEventListener("mouseout", function ( ev ) {
  133. clearTimeout(_self.tooltipTimer);
  134. _self.hideTooltip();
  135. }.bind(minderNode));
  136. }
  137. if( data.isDepartment ){
  138. var expanderNode = minderNode.getRenderer('ExpanderRenderer').getRenderShape();
  139. if( expanderNode ){
  140. expanderNode.addEventListener("mousedown", function(ev){
  141. var data = this.getData();
  142. if( !data.loaded ){
  143. setTimeout( function(){
  144. _self.expendDepartment( this, data, function(){
  145. }.bind(this))
  146. }.bind(this), 100 )
  147. }
  148. }.bind(minderNode));
  149. }
  150. }
  151. var cNode = minderNode.getRenderContainer().node;
  152. cNode.addEventListener("click", function(ev){
  153. var data = this.getData();
  154. if( data.isDepartment ){
  155. if( !data.loaded ){
  156. setTimeout( function(){
  157. _self.expendDepartment( this, data, function(){
  158. }.bind(this))
  159. }.bind(this), 100 )
  160. }else{
  161. var renderer = this.getRenderer('ExpanderRenderer');
  162. renderer.expander.fire("mousedown");
  163. }
  164. }else{
  165. //if( !data.isRoot ){
  166. // var renderer = this.getRenderer('ExpanderRenderer');
  167. // renderer.expander.fire("mousedown");
  168. //}
  169. }
  170. }.bind(minderNode));
  171. //cNode.addEventListener("dblclick", function ( ev ) {
  172. // _self.openWork( this, this.getData() );
  173. //}.bind(minderNode));
  174. }
  175. },
  176. expendDepartment: function( minderNode, data, callback ){
  177. var _self = this;
  178. if( this.isLoaddingChildren )return;
  179. this.isLoaddingChildren = true;
  180. this.actions.listPriorityByUnitMeasure( this.options.year, data.measureId, data.department, function( json ){
  181. data.loaded = true;
  182. if( !json.data )json.data = [];
  183. this.proiorityLength = json.data.length;
  184. this.proiorityLoadedLength = 0;
  185. var j = {
  186. data : data,
  187. children : []
  188. };
  189. json.data.each( function( d ){
  190. if(d.keyworktitle ){
  191. d.text = d.keyworktitle;
  192. d.note = " ";
  193. d.department = data.department;
  194. d.isPriority = true;
  195. d.watch = true;
  196. j.children.push( {
  197. data : d
  198. })
  199. }
  200. });
  201. while (minderNode.getChildren().length){
  202. var node = minderNode.getChildren()[0];
  203. this.minder.km.removeNode(node)
  204. }
  205. this.minder.km.importNode(minderNode, j );
  206. var nodes = minderNode.getChildren();
  207. if( nodes.length ){
  208. nodes.forEach(function (node) {
  209. this.expendPriority( minderNode, node, node.getData(), null )
  210. }.bind(this));
  211. }else{
  212. this.minder.km.refresh();
  213. }
  214. this.isLoaddingChildren = false;
  215. }.bind(this))
  216. },
  217. expendPriority : function( departmentNode, minderNode, data, callback ){
  218. var _self = this;
  219. this.actions.listWithPriority( this.options.year, {
  220. "workIds":[data.id],"unitList":[ data.department ] //,"reportObjType":"UNIT"
  221. }, function( json ){
  222. var obj = {
  223. };
  224. var array = json.data;
  225. array.sort( function(a, b){
  226. return ( a.month ).localeCompare( b.month );
  227. });
  228. array.each( function( d ) {
  229. if (!obj[d.month])obj[d.month] = [];
  230. obj[d.month].push( d )
  231. });
  232. var j = {
  233. data : data,
  234. children : []
  235. };
  236. for( var key in obj ){
  237. var arr = [];
  238. obj[key].each( function( o ){
  239. var a = [];
  240. o.progList.each( function( prog ){
  241. a.push( this.app.common.splitWithLength( prog.targetPerson.split("@")[0] + ":" + prog.progressContent, 35 ) );
  242. }.bind(this));
  243. arr.push( a.join("\n") );
  244. }.bind(this));
  245. j.children.push( {
  246. data : {
  247. text : parseInt( key ) +"月"
  248. },
  249. children : [{
  250. data : { text : arr.join( "\n" ) }
  251. }]
  252. })
  253. }
  254. this.minder.km.importNode(minderNode, j );
  255. this.proiorityLoadedLength ++;
  256. if( this.proiorityLoadedLength == this.proiorityLength ){
  257. departmentNode.expand();
  258. this.minder.km.refresh();
  259. var nodes = departmentNode.getChildren();
  260. nodes.forEach(function (node) {
  261. this.setMinderNode(node);
  262. }.bind(this));
  263. }
  264. //this.actions.listWithPriority( this.options.year, {
  265. // "workIds":[data.id],"unitList":[ data.department ],"reportObjType":"PERSON"
  266. //}, function( js ){
  267. // var array = js.data;
  268. // array.sort( function(a, b){
  269. // return ( a.month + a.targetPerson ).localeCompare( b.month + b.targetPerson );
  270. // });
  271. // array.each( function( d ) {
  272. // if (!obj[d.month])obj[d.month] = [];
  273. // obj[d.month].push(d)
  274. // });
  275. //
  276. //
  277. //}.bind(this))
  278. }.bind(this))
  279. },
  280. loadTooltip: function( data, c ){
  281. if( !this.tooltips )this.tooltips = {};
  282. if( this.tooltips[ data.id ] ){
  283. var tooltip = this.currentTooltip = this.tooltips[ data.id ];
  284. tooltip.targetCoordinates = c;
  285. tooltip.load();
  286. }else{
  287. if( data.isRoot ){
  288. var tooltip = this.currentTooltip = new MWF.xApplication.Report.KeyWorkTooltip( this.node, null, this.app, data, {}, c);
  289. }else if( data.isMeasure ){
  290. var tooltip = this.currentTooltip = new MWF.xApplication.Report.MeasureTooltip( this.node, null, this.app, data, {}, c);
  291. }else if( data.isPriority ){
  292. var tooltip = this.currentTooltip = new MWF.xApplication.Report.PriorityTooltip( this.node, null, this.app, data, {}, c);
  293. }
  294. if( tooltip ){
  295. tooltip.load();
  296. this.tooltips[ data.id ] = tooltip;
  297. }
  298. }
  299. },
  300. hideTooltip: function(){
  301. if( this.currentTooltip ){
  302. this.currentTooltip.hide()
  303. }
  304. }
  305. });