WorkForm.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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","Attachment",null,false);
  5. MWF.xApplication.Execution.WorkForm = new Class({
  6. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "width": "800",
  11. "height": "100%",
  12. "top" : 0,
  13. "left" : 0,
  14. "hasTop": true,
  15. "hasIcon": false,
  16. "hasBottom": true,
  17. "title": "",
  18. "draggable": false,
  19. "closeAction": 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.workForm;
  26. this.actions = this.app.restActions;
  27. this.path = "/x_component_Execution/$WorkForm/";
  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. //isNew = false,重新获取一遍,isNew = new 是新建工作 新建判断都方在options里 有parentWorkId一定是有上级工作,如果是centerWorkId是第一层创建
  36. if(this.options.isNew){
  37. if(this.options.parentWorkId){
  38. this.actions.getBaseWorkInfo(this.options.parentWorkId,function(json){
  39. if(json.data){
  40. this.parentWorkData = json.data
  41. }
  42. }.bind(this),
  43. function(xhr,text,error){
  44. this.showErrorMessage(xhr,text,error)
  45. }.bind(this),false
  46. )
  47. }else if(this.options.centerWorkId){
  48. this.data.centerId = this.options.centerWorkId
  49. }else if(this.data.centerWorkId) {
  50. this.data.centerId = this.data.centerWorkId
  51. }
  52. }else{
  53. if(this.data.id){
  54. this.id = this.data.id
  55. }else if(this.options.id){
  56. this.id = this.options.id
  57. }
  58. this.actions.getBaseWorkInfo(this.id,function(json){
  59. if(json.data){
  60. this.data = json.data
  61. }
  62. }.bind(this),
  63. function(xhr,text,error){
  64. this.showErrorMessage(xhr,text,error)
  65. }.bind(this),false
  66. )
  67. }
  68. if (this.options.isNew) {
  69. this.create();
  70. } else if (this.options.isEdited) {
  71. this.edit();
  72. } else {
  73. this.open();
  74. }
  75. },
  76. createTopNode: function () {
  77. if (!this.formTopNode) {
  78. this.formTopNode = new Element("div.formTopNode", {
  79. "styles": this.css.formTopNode
  80. }).inject(this.formNode);
  81. this.formTopIconNode = new Element("div", {
  82. "styles": this.css.formTopIconNode
  83. }).inject(this.formTopNode)
  84. this.formTopTextNode = new Element("div", {
  85. "styles": this.css.formTopTextNode,
  86. "text": this.options.title + ( this.data.title ? ("-" + this.data.title ) : "" )
  87. }).inject(this.formTopNode)
  88. if (this.options.closeAction) {
  89. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  90. this.formTopCloseActionNode.addEvent("click", function () {
  91. this.close()
  92. }.bind(this))
  93. }
  94. this.formTopContentNode = new Element("div", {
  95. "styles": this.css.formTopContentNode
  96. }).inject(this.formTopNode)
  97. this._createTopContent();
  98. }
  99. },
  100. _createTopContent: function () {
  101. },
  102. _createTableContent: function () {
  103. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  104. "<tr>" +
  105. " <td styles='formTableTitle' lable='timeLimit'></td>" +
  106. " <td styles='formTableValue' item='timeLimit'></td>" +
  107. " <td styles='formTableTitle' lable='reportCycle'></td>" +
  108. " <td styles='formTableValue'><span item='reportCycle'></span><span item='reportDay'></span></td>" +
  109. "</tr><tr>" +
  110. " <td styles='formTableTitle' lable='dutyDepartment'></td>" +
  111. " <td styles='formTableValue' item='dutyDepartment'></td>" +
  112. " <td styles='formTableTitle' lable='dutyPerson'></td>" +
  113. " <td styles='formTableValue' item='dutyPerson'></td>" +
  114. "</tr><tr>" +
  115. " <td styles='formTableTitle' lable='secondDepartment'></td>" +
  116. " <td styles='formTableValue' item='secondDepartment'></td>" +
  117. " <td styles='formTableTitle' lable='secondPerson'></td>" +
  118. " <td styles='formTableValue' item='secondPerson'></td>" +
  119. "</tr><tr>" +
  120. " <td styles='formTableTitle' lable='readReader'></td>" +
  121. " <td styles='formTableValue' item='readReader' colspan='3'></td>" +
  122. "</tr><tr>" +
  123. " <td styles='formTableValue' colspan='4'>" +
  124. " <div styles='formTableTitleDiv' lable='workSplitAndDescription'></div>" +
  125. " <div styles='formTableValueDiv' item='workSplitAndDescription'></div>" +
  126. " </td>" +
  127. "</tr><tr>" +
  128. " <td styles='formTableValue' colspan='4'>" +
  129. " <div styles='formTableTitleDiv' lable='specificActionInitiatives'></div>" +
  130. " <div styles='formTableValueDiv' item='specificActionInitiatives'></div>" +
  131. " </td>" +
  132. "</tr><tr>" +
  133. "</tr><tr>" +
  134. " <td styles='formTableValue' colspan='4'>" +
  135. " <div styles='formTableTitleDiv' lable='milestoneMark'></div>" +
  136. " <div styles='formTableValueDiv' item='milestoneMark'></div>" +
  137. " </td>" +
  138. "</tr><tr>" +
  139. " <td styles='formTableValue' colspan='4'>" +
  140. " <div styles='formTableValueDiv' item='attachments'></div>"+
  141. " </td>" +
  142. "</tr>"+
  143. "</table>"
  144. this.formTableArea.set("html", html);
  145. this.loadForm();
  146. },
  147. loadForm: function(){
  148. if(this.parentWorkData){
  149. this.data.parentWorkId = this.parentWorkData.id;
  150. this.data.workDetail = this.parentWorkData.workDetail;
  151. this.data.centerId = this.parentWorkData.centerId;
  152. }
  153. this.form = new MForm(this.formTableArea, this.data, {
  154. style: "execution",
  155. isEdited: this.isEdited || this.isNew,
  156. itemTemplate: this.getItemTemplate(this.lp )
  157. },this.app);
  158. this.form.load();
  159. var taObj = this.formTableArea.getElements("textarea");
  160. taObj.setStyles({height:"70px"})
  161. this.attachmentArea = this.formTableArea.getElement("[item='attachments']");
  162. this.loadAttachment( this.attachmentArea );
  163. },
  164. getItemTemplate: function( lp ){
  165. _self = this;
  166. return {
  167. workType: {
  168. text: lp.workType + ":",
  169. type: "select",
  170. notEmpty:true,
  171. selectValue: lp.workTypeValue.split(",")
  172. },
  173. workLevel: {
  174. text: lp.workLevel + ":",
  175. type: "select",
  176. notEmpty:true,
  177. selectValue: lp.workLevelValue.split(",")
  178. },
  179. timeLimit: {text: lp.timeLimit + ":", tType: "date",name:"completeDateLimitStr",notEmpty:true},
  180. reportCycle: {
  181. text: lp.reportCycle + ":",
  182. type: "select",
  183. notEmpty:true,
  184. //selectValue: lp.reportCycleValue.split(","),
  185. selectText: lp.reportCycleText.split(","),
  186. className: "inputSelectUnformatWidth",
  187. event: {
  188. change: function (item, ev) {
  189. if (item.get("value") == lp.reportCycleText.split(",")[0]) {
  190. this.form.getItem("reportDay").resetItemOptions(lp.weekDayValue.split(","),lp.weekDayText.split(","))
  191. } else if (item.get("value") == lp.reportCycleText.split(",")[1]) {
  192. this.form.getItem("reportDay").resetItemOptions(lp.monthDayValue.split(","),lp.monthDayText.split(","))
  193. }
  194. }.bind(this)
  195. }
  196. },
  197. reportDay: {
  198. type: "select",
  199. name:"reportDayInCycle",
  200. notEmpty:true,
  201. selectValue: (!this.data.reportCycle || this.data.reportCycle==lp.reportCycleText.split(",")[0])?lp.weekDayValue.split(","):lp.monthDayValue.split(","), //lp.weekDayValue.split(","),
  202. selectText: (!this.data.reportCycle || this.data.reportCycle==lp.reportCycleText.split(",")[0])?lp.weekDayText.split(","):lp.monthDayText.split(","),
  203. className: "inputSelectUnformatWidth"
  204. },
  205. dutyDepartment: {text: lp.dutyDepartment + ":", tType: "department",name:"responsibilityOrganizationName",notEmpty:true,event:{
  206. "change":function(item){
  207. var department = item.getValue();
  208. if( department ){
  209. _self.getDepartmentLeader( department, function( leader ){
  210. _self.form.getItem("dutyPerson").setValue(leader);
  211. })
  212. }
  213. }
  214. }},
  215. dutyPerson: {text: lp.dutyPerson + ":", tType: "identity",count:1,name:"responsibilityIdentity",notEmpty:true, onQuerySelect : function( item ){
  216. var department = this.form.getItem("dutyDepartment").getValue();
  217. item.options.departments = department ? [department] : [] ;
  218. }.bind(this)},
  219. secondDepartment: {text: lp.secondDepartment + ":", tType: "department",name:"cooperateOrganizationName", count: 0,event:{
  220. "change":function(item){
  221. var deptstr = item.getValue();
  222. if(deptstr){
  223. var depts = deptstr.split(",");
  224. var users = ""
  225. for(var i=0;i<depts.length;i++){
  226. if(depts[i]!=""){
  227. _self.getDepartmentLeader( depts[i], function( leader ){
  228. if(users=="") users = leader
  229. else users = users + ","+leader
  230. })
  231. }
  232. }
  233. _self.form.getItem("secondPerson").setValue(users);
  234. }
  235. }
  236. }},
  237. secondPerson: {text: lp.secondPerson + ":", tType: "identity",name:"cooperateIdentity", count: 0},
  238. readReader: {text: lp.readReader + ":", tType: "identity", name:"readLeaderIdentity",count: 0},
  239. subject: {text: lp.subject + ":",name:"title",notEmpty:true},
  240. workSplitAndDescription: {text: lp.workSplitAndDescription + ":", type: "textarea",name:"workDetail",notEmpty:true},
  241. specificActionInitiatives: {text: lp.specificActionInitiatives + ":", type: "textarea",name:"progressAction"},
  242. cityCompanyDuty: {text: lp.cityCompanyDuty + ":", type: "textarea",name:"dutyDescription"},
  243. milestoneMark: {text: lp.milestoneMark + ":", type: "textarea",name:"landmarkDescription"},
  244. importantMatters: {text: lp.importantMatters + ":", type: "textarea",name:"majorIssuesDescription"}
  245. }
  246. },
  247. loadAttachment: function( area ){
  248. this.attachment = new MWF.xApplication.Execution.Attachment( area, this.app, this.actions, this.app.lp, {
  249. documentId : this.data.id,
  250. isNew : this.options.isNew,
  251. isEdited : this.options.isEdited,
  252. onQueryUploadAttachment : function(){
  253. this.attachment.isQueryUploadSuccess = true;
  254. if( !this.data.id || this.data.id=="" ){
  255. var data = this.form.getResult(true, ",", true, false, true);
  256. if( !data ){
  257. this.attachment.isQueryUploadSuccess = false;
  258. return;
  259. }
  260. if(this.options.isNew){
  261. data.centerId = this.options.centerWorkId || this.data.centerWorkId || this.data.centerId ;
  262. }
  263. this.app.restActions.saveTask(data, function(json){
  264. if(json.type && json.type == "success"){
  265. if(json.data.id) {
  266. this.attachment.options.documentId = json.data.id;
  267. this.data.id = json.data.id;
  268. //this.options.isNew = false;
  269. }
  270. }
  271. }.bind(this), function(xhr,text,error){
  272. this.showErrorMessage(xhr,text,error)
  273. }.bind(this),false)
  274. }
  275. }.bind(this)
  276. })
  277. this.attachment.load();
  278. },
  279. _createBottomContent: function () {
  280. this.cancelActionNode = new Element("div.formCancelActionNode", {
  281. "styles": this.css.formCancelActionNode,
  282. "text": this.app.lp.cancel
  283. }).inject(this.formBottomNode);
  284. this.cancelActionNode.addEvent("click", function (e) {
  285. this.cancel(e);
  286. }.bind(this));
  287. if ((this.isNew || this.isEdited) && this.options.actionStatus == "save" ) {
  288. this.okActionNode = new Element("div.formOkActionNode", {
  289. "styles": this.css.formOkActionNode,
  290. "text": this.app.lp.ok
  291. }).inject(this.formBottomNode);
  292. this.okActionNode.addEvent("click", function (e) {
  293. this.ok(e);
  294. }.bind(this));
  295. }
  296. if(this.options.actionStatus=="deploy"){
  297. this.deployActionNode = new Element("div.formDeployActionNode",{
  298. "styles": this.css.formOkActionNode,
  299. "text" : this.app.lp.deploy
  300. }).inject(this.formBottomNode)
  301. .addEvent("click",function(){
  302. this.deploy();
  303. }.bind(this))
  304. }
  305. },
  306. deploy: function(){
  307. //先调用保存,再部署
  308. var data = this.form.getResult(true, ",", true, false, true);
  309. if (data) {
  310. data.title = data.workDetail;
  311. data.deployerName = this.app.user;
  312. data.creatorName = this.app.user;
  313. data.centerId = this.data.centerId;
  314. this.app.restActions.saveTask(data,function(json){
  315. if(json.type && json.type == "success"){
  316. if(json.data.id){
  317. var ids = [];
  318. ids.push(json.data.id);
  319. var workData = { "workIds":ids };
  320. this.actions.deployBaseWork( workData, function( json ){
  321. if(json.type && json.type=="success"){
  322. this.app.notice(this.app.lp.WorkDeploy.deployeSuccess, "ok");
  323. //this.reloadContent();
  324. this.close();
  325. }
  326. this.fireEvent("postDeploy", json);
  327. }.bind(this),function(xhr,error,text){
  328. var errorText = error;
  329. if (xhr) errorMessage = xhr.responseText;
  330. var e = JSON.parse(errorMessage);
  331. if(e.message){
  332. this.app.notice( e.message,"error");
  333. }else{
  334. this.app.notice( errorText,"error");
  335. }
  336. }.bind(this));
  337. }
  338. }
  339. }.bind(this))
  340. }
  341. },
  342. _ok: function (data, callback) {
  343. //data.title = data.workDetail;
  344. //if(this.options.isNew){
  345. // data.deployerName = this.app.user;
  346. // data.creatorName = this.app.user;
  347. // data.centerId = this.data.centerWorkId
  348. //}
  349. this.app.restActions.saveTask(data,function(json){
  350. if(json.type && json.type=="success"){
  351. this.app.notice(this.lp.submitSuccess, "ok");
  352. if(this.options.tabLocation){
  353. //if(this.options.from == "view"){
  354. //if(this.app.workTask.contentDiv) this.app.workTask.contentDiv.destroy()
  355. if(this.app.workTask)this.app.workTask.loadBaseWorkList(this.options.tabLocation);
  356. if(this.app.workList)this.app.workList.loadBaseWorkList(this.options.tabLocation)
  357. //}
  358. }else{
  359. if(this.explorer && this.explorer.explorer && this.explorer.explorer.reloadList){
  360. this.explorer.explorer.reloadList();
  361. }
  362. }
  363. this.close();
  364. }
  365. this.fireEvent("postSave", json);
  366. }.bind(this),function(xhr,text,error){
  367. var errorText = error;
  368. if (xhr) errorMessage = xhr.responseText;
  369. var e = JSON.parse(errorMessage);
  370. if(e.message){
  371. this.app.notice( e.message,"error");
  372. }else{
  373. this.app.notice( errorText,"error");
  374. }
  375. }.bind(this));
  376. //this.app.restActions.saveDocument( this.data.id, data, function(json){
  377. // if( callback )callback(json);
  378. //}.bind(this));
  379. },
  380. getDepartmentLeader:function(department, callback){
  381. this.app.restActions.getDepartmentDuty(function( json ){
  382. if( json.data.identityList && json.data.identityList.length > 0 ){
  383. if(callback) callback(json.data.identityList[0])
  384. //this.app.restActions.getPersonByIdentity( function(data){
  385. // if(callback)callback(data.data.name);
  386. //}.bind(this),null, json.data.identityList[0] ,false)
  387. }
  388. }.bind(this),null,this.app.lp.departmentLeader, department, false )
  389. },
  390. showErrorMessage:function(xhr,text,error){
  391. var errorText = error;
  392. if (xhr) errorMessage = xhr.responseText;
  393. if(errorMessage!=""){
  394. var e = JSON.parse(errorMessage);
  395. if(e.message){
  396. this.app.notice( e.message,"error");
  397. }else{
  398. this.app.notice( errorText,"error");
  399. }
  400. }else{
  401. this.app.notice(errorText,"error")
  402. }
  403. }
  404. });