TaskWidget.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.TaskCenter = MWF.xApplication.process.TaskCenter || {};
  3. MWF.xApplication.process.TaskCenter.TaskWidget = new Class({
  4. Extends: MWF.xApplication.Common.Widget,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "title": MWF.xApplication.process.TaskCenter.LP.title,
  9. "appName": "process.TaskCenter",
  10. "name": "TaskWidget",
  11. "position": {"right": 10, "bottom": 10},
  12. "width": "400",
  13. "height": "550"
  14. },
  15. init: function(){
  16. this.isItemsLoaded = false;
  17. this.isItemLoadding = false;
  18. this.loadItemQueue = 0;
  19. this.items = [];
  20. this.pageCount = 10;
  21. },
  22. loadContent: function(callback){
  23. // this.content.set("text", "ok")
  24. this.init();
  25. this.addEvent("scroll", function(y){
  26. var scrollSize = this.widget.contentScrollNode.getScrollSize();
  27. var clientSize = this.widget.contentScrollNode.getSize();
  28. var scrollHeight = scrollSize.y-clientSize.y;
  29. if (y+60>scrollHeight) {
  30. if (!this.isElementLoaded) this.listItemNext();
  31. }
  32. }.bind(this));
  33. this.addEvent("dragComplete", function(el, e){
  34. var p = this.widget.node.getPosition(this.widget.node.getOffsetParent());
  35. this.options.position = {"top": p.y, "left": p.x};
  36. });
  37. this.listItemNext();
  38. if (callback) callback();
  39. },
  40. listItemNext: function(count){
  41. if (!this.isItemsLoaded){
  42. if (!this.isItemLoadding){
  43. this.isItemLoadding = true;
  44. this._getCurrentPageData(function(json){
  45. this.count = json.count;
  46. if (json.count<=this.items.length){
  47. this.isItemsLoaded = true;
  48. }
  49. json.data.each(function(task){
  50. this.items.push(new MWF.xApplication.process.TaskCenter.TaskWidget.Item(task, this));
  51. }.bind(this));
  52. this.isItemLoadding = false;
  53. if (this.loadItemQueue>0){
  54. this.loadItemQueue--;
  55. this.listItemNext();
  56. }
  57. }.bind(this), count);
  58. }else{
  59. this.loadItemQueue++;
  60. }
  61. }
  62. },
  63. _getCurrentPageData: function(callback, count){
  64. this.getAction(function(){
  65. var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  66. this.action.listTaskNext(function(json){
  67. if (callback) callback(json);
  68. }, null, id, count || this.pageCount);
  69. }.bind(this));
  70. },
  71. getAction: function(callback){
  72. if (!this.action){
  73. this.action = MWF.Actions.get("x_processplatform_assemble_surface");
  74. if (callback) callback();
  75. // MWF.xDesktop.requireApp("process.TaskCenter", "Actions.RestActions", function(){
  76. // this.action = new MWF.xApplication.process.TaskCenter.Actions.RestActions();
  77. // if (callback) callback();
  78. // }.bind(this));
  79. }else{
  80. if (callback) callback();
  81. }
  82. }
  83. });
  84. MWF.xApplication.process.TaskCenter.TaskWidget.Item = new Class({
  85. initialize: function (data, list) {
  86. this.data = data;
  87. this.list = list;
  88. this.container = this.list.content;
  89. this.load();
  90. },
  91. load: function () {
  92. this.node = new Element("div", {"styles": this.list.css.itemNode}).inject(this.container);
  93. this.iconNode = new Element("div", {"styles": this.list.css.itemIconNode}).inject(this.node);
  94. this.actionAreaNode = new Element("div", {"styles": this.list.css.itemActionAreaNode}).inject(this.node);
  95. this.contentNode = new Element("div", {"styles": this.list.css.itemContentNode}).inject(this.node);
  96. this.inforTopNode = new Element("div", {"styles": this.list.css.itemInforTopNode}).inject(this.contentNode);
  97. this.inforTopActivityNode = new Element("div", {"styles": this.list.css.itemInforTopActivityNode}).inject(this.inforTopNode);
  98. this.inforTopTimeNode = new Element("div", {"styles": this.list.css.itemInforTopTimeNode}).inject(this.inforTopNode);
  99. this.titleNode = new Element("div", {"styles": this.list.css.itemTitleNode}).inject(this.contentNode);
  100. this.inforBottomNode = new Element("div", {"styles": this.list.css.itemInforBottomNode}).inject(this.contentNode);
  101. this.setContent();
  102. //this.setNewIcon();
  103. this.setEvent();
  104. },
  105. setContent: function(){
  106. var i = (Math.random()*10).toInt();
  107. if ((i % 2)==0){
  108. this.iconNode.setStyle("background-image", "url("+"../x_component_process_TaskCenter/$TaskWidget/default/read2.png)");
  109. }else{
  110. this.iconNode.setStyle("background-image", "url("+"../x_component_process_TaskCenter/$TaskWidget/default/task2.png)");
  111. }
  112. this.inforTopActivityNode.set("text", this.data.activityName);
  113. this.inforTopTimeNode.set("text", this.data.startTime);
  114. this.titleNode.set("text", this.data.title);
  115. this.inforBottomNode.set("text", this.data.applicationName+">>"+this.data.processName);
  116. },
  117. setEvent: function(){
  118. this.contentNode.addEvent("click", function(){
  119. this.openTask();
  120. }.bind(this));
  121. },
  122. openTask: function(e){
  123. var options = {"workId": this.data.work};
  124. this.list.desktop.openApplication(e, "process.Work", options, {"taskObject": this});
  125. },
  126. destroy: function(){
  127. this.node.destroy();
  128. delete this.node;
  129. delete this.iconNode;
  130. delete this.actionAreaNode;
  131. delete this.contentNode;
  132. delete this.inforTopNode;
  133. delete this.inforTopActivityNode;
  134. delete this.inforTopTimeNode;
  135. delete this.titleNode;
  136. delete this.inforBottomNode;
  137. delete this;
  138. }
  139. });