BaseWorkList.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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.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.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. this.actions.getBaseWorkListNext(id, count, filter, function (json) {
  186. if (callback)callback(json);
  187. }.bind(this),function(xhr,error,text){
  188. this.explorer.explorer.showErrorMsg(xhr,error,text)
  189. }.bind(this))
  190. },
  191. _create: function(){
  192. },
  193. _openDocument: function( documentData ){
  194. this.workForm = new MWF.xApplication.ExeManager.BaseWorkList.WorkForm(this.explorer.explorer, this.actions, documentData, {
  195. "isNew": false,
  196. "isEdited": false,
  197. "onPostSave" : function(){
  198. this.view.explorer.contentChanged = true;
  199. }.bind(this)
  200. })
  201. this.workForm.load();
  202. },
  203. _queryCreateViewNode: function(){
  204. },
  205. _postCreateViewNode: function( viewNode ){
  206. },
  207. _queryCreateViewHead:function(){
  208. },
  209. _postCreateViewHead: function( headNode ){
  210. }
  211. })
  212. MWF.xApplication.ExeManager.BaseWorkList.Document = new Class({
  213. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  214. action_remove: function(e){
  215. var _self = this;
  216. this.app.confirm("warn",e,this.lp.warnTitle,this.lp.warnContent,300,120,function(){
  217. _self.actions.deleteBaseWork(_self.data.id,function(json){
  218. _self.app.notice(_self.lp.removeResult.success, "success");
  219. _self.view.explorer.explorer.reload();
  220. _self.view.explorer.explorer.resizeWindow();
  221. }.bind(_self),function(xhr,error,text){
  222. _self.view.explorer.explorer.showErrorMsg(xhr,error,text);
  223. }.bind(_self),false)
  224. this.close();
  225. },function(){
  226. this.close();
  227. })
  228. }
  229. })
  230. MWF.xApplication.ExeManager.BaseWorkList.WorkForm = new Class({
  231. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  232. Implements: [Options, Events],
  233. options: {
  234. "style": "default",
  235. "width": "800",
  236. "height": "100%",
  237. "top" : 0,
  238. "left" : 0,
  239. "hasTop": true,
  240. "hasIcon": false,
  241. "hasBottom": true,
  242. "title": "",
  243. "draggable": false,
  244. "closeAction": true,
  245. "isNew": false,
  246. "isEdited": false
  247. },
  248. initialize: function (explorer, actions, data, options) {
  249. this.setOptions(options);
  250. this.explorer = explorer;
  251. this.app = explorer.app;
  252. this.lp = this.app.lp.baseWorkForm;
  253. this.actions = this.app.restActions;
  254. this.path = "/x_component_ExeManager/$BaseWorkList/";
  255. this.cssPath = this.path + this.options.style + "/baseWorkForm.wcss";
  256. this._loadCss();
  257. this.options.title = this.lp.title;
  258. this.data = data || {};
  259. this.actions = actions;
  260. },
  261. load: function () {
  262. if(this.data.id){
  263. this.actions.getBaseWorkDetails(this.data.id, function (json) {
  264. this.data.workSplitAndDescription = json.data.workDetail
  265. this.data.specificActionInitiatives = json.data.progressAction
  266. this.data.cityCompanyDuty = json.data.dutyDescription
  267. this.data.milestoneMark = json.data.landmarkDescription
  268. this.data.importantMatters = json.data.majorIssuesDescription
  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.data.title ? ("-" + this.data.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. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  343. "<tr>" +
  344. " <td styles='formTableTitle' lable='timeLimit'></td>" +
  345. " <td styles='formTableValue' item='timeLimit'></td>" +
  346. " <td styles='formTableTitle' lable='reportCycle'></td>" +
  347. " <td styles='formTableValue'><span item='reportCycle'></span><span item='reportDay' style='margin-left:5px'></span></td>" +
  348. "</tr><tr>" +
  349. " <td styles='formTableTitle' lable='dutyDepartment'></td>" +
  350. " <td styles='formTableValue' item='dutyDepartment'></td>" +
  351. " <td styles='formTableTitle' lable='dutyPerson'></td>" +
  352. " <td styles='formTableValue' item='dutyPerson'></td>" +
  353. "</tr><tr>" +
  354. " <td styles='formTableTitle' lable='secondDepartment'></td>" +
  355. " <td styles='formTableValue' item='secondDepartment'></td>" +
  356. " <td styles='formTableTitle' lable='secondPerson'></td>" +
  357. " <td styles='formTableValue' item='secondPerson'></td>" +
  358. "</tr><tr>" +
  359. " <td styles='formTableTitle' lable='readReader'></td>" +
  360. " <td styles='formTableValue' item='readReader' colspan='3'></td>" +
  361. "</tr><tr>" +
  362. " <td styles='formTableValue' colspan='4'>" +
  363. " <div styles='formTableTitleDiv' lable='workSplitAndDescription'></div>" +
  364. " <div styles='formTableValueDiv' item='workSplitAndDescription'></div>" +
  365. " </td>" +
  366. "</tr><tr>" +
  367. " <td styles='formTableValue' colspan='4'>" +
  368. " <div styles='formTableTitleDiv' lable='specificActionInitiatives'></div>" +
  369. " <div styles='formTableValueDiv' item='specificActionInitiatives'></div>" +
  370. " </td>" +
  371. "</tr><tr>" +
  372. "</tr><tr>" +
  373. " <td styles='formTableValue' colspan='4'>" +
  374. " <div styles='formTableTitleDiv' lable='milestoneMark'></div>" +
  375. " <div styles='formTableValueDiv' item='milestoneMark'></div>" +
  376. " </td>" +
  377. "</tr><tr>" +
  378. " <td styles='formTableValue' colspan='4'>" +
  379. " <div styles='formTableValueDiv' item='attachments'></div>"+
  380. " </td>" +
  381. "</tr>"+
  382. "</table>"
  383. this.formTableArea.set("html", html);
  384. this.loadForm();
  385. },
  386. loadForm: function(){
  387. this.form = new MForm(this.formTableArea, this.data, {
  388. style: "execution",
  389. isEdited: this.isEdited || this.isNew,
  390. itemTemplate: this.getItemTemplate(this.lp )
  391. },this.app);
  392. this.form.load();
  393. this.attachmentArea = this.formTableArea.getElement("[item='attachments']");
  394. this.loadAttachment( this.attachmentArea );
  395. },
  396. getItemTemplate: function( lp ){
  397. _self = this;
  398. return {
  399. timeLimit: {text: lp.timeLimit + ":", name:"completeDateLimitStr"},
  400. //workType: {
  401. // text: lp.workType + ":",
  402. // name: "workType"
  403. //},
  404. //workLevel: {
  405. // text: lp.workLevel + ":"
  406. //},
  407. //timeLimit: {text: lp.timeLimit + ":", name:"completeDateLimitStr"},
  408. reportCycle: {
  409. text: lp.reportCycle + ":"
  410. },
  411. reportDay: {
  412. name: "reportDayInCycle"
  413. },
  414. dutyDepartment: {text: lp.dutyDepartment + ":", tType: "department",name:"responsibilityOrganizationName"},
  415. dutyPerson: {text: lp.dutyPerson + ":",name:"responsibilityIdentity"},
  416. secondDepartment: {text: lp.secondDepartment + ":", tType: "department",name:"cooperateOrganizationName"},
  417. secondPerson: {text: lp.secondPerson + ":", tType: "identity",name:"cooperateIdentity", count: 0},
  418. readReader: {text: lp.readReader + ":", tType: "identity", name:"readLeaderIdentity",count: 0},
  419. subject: {text: lp.subject + ":",name:"title",notEmpty:true},
  420. workSplitAndDescription: {text: lp.workSplitAndDescription + ":", type: "textarea",name:"workDetail",notEmpty:true,style:{"height":"70px"}},
  421. specificActionInitiatives: {text: lp.specificActionInitiatives + ":", type: "textarea",name:"progressAction",style:{"height":"70px"}},
  422. cityCompanyDuty: {text: lp.cityCompanyDuty + ":", type: "textarea",name:"dutyDescription"},
  423. milestoneMark: {text: lp.milestoneMark + ":", type: "textarea",name:"landmarkDescription",style:{"height":"70px"}},
  424. importantMatters: {text: lp.importantMatters + ":", type: "textarea",name:"majorIssuesDescription"}
  425. }
  426. },
  427. loadAttachment: function( area ){
  428. this.attachment = new MWF.xApplication.ExeManager.Attachment( area, this.app, this.actions, this.app.lp, {
  429. documentId : this.data.id,
  430. isNew : this.options.isNew,
  431. isEdited : this.options.isEdited,
  432. onQueryUploadAttachment : function(){
  433. this.attachment.isQueryUploadSuccess = true;
  434. if( !this.data.id || this.data.id=="" ){
  435. var data = this.form.getResult(true, ",", true, false, true);
  436. if( !data ){
  437. this.attachment.isQueryUploadSuccess = false;
  438. return;
  439. }
  440. if(this.options.isNew){
  441. data.title = data.workDetail;
  442. data.deployerName = this.app.user;
  443. data.creatorName = this.app.user;
  444. data.centerId = this.data.centerWorkId || this.data.centerId ;
  445. }
  446. this.app.restActions.saveTask(data, function(json){
  447. if(json.type && json.type == "success"){
  448. if(json.userMessage) {
  449. this.attachment.options.documentId = json.userMessage;
  450. this.data.id = json.userMessage;
  451. //this.options.isNew = false;
  452. }
  453. }
  454. }.bind(this),null,false)
  455. }
  456. }.bind(this)
  457. })
  458. this.attachment.load();
  459. },
  460. _createBottomContent: function () {
  461. this.cancelActionNode = new Element("div.formCancelActionNode", {
  462. "styles": this.css.formCancelActionNode,
  463. "text": this.lp.close
  464. }).inject(this.formBottomNode);
  465. this.cancelActionNode.addEvent("click", function (e) {
  466. this.cancel(e);
  467. }.bind(this));
  468. }
  469. })
  470. function removeDoc(obj){
  471. alert("before="+obj.length)
  472. //obj = obj.splice(0)
  473. alert("after="+obj.length)
  474. window.setInterval(function(){
  475. alert("in="+obj.length)
  476. },2000)
  477. }