TaskSub.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. });
  80. this.searchReset = new Element("div.searchReset",{styles:this.css.searchReset}).inject(this.searchDiv);
  81. this.searchReset.addEvents({
  82. mouseover:function(){ this.setStyles({"background-image":"url(/x_component_TeamWork/$TaskSub/default/icon/icon_off_click.png)"}) },
  83. mouseout:function(){ this.setStyles({"background-image":"url(/x_component_TeamWork/$TaskSub/default/icon/icon_off.png)"}) },
  84. click:function(){
  85. this.total = 0;
  86. this.curCount = 0;
  87. this.searchInput.set("value","");
  88. this.searchReset.show();
  89. this.searchReset.hide();
  90. this.taskListLayout.empty();
  91. this.loadTaskList();
  92. this.createBottomLayout();
  93. delete this.selectedItem;
  94. }.bind(this)
  95. });
  96. this.taskListLayout = new Element("div.taskListLayout",{styles:this.css.taskListLayout}).inject(this.contentLayout);
  97. this.taskListLayout.addEvents({
  98. scroll:function(){
  99. var stop = this.taskListLayout.getScrollTop();
  100. var cheight= this.taskListLayout.getSize().y;
  101. var sheight = this.taskListLayout.getScrollHeight();
  102. var borderWidth = this.taskListLayout.getBorder()["border-top-width"].toInt()+this.taskListLayout.getBorder()["border-bottom-width"].toInt();
  103. if(sheight == stop + cheight-borderWidth && this.isLoaded && this.curCount < this.total){
  104. this.loadTaskList(this.listId);
  105. }
  106. }.bind(this)
  107. });
  108. this.loadTaskList()
  109. },
  110. loadTaskList:function(id,key){
  111. var tmploading = new Element("div.loading",{styles:{"width":"500px"}}).inject(this.taskListLayout);
  112. this.app.setLoading(tmploading);
  113. this.taskListLayout.scrollTo(0,this.taskListLayout.getScrollSize().y);
  114. var id = this.listId = id||"(0)";
  115. var count=10;
  116. var filter = {
  117. project:this.data.data.project
  118. };
  119. if(key && key!=""){
  120. filter.title = key
  121. }
  122. this.total = this.total || 0;
  123. this.curCount = this.curCount || 0;
  124. this.isLoaded = false;
  125. //alert("curcount="+this.curCount+"total="+this.total);alert(id)
  126. this.actions.listNextWithFilter(id,count,filter,function(json){
  127. this.total = json.count;
  128. this.taskListData = json.data;
  129. tmploading.destroy();
  130. this.taskListData.each(function(d,i){
  131. this.loadTaskItem(d);
  132. id = d.id;
  133. this.listId = d.id;
  134. this.curCount = this.curCount + 1;
  135. this.isLoaded = true;
  136. }.bind(this));
  137. }.bind(this))
  138. },
  139. loadTaskItem:function(data){
  140. var _self = this;
  141. var taskItem = new Element("div.taskItem",{styles:this.css.taskItem,id:data.id}).inject(this.taskListLayout);
  142. taskItem.addEvents({
  143. mouseover:function(){
  144. if(_self.selectedItem == this)return;
  145. this.setStyles({"background-color":"#f2f5f7"})
  146. },
  147. mouseout:function(){
  148. if(_self.selectedItem == this)return;
  149. this.setStyles({"background-color":""})
  150. },
  151. click:function(){
  152. if(_self.selectedItem){
  153. _self.selectedItem.setStyles({"background-color":""});
  154. _self.selectedItem.getElements(".taskName").setStyles({"color":"#666666"});
  155. }
  156. this.setStyles({"background-color":"#3da8f5"});
  157. this.getElements(".taskName").setStyles({"color":"#ffffff"});
  158. _self.okAction.setStyles({
  159. "cursor":"pointer",
  160. "background-color":"#4A90E2"
  161. });
  162. _self.selectedItem = this;
  163. }
  164. });
  165. var taskName = new Element("div.taskName",{styles:this.css.taskName,text:data.name}).inject(taskItem);
  166. var n = data.executor.split("@")[0];
  167. n = n.substr(0,1);
  168. var taskPerson = new Element("div.taskPerson",{styles:this.css.taskPerson,text:n}).inject(taskItem);
  169. },
  170. createBottomLayout:function(){
  171. this.bottomLayout.empty();
  172. this.okAction = new Element("div.okAction",{styles:this.css.okAction,text:this.lp.ok}).inject(this.bottomLayout);
  173. this.okAction.addEvents({
  174. click:function(){
  175. if(this.selectedItem){
  176. var data = {
  177. parent : this.selectedItem.get("id"),
  178. id:this.data.data.id
  179. };
  180. if(this.selectedItem.get("id") == this.data.data.id){
  181. this.app.notice(this.lp.subToSelf,"info");
  182. return ;
  183. }
  184. this.actions.save(data,function(json){
  185. this.explorer._createTableContent();
  186. this.close();
  187. }.bind(this))
  188. }
  189. }.bind(this)
  190. })
  191. }
  192. });