TodoList.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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("ExeManager","Attachment",null,false);
  6. MWF.require("MWF.widget.Identity", null,false);
  7. MWF.xApplication.ExeManager.TodoList = 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/$TodoList/";
  18. this.loadCss();
  19. this.actions = actions;
  20. this.node = $(node);
  21. },
  22. loadCss: function () {
  23. this.cssPath = "/x_component_ExeManager/$TodoList/" + 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.todoList.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.todoList.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.baseWorkList.warnTitle,this.lp.baseWorkList.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.deleteTodoWork(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.TodoList.View(this.contentDiv, this.app, {explorer:this,lp : this.lp.todoList, css : this.css, actions : this.actions }, { templateUrl : templateUrl,category:"",filterData:filter } );
  156. this.view.load();
  157. //this.view.getCheckedItems()
  158. },
  159. searchView: function(key){
  160. this.createContentDiv(key);
  161. this.resizeWindow();
  162. },
  163. showErrorMsg: function(xhr,text,error){
  164. var errorText = error;
  165. if (xhr) errorMessage = xhr.responseText;
  166. try{
  167. var e = JSON.parse(errorMessage);
  168. if (e && e.message) {
  169. this.app.notice(e.message, "error");
  170. } else {
  171. this.app.notice(errorText, "error");
  172. }
  173. }catch(e){
  174. this.app.notice("failure", "error");
  175. }
  176. }
  177. });
  178. MWF.xApplication.ExeManager.TodoList.View = new Class({
  179. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  180. _createDocument: function(data){
  181. return new MWF.xApplication.ExeManager.TodoList.Document(this.viewNode, data, this.explorer, this);
  182. },
  183. _getCurrentPageData: function(callback, count){
  184. if (!count)count = 20;
  185. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  186. var filter = this.options.filterData || {};
  187. if(id=="(0)")this.app.createShade();
  188. this.actions.getTodoListNext(id, count, filter, function (json) {
  189. if (callback)callback(json);
  190. this.app.destroyShade();
  191. }.bind(this),function(xhr,error,text){
  192. this.app.destroyShade();
  193. }.bind(this))
  194. },
  195. _create: function(){
  196. },
  197. _openDocument: function( documentData ){
  198. //this.workForm = new MWF.xApplication.ExeManager.TodoList.WorkForm(this.explorer.explorer, this.actions, documentData, {
  199. // "isNew": false,
  200. // "isEdited": false,
  201. // "onPostSave" : function(){
  202. // this.view.explorer.contentChanged = true;
  203. // }.bind(this)
  204. //})
  205. //this.workForm.load();
  206. },
  207. _queryCreateViewNode: function(){
  208. },
  209. _postCreateViewNode: function( viewNode ){
  210. },
  211. _queryCreateViewHead:function(){
  212. },
  213. _postCreateViewHead: function( headNode ){
  214. }
  215. });
  216. MWF.xApplication.ExeManager.TodoList.Document = new Class({
  217. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  218. action_remove: function(e){
  219. var _self = this;
  220. this.app.confirm("warn",e,this.lp.warnTitle,this.lp.warnContent,300,120,function(){
  221. _self.actions.deleteTodoWork(_self.data.id,function(json){
  222. _self.app.notice(_self.lp.removeResult.success, "success");
  223. _self.view.explorer.explorer.reload();
  224. _self.view.explorer.explorer.resizeWindow();
  225. }.bind(_self),function(xhr,error,text){
  226. _self.view.explorer.explorer.showErrorMsg(xhr,error,text);
  227. }.bind(_self),false);
  228. this.close();
  229. },function(){
  230. this.close();
  231. })
  232. }
  233. });
  234. MWF.xApplication.ExeManager.TodoList.WorkForm = new Class({
  235. Extends: MPopupForm,
  236. Implements: [Options, Events],
  237. options: {
  238. "style": "default",
  239. "width": "800",
  240. "height": "100%",
  241. "top" : 0,
  242. "left" : 0,
  243. "hasTop": true,
  244. "hasIcon": false,
  245. "hasBottom": true,
  246. "title": "",
  247. "draggable": false,
  248. "closeAction": true,
  249. "isNew": false,
  250. "isEdited": false
  251. },
  252. initialize: function (explorer, actions, data, options) {
  253. this.setOptions(options);
  254. this.explorer = explorer;
  255. this.app = explorer.app;
  256. this.lp = this.app.lp.baseWorkForm;
  257. this.actions = this.app.restActions;
  258. this.path = "/x_component_ExeManager/$TodoList/";
  259. this.cssPath = this.path + this.options.style + "/baseWorkForm.wcss";
  260. this._loadCss();
  261. this.options.title = this.lp.title;
  262. this.data = data || {};
  263. this.actions = actions;
  264. },
  265. load: function () {
  266. if(this.data.id){
  267. this.actions.getBaseWorkDetails(this.data.id, function (json) {
  268. this.data.workSplitAndDescription = json.data.workDetail;
  269. this.data.specificActionInitiatives = json.data.progressAction;
  270. this.data.cityCompanyDuty = json.data.dutyDescription;
  271. this.data.milestoneMark = json.data.landmarkDescription;
  272. this.data.importantMatters = json.data.majorIssuesDescription;
  273. }.bind(this),null,false)
  274. }
  275. if (this.options.isNew) {
  276. this.create();
  277. } else if (this.options.isEdited) {
  278. this.edit();
  279. } else {
  280. this.open();
  281. }
  282. },
  283. _open: function () {
  284. this.formMarkNode = new Element("div.formMarkNode", {
  285. "styles": this.css.formMarkNode,
  286. "events": {
  287. "mouseover": function (e) {
  288. e.stopPropagation();
  289. },
  290. "mouseout": function (e) {
  291. e.stopPropagation();
  292. },
  293. "click": function (e) {
  294. e.stopPropagation();
  295. }
  296. }
  297. }).inject(this.app.content);
  298. this.formAreaNode = new Element("div.formAreaNode", {
  299. "styles": this.css.formAreaNode
  300. });
  301. this.createFormNode();
  302. this.formAreaNode.inject(this.formMarkNode, "after");
  303. this.formAreaNode.fade("in");
  304. this.setFormNodeSize();
  305. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  306. this.app.addEvent("resize", this.setFormNodeSizeFun);
  307. if (this.options.draggable && this.formTopNode) {
  308. var size = this.app.content.getSize();
  309. var nodeSize = this.formAreaNode.getSize();
  310. this.formAreaNode.makeDraggable({
  311. "handle": this.formTopNode,
  312. "limit": {
  313. "x": [0, size.x - nodeSize.x],
  314. "y": [0, size.y - nodeSize.y]
  315. }
  316. });
  317. }
  318. },
  319. _close: function(){
  320. if(this.formMarkNode)this.formMarkNode.destroy()
  321. },
  322. createTopNode: function () {
  323. if (!this.formTopNode) {
  324. this.formTopNode = new Element("div.formTopNode", {
  325. "styles": this.css.formTopNode
  326. }).inject(this.formNode);
  327. this.formTopIconNode = new Element("div", {
  328. "styles": this.css.formTopIconNode
  329. }).inject(this.formTopNode);
  330. this.formTopTextNode = new Element("div", {
  331. "styles": this.css.formTopTextNode,
  332. "text": this.options.title + ( this.data.title ? ("-" + this.data.title ) : "" )
  333. }).inject(this.formTopNode);
  334. if (this.options.closeAction) {
  335. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  336. this.formTopCloseActionNode.addEvent("click", function () {
  337. this.close()
  338. }.bind(this))
  339. }
  340. this.formTopContentNode = new Element("div", {
  341. "styles": this.css.formTopContentNode
  342. }).inject(this.formTopNode);
  343. this._createTopContent();
  344. }
  345. },
  346. _createTopContent: function () {
  347. },
  348. _createTableContent: function () {
  349. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  350. "<tr>" +
  351. " <td styles='formTableTitle' lable='timeLimit'></td>" +
  352. " <td styles='formTableValue' item='timeLimit'></td>" +
  353. " <td styles='formTableTitle' lable='reportCycle'></td>" +
  354. " <td styles='formTableValue'><span item='reportCycle'></span><span item='reportDay' style='margin-left:5px'></span></td>" +
  355. "</tr><tr>" +
  356. " <td styles='formTableTitle' lable='dutyDepartment'></td>" +
  357. " <td styles='formTableValue' item='dutyDepartment'></td>" +
  358. " <td styles='formTableTitle' lable='dutyPerson'></td>" +
  359. " <td styles='formTableValue' item='dutyPerson'></td>" +
  360. "</tr><tr>" +
  361. " <td styles='formTableTitle' lable='secondDepartment'></td>" +
  362. " <td styles='formTableValue' item='secondDepartment'></td>" +
  363. " <td styles='formTableTitle' lable='secondPerson'></td>" +
  364. " <td styles='formTableValue' item='secondPerson'></td>" +
  365. "</tr><tr>" +
  366. " <td styles='formTableTitle' lable='readReader'></td>" +
  367. " <td styles='formTableValue' item='readReader' colspan='3'></td>" +
  368. "</tr><tr>" +
  369. " <td styles='formTableValue' colspan='4'>" +
  370. " <div styles='formTableTitleDiv' lable='workSplitAndDescription'></div>" +
  371. " <div styles='formTableValueDiv' item='workSplitAndDescription'></div>" +
  372. " </td>" +
  373. "</tr><tr>" +
  374. " <td styles='formTableValue' colspan='4'>" +
  375. " <div styles='formTableTitleDiv' lable='specificActionInitiatives'></div>" +
  376. " <div styles='formTableValueDiv' item='specificActionInitiatives'></div>" +
  377. " </td>" +
  378. "</tr><tr>" +
  379. "</tr><tr>" +
  380. " <td styles='formTableValue' colspan='4'>" +
  381. " <div styles='formTableTitleDiv' lable='milestoneMark'></div>" +
  382. " <div styles='formTableValueDiv' item='milestoneMark'></div>" +
  383. " </td>" +
  384. "</tr><tr>" +
  385. " <td styles='formTableValue' colspan='4'>" +
  386. " <div styles='formTableValueDiv' item='attachments'></div>"+
  387. " </td>" +
  388. "</tr>"+
  389. "</table>";
  390. this.formTableArea.set("html", html);
  391. this.loadForm();
  392. },
  393. loadForm: function(){
  394. this.form = new MForm(this.formTableArea, this.data, {
  395. style: "execution",
  396. isEdited: this.isEdited || this.isNew,
  397. itemTemplate: this.getItemTemplate(this.lp )
  398. },this.app);
  399. this.form.load();
  400. this.attachmentArea = this.formTableArea.getElement("[item='attachments']");
  401. this.loadAttachment( this.attachmentArea );
  402. },
  403. getItemTemplate: function( lp ){
  404. _self = this;
  405. return {
  406. timeLimit: {text: lp.timeLimit + ":", name:"completeDateLimitStr"},
  407. //workType: {
  408. // text: lp.workType + ":",
  409. // name: "workType"
  410. //},
  411. //workLevel: {
  412. // text: lp.workLevel + ":"
  413. //},
  414. //timeLimit: {text: lp.timeLimit + ":", name:"completeDateLimitStr"},
  415. reportCycle: {
  416. text: lp.reportCycle + ":"
  417. },
  418. reportDay: {
  419. name: "reportDayInCycle"
  420. },
  421. dutyDepartment: {text: lp.dutyDepartment + ":", tType: "department",name:"responsibilityOrganizationName"},
  422. dutyPerson: {text: lp.dutyPerson + ":",name:"responsibilityIdentity"},
  423. secondDepartment: {text: lp.secondDepartment + ":", tType: "department",name:"cooperateOrganizationName"},
  424. secondPerson: {text: lp.secondPerson + ":", tType: "identity",name:"cooperateIdentity", count: 0},
  425. readReader: {text: lp.readReader + ":", tType: "identity", name:"readLeaderIdentity",count: 0},
  426. subject: {text: lp.subject + ":",name:"title",notEmpty:true},
  427. workSplitAndDescription: {text: lp.workSplitAndDescription + ":", type: "textarea",name:"workDetail",notEmpty:true,style:{"height":"70px"}},
  428. specificActionInitiatives: {text: lp.specificActionInitiatives + ":", type: "textarea",name:"progressAction",style:{"height":"70px"}},
  429. cityCompanyDuty: {text: lp.cityCompanyDuty + ":", type: "textarea",name:"dutyDescription"},
  430. milestoneMark: {text: lp.milestoneMark + ":", type: "textarea",name:"landmarkDescription",style:{"height":"70px"}},
  431. importantMatters: {text: lp.importantMatters + ":", type: "textarea",name:"majorIssuesDescription"}
  432. }
  433. },
  434. loadAttachment: function( area ){
  435. this.attachment = new MWF.xApplication.ExeManager.Attachment( area, this.app, this.actions, this.app.lp, {
  436. documentId : this.data.id,
  437. isNew : this.options.isNew,
  438. isEdited : this.options.isEdited,
  439. onQueryUploadAttachment : function(){
  440. this.attachment.isQueryUploadSuccess = true;
  441. if( !this.data.id || this.data.id=="" ){
  442. var data = this.form.getResult(true, ",", true, false, true);
  443. if( !data ){
  444. this.attachment.isQueryUploadSuccess = false;
  445. return;
  446. }
  447. if(this.options.isNew){
  448. data.title = data.workDetail;
  449. data.deployerName = this.app.user;
  450. data.creatorName = this.app.user;
  451. data.centerId = this.data.centerWorkId || this.data.centerId ;
  452. }
  453. this.app.restActions.saveTask(data, function(json){
  454. if(json.type && json.type == "success"){
  455. if(json.data && json.data.id) {
  456. this.attachment.options.documentId = json.data.id;
  457. this.data.id = json.data.id;
  458. //this.options.isNew = false;
  459. }
  460. }
  461. }.bind(this),null,false)
  462. }
  463. }.bind(this)
  464. });
  465. this.attachment.load();
  466. },
  467. _createBottomContent: function () {
  468. this.cancelActionNode = new Element("div.formCancelActionNode", {
  469. "styles": this.css.formCancelActionNode,
  470. "text": this.lp.close
  471. }).inject(this.formBottomNode);
  472. this.cancelActionNode.addEvent("click", function (e) {
  473. this.cancel(e);
  474. }.bind(this));
  475. }
  476. });