TaskRank.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. MWF.xApplication.BAM.summary = MWF.xApplication.BAM.summary || {};
  2. MWF.xApplication.BAM.summary.TaskRank = new Class({
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default"
  6. },
  7. initialize: function(summary, node, options){
  8. this.setOptions(options);
  9. this.summary = summary;
  10. this.app = this.summary.app;
  11. this.css = this.app.css;
  12. this.lp = this.app.lp;
  13. this.container = $(node);
  14. this.category = "unit";
  15. this.data = null;
  16. this.maxColumn = 10;
  17. this.barOptions = {"style": "default", "marginBottom": 5};
  18. this.load();
  19. },
  20. load: function(){
  21. this.node = new Element("div", {"styles": this.css.taskRankContentAreaNode}).inject(this.container);
  22. this.loadTaskRankArea();
  23. //this.loadBar();
  24. this.loadBarData(this.loadBar.bind(this));
  25. },
  26. reload: function(){
  27. if (this.durationBar) this.durationBar.destroy();
  28. if (this.elapsedCountBar) this.elapsedCountBar.destroy();
  29. if (this.completedCountBar) this.completedCountBar.destroy();
  30. if (this.completedTimelinessBar) this.completedTimelinessBar.destroy();
  31. if (this.timeoutRateBar) this.timeoutRateBar.destroy();
  32. this.durationBar = null;
  33. this.elapsedCountBar = null;
  34. this.completedCountBar = null;
  35. this.completedTimelinessBar = null;
  36. this.timeoutRateBar = null;
  37. this.durationNode.empty();
  38. this.expiredCountNode.empty();
  39. this.completedCountNode.empty();
  40. this.completedTimelinessNode.empty();
  41. this.timeoutRateNode.empty();
  42. this.loadBarData(this.loadBar.bind(this));
  43. //this.expiredPage.showTabIm();
  44. },
  45. loadBar: function(){
  46. MWF.require("MWF.widget.chart.Bar", function(){
  47. this.durationPage.addEvent("show", function(){
  48. if (!this.durationBar){
  49. this.durationBar = this.loadBarChart(this.durationNode, this[this.category+"RankData"].taskDuration.slice(0,this.maxColumn));
  50. } else {
  51. this.durationBar.transition();
  52. }
  53. }.bind(this));
  54. this.expiredCountPage.addEvent("show", function(){
  55. if (!this.elapsedCountBar){
  56. this.elapsedCountBar = this.loadBarChart(this.expiredCountNode, this[this.category+"RankData"].taskElapsedCount.slice(0,this.maxColumn));
  57. } else {
  58. this.elapsedCountBar.transition();
  59. }
  60. }.bind(this));
  61. this.completedCountPage.addEvent("show", function(){
  62. if (!this.completedCountBar){
  63. this.completedCountBar = this.loadBarChart(this.completedCountNode, this[this.category+"RankData"].taskCompletedCount.slice(0,this.maxColumn));
  64. } else {
  65. this.completedCountBar.transition();
  66. }
  67. }.bind(this));
  68. this.completedTimelinessPage.addEvent("show", function(){
  69. if (!this.completedTimelinessBar){
  70. var options = (this.barOptions) ? Object.clone(this.barOptions) : {};
  71. options.tickFormat = ".0%";
  72. options.dataFormat = ".1%";
  73. this.completedTimelinessBar = this.loadBarChart(this.completedTimelinessNode, this[this.category+"RankData"].taskCompletedTimeliness.slice(0,this.maxColumn), options);
  74. } else {
  75. this.completedTimelinessBar.transition();
  76. }
  77. }.bind(this));
  78. this.timeoutRatePage.addEvent("show", function(){
  79. if (!this.timeoutRateBar){
  80. var options = (this.barOptions) ? Object.clone(this.barOptions) : {};
  81. options.tickFormat = ".0%";
  82. options.dataFormat = ".1%";
  83. this.timeoutRateBar = this.loadBarChart(this.timeoutRateNode, this[this.category+"RankData"].taskTimeoutRate.slice(0,this.maxColumn), options);
  84. } else {
  85. this.timeoutRateBar.transition();
  86. }
  87. }.bind(this));
  88. if (this.durationPage.isShow){
  89. this.durationPage.showIm();
  90. }else{
  91. this.durationPage.showTabIm();
  92. }
  93. }.bind(this));
  94. },
  95. loadBarChart: function(node, data, options){
  96. var bar = new MWF.widget.chart.Bar(node, data, "name", options);
  97. bar.addBar("value");
  98. bar.addEvents({
  99. "mouseover": function(rects, texts, d, i){
  100. texts.filter(function(data, idx){return (idx==i);}).attr("display", "block");
  101. var rect = rects.filter(function(data, idx){return (idx==i);});
  102. var color = rect.attr("fill");
  103. rect.node().store("color", color);
  104. rect.attr("fill", "brown");
  105. }.bind(this),
  106. "mouseout": function(rects, texts, d, i){
  107. texts.filter(function(data, idx){return (idx==i);}).attr("display", "none");
  108. var rect = rects.filter(function(data, idx){return (idx==i);});
  109. var color = rect.node().retrieve("color");
  110. rect.attr("fill", color);
  111. }.bind(this)
  112. });
  113. bar.load();
  114. return bar;
  115. },
  116. loadBarData: function(callback){
  117. var method = "load-rank-"+this.category+"-data";
  118. //this.data = this.app.actions.getRankData(this.app.organizationData[this.category]);
  119. this[method.camelCase()](function(){
  120. if (callback) callback();
  121. }.bind(this));
  122. },
  123. loadTab: function(){
  124. this.tab = new MWF.widget.Tab(this.chartAreaNode, {"style": "BAM_rank"});
  125. this.tab.load();
  126. this.durationNode = new Element("div", {"styles": this.css.taskRankTabAreaNode});
  127. this.expiredCountNode = new Element("div", {"styles": this.css.taskRankTabAreaNode});
  128. this.completedCountNode = new Element("div", {"styles": this.css.taskRankTabAreaNode});
  129. this.completedTimelinessNode = new Element("div", {"styles": this.css.taskRankTabAreaNode});
  130. this.timeoutRateNode = new Element("div", {"styles": this.css.taskRankTabAreaNode});
  131. this.durationPage = this.tab.addTab(this.durationNode, this.lp.taskRankTypeExpired);
  132. this.expiredCountPage = this.tab.addTab(this.expiredCountNode, this.lp.taskRankTypeExpiredCount);
  133. this.completedCountPage = this.tab.addTab(this.completedCountNode, this.lp.taskRankTypeCompletedCount);
  134. this.completedTimelinessPage = this.tab.addTab(this.completedTimelinessNode, this.lp.timeliness);
  135. this.timeoutRatePage = this.tab.addTab(this.timeoutRateNode, this.lp.timeout);
  136. },
  137. loadCategory: function(){
  138. var id = new MWF.widget.UUID();
  139. // var html = "<input name='"+id+"TaskRankCategory' type='radio' value='company'>"+this.lp.company+
  140. // "<input name='"+id+"TaskRankCategory' type='radio' value='department' checked>"+this.lp.department+
  141. // "<input name='"+id+"TaskRankCategory' type='radio' value='person'>"+this.lp.person;
  142. var html = "<input name='"+id+"TaskRankCategory' type='radio' value='unit' checked>"+this.lp.unit+
  143. "<input name='"+id+"TaskRankCategory' type='radio' value='person'>"+this.lp.person;
  144. this.categoryNode.set("html", html);
  145. var _self = this;
  146. this.categoryNode.getElements("input").addEvent("click", function(){
  147. _self.category = this.value;
  148. _self.reload();
  149. });
  150. },
  151. loadTaskRankArea: function(){
  152. this.headNode = new Element("div", {"styles": this.css.taskRankHeadNode}).inject(this.node);
  153. this.categoryNode = new Element("div", {"styles": this.css.taskRankCategoryNode}).inject(this.headNode);
  154. this.actionNode = new Element("div", {"styles": this.css.taskRankActionNode}).inject(this.headNode);
  155. this.titleNode = new Element("div", {"styles": this.css.taskRankTitleNode, "text": this.lp.top10}).inject(this.headNode);
  156. this.chartAreaNode = new Element("div", {"styles": this.css.taskRankChartAreaNode}).inject(this.node);
  157. this.loadTab();
  158. this.loadCategory();
  159. this.actionNode.addEvent("click", function(){
  160. if (!this.maxNode){
  161. this.maxSizeChart();
  162. }else{
  163. this.returnSizeChart();
  164. }
  165. }.bind(this));
  166. },
  167. returnSizeChart: function(){
  168. this.resizeReturnChart();
  169. var size = this.container.getSize();
  170. var position = this.container.getPosition(this.container.getOffsetParent());
  171. new Fx.Morph(this.maxNode, {"duration": 150}).start({
  172. "height": ""+size.y+"px",
  173. "width": ""+size.x+"px",
  174. "left": ""+position.x+"px",
  175. "top": ""+position.y+"px"
  176. }).chain(function(){
  177. this.maxNode.destroy();
  178. this.maxNode = null;
  179. this.reload();
  180. if (this.resizeMaxChartFun) this.app.removeEvent("resize", this.resizeMaxChartFun);
  181. }.bind(this));
  182. },
  183. resizeReturnChart: function(){
  184. this.node.inject(this.container);
  185. this.node.setStyles(this.css.taskContentNode);
  186. this.chartAreaNode.setStyles(this.css.contentChartAreaNode);
  187. this.actionNode.setStyles(this.css.taskRankActionNode);
  188. var tabSize = this.chartAreaNode.getSize();
  189. var h = tabSize.y-24;
  190. this.durationNode.setStyle("height", ""+h+"px");
  191. this.expiredCountNode.setStyle("height", ""+h+"px");
  192. this.completedCountNode.setStyle("height", ""+h+"px");
  193. if (this.completedTimelinessNode) this.completedTimelinessNode.setStyle("height", ""+h+"px");
  194. if (this.timeoutRateNode) this.timeoutRateNode.setStyle("height", ""+h+"px");
  195. this.maxColumn = 10;
  196. this.barOptions = {"marginBottom": 46, "style": "task"};
  197. },
  198. maxSizeChart: function(){
  199. this.createMaxNode();
  200. var maxSize = this.app.content.getSize();
  201. var x = maxSize.x-18;
  202. var y= maxSize.y-18;
  203. new Fx.Morph(this.maxNode, {"duration": 150}).start({
  204. "height": ""+y+"px",
  205. "width": ""+x+"px",
  206. "left": "5px",
  207. "top": "5px"
  208. }).chain(function(){
  209. this.reloadMaxChart();
  210. this.resizeMaxChartFun = this.resizeMaxChart.bind(this);
  211. this.app.addEvent("resize", this.resizeMaxChartFun);
  212. }.bind(this));
  213. },
  214. resizeMaxChart: function(){
  215. var maxSize = this.app.content.getSize();
  216. var x = maxSize.x-18;
  217. var y= maxSize.y-18;
  218. this.maxNode.setStyles({
  219. "height": ""+y+"px",
  220. "width": ""+x+"px",
  221. "left": "5px",
  222. "top": "5px"
  223. });
  224. this.reloadMaxChart();
  225. },
  226. reloadMaxChart: function(){
  227. this.node.inject(this.maxNode);
  228. this.node.setStyles(this.css.taskContentNode_max);
  229. this.chartAreaNode.setStyles(this.css.contentChartAreaNode_max);
  230. this.actionNode.setStyles(this.css.taskRankActionNode_max);
  231. var tabSize = this.chartAreaNode.getSize();
  232. var h = tabSize.y-80;
  233. this.durationNode.setStyle("height", ""+h+"px");
  234. this.expiredCountNode.setStyle("height", ""+h+"px");
  235. this.completedCountNode.setStyle("height", ""+h+"px");
  236. if (this.completedTimelinessNode) this.completedTimelinessNode.setStyle("height", ""+h+"px");
  237. if (this.timeoutRateNode) this.timeoutRateNode.setStyle("height", ""+h+"px");
  238. this.maxColumn = Math.round(tabSize.x/40);
  239. this.barOptions = {"marginBottom": 100, "delay": 10, "style": "default_max"};
  240. this.reload();
  241. },
  242. createMaxNode: function(){
  243. this.maxNode = new Element("div", {"styles": this.css.contentChartMaxAreaNode}).inject(this.container, "after");
  244. var size = this.container.getSize();
  245. this.maxNode.setStyles({
  246. "height": ""+size.y+"px",
  247. "width": ""+size.x+"px"
  248. });
  249. this.maxNode.position({
  250. "relativeTo": this.container,
  251. "position": "upperLeft",
  252. "edge": "upperLeft"
  253. });
  254. },
  255. loadRankUnitData: function(callback){
  256. if (!this.unitRankData){
  257. this.unitRankData = this.app.actions.getRankData(this.summary.organizationData.unit || []);
  258. if (callback) callback();
  259. }else{
  260. if (callback) callback();
  261. }
  262. },
  263. // loadRankCompanyData: function(callback){
  264. // if (!this.companyRankData){
  265. // this.companyRankData = this.app.actions.getRankData(this.summary.organizationData.company || []);
  266. // if (callback) callback();
  267. // }else{
  268. // if (callback) callback();
  269. // }
  270. // },
  271. // loadRankDepartmentData: function(callback){
  272. // if (!this.departmentRankData){
  273. // this.departmentRankData = this.app.actions.getRankData(this.summary.organizationData.department || []);
  274. // if (callback) callback();
  275. // }else{
  276. // if (callback) callback();
  277. // }
  278. // },
  279. loadRankPersonData: function(callback){
  280. if (!this.personRankData){
  281. this.personRankData = this.app.actions.getRankData(this.summary.organizationData.person || []);
  282. if (callback) callback();
  283. }else{
  284. if (callback) callback();
  285. }
  286. },
  287. destroy: function(){
  288. if (this.durationBar) this.durationBar.destroy();
  289. if (this.elapsedCountBar) this.elapsedCountBar.destroy();
  290. if (this.completedCountBar) this.completedCountBar.destroy();
  291. if (this.completedTimelinessBar) this.completedTimelinessBar.destroy();
  292. if (this.timeoutRateBar) this.timeoutRateBar.destroy();
  293. MWF.release(this);
  294. }
  295. });