CenterWorkList.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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("Execution","Attachment",null,false);
  6. MWF.require("MWF.widget.Identity", null,false);
  7. MWF.xApplication.ExeManager.CenterWorkList = 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/$CenterWorkList/";
  18. this.loadCss();
  19. this.actions = actions;
  20. this.node = $(node);
  21. },
  22. loadCss: function () {
  23. this.cssPath = "/x_component_ExeManager/$CenterWorkList/" + 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.centerWorkList.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.centerWorkList.searchAction
  72. }).inject(this.toolBarSearchDiv);
  73. this.toolBarSearchActionBtn.addEvents({
  74. "click":function(e){
  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.centerWorkList.warnTitle,this.lp.centerWorkList.warnContent,300,120,function(){
  93. _self.toolBarStatusDiv.setStyle("display","");
  94. //removeDoc(_self.checkedDoc)
  95. __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.deleteCenterWork(removeDocs[0].data.id,function(json){
  113. }.bind(_self),function(xhr,error,text){
  114. _self.app.notice(_self.lp.centerWorkList.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. 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.CenterWorkList.View(this.contentDiv, this.app, {explorer:this,lp : this.lp.centerWorkList, 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. if (xhr) errorMessage = xhr.responseText;
  165. try{
  166. var e = JSON.parse(errorMessage);
  167. if (e && e.message) {
  168. this.app.notice(e.message, "error");
  169. } else {
  170. this.app.notice(errorText, "error");
  171. }
  172. }catch(e){
  173. this.app.notice("failure", "error");
  174. }
  175. }
  176. });
  177. MWF.xApplication.ExeManager.CenterWorkList.View = new Class({
  178. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  179. _createDocument: function(data){
  180. return new MWF.xApplication.ExeManager.CenterWorkList.Document(this.viewNode, data, this.explorer, this);
  181. },
  182. _getCurrentPageData: function(callback, count){
  183. if (!count)count = 20;
  184. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  185. var filter = this.options.filterData || {};
  186. if(id=="(0)")this.app.createShade();
  187. this.actions.getCenterWorkListNext(id, count, filter, function (json) {
  188. if (callback)callback(json);
  189. this.app.destroyShade();
  190. }.bind(this),function(xhr,error,text){
  191. }.bind(this))
  192. },
  193. _create: function(){
  194. },
  195. _openDocument: function( documentData ){
  196. this.workForm = new MWF.xApplication.ExeManager.CenterWorkList.WorkForm(this.explorer.explorer, this.actions, documentData, {
  197. "isNew": false,
  198. "isEdited": false,
  199. "onPostSave" : function(){
  200. this.view.explorer.contentChanged = true;
  201. }.bind(this)
  202. });
  203. this.workForm.load();
  204. },
  205. _queryCreateViewNode: function(){
  206. },
  207. _postCreateViewNode: function( viewNode ){
  208. },
  209. _queryCreateViewHead:function(){
  210. },
  211. _postCreateViewHead: function( headNode ){
  212. }
  213. });
  214. MWF.xApplication.ExeManager.CenterWorkList.Document = new Class({
  215. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  216. action_remove: function(e){
  217. var _self = this;
  218. this.app.confirm("warn",e,this.lp.warnTitle,this.lp.warnContent,300,120,function(){
  219. _self.actions.deleteCenterWork(_self.data.id,function(json){
  220. _self.view.explorer.explorer.reload();
  221. _self.view.explorer.explorer.resizeWindow();
  222. }.bind(_self),function(xhr,error,text){
  223. _self.view.explorer.showErrorMsg(xhr,error,text);
  224. }.bind(_self),false);
  225. _self.app.notice(_self.lp.removeResult.success, "success");
  226. this.close();
  227. },function(){
  228. this.close();
  229. })
  230. }
  231. });
  232. MWF.xApplication.ExeManager.CenterWorkList.WorkForm = new Class({
  233. Extends: MPopupForm,
  234. Implements: [Options, Events],
  235. options: {
  236. "style": "default",
  237. "width": "800",
  238. "height": "100%",
  239. "top" : 0,
  240. "left" : 0,
  241. "hasTop": true,
  242. "hasIcon": false,
  243. "hasBottom": true,
  244. "title": "",
  245. "draggable": false,
  246. "closeAction": true,
  247. "isNew": false,
  248. "isEdited": false
  249. },
  250. initialize: function (explorer, actions, data, options) {
  251. this.setOptions(options);
  252. this.explorer = explorer;
  253. this.app = explorer.app;
  254. this.lp = this.app.lp.centerWorkForm;
  255. this.actions = this.app.restActions;
  256. this.path = "/x_component_ExeManager/$CenterWorkList/";
  257. this.cssPath = this.path + this.options.style + "/centerWorkForm.wcss";
  258. this._loadCss();
  259. this.options.title = this.lp.title;
  260. this.data = data || {};
  261. this.actions = actions;
  262. },
  263. load: function () {
  264. //if(this.data.title) this.data.centerWorkTitle = this.data.title
  265. //this.data.centerWorkTitle = "ttttttttttttttttttttt"
  266. if (this.options.isNew) {
  267. this.create();
  268. } else if (this.options.isEdited) {
  269. this.edit();
  270. } else {
  271. this.open();
  272. }
  273. },
  274. _open: function () {
  275. this.formMarkNode = new Element("div.formMarkNode", {
  276. "styles": this.css.formMarkNode,
  277. "events": {
  278. "mouseover": function (e) {
  279. e.stopPropagation();
  280. },
  281. "mouseout": function (e) {
  282. e.stopPropagation();
  283. },
  284. "click": function (e) {
  285. e.stopPropagation();
  286. }
  287. }
  288. }).inject(this.app.content);
  289. this.formAreaNode = new Element("div.formAreaNode", {
  290. "styles": this.css.formAreaNode
  291. });
  292. this.createFormNode();
  293. this.formAreaNode.inject(this.formMarkNode, "after");
  294. this.formAreaNode.fade("in");
  295. this.setFormNodeSize();
  296. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  297. this.app.addEvent("resize", this.setFormNodeSizeFun);
  298. if (this.options.draggable && this.formTopNode) {
  299. var size = this.app.content.getSize();
  300. var nodeSize = this.formAreaNode.getSize();
  301. this.formAreaNode.makeDraggable({
  302. "handle": this.formTopNode,
  303. "limit": {
  304. "x": [0, size.x - nodeSize.x],
  305. "y": [0, size.y - nodeSize.y]
  306. }
  307. });
  308. }
  309. },
  310. _close: function(){
  311. if(this.formMarkNode)this.formMarkNode.destroy()
  312. },
  313. createTopNode: function () {
  314. if (!this.formTopNode) {
  315. this.formTopNode = new Element("div.formTopNode", {
  316. "styles": this.css.formTopNode
  317. }).inject(this.formNode);
  318. this.formTopIconNode = new Element("div", {
  319. "styles": this.css.formTopIconNode
  320. }).inject(this.formTopNode);
  321. this.formTopTextNode = new Element("div", {
  322. "styles": this.css.formTopTextNode,
  323. "text": this.options.title + ( this.data.title ? ("-" + this.data.title ) : "" )
  324. }).inject(this.formTopNode);
  325. if (this.options.closeAction) {
  326. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  327. this.formTopCloseActionNode.addEvent("click", function () {
  328. this.close()
  329. }.bind(this))
  330. }
  331. this.formTopContentNode = new Element("div", {
  332. "styles": this.css.formTopContentNode
  333. }).inject(this.formTopNode);
  334. this._createTopContent();
  335. }
  336. },
  337. _createTopContent: function () {
  338. },
  339. _createTableContent: function () {
  340. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  341. "<tr>" +
  342. " <td styles='formTableTitle' lable='centerWorkTitle'></td>" +
  343. " <td colspan='3' styles='formTableValue' item='centerWorkTitle'></td>" +
  344. "</tr><tr>" +
  345. " <td styles='formTableTitle' lable='checkLeader'></td>" +
  346. " <td colspan='3' styles='formTableValue' item='checkLeader'></td>" +
  347. "</tr><tr>" +
  348. " <td styles='formTableTitle' lable='workType'></td>" +
  349. " <td styles='formTableValue' item='workType'></td>" +
  350. " <td styles='formTableTitle' lable='defaultCompleteDateLimitStr'></td>" +
  351. " <td styles='formTableValue' item='defaultCompleteDateLimitStr'></td>" +
  352. "</tr><tr>" +
  353. " <td styles='formTableTitle' lable='workDescription'></td>" +
  354. " <td styles='formTableValue' item='workDescription' colspan='3'></td>" +
  355. "</tr>"+
  356. "</table>";
  357. this.formTableArea.set("html", html);
  358. this.loadForm();
  359. },
  360. loadForm: function(){
  361. this.form = new MForm(this.formTableArea, this.data, {
  362. style: "execution",
  363. isEdited: this.isEdited || this.isNew,
  364. itemTemplate: this.getItemTemplate(this.lp )
  365. },this.app);
  366. this.form.load();
  367. //this.attachmentArea = this.formTableArea.getElement("[item='attachments']");
  368. //this.loadAttachment( this.attachmentArea );
  369. },
  370. getItemTemplate: function( lp ){
  371. _self = this;
  372. return {
  373. centerWorkTitle: {text: lp.centerWorkTitle + ":",name:"title"},
  374. checkLeader:{text:lp.checkLeader+":",name:"reportAuditLeaderIdentity"},
  375. workType:{text:lp.workType+":",name:"defaultWorkType"},
  376. defaultCompleteDateLimitStr:{text:lp.defaultCompleteDateLimitStr+":",name:"defaultCompleteDateLimitStr"},
  377. workDescription:{text:lp.workDescription+":",name:"description"}
  378. }
  379. },
  380. loadAttachment: function( area ){
  381. this.attachment = new MWF.xApplication.Execution.Attachment( area, this.app, this.actions, this.app.lp, {
  382. documentId : this.data.id,
  383. isNew : this.options.isNew,
  384. isEdited : this.options.isEdited,
  385. onQueryUploadAttachment : function(){
  386. this.attachment.isQueryUploadSuccess = true;
  387. if( !this.data.id || this.data.id=="" ){
  388. var data = this.form.getResult(true, ",", true, false, true);
  389. if( !data ){
  390. this.attachment.isQueryUploadSuccess = false;
  391. return;
  392. }
  393. if(this.options.isNew){
  394. data.title = data.workDetail;
  395. data.deployerName = this.app.user;
  396. data.creatorName = this.app.user;
  397. data.centerId = this.data.centerWorkId || this.data.centerId ;
  398. }
  399. this.app.restActions.saveTask(data, function(json){
  400. if(json.type && json.type == "success"){
  401. if(json.data && json.data.id) {
  402. this.attachment.options.documentId = json.data.id;
  403. this.data.id = json.data.id;
  404. //this.options.isNew = false;
  405. }
  406. }
  407. }.bind(this),null,false)
  408. }
  409. }.bind(this)
  410. });
  411. this.attachment.load();
  412. },
  413. _createBottomContent: function () {
  414. this.cancelActionNode = new Element("div.formCancelActionNode", {
  415. "styles": this.css.formCancelActionNode,
  416. "text": this.lp.close
  417. }).inject(this.formBottomNode);
  418. this.cancelActionNode.addEvent("click", function (e) {
  419. this.cancel(e);
  420. }.bind(this));
  421. }
  422. });