WorkDeploy.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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.app.createShade(null,"正在导入,请稍后.....")
  388. this.actions.importBaseWork(centerId,function(json){
  389. this.reloadTableContent(centerId)
  390. this.app.destroyShade()
  391. }.bind(this),function(xhr,text,error){
  392. this.showErrorMessage(xhr,text,error)
  393. this.app.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.app.createShade();
  406. _self.actions.deleteCenterWork(_self.centerWorkData.id, function(json){
  407. if(json.type && json.type=="success"){
  408. _self.app.notice(this.lp.prompt.deleteCenterWork, "success");
  409. _self.closeWork({"action":"reload"});
  410. }
  411. _self.app.destroyShade();
  412. }.bind(_self),function(xhr,text,error){
  413. _self.showErrorMessage(xhr,text,error);
  414. _self.app.destroyShade();
  415. }.bind(_self));
  416. this.close()
  417. },function(){
  418. this.close();
  419. })
  420. },
  421. deployWork:function(e){
  422. var _self = this;
  423. _self.app.confirm("warn",e,_self.lp.submitWarn.warnTitle,_self.lp.submitWarn.warnDeployContent,300,120,function(){
  424. _self.app.createShade();
  425. _self.actions.deployCenterWork(_self.centerWorkData.id, function(json){
  426. if(json.type && json.type=="success"){
  427. _self.app.notice(this.lp.prompt.deployCenterWork, "success");
  428. _self.close();
  429. _self.fireEvent("reloadView", {"action":"reload"});
  430. _self.app.destroyShade();
  431. }
  432. }.bind(_self),function(xhr,text,error){
  433. _self.showErrorMessage(xhr,text,error);
  434. _self.app.destroyShade();
  435. }.bind(_self));
  436. this.close()
  437. },function(){
  438. this.close();
  439. })
  440. },
  441. confirmWork:function(e){
  442. var _self = this;
  443. _self.app.confirm("warn",e,_self.lp.submitWarn.warnTitle,_self.lp.submitWarn.warnConfirmContent,300,120,function(){
  444. _self.actions.deployCenterWork(_self.centerWorkData.id, function(json){
  445. _self.app.createShade();
  446. if(json.type && json.type=="success"){
  447. _self.app.notice(this.lp.prompt.comfirmCenterWork, "success");
  448. _self.close();
  449. _self.fireEvent("reloadView", {"action":"reload"});
  450. _self.app.destroyShade();
  451. }
  452. }.bind(_self),function(xhr,text,error){
  453. _self.showErrorMessage(xhr,text,error);
  454. _self.app.destroyShade();
  455. }.bind(_self));
  456. this.close()
  457. },function(){
  458. this.close();
  459. })
  460. },
  461. archiveWork:function(e){
  462. var _self = this;
  463. _self.app.confirm("warn",e,_self.lp.submitWarn.warnTitle,_self.lp.submitWarn.warnArchiveContent,300,120,function(){
  464. _self.app.createShade();
  465. _self.actions.archiveMainTask(_self.centerWorkData.id, function(json){
  466. if(json.type && json.type=="success"){
  467. _self.app.notice(this.lp.prompt.archiveCenterWork, "success");
  468. _self.close();
  469. _self.fireEvent("reloadView", {"action":"reload"});
  470. _self.app.destroyShade();
  471. }
  472. }.bind(_self),function(xhr,text,error){
  473. _self.showErrorMessage(xhr,text,error);
  474. _self.app.destroyShade();
  475. }.bind(_self));
  476. this.close()
  477. },function(){
  478. this.close();
  479. })
  480. },
  481. //*************************底部按钮及方法**************************************
  482. saveCenterWork: function(data,callback){
  483. this.app.restActions.saveCenterWork( data,
  484. function(json){
  485. if( callback )callback(json);
  486. }.bind(this),
  487. function(xhr,text,error){
  488. this.showErrorMessage(xhr,text,error)
  489. }.bind(this),
  490. false
  491. );
  492. },
  493. openWorkForm : function( data ){
  494. MWF.xDesktop.requireApp("Execution", "WorkForm", function(){
  495. this.workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,{"centerWorkId": data.id || this.options.centerWorkId },{
  496. "isNew": true,
  497. "isEdited": false,
  498. "actionStatus":"save",
  499. "onPostSave" : function(){
  500. this.reloadTableContent()
  501. }.bind(this)
  502. });
  503. //alert("cccc="+this.centerWorkId)
  504. this.workform.load();
  505. }.bind(this));
  506. },
  507. showErrorMessage:function(xhr,text,error){
  508. var errorText = error;
  509. if (xhr) errorMessage = xhr.responseText;
  510. if(errorMessage!=""){
  511. var e = JSON.parse(errorMessage);
  512. if(e.message){
  513. this.app.notice( e.message,"error");
  514. }else{
  515. this.app.notice( errorText,"error");
  516. }
  517. }else{
  518. this.app.notice(errorText,"error")
  519. }
  520. }
  521. })
  522. MWF.xApplication.Execution.WorkDeploy.MyDeployWorkView = new Class({
  523. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  524. _createDocument: function(data){
  525. return new MWF.xApplication.Execution.WorkDeploy.MyDeployWorkDocument(this.viewNode, data, this.explorer, this);
  526. },
  527. _getCurrentPageData: function(callback, count){
  528. if(!this.explorer.centerWorkId) return
  529. this.actions.getMyDeployWork(this.explorer.centerWorkId,function(json){
  530. if(json.data.length==0){
  531. this.explorer.myDeployWorkArea.destroy();
  532. }
  533. if (callback) callback(json)
  534. }.bind(this),
  535. function(xhr,text,error){
  536. this.explorer.showErrorMessage(xhr,text,error)
  537. }.bind(this),false)
  538. },
  539. _queryCreateViewNode: function(){
  540. },
  541. _postCreateViewNode: function( viewNode ){
  542. },
  543. _queryCreateViewHead:function(){
  544. },
  545. _postCreateViewHead: function( headNode ){
  546. }
  547. })
  548. MWF.xApplication.Execution.WorkDeploy.MyDeployWorkDocument = new Class({
  549. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  550. action_edit : function(){
  551. this.workForm = new MWF.xApplication.Execution.WorkDeploy.WorkForm(this.view.explorer, this.actions, this.data, {
  552. "isNew": false,
  553. "isEdited": true,
  554. "actionStatus":"save",
  555. "onPostSave" : function(){
  556. this.view.explorer.contentChanged = true;
  557. }.bind(this)
  558. })
  559. this.workForm.load();
  560. },
  561. _queryCreateDocumentNode:function( itemData ){
  562. },
  563. _postCreateDocumentNode: function( itemNode, itemData ){
  564. var ftd = itemNode.getElements("td")[0]
  565. itemNode.empty()
  566. var newTd = new Element("td",{
  567. "colspan":this.view.template.items.length,
  568. "style":ftd.get("style"),
  569. "html":ftd.get("html")
  570. }).inject(itemNode)
  571. if(itemData.subWorks){
  572. itemData.subWorks.each(function(d,i){
  573. var subTrNode = new Element("tr.subTrNode",{
  574. "styles":this.css.subTrNode
  575. }).inject(this.view.viewNode)
  576. subTrNode.addEvents({
  577. "click":function(){
  578. this.action_view(d.id)
  579. }.bind(this),
  580. "mouseover":function(){
  581. subTrNode.setStyles(this.css["documentNode_over"])
  582. }.bind(this),
  583. "mouseout":function(){
  584. subTrNode.setStyles(this.css.subTrNode)
  585. }.bind(this)
  586. })
  587. this.view.template.items.each(function(dd,i){
  588. htmlValue = dd.content.html;
  589. subTrNode.set("html",subTrNode.get("html")+htmlValue)
  590. }.bind(this))
  591. this.setLables(subTrNode,d);
  592. this.setValues(subTrNode,d);
  593. this.setStyles(subTrNode,d);
  594. this.setActions(subTrNode,d)
  595. }.bind(this))
  596. }
  597. },
  598. setLables:function(container,data){
  599. container.getElements("[lable]").each(function(el){
  600. var val = el.get("lable");
  601. if( val && this.lp[val] ){
  602. el.set("text", this.lp[val] )
  603. }
  604. }.bind(this))
  605. },
  606. setValues:function(container,data){
  607. container.getElements("[item]").each(function(el){
  608. var val = el.get("item");
  609. if(data[val]){
  610. el.set("text", data[val].length>70 ? data[val].substr(0,70)+'...' : data[val])
  611. }
  612. }.bind(this))
  613. container.getElements("[title]").each(function(el){
  614. var val = el.get("title");
  615. if(data[val]){
  616. el.set("title", data[val] )
  617. }
  618. }.bind(this))
  619. },
  620. setStyles:function(container,data){
  621. var tdActionNode = container.getElements("td[actionTd='yes']")
  622. if(!tdActionNode) return
  623. container.getElements("[styles]").each(function(el){
  624. var val = el.get("styles");
  625. if( val && this.css[val] ){
  626. el.setStyles(this.css[val])
  627. }
  628. }.bind(this))
  629. container.getElements("[subStyles]").each(function(el){
  630. var val = el.get("subStyles");
  631. if( val && this.css[val] ){
  632. el.setStyles(this.css[val])
  633. }
  634. }.bind(this))
  635. },
  636. setActions:function(container,data){
  637. var actionTdNode = container.getElement("td[actionTd='yes']")
  638. if(!actionTdNode) return
  639. if(data.operation){
  640. data.operation.each(function(d,i){
  641. var actionSpan = new Element("span.actionSpan",{
  642. "styles":this.css.documentActionNode,
  643. }).inject(actionTdNode)
  644. if(data.operation.length==1){
  645. if(d == "VIEW"){
  646. actionSpan.set("text",this.lp.action_view)
  647. actionSpan.addEvent("click", function (e) {
  648. this.action_view(data.id);
  649. return false;
  650. }.bind(this));
  651. }
  652. }
  653. if(d == "EDIT"){
  654. actionSpan.set("text",this.lp.action_edit)
  655. actionSpan.addEvent("click", function (e) {
  656. this.action_edit(data.id);
  657. return false;
  658. }.bind(this));
  659. }else if(d == "DELETE"){
  660. actionSpan.set("text",this.lp.action_delete)
  661. actionSpan.addEvent("click", function (e) {
  662. this.action_delete(data.id,e);
  663. return false;
  664. }.bind(this));
  665. }
  666. }.bind(this))
  667. }
  668. },
  669. action_view:function(id){
  670. this.workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,{"id": id },{
  671. "isNew": false,
  672. "isEdited": false,
  673. "actionStatus":"save",
  674. "onPostSave" : function(){
  675. this.explorer.contentChanged = true;
  676. }.bind(this)
  677. });
  678. this.workform.load();
  679. },
  680. action_edit:function(id){
  681. this.workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,{"id": id },{
  682. "isNew": false,
  683. "isEdited": true,
  684. "actionStatus":"save",
  685. "onPostSave" : function(){
  686. this.explorer.reloadTableContent()
  687. }.bind(this)
  688. });
  689. this.workform.load();
  690. },
  691. action_delete:function(id,e){
  692. var _self = this;
  693. _self.view.app.confirm("warn",e,_self.view.app.lp.WorkDeploy.submitWarn.warnTitle,_self.view.app.lp.WorkDeploy.submitWarn.warnContent,300,120,function(){
  694. _self.app.createShade()
  695. _self.actions.deleteBaseWork(id, function(json){
  696. if(json.type && json.type=="success"){
  697. this.app.notice(_self.view.explorer.lp.prompt.deleteBaseWork, "success");
  698. _self.view.explorer.reloadTableContent();
  699. _self.app.destroyShade();
  700. }
  701. }.bind(_self),function(xhr,text,error){
  702. _self.view.explorer.showErrorMessage(xhr,text,error)
  703. _self.app.destroyShade();
  704. }.bind(_self));
  705. this.close()
  706. },function(){
  707. this.close();
  708. })
  709. }
  710. })
  711. MWF.xApplication.Execution.WorkDeploy.MyWorkView = new Class({
  712. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  713. _createDocument: function(data){
  714. return new MWF.xApplication.Execution.WorkDeploy.MyWorkDocument(this.viewNode, data, this.explorer, this);
  715. },
  716. _getCurrentPageData: function(callback, count){
  717. if(this.explorer.centerWorkId){
  718. this.actions.getMyRelativeWork( this.explorer.centerWorkId, function(json){
  719. if(json.data.length==0){
  720. this.explorer.myWorkContentArea.destroy();
  721. }
  722. if (callback) callback(json)
  723. }.bind(this),null,false);
  724. }
  725. },
  726. _openDocument: function( documentData ){
  727. this.workForm = new MWF.xApplication.Execution.WorkForm(this, this.actions, documentData, {
  728. "isNew": false,
  729. "isEdited": false
  730. })
  731. this.workForm.load();
  732. },
  733. _queryCreateViewNode: function(){
  734. },
  735. _postCreateViewNode: function( viewNode ){
  736. },
  737. _queryCreateViewHead:function(){
  738. },
  739. _postCreateViewHead: function( headNode ){
  740. }
  741. })
  742. MWF.xApplication.Execution.WorkDeploy.MyWorkDocument = new Class({
  743. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  744. viewActionReturn:function(d) {
  745. var ret = false
  746. if(d.operation && d.operation.length==1){
  747. ret = true;
  748. }
  749. return ret;
  750. },
  751. splitActionReturn:function(d) {
  752. var ret = false
  753. if (d.operation && d.operation.indexOf("SPLIT")>-1)ret = true;
  754. return ret;
  755. },
  756. authorizeActionReturn:function(d) {
  757. var ret = false
  758. if (d.operation && d.operation.indexOf("AUTHORIZE")>-1)ret = true;
  759. return ret;
  760. },
  761. tackBackActionReturn:function(d){
  762. var ret = false
  763. if (d.operation && d.operation.indexOf("TACKBACK")>-1)ret = true;
  764. return ret;
  765. },
  766. action_view:function(){
  767. MWF.xDesktop.requireApp("Execution", "WorkForm", function(){
  768. var workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,this.data,{
  769. "isNew": false,
  770. "isEdited": false
  771. });
  772. workform.load();
  773. }.bind(this));
  774. },
  775. action_split:function(){
  776. MWF.xDesktop.requireApp("Execution", "WorkForm", function(){
  777. var data = {
  778. title : this.data.title,
  779. centerId : this.data.centerId,
  780. //centerTitle: this.data.centerTitle,
  781. parentWorkId : this.data.id,
  782. //parentWorkTitle : this.data.title,
  783. workType : this.data.workType,
  784. workLevel : this.data.workLevel,
  785. completeDateLimitStr : this.data.completeDateLimitStr,
  786. completeDateLimit : this.data.completeDateLimit,
  787. reportCycle: this.data.reportCycle,
  788. reportDayInCycle: this.data.reportDayInCycle
  789. }
  790. if(this.data.id){
  791. this.actions.getBaseWorkDetails(this.data.id, function (json) {
  792. data.workSplitAndDescription = json.data.workDetail
  793. //data.specificActionInitiatives = json.data.progressAction
  794. //data.cityCompanyDuty = json.data.dutyDescription
  795. //data.milestoneMark = json.data.landmarkDescription
  796. //data.importantMatters = json.data.majorIssuesDescription
  797. }.bind(this),null,false)
  798. }
  799. var workform = new MWF.xApplication.Execution.WorkForm(this, this.app.restActions,{},{
  800. "isNew": true,
  801. "isEdited": false,
  802. "parentWorkId":this.data.id,
  803. "actionStatus":"save",
  804. "onPostSave" : function(){
  805. this.explorer.reloadTableContent()
  806. }.bind(this)
  807. });
  808. workform.load();
  809. }.bind(this));
  810. },
  811. action_authorize:function(){
  812. data = {
  813. workId : this.data.id
  814. };
  815. var appointForm = new MWF.xApplication.Execution.WorkDeploy.Appoint(this.view.app,this.view.app.restActions,data,this.view.css,{
  816. "ieEdited": true,
  817. "onReloadView" : function( data ){
  818. this.explorer.reloadTableContent()
  819. }.bind(this)
  820. });
  821. appointForm.load();
  822. },
  823. action_tackBack: function(e){
  824. var _self = this;
  825. _self.app.confirm("warn",e,_self.lp.submitWarn.warnTitle,_self.lp.submitWarn.warnTackBackContent,300,120,function(){
  826. _self.actions.unAppointBaseWork({workId:_self.data.id}, function(json){
  827. if(json.type && json.type=="success"){
  828. _self.app.notice(_self.explorer.lp.prompt.tackbackBaseWork, "success");
  829. _self.explorer.reloadTableContent();
  830. }
  831. }.bind(_self),function(xhr,text,error){
  832. _self.explorer.showErrorMessage(xhr,text,error)
  833. }.bind(_self));
  834. this.close()
  835. },function(){
  836. this.close();
  837. })
  838. },
  839. _queryCreateDocumentNode:function( itemData ){
  840. },
  841. _postCreateDocumentNode: function( itemNode, itemData ){
  842. if(itemNode.getElements("div[item='workDetail']").length>0){
  843. if(itemData.hasSubWorks){
  844. itemNode.getElements("div[item='workDetail']").setStyle("color","#ec6a1a");
  845. }
  846. //this.view.actions.getBaseWorksByParentId(itemData.id,function(json){
  847. // if(json.data && json.data.length>0){
  848. // itemNode.getElements("div[item='title']").setStyle("color","#ec6a1a");
  849. // //itemNode.getElements("div[item='title']").set("title",this.view.lp.splitReady);
  850. // }
  851. //}.bind(this))
  852. }
  853. if(itemNode.getElements("div[name='appointDiv']")){
  854. if(itemData.workProcessIdentity && itemData.workProcessIdentity.indexOf("AUTHORIZE")>-1){
  855. itemNode.getElements("div[name='appointDiv']").setStyle("display","")
  856. }
  857. }
  858. if(itemNode.getElements("div[styles='documentSubject']")){
  859. itemNode.getElements("div[styles='documentSubject']").set("title",itemData.workDetail)
  860. }
  861. }
  862. })
  863. MWF.xApplication.Execution.WorkDeploy.Appoint = new Class({
  864. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  865. Implements: [Options, Events],
  866. options: {
  867. "style": "default",
  868. "width": "500",
  869. "height": "300",
  870. "hasTop": true,
  871. "hasIcon": false,
  872. "hasBottom": true,
  873. "title": "",
  874. "draggable": false,
  875. "closeAction": true,
  876. "closeText" : "",
  877. "needLogout" : false,
  878. "isNew": true
  879. },
  880. initialize: function (app, actions, data, css, options) {
  881. this.setOptions(options);
  882. this.app = app;
  883. this.actions = this.app.restActions;
  884. this.css = css;
  885. //this.options.title = this.app.lp.idenitySelectTitle;
  886. //
  887. //this.identities = identities;
  888. this.data = data || {};
  889. this.actions = actions;
  890. },
  891. load: function () {
  892. this.create();
  893. },
  894. createTopNode: function () {
  895. if (!this.formTopNode) {
  896. this.formTopNode = new Element("div.formTopNode", {
  897. "styles": this.css.formTopNode
  898. }).inject(this.formNode);
  899. this.formTopIconNode = new Element("div.formTopIconNode", {
  900. "styles": this.css.formTopIconNode
  901. }).inject(this.formTopNode)
  902. this.formTopTextNode = new Element("div.formTopTextNode", {
  903. "styles": this.css.formTopTextNode,
  904. "text": this.app.lp.workTask.appoint.appointTitle
  905. }).inject(this.formTopNode)
  906. if (this.options.closeAction) {
  907. this.formTopCloseActionNode = new Element("div.formTopCloseActionNode", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  908. this.formTopCloseActionNode.addEvent("click", function () {
  909. this.close()
  910. }.bind(this))
  911. }
  912. this.formTopContentNode = new Element("div.formTopContentNode", {
  913. "styles": this.css.formTopContentNode
  914. }).inject(this.formTopNode)
  915. //this._createTopContent();
  916. }
  917. },
  918. _createTableContent: function () {
  919. var table = new Element("table",{"width":"100%",border:"0",cellpadding:"5",cellspacing:"0"}).inject(this.formTableArea);
  920. table.setStyles({"margin-top":"40px"})
  921. var tr = new Element("tr").inject(table);
  922. var td = new Element("td",{
  923. text : this.app.lp.workTask.appoint.appointFor,
  924. valign:"middle",
  925. width:"20%"
  926. }).inject(tr);
  927. td = new Element("td",{width:"80%"}).inject(tr);
  928. this.appointPerson = new Element("input",{
  929. "readonly": true
  930. }).inject(td);
  931. this.appointPerson.setStyles({"width":"90%","height":"20px"})
  932. this.appointPerson.addEvents({
  933. "click":function(){
  934. this.selectPerson(this.appointPerson,"identity",1)
  935. }.bind(this)
  936. })
  937. tr = new Element("tr").inject(table);
  938. td = new Element("td",{
  939. "text" : this.app.lp.workTask.appoint.appointOpinion,
  940. valign:"middle"
  941. }).inject(tr);
  942. td = new Element("td").inject(tr);
  943. this.appointOpinion = new Element("textarea").inject(td)
  944. this.appointOpinion.setStyles({"width":"90%","height":"50px"})
  945. },
  946. _createBottomContent: function () {
  947. this.cancelActionNode = new Element("div.formCancelActionNode", {
  948. "styles": this.css.formCancelActionNode,
  949. "text": this.app.lp.workTask.appoint.appointCancel
  950. }).inject(this.formBottomNode);
  951. this.cancelActionNode.addEvent("click", function (e) {
  952. this.close();
  953. }.bind(this));
  954. this.okActionNode = new Element("div.formOkActionNode", {
  955. "styles": this.css.formOkActionNode,
  956. "text": this.app.lp.workTask.appoint.appointOK
  957. }).inject(this.formBottomNode);
  958. this.okActionNode.addEvent("click", function (e) {
  959. this.ok(e);
  960. }.bind(this));
  961. },
  962. ok:function(){
  963. if(this.appointPerson.get("value")==""){
  964. this.app.notice(this.app.lp.workTask.appoint.personEmpty,"error")
  965. return false;
  966. }
  967. if(this.appointOpinion.get("value")==""){
  968. this.app.notice(this.app.lp.workTask.appoint.opinionEmpty,"error")
  969. return false;
  970. }
  971. var submitData = {
  972. workId : this.data.workId,
  973. undertakerIdentity : this.appointPerson.get("value"),
  974. authorizeOpinion : this.appointOpinion.get("value")
  975. }
  976. this.actions.appointBaseWork(submitData,function(json){
  977. this.app.notice(this.app.lp.WorkDeploy.prompt.authorizeBaseWork,"success")
  978. this.close();
  979. this.fireEvent("reloadView");
  980. }.bind(this),function(xhr,text,error){
  981. var errorText = error;
  982. if (xhr) errorMessage = xhr.responseText;
  983. var e = JSON.parse(errorMessage);
  984. if(e.message){
  985. this.app.notice( e.message,"error");
  986. }else{
  987. this.app.notice( errorText,"error");
  988. }
  989. }.bind(this),false)
  990. },
  991. selectPerson: function( item, type,count ) {
  992. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  993. this.fireEvent("querySelect", this);
  994. var value = item.get("value").split(this.valSeparator);
  995. var options = {
  996. "type": type,
  997. "title": this.app.lp.workTask.appoint.appointTitle,
  998. "count": count,
  999. "names": value || [],
  1000. "onComplete": function (items) {
  1001. var arr = [];
  1002. items.each(function (item) {
  1003. arr.push(item.data.name);
  1004. }.bind(this));
  1005. item.set("value", arr.join(","));
  1006. }.bind(this)
  1007. };
  1008. var selector = new MWF.OrgSelector(this.app.content, options);
  1009. }
  1010. });