TaskSub.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. MWF.xApplication.TeamWork = MWF.xApplication.TeamWork || {};
  2. MWF.xApplication.TeamWork.TaskSub = new Class({
  3. Extends: MPopupForm,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "width": 600,
  8. "height": 450,
  9. "top": 100,
  10. "left": null,
  11. "bottom" : null,
  12. "right" : null,
  13. "minWidth" : 300,
  14. "minHeight" : 220,
  15. "isLimitSize": true,
  16. "ifFade": true,
  17. "hasTop": false,
  18. "hasTopIcon" : false,
  19. "hasTopContent" : false,
  20. "hasIcon": false,
  21. "hasBottom": false,
  22. "hasMask" : true,
  23. "closeByClickMask" : true,
  24. "hasScroll" : false,
  25. "scrollType" : "",
  26. "title": "",
  27. "draggable": false,
  28. "resizeable" : false,
  29. "maxAction" : false,
  30. "closeAction": false,
  31. "relativeToApp" : true,
  32. "sizeRelateTo" : "app", //desktop
  33. "resultSeparator" : ","
  34. },
  35. initialize: function (explorer, data, options, para) {
  36. this.setOptions(options);
  37. this.explorer = explorer;
  38. this.app = this.explorer.app;
  39. this.container = this.app.content;
  40. this.lp = this.app.lp.taskSub;
  41. //this.actions = this.explorer.actions || this.app.actions || this.app.rectActions;
  42. this.rootActions = this.app.rootActions;
  43. this.actions = this.rootActions.TaskAction;
  44. this.data = data || {};
  45. this.cssPath = "../x_component_TeamWork/$TaskSub/"+this.options.style+"/css.wcss";
  46. this.load();
  47. },
  48. _createTableContent: function () {
  49. //this.formTableArea
  50. this.topLayout = new Element("div.topLayout",{styles:this.css.topLayout}).inject(this.formTableArea);
  51. this.createTopLayout();
  52. this.contentLayout = new Element("div.contentLayout",{styles:this.css.contentLayout}).inject(this.formTableArea);
  53. this.createContentLayout();
  54. this.bottomLayout = new Element("div.bottomLayout",{styles:this.css.bottomLayout}).inject(this.formTableArea);
  55. this.createBottomLayout();
  56. },
  57. createTopLayout:function(){
  58. this.topLayout.empty();
  59. this.topLayout.set("text",this.lp.title)
  60. },
  61. createContentLayout:function(){
  62. this.contentLayout.empty();
  63. this.searchDiv = new Element("div.searchDiv",{styles:this.css.searchDiv}).inject(this.contentLayout);
  64. this.searchInput = new Element("input.searchInput",{styles:this.css.searchInput,placeHolder:this.lp.searchPlace}).inject(this.searchDiv);
  65. this.searchInput.addEvents({
  66. keyup:function(e){
  67. var keycode = (e.event.keyCode ? e.event.keyCode : e.event.which);
  68. var key = this.searchInput.get("value").trim();
  69. if(keycode == 13 && key !=""){
  70. this.total = 0;
  71. this.curCount = 0;
  72. this.searchReset.show();
  73. this.taskListLayout.empty();
  74. this.loadTaskList(null,key);
  75. this.createBottomLayout();
  76. delete this.selectedItem;
  77. }
  78. }.bind(this),
  79. focus:function(){
  80. this.searchDiv.setStyles({"border":"1px solid #4A90E2"});
  81. }.bind(this),
  82. blur:function(){
  83. this.searchDiv.setStyles({"border":"1px solid #A6A6A6"});
  84. }.bind(this)
  85. });
  86. this.searchReset = new Element("div.searchReset",{styles:this.css.searchReset}).inject(this.searchDiv);
  87. this.searchReset.addEvents({
  88. mouseover:function(){ this.setStyles({"background-image":"url(../x_component_TeamWork/$TaskSub/default/icon/icon_off_click.png)"}) },
  89. mouseout:function(){ this.setStyles({"background-image":"url(../x_component_TeamWork/$TaskSub/default/icon/icon_off.png)"}) },
  90. click:function(){
  91. this.total = 0;
  92. this.curCount = 0;
  93. this.searchInput.set("value","");
  94. this.searchReset.show();
  95. this.searchReset.hide();
  96. this.taskListLayout.empty();
  97. this.loadTaskList();
  98. this.createBottomLayout();
  99. delete this.selectedItem;
  100. }.bind(this)
  101. });
  102. this.taskListLayout = new Element("div.taskListLayout",{styles:this.css.taskListLayout}).inject(this.contentLayout);
  103. this.taskListLayout.addEvents({
  104. scroll:function(){
  105. var stop = this.taskListLayout.getScrollTop();
  106. var cheight= this.taskListLayout.getSize().y;
  107. var sheight = this.taskListLayout.getScrollHeight();
  108. var borderWidth = this.taskListLayout.getBorder()["border-top-width"].toInt()+this.taskListLayout.getBorder()["border-bottom-width"].toInt();
  109. if(sheight == stop + cheight-borderWidth && this.isLoaded && this.curCount < this.total){
  110. this.loadTaskList(this.listId);
  111. }
  112. }.bind(this)
  113. });
  114. this.loadTaskList()
  115. },
  116. loadTaskList:function(id,key){
  117. var tmploading = new Element("div.loading",{styles:{"width":"500px"}}).inject(this.taskListLayout);
  118. this.app.setLoading(tmploading);
  119. this.taskListLayout.scrollTo(0,this.taskListLayout.getScrollSize().y);
  120. var id = this.listId = id||"(0)";
  121. var count=10;
  122. var filter = {
  123. project:this.data.data.project
  124. };
  125. if(key && key!=""){
  126. filter.title = key
  127. }
  128. this.total = this.total || 0;
  129. this.curCount = this.curCount || 0;
  130. this.isLoaded = false;
  131. //alert("curcount="+this.curCount+"total="+this.total);alert(id)
  132. this.actions.listNextWithFilter(id,count,filter,function(json){
  133. this.total = json.count;
  134. this.taskListData = json.data;
  135. tmploading.destroy();
  136. this.taskListData.each(function(d,i){
  137. this.loadTaskItem(d);
  138. id = d.id;
  139. this.listId = d.id;
  140. this.curCount = this.curCount + 1;
  141. this.isLoaded = true;
  142. }.bind(this));
  143. }.bind(this))
  144. },
  145. loadTaskItem:function(data){
  146. var _self = this;
  147. var taskItem = new Element("div.taskItem",{styles:this.css.taskItem,id:data.id}).inject(this.taskListLayout);
  148. taskItem.addEvents({
  149. mouseover:function(){
  150. if(_self.selectedItem == this)return;
  151. this.setStyles({"background-color":"#f2f5f7"})
  152. },
  153. mouseout:function(){
  154. if(_self.selectedItem == this)return;
  155. this.setStyles({"background-color":""})
  156. },
  157. click:function(){
  158. if(_self.selectedItem){
  159. _self.selectedItem.setStyles({"background-color":""});
  160. _self.selectedItem.getElements(".taskName").setStyles({"color":"#666666"});
  161. }
  162. this.setStyles({"background-color":"#3da8f5"});
  163. this.getElements(".taskName").setStyles({"color":"#ffffff"});
  164. _self.okAction.setStyles({
  165. "cursor":"pointer",
  166. "background-color":"#4A90E2"
  167. });
  168. _self.selectedItem = this;
  169. }
  170. });
  171. var taskName = new Element("div.taskName",{styles:this.css.taskName,text:data.name}).inject(taskItem);
  172. var n = data.executor.split("@")[0];
  173. n = n.substr(0,1);
  174. var taskPerson = new Element("div.taskPerson",{styles:this.css.taskPerson,text:n}).inject(taskItem);
  175. },
  176. createBottomLayout:function(){
  177. this.bottomLayout.empty();
  178. this.okAction = new Element("div.okAction",{styles:this.css.okAction,text:this.lp.ok}).inject(this.bottomLayout);
  179. this.okAction.addEvents({
  180. click:function(){
  181. if(this.selectedItem){
  182. var data = {
  183. parent : this.selectedItem.get("id"),
  184. id:this.data.data.id
  185. };
  186. if(this.selectedItem.get("id") == this.data.data.id){
  187. this.app.notice(this.lp.subToSelf,"info");
  188. return ;
  189. }
  190. this.actions.transformAsSubTask(this.data.data.id,this.selectedItem.get("id"),function(json){
  191. this.explorer._createTableContent();
  192. this.close();
  193. }.bind(this));
  194. // this.actions.save(data,function(json){
  195. // this.explorer._createTableContent();
  196. // this.close();
  197. // }.bind(this))
  198. }
  199. }.bind(this)
  200. })
  201. }
  202. });