PriorityForm.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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","PriorityAttachment",null,false);
  7. MWF.xApplication.Strategy.PriorityForm = 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": true,
  19. "maxAction":true,
  20. "closeAction": true
  21. },
  22. initialize: function (explorer, data, options, para) {
  23. this.setOptions(options);
  24. this.explorer = explorer;
  25. if( para ){
  26. if( this.options.relativeToApp ){
  27. this.app = para.app || this.explorer.app;
  28. this.container = para.container || this.app.content;
  29. this.lp = para.lp || this.explorer.lp || this.app.lp;
  30. this.css = para.css || this.explorer.css || this.app.css;
  31. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  32. }else{
  33. this.container = para.container;
  34. this.lp = para.lp || this.explorer.lp;
  35. this.css = para.css || this.explorer.css;
  36. this.actions = para.actions || this.explorer.actions;
  37. }
  38. }else{
  39. if( this.options.relativeToApp ){
  40. this.app = this.explorer.app;
  41. this.container = this.app.content;
  42. this.lp = this.explorer.lp || this.app.lp;
  43. this.css = this.explorer.css || this.app.css;
  44. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  45. }else{
  46. this.container = window.document.body;
  47. this.lp = this.explorer.lp;
  48. this.css = this.explorer.css;
  49. this.actions = this.explorer.actions;
  50. }
  51. }
  52. this.data = data || {};
  53. },
  54. load: function () {
  55. this.lp = this.app.lp.priority.popupForm;
  56. this.path = "/x_component_Strategy/$PriorityForm/";
  57. this.cssPath = this.path + this.options.style + "/css.wcss";
  58. this._loadCss();
  59. this.options.title = this.lp.title;
  60. this.defaultYear = this.options.year;
  61. this.currentYear = this.defaultYear;
  62. this.currentDepartment = this.options.department;
  63. var now = new Date();
  64. this.thisYear = now.getFullYear();
  65. if (this.options.isNew) {
  66. this.create();
  67. } else if (this.options.isEdited) {
  68. this.edit();
  69. } else {
  70. this.open();
  71. }
  72. },
  73. createTopNode: function () {
  74. this.fireEvent("queryCreateTop");
  75. if (!this.formTopNode) {
  76. this.formTopNode = new Element("div.formTopNode", {
  77. "styles": this.css.formTopNode
  78. }).inject(this.formNode);
  79. if(this.options.hasTopIcon){
  80. this.formTopIconNode = new Element("div", {
  81. "styles": this.css.formTopIconNode
  82. }).inject(this.formTopNode);
  83. }
  84. this.formTopTextNode = new Element("div", {
  85. "styles": this.css.formTopTextNode,
  86. "text": this.options.title
  87. }).inject(this.formTopNode);
  88. if (this.options.closeAction) {
  89. this.formTopCloseActionNode = new Element("div", {
  90. "styles": this.css.formTopCloseActionNode,
  91. "title" : "关闭"
  92. }).inject(this.formTopNode);
  93. this.formTopCloseActionNode.addEvent("click", function ( ev ) {
  94. this.close();
  95. ev.stopPropagation();
  96. }.bind(this));
  97. }
  98. if( this.options.maxAction ){
  99. this.formTopMaxActionNode = new Element("div", {
  100. "styles": this.css.formTopMaxActionNode,
  101. "title" : "最大化"
  102. }).inject(this.formTopNode);
  103. this.formTopMaxActionNode.addEvent("click", function () {
  104. this.maxSize();
  105. }.bind(this));
  106. this.formTopRestoreActionNode = new Element("div", {
  107. "styles": this.css.formTopRestoreActionNode,
  108. "title" : "还原"
  109. }).inject(this.formTopNode);
  110. this.formTopRestoreActionNode.addEvent("click", function () {
  111. this.restoreSize();
  112. }.bind(this));
  113. this.formTopNode.addEvent("dblclick", function(){
  114. this.switchMax();
  115. }.bind(this));
  116. }
  117. if(this.options.hasTopContent){
  118. this.formTopContentNode = new Element("div.formTopContentNode", {
  119. "styles": this.css.formTopContentNode
  120. }).inject(this.formTopNode);
  121. this._createTopContent();
  122. }
  123. }
  124. this.fireEvent("postCreateTop");
  125. //if (!this.formTopNode) {
  126. // this.formTopNode = new Element("div.formTopNode", {
  127. // "styles": this.css.formTopNode,
  128. // "text": this.options.title
  129. // }).inject(this.formNode);
  130. //
  131. // this._createTopContent();
  132. //
  133. // if (this.options.closeAction) {
  134. // this.formTopCloseActionNode = new Element("div.formTopCloseActionNode", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  135. // this.formTopCloseActionNode.addEvent("click", function () {
  136. // this.close()
  137. // }.bind(this))
  138. // }
  139. //}
  140. },
  141. //createTopNode: function () {
  142. // if (!this.formTopNode) {
  143. // this.formTopNode = new Element("div.formTopNode", {
  144. // "styles": this.css.formTopNode
  145. // }).inject(this.formNode);
  146. //
  147. // this.formTopTextNode = new Element("div", {
  148. // "styles": this.css.formTopTextNode,
  149. // "text": this.data.title ? this.data.title : this.lp.addTitle
  150. // }).inject(this.formTopNode);
  151. //
  152. // if (this.options.closeAction) {
  153. // this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  154. // this.formTopCloseActionNode.addEvent("click", function () {
  155. // this.close()
  156. // }.bind(this))
  157. // }
  158. //
  159. // this._createTopContent();
  160. // }
  161. //},
  162. _createTopContent: function () {
  163. },
  164. _createTableContent: function () {
  165. this.getData(function(){this.createTableInfo()}.bind(this));
  166. },
  167. getData:function(callback){
  168. if(!this.options.isNew){
  169. if(this.data.id){
  170. this.id = this.data.id;
  171. }else if(this.options.id){
  172. this.id = this.options.id;
  173. }
  174. this.actions.getPriorityById(this.id,function(json){
  175. this.data = json.data;
  176. this.formTopTextNode.set("text",this.data.keyworktitle);
  177. this.currentDepartment = json.data.keyworkunit;
  178. if(callback)callback()
  179. }.bind(this));
  180. }else{
  181. if(callback)callback();
  182. }
  183. },
  184. createTableInfo:function(){
  185. var html = "<table width='100%' border='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  186. "<tr>" +
  187. " <td styles='formTableTitle' lable='sequencenumber'></td>" +
  188. " <td styles='formTableValue' item='sequencenumber'></td>" +
  189. "</tr>"+
  190. "<tr>" +
  191. " <td styles='formTableTitle' lable='keyworktitle'></td>" +
  192. " <td styles='formTableValue' item='keyworktitle'></td>" +
  193. "</tr>"+
  194. "<tr>" +
  195. " <td styles='formTableTitle' lable='keyworkyear'></td>" +
  196. " <td styles='formTableYearValue' item='keyworkyear'></td>" +
  197. "</tr>"+
  198. "<tr>" +
  199. " <td styles='formTableTitle' lable='deptlist'></td>" +
  200. " <td styles='formTableValue' item='keyworkunit'></td>" +
  201. "</tr>"+
  202. "<tr>" +
  203. " <td styles='formTableTitle' lable='validDate'></td>" +
  204. " <td styles='formTableValue'>"+
  205. " <div styles='formTableDate' item='keyworkbegindate'></div>"+
  206. " <div styles='formTableDate' lable='validDateMonth'></div><div styles='formTableDate' lable='validDateConnect'></div>"+
  207. " <div styles='formTableDate' item='keyworkenddate'></div><div styles='formTableDate' lable='validDateMonth'></div>"+
  208. " </td>" +
  209. "</tr>"+
  210. "<tr>" +
  211. " <td styles='formTableTitle' lable='measureslist'></td>" +
  212. " <td styles='formTableValue'><div styles='measureList' item='measureslist' id='measureList'></div></td>" +
  213. "</tr>"+
  214. "<tr>" +
  215. " <td styles='formTableTitle' lable='keyworkdescribe'></td>" +
  216. " <td styles='formTableValue' item='keyworkdescribe'></td>" +
  217. "</tr>"+
  218. "<tr>" +
  219. " <td styles='formTableTitle' lable='attachments'></td>"+
  220. " <td styles='formTableValue'>"+
  221. "<div styles='formTableValueDiv' item='attachments'></div>"+
  222. " </td>" +
  223. "</tr>"+
  224. "</table>";
  225. this.formTableArea.set("html", html);
  226. if(this.options.isNew || this.options.isEdited){
  227. this.getMeasureList(this.currentYear || this.thisYear,
  228. function(){
  229. this.loadForm();
  230. }.bind(this)
  231. );
  232. this.createActionBar();
  233. }else{
  234. this.loadForm();
  235. }
  236. },
  237. loadForm: function(){
  238. this.priorityForm = new MForm(this.formTableArea, this.data, {
  239. style: "default",
  240. isEdited: this.isEdited || this.isNew,
  241. itemTemplate: this.getItemTemplate(this.lp )
  242. },this.app,this.css);
  243. this.priorityForm.load();
  244. if(!(this.options.isEdited || this.options.isNew)){
  245. this.formTableArea.getElementById("measureList").setStyles({"border":"0px","min-height":"0px"});
  246. }
  247. var taObj = this.formTableArea.getElements("textarea");
  248. taObj.setStyles({height:"100px"});
  249. if(!(this.options.isEdited || this.options.isNew)){
  250. //处理样式及相关联id对应标题问题
  251. var obj = this.formTableArea.getElementById("measureList");
  252. if(obj){
  253. obj.setStyles({"border":"0px","min-height":"0px"});
  254. obj.set("html","");
  255. if(this.data.measureslist){
  256. this.data.measureslist.each(function(d){
  257. this.actions.getMeasureById(d,function(json){
  258. if(json.type == "success"){
  259. new Element("div.measureItem",{
  260. "styles":this.css.measureItem,
  261. "text":json.data.measuresinfotitle
  262. }).inject(obj).
  263. addEvents({
  264. "click":function(){
  265. var _width = this.options.width || "100%";
  266. var _height = this.options.height || "100%";
  267. //_width = parseInt(_width)-10;
  268. //_height = parseInt(_height)-10;
  269. MWF.xDesktop.requireApp("Strategy", "MeasureForm", function(){
  270. this.measureForm = new MWF.xApplication.Strategy.MeasureForm(this, this.actions,{"id":d},{
  271. "isEdited":false,
  272. "width":isNaN(_width)?(parseInt(_width)-10)+"%":_width-50,
  273. "height":isNaN(_height)?(parseInt(_height)-10)+"%":_height-50
  274. } );
  275. this.measureForm.container = this.app.portalContainer || this.app.content;
  276. this.measureForm.load();
  277. }.bind(this));
  278. }.bind(this)
  279. });
  280. }
  281. }.bind(this));
  282. }.bind(this));
  283. }
  284. }
  285. }
  286. this.attachmentArea = this.formTableArea.getElement("[item='attachments']");
  287. this.loadAttachment( this.attachmentArea );
  288. },
  289. loadAttachment: function( area ){
  290. this.attachment = new MWF.xApplication.Strategy.PriorityAttachment( area, this.app, this.actions, this.app.lp.attachment.priority, {
  291. workId : this.data.id,
  292. isNew : this.options.isNew,
  293. isEdited : this.options.isEdited,
  294. onQueryUploadAttachment : function(){
  295. this.attachment.isQueryUploadSuccess = true;
  296. if( !this.data.id || this.data.id=="" ){
  297. var data = this.priorityForm.getResult(true, ",", true, false, true);
  298. if(data && this.currentDepartment && this.currentDepartment!=""){
  299. data.keyworkyear = this.currentYear || this.thisYear;
  300. data.keyworkunit = this.currentDepartment;
  301. data.measureslist = data.measureslist.split(",");
  302. this.actions.savePriority(data,function(json){
  303. if(json.type == "success"){
  304. if(json.data.id) {
  305. this.data = json.data;
  306. this.id = json.data.id;
  307. this.attachment.options.workId = json.data.id;
  308. //this.options.isNew = false;
  309. }
  310. }
  311. }.bind(this),function(xhr,error,text){
  312. this.app.showErrorMessage(xhr,error,text);
  313. this.attachment.isQueryUploadSuccess = false;
  314. //return;
  315. }.bind(this),false);
  316. }else{
  317. this.attachment.isQueryUploadSuccess = false;
  318. //return;
  319. }
  320. }
  321. }.bind(this)
  322. });
  323. this.attachment.load();
  324. },
  325. getMeasureList:function(year,callback){
  326. this.measureListTitle = [];
  327. this.measureListId = [];
  328. var data = {
  329. "measuresinfoyear" : year||this.thisYear,
  330. "deptlist":[this.currentDepartment]
  331. };
  332. this.actions.getMeasureListNext("(0)",100,data,function(json){
  333. if(json.type=="success"){
  334. json.data.each(function(d){
  335. this.measureListTitle.push(d.measuresinfotitle);
  336. this.measureListId.push(d.id);
  337. }.bind(this));
  338. if (callback)callback();
  339. }
  340. }.bind(this));
  341. },
  342. getItemTemplate: function( lp ){
  343. _self = this;
  344. return {
  345. "sequencenumber":{
  346. text:lp.sequencenumber+":",
  347. style:{"text-indent":"3px"},
  348. notEmpty:true
  349. },
  350. "keyworktitle":{
  351. text:lp.title+":",
  352. style:{"text-indent":"3px"},
  353. notEmpty:true
  354. },
  355. "keyworkyear":{
  356. text:lp.year+":",
  357. notEmpty:true,
  358. type:this.options.isNew?"select":"innerText",
  359. value:this.currentYear||this.thisYear,
  360. attr : {style:"width:100%;height:30px;border-radius:3px;"},
  361. selectValue:lp.selectYears.split(","),
  362. selecTtext:lp.selectYears.split(","),
  363. event:{
  364. "change":function(item){
  365. var year = item.getValue();
  366. _self.currentYear = year;
  367. _self.getMeasureList(year,
  368. function(){
  369. _self.loadForm()
  370. }
  371. );
  372. }
  373. }
  374. },
  375. "keyworkunit":{
  376. isEdited:false,
  377. text:lp.department+":",
  378. notEmpty:true,
  379. type: "org",
  380. value:this.options.department,
  381. orgType:"unit",
  382. name:"deptlist",
  383. count: 0,
  384. attr : {readonly:true,unformatWidth:true}
  385. },
  386. "validDate":{
  387. text:lp.validDate+":"
  388. },
  389. "keyworkbegindate":{
  390. text:lp.keyworkbegindate,
  391. type: "select",
  392. name:"keyworkbegindate",
  393. notEmpty:true,
  394. //selectValue: !this.data.keyworkbegindate?lp.selectMonth.split(","):this.data.keyworkbegindate.toString(), //lp.weekDayValue.split(","),
  395. //selectText: !this.data.keyworkbegindate?lp.selectMonth.split(","):this.data.keyworkbegindate.toString(),
  396. selectText: lp.selectMonth.split(","),
  397. style:{"width":"50px","height":"20px","text-indent":"3px"},
  398. attr : {readonly:true}
  399. },
  400. "validDateConnect":{
  401. text:lp.validDateConnect
  402. },
  403. "validDateMonth":{
  404. text:lp.validDateMonth,
  405. style:{"margin-left":"10px","margin-right":"10px","text-indent":"3px"}
  406. },
  407. "keyworkenddate":{
  408. text:lp.keyworkenddate,
  409. type: "select",
  410. name:"keyworkenddate",
  411. notEmpty:true,
  412. //selectValue: !this.data.keyworkenddate?lp.selectMonth.split(","):this.data.keyworkenddate.toString(), //lp.weekDayValue.split(","),
  413. //selectText: !this.data.keyworkenddate?lp.selectMonth.split(","):this.data.keyworkenddate.toString(),
  414. selectText: lp.selectMonth.split(","),
  415. style:{"width":"50px","height":"20px","text-indent":"3px"},
  416. attr : {readonly:true}
  417. },
  418. "measureslist":{
  419. text:lp.measurelist+":",
  420. type:"checkbox",
  421. notEmpty:true,
  422. selectText:this.measureListTitle?this.measureListTitle.join(",").split(","):"",
  423. selectValue:this.measureListId?this.measureListId.join(",").split(","):""
  424. },
  425. "keyworkdescribe":{
  426. type:"textarea",
  427. style:{"text-indent":"3px","height":"100px"},
  428. text:lp.description+":"
  429. },
  430. "attachments":{
  431. text:lp.attachments,
  432. type:"innertext"
  433. }
  434. };
  435. },
  436. createActionBar:function(){
  437. this.actionContent = new Element("div.actionContent",{"styles":this.css.actionContent}).inject(this.formTableContainer);
  438. this.actionBar = new Element("div.actionBar",{"styles":this.css.actionBar}).inject(this.actionContent);
  439. this.saveAction = new Element("div.saveAction",{
  440. "styles":this.css.saveAction,
  441. "text":this.lp.saveAction
  442. }).inject(this.actionBar).
  443. addEvents({
  444. "click":function(){
  445. this.save();
  446. }.bind(this)
  447. });
  448. this.cancelAction = new Element("div.cancelAction",{
  449. "styles":this.css.cancelAction,
  450. "text":this.lp.cancelAction
  451. }).inject(this.actionBar).
  452. addEvents({
  453. "click":function(){
  454. this.close();
  455. }.bind(this)
  456. })
  457. },
  458. save:function(callback){
  459. var data = this.priorityForm.getResult(true, ",", true, false, true);
  460. if(data && this.currentDepartment && this.currentDepartment!=""){
  461. this.createShade();
  462. data.keyworkyear = this.currentYear || this.thisYear;
  463. data.keyworkunit = this.currentDepartment;
  464. data.measureslist = data.measureslist.split(",");
  465. data.id = this.id || this.data.id;
  466. this.actions.savePriority(data,function(json){
  467. if(json.type == "success"){
  468. this.close();
  469. this.fireEvent("postSave", json);
  470. }else if(json.type == "error"){
  471. this.app.notice(json.message,"error")
  472. }
  473. this.destroyShade();
  474. if(callback)callback()
  475. }.bind(this),function(xhr,text,error){
  476. this.showErrorMessage(xhr,text,error);
  477. this.destroyShade();
  478. }.bind(this));
  479. }
  480. },
  481. createShade: function(o,txtInfo){
  482. var defaultObj = this.container||this.app;
  483. var obj = o || defaultObj;
  484. var txt = txtInfo || "loading...";
  485. if(this.shadeDiv){ this.shadeDiv.destroy()}
  486. if(this["shadeTxtDiv"]) this["shadeTxtDiv"].destroy();
  487. this.shadeDiv = new Element("div.shadeDiv").inject(obj);
  488. this.inforDiv = new Element("div.inforDiv",{
  489. styles:{"height":"16px","display":"inline-block","position":"absolute","background-color":"#000000","border-radius":"3px","padding":"5px 10px"}
  490. }).inject(this.shadeDiv);
  491. this.loadImg = new Element("img.loadImg",{
  492. styles:{"width":"16px","height":"16px","float":"left"},
  493. src:this.path+"default/icon/loading.gif"
  494. }).inject(this.inforDiv);
  495. this.shadeTxtSpan = new Element("span.shadeTxtSpan").inject(this.inforDiv);
  496. this.shadeTxtSpan.set("text",txt);
  497. this.shadeDiv.setStyles({
  498. "width":"100%","height":"100%","position":"absolute","opacity":"0.6","background-color":"#cccccc","z-index":"999"
  499. });
  500. this.shadeTxtSpan.setStyles({"color":"#ffffff","font-size":"12px","display":"inline-block","line-height":"16px","padding-left":"5px"});
  501. var x = obj.getSize().x;
  502. var y = obj.getSize().y;
  503. this.shadeDiv.setStyles({
  504. "left":(obj.getLeft()-defaultObj.getLeft())+"px",
  505. "top":(obj.getTop()-defaultObj.getTop())+"px",
  506. "width":x+"px",
  507. "height":y+"px"
  508. });
  509. if(obj.getStyle("position")=="absolute"){
  510. this.shadeDiv.setStyles({
  511. "left":"0px",
  512. "top":"0px"
  513. })
  514. }
  515. this.inforDiv.setStyles({
  516. "left":(x/2)+"px",
  517. "top":(y/2)+"px"
  518. })
  519. },
  520. destroyShade : function(){
  521. if(this.shadeDiv) this.shadeDiv.destroy();
  522. //if(this.shadeDiv) this.shadeDiv.destroy()
  523. },
  524. showErrorMessage:function(xhr,text,error){
  525. var errorText = error;
  526. var errorMessage;
  527. if (xhr) errorMessage = xhr.responseText;
  528. if(errorMessage!=""){
  529. var e = JSON.parse(errorMessage);
  530. if(e.message){
  531. this.notice( e.message,"error");
  532. }else{
  533. this.notice( errorText,"error");
  534. }
  535. }else{
  536. this.notice(errorText,"error");
  537. }
  538. }
  539. });