preview.jsp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. <t:base type="jquery,easyui,tools"></t:base>
  7. <link rel="stylesheet" href="plug-in/Validform/css/style.css" type="text/css"/>
  8. <link rel="stylesheet" href="plug-in/Validform/css/tablefrom.css" type="text/css"/>
  9. <link rel="stylesheet" href="plug-in/Formdesign/js/ueditor/formdesign/bootstrap/css/bootstrap.css">
  10. <!--[if lte IE 6]>
  11. <link rel="stylesheet" type="text/css" href="plug-in/Formdesign/js/ueditor/formdesign/bootstrap/css/bootstrap-ie6.css">
  12. <![endif]-->
  13. <!--[if lte IE 7]>
  14. <link rel="stylesheet" type="text/css" href="plug-in/Formdesign/js/ueditor/formdesign/bootstrap/css/ie.css">
  15. <![endif]-->
  16. <link rel="stylesheet" href="plug-in/Formdesign/js/ueditor/formdesign/leipi.style.css">
  17. </head>
  18. <body>
  19. <textarea id="original" style="display:none">${contents}</textarea>
  20. <div id='preview'/>
  21. <script>
  22. $(function(){
  23. var html = parse_form($('#original').val());
  24. $.ajax({
  25. type: 'POST',
  26. url : 'cgformFtlController.do?parseUeditor',
  27. dataType : 'json',
  28. data : {'action' :'edit','parseForm':html},
  29. success : function(msg){
  30. if(msg.success){
  31. //update-begin--Author:jg_renjie Date:20150706 for:更改解析参数的方式
  32. var d = msg.msg;
  33. if(d != null && d != ''){
  34. $('#preview').html(msg.msg.replace(new RegExp(/(&quot;)/g),"'"));
  35. }
  36. //update-end--Author:jg_renjie Date:20150706 for:更改解析参数的方式
  37. }else{
  38. tip(msg.msg);
  39. }
  40. }
  41. });
  42. });
  43. //update-begin--Author:jg_renjie Date:20150706 for:更新parse_form,与官网同步
  44. function parse_form(template,fields)
  45. {
  46. //正则 radios|checkboxs|select 匹配的边界 |--| 因为当使用 {} 时js报错 (plugins|fieldname|fieldflow)
  47. var preg = /(\|-<span(((?!<span).)*plugins=\"(radios|checkboxs|select)\".*?)>(.*?)<\/span>-\||<(img|input|textarea|select).*?(<\/select>|<\/textarea>|\/>))/gi,preg_attr =/(\w+)=\"(.?|.+?)\"/gi,preg_group =/<input.*?\/>/gi;
  48. if(!fields) fields = 0;
  49. var template_parse = template,template_data = new Array(),add_fields=new Object(),checkboxs=0;
  50. var pno = 0;
  51. template.replace(preg, function(plugin,p1,p2,p3,p4,p5,p6){
  52. var parse_attr = new Array(),attr_arr_all = new Object(),name = '', select_dot = '' , is_new=false;
  53. var p0 = plugin;
  54. var tag = p6 ? p6 : p4;
  55. //alert(tag + " \n- t1 - "+p1 +" \n-2- " +p2+" \n-3- " +p3+" \n-4- " +p4+" \n-5- " +p5+" \n-6- " +p6);
  56. if(tag == 'radios' || tag == 'checkboxs')
  57. {
  58. plugin = p2;
  59. }else if(tag == 'select')
  60. {
  61. plugin = plugin.replace('|-','');
  62. plugin = plugin.replace('-|','');
  63. }
  64. plugin.replace(preg_attr, function(str0,attr,val) {
  65. if(attr=='name')
  66. {
  67. if(val=='NEWFIELD')
  68. {
  69. is_new=true;
  70. fields++;
  71. val = 'data_'+fields;
  72. }
  73. name = val;
  74. }
  75. if(tag=='select' && attr=='value')
  76. {
  77. if(!attr_arr_all[attr]) attr_arr_all[attr] = '';
  78. attr_arr_all[attr] += select_dot + val;
  79. select_dot = ',';
  80. }else
  81. {
  82. attr_arr_all[attr] = val;
  83. }
  84. var oField = new Object();
  85. oField[attr] = val;
  86. parse_attr.push(oField);
  87. })
  88. /*alert(JSON.stringify(parse_attr));return;*/
  89. if(tag =='checkboxs') /*复选组 多个字段 */
  90. {
  91. plugin = p0;
  92. plugin = plugin.replace('|-','');
  93. plugin = plugin.replace('-|','');
  94. var name = 'checkboxs_'+checkboxs;
  95. attr_arr_all['parse_name'] = name;
  96. attr_arr_all['name'] = '';
  97. attr_arr_all['value'] = '';
  98. attr_arr_all['content'] = '<span plugins="checkboxs" title="'+attr_arr_all['title']+'">';
  99. var dot_name ='', dot_value = '';
  100. p5.replace(preg_group, function(parse_group) {
  101. var is_new=false,option = new Object();
  102. parse_group.replace(preg_attr, function(str0,k,val) {
  103. if(k=='name')
  104. {
  105. if(val=='NEWFIELD')
  106. {
  107. is_new=true;
  108. fields++;
  109. val = 'data_'+fields;
  110. }
  111. attr_arr_all['name'] += dot_name + val;
  112. dot_name = ',';
  113. }
  114. else if(k=='value')
  115. {
  116. attr_arr_all['value'] += dot_value + val;
  117. dot_value = ',';
  118. }
  119. option[k] = val;
  120. });
  121. if(!attr_arr_all['options']) attr_arr_all['options'] = new Array();
  122. attr_arr_all['options'].push(option);
  123. if(!option['checked']) option['checked'] = '';
  124. var checked = option['checked'] ? 'checked="checked"' : '';
  125. attr_arr_all['content'] +='<input type="checkbox" name="'+option['name']+'" value="'+option['value']+'" fieldname="' + attr_arr_all['fieldname'] + option['fieldname'] + '" fieldflow="' + attr_arr_all['fieldflow'] + '" '+checked+'/>'+option['value']+'&nbsp;';
  126. if(is_new)
  127. {
  128. var arr = new Object();
  129. arr['name'] = option['name'];
  130. arr['plugins'] = attr_arr_all['plugins'];
  131. arr['fieldname'] = attr_arr_all['fieldname'] + option['fieldname'];
  132. arr['fieldflow'] = attr_arr_all['fieldflow'];
  133. add_fields[option['name']] = arr;
  134. }
  135. });
  136. attr_arr_all['content'] += '</span>';
  137. //parse
  138. template = template.replace(plugin,attr_arr_all['content']);
  139. template_parse = template_parse.replace(plugin,'{'+name+'}');
  140. template_parse = template_parse.replace('{|-','');
  141. template_parse = template_parse.replace('-|}','');
  142. template_data[pno] = attr_arr_all;
  143. checkboxs++;
  144. }else if(name)
  145. {
  146. if(tag =='radios') /*单选组 一个字段*/
  147. {
  148. plugin = p0;
  149. plugin = plugin.replace('|-','');
  150. plugin = plugin.replace('-|','');
  151. attr_arr_all['value'] = '';
  152. attr_arr_all['content'] = '<span plugins="radios" name="'+attr_arr_all['name']+'" title="'+attr_arr_all['title']+'">';
  153. var dot='';
  154. p5.replace(preg_group, function(parse_group) {
  155. var option = new Object();
  156. parse_group.replace(preg_attr, function(str0,k,val) {
  157. if(k=='value')
  158. {
  159. attr_arr_all['value'] += dot + val;
  160. dot = ',';
  161. }
  162. option[k] = val;
  163. });
  164. option['name'] = attr_arr_all['name'];
  165. if(!attr_arr_all['options']) attr_arr_all['options'] = new Array();
  166. attr_arr_all['options'].push(option);
  167. if(!option['checked']) option['checked'] = '';
  168. var checked = option['checked'] ? 'checked="checked"' : '';
  169. attr_arr_all['content'] +='<input type="radio" name="'+attr_arr_all['name']+'" value="'+option['value']+'" '+checked+'/>'+option['value']+'&nbsp;';
  170. });
  171. attr_arr_all['content'] += '</span>';
  172. }else
  173. {
  174. attr_arr_all['content'] = is_new ? plugin.replace(/NEWFIELD/,name) : plugin;
  175. }
  176. //attr_arr_all['itemid'] = fields;
  177. //attr_arr_all['tag'] = tag;
  178. template = template.replace(plugin,attr_arr_all['content']);
  179. template_parse = template_parse.replace(plugin,'{'+name+'}');
  180. template_parse = template_parse.replace('{|-','');
  181. template_parse = template_parse.replace('-|}','');
  182. if(is_new)
  183. {
  184. var arr = new Object();
  185. arr['name'] = name;
  186. arr['plugins'] = attr_arr_all['plugins'];
  187. arr['title'] = attr_arr_all['title'];
  188. arr['orgtype'] = attr_arr_all['orgtype'];
  189. arr['fieldname'] = attr_arr_all['fieldname'];
  190. arr['fieldflow'] = attr_arr_all['fieldflow'];
  191. add_fields[arr['name']] = arr;
  192. }
  193. template_data[pno] = attr_arr_all;
  194. }
  195. pno++;
  196. })
  197. var view = template.replace(/{\|-/g,'');
  198. view = view.replace(/-\|}/g,'');
  199. var parse_form = new Object({
  200. 'fields':fields,//总字段数
  201. 'template':template,//完整html
  202. 'parse':view,
  203. 'data':template_data,//控件属性
  204. 'add_fields':add_fields//新增控件
  205. });
  206. return JSON.stringify(parse_form);
  207. //update-end--Author:jg_renjie Date:20150706 for:更新parse_form,与官网同步
  208. }</script></body>
  209. </html>