autoForm-add.vm 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>表单表</title>
  5. <script type="text/javascript" src="plug-in/mutiLang/zh-cn.js"></script>
  6. <script type="text/javascript" src="plug-in/jquery/jquery-1.9.0.js"></script>
  7. <script type="text/javascript" src="plug-in/jquery/jquery.cookie.js"></script>
  8. <script type="text/javascript" src="plug-in/jquery-plugs/storage/jquery.storageapi.min.js"></script>
  9. <script type="text/javascript" src="plug-in/tools/dataformat.js"></script>
  10. <link id="easyuiTheme" rel="stylesheet" href="plug-in/easyui/themes/metrole/easyui.css" type="text/css"></link>
  11. <link id="easyuiTheme" rel="stylesheet" href="plug-in/easyui/themes/metrole/main.css" type="text/css"></link>
  12. <link id="easyuiTheme" rel="stylesheet" href="plug-in/easyui/themes/metrole/icon.css" type="text/css"></link>
  13. <link rel="stylesheet" type="text/css" href="plug-in/accordion/css/accordion.css">
  14. <link rel="stylesheet" type="text/css" href="plug-in/accordion/css/icons.css">
  15. <script type="text/javascript" src="plug-in/easyui/jquery.easyui.min.1.3.2.js"></script>
  16. <script type="text/javascript" src="plug-in/easyui/locale/zh-cn.js"></script>
  17. <script type="text/javascript" src="plug-in/tools/syUtil.js"></script>
  18. <script type="text/javascript" src="plug-in/easyui/extends/datagrid-scrollview.js"></script>
  19. <link rel="stylesheet" href="plug-in/tools/css/metrole/common.css" type="text/css"></link>
  20. <link rel="stylesheet" href="plug-in/ace/css/font-awesome.css" type="text/css"></link>
  21. <script type="text/javascript" src="plug-in/lhgDialog/lhgdialog.min.js?skin=metrole"></script>
  22. <script type="text/javascript" src="plug-in/ace/js/bootstrap-tab.js"></script>
  23. <script type="text/javascript" src="plug-in/tools/curdtools_zh-cn.js"></script>
  24. <script type="text/javascript" src="plug-in/tools/easyuiextend.js"></script>
  25. <script type="text/javascript" src="plug-in/jquery-plugs/hftable/jquery-hftable.js"></script>
  26. <script type="text/javascript" src="plug-in/tools/json2.js"></script>
  27. <link rel="stylesheet" type="text/css" href="plug-in/ztree/css/zTreeStyle.css">
  28. <script type="text/javascript" src="plug-in/ztree/js/jquery.ztree.core-3.5.min.js"></script>
  29. <script type="text/javascript" src="plug-in/ztree/js/jquery.ztree.excheck-3.5.min.js"></script>
  30. <script type="text/javascript">
  31. var setting = {
  32. check: {
  33. enable: true
  34. },
  35. data: {
  36. simpleData: {
  37. enable: true
  38. }
  39. }
  40. };
  41. var stylesetting = {
  42. check: {
  43. enable: true,
  44. chkStyle: "radio",
  45. radioType: "level"
  46. },
  47. data: {
  48. simpleData: {
  49. enable: true
  50. }
  51. }
  52. };
  53. function showIconForTree(treeId, treeNode) {
  54. return ! treeNode.isParent;
  55. }
  56. //初始化主数据源
  57. function initMainTableSourceSelect() {
  58. var ztree = jQuery.fn.zTree.getZTreeObj("dbSelect");
  59. var node = ztree.getNodesByParam("pid", 0, null);
  60. var options = "<option value=''>请选择主数据源</option>";
  61. jQuery.each(node, function(i, f) {
  62. options += "<option value='" + f.dbCode + "'>" + f.name + "</option>";
  63. })
  64. jQuery("#mainTableSource").html(options);
  65. }
  66. jQuery(function() {
  67. jQuery.fn.zTree.init(jQuery("#dbSelect"), setting, []);
  68. var styleDate = eval('$!{styleSelect}');
  69. var iconPath = "plug-in/ztree/css/img/diy/2.png";
  70. jQuery(styleDate).each(function(i) {
  71. this.icon = iconPath;
  72. });
  73. jQuery.fn.zTree.init(jQuery("#styleSelect"), stylesetting, styleDate);
  74. initMainTableSourceSelect();
  75. /* //自定义easyui表单验证规则
  76. jQuery.extend(jQuery.fn.validatebox.defaults.rules, {
  77. uniqueNm: {
  78. validator: function (value) {
  79. jQuery.post(
  80. 'autoFormController.do?checkFormNm',
  81. {formName:value},
  82. function(data){
  83. var d = jQuery.parseJSON(data);
  84. if(d.msg == '0' || d.msg == '1'){
  85. jQuery("#formName").removeClass();
  86. } else{
  87. return false;
  88. }
  89. }
  90. );
  91. },
  92. message: '表单名称重复,请重新输入'
  93. }
  94. });
  95. */
  96. //添加生成按钮的onclick事件
  97. jQuery("#createCode").click(function() {
  98. var formdbId = getNodeId();
  99. if (formdbId == '') {
  100. tip('请选择表单数据源');
  101. }
  102. var styleId = getStyleId();
  103. if (styleId == '') {
  104. tip('请选择自定义表单模板');
  105. }
  106. jQuery.post('autoFormController.do?docreateCode', {
  107. formdbId: formdbId,
  108. styleId: styleId
  109. },
  110. function(data) {
  111. var d = jQuery.parseJSON(data);
  112. if (d.success) {
  113. var editor = UE.getEditor('content');
  114. editor.ready(function() {
  115. setContent();
  116. //editor.setContent(jQuery("#formContent").val()+d.msg.replace(new RegExp(/(&quot;)/g),"'"));
  117. editor.execCommand('inserthtml', d.msg.replace(new RegExp(/(&quot;)/g), "'"));
  118. });
  119. }
  120. });
  121. });
  122. });
  123. function doAdd() {
  124. var id = jQuery("#id").val();
  125. if (jQuery.trim(id) == '') {
  126. //在提交前,先提醒需要保存当前页面信息,才能继续添加
  127. jQuery.dialog.confirm('自定义表单信息保存后才能添加数据源,是否保存?',
  128. function() {
  129. jQuery('#formobj').form('submit', {
  130. url: 'autoFormController.do?doUpdate',
  131. onSubmit: function() {
  132. if (leipiEditor.queryCommandState('source')) leipiEditor.execCommand('source'); //切换到编辑模式才提交,否则有bug
  133. if (leipiEditor.hasContents()) {
  134. leipiEditor.sync();
  135. var parse_form = leipiFormDesign.parse_form(leipiEditor.getContent());
  136. jQuery("#formContent").val(parse_form);
  137. } else {
  138. jQuery("#formContent").val('');
  139. }
  140. return jQuery("#formobj").form('validate');
  141. },
  142. success: function(data) {
  143. var d = jQuery.parseJSON(data);
  144. if (d.success) {
  145. id = d.attributes.id;
  146. jQuery("#id").val(id);
  147. leipiEditor.ready(function() {
  148. leipiEditor.execCommand('serverparam', 'id', jQuery('#id').val());
  149. });
  150. saveForm(id);
  151. }
  152. }
  153. });
  154. });
  155. } else {
  156. saveForm(id);
  157. }
  158. }
  159. function saveForm(id) {
  160. var addurl = "autoFormDbController.do?goAdd_vm&autoFormId=" + id;
  161. jQuery.dialog({
  162. content: 'url:' + addurl,
  163. lock: true,
  164. //zIndex:1990,
  165. width: 700,
  166. height: 400,
  167. title: "录入",
  168. opacity: 0.3,
  169. cache: false,
  170. modal: false,
  171. okVal: "确定",
  172. ok: function() {
  173. var iframe = this.iframe.contentWindow;
  174. iframe.jQuery('#formobj').form('submit', {
  175. url: 'autoFormDbController.do?doAdd',
  176. onSubmit: function() {
  177. iframe.setDataSourceVal();
  178. return iframe.jQuery("#formobj").Validform({
  179. tiptype: 3
  180. }).check();
  181. },
  182. success: function(data) {
  183. iframe.windowapi.close();
  184. var d = jQuery.parseJSON(data);
  185. if (d.success) {
  186. tip(d.msg);
  187. doReload();
  188. } else {
  189. tip(d.msg);
  190. }
  191. }
  192. });
  193. return false;
  194. },
  195. cancelVal: '取消',
  196. cancel: true
  197. /*为true等价于function(){}*/
  198. }).max().zindex();
  199. }
  200. function doUpdate() {
  201. //获取选中的父节点
  202. var id = getNodeId();
  203. if (id == null || id == '') {
  204. alert('请选择需要编辑的表单数据源');
  205. return false;
  206. }
  207. var addurl = "autoFormDbController.do?goUpdate&id=" + id;
  208. jQuery.dialog({
  209. content: 'url:' + addurl,
  210. lock: true,
  211. //zIndex:1990,
  212. width: 700,
  213. height: 400,
  214. title: "编辑",
  215. opacity: 0.3,
  216. cache: false,
  217. okVal: '确定',
  218. ok: function() {
  219. var iframe = this.iframe.contentWindow;
  220. iframe.jQuery('#formobj').form('submit', {
  221. url: 'autoFormDbController.do?doUpdate',
  222. onSubmit: function() {
  223. iframe.setDataSourceVal();
  224. return (iframe.jQuery("#formobj").Validform({
  225. tiptype: 3
  226. }).check());
  227. },
  228. success: function(data) {
  229. iframe.windowapi.close();
  230. var d = jQuery.parseJSON(data);
  231. if (d.success) {
  232. tip(d.msg);
  233. doReload();
  234. }
  235. }
  236. });
  237. return false;
  238. },
  239. cancelVal: '取消',
  240. cancel: true
  241. /*为true等价于function(){}*/
  242. }).max().zindex();
  243. }
  244. function doDelete() {
  245. var id = getNodeId();
  246. if (id == null || id == '') {
  247. alert('请选择需要删除的表单数据源');
  248. return false;
  249. }
  250. jQuery.dialog.confirm('你确定永久删除该数据吗?',
  251. function() {
  252. jQuery.post('autoFormDbController.do?doBatchDel', {
  253. ids: id
  254. },
  255. function(data) {
  256. var d = jQuery.parseJSON(data);
  257. if (d.success) {
  258. doReload();
  259. }
  260. });
  261. });
  262. }
  263. function doReload() {
  264. jQuery.post('autoFormController.do?treeReload', {
  265. autoFormId: jQuery("#id").val()
  266. },
  267. function(data) {
  268. var d = jQuery.parseJSON(data);
  269. if (d.success) {
  270. var dbDate = eval(d.msg);
  271. jQuery.fn.zTree.init(jQuery("#dbSelect"), setting, dbDate);
  272. initMainTableSourceSelect();
  273. }
  274. });
  275. }
  276. //改成多选时取得多个ID根据","分割
  277. function getNodeId() {
  278. var treeObj = jQuery.fn.zTree.getZTreeObj("dbSelect");
  279. var nodes = treeObj.getCheckedNodes(true);
  280. if (nodes.length == 0) {
  281. return "";
  282. }
  283. var ids = [];
  284. for (var i = 0; i < nodes.length; i++) {
  285. if (nodes[i].pid == '0') {
  286. ids.push(nodes[i].id);
  287. }
  288. }
  289. return ids.join(',');
  290. }
  291. function getStyleId() {
  292. var treeObj = jQuery.fn.zTree.getZTreeObj("styleSelect");
  293. var nodes = treeObj.getCheckedNodes(true);
  294. if (nodes.length == 0) {
  295. return "";
  296. }
  297. var id = "";
  298. for (var i = 0; i < nodes.length; i++) {
  299. id = nodes[i].id;
  300. break;
  301. }
  302. return id;
  303. }
  304. function doExit() {
  305. var cur = window.top.jQuery('#maintabs').tabs('getSelected');
  306. var index = window.top.jQuery('#maintabs').tabs('getTabIndex', cur);
  307. window.top.jQuery('#maintabs').tabs('close', index);
  308. }
  309. function doSubmit() {
  310. jQuery('#formobj').form('submit', {
  311. url: 'autoFormController.do?doUpdate',
  312. onSubmit: function() {
  313. if (leipiEditor.queryCommandState('source')) leipiEditor.execCommand('source'); //切换到编辑模式才提交,否则有bug
  314. if (leipiEditor.hasContents()) {
  315. leipiEditor.sync();
  316. var parse_form = leipiFormDesign.parse_form(leipiEditor.getContent());
  317. jQuery("#formContent").val(parse_form);
  318. } else {
  319. jQuery("#formContent").val('');
  320. }
  321. return jQuery("#formobj").form('validate');
  322. },
  323. success: function(data) {
  324. var d = jQuery.parseJSON(data);
  325. if (d.success) {
  326. id = d.attributes.id;
  327. jQuery("#id").val(id);
  328. leipiEditor.ready(function() {
  329. leipiEditor.execCommand('serverparam', 'id', jQuery('#id').val());
  330. });
  331. tip(d.msg);
  332. } else {
  333. tip(d.msg);
  334. }
  335. }
  336. });
  337. }
  338. </script>
  339. <style>
  340. .menu {
  341. list-style: none;
  342. width: 100%;
  343. }
  344. .menu li {
  345. float: left;
  346. }
  347. </style>
  348. <link rel="stylesheet" href="plug-in/Validform/css/metrole/style.css" type="text/css" />
  349. <link rel="stylesheet" href="plug-in/Validform/css/metrole/tablefrom.css" type="text/css" />
  350. <script type="text/javascript" src="plug-in/Validform/js/Validform_v5.3.1_min_zh-cn.js"></script>
  351. <script type="text/javascript" src="plug-in/Validform/js/Validform_Datatype_zh-cn.js"></script>
  352. <script type="text/javascript" src="plug-in/Validform/js/datatype_zh-cn.js"></script>
  353. <script type="text/javascript">
  354. jQuery(function() {
  355. jQuery("#formobj").Validform({
  356. tiptype: 1,
  357. btnSubmit: "#btn",
  358. btnReset: "#btn_reset",
  359. ajaxPost: true,
  360. beforeSubmit: function(curform) {
  361. var tag = false;
  362. return setContent()
  363. },
  364. callback: function(data) {
  365. test(data);
  366. }
  367. });
  368. });
  369. </script>
  370. </head>
  371. <body>
  372. <div id="cc" class="easyui-layout" fit="true">
  373. <div data-options="region:'north',split:false,border:false">
  374. <div class="panel-header" align="left">
  375. <a href="#" class="easyui-linkbutton l-btn" plain="true" iconcls="icon-save" onclick="javascript:doSubmit();">保存</a>
  376. <a href="#" class="easyui-linkbutton l-btn" plain="true" iconcls="icon-cancel" onclick="javascript:doExit();">关闭</a></div>
  377. </div>
  378. <div data-options="region:'west',title:'表单数据源',split:true" style="width: 200px;">
  379. <div region="north" border="false" style="overflow: hidden;" fit="true">
  380. <div style="width: 99.5%; height: 300px; overflow-y: auto;">
  381. <ul class="menu" style="width: 187px">
  382. <li style="width: 15%;">
  383. <a href="#" onclick="javascript:doAdd();"><img src="plug-in/easyui/themes/icons/edit_add.png" /></a>
  384. </li>
  385. <li style="width: 15%;">
  386. <a href="#" onclick="javascript:doUpdate();"><img src="plug-in/easyui/themes/icons/pencil.png" /></a>
  387. </li>
  388. <li style="width: 15%;">
  389. <a href="#" onclick="javascript:doDelete();"><img src="plug-in/easyui/themes/icons/cancel.png" /></a>
  390. </li>
  391. <li style="width: 15%;">
  392. <a href="#" onclick="javascript:doReload();"><img src="plug-in/easyui/themes/icons/reload.png" /></a>
  393. </li>
  394. <li>
  395. <a href="#" class="easyui-linkbutton c1" id="createCode">&nbsp;生 成&nbsp;</a></li>
  396. </ul>
  397. <ul id="dbSelect" class="ztree" style="margin-top: 30px;"></ul>
  398. </div>
  399. </div>
  400. <div region="south" border="false" style="overflow: hidden;">
  401. <div style="width: 99.5%; overflow-y: auto;">
  402. <div class="panel-header">
  403. <div class="panel-title">选择默认模板样式</div></div>
  404. <ul id="styleSelect" class="ztree"></ul>
  405. </div>
  406. </div>
  407. </div>
  408. <div data-options="region:'center',title:'表单内容'" style="padding: 5px; background: #eee;">
  409. <form id="formobj" action="autoFormController.do?doUpdate" name="formobj" method="post">
  410. <input id="id" name="id" type="hidden" value="" />
  411. <input id="formStyleId" name="formStyleId" type="hidden" value="" />
  412. <table style="width: 100%;" cellpadding="0" cellspacing="1" class="formtable">
  413. <tr>
  414. <td align="right" style="width: 8%;">
  415. <label class="Validform_label">表单编码:</label>
  416. </td>
  417. <td class="value" style="width: 20%;">
  418. <input
  419. id="formName"
  420. name="formName"
  421. type="text"
  422. style="width: 75%;"
  423. class="easyui-validatebox"
  424. required="true"
  425. errorMsg="不能为中文"
  426. ajaxurl="autoFormController.do?checkTbCode"
  427. datatype="/^[A-Za-z\d-._]+$/"
  428. missingMessage="表单编码必须填写"
  429. />
  430. <span class="Validform_checktip"></span>
  431. <label class="Validform_label" style="display: none;">表单编码</label>
  432. </td>
  433. <td align="right" style="width: 8%;">
  434. <label class="Validform_label">表单名:</label>
  435. </td>
  436. <td class="value" style="width: 20%;">
  437. <input id="formDesc" required="true" name="formDesc" type="text" style="width: 75%;" class="easyui-validatebox" />
  438. <span class="Validform_checktip"></span>
  439. <label class="Validform_label" style="display: none;">表单名</label>
  440. </td>
  441. <td align="right" style="width: 8%;">
  442. <label class="Validform_label">主数据源:</label>
  443. </td>
  444. <td class="value" style="width: 20%;">
  445. <select id="mainTableSource" name="mainTableSource"></select>
  446. <span class="Validform_checktip"></span>
  447. <label class="Validform_label" style="display: none;">表单名</label>
  448. </td>
  449. </tr>
  450. <tr>
  451. <td class="value" colspan=6>
  452. <input id="formContent" name="formContent" type="hidden">
  453. <script id="content" type="text/plain" style="width:99%;"></script>
  454. </td>
  455. </tr>
  456. </table>
  457. </form>
  458. </div>
  459. </div>
  460. </body>
  461. <script>UEDITOR_HOME_URL='$!{basePath}/plug-in/Formdesign/js/ueditor/';</script>
  462. <script type="text/javascript" charset="utf-8" src="plug-in/Formdesign/js/ueditor/ueditor.config.js?2023"></script>
  463. <script type="text/javascript" charset="utf-8" src="plug-in/Formdesign/js/ueditor/ueditor.all.js?2023"> </script>
  464. <script type="text/javascript" charset="utf-8" src="plug-in/Formdesign/js/ueditor/lang/zh-cn/zh-cn.js?2023"></script>
  465. <script type="text/javascript" charset="utf-8" src="plug-in/Formdesign/js/ueditor/formdesign/leipi.formdesign.v4.js?2023"></script>
  466. <script type="text/javascript">
  467. var leipiEditor = UE.getEditor('content',{
  468. //allowDivTransToP: false,//阻止转换div 为p
  469. toolleipi:true,//是否显示,设计器的 toolbars
  470. textarea: 'design_content',
  471. //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个 /*
  472. toolbars: [[
  473. 'fullscreen', 'source', '|', 'undo', 'redo', '|',//'date', 'time',
  474. 'fontfamily', 'fontsize', '|', 'indent', '|',
  475. //'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
  476. //'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
  477. //'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
  478. //'directionalityltr', 'directionalityrtl', 'indent', '|',
  479. 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', //'touppercase', 'tolowercase', '|',
  480. //'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
  481. //'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
  482. //'horizontal', 'spechars', 'snapscreen', 'wordimage', '|',
  483. 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', '|',
  484. //'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', '|',//'charts', '|',
  485. //'print', 'preview', 'searchreplace', 'help', 'drafts'
  486. ]],
  487. wordCount:false,
  488. elementPathEnabled:false,
  489. initialFrameHeight:400
  490. });
  491. var leipiFormDesign = {
  492. exec : function (method) {
  493. leipiEditor.execCommand(method);
  494. },
  495. parse_form:function(template,fields)
  496. {
  497. //正则 radios|checkboxs|select 匹配的边界 |--| 因为当使用 {} 时js报错 (plugins|fieldname|fieldflow)
  498. var preg = /(\|-<span(((?!<span).)*plugins=\"(radios|checkboxs|select)\".*?)>(.*?)<\/span>-\||<(img|input|textarea|select).*?(<\/select>|<\/textarea>|\/>))/gi,preg_attr =/(\w+)=\"(.?|.+?)\"/gi,preg_group =/<input.*?\/>/gi;
  499. if(!fields) fields = 0;
  500. var template_parse = template,template_data = new Array(),add_fields=new Object(),checkboxs=0;
  501. var pno = 0;
  502. template.replace(preg, function(plugin,p1,p2,p3,p4,p5,p6){
  503. var parse_attr = new Array(),attr_arr_all = new Object(),name = '', select_dot = '' , is_new=false;
  504. var p0 = plugin;
  505. var tag = p6 ? p6 : p4;
  506. //alert(tag + " \n- t1 - "+p1 +" \n-2- " +p2+" \n-3- " +p3+" \n-4- " +p4+" \n-5- " +p5+" \n-6- " +p6);
  507. if(tag == 'radios' || tag == 'checkboxs')
  508. {
  509. plugin = p2;
  510. }else if(tag == 'select')
  511. {
  512. plugin = plugin.replace('|-','');
  513. plugin = plugin.replace('-|','');
  514. }
  515. plugin.replace(preg_attr, function(str0,attr,val) {
  516. if(attr=='name')
  517. {
  518. if(val=='NEWFIELD')
  519. {
  520. is_new=true;
  521. fields++;
  522. val = 'data_'+fields;
  523. }
  524. name = val;
  525. }
  526. if(tag=='select' && attr=='value')
  527. {
  528. if(!attr_arr_all[attr]) attr_arr_all[attr] = '';
  529. attr_arr_all[attr] += select_dot + val;
  530. select_dot = ',';
  531. }else
  532. {
  533. attr_arr_all[attr] = val;
  534. }
  535. var oField = new Object();
  536. oField[attr] = val;
  537. parse_attr.push(oField);
  538. })
  539. /*alert(JSON.stringify(parse_attr));return;*/
  540. if(tag =='checkboxs') /*复选组 多个字段 */
  541. {
  542. plugin = p0;
  543. plugin = plugin.replace('|-','');
  544. plugin = plugin.replace('-|','');
  545. var name = 'checkboxs_'+checkboxs;
  546. attr_arr_all['parse_name'] = name;
  547. attr_arr_all['name'] = '';
  548. attr_arr_all['value'] = '';
  549. attr_arr_all['content'] = '<span leipiplugins="checkboxs" selector="'+attr_arr_all['selector']+'" autofield="'+attr_arr_all['autofield']+'" title="'+attr_arr_all['title']+'">';
  550. var dot_name ='', dot_value = '';
  551. p5.replace(preg_group, function(parse_group) {
  552. var is_new=false,option = new Object();
  553. parse_group.replace(preg_attr, function(str0,k,val) {
  554. if(k=='name')
  555. {
  556. if(val=='NEWFIELD')
  557. {
  558. is_new=true;
  559. fields++;
  560. val = 'data_'+fields;
  561. }
  562. attr_arr_all['name'] += dot_name + val;
  563. dot_name = ',';
  564. }
  565. else if(k=='value')
  566. {
  567. attr_arr_all['value'] += dot_value + val;
  568. dot_value = ',';
  569. }
  570. option[k] = val;
  571. });
  572. if(!attr_arr_all['options']) attr_arr_all['options'] = new Array();
  573. attr_arr_all['options'].push(option);
  574. if(!option['checked']) option['checked'] = '';
  575. var checked = option['checked'] ? 'checked="checked"' : '';
  576. var checkedtext=option['checkedtext'] ? option['checkedtext'] :option['value'];
  577. attr_arr_all['content'] +='<input type="checkbox" name="'+option['name']+'" checkedtext="'+checkedtext+'" value="'+option['value']+'" fieldname="' + attr_arr_all['fieldname'] + option['fieldname'] + '" fieldflow="' + attr_arr_all['fieldflow'] + '" '+checked+'/>'+checkedtext+'&nbsp;';
  578. if(is_new)
  579. {
  580. var arr = new Object();
  581. arr['name'] = option['name'];
  582. arr['plugins'] = attr_arr_all['plugins'];
  583. arr['fieldname'] = attr_arr_all['fieldname'] + option['fieldname'];
  584. arr['fieldflow'] = attr_arr_all['fieldflow'];
  585. add_fields[option['name']] = arr;
  586. }
  587. });
  588. attr_arr_all['content'] += '</span>';
  589. //parse
  590. template = template.replace(plugin,attr_arr_all['content']);
  591. template_parse = template_parse.replace(plugin,'{'+name+'}');
  592. template_parse = template_parse.replace('{|-','');
  593. template_parse = template_parse.replace('-|}','');
  594. template_data[pno] = attr_arr_all;
  595. checkboxs++;
  596. }else if(name)
  597. {
  598. if(tag =='radios') /*单选组 一个字段*/
  599. {
  600. plugin = p0;
  601. plugin = plugin.replace('|-','');
  602. plugin = plugin.replace('-|','');
  603. attr_arr_all['value'] = '';
  604. attr_arr_all['content'] = '<span leipiplugins="radios" selector="'+attr_arr_all['selector']+'" name="'+attr_arr_all['name']+'" autofield="'+attr_arr_all['autofield']+'" title="'+attr_arr_all['title']+'">';
  605. var dot='';
  606. p5.replace(preg_group, function(parse_group) {
  607. var option = new Object();
  608. parse_group.replace(preg_attr, function(str0,k,val) {
  609. if(k=='value')
  610. {
  611. attr_arr_all['value'] += dot + val;
  612. dot = ',';
  613. }
  614. option[k] = val;
  615. });
  616. option['name'] = attr_arr_all['name'];
  617. if(!attr_arr_all['options']) attr_arr_all['options'] = new Array();
  618. attr_arr_all['options'].push(option);
  619. if(!option['checked']) option['checked'] = '';
  620. var checked = option['checked'] ? 'checked="checked"' : '';
  621. var checkedtext=option['checkedtext'] ? option['checkedtext'] :option['value'];
  622. attr_arr_all['content'] +='<input type="radio" name="'+attr_arr_all['name']+'" checkedtext="'+checkedtext+'" value="'+option['value']+'" '+checked+'/>'+checkedtext+'&nbsp;';
  623. });
  624. attr_arr_all['content'] += '</span>';
  625. }else
  626. {
  627. attr_arr_all['content'] = is_new ? plugin.replace(/NEWFIELD/,name) : plugin;
  628. }
  629. //attr_arr_all['itemid'] = fields;
  630. //attr_arr_all['tag'] = tag;
  631. template = template.replace(plugin,attr_arr_all['content']);
  632. template_parse = template_parse.replace(plugin,'{'+name+'}');
  633. template_parse = template_parse.replace('{|-','');
  634. template_parse = template_parse.replace('-|}','');
  635. if(is_new)
  636. {
  637. var arr = new Object();
  638. arr['name'] = name;
  639. arr['plugins'] = attr_arr_all['plugins'];
  640. arr['title'] = attr_arr_all['title'];
  641. arr['orgtype'] = attr_arr_all['orgtype'];
  642. arr['fieldname'] = attr_arr_all['fieldname'];
  643. arr['fieldflow'] = attr_arr_all['fieldflow'];
  644. add_fields[arr['name']] = arr;
  645. }
  646. template_data[pno] = attr_arr_all;
  647. }
  648. pno++;
  649. })
  650. var view = template.replace(/{\|-/g,'');
  651. view = view.replace(/-\|}/g,'');
  652. var parse_form = new Object({
  653. 'fields':fields,//总字段数
  654. 'template':template,//完整html
  655. 'parse':view,
  656. 'data':template_data,//控件属性
  657. 'add_fields':add_fields//新增控件
  658. });
  659. return JSON.stringify(parse_form);
  660. },
  661. /*type = save 保存设计 versions 保存版本 close关闭 */
  662. fnCheckForm : function ( type ) {
  663. if(formEditor.queryCommandState( 'source' ))
  664. formEditor.execCommand('source');//切换到编辑模式才提交,否则有bug
  665. if(formEditor.hasContents()){
  666. formEditor.sync();/*同步内容*/
  667. //--------------以下仅参考-----------------------------------------------------------------------------------------------------
  668. var type_value='',formid=0,fields=jQuery("#fields").val(),formeditor='';
  669. if( typeof type!=='undefined' ){
  670. type_value = type;
  671. }
  672. //获取表单设计器里的内容
  673. formeditor=formEditor.getContent();
  674. //解析表单设计器控件
  675. var parse_form = this.parse_form(formeditor,fields);
  676. //alert(parse_form);
  677. //异步提交数据
  678. jQuery.ajax({
  679. type: 'POST',
  680. url : '/config/form/processor',
  681. //dataType : 'json',
  682. data : {'type' : type_value,'formid':'','parse_form':parse_form},
  683. success : function(data){
  684. if(data == true) {
  685. alert('表单保存成功');
  686. window.location.href='/config/form';
  687. } else {
  688. alert('表单保存失败');
  689. }
  690. }
  691. });
  692. } else {
  693. alert('表单内容不能为空!')
  694. jQuery('#submitbtn').button('reset');
  695. return false;
  696. }
  697. } ,
  698. // 预览表单
  699. fnReview : function (){
  700. if(leipiEditor.queryCommandState( 'source' ))
  701. leipiEditor.execCommand('source');
  702. if(leipiEditor.hasContents()){
  703. leipiEditor.sync();
  704. var parse_form = this.parse_form(leipiEditor.getContent());
  705. jQuery("#formContent").val(parse_form);
  706. document.formobj.target="mywin";
  707. window.open('','mywin',"menubar=0,toolbar=0,status=0,resizable=1,left=0,top=0,scrollbars=1,width=" +(screen.availWidth-10) + ",height=" + (screen.availHeight-50) + "\"");
  708. document.formobj.action="autoFormController.do?review";
  709. document.formobj.submit(); //提交表单
  710. } else {
  711. alert('表单内容不能为空!');
  712. return false;
  713. }
  714. }
  715. };
  716. function setContent(){
  717. if(leipiEditor.queryCommandState( 'source' ))
  718. leipiEditor.execCommand('source');//切换到编辑模式才提交,否则有bug
  719. if(leipiEditor.hasContents()){
  720. leipiEditor.sync();
  721. jQuery("#formContent").val(leipiEditor.getContent());
  722. }
  723. }
  724. </script>
  725. </html>