WorkDeploy.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  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.WorkDeploy = new Class({
  6. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "width": "90%",
  11. "height": "90%",
  12. "hasTop": true,
  13. "hasIcon": false,
  14. "hasBottom": true,
  15. "title": "",
  16. "draggable": false,
  17. "closeAction": true,
  18. "isNew": false,
  19. "isEdited": true
  20. },
  21. initialize: function (explorer, actions, data, options) {
  22. this.setOptions(options);
  23. this.explorer = explorer;
  24. this.app = explorer.app;
  25. this.lp = this.app.lp.WorkDeploy;
  26. this.actions = this.app.restActions;
  27. this.path = "/x_component_Execution/$WorkDeploy/";
  28. this.cssPath = this.path + this.options.style + "/css.wcss";
  29. this._loadCss();
  30. this.options.title = this.lp.title;
  31. this.data = data || {};
  32. this.actions = actions;
  33. },
  34. load: function () {
  35. this.getCenterWorkInfo();
  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. getCenterWorkInfo:function(centerId){
  45. var id = "(0)"
  46. if(arguments.length==1){
  47. id = centerId;
  48. }else{
  49. if(this.data.id){
  50. id = this.data.id;
  51. }
  52. }
  53. this.actions.getCenterWorkInfo(id,function(json){
  54. if(json.type = "success"){
  55. this.centerWorkData = json.data;
  56. this.centerWorkId = this.centerWorkData.id
  57. }
  58. }.bind(this),function(xhr,error,text){
  59. this.showErrorMessage(xhr,error,text)
  60. }.bind(this),false)
  61. },
  62. createTopNode: function () {
  63. if (!this.formTopNode) {
  64. this.formTopNode = new Element("div.formTopNode", {
  65. "styles": this.css.formTopNode
  66. }).inject(this.formNode);
  67. this.formTopIconNode = new Element("div", {
  68. "styles": this.css.formTopIconNode
  69. }).inject(this.formTopNode)
  70. this.formTopTextNode = new Element("div", {
  71. "styles": this.css.formTopTextNode,
  72. "text": this.options.title
  73. }).inject(this.formTopNode)
  74. if (this.options.closeAction) {
  75. this.formTopCloseActionNode = new Element("div.formTopCloseActionNode", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  76. this.formTopCloseActionNode.addEvent("click", function () {
  77. this.close()
  78. }.bind(this))
  79. }
  80. this.formTopContentNode = new Element("div", {
  81. "styles": this.css.formTopContentNode
  82. }).inject(this.formTopNode)
  83. this._createTopContent();
  84. }
  85. },
  86. _createTopContent: function () {
  87. if(this.formTopContentNode) this.formTopContentNode.empty()
  88. var html = "<span styles='formTopContentTitle' lable='drafter'></span>" +
  89. " <span styles='formTopContentValue' item='drafter'></span>" +
  90. "<span styles='formTopContentTitle' lable='draftDepartment'></span>" +
  91. " <span styles='formTopContentValue' item='draftDepartment'></span>" +
  92. "<span styles='formTopContentTitle' lable='draftDate'></span>" +
  93. " <span styles='formTopContentValue' item='draftDate'></span>"
  94. this.formTopContentNode.set("html", html);
  95. var form = new MForm(this.formTopContentNode, this.centerWorkData, {
  96. isEdited: false,
  97. itemTemplate: {
  98. drafter: {text: this.lp.drafter + ":", name:"creatorName", type: "innertext"},
  99. draftDepartment: {text: this.lp.draftDepartment + ":", name:"creatorOrganizationName", type: "innertext"},
  100. draftDate: {text: this.lp.draftDate + ":",name:"createTime", type: "innertext"}
  101. }
  102. }, this.app, this.css);
  103. form.load();
  104. },
  105. reloadTableContent:function(id){
  106. if(arguments.length==0){
  107. if(this.centerWorkData){
  108. id = this.centerWorkData.id
  109. }else if(this.data.id){
  110. id = this.data.id
  111. }else if(this.options.centerWorkId){
  112. this.options.centerWorkId
  113. }
  114. }
  115. this.getCenterWorkInfo(id);
  116. this._createTopContent();
  117. this._createTableContent(this.centerWorkData);
  118. this._createBottomContent();
  119. },
  120. _createTableContent: function () {
  121. if(this.formTableArea) this.formTableArea.empty();
  122. //alert(this.centerWorkData)
  123. this.createCenterWorkInfor(this.centerWorkData);
  124. this.createImportContent();
  125. this.createMyWorkList();
  126. this.creataMyDeployWorkList();
  127. },
  128. createCenterWorkInfor: function(data) {
  129. this.centerWorkContentArea = new Element("div.centerWorkContentArea", {
  130. "styles": this.css.workContentArea
  131. }).inject(this.formTableArea);
  132. var workContentTitleNode = new Element("div.workContentTitleNode", {
  133. "styles": this.css.workContentTitleNode,
  134. "text": this.lp.centerWorkInfor
  135. }).inject(this.centerWorkContentArea);
  136. this.centerWorkContentNode = new Element("div.centerWorkContentNode", {
  137. "styles": this.css.workContentNode
  138. }).inject(this.centerWorkContentArea);
  139. this.loadCenterWorkInfor(data)
  140. },
  141. loadCenterWorkInfor: function(data){
  142. this.centerWorkContentNode.empty();
  143. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='centerWorkInforTable'>" +
  144. "<tr><td styles='centerWorkInforTitle' lable='centerWorkTitle'></td>" +
  145. " <td styles='centerWorkInforValue' item='centerWorkTitle'></td></tr>" +
  146. "<tr><td colspan='2'>" +
  147. " <div styles='centerWorkInforTitleDiv' lable='reportAuditLeader'></div>" +
  148. " <div styles='centerWorkInforValueDiv' item='reportAuditLeader'></div>" +
  149. " <div styles='centerWorkInforTitleDiv' lable='defaultWorkType'></div>" +
  150. " <div styles='centerWorkInforValueDiv' item='defaultWorkType'></div>" +
  151. " <div styles='centerWorkInforTitleDiv' lable='workCompletedLimit'></div>" +
  152. " <div styles='centerWorkInforValueDiv' item='workCompletedLimit'></div>" +
  153. "</td></tr>" +
  154. "<tr><td styles='centerWorkInforTitle' lable='centerWorkMemo'></td>" +
  155. " <td styles='centerWorkInforValue' item='centerWorkMemo'></td></tr>" +
  156. "</table>"
  157. this.centerWorkContentNode.set("html", html);
  158. var resultWorkType = []
  159. var resultWorkTypeTxt = ""
  160. if(data.workTypes){
  161. data.workTypes.each(function(d,i){
  162. if(d.workTypeName) resultWorkType.push(d.workTypeName)
  163. })
  164. }
  165. resultWorkTypeTxt = resultWorkType.join(",")
  166. if(resultWorkType.length>0){
  167. resultWorkTypeTxt = ","+resultWorkTypeTxt
  168. }
  169. var form = this.centerForm = new MForm(this.centerWorkContentNode, data, {
  170. isEdited: this.isEdited || this.isNew,
  171. itemTemplate: {
  172. centerWorkTitle: {
  173. text: this.lp.centerWorkTitle + ":", name : "title", type: "text",
  174. notEmpty:true,
  175. },
  176. defaultWorkType: {
  177. text: this.lp.defaultWorkType + ":", name : "defaultWorkType", type: "select",
  178. selectValue : resultWorkTypeTxt,
  179. selectText : resultWorkTypeTxt,
  180. notEmpty:true,
  181. style : {"width":"100px","height":"30px","border-radius":"1px"}
  182. },
  183. defaultWorkLevel: {
  184. text: this.lp.defaultWorkLevel + ":", name:"defaultWorkLevel", type: "select",selectValue : this.lp.defaultWorkTypeValue,
  185. notEmpty:true,
  186. style : {"width":"200px","height":"30px","color":"#999999","border-radius":"1px","box-shadow": "0px 0px 1px #CCC"}
  187. },
  188. reportAuditLeader: {
  189. text: this.lp.reportAuditLeader + ":", name:"reportAuditLeaderIdentity",
  190. tType:"identity",
  191. attr:{"readonly":true},
  192. notEmpty:false,
  193. count: 0,
  194. value: this.reportAuditLeader?this.reportAuditLeader:"",
  195. style : {"width":"300px"}
  196. },
  197. workCompletedLimit: {
  198. text: this.lp.workCompletedLimit + ":", name:"defaultCompleteDateLimitStr", type: "text",
  199. tType:"date",
  200. attr:{"readonly":true},
  201. notEmpty:true
  202. },
  203. centerWorkMemo: {
  204. text: this.lp.centerWorkMemo + ":",
  205. name: "description",
  206. type: "textarea"
  207. }
  208. }
  209. }, this.app);
  210. form.load();
  211. },
  212. createImportContent: function(){
  213. if(this.centerWorkData && this.centerWorkData.operation){
  214. if(this.centerWorkData.operation.indexOf("IMPORTWORK")>-1){
  215. this.importDiv = new Element("div.importDiv",{
  216. "styles" : this.css.importDiv
  217. }).inject(this.formTableArea);
  218. this.importTemplateDiv = new Element("div.importTemplateDiv",{
  219. "styles": this.css.importTemplateDiv,
  220. "text":this.lp.importTemplate
  221. }).inject(this.importDiv)
  222. this.importTemplateDiv.addEvents({
  223. "click":function(){
  224. window.open("/x_component_Execution/baseWork.xls")
  225. }.bind(this)
  226. })
  227. this.importTitleDiv = new Element("div.importTitleDiv",{
  228. "styles": this.css.importTitleDiv,
  229. "text":this.lp.importTemplateTitle
  230. }).inject(this.importDiv);
  231. }
  232. }
  233. },
  234. createMyWorkList : function(){
  235. if(this.myWorkContentArea) this.myWorkContentArea.destroy();
  236. var workContentArea = this.myWorkContentArea = new Element("div.workContentArea", {
  237. "styles": this.css.workContentArea
  238. }).inject(this.formTableArea);
  239. var workContentTitleNode = new Element("div", {
  240. "styles": this.css.workContentTitleNode,
  241. "text": this.lp.myWorkInfor
  242. }).inject(workContentArea);
  243. var workContentNode = new Element("div", {
  244. "styles": this.css.workContentNode
  245. }).inject(workContentArea);
  246. //this.createSplitWorkList();
  247. var list = this.myWorkView = new MWF.xApplication.Execution.WorkDeploy.MyWorkView(workContentNode, this.app, this, { templateUrl : this.path+"myWork.json" })
  248. list.load();
  249. },
  250. creataMyDeployWorkList : function(){
  251. var workContentArea = this.myDeployWorkArea = new Element("div.myDeployWorkArea", {
  252. "styles": this.css.workContentArea
  253. }).inject(this.formTableArea);
  254. var myDeployWorkTitleNode = new Element("div.myDeployWorkTitleNode", {
  255. "styles": this.css.workContentTitleNode,
  256. "text": this.lp.deployWorkInfor
  257. }).inject(workContentArea);
  258. var list = this.myDeployWorkView = new MWF.xApplication.Execution.WorkDeploy.MyDeployWorkView(workContentArea, this.app, this, { templateUrl : this.path+"myDeployWork.json" })
  259. list.load();
  260. },
  261. //*************************底部按钮及方法**************************************
  262. _createBottomContent: function () {
  263. if(this.formBottomNode) this.formBottomNode.empty();
  264. if(this.centerWorkData && this.centerWorkData.operation){
  265. this.centerWorkData.operation.each(function(d,i){
  266. if(d == "CLOSE"){
  267. this.closeBotton = new Element("div.closeBotton", {
  268. "styles": this.css.formActionNode,
  269. "text": this.lp.botton.close
  270. }).inject(this.formBottomNode);
  271. this.closeBotton.addEvent("click", function (e) {
  272. this.closeWork(e);
  273. }.bind(this));
  274. }else if(d == "CREATEWORK"){
  275. this.newBotton = new Element("div.newBotton", {
  276. "styles": this.css.formActionNode,
  277. "text": this.lp.botton.new
  278. }).inject(this.formBottomNode);
  279. this.newBotton.addEvent("click", function (e) {
  280. this.createWork(e);
  281. }.bind(this));
  282. }else if(d == "IMPORTWORK"){
  283. this.importBotton = new Element("div.importBotton", {
  284. "styles": this.css.formActionNode,
  285. "text": this.lp.botton.import
  286. }).inject(this.formBottomNode);
  287. this.importBotton.addEvent("click", function (e) {
  288. this.importWork(e);
  289. }.bind(this));
  290. }else if(d == "DELETE"){
  291. this.deleteBotton = new Element("div.deleteBotton", {
  292. "styles": this.css.formActionNode,
  293. "text": this.lp.botton.delete
  294. }).inject(this.formBottomNode);
  295. this.deleteBotton.addEvent("click", function (e) {
  296. this.deleteWork(e);
  297. }.bind(this));
  298. }else if(d == "DEPLOY"){
  299. this.deployBotton = new Element("div.deployBotton", {
  300. "styles": this.css.formActionNode,
  301. "text": this.lp.botton.deploy
  302. }).inject(this.formBottomNode);
  303. this.deployBotton.addEvent("click", function (e) {
  304. this.deployWork(e);
  305. }.bind(this));
  306. }else if(d == "ARCHIVE"){
  307. this.archiveBotton = new Element("div.archiveBotton", {
  308. "styles": this.css.formActionNode,
  309. "text": this.lp.botton.archive
  310. }).inject(this.formBottomNode);
  311. this.archiveBotton.addEvent("click", function (e) {
  312. this.archiveWork(e);
  313. }.bind(this));
  314. } if(d == "CONFIRM"){
  315. this.confirmBotton = new Element("div.confirmBotton", {
  316. "styles": this.css.formActionNode,
  317. "text": this.lp.botton.confirm
  318. }).inject(this.formBottomNode);
  319. this.confirmBotton.addEvent("click", function (e) {
  320. this.confirmWork(e);
  321. }.bind(this));
  322. }
  323. }.bind(this))
  324. }
  325. },
  326. closeWork:function(data){
  327. this.close();
  328. //this.fireEvent("reloadView", data);
  329. this.fireEvent("reloadView", {"action":"reload"});
  330. },
  331. createWork:function(){
  332. var r = this.centerForm.getResult(true,",",true,false,true);
  333. if( !r ){
  334. return
  335. }
  336. if(this.options.isNew || this.options.isEdited){
  337. this.saveCenterWork(r,function(json){
  338. if(json.type && json.type == "error"){
  339. this.app.notice(json.message, "error")
  340. }else{
  341. if(json.data && json.data.id)this.reloadTableContent(json.data.id)
  342. if(this.centerWorkData)this.openWorkForm(this.centerWorkData)
  343. }
  344. }.bind(this))
  345. }else{
  346. if(this.centerWorkData)this.openWorkForm(this.centerWorkData)
  347. }
  348. },
  349. importWork:function(){
  350. var centerId;
  351. var r = this.centerForm.getResult(true,",",true,false,true);
  352. if( !r ){
  353. return false;
  354. }
  355. if(this.options.isNew || this.options.isEdited){
  356. this.saveCenterWork(r,function(json){
  357. if(json.type && json.type == "error"){
  358. this.app.notice(json.message, "error")
  359. }else{
  360. if(json.data && json.data.id){
  361. centerId = json.data.id;
  362. this.reloadTableContent(json.data.id)
  363. }
  364. }
  365. }.bind(this))
  366. }else{
  367. if(this.centerWorkData) centerId = this.centerWorkData.id
  368. }
  369. if (centerId && !this.uploadFileAreaNode){
  370. this.uploadFileAreaNode = new Element("div");
  371. var html = "<input name=\"file\" type=\"file\" />";
  372. this.uploadFileAreaNode.set("html", html);
  373. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  374. this.fileUploadNode.addEvent("change", function(){
  375. var files = fileNode.files;
  376. if (files.length){
  377. for (var i = 0; i < files.length; i++) {
  378. var file = files.item(i);
  379. var tmp = file.name.split(".");
  380. this.uploadFileName = file.name;
  381. if( tmp[tmp.length-1].toLowerCase() != "xls" && tmp[tmp.length-1].toLowerCase() != "xlsx" ){
  382. this.app.notice("请导入excel文件!","error");
  383. return;
  384. }
  385. var formData = new FormData();
  386. formData.append('file', file);
  387. this.createShade("正在导入,请稍后.....")
  388. this.actions.importBaseWork(centerId,function(json){
  389. this.reloadTableContent(centerId)
  390. this.destroyShade()
  391. }.bind(this),function(xhr,text,error){
  392. this.showErrorMessage(xhr,text,error)
  393. this.destroyShade()
  394. }.bind(this),formData,file)
  395. }
  396. }
  397. }.bind(this));
  398. }
  399. var fileNode = this.uploadFileAreaNode.getFirst();
  400. fileNode.click();
  401. },
  402. deleteWork:function(e){
  403. var _self = this;
  404. _self.app.confirm("warn",e,_self.lp.submitWarn.warnTitle,_self.lp.submitWarn.warnContent,300,120,function(){
  405. _self.actions.deleteCenterWork(_self.centerWorkData.id, function(json){
  406. if(json.type && json.type=="success"){
  407. _self.app.notice(this.lp.prompt.deleteCenterWork, "success");
  408. _self.closeWork({"action":"reload"});
  409. }
  410. }.bind(_self),function(xhr,text,error){
  411. _self.showErrorMessage(xhr,text,error)
  412. }.bind(_self));
  413. this.close()
  414. },function(){
  415. this.close();
  416. })
  417. },
  418. deployWork:function(e){
  419. var _self = this;
  420. _self.app.confirm("warn",e,_self.lp.submitWarn.warnTitle,_self.lp.submitWarn.warnDeployContent,300,120,function(){
  421. _self.actions.deployCenterWork(_self.centerWorkData.id, function(json){
  422. if(json.type && json.type=="success"){
  423. _self.app.notice(this.lp.prompt.deployCenterWork, "success");
  424. _self.close();
  425. _self.fireEvent("reloadView", {"action":"reload"});
  426. }
  427. }.bind(_self),function(xhr,text,error){
  428. _self.showErrorMessage(xhr,text,error)
  429. }.bind(_self));
  430. this.close()
  431. },function(){
  432. this.close();
  433. })
  434. },
  435. confirmWork:function(e){
  436. var _self = this;
  437. _self.app.confirm("warn",e,_self.lp.submitWarn.warnTitle,_self.lp.submitWarn.warnConfirmContent,300,120,function(){
  438. _self.actions.deployCenterWork(_self.centerWorkData.id, function(json){
  439. if(json.type && json.type=="success"){
  440. _self.app.notice(this.lp.prompt.comfirmCenterWork, "success");
  441. _self.close();
  442. _self.fireEvent("reloadView", {"action":"reload"});
  443. }
  444. }.bind(_self),function(xhr,text,error){
  445. _self.showErrorMessage(xhr,text,error)
  446. }.bind(_self));
  447. this.close()
  448. },function(){
  449. this.close();
  450. })
  451. },
  452. archiveWork:function(e){
  453. var _self = this;
  454. _self.app.confirm("warn",e,_self.lp.submitWarn.warnTitle,_self.lp.submitWarn.warnArchiveContent,300,120,function(){
  455. _self.actions.archiveMainTask(_self.centerWorkData.id, function(json){
  456. if(json.type && json.type=="success"){
  457. _self.app.notice(this.lp.prompt.archiveCenterWork, "success");
  458. _self.close();
  459. _self.fireEvent("reloadView", {"action":"reload"});
  460. }
  461. }.bind(_self),function(xhr,text,error){
  462. _self.showErrorMessage(xhr,text,error)
  463. }.bind(_self));
  464. this.close()
  465. },function(){
  466. this.close();
  467. })
  468. },
  469. //*************************底部按钮及方法**************************************
  470. createShade: function(txt){
  471. if(this.shadeDiv){ this.shadeDiv.destroy()}
  472. if(this.shadeTxtDiv) this.shadeTxtDiv.destroy()
  473. this.shadeDiv = new Element("div.shadeDiv").inject(this.formNode)
  474. this.shadeTxtDiv = new Element("div.shadeTxtDiv").inject(this.shadeDiv);
  475. this.shadeTxtDiv.set("text",txt)
  476. this.shadeDiv.setStyles({
  477. "left":"0px","top":"40px","width":"100%","height":"100%","position":"absolute","opacity":"0.6","background-color":"#999999","z-index":"999",
  478. "text-align":"center"
  479. })
  480. this.shadeTxtDiv.setStyles({"color":"#ffffff","font-size":"30px","margin-top":"300px"})
  481. },
  482. destroyShade : function(){
  483. if(this.shadeDiv) this.shadeDiv.destroy()
  484. if(this.shadeDiv) this.shadeDiv.destroy()
  485. },
  486. saveCenterWork: function(data,callback){
  487. this.app.restActions.saveCenterWork( data,
  488. function(json){
  489. if( callback )callback(json);
  490. }.bind(this),
  491. function(xhr,text,error){
  492. this.showErrorMessage(xhr,text,error)
  493. }.bind(this),
  494. false
  495. );
  496. },
  497. openWorkForm : function( data ){
  498. MWF.xDesktop.requireApp("Execution", "WorkForm", function(){
  499. this.workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,{"centerWorkId": data.id || this.options.centerWorkId },{
  500. "isNew": true,
  501. "isEdited": false,
  502. "actionStatus":"save",
  503. "onPostSave" : function(){
  504. this.reloadTableContent()
  505. }.bind(this)
  506. });
  507. //alert("cccc="+this.centerWorkId)
  508. this.workform.load();
  509. }.bind(this));
  510. },
  511. showErrorMessage:function(xhr,text,error){
  512. var errorText = error;
  513. if (xhr) errorMessage = xhr.responseText;
  514. if(errorMessage!=""){
  515. var e = JSON.parse(errorMessage);
  516. if(e.message){
  517. this.app.notice( e.message,"error");
  518. }else{
  519. this.app.notice( errorText,"error");
  520. }
  521. }else{
  522. this.app.notice(errorText,"error")
  523. }
  524. }
  525. })
  526. MWF.xApplication.Execution.WorkDeploy.MyDeployWorkView = new Class({
  527. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  528. _createDocument: function(data){
  529. return new MWF.xApplication.Execution.WorkDeploy.MyDeployWorkDocument(this.viewNode, data, this.explorer, this);
  530. },
  531. _getCurrentPageData: function(callback, count){
  532. if(!this.explorer.centerWorkId) return
  533. this.actions.getMyDeployWork(this.explorer.centerWorkId,function(json){
  534. if(json.data.length==0){
  535. this.explorer.myDeployWorkArea.destroy();
  536. }
  537. if (callback) callback(json)
  538. }.bind(this),
  539. function(xhr,text,error){
  540. this.explorer.showErrorMessage(xhr,text,error)
  541. }.bind(this),false)
  542. },
  543. _queryCreateViewNode: function(){
  544. },
  545. _postCreateViewNode: function( viewNode ){
  546. },
  547. _queryCreateViewHead:function(){
  548. },
  549. _postCreateViewHead: function( headNode ){
  550. }
  551. })
  552. MWF.xApplication.Execution.WorkDeploy.MyDeployWorkDocument = new Class({
  553. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  554. action_edit : function(){
  555. this.workForm = new MWF.xApplication.Execution.WorkDeploy.WorkForm(this.view.explorer, this.actions, this.data, {
  556. "isNew": false,
  557. "isEdited": true,
  558. "actionStatus":"save",
  559. "onPostSave" : function(){
  560. this.view.explorer.contentChanged = true;
  561. }.bind(this)
  562. })
  563. this.workForm.load();
  564. },
  565. _queryCreateDocumentNode:function( itemData ){
  566. },
  567. _postCreateDocumentNode: function( itemNode, itemData ){
  568. var ftd = itemNode.getElements("td")[0]
  569. itemNode.empty()
  570. var newTd = new Element("td",{
  571. "colspan":this.view.template.items.length,
  572. "style":ftd.get("style"),
  573. "html":ftd.get("html")
  574. }).inject(itemNode)
  575. if(itemData.subWorks){
  576. itemData.subWorks.each(function(d,i){
  577. var subTrNode = new Element("tr.subTrNode",{
  578. "styles":this.css.subTrNode
  579. }).inject(this.view.viewNode)
  580. subTrNode.addEvents({
  581. "click":function(){
  582. this.action_view(d.id)
  583. }.bind(this),
  584. "mouseover":function(){
  585. subTrNode.setStyles(this.css["documentNode_over"])
  586. }.bind(this),
  587. "mouseout":function(){
  588. subTrNode.setStyles(this.css.subTrNode)
  589. }.bind(this)
  590. })
  591. this.view.template.items.each(function(dd,i){
  592. htmlValue = dd.content.html;
  593. subTrNode.set("html",subTrNode.get("html")+htmlValue)
  594. }.bind(this))
  595. this.setLables(subTrNode,d);
  596. this.setValues(subTrNode,d);
  597. this.setStyles(subTrNode,d);
  598. this.setActions(subTrNode,d)
  599. }.bind(this))
  600. }
  601. },
  602. setLables:function(container,data){
  603. container.getElements("[lable]").each(function(el){
  604. var val = el.get("lable");
  605. if( val && this.lp[val] ){
  606. el.set("text", this.lp[val] )
  607. }
  608. }.bind(this))
  609. },
  610. setValues:function(container,data){
  611. container.getElements("[item]").each(function(el){
  612. var val = el.get("item");
  613. if(data[val]){
  614. el.set("text", data[val].length>70 ? data[val].substr(0,70)+'...' : data[val])
  615. }
  616. }.bind(this))
  617. container.getElements("[title]").each(function(el){
  618. var val = el.get("title");
  619. if(data[val]){
  620. el.set("title", data[val] )
  621. }
  622. }.bind(this))
  623. },
  624. setStyles:function(container,data){
  625. var tdActionNode = container.getElements("td[actionTd='yes']")
  626. if(!tdActionNode) return
  627. container.getElements("[styles]").each(function(el){
  628. var val = el.get("styles");
  629. if( val && this.css[val] ){
  630. el.setStyles(this.css[val])
  631. }
  632. }.bind(this))
  633. container.getElements("[subStyles]").each(function(el){
  634. var val = el.get("subStyles");
  635. if( val && this.css[val] ){
  636. el.setStyles(this.css[val])
  637. }
  638. }.bind(this))
  639. },
  640. setActions:function(container,data){
  641. var actionTdNode = container.getElement("td[actionTd='yes']")
  642. if(!actionTdNode) return
  643. if(data.operation){
  644. data.operation.each(function(d,i){
  645. var actionSpan = new Element("span.actionSpan",{
  646. "styles":this.css.documentActionNode,
  647. }).inject(actionTdNode)
  648. if(data.operation.length==1){
  649. if(d == "VIEW"){
  650. actionSpan.set("text",this.lp.action_view)
  651. actionSpan.addEvent("click", function (e) {
  652. this.action_view(data.id);
  653. return false;
  654. }.bind(this));
  655. }
  656. }
  657. if(d == "EDIT"){
  658. actionSpan.set("text",this.lp.action_edit)
  659. actionSpan.addEvent("click", function (e) {
  660. this.action_edit(data.id);
  661. return false;
  662. }.bind(this));
  663. }else if(d == "DELETE"){
  664. actionSpan.set("text",this.lp.action_delete)
  665. actionSpan.addEvent("click", function (e) {
  666. this.action_delete(data.id,e);
  667. return false;
  668. }.bind(this));
  669. }
  670. }.bind(this))
  671. }
  672. },
  673. action_view:function(id){
  674. this.workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,{"id": id },{
  675. "isNew": false,
  676. "isEdited": false,
  677. "actionStatus":"save",
  678. "onPostSave" : function(){
  679. this.explorer.contentChanged = true;
  680. }.bind(this)
  681. });
  682. this.workform.load();
  683. },
  684. action_edit:function(id){
  685. this.workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,{"id": id },{
  686. "isNew": false,
  687. "isEdited": true,
  688. "actionStatus":"save",
  689. "onPostSave" : function(){
  690. this.explorer.reloadTableContent()
  691. }.bind(this)
  692. });
  693. this.workform.load();
  694. },
  695. action_delete:function(id,e){
  696. var _self = this;
  697. _self.view.app.confirm("warn",e,_self.view.app.lp.WorkDeploy.submitWarn.warnTitle,_self.view.app.lp.WorkDeploy.submitWarn.warnContent,300,120,function(){
  698. _self.actions.deleteBaseWork(id, function(json){
  699. if(json.type && json.type=="success"){
  700. this.app.notice(_self.view.explorer.lp.prompt.deleteBaseWork, "success");
  701. _self.view.explorer.reloadTableContent()
  702. }
  703. }.bind(_self),function(xhr,text,error){
  704. _self.view.explorer.showErrorMessage(xhr,text,error)
  705. }.bind(_self));
  706. this.close()
  707. },function(){
  708. this.close();
  709. })
  710. }
  711. })
  712. MWF.xApplication.Execution.WorkDeploy.MyWorkView = new Class({
  713. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  714. _createDocument: function(data){
  715. return new MWF.xApplication.Execution.WorkDeploy.MyWorkDocument(this.viewNode, data, this.explorer, this);
  716. },
  717. _getCurrentPageData: function(callback, count){
  718. if(this.explorer.centerWorkId){
  719. this.actions.getMyRelativeWork( this.explorer.centerWorkId, function(json){
  720. if(json.data.length==0){
  721. this.explorer.myWorkContentArea.destroy();
  722. }
  723. if (callback) callback(json)
  724. }.bind(this),null,false);
  725. }
  726. },
  727. _openDocument: function( documentData ){
  728. this.workForm = new MWF.xApplication.Execution.WorkForm(this, this.actions, documentData, {
  729. "isNew": false,
  730. "isEdited": false
  731. })
  732. this.workForm.load();
  733. },
  734. _queryCreateViewNode: function(){
  735. },
  736. _postCreateViewNode: function( viewNode ){
  737. },
  738. _queryCreateViewHead:function(){
  739. },
  740. _postCreateViewHead: function( headNode ){
  741. }
  742. })
  743. MWF.xApplication.Execution.WorkDeploy.MyWorkDocument = new Class({
  744. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  745. viewActionReturn:function(d) {
  746. var ret = false
  747. if(d.operation && d.operation.length==1){
  748. ret = true;
  749. }
  750. return ret;
  751. },
  752. splitActionReturn:function(d) {
  753. var ret = false
  754. if (d.operation && d.operation.indexOf("SPLIT")>-1)ret = true;
  755. return ret;
  756. },
  757. authorizeActionReturn:function(d) {
  758. var ret = false
  759. if (d.operation && d.operation.indexOf("AUTHORIZE")>-1)ret = true;
  760. return ret;
  761. },
  762. tackBackActionReturn:function(d){
  763. var ret = false
  764. if (d.operation && d.operation.indexOf("TACKBACK")>-1)ret = true;
  765. return ret;
  766. },
  767. action_view:function(){
  768. MWF.xDesktop.requireApp("Execution", "WorkForm", function(){
  769. var workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,this.data,{
  770. "isNew": false,
  771. "isEdited": false
  772. });
  773. workform.load();
  774. }.bind(this));
  775. },
  776. action_split:function(){
  777. MWF.xDesktop.requireApp("Execution", "WorkForm", function(){
  778. var data = {
  779. title : this.data.title,
  780. centerId : this.data.centerId,
  781. //centerTitle: this.data.centerTitle,
  782. parentWorkId : this.data.id,
  783. //parentWorkTitle : this.data.title,
  784. workType : this.data.workType,
  785. workLevel : this.data.workLevel,
  786. completeDateLimitStr : this.data.completeDateLimitStr,
  787. completeDateLimit : this.data.completeDateLimit,
  788. reportCycle: this.data.reportCycle,
  789. reportDayInCycle: this.data.reportDayInCycle
  790. }
  791. if(this.data.id){
  792. this.actions.getBaseWorkDetails(this.data.id, function (json) {
  793. data.workSplitAndDescription = json.data.workDetail
  794. //data.specificActionInitiatives = json.data.progressAction
  795. //data.cityCompanyDuty = json.data.dutyDescription
  796. //data.milestoneMark = json.data.landmarkDescription
  797. //data.importantMatters = json.data.majorIssuesDescription
  798. }.bind(this),null,false)
  799. }
  800. var workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,{},{
  801. "isNew": true,
  802. "isEdited": false,
  803. "parentWorkId":this.data.id,
  804. "actionStatus":"save",
  805. "onPostSave" : function(){
  806. this.explorer.reloadTableContent()
  807. }.bind(this)
  808. });
  809. workform.load();
  810. }.bind(this));
  811. },
  812. action_authorize:function(){
  813. data = {
  814. workId : this.data.id
  815. };
  816. var appointForm = new MWF.xApplication.Execution.WorkDeploy.Appoint(this.view.app,this.view.app.restActions,data,this.view.css,{
  817. "ieEdited": true,
  818. "onReloadView" : function( data ){
  819. this.explorer.reloadTableContent()
  820. }.bind(this)
  821. });
  822. appointForm.load();
  823. },
  824. action_tackBack: function(e){
  825. var _self = this;
  826. _self.app.confirm("warn",e,_self.lp.submitWarn.warnTitle,_self.lp.submitWarn.warnTackBackContent,300,120,function(){
  827. _self.actions.unAppointBaseWork({workId:_self.data.id}, function(json){
  828. if(json.type && json.type=="success"){
  829. _self.app.notice(_self.explorer.lp.prompt.tackbackBaseWork, "success");
  830. _self.explorer.reloadTableContent();
  831. }
  832. }.bind(_self),function(xhr,text,error){
  833. _self.explorer.showErrorMessage(xhr,text,error)
  834. }.bind(_self));
  835. this.close()
  836. },function(){
  837. this.close();
  838. })
  839. },
  840. _queryCreateDocumentNode:function( itemData ){
  841. },
  842. _postCreateDocumentNode: function( itemNode, itemData ){
  843. if(itemNode.getElements("div[item='workDetail']").length>0){
  844. if(itemData.hasSubWorks){
  845. itemNode.getElements("div[item='workDetail']").setStyle("color","#ec6a1a");
  846. }
  847. //this.view.actions.getBaseWorksByParentId(itemData.id,function(json){
  848. // if(json.data && json.data.length>0){
  849. // itemNode.getElements("div[item='title']").setStyle("color","#ec6a1a");
  850. // //itemNode.getElements("div[item='title']").set("title",this.view.lp.splitReady);
  851. // }
  852. //}.bind(this))
  853. }
  854. if(itemNode.getElements("div[name='appointDiv']")){
  855. if(itemData.workProcessIdentity && itemData.workProcessIdentity.indexOf("AUTHORIZE")>-1){
  856. itemNode.getElements("div[name='appointDiv']").setStyle("display","")
  857. }
  858. }
  859. if(itemNode.getElements("div[styles='documentSubject']")){
  860. itemNode.getElements("div[styles='documentSubject']").set("title",itemData.workDetail)
  861. }
  862. }
  863. })
  864. MWF.xApplication.Execution.WorkDeploy.Appoint = new Class({
  865. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  866. Implements: [Options, Events],
  867. options: {
  868. "style": "default",
  869. "width": "500",
  870. "height": "300",
  871. "hasTop": true,
  872. "hasIcon": false,
  873. "hasBottom": true,
  874. "title": "",
  875. "draggable": false,
  876. "closeAction": true,
  877. "closeText" : "",
  878. "needLogout" : false,
  879. "isNew": true
  880. },
  881. initialize: function (app, actions, data, css, options) {
  882. this.setOptions(options);
  883. this.app = app;
  884. this.actions = this.app.restActions;
  885. this.css = css;
  886. //this.options.title = this.app.lp.idenitySelectTitle;
  887. //
  888. //this.identities = identities;
  889. this.data = data || {};
  890. this.actions = actions;
  891. },
  892. load: function () {
  893. this.create();
  894. },
  895. createTopNode: function () {
  896. if (!this.formTopNode) {
  897. this.formTopNode = new Element("div.formTopNode", {
  898. "styles": this.css.formTopNode
  899. }).inject(this.formNode);
  900. this.formTopIconNode = new Element("div.formTopIconNode", {
  901. "styles": this.css.formTopIconNode
  902. }).inject(this.formTopNode)
  903. this.formTopTextNode = new Element("div.formTopTextNode", {
  904. "styles": this.css.formTopTextNode,
  905. "text": this.app.lp.workTask.appoint.appointTitle
  906. }).inject(this.formTopNode)
  907. if (this.options.closeAction) {
  908. this.formTopCloseActionNode = new Element("div.formTopCloseActionNode", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  909. this.formTopCloseActionNode.addEvent("click", function () {
  910. this.close()
  911. }.bind(this))
  912. }
  913. this.formTopContentNode = new Element("div.formTopContentNode", {
  914. "styles": this.css.formTopContentNode
  915. }).inject(this.formTopNode)
  916. //this._createTopContent();
  917. }
  918. },
  919. _createTableContent: function () {
  920. var table = new Element("table",{"width":"100%",border:"0",cellpadding:"5",cellspacing:"0"}).inject(this.formTableArea);
  921. table.setStyles({"margin-top":"40px"})
  922. var tr = new Element("tr").inject(table);
  923. var td = new Element("td",{
  924. text : this.app.lp.workTask.appoint.appointFor,
  925. valign:"middle",
  926. width:"20%"
  927. }).inject(tr);
  928. td = new Element("td",{width:"80%"}).inject(tr);
  929. this.appointPerson = new Element("input",{
  930. "readonly": true
  931. }).inject(td);
  932. this.appointPerson.setStyles({"width":"90%","height":"20px"})
  933. this.appointPerson.addEvents({
  934. "click":function(){
  935. this.selectPerson(this.appointPerson,"identity",1)
  936. }.bind(this)
  937. })
  938. tr = new Element("tr").inject(table);
  939. td = new Element("td",{
  940. "text" : this.app.lp.workTask.appoint.appointOpinion,
  941. valign:"middle"
  942. }).inject(tr);
  943. td = new Element("td").inject(tr);
  944. this.appointOpinion = new Element("textarea").inject(td)
  945. this.appointOpinion.setStyles({"width":"90%","height":"50px"})
  946. },
  947. _createBottomContent: function () {
  948. this.cancelActionNode = new Element("div.formCancelActionNode", {
  949. "styles": this.css.formCancelActionNode,
  950. "text": this.app.lp.workTask.appoint.appointCancel
  951. }).inject(this.formBottomNode);
  952. this.cancelActionNode.addEvent("click", function (e) {
  953. this.close();
  954. }.bind(this));
  955. this.okActionNode = new Element("div.formOkActionNode", {
  956. "styles": this.css.formOkActionNode,
  957. "text": this.app.lp.workTask.appoint.appointOK
  958. }).inject(this.formBottomNode);
  959. this.okActionNode.addEvent("click", function (e) {
  960. this.ok(e);
  961. }.bind(this));
  962. },
  963. ok:function(){
  964. if(this.appointPerson.get("value")==""){
  965. this.app.notice(this.app.lp.workTask.appoint.personEmpty,"error")
  966. return false;
  967. }
  968. if(this.appointOpinion.get("value")==""){
  969. this.app.notice(this.app.lp.workTask.appoint.opinionEmpty,"error")
  970. return false;
  971. }
  972. var submitData = {
  973. workId : this.data.workId,
  974. undertakerIdentity : this.appointPerson.get("value"),
  975. authorizeOpinion : this.appointOpinion.get("value")
  976. }
  977. this.actions.appointBaseWork(submitData,function(json){
  978. this.app.notice(this.app.lp.WorkDeploy.prompt.authorizeBaseWork,"success")
  979. this.close();
  980. this.fireEvent("reloadView");
  981. }.bind(this),function(xhr,text,error){
  982. var errorText = error;
  983. if (xhr) errorMessage = xhr.responseText;
  984. var e = JSON.parse(errorMessage);
  985. if(e.message){
  986. this.app.notice( e.message,"error");
  987. }else{
  988. this.app.notice( errorText,"error");
  989. }
  990. }.bind(this),false)
  991. },
  992. selectPerson: function( item, type,count ) {
  993. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  994. this.fireEvent("querySelect", this);
  995. var value = item.get("value").split(this.valSeparator);
  996. var options = {
  997. "type": type,
  998. "title": this.app.lp.workTask.appoint.appointTitle,
  999. "count": count,
  1000. "names": value || [],
  1001. "onComplete": function (items) {
  1002. var arr = [];
  1003. items.each(function (item) {
  1004. arr.push(item.data.name);
  1005. }.bind(this));
  1006. item.set("value", arr.join(","));
  1007. }.bind(this)
  1008. };
  1009. var selector = new MWF.OrgSelector(this.app.content, options);
  1010. }
  1011. });