KeyWorkForm.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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.KeyWorkForm = 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. "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.keyWork.popupForm;
  26. this.actions = this.app.restActions;
  27. this.path = "../x_component_Strategy/$KeyWorkForm/";
  28. this.cssPath = this.path + this.options.style + "/css.wcss";
  29. this._loadCss();
  30. this.options.title = this.lp.title;
  31. this.defaultYear = this.options.year;
  32. this.data = data || {};
  33. this.actions = actions;
  34. this.orgActions = MWF.Actions.get("x_organization_assemble_control");
  35. },
  36. load: function () {
  37. var now = new Date();
  38. this.thisYear = now.getFullYear();
  39. if (this.options.isNew) {
  40. this.create();
  41. } else if (this.options.isEdited) {
  42. this.edit();
  43. } else {
  44. this.open();
  45. }
  46. },
  47. createTopNode: function () {
  48. if (!this.formTopNode) {
  49. this.formTopNode = new Element("div.formTopNode", {
  50. "styles": this.css.formTopNode
  51. }).inject(this.formNode);
  52. this.formTopTextNode = new Element("div", {
  53. "styles": this.css.formTopTextNode,
  54. "text": this.data.title ? this.data.title : this.lp.addTitle
  55. }).inject(this.formTopNode);
  56. if (this.options.closeAction) {
  57. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  58. this.formTopCloseActionNode.addEvent("click", function () {
  59. this.close();
  60. }.bind(this))
  61. }
  62. this._createTopContent();
  63. }
  64. },
  65. _createTopContent: function () {
  66. },
  67. _createTableContent: function () {
  68. this.getData(function(){
  69. this.createTableInfo();
  70. }.bind(this));
  71. },
  72. getData:function(callback){
  73. if(!this.options.isNew){
  74. if(this.data.id){
  75. this.id = this.data.id;
  76. }else if(this.options.id){
  77. this.id = this.options.id;
  78. }
  79. this.actions.getKeyWorkById(this.id,function(json){
  80. this.data = json.data;
  81. this.formTopTextNode.set("text",this.data.strategydeploytitle);
  82. if(callback)callback();
  83. }.bind(this));
  84. }else{
  85. this.orgActions.listTopUnit(function(json){
  86. if(json.type == "success"){
  87. if(json.data && json.data.length>0){
  88. this.data.deptlist = json.data[0].distinguishedName;
  89. if(callback)callback();
  90. }
  91. }
  92. }.bind(this))
  93. }
  94. },
  95. createTableInfo:function(){
  96. //var html = "<table width='100%' border='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  97. var html = "<table styles='formTable'>" +
  98. "<tr>" +
  99. " <td styles='formTableTitle' lable='sequencenumber'></td>" +
  100. " <td styles='formTableValue' item='sequencenumber'></td>" +
  101. "</tr>"+
  102. "<tr>" +
  103. " <td styles='formTableTitle' lable='strategydeploytitle'></td>" +
  104. " <td styles='formTableValue' item='strategydeploytitle'></td>" +
  105. "</tr>"+
  106. "<tr>" +
  107. " <td styles='formTableTitle' lable='strategydeployyear'></td>" +
  108. " <td styles='formTableValue' item='strategydeployyear'></td>" +
  109. "</tr>"+
  110. "<tr style='display:none'>" +
  111. " <td styles='formTableTitle' lable='deptlist'></td>" +
  112. " <td styles='formTableValue' item='deptlist'></td>" +
  113. "</tr>"+
  114. //"<tr>" +
  115. //" <td styles='formTableTitle' lable='strategydeploydescribe'></td>" +
  116. //" <td styles='formTableValue' item='strategydeploydescribe'></td>" +
  117. //"</tr>"+
  118. "</table>";
  119. this.formTableArea.set("html", html);
  120. this.loadForm();
  121. if(this.options.isNew || this.options.isEdited){
  122. this.createActionBar();
  123. }
  124. },
  125. loadForm: function(){
  126. this.keyWorkForm = new MForm(this.formTableArea, this.data, {
  127. style: "default",
  128. isEdited: this.isEdited || this.isNew,
  129. itemTemplate: this.getItemTemplate(this.lp )
  130. },this.app,this.css);
  131. this.keyWorkForm.load();
  132. var taObj = this.formTableArea.getElements("textarea");
  133. taObj.setStyles({height:"100px"});
  134. //this.attachmentArea = this.formTableArea.getElement("[item='attachments']");
  135. //this.loadAttachment( this.attachmentArea );
  136. },
  137. getItemTemplate: function( lp ){
  138. _self = this;
  139. return {
  140. "sequencenumber":{
  141. text:lp.sequencenumber+":",
  142. notEmpty:true
  143. },
  144. "strategydeploytitle":{
  145. text:lp.title+":",
  146. notEmpty:true
  147. },
  148. "strategydeployyear":{
  149. text:lp.year+":",
  150. notEmpty:true,
  151. type:this.options.isNew?"select":"innerText",
  152. value:this.defaultYear||this.thisYear,
  153. attr : {style:"width:100%;height:30px;border-radius:3px;"},
  154. selectValue:lp.selectYears.split(","),
  155. selecTtext:lp.selectYears.split(",")
  156. },
  157. "deptlist":{
  158. text:lp.department+":",
  159. isEdited:false,
  160. notEmpty:true,
  161. type: "org",
  162. orgType:"unit",
  163. name:"deptlist",
  164. count: 0,
  165. attr : {readonly:true}
  166. },
  167. "strategydeploydescribe":{
  168. type:"textarea",
  169. attr:{style:"height:100px"},
  170. text:lp.description+":"
  171. }
  172. };
  173. },
  174. loadAttachment: function( area ){
  175. //this.attachment = new MWF.xApplication.Execution.Attachment( area, this.app, this.actions, this.app.lp, {
  176. // documentId : this.data.id,
  177. // isNew : this.options.isNew,
  178. // isEdited : this.options.isEdited,
  179. // onQueryUploadAttachment : function(){
  180. // this.attachment.isQueryUploadSuccess = true;
  181. // if( !this.data.id || this.data.id=="" ){
  182. // var data = this.form.getResult(true, ",", true, false, true);
  183. // if( !data ){
  184. // this.attachment.isQueryUploadSuccess = false;
  185. // return;
  186. // }
  187. // if(this.options.isNew){
  188. // data.centerId = this.options.centerWorkId || this.data.centerWorkId || this.data.centerId ;
  189. // }
  190. // this.app.restActions.saveTask(data, function(json){
  191. // if(json.type && json.type == "success"){
  192. // if(json.data.id) {
  193. // this.attachment.options.documentId = json.data.id;
  194. // this.data.id = json.data.id;
  195. // //this.options.isNew = false;
  196. // }
  197. // }
  198. // }.bind(this), function(xhr,text,error){
  199. // this.showErrorMessage(xhr,text,error)
  200. // }.bind(this),false)
  201. // }
  202. // }.bind(this)
  203. //});
  204. //
  205. //this.attachment.load();
  206. },
  207. createActionBar:function(){
  208. this.actionContent = new Element("div.actionContent",{"styles":this.css.actionContent}).inject(this.formTableContainer);
  209. this.actionBar = new Element("div.actionBar",{"styles":this.css.actionBar}).inject(this.actionContent);
  210. this.saveAction = new Element("div.saveAction",{
  211. "styles":this.css.saveAction,
  212. "text":this.lp.saveAction
  213. }).inject(this.actionBar).
  214. addEvents({
  215. "click":function(){
  216. this.save();
  217. }.bind(this)
  218. });
  219. this.cancelAction = new Element("div.cancelAction",{
  220. "styles":this.css.cancelAction,
  221. "text":this.lp.cancelAction
  222. }).inject(this.actionBar).
  223. addEvents({
  224. "click":function(){
  225. this.close();
  226. }.bind(this)
  227. });
  228. },
  229. save:function(callback){
  230. var data = this.keyWorkForm.getResult(true, ",", true, false, true);
  231. if(data){
  232. this.app.createShade();
  233. data.deptlist = data.deptlist.split(",");
  234. this.actions.saveKeyWork(data,function(json){
  235. if(json.type == "success"){
  236. this.close();
  237. this.fireEvent("postSave", json);
  238. }else if(json.type == "error"){
  239. this.app.notice(json.message,"error");
  240. }
  241. this.app.destroyShade();
  242. if(callback)callback();
  243. }.bind(this),function(xhr,text,error){
  244. this.app.showErrorMessage(xhr,text,error);
  245. this.app.destroyShade();
  246. }.bind(this));
  247. }
  248. },
  249. createShade: function(o,txtInfo){
  250. var defaultObj = this.content;
  251. var obj = o || defaultObj;
  252. var txt = txtInfo || "loading...";
  253. if(this.shadeDiv){ this.shadeDiv.destroy()}
  254. if(this["shadeTxtDiv"]) this["shadeTxtDiv"].destroy();
  255. this.shadeDiv = new Element("div.shadeDiv").inject(obj);
  256. this.inforDiv = new Element("div.inforDiv",{
  257. styles:{"height":"16px","display":"inline-block","position":"absolute","background-color":"#000000","border-radius":"3px","padding":"5px 10px"}
  258. }).inject(this.shadeDiv);
  259. this.loadImg = new Element("img.loadImg",{
  260. styles:{"width":"16px","height":"16px","float":"left"},
  261. src:this.path+"default/icon/loading.gif"
  262. }).inject(this.inforDiv);
  263. this.shadeTxtSpan = new Element("span.shadeTxtSpan").inject(this.inforDiv);
  264. this.shadeTxtSpan.set("text",txt);
  265. this.shadeDiv.setStyles({
  266. "width":"100%","height":"100%","position":"absolute","opacity":"0.6","background-color":"#cccccc","z-index":"999"
  267. });
  268. this.shadeTxtSpan.setStyles({"color":"#ffffff","font-size":"12px","display":"inline-block","line-height":"16px","padding-left":"5px"});
  269. var x = obj.getSize().x;
  270. var y = obj.getSize().y;
  271. this.shadeDiv.setStyles({
  272. "left":(obj.getLeft()-defaultObj.getLeft())+"px",
  273. "top":(obj.getTop()-defaultObj.getTop())+"px",
  274. "width":x+"px",
  275. "height":y+"px"
  276. });
  277. if(obj.getStyle("position")=="absolute"){
  278. this.shadeDiv.setStyles({
  279. "left":"0px",
  280. "top":"0px"
  281. })
  282. }
  283. this.inforDiv.setStyles({
  284. "left":(x/2)+"px",
  285. "top":(y/2)+"px"
  286. })
  287. },
  288. destroyShade : function(){
  289. if(this.shadeDiv) this.shadeDiv.destroy();
  290. //if(this.shadeDiv) this.shadeDiv.destroy()
  291. },
  292. showErrorMessage:function(xhr,text,error){
  293. var errorText = error;
  294. var errorMessage;
  295. if (xhr) errorMessage = xhr.responseText;
  296. if(errorMessage!=""){
  297. var e = JSON.parse(errorMessage);
  298. if(e.message){
  299. this.notice( e.message,"error");
  300. }else{
  301. this.notice( errorText,"error");
  302. }
  303. }else{
  304. this.notice(errorText,"error");
  305. }
  306. }
  307. });