WorkReportList.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. MWF.xApplication.ExeManager = MWF.xApplication.ExeManager || {};
  2. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  5. MWF.xDesktop.requireApp("ExeManager","Attachment",null,false);
  6. MWF.require("MWF.widget.Identity", null,false);
  7. MWF.xApplication.ExeManager.WorkReportList = new Class({
  8. Extends: MWF.widget.Common,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default"
  12. },
  13. initialize: function (node, app, actions, options) {
  14. this.setOptions(options);
  15. this.app = app;
  16. this.lp = app.lp;
  17. this.path = "/x_component_ExeManager/$WorkReportList/";
  18. this.loadCss();
  19. this.actions = actions;
  20. this.node = $(node);
  21. },
  22. loadCss: function () {
  23. this.cssPath = "/x_component_ExeManager/$WorkReportList/" + this.options.style + "/css.wcss";
  24. this._loadCss();
  25. },
  26. load: function () {
  27. this.middleContent = this.app.middleContent;
  28. this.middleContent.setStyles({"margin-top":"0px","border":"0px solid #f00","background-color":"#ffffff"});
  29. this.createToolBarContent();
  30. this.createContentDiv();
  31. this.resizeWindow();
  32. this.app.addEvent("resize", function(){
  33. this.resizeWindow();
  34. }.bind(this));
  35. },
  36. reload: function(){
  37. this.createToolBarContent();
  38. this.createContentDiv();
  39. },
  40. resizeWindow: function(){
  41. var size = this.app.middleContent.getSize();
  42. this.contentDiv.setStyles({"height":(size.y-110)+"px"});
  43. },
  44. createToolBarContent: function(){
  45. if(this.toolBarDiv) this.toolBarDiv.destroy();
  46. this.toolBarDiv = new Element("div.toolBarDiv",{"styles":this.css.toolBarDiv}).inject(this.middleContent);
  47. this.toolBarActionDiv = new Element("div.toolBarActionDiv",{"styles":this.css.toolBarActionDiv}).inject(this.toolBarDiv);
  48. this.toolBarActionBRemoveBtn = new Element("div.toolBarActionBRemoveBtn",{
  49. "styles":this.css.toolBarActionBtn,
  50. "text": this.lp.baseWorkList.remove
  51. }).inject(this.toolBarActionDiv);
  52. this.toolBarActionBRemoveBtn.addEvents({
  53. "click":function(e){
  54. this.checkedDoc = this.view.getCheckedItems();
  55. this.removeDocument(e);
  56. }.bind(this)
  57. });
  58. this.toolBarSearchDiv = new Element("div.toolBarSearchDiv",{"styles":this.css.toolBarSearchDiv}).inject(this.toolBarDiv);
  59. this.toolBarSearchInput = new Element("input.toolBarSearchInput",{
  60. "styles":this.css.toolBarSearchInput
  61. }).inject(this.toolBarSearchDiv);
  62. this.toolBarSearchInput.addEvents({
  63. "keyup":function(e){
  64. if(e.code == 13){
  65. this.searchView(this.toolBarSearchInput.get("value"))
  66. }
  67. }.bind(this)
  68. });
  69. this.toolBarSearchActionBtn = new Element("div.toolBarSearchBtn",{
  70. "styles":this.css.toolBarSearchBtn,
  71. "text": this.lp.baseWorkList.searchAction
  72. }).inject(this.toolBarSearchDiv);
  73. this.toolBarSearchActionBtn.addEvents({
  74. "click":function(){
  75. this.searchView(this.toolBarSearchInput.get("value"))
  76. }.bind(this)
  77. });
  78. //this.toolBarSearchResetBtn = new Element("div.toolBarSearchBtn",{
  79. // "styles":this.css.toolBarSearchBtn,
  80. // "text":"重置"
  81. //}).inject(this.toolBarSearchDiv);
  82. this.toolBarStatusDiv = new Element("div.toolBarStatusDiv",{
  83. "styles":this.css.toolBarStatusDiv
  84. }).inject(this.toolBarDiv);
  85. this.toolBarStatusDiv.setStyle("display","none");
  86. this.toolBarStatusAllDiv = new Element("div.toolBarStatusAllDiv",{styles:this.css.toolBarStatusAllDiv}).inject(this.toolBarStatusDiv);
  87. this.toolBarStatusPercentDiv = new Element("div.toolBarStatusPercentDiv",{styles:this.css.toolBarStatusPercentDiv}).inject(this.toolBarStatusDiv);
  88. },
  89. removeDocument:function(e) {
  90. var _self = this;
  91. var flag = true;
  92. this.app.confirm("warn",e,this.lp.baseWorkList.warnTitle,this.lp.baseWorkList.warnContent,300,120,function(){
  93. _self.toolBarStatusDiv.setStyle("display","");
  94. //removeDoc(_self.checkedDoc)
  95. var __self = this;
  96. var removeDocs = _self.checkedDoc;
  97. var removeDocsLen = removeDocs.length;
  98. var removeDocCurLen = 0;
  99. var timeInt = window.setInterval(function(){
  100. if(removeDocs.length==0 || !flag){
  101. clearInterval(timeInt);
  102. __self.close();
  103. _self.reload();
  104. _self.resizeWindow();
  105. }else{
  106. removeDocCurLen ++;
  107. var _width = removeDocCurLen / removeDocsLen;
  108. _width = _width * _self.toolBarStatusAllDiv.getSize().x;
  109. _self.toolBarStatusPercentDiv.set("text",removeDocCurLen+"/"+removeDocsLen);
  110. _self.toolBarStatusPercentDiv.setStyles({"width":_width+"px"});
  111. if( flag && removeDocs[0].data && removeDocs[0].data.id){
  112. _self.actions.deleteWorkReport(removeDocs[0].data.id,function(json){
  113. }.bind(_self),function(){
  114. _self.app.notice(_self.lp.baseWorkList.removeResult.failure+":"+removeDocs[0].data.title,"error");
  115. flag = false
  116. }.bind(_self),false)
  117. }
  118. removeDocs = removeDocs.slice(1,removeDocs.length);
  119. }
  120. }.bind(_self),10);
  121. },function(){
  122. this.close();
  123. })
  124. },
  125. createContentDiv: function(key){
  126. if(this.contentDiv) this.contentDiv.destroy();
  127. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.middleContent);
  128. if(this.scrollBar && this.scrollBar.scrollVAreaNode){
  129. this.scrollBar.scrollVAreaNode.destroy();
  130. }
  131. MWF.require("MWF.widget.ScrollBar", function () {
  132. this.scrollBar = new MWF.widget.ScrollBar(this.contentDiv, {
  133. "indent": false,
  134. "style": "xApp_TaskList",
  135. "where": "before",
  136. "distance": 30,
  137. "friction": 4,
  138. "axis": {"x": false, "y": true},
  139. "onScroll": function (y) {
  140. var scrollSize = this.contentDiv.getScrollSize();
  141. var clientSize = this.contentDiv.getSize();
  142. var scrollHeight = scrollSize.y - clientSize.y;
  143. var view = this.view;
  144. if (y + 200 > scrollHeight && view && view.loadElementList) {
  145. if (! view.isItemsLoaded) view.loadElementList();
  146. }
  147. }.bind(this)
  148. });
  149. }.bind(this),false);
  150. var templateUrl = this.path+"listItem.json";
  151. var filter = {
  152. filterLikeContent:key
  153. };
  154. if(this.view) delete this.view;
  155. this.view = new MWF.xApplication.ExeManager.WorkReportList.View(this.contentDiv, this.app, {explorer:this,lp : this.lp.workReportList, css : this.css, actions : this.actions }, { templateUrl : templateUrl,category:"",filterData:filter } );
  156. this.view.load();
  157. },
  158. searchView: function(key){
  159. this.createContentDiv(key);
  160. this.resizeWindow();
  161. },
  162. showErrorMsg: function(xhr,text,error){
  163. var errorText = error;
  164. var errorMessage;
  165. if (xhr) errorMessage = xhr.responseText;
  166. try{
  167. var e = JSON.parse(errorMessage);
  168. if (e && e.message) {
  169. this.app.notice(e.message, "error");
  170. } else {
  171. this.app.notice(errorText, "error");
  172. }
  173. }catch(e){
  174. this.app.notice("failure", "error");
  175. }
  176. }
  177. });
  178. MWF.xApplication.ExeManager.WorkReportList.View = new Class({
  179. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  180. _createDocument: function(data){
  181. return new MWF.xApplication.ExeManager.WorkReportList.Document(this.viewNode, data, this.explorer, this);
  182. },
  183. _getCurrentPageData: function(callback, count){
  184. if (!count)count = 20;
  185. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  186. var filter = this.options.filterData || {};
  187. if(id=="(0)")this.app.createShade();
  188. this.actions.getReportWorkListNext(id, count, filter, function (json) {
  189. if (callback)callback(json);
  190. this.app.destroyShade();
  191. }.bind(this),function(xhr,error,text){
  192. this.explorer.explorer.showErrorMsg(xhr,error,text)
  193. }.bind(this))
  194. },
  195. _create: function(){
  196. },
  197. _openDocument: function( documentData ){
  198. this.workForm = new MWF.xApplication.ExeManager.WorkReportList.WorkReportForm(this.explorer.explorer, this.actions, documentData, {
  199. "isNew": false,
  200. "isEdited": false,
  201. "onPostSave" : function(){
  202. this.view.explorer.contentChanged = true;
  203. }.bind(this)
  204. });
  205. this.workForm.load();
  206. },
  207. _queryCreateViewNode: function(){
  208. },
  209. _postCreateViewNode: function( viewNode ){
  210. },
  211. _queryCreateViewHead:function(){
  212. },
  213. _postCreateViewHead: function( headNode ){
  214. }
  215. });
  216. MWF.xApplication.ExeManager.WorkReportList.Document = new Class({
  217. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  218. action_remove: function(e){
  219. var _self = this;
  220. this.app.confirm("warn",e,this.lp.warnTitle,this.lp.warnContent,300,120,function(){
  221. _self.actions.deleteWorkReport(_self.data.id,function(){
  222. _self.app.notice(_self.lp.removeResult.success, "success");
  223. _self.view.explorer.explorer.reload();
  224. _self.view.explorer.explorer.resizeWindow();
  225. }.bind(_self),function(xhr,error,text){
  226. _self.view.explorer.explorer.showErrorMsg(xhr,error,text);
  227. }.bind(_self),false);
  228. this.close();
  229. },function(){
  230. this.close();
  231. })
  232. }
  233. });
  234. MWF.xApplication.ExeManager.WorkReportList.WorkReportForm = new Class({
  235. Extends: MPopupForm,
  236. Implements: [Options, Events],
  237. options: {
  238. "style": "default",
  239. "width": "800",
  240. "height": "100%",
  241. "top" : 0,
  242. "left" : 0,
  243. "hasTop": true,
  244. "hasIcon": false,
  245. "hasBottom": true,
  246. "title": "",
  247. "draggable": false,
  248. "closeAction": true,
  249. "isNew": false,
  250. "isEdited": false
  251. },
  252. initialize: function (explorer, actions, data, options) {
  253. this.setOptions(options);
  254. this.explorer = explorer;
  255. this.app = explorer.app;
  256. this.lp = this.app.lp.workReportForm;
  257. this.actions = this.app.restActions;
  258. this.path = "/x_component_ExeManager/$WorkReportList/";
  259. this.cssPath = this.path + this.options.style + "/workReportForm.wcss";
  260. this._loadCss();
  261. this.options.title = this.lp.title;
  262. this.data = data || {};
  263. this.actions = actions;
  264. },
  265. load: function () {
  266. if(this.data.id){
  267. this.actions.getWorkReport(this.data.id, function (json) {
  268. this.workReportData = json.data;
  269. }.bind(this),null,false)
  270. }
  271. if (this.options.isNew) {
  272. this.create();
  273. } else if (this.options.isEdited) {
  274. this.edit();
  275. } else {
  276. this.open();
  277. }
  278. },
  279. _open: function () {
  280. this.formMarkNode = new Element("div.formMarkNode", {
  281. "styles": this.css.formMarkNode,
  282. "events": {
  283. "mouseover": function (e) {
  284. e.stopPropagation();
  285. },
  286. "mouseout": function (e) {
  287. e.stopPropagation();
  288. },
  289. "click": function (e) {
  290. e.stopPropagation();
  291. }
  292. }
  293. }).inject(this.app.content);
  294. this.formAreaNode = new Element("div.formAreaNode", {
  295. "styles": this.css.formAreaNode
  296. });
  297. this.createFormNode();
  298. this.formAreaNode.inject(this.formMarkNode, "after");
  299. this.formAreaNode.fade("in");
  300. this.setFormNodeSize();
  301. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  302. this.app.addEvent("resize", this.setFormNodeSizeFun);
  303. if (this.options.draggable && this.formTopNode) {
  304. var size = this.app.content.getSize();
  305. var nodeSize = this.formAreaNode.getSize();
  306. this.formAreaNode.makeDraggable({
  307. "handle": this.formTopNode,
  308. "limit": {
  309. "x": [0, size.x - nodeSize.x],
  310. "y": [0, size.y - nodeSize.y]
  311. }
  312. });
  313. }
  314. },
  315. createTopNode: function () {
  316. if (!this.formTopNode) {
  317. this.formTopNode = new Element("div.formTopNode", {
  318. "styles": this.css.formTopNode
  319. }).inject(this.formNode);
  320. this.formTopIconNode = new Element("div", {
  321. "styles": this.css.formTopIconNode
  322. }).inject(this.formTopNode);
  323. this.formTopTextNode = new Element("div", {
  324. "styles": this.css.formTopTextNode,
  325. "text": this.options.title + ( this.workReportData.title ? ("-" + this.workReportData.title ) : "" )
  326. }).inject(this.formTopNode);
  327. if (this.options.closeAction) {
  328. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  329. this.formTopCloseActionNode.addEvent("click", function () {
  330. this.close()
  331. }.bind(this))
  332. }
  333. this.formTopContentNode = new Element("div", {
  334. "styles": this.css.formTopContentNode
  335. }).inject(this.formTopNode);
  336. this._createTopContent();
  337. }
  338. },
  339. _createTopContent: function () {
  340. },
  341. _createTableContent: function () {
  342. if(this.formTableArea) this.formTableArea.empty();
  343. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.formTableArea);
  344. var titleDiv = new Element("div.titleDiv",{"styles":this.css.titleDiv,"text":this.lp.title}).inject(this.contentDiv);
  345. var valueDiv = new Element("div.valueDiv",{"styles":this.css.valueDiv,"text":this.workReportData.title}).inject(this.contentDiv);
  346. titleDiv = new Element("div.titleDiv",{"styles":this.css.titleDiv,"text":this.lp.times}).inject(this.contentDiv);
  347. valueDiv = new Element("div.valueDiv",{"styles":this.css.valueDiv,"text":this.workReportData.shortTitle}).inject(this.contentDiv);
  348. titleDiv = new Element("div.titleDiv",{"styles":this.css.titleDiv,"text":this.lp.progressDescription}).inject(this.contentDiv);
  349. valueDiv = new Element("div.valueDiv",{"styles":this.css.valueDiv,"text":this.workReportData.progressDescription}).inject(this.contentDiv);
  350. titleDiv = new Element("div.titleDiv",{"styles":this.css.titleDiv,"text":this.lp.workPlan}).inject(this.contentDiv);
  351. valueDiv = new Element("div.valueDiv",{"styles":this.css.valueDiv,"text":this.workReportData.workPlan}).inject(this.contentDiv);
  352. },
  353. _createBottomContent: function () {
  354. this.cancelActionNode = new Element("div.formCancelActionNode", {
  355. "styles": this.css.formCancelActionNode,
  356. "text": this.lp.close
  357. }).inject(this.formBottomNode);
  358. this.cancelActionNode.addEvent("click", function (e) {
  359. this.cancel(e);
  360. }.bind(this));
  361. }
  362. });