CenterWorkList.js 18 KB

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