FormExplorer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. MWF.xDesktop.requireApp("cms.ColumnManager", "Explorer", null, false);
  2. MWF.xApplication.cms.ColumnManager.FormExplorer = new Class({
  3. Extends: MWF.xApplication.cms.ColumnManager.Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "create": MWF.CMSCM.LP.form.create,
  7. "search": MWF.CMSCM.LP.form.search,
  8. "searchText": MWF.CMSCM.LP.form.searchText,
  9. "noElement": MWF.CMSCM.LP.form.noFormNoticeText
  10. },
  11. //
  12. //_createElement: function(e){
  13. // var _self = this;
  14. // var createForm = function(e, template){
  15. // layout.desktop.getFormDesignerStyle(function(){
  16. // var options = {
  17. // "style": layout.desktop.formDesignerStyle,
  18. // "template": template,
  19. // "onQueryLoad": function(){
  20. // this.actions = _self.app.restActions;
  21. // this.column = _self.app.options.column;
  22. // this.application = _self.app.options.column;
  23. // },
  24. // "onPostSave" : function(){
  25. // _self.reload();
  26. // }
  27. // };
  28. // layout.desktop.openApplication(e, "cms.FormDesigner", options);
  29. // }.bind(this));
  30. //
  31. // }
  32. //
  33. // var createTemplateMaskNode = new Element("div", {"styles": this.css.createTemplateMaskNode}).inject(this.app.content);
  34. // var createTemplateAreaNode = new Element("div", {"styles": this.css.createFormTemplateAreaNode}).inject(this.app.content);
  35. // createTemplateAreaNode.fade("in");
  36. //
  37. // var createTemplateScrollNode = new Element("div", {"styles": this.css.createTemplateScrollNode}).inject(createTemplateAreaNode);
  38. // var createTemplateContentNode = new Element("div", {"styles": this.css.createTemplateContentNode}).inject(createTemplateScrollNode);
  39. // MWF.require("MWF.widget.ScrollBar", function(){
  40. // new MWF.widget.ScrollBar(createTemplateScrollNode, {"indent": false});
  41. // }.bind(this));
  42. //
  43. // var _self = this;
  44. // var url = "../x_component_cms_FormDesigner/Module/Form/template/templates.json";
  45. // MWF.getJSON(url, function(json){
  46. // json.each(function(template){
  47. // var templateNode = new Element("div", {"styles": this.css.templateNode}).inject(createTemplateContentNode);
  48. // var templateIconNode = new Element("div", {"styles": this.css.templateIconNode}).inject(templateNode);
  49. // var templateTitleNode = new Element("div", {"styles": this.css.templateTitleNode, "text": template.title}).inject(templateNode);
  50. // templateNode.store("template", template.name);
  51. //
  52. // var templateIconImgNode = new Element("img", {"styles": this.css.templateIconImgNode}).inject(templateIconNode);
  53. // templateIconImgNode.set("src", "../x_component_cms_FormDesigner/Module/Form/template/"+template.icon);
  54. //
  55. // templateNode.addEvents({
  56. // "mouseover": function(){this.setStyles(_self.css.templateNode_over)},
  57. // "mouseout": function(){this.setStyles(_self.css.templateNode)},
  58. // "mousedown": function(){this.setStyles(_self.css.templateNode_down)},
  59. // "mouseup": function(){this.setStyles(_self.css.templateNode_over)},
  60. // "click": function(e){
  61. // createForm(e, this.retrieve("template"));
  62. // createTemplateAreaNode.destroy();
  63. // createTemplateMaskNode.destroy();
  64. // }
  65. // });
  66. //
  67. // }.bind(this))
  68. //
  69. // }.bind(this));
  70. //
  71. // createTemplateMaskNode.addEvent("click", function(){
  72. // createTemplateAreaNode.destroy();
  73. // createTemplateMaskNode.destroy();
  74. // });
  75. //
  76. // var size = this.app.content.getSize();
  77. // var y = (size.y - 262)/2;
  78. // var x = (size.x - 828)/2;
  79. // if (y<0) y=0;
  80. // if (x<0) x=0;
  81. // createTemplateAreaNode.setStyles({
  82. // "top": ""+y+"px",
  83. // "left": ""+x+"px"
  84. // });
  85. //
  86. //},
  87. _createElement: function(e){
  88. this.formTemplateList = null;
  89. this.defalutFormTemplateList = null;
  90. var _self = this;
  91. MWF.requireApp("cms.ColumnManager", "widget.CMSFormTemplateSelector", null, false);
  92. new MWF.xApplication.cms.ColumnManager.CMSFormTemplateSelector(this.app, {
  93. onSelectDefaultForm: function (template) {
  94. layout.desktop.getFormDesignerStyle(function () {
  95. var options = {
  96. "style": layout.desktop.formDesignerStyle,
  97. "template": template,
  98. "application":{
  99. "name": _self.app.options.application.name,
  100. "id": _self.app.options.application.id
  101. },
  102. "onQueryLoad": function () {
  103. this.actions = _self.app.restActions;
  104. this.application = _self.app.options.application;
  105. },
  106. "onPostSave": function () {
  107. _self.reload();
  108. }
  109. };
  110. layout.desktop.openApplication(e, "cms.FormDesigner", options);
  111. }.bind(this));
  112. },
  113. onSelectForm: function (template) {
  114. layout.desktop.getFormDesignerStyle(function () {
  115. var options = {
  116. "style": layout.desktop.formDesignerStyle,
  117. "templateId": template,
  118. "application":{
  119. "name": _self.app.options.application.name,
  120. "id": _self.app.options.application.id
  121. },
  122. "onQueryLoad": function () {
  123. this.actions = _self.app.restActions;
  124. this.application = _self.app.options.application;
  125. },
  126. "onPostSave": function () {
  127. _self.reload();
  128. }
  129. };
  130. layout.desktop.openApplication(e, "cms.FormDesigner", options);
  131. }.bind(this));
  132. }
  133. }).load();
  134. },
  135. showDeleteAction: function(){
  136. if (!this.deleteItemsAction){
  137. this.deleteItemsAction = new Element("div", {
  138. "styles": this.css.deleteItemsAction,
  139. "text": this.app.lp.deleteItems
  140. }).inject(this.node);
  141. this.deleteItemsAction.fade("in");
  142. this.deleteItemsAction.position({
  143. relativeTo: this.elementContentListNode
  144. });
  145. this.deleteItemsAction.addEvent("click", function(){
  146. var _self = this;
  147. this.app.confirm("warn", this.deleteItemsAction, MWF.CMSCM.LP.form.deleteFormTitle, MWF.CMSCM.LP.form.deleteForm, 300, 120, function(){
  148. _self.deleteItems();
  149. this.close();
  150. }, function(){
  151. this.close();
  152. });
  153. }.bind(this));
  154. }
  155. },
  156. _loadItemDataList: function(callback){
  157. this.app.restActions.listForm(this.app.options.column.id,callback);
  158. },
  159. _getItemObject: function(item, index){
  160. return new MWF.xApplication.cms.ColumnManager.FormExplorer.Form(this, item, {index:index})
  161. },
  162. setTooltip: function(){
  163. this.options.tooltip = {
  164. "create": MWF.CMSCM.LP.form.create,
  165. "search": MWF.CMSCM.LP.form.search,
  166. "searchText": MWF.CMSCM.LP.form.searchText,
  167. "noElement": MWF.CMSCM.LP.form.noFormNoticeText
  168. };
  169. },
  170. deleteItems: function(){
  171. while (this.deleteMarkItems.length){
  172. var item = this.deleteMarkItems.shift();
  173. if (this.deleteMarkItems.length){
  174. item.deleteForm();
  175. }else{
  176. item.deleteForm(function(){
  177. // this.reloadItems();
  178. this.hideDeleteAction();
  179. this.reload();
  180. }.bind(this));
  181. }
  182. }
  183. },
  184. keyCopy: function(e){
  185. if (this.selectMarkItems.length){
  186. var items = [];
  187. var i = 0;
  188. var checkItems = function(e){
  189. if (i>=this.selectMarkItems.length){
  190. if (items.length){
  191. var str = JSON.encode(items);
  192. if (e){
  193. e.clipboardData.setData('text/plain', str);
  194. }else {
  195. window.clipboardData.setData("Text", str);
  196. }
  197. this.app.notice(this.app.lp.copyed, "success");
  198. }
  199. }
  200. }.bind(this);
  201. this.selectMarkItems.each(function(item){
  202. this.app.restActions.getForm(item.data.id, function(json){
  203. //this.app.restActions.listFormFieldWithForm(item.data.id, function(fieldJson){
  204. // var fieldList = [];
  205. // fieldJson.data.number.each(function(f){ fieldList.push({"dataType": "number", "name": f.name}) });
  206. // fieldJson.data.person.each(function(f){ fieldList.push({"dataType": "person", "name": f.name}) });
  207. // fieldJson.data.string.each(function(f){ fieldList.push({"dataType": "string", "name": f.name}) });
  208. //
  209. // json.data.fieldList = fieldList;
  210. //}.bind(this), null, false);
  211. json.data.elementType = "form";
  212. items.push(json.data);
  213. i++;
  214. checkItems(e);
  215. }.bind(this), null, false)
  216. }.bind(this));
  217. }
  218. },
  219. keyPaste: function(e){
  220. var dataStr = "";
  221. if (e){
  222. dataStr = e.clipboardData.getData('text/plain');
  223. }else{
  224. dataStr = window.clipboardData.getData("Text");
  225. }
  226. var data = JSON.decode(dataStr);
  227. this.pasteItem(data, 0);
  228. },
  229. pasteItem: function(data, i){
  230. if (i<data.length){
  231. var item = data[i];
  232. if (item.elementType==="form"){
  233. this.saveItemAs(item, function(){
  234. i++;
  235. this.pasteItem(data, i);
  236. }.bind(this), function(){
  237. i++;
  238. this.pasteItem(data, i);
  239. }.bind(this), function(){
  240. this.reload();
  241. }.bind(this));
  242. }else{
  243. i++;
  244. this.pasteItem(data, i);
  245. }
  246. }else{
  247. this.reload();
  248. }
  249. },
  250. saveItemAs: function(data, success, failure, cancel){
  251. this.app.restActions.listForm(this.app.options.application.id, function(dJson){
  252. dJson.data = dJson.data || [];
  253. var i=1;
  254. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  255. if (someItems.length){
  256. var someItem = someItems[0];
  257. var lp = this.app.lp;
  258. var _self = this;
  259. var d1 = new Date().parse(data.updateTime);
  260. var d2 = new Date().parse(someItem.updateTime);
  261. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  262. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='font-weight: bold; font-size:14px;'>"+lp.copySource+" "+someItem.name+"</div>";
  263. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.updateTime+"</div>" +
  264. //"<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(someItem.lastUpdatePerson)+"</div>" +
  265. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  266. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='clear: both;font-weight: bold; font-size:14px;'>"+lp.copyTarget+" "+data.name+"</div>";
  267. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.updateTime+"</div>" +
  268. //"<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(data.lastUpdatePerson)+"</div>" +
  269. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  270. // html += "<>"
  271. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  272. {
  273. "text": lp.copyConfirm_overwrite,
  274. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  275. },
  276. {
  277. "text": lp.copyConfirm_new,
  278. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  279. },
  280. {
  281. "text": lp.copyConfirm_skip,
  282. "action": function(){/*nothing*/ this.close(); if (success) success();}
  283. },
  284. {
  285. "text": lp.copyConfirm_cancel,
  286. "action": function(){this.close(); if (cancel) cancel();}
  287. }
  288. ]);
  289. }else{
  290. this.saveItemAsNew(dJson, data, success, failure)
  291. }
  292. }.bind(this), function(){if (failure) failure();}.bind(this));
  293. },
  294. saveItemAsUpdate: function(someItem, form, success, failure){
  295. var item = this.app.options.application;
  296. var pcdata = JSON.decode(MWF.decodeJsonString(form.data));
  297. var mobiledata = JSON.decode(MWF.decodeJsonString(form.mobileData));
  298. pcdata.id = someItem.id;
  299. pcdata.isNewForm = false;
  300. pcdata.json.id = someItem.id;
  301. pcdata.json.application = item.id;
  302. pcdata.json.applicationName = item.name;
  303. pcdata.json.name = someItem.name;
  304. pcdata.json.alias = someItem.alias;
  305. pcdata.json.appId = item.id;
  306. pcdata.json.appName = item.name;
  307. mobiledata.json.id = someItem.id;
  308. mobiledata.json.application = item.id;
  309. mobiledata.json.applicationName = item.name;
  310. mobiledata.applicationName = item.name;
  311. mobiledata.json.name = someItem.name;
  312. mobiledata.json.alias = someItem.alias;
  313. mobiledata.json.appId = item.id;
  314. mobiledata.json.appName = item.name;
  315. this.app.restActions.saveForm(pcdata, mobiledata, form.fieldList, function(){
  316. if (success) success();
  317. }.bind(this), function(){
  318. if (failure) failure();
  319. }.bind(this));
  320. },
  321. saveItemAsNew: function(formsJson, form, success, failure){
  322. var item = this.app.options.application;
  323. var id = item.id;
  324. var name = item.name;
  325. var pcdata = JSON.decode(MWF.decodeJsonString(form.data));
  326. var mobiledata = JSON.decode(MWF.decodeJsonString(form.mobileData));
  327. var oldName = pcdata.json.name;
  328. var i=1;
  329. while (formsJson.data.some(function(d){ return d.name==pcdata.json.name })){
  330. pcdata.json.name = oldName+"_copy"+i;
  331. mobiledata.json.name = oldName+"_copy"+i;
  332. i++;
  333. }
  334. pcdata.id = "";
  335. pcdata.isNewForm = true;
  336. pcdata.json.id = "";
  337. pcdata.json.application = id;
  338. pcdata.json.applicationName = name;
  339. pcdata.json.appId = id;
  340. pcdata.json.appName = name;
  341. pcdata.json.alias = "";
  342. mobiledata.json.id = "";
  343. mobiledata.json.application = id;
  344. mobiledata.json.applicationName = name;
  345. mobiledata.applicationName = name;
  346. mobiledata.json.appId = id;
  347. mobiledata.json.appName = name;
  348. mobiledata.json.alias = "";
  349. this.app.restActions.saveForm(pcdata, mobiledata, form.fieldList, function(){
  350. if (success) success();
  351. }.bind(this), function(){
  352. if (failure) failure();
  353. }.bind(this));
  354. }
  355. });
  356. MWF.xApplication.cms.ColumnManager.FormExplorer.Form = new Class({
  357. Extends: MWF.xApplication.cms.ColumnManager.Explorer.Item,
  358. _open: function(e){
  359. layout.desktop.getFormDesignerStyle(function(){
  360. var _self = this;
  361. var options = {
  362. "style": layout.desktop.formDesignerStyle,
  363. "appId": "cms.FormDesigner"+_self.data.id,
  364. "id": _self.data.id,
  365. // "application": _self.explorer.app.options.column.id,
  366. "application":{
  367. "name": _self.explorer.app.options.column.name,
  368. "id": _self.explorer.app.options.column.id
  369. },
  370. "onQueryLoad": function(){
  371. this.actions = _self.explorer.actions;
  372. this.category = _self;
  373. this.options.id = _self.data.id;
  374. this.column = _self.explorer.app.options.column;
  375. this.application = _self.explorer.app.options.column;
  376. }
  377. };
  378. this.explorer.app.desktop.openApplication(e, "cms.FormDesigner", options);
  379. }.bind(this));
  380. },
  381. _getIcon: function(){
  382. var x = (Math.random()*33).toInt();
  383. return "process_icon_"+x+".png";
  384. },
  385. _getLnkPar: function(){
  386. return {
  387. "icon": this.explorer.path+this.explorer.options.style+"/formIcon/lnk.png",
  388. "title": this.data.name,
  389. "par": "cms.FormDesigner#{\"id\": \""+this.data.id+"\"}"
  390. };
  391. },
  392. // deleteItem: function(e){
  393. // var _self = this;
  394. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  395. // _self.deleteForm();
  396. // this.close();
  397. // },function(){
  398. // this.close();
  399. // });
  400. // },
  401. deleteForm: function(callback){
  402. this.explorer.app.restActions.removeForm(this.data.id, function(){
  403. this.node.destroy();
  404. if (callback) callback();
  405. }.bind(this));
  406. },
  407. saveItemAs: function(item) {
  408. var id = item.id;
  409. var name = item.name || item.appName;
  410. this.explorer.app.restActions.getForm(this.data.id, function (json) {
  411. var pcdata = JSON.decode(MWF.decodeJsonString(json.data.data));
  412. var mobiledata = JSON.decode(MWF.decodeJsonString(json.data.mobileData));
  413. pcdata.json.alias = "";
  414. mobiledata.json.alias = "";
  415. var oldName = pcdata.json.name;
  416. this.explorer.app.restActions.listForm(id, function (formsJson) {
  417. formsJson.data = formsJson.data || [];
  418. var i = 1;
  419. while (formsJson.data.some(function (d) {
  420. return d.name == pcdata.json.name
  421. })) {
  422. pcdata.json.name = oldName + "_copy" + i;
  423. mobiledata.json.name = oldName + "_copy" + i;
  424. i++;
  425. }
  426. pcdata.id = "";
  427. pcdata.isNewForm = true;
  428. pcdata.json.id = "";
  429. pcdata.json.application = id;
  430. pcdata.json.applicationName = name;
  431. pcdata.json.appId = id;
  432. pcdata.json.appName = name;
  433. mobiledata.json.id = "";
  434. mobiledata.json.application = id;
  435. mobiledata.applicationName = name;
  436. mobiledata.json.applicationName = name;
  437. mobiledata.json.appId = id;
  438. mobiledata.json.appName = name;
  439. //this.explorer.app.restActions.listFormFieldWithForm(this.data.id, function(fieldJson){
  440. // var fieldList = [];
  441. // if (fieldJson.data.number) fieldJson.data.number.each(function(f){ fieldList.push({"dataType": "number", "name": f.name}) });
  442. // if (fieldJson.data.person) fieldJson.data.person.each(function(f){ fieldList.push({"dataType": "person", "name": f.name}) });
  443. // if (fieldJson.data.string) fieldJson.data.string.each(function(f){ fieldList.push({"dataType": "string", "name": f.name}) });
  444. var fieldList = [];
  445. this.explorer.app.restActions.saveForm(pcdata, mobiledata, fieldList, function () {
  446. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  447. }.bind(this));
  448. //}.bind(this));
  449. }.bind(this));
  450. }.bind(this));
  451. }
  452. });