autoForm-add.jsp 30 KB

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