autoForm-update.jsp 31 KB

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