BaseWorkList.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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("ExeManager","Attachment",null,false);
  5. MWF.require("MWF.widget.Identity", null,false);
  6. MWF.xApplication.ExeManager.BaseWorkList = 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/$BaseWorkList/";
  17. this.loadCss();
  18. this.actions = actions;
  19. this.node = $(node);
  20. },
  21. loadCss: function () {
  22. this.cssPath = "/x_component_ExeManager/$BaseWorkList/" + 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.baseWorkList.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.baseWorkList.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.baseWorkList.warnTitle,this.lp.baseWorkList.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.deleteBaseWork(removeDocs[0].data.id,function(json){
  112. }.bind(_self),function(xhr,error,text){
  113. _self.app.notice(_self.lp.baseWorkList.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.BaseWorkList.View(this.contentDiv, this.app, {explorer:this,lp : this.lp.baseWorkList, 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.BaseWorkList.View = new Class({
  177. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  178. _createDocument: function(data){
  179. return new MWF.xApplication.ExeManager.BaseWorkList.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.getBaseWorkListNext(id, count, filter, function (json) {
  187. if (callback)callback(json);
  188. this.app.destroyShade();
  189. }.bind(this),function(xhr,error,text){
  190. this.explorer.explorer.showErrorMsg(xhr,error,text)
  191. }.bind(this))
  192. },
  193. _create: function(){
  194. },
  195. _openDocument: function( documentData ){
  196. this.workForm = new MWF.xApplication.ExeManager.BaseWorkList.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.BaseWorkList.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.deleteBaseWork(_self.data.id,function(json){
  220. _self.app.notice(_self.lp.removeResult.success, "success");
  221. _self.view.explorer.explorer.reload();
  222. _self.view.explorer.explorer.resizeWindow();
  223. }.bind(_self),function(xhr,error,text){
  224. _self.view.explorer.explorer.showErrorMsg(xhr,error,text);
  225. }.bind(_self),false)
  226. this.close();
  227. },function(){
  228. this.close();
  229. })
  230. }
  231. })
  232. MWF.xApplication.ExeManager.BaseWorkList.WorkForm = new Class({
  233. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  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.baseWorkForm;
  255. this.actions = this.app.restActions;
  256. this.path = "/x_component_ExeManager/$BaseWorkList/";
  257. this.cssPath = this.path + this.options.style + "/baseWorkForm.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.id){
  265. this.actions.getBaseWorkDetails(this.data.id, function (json) {
  266. this.data.workSplitAndDescription = json.data.workDetail
  267. this.data.specificActionInitiatives = json.data.progressAction
  268. this.data.cityCompanyDuty = json.data.dutyDescription
  269. this.data.milestoneMark = json.data.landmarkDescription
  270. this.data.importantMatters = json.data.majorIssuesDescription
  271. }.bind(this),null,false)
  272. }
  273. if (this.options.isNew) {
  274. this.create();
  275. } else if (this.options.isEdited) {
  276. this.edit();
  277. } else {
  278. this.open();
  279. }
  280. },
  281. _open: function () {
  282. this.formMarkNode = new Element("div.formMarkNode", {
  283. "styles": this.css.formMarkNode,
  284. "events": {
  285. "mouseover": function (e) {
  286. e.stopPropagation();
  287. },
  288. "mouseout": function (e) {
  289. e.stopPropagation();
  290. },
  291. "click": function (e) {
  292. e.stopPropagation();
  293. }
  294. }
  295. }).inject(this.app.content);
  296. this.formAreaNode = new Element("div.formAreaNode", {
  297. "styles": this.css.formAreaNode
  298. });
  299. this.createFormNode();
  300. this.formAreaNode.inject(this.formMarkNode, "after");
  301. this.formAreaNode.fade("in");
  302. this.setFormNodeSize();
  303. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  304. this.app.addEvent("resize", this.setFormNodeSizeFun);
  305. if (this.options.draggable && this.formTopNode) {
  306. var size = this.app.content.getSize();
  307. var nodeSize = this.formAreaNode.getSize();
  308. this.formAreaNode.makeDraggable({
  309. "handle": this.formTopNode,
  310. "limit": {
  311. "x": [0, size.x - nodeSize.x],
  312. "y": [0, size.y - nodeSize.y]
  313. }
  314. });
  315. }
  316. },
  317. createTopNode: function () {
  318. if (!this.formTopNode) {
  319. this.formTopNode = new Element("div.formTopNode", {
  320. "styles": this.css.formTopNode
  321. }).inject(this.formNode);
  322. this.formTopIconNode = new Element("div", {
  323. "styles": this.css.formTopIconNode
  324. }).inject(this.formTopNode)
  325. this.formTopTextNode = new Element("div", {
  326. "styles": this.css.formTopTextNode,
  327. "text": this.options.title + ( this.data.title ? ("-" + this.data.title ) : "" )
  328. }).inject(this.formTopNode)
  329. if (this.options.closeAction) {
  330. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  331. this.formTopCloseActionNode.addEvent("click", function () {
  332. this.close()
  333. }.bind(this))
  334. }
  335. this.formTopContentNode = new Element("div", {
  336. "styles": this.css.formTopContentNode
  337. }).inject(this.formTopNode)
  338. this._createTopContent();
  339. }
  340. },
  341. _createTopContent: function () {
  342. },
  343. _createTableContent: function () {
  344. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  345. "<tr>" +
  346. " <td styles='formTableTitle' lable='timeLimit'></td>" +
  347. " <td styles='formTableValue' item='timeLimit'></td>" +
  348. " <td styles='formTableTitle' lable='reportCycle'></td>" +
  349. " <td styles='formTableValue'><span item='reportCycle'></span><span item='reportDay' style='margin-left:5px'></span></td>" +
  350. "</tr><tr>" +
  351. " <td styles='formTableTitle' lable='dutyDepartment'></td>" +
  352. " <td styles='formTableValue' item='dutyDepartment'></td>" +
  353. " <td styles='formTableTitle' lable='dutyPerson'></td>" +
  354. " <td styles='formTableValue' item='dutyPerson'></td>" +
  355. "</tr><tr>" +
  356. " <td styles='formTableTitle' lable='secondDepartment'></td>" +
  357. " <td styles='formTableValue' item='secondDepartment'></td>" +
  358. " <td styles='formTableTitle' lable='secondPerson'></td>" +
  359. " <td styles='formTableValue' item='secondPerson'></td>" +
  360. "</tr><tr>" +
  361. " <td styles='formTableTitle' lable='readReader'></td>" +
  362. " <td styles='formTableValue' item='readReader' colspan='3'></td>" +
  363. "</tr><tr>" +
  364. " <td styles='formTableValue' colspan='4'>" +
  365. " <div styles='formTableTitleDiv' lable='workSplitAndDescription'></div>" +
  366. " <div styles='formTableValueDiv' item='workSplitAndDescription'></div>" +
  367. " </td>" +
  368. "</tr><tr>" +
  369. " <td styles='formTableValue' colspan='4'>" +
  370. " <div styles='formTableTitleDiv' lable='specificActionInitiatives'></div>" +
  371. " <div styles='formTableValueDiv' item='specificActionInitiatives'></div>" +
  372. " </td>" +
  373. "</tr><tr>" +
  374. "</tr><tr>" +
  375. " <td styles='formTableValue' colspan='4'>" +
  376. " <div styles='formTableTitleDiv' lable='milestoneMark'></div>" +
  377. " <div styles='formTableValueDiv' item='milestoneMark'></div>" +
  378. " </td>" +
  379. "</tr><tr>" +
  380. " <td styles='formTableValue' colspan='4'>" +
  381. " <div styles='formTableValueDiv' item='attachments'></div>"+
  382. " </td>" +
  383. "</tr>"+
  384. "</table>"
  385. this.formTableArea.set("html", html);
  386. this.loadForm();
  387. },
  388. loadForm: function(){
  389. this.form = new MForm(this.formTableArea, this.data, {
  390. style: "execution",
  391. isEdited: this.isEdited || this.isNew,
  392. itemTemplate: this.getItemTemplate(this.lp )
  393. },this.app);
  394. this.form.load();
  395. this.attachmentArea = this.formTableArea.getElement("[item='attachments']");
  396. this.loadAttachment( this.attachmentArea );
  397. },
  398. getItemTemplate: function( lp ){
  399. _self = this;
  400. return {
  401. timeLimit: {text: lp.timeLimit + ":", name:"completeDateLimitStr"},
  402. //workType: {
  403. // text: lp.workType + ":",
  404. // name: "workType"
  405. //},
  406. //workLevel: {
  407. // text: lp.workLevel + ":"
  408. //},
  409. //timeLimit: {text: lp.timeLimit + ":", name:"completeDateLimitStr"},
  410. reportCycle: {
  411. text: lp.reportCycle + ":"
  412. },
  413. reportDay: {
  414. name: "reportDayInCycle"
  415. },
  416. dutyDepartment: {text: lp.dutyDepartment + ":", tType: "department",name:"responsibilityOrganizationName"},
  417. dutyPerson: {text: lp.dutyPerson + ":",name:"responsibilityIdentity"},
  418. secondDepartment: {text: lp.secondDepartment + ":", tType: "department",name:"cooperateOrganizationName"},
  419. secondPerson: {text: lp.secondPerson + ":", tType: "identity",name:"cooperateIdentity", count: 0},
  420. readReader: {text: lp.readReader + ":", tType: "identity", name:"readLeaderIdentity",count: 0},
  421. subject: {text: lp.subject + ":",name:"title",notEmpty:true},
  422. workSplitAndDescription: {text: lp.workSplitAndDescription + ":", type: "textarea",name:"workDetail",notEmpty:true,style:{"height":"70px"}},
  423. specificActionInitiatives: {text: lp.specificActionInitiatives + ":", type: "textarea",name:"progressAction",style:{"height":"70px"}},
  424. cityCompanyDuty: {text: lp.cityCompanyDuty + ":", type: "textarea",name:"dutyDescription"},
  425. milestoneMark: {text: lp.milestoneMark + ":", type: "textarea",name:"landmarkDescription",style:{"height":"70px"}},
  426. importantMatters: {text: lp.importantMatters + ":", type: "textarea",name:"majorIssuesDescription"}
  427. }
  428. },
  429. loadAttachment: function( area ){
  430. this.attachment = new MWF.xApplication.ExeManager.Attachment( area, this.app, this.actions, this.app.lp, {
  431. documentId : this.data.id,
  432. isNew : this.options.isNew,
  433. isEdited : this.options.isEdited,
  434. onQueryUploadAttachment : function(){
  435. this.attachment.isQueryUploadSuccess = true;
  436. if( !this.data.id || this.data.id=="" ){
  437. var data = this.form.getResult(true, ",", true, false, true);
  438. if( !data ){
  439. this.attachment.isQueryUploadSuccess = false;
  440. return;
  441. }
  442. if(this.options.isNew){
  443. data.title = data.workDetail;
  444. data.deployerName = this.app.user;
  445. data.creatorName = this.app.user;
  446. data.centerId = this.data.centerWorkId || this.data.centerId ;
  447. }
  448. this.app.restActions.saveTask(data, function(json){
  449. if(json.type && json.type == "success"){
  450. if(json.data && json.data.id) {
  451. this.attachment.options.documentId = json.data.id;
  452. this.data.id = json.data.id;
  453. //this.options.isNew = false;
  454. }
  455. }
  456. }.bind(this),null,false)
  457. }
  458. }.bind(this)
  459. })
  460. this.attachment.load();
  461. },
  462. _createBottomContent: function () {
  463. this.cancelActionNode = new Element("div.formCancelActionNode", {
  464. "styles": this.css.formCancelActionNode,
  465. "text": this.lp.close
  466. }).inject(this.formBottomNode);
  467. this.cancelActionNode.addEvent("click", function (e) {
  468. this.cancel(e);
  469. }.bind(this));
  470. }
  471. })
  472. function removeDoc(obj){
  473. alert("before="+obj.length)
  474. //obj = obj.splice(0)
  475. alert("after="+obj.length)
  476. window.setInterval(function(){
  477. alert("in="+obj.length)
  478. },2000)
  479. }