WorkGather.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. MWF.xApplication.Execution = MWF.xApplication.Execution || {};
  2. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  4. MWF.xDesktop.requireApp("Execution", "WorkForm", null, false);
  5. MWF.xApplication.Execution.WorkGather = new Class({
  6. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  7. Implements: [Options, Events],
  8. options: {
  9. //"centerWorkId" : "fc44be47-7271-469f-8f04-deebdb71d3e6",
  10. "style": "default",
  11. "width": "100%",
  12. "height": "100%",
  13. "hasTop": true,
  14. "hasIcon": false,
  15. "hasBottom": true,
  16. "title": "",
  17. "draggable": false,
  18. "closeAction": true,
  19. "isNew": false,
  20. "isEdited": true
  21. },
  22. initialize: function (explorer, actions, data, options) {
  23. this.setOptions(options);
  24. this.explorer = explorer;
  25. this.app = explorer.app;
  26. this.lp = this.app.lp.workGather;
  27. this.actions = this.app.restActions;
  28. this.path = "/x_component_Execution/$WorkGather/";
  29. this.cssPath = this.path + this.options.style + "/css.wcss";
  30. this._loadCss();
  31. this.data = data || {};
  32. this.actions = actions;
  33. },
  34. load: function () {
  35. //alert(JSON.stringify(this.data))
  36. if (this.options.isNew) {
  37. this.create();
  38. } else if (this.options.isEdited) {
  39. this.edit();
  40. } else {
  41. this.open();
  42. }
  43. },
  44. createTopNode: function () {
  45. if (!this.formTopNode) {
  46. this.formTopNode = new Element("div.formTopNode", {
  47. "styles": this.css.formTopNode
  48. }).inject(this.formNode);
  49. this.formTopIconNode = new Element("div", {
  50. "styles": this.css.formTopIconNode
  51. }).inject(this.formTopNode)
  52. this.formTopTextNode = new Element("div", {
  53. "styles": this.css.formTopTextNode,
  54. "text": this.data.title
  55. }).inject(this.formTopNode)
  56. if (this.options.closeAction) {
  57. this.formTopCloseActionNode = new Element("div.formTopCloseActionNode", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  58. this.formTopCloseActionNode.addEvent("click", function () {
  59. this.close()
  60. }.bind(this))
  61. }
  62. this.formTopContentNode = new Element("div", {
  63. "styles": this.css.formTopContentNode
  64. }).inject(this.formTopNode)
  65. this._createTopContent();
  66. }
  67. },
  68. _createTopContent: function () {
  69. },
  70. _createTableContent: function (data) {
  71. this.titleDiv = new Element("div.titleDiv",{
  72. "styles":this.css.titleDiv,
  73. "text":this.data.title
  74. }).inject(this.formTableArea)
  75. this.inforDiv = new Element("div.inforDiv",{"styles":this.css.inforDiv}).inject(this.formTableArea);
  76. //this.gatherDiv = new Element("div.gatherDiv",{"styles":this.css.gatherDiv}).inject(this.formTableArea);
  77. this.gatherJson = null;
  78. this.gatherJsonLen = 0;
  79. this.loadGather();
  80. },
  81. loadGather: function(){
  82. if(this.gatherDiv) this.gatherDiv.destroy();
  83. this.gatherDiv = new Element("div.gatherDiv",{"styles":this.css.gatherDiv}).inject(this.formTableArea);
  84. this.tabContentDiv = new Element("div.tabContentDiv",{
  85. "styles":this.css.tabContentDiv
  86. }).inject(this.gatherDiv);
  87. this.actions.getDepartmentGather(this.data.gatherId,function(json){
  88. if(json.data) {
  89. this.gatherJson = json.data;
  90. this.gatherJsonLen = json.data.length;
  91. }
  92. }.bind(this),null,false)
  93. if(this.gatherJsonLen>0){
  94. this.loadTabContent();
  95. }
  96. },
  97. loadTabContent : function(){
  98. for(i=0;i<this.gatherJson.length;i++){
  99. this.tabContentLi = new Element("li.tabContentLi",{
  100. "styles": this.css.tabContentLi,
  101. "tabIndex" : i,
  102. "text" : this.gatherJson[i].activityName+"("+this.gatherJson[i].count+")",
  103. "tabName" : this.gatherJson[i].activityName
  104. }).inject(this.tabContentDiv);
  105. }
  106. var _this = this;
  107. this.tabContentDiv.getElements("li").addEvents({
  108. "click":function(){
  109. _this.loadGatherContent(this)
  110. }
  111. })
  112. if(this.curTabIndex){
  113. }else{
  114. this.curTabName = "";
  115. this.curTabIndex = 0;
  116. }
  117. this.tabContentDiv.getElements("li")[this.curTabIndex].click();
  118. },
  119. loadGatherContent: function(obj){
  120. this.curTabName = obj.get("tabName");
  121. this.curTabIndex = obj.get("tabIndex");
  122. this.tabContentDiv.getElements("li").setStyles({"background-color":"","color":""})
  123. obj.setStyles({"background-color":"#3d77c1","color":"#ffffff"});
  124. if(this.gatherContentDiv) this.gatherContentDiv.destroy()
  125. this.gatherContentDiv = new Element("div.gatherContentDiv",{
  126. "styles": this.css.gatherContentDiv
  127. }).inject(this.gatherDiv);
  128. var tab = obj.get("tabIndex");
  129. var tabName = obj.get("tabName");
  130. if(obj.get("tabName") == this.lp.gatherName.drafter){
  131. templateUrl = this.path+"listItem_drafter.json"
  132. }else if(obj.get("tabName") == this.lp.gatherName.manager){
  133. templateUrl = this.path+"listItem_manager.json"
  134. }else if(obj.get("tabName") == this.lp.gatherName.leader){
  135. templateUrl = this.path+"listItem_leader.json"
  136. }
  137. this.reportDataArr = [];
  138. this.WorkReportView = new MWF.xApplication.Execution.WorkGather.WorkReportView(this.gatherContentDiv, this.app, this, { templateUrl : templateUrl,tab: tab,tabName:tabName})
  139. this.WorkReportView.load();
  140. },
  141. openWorkReport: function(workReportId,workId){
  142. MWF.xDesktop.requireApp("Execution", "WorkReport", function(){
  143. var data = {
  144. workReportId : workReportId,
  145. workId : workId
  146. }
  147. this.workReport = new MWF.xApplication.Execution.WorkReport(this, this.actions,data,{
  148. "isEdited":false,
  149. "width":"90%",
  150. "height":"90%",
  151. onReloadView : function( data ){
  152. this.actions.getDepartmentGather(this.data.gatherId,function(json){
  153. if(json.data && json.data.length==0){
  154. this.fireEvent("reloadView");
  155. this.close()
  156. }
  157. }.bind(this),null,false)
  158. this.loadGather();
  159. }.bind(this)
  160. } );
  161. this.workReport.load();
  162. }.bind(this));
  163. },
  164. _createBottomContent: function () {
  165. this.submitActionNode = new Element("div.submitActionNode", {
  166. "styles": this.css.formActionNode,
  167. "text": this.lp.bottomAction.submit
  168. }).inject(this.formBottomNode);
  169. var _self = this;
  170. this.submitActionNode.addEvent("click", function (e) {
  171. this.app.confirm("warn",e,this.lp.submitWarn.warnTitle,this.lp.submitWarn.warnContent,300,120,function(){
  172. _self.submitGather()
  173. this.close();
  174. },function(){
  175. this.close();
  176. })
  177. }.bind(this));
  178. this.closeActionNode = new Element("div.formActionNode", {
  179. "styles": this.css.formActionNode,
  180. "text": this.lp.bottomAction.close
  181. }).inject(this.formBottomNode);
  182. this.closeActionNode.addEvent("click", function (e) {
  183. this.close(e);
  184. }.bind(this));
  185. },
  186. submit:function(workReportData){
  187. var progressText = this.gatherDiv.getElementById("progress"+workReportData.id);
  188. var progressValue = "";
  189. if(progressText) progressValue = progressText.get("value");
  190. var planText = this.gatherDiv.getElementById("plan"+workReportData.id);
  191. var planValue = "";
  192. if(planText) planValue = planText.get("value");
  193. var adminText = this.gatherDiv.getElementById("admin"+workReportData.id);
  194. var adminValue = "";
  195. if(adminText) adminValue = adminText.get("value");
  196. var opinionValue = ""
  197. var opinionText = this.gatherDiv.getElementById("opinion"+workReportData.id);
  198. if(opinionText) opinionValue = opinionText.get("value");
  199. if(progressText && progressValue==""){
  200. this.app.notice(this.lp.viewProgressDescription+this.lp.notEmpty,"error")
  201. return false;
  202. }
  203. if(planText && planValue==""){
  204. this.app.notice(this.lp.viewWorkPlan+this.lp.notEmpty,"error")
  205. return false;
  206. }
  207. var submitData = {
  208. workId : workReportData.workId,
  209. id : workReportData.id,
  210. progressDescription : progressValue,
  211. workPlan : planValue,
  212. adminSuperviseInfo : adminValue,
  213. opinion : opinionValue
  214. }
  215. this.actions.submitWorkReport( submitData, function(json){
  216. if(json.type == "success"){
  217. this.app.notice(this.lp.prompt.submitWorkReport,"success");
  218. this.actions.getDepartmentGather(this.data.gatherId,function(json){
  219. if(json.data && json.data.length==0){
  220. this.fireEvent("reloadView");
  221. this.close()
  222. }else{
  223. if(this.gatherJson[this.curTabIndex].count == 1){
  224. this.curTabIndex = 0;
  225. this.curTabName = "";
  226. }
  227. this.loadGather();
  228. }
  229. }.bind(this),null,false)
  230. }
  231. }.bind(this),function(xhr,text,error){
  232. var errorText = error;
  233. if (xhr) errorMessage = xhr.responseText;
  234. var e = JSON.parse(errorMessage);
  235. if(e.message){
  236. this.app.notice( e.message,"error");
  237. }else{
  238. this.app.notice( errorText,"error");
  239. }
  240. }.bind(this));
  241. },
  242. submitGather:function(){
  243. this.submitStatus = true;
  244. this.submitError = "";
  245. if(this.reportDataArr){
  246. for(var i=0;i<this.reportDataArr.length;i++){
  247. this.currentReportData = this.reportDataArr[i]
  248. if(this.submitStatus){
  249. var progressText = this.gatherDiv.getElementById("progress"+this.currentReportData.id);
  250. var progressValue = "";
  251. if(progressText) progressValue = progressText.get("value");
  252. var planText = this.gatherDiv.getElementById("plan"+this.currentReportData.id);
  253. var planValue = "";
  254. if(planText) planValue = planText.get("value");
  255. var adminText = this.gatherDiv.getElementById("admin"+this.currentReportData.id);
  256. var adminValue = "";
  257. if(adminText) adminValue = adminText.get("value");
  258. var opinionValue = ""
  259. var opinionText = this.gatherDiv.getElementById("opinion"+this.currentReportData.id);
  260. if(opinionText) opinionValue = opinionText.get("value");
  261. var submitData = {
  262. workId : this.currentReportData.workId,
  263. id : this.currentReportData.id,
  264. progressDescription : progressValue,
  265. workPlan : planValue,
  266. adminSuperviseInfo : adminValue,
  267. opinion : opinionValue
  268. }
  269. //if(i==0){
  270. // submitData.workId = "fefwfwfwfewfwfewfe";
  271. // submitData.id = "eeeeeeeeee"
  272. //
  273. //}
  274. this.actions.submitWorkReport( submitData, function(json){
  275. }.bind(this), function(xhr){
  276. var json = JSON.parse(xhr.responseText);
  277. this.submitError = "《"+this.currentReportData.title+"》"+json.message
  278. this.submitStatus = false;
  279. }.bind(this),false);
  280. }
  281. }
  282. }
  283. if(!this.submitStatus){
  284. this.app.notice(this.submitError, "error");
  285. this.loadGather();
  286. }else{
  287. //alert(this.gatherJsonLen)
  288. this.app.notice(this.lp.submitWarn.submitSuccess, "success");
  289. if(this.gatherJsonLen==1 ||this.gatherJsonLen==0 ){
  290. this.fireEvent("reloadView");
  291. this.close();
  292. }else{
  293. this.curTabIndex = 0;
  294. this.curTabName = "";
  295. this.loadGather();
  296. }
  297. }
  298. }
  299. })
  300. MWF.xApplication.Execution.WorkGather.WorkReportView = new Class({
  301. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  302. _createDocument: function(data){
  303. data.tabName = this.options.tabName;
  304. return new MWF.xApplication.Execution.WorkGather.WorkReportDocument(this.viewNode, data, this.explorer, this);
  305. },
  306. _getCurrentPageData: function(callback, count){
  307. this.actions.getDepartmentGather(this.explorer.data.gatherId,function(json){ //alert(JSON.stringify(json))
  308. if(json.data){
  309. if(this.options.tab){
  310. var tabIndex = parseInt(this.options.tab);
  311. json = json.data[tabIndex].reportCollect
  312. } else{
  313. json = json.data[0].reportCollect
  314. }
  315. if(callback) callback(json)
  316. }
  317. }.bind(this),null,false)
  318. },
  319. loadElementList: function (count) {
  320. if (!this.isItemsLoaded) {
  321. if (!this.isItemLoadding) {
  322. this.isItemLoadding = true;
  323. this._getCurrentPageData(function (json) {
  324. //if( !json.data )return;
  325. var length = json.count; //|| json.data.length;
  326. //if (!this.isCountShow){
  327. // this.filterAllProcessNode.getFirst("span").set("text", "("+this.count+")");
  328. // this.isCountShow = true;
  329. //}
  330. if (length <= this.items.length) {
  331. this.isItemsLoaded = true;
  332. }
  333. json.reportInfos.each(function (data) {
  334. if (!this.documents[data.id]) {
  335. var item = this._createDocument(data);
  336. this.items.push(item);
  337. this.documents[data.id] = item;
  338. }
  339. }.bind(this));
  340. this.isItemLoadding = false;
  341. if (this.loadItemQueue > 0) {
  342. this.loadItemQueue--;
  343. this.loadElementList();
  344. }
  345. }.bind(this), count);
  346. } else {
  347. this.loadItemQueue++;
  348. }
  349. }
  350. },
  351. _removeDocument: function(documentData, all){
  352. },
  353. _create: function(data){
  354. },
  355. _openDocument: function( documentData ){
  356. //this.workForm = new MWF.xApplication.Execution.WorkForm(this, this.actions, documentData, {
  357. // "isNew": false,
  358. // "isEdited": false
  359. //})
  360. //this.workForm.load();
  361. },
  362. _queryCreateViewNode: function(){
  363. },
  364. _postCreateViewNode: function( viewNode ){
  365. },
  366. _queryCreateViewHead:function(){
  367. },
  368. _postCreateViewHead: function( headNode ){
  369. }
  370. })
  371. MWF.xApplication.Execution.WorkGather.WorkReportDocument = new Class({
  372. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  373. _queryCreateDocumentNode:function( itemData ){
  374. },
  375. _postCreateDocumentNode: function( itemNode, itemData ){
  376. //alert(JSON.stringify(itemData))
  377. //alert(itemNode.get("html"))
  378. if(itemData.tabName ==this.view.lp.gatherName.drafter){
  379. cols = 4
  380. }else if(itemData.tabName ==this.view.lp.gatherName.manager){
  381. cols = 5
  382. }else if(itemData.tabName ==this.view.lp.gatherName.leader){
  383. cols = 6
  384. }
  385. if( itemData.reports ){
  386. itemData.reports.each(function(d){
  387. this.view.explorer.reportDataArr.push(d);
  388. var trNode = new Element("tr.trNodeTitle",{"styles":this.view.css.trNodeTitle}).inject(this.view.viewNode);
  389. var tdNode = new Element("td.tdNodeTitle",{
  390. "styles":this.view.css.tdNodeTitle,
  391. //"text": d.title + "(" +d.createTime+ ")",
  392. "html" : d.title + "&nbsp;&nbsp;&nbsp;&nbsp;(" +d.createTime+ ")",
  393. "colspan":cols
  394. }).inject(trNode).
  395. addEvents({
  396. "click":function(){
  397. this.view.explorer.openWorkReport(d.id, d.workId);
  398. }.bind(this)
  399. })
  400. trNode = new Element("tr.trNode",{"styles":this.view.css.trNode}).inject(this.view.viewNode)
  401. tdNode = new Element("td.tdNodeContent",{
  402. "styles":this.view.css.tdNodeContent
  403. }).inject(trNode); //事项分解
  404. divNode = new Element("div.divNode",{
  405. "styles":this.view.css.divNode,
  406. "text": d.workInfo.shortProgressAction?d.workInfo.shortProgressAction:"",
  407. "title": d.workInfo.shortProgressAction?d.workInfo.shortProgressAction:""
  408. }).inject(tdNode); //具体行动
  409. if(itemData.tabName ==this.view.lp.gatherName.drafter){//草稿
  410. tdNode = new Element("td.tdNodeContent",{
  411. "styles":this.view.css.tdNodeContent
  412. }).inject(trNode);
  413. var teextareaNode = new Element("textarea.tetareaNode",{
  414. "styles":this.view.css.textareaNode,
  415. "id":"progress"+ d.id,
  416. "value": d.progressDescription
  417. }).inject(tdNode); //截止当前
  418. tdNode = new Element("td.tdNodeContent",{
  419. "styles":this.view.css.tdNodeContent
  420. }).inject(trNode);
  421. var teextareaNode = new Element("textarea.tetareaNode",{
  422. "styles":this.view.css.textareaNode,
  423. "id":"plan"+ d.id,
  424. "value": d.workPlan
  425. }).inject(tdNode); //下一步
  426. }else if(itemData.tabName ==this.view.lp.gatherName.manager){//管理员
  427. tdNode = new Element("td.tdNodeContent",{
  428. "styles":this.view.css.tdNodeContent
  429. }).inject(trNode);
  430. divNode = new Element("div.divNode",{
  431. "styles":this.view.css.divNode,
  432. "text": d.progressDescription,
  433. "title": d.progressDescription
  434. }).inject(tdNode); //截止当前
  435. tdNode = new Element("td.tdNodeContent",{
  436. "styles":this.view.css.tdNodeContent
  437. }).inject(trNode);
  438. divNode = new Element("div.divNode",{
  439. "styles":this.view.css.divNode,
  440. "text": d.workPlan,
  441. "title": d.workPlan
  442. }).inject(tdNode); //下一步要点
  443. tdNode = new Element("td.tdNodeContent",{
  444. "styles":this.view.css.tdNodeContent
  445. }).inject(trNode);
  446. var teextareaNode = new Element("textarea.tetareaNode",{
  447. "styles":this.view.css.textareaNode,
  448. "id":"admin"+ d.id,
  449. value: d.adminSuperviseInfo
  450. }).inject(tdNode); //管理员
  451. }else if(itemData.tabName ==this.view.lp.gatherName.leader){ //领导
  452. tdNode = new Element("td.tdNodeContent",{
  453. "styles":this.view.css.tdNodeContent
  454. }).inject(trNode);
  455. divNode = new Element("div.divNode",{
  456. "styles":this.view.css.divNode,
  457. "text": d.progressDescription,
  458. "title": d.progressDescription
  459. }).inject(tdNode); //截止当前
  460. tdNode = new Element("td.tdNodeContent",{
  461. "styles":this.view.css.tdNodeContent
  462. }).inject(trNode);
  463. divNode = new Element("div.divNode",{
  464. "styles":this.view.css.divNode,
  465. "text": d.workPlan,
  466. "title": d.workPlan
  467. }).inject(tdNode); //下一步要点
  468. tdNode = new Element("td.tdNodeContent",{
  469. "styles":this.view.css.tdNodeContent
  470. }).inject(trNode);
  471. divNode = new Element("div.divNode", {
  472. "styles": this.view.css.divNode,
  473. "text": d.adminSuperviseInfo,
  474. "title": d.adminSuperviseInfo
  475. }).inject(tdNode); //管理员
  476. tdNode = new Element("td.tdNodeContent",{
  477. "styles":this.view.css.tdNodeContent
  478. }).inject(trNode);
  479. var teextareaNode = new Element("textarea.tetareaNode",{
  480. "styles":this.view.css.textareaNode,
  481. "id":"opinion"+ d.id
  482. }).inject(tdNode); //管理员
  483. }
  484. var tdNodeAction = new Element("td.tdNodeAction",{
  485. "styles":this.view.css.tdNodeAction,
  486. }).inject(trNode);
  487. var actionTxt = new Element("a.actionTxt",{
  488. "styles":this.view.css.actionTxt,
  489. "text":this.view.lp.viewSubmit
  490. }).inject(tdNodeAction)
  491. .addEvents({
  492. "click":function(){
  493. this.view.explorer.submit(d)
  494. }.bind(this)
  495. }) // 操作
  496. ////管理员
  497. //if(d.isWorkAdmin && d.processStatus == this.view.lp.activityName.manager){
  498. //
  499. //}else{
  500. //
  501. //}
  502. ////领导
  503. ////this.workReportData.processStatus == this.lp.activityName.leader && this.workReportData.isReadLeader && this.processIdentity.indexOf(this.app.identity)>-1
  504. //if(d.processStatus == this.view.lp.activityName.leader && d.isReadLeader && d.currentProcessorIdentity.indexOf(this.app.identity)>-1){
  505. // tdNode = new Element("td.tdNodeContent",{
  506. // "styles":this.view.css.tdNodeContent
  507. // }).inject(trNode);
  508. // var teextareaNode = new Element("textarea.tetareaNode",{
  509. // "styles":this.view.css.textareaNode,
  510. // "id":"opinion"+ d.id
  511. // }).inject(tdNode);
  512. //}else{
  513. // tdNode = new Element("td.tdNodeContent",{
  514. // "styles":this.view.css.tdNodeContent,
  515. // "text": ""
  516. // }).inject(trNode);
  517. //}
  518. //
  519. //var tdNodeAction = new Element("td.tdNodeAction",{
  520. // "styles":this.view.css.tdNodeAction,
  521. //}).inject(trNode);
  522. //var actionTxt = new Element("a.actionTxt",{
  523. // "styles":this.view.css.actionTxt,
  524. // "text":this.view.lp.viewSubmit
  525. //}).inject(tdNodeAction)
  526. // .addEvents({
  527. // "click":function(){
  528. // this.view.explorer.submit(d)
  529. // }.bind(this)
  530. // })
  531. }.bind(this))
  532. //this.view.viewNode.getElements("textarea").setStyle("height","100%")
  533. }
  534. }
  535. })