TaskContent.js 13 KB

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