CenterWorkList.js 18 KB

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