MeasureForm.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. MWF.xApplication.Strategy = MWF.xApplication.Strategy || {};
  2. //MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Strategy", "Template", null, false);
  4. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  5. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  6. MWF.xDesktop.requireApp("Strategy","Attachment",null,false);
  7. MWF.xApplication.Strategy.MeasureForm = new Class({
  8. Extends: MPopupForm,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "width": "90%",
  13. "height": "100%",
  14. "hasTop": true,
  15. "hasIcon": false,
  16. "hasBottom": false,
  17. "title": "",
  18. "draggable": false,
  19. "maxAction":true,
  20. "closeAction": true
  21. },
  22. initialize: function (explorer, actions, data, options) {
  23. this.setOptions(options);
  24. this.explorer = explorer;
  25. this.app = explorer.app;
  26. this.lp = this.app.lp.measure.popupForm;
  27. this.actions = this.app.restActions;
  28. this.path = "../x_component_Strategy/$MeasureForm/";
  29. this.cssPath = this.path + this.options.style + "/css.wcss";
  30. this._loadCss();
  31. this.options.title = this.lp.title;
  32. this.defaultYear = this.options.year;
  33. this.data = data || {};
  34. this.actions = actions;
  35. //alert("init="+this.data.parentid);
  36. },
  37. load: function () {
  38. var now = new Date();
  39. this.thisYear = now.getFullYear();
  40. if (this.options.isNew) {
  41. this.create();
  42. } else if (this.options.isEdited) {
  43. this.edit();
  44. } else {
  45. this.open();
  46. }
  47. },
  48. createTopNode: function () {
  49. if (!this.formTopNode) {
  50. this.formTopNode = new Element("div.formTopNode", {
  51. "styles": this.css.formTopNode
  52. }).inject(this.formNode);
  53. this.formTopTextNode = new Element("div", {
  54. "styles": this.css.formTopTextNode,
  55. "text": this.data.title ? this.data.title : this.lp.addTitle
  56. }).inject(this.formTopNode);
  57. if (this.options.closeAction) {
  58. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  59. this.formTopCloseActionNode.addEvent("click", function () {
  60. this.close();
  61. }.bind(this))
  62. }
  63. this._createTopContent();
  64. }
  65. },
  66. _createTopContent: function () {
  67. },
  68. _createTableContent: function () {
  69. //获取默认下一个序号
  70. if(this.data.parentid){
  71. this.actions.getMeasureMaxNumber(this.data.parentid,function(json){
  72. if(json.type=="success"){
  73. if(json.data && json.data.value){
  74. this.data.sequencenumber = json.data.value;
  75. }
  76. }
  77. }.bind(this),null,false);
  78. }
  79. this.getData(
  80. function(){
  81. this.createTableInfo();
  82. }.bind(this)
  83. );
  84. },
  85. getData:function(callback){
  86. if(!this.options.isNew){
  87. if(this.data.id){
  88. this.id = this.data.id;
  89. }else if(this.options.id){
  90. this.id = this.options.id;
  91. }
  92. this.actions.getMeasureById(this.id,function(json){
  93. if(json.type=="success"){
  94. this.data = json.data;
  95. this.formTopTextNode.set("text",this.data.measuresinfotitle);
  96. if(json.data.measuresinfoyear){
  97. this.currentYear = json.data.measuresinfoyear;
  98. }
  99. if(callback)callback();
  100. }
  101. }.bind(this));
  102. }else{
  103. if(callback)callback()
  104. }
  105. },
  106. createTableInfo:function(){
  107. var html = "<table width='100%' border='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  108. "<tr>" +
  109. " <td styles='formTableTitle' lable='sequencenumber'></td>" +
  110. " <td styles='formTableValue' item='sequencenumber'></td>" +
  111. "</tr>"+
  112. "<tr>" +
  113. " <td styles='formTableTitle' lable='measuresinfotitle'></td>" +
  114. " <td styles='formTableValue' item='measuresinfotitle'></td>" +
  115. "</tr>"+
  116. "<tr>" +
  117. " <td styles='formTableTitle' lable='measuresyear'></td>" +
  118. " <td styles='formTableYearValue' item='measuresyear'></td>" +
  119. "</tr>"+
  120. "<tr>" +
  121. " <td styles='formTableTitle' lable='deptlist'></td>" +
  122. " <td styles='formTableValue' item='measuresdutydept'></td>" +
  123. "</tr>"+
  124. "<tr>" +
  125. " <td styles='formTableTitle' lable='measuresdutydept'></td>" +
  126. " <td styles='formTableValue' item='deptlist'></td>" +
  127. "</tr>"+
  128. "<tr>" +
  129. " <td styles='formTableTitle' lable='measuressupportdepts'></td>" +
  130. " <td styles='formTableValue' item='measuressupportdepts'></td>" +
  131. "</tr>"+
  132. "<tr>" +
  133. " <td styles='formTableTitle' lable='measuresinfoparentid'></td>" +
  134. " <td styles='formTableValue'><div styles='keyWorkList' item='measuresinfoparentid' id='keyWorkList'></div></td>" +
  135. "</tr>"+
  136. "<tr>" +
  137. " <td styles='formTableTitle' lable='measuresinfodescribe'></td>" +
  138. " <td styles='formTableValue' item='measuresinfodescribe'></td>" +
  139. "</tr>"+
  140. "<tr>" +
  141. " <td styles='formTableTitle' lable='measuresinfotargetvalue'></td>" +
  142. " <td styles='formTableValue' item='measuresinfotargetvalue'></td>" +
  143. "</tr>"+
  144. "</table>";
  145. this.formTableArea.set("html", html);
  146. if(this.options.isEdited || this.options.isNew){
  147. this.getKeyWorkList(this.currentYear || this.defaultYear || this.thisYear,
  148. function(){
  149. this.loadForm();
  150. }.bind(this)
  151. );
  152. this.createActionBar();
  153. }else{
  154. this.loadForm();
  155. }
  156. },
  157. getKeyWorkList:function(year,callback){
  158. this.keyWorkListTitle = [];
  159. this.keyWorkListId = [];
  160. this.actions.getKeyWorkListNext("(0)",100,{"strategydeployyear":year||this.thisYear},function(json){
  161. if(json.type=="success"){
  162. json.data.each(function(d){
  163. this.keyWorkListTitle.push(d.strategydeploytitle);
  164. this.keyWorkListId.push(d.id);
  165. }.bind(this));
  166. if (callback)callback();
  167. }
  168. }.bind(this));
  169. },
  170. loadForm: function(){
  171. this.measureForm = new MForm(this.formTableArea, this.data, {
  172. style: "default",
  173. isEdited: this.isEdited || this.isNew,
  174. itemTemplate: this.getItemTemplate(this.lp )
  175. },this.app,this.css);
  176. //alert(this.currentYear || this.defaultYear || this.thisYear)
  177. this.measureForm.load();
  178. if(!(this.options.isEdited || this.options.isNew) || (this.options.from && this.options.from=="portal")){
  179. //处理样式及相关联id对应标题问题
  180. var obj = this.formTableArea.getElementById("keyWorkList");
  181. if(obj){
  182. obj.setStyles({"border":"0px","min-height":"0px"});
  183. obj.set("html","");
  184. this.keyWorkItem = new Element("div.keyWorkItem",{
  185. name:"measuresinfoparentid",
  186. styles:{"cursor":"pointer"}
  187. }).inject(obj);
  188. this.actions.getKeyWorkById(this.data.measuresinfoparentid,function(json){
  189. if(json.type=="success" && json.data && json.data.strategydeploytitle){
  190. this.keyWorkItem.set("text",json.data.strategydeploytitle);
  191. this.keyWorkItem.addEvents({
  192. "click":function(){
  193. MWF.xDesktop.requireApp("Strategy", "KeyWorkForm", function(){
  194. var _width = this.options.width || "100%";
  195. var _height = this.options.height || "100%";
  196. //_width = parseInt(_width)-10;
  197. //_height = parseInt(_height)-10;
  198. this.KeyWorkForm = new MWF.xApplication.Strategy.KeyWorkForm(this, this.actions,{"id":this.data.measuresinfoparentid},{
  199. "isEdited":false,
  200. "width":isNaN(_width)?(parseInt(_width)-10)+"%":_width-50,
  201. "height":isNaN(_height)?(parseInt(_height)-10)+"%":_height-50
  202. } );
  203. this.KeyWorkForm.container = this.app.portalContainer || this.app.content;
  204. this.KeyWorkForm.load();
  205. }.bind(this));
  206. }.bind(this)
  207. });
  208. }
  209. }.bind(this));
  210. }
  211. }
  212. var taObj = this.formTableArea.getElements("textarea");
  213. taObj.setStyles({height:"100px"});
  214. //this.attachmentArea = this.formTableArea.getElement("[item='attachments']");
  215. //this.loadAttachment( this.attachmentArea );
  216. },
  217. getItemTemplate: function( lp ){
  218. _self = this;
  219. return {
  220. "sequencenumber":{
  221. text:lp.sequencenumber+":",
  222. name:"sequencenumber",
  223. notEmpty:true
  224. },
  225. "measuresinfotitle":{
  226. text:lp.title+":",
  227. notEmpty:true
  228. },
  229. "measuresyear":{
  230. text:lp.year+":",
  231. notEmpty:true,
  232. type:this.options.isNew?"select":"innerText",
  233. value:this.currentYear || this.defaultYear || this.thisYear,
  234. attr : {style:"width:100%;height:30px;border-radius:3px;"},
  235. selectValue:lp.selectYears.split(","),
  236. selectText:lp.selectYears.split(","),
  237. //defaultValue:this.currentYear || this.defaultYear || this.thisYear,
  238. event:{
  239. "change":function(item){
  240. var year = item.getValue();
  241. _self.currentYear = year;
  242. _self.getKeyWorkList(year,
  243. function(){
  244. _self.loadForm()
  245. }
  246. );
  247. }
  248. }
  249. },
  250. "deptlist":{
  251. text:lp.department+":",
  252. notEmpty:true,
  253. type: "org",
  254. orgType:"unit",
  255. name:"deptlist",
  256. count: 0,
  257. attr : {readonly:true}
  258. },
  259. "measuresdutydept":{
  260. text:lp.resDepartment+":",
  261. notEmpty:true,
  262. type: "org",
  263. orgType:"unit",
  264. name:"measuresdutydept",
  265. count: 1,
  266. attr : {readonly:true}
  267. },
  268. "measuressupportdepts":{
  269. text:lp.measuressupportdepts+":",
  270. notEmpty:true,
  271. type: "text",
  272. name:"measuressupportdepts",
  273. attr : {}
  274. },
  275. "measuresinfoparentid":{
  276. text:lp.keyWork+":",
  277. isEdited:this.options.from == "portal"?false:true,
  278. name:"measuresinfoparentid",
  279. notEmpty:true,
  280. type:"radio",
  281. style:{"height":"25px"},
  282. event:{
  283. "click":function(item){
  284. var t = typeof item["getValue"];
  285. if(t == "function"){
  286. var id = item.getValue();
  287. if(id){
  288. _self.actions.getMeasureMaxNumber(id,function(json){
  289. if(json.type=="success"){
  290. if(json.data && json.data.value){
  291. var o =_self.formTableArea.getElements("[name='sequencenumber']");
  292. o[0].set("value",json.data.value);
  293. }
  294. }
  295. }.bind(this));
  296. }
  297. }
  298. //_self.currentYear = year;
  299. //
  300. //_self.getKeyWorkList(year,
  301. // function(){
  302. // _self.loadForm()
  303. // }
  304. //);
  305. }
  306. },
  307. selectText:this.keyWorkListTitle?this.keyWorkListTitle.join("##").split("##"):"",
  308. selectValue:this.keyWorkListId?this.keyWorkListId.join("##").split("##"):""
  309. },
  310. "measuresinfodescribe":{
  311. type:"textarea",
  312. attr:{style:"height:100px"},
  313. text:lp.description+":"
  314. },
  315. "measuresinfotargetvalue":{
  316. type:"textarea",
  317. attr:{style:"height:100px"},
  318. text:lp.measuresinfotargetvalue+":"
  319. }
  320. };
  321. },
  322. loadAttachment: function( area ){
  323. },
  324. createActionBar:function(){
  325. this.actionContent = new Element("div.actionContent",{"styles":this.css.actionContent}).inject(this.formTableContainer);
  326. this.actionBar = new Element("div.actionBar",{"styles":this.css.actionBar}).inject(this.actionContent);
  327. this.saveAction = new Element("div.saveAction",{
  328. "styles":this.css.saveAction,
  329. "text":this.lp.saveAction
  330. }).inject(this.actionBar).
  331. addEvents({
  332. "click":function(){
  333. this.save();
  334. }.bind(this)
  335. });
  336. this.cancelAction = new Element("div.cancelAction",{
  337. "styles":this.css.cancelAction,
  338. "text":this.lp.cancelAction
  339. }).inject(this.actionBar).
  340. addEvents({
  341. "click":function(){
  342. this.close();
  343. }.bind(this)
  344. })
  345. },
  346. save:function(callback){
  347. var _measuresinfoparentid = this.data.measuresinfoparentid;
  348. var data = this.measureForm.getResult(true, ",", true, false, true);
  349. //return;
  350. if(data){
  351. this.app.createShade();
  352. if(this.options.from == "portal"){
  353. data.measuresinfoparentid = this.data.measuresinfoparentid || _measuresinfoparentid;
  354. }
  355. data.deptlist = data.deptlist.split(",");
  356. data.measuresinfoyear = data.measuresyear;
  357. this.actions.saveMeasure(data,function(json){
  358. if(json.type == "success"){
  359. this.close();
  360. this.fireEvent("postSave", json);
  361. }else if(json.type == "error"){
  362. this.app.notice(json.message,"error")
  363. }
  364. this.app.destroyShade();
  365. if(callback)callback()
  366. }.bind(this),function(xhr,text,error){
  367. this.app.showErrorMessage(xhr,text,error);
  368. this.app.destroyShade();
  369. }.bind(this));
  370. }
  371. },
  372. createShade: function(o,txtInfo){
  373. var defaultObj = this.content;
  374. var obj = o || defaultObj;
  375. var txt = txtInfo || "loading...";
  376. if(this.shadeDiv){ this.shadeDiv.destroy()}
  377. if(this["shadeTxtDiv"]) this["shadeTxtDiv"].destroy();
  378. this.shadeDiv = new Element("div.shadeDiv").inject(obj);
  379. this.inforDiv = new Element("div.inforDiv",{
  380. styles:{"height":"16px","display":"inline-block","position":"absolute","background-color":"#000000","border-radius":"3px","padding":"5px 10px"}
  381. }).inject(this.shadeDiv);
  382. this.loadImg = new Element("img.loadImg",{
  383. styles:{"width":"16px","height":"16px","float":"left"},
  384. src:this.path+"default/icon/loading.gif"
  385. }).inject(this.inforDiv);
  386. this.shadeTxtSpan = new Element("span.shadeTxtSpan").inject(this.inforDiv);
  387. this.shadeTxtSpan.set("text",txt);
  388. this.shadeDiv.setStyles({
  389. "width":"100%","height":"100%","position":"absolute","opacity":"0.6","background-color":"#cccccc","z-index":"999"
  390. });
  391. this.shadeTxtSpan.setStyles({"color":"#ffffff","font-size":"12px","display":"inline-block","line-height":"16px","padding-left":"5px"});
  392. var x = obj.getSize().x;
  393. var y = obj.getSize().y;
  394. this.shadeDiv.setStyles({
  395. "left":(obj.getLeft()-defaultObj.getLeft())+"px",
  396. "top":(obj.getTop()-defaultObj.getTop())+"px",
  397. "width":x+"px",
  398. "height":y+"px"
  399. });
  400. if(obj.getStyle("position")=="absolute"){
  401. this.shadeDiv.setStyles({
  402. "left":"0px",
  403. "top":"0px"
  404. })
  405. }
  406. this.inforDiv.setStyles({
  407. "left":(x/2)+"px",
  408. "top":(y/2)+"px"
  409. })
  410. },
  411. destroyShade : function(){
  412. if(this.shadeDiv) this.shadeDiv.destroy();
  413. //if(this.shadeDiv) this.shadeDiv.destroy()
  414. },
  415. showErrorMessage:function(xhr,text,error){
  416. var errorText = error;
  417. var errorMessage;
  418. if (xhr) errorMessage = xhr.responseText;
  419. if(errorMessage!=""){
  420. var e = JSON.parse(errorMessage);
  421. if(e.message){
  422. this.notice( e.message,"error");
  423. }else{
  424. this.notice( errorText,"error");
  425. }
  426. }else{
  427. this.notice(errorText,"error");
  428. }
  429. },
  430. aa:function(){
  431. var val = "";if(d.configValue && d.configValue!='') {var v = d.configValue.split(',');for (i = 0; i < v.length; i++) {if (val == '') {val = v[i].split('@')[0];} else {val = val + ',' + v[i].split('@')[0];};}} return val
  432. }
  433. });