sysWordTemplateEdit.jsp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <%--
  2. time:2011-11-16 16:34:16
  3. --%>
  4. <%@page language="java" pageEncoding="UTF-8"%>
  5. <%@include file="/commons/include/html_doctype.html"%>
  6. <html>
  7. <head>
  8. <title>编辑WORD表单模板</title>
  9. <%@include file="/commons/include/form.jsp"%>
  10. <script type="text/javascript" src="${ctx}/js/util/json2.js"></script>
  11. <script type="text/javascript" src="${ctx}/js/hotent/CustomValid.js"></script>
  12. <script type="text/javascript" src="${ctx}/js/hotent/platform/form/FormTableDialog.js"></script>
  13. <script type="text/javascript">
  14. $(function() {
  15. $('#frmWorkFlow').ajaxForm({success:showResponse });
  16. $('#btnAdd').click(function(){
  17. var subSql = $('#subTableTemplate').find('tr').clone();
  18. $('#sqlTable').append(subSql);
  19. });
  20. $('#sqlTable').delegate('.delSubTableSql', 'click', function(){
  21. $(this).closest('tr').remove();
  22. });
  23. initSqlArea();
  24. $('#type').change(function(){
  25. typeChange();
  26. });
  27. typeChange();
  28. });
  29. function initSqlArea(){
  30. var sqlJson = "${sysWordTemplate.sql}";
  31. if(!sqlJson) return;
  32. sqlJson = $.parseJSON(sqlJson);
  33. $('#main').val(sqlJson.main);
  34. var subTable = sqlJson.subTable;
  35. for(var key in subTable){
  36. $('#btnAdd').trigger('click');
  37. var sub = $('#sqlTable').find('tr.subTableSqlTr:last');
  38. sub.find('.subTableName').val(key);
  39. sub.find('.subTableSql').val(subTable[key]);
  40. }
  41. }
  42. function typeChange(obj){
  43. var value = $('#type').val();
  44. if(!value || value=='0'){
  45. $('.sqlOption').hide();
  46. $('.formOption').show();
  47. }else {
  48. $('.sqlOption').show();
  49. $('.formOption').hide();
  50. }
  51. }
  52. function showResponse(responseText){
  53. var obj=new com.hotent.form.ResultMessage(responseText);
  54. if(obj.isSuccess()){
  55. var id = obj.getMessage();
  56. $('#id').val(id);
  57. if(isNext) {
  58. var url = 'editTemplate.ht?id='+id;
  59. window.location.href = url.getNewUrl();
  60. }else {
  61. $.ligerDialog.confirm("保存成功,是否继续操作", "提示信息", function(rtn) {
  62. if (!rtn) {
  63. window.opener.location.reload();
  64. window.close();
  65. }
  66. });
  67. }
  68. }else{
  69. $.ligerDialog.error(obj.getMessage(), '出错信息');
  70. $.ligerDialog.err("提示信息","WORD模版保存失败!",obj.getMessage());
  71. }
  72. }
  73. var isNext = false;// 是否是下一步,在showResponse中使用
  74. function submitData(isDoNext) {
  75. var type = $('#type').val();
  76. var valid = $("#frmWorkFlow").form().valid();
  77. if(!valid) return false;
  78. if(setSqlField(type)===true){
  79. $.ligerDialog.warn("SQL别名重复!");
  80. return false;
  81. }
  82. setSqlField(type);
  83. isNext = isDoNext;
  84. $('#frmWorkFlow').submit();
  85. }
  86. // 如果的SQL类型,则将SQL拼装成JSON放到表单的隐藏字段中
  87. function setSqlField(type){
  88. if(type!='1') return '';
  89. var sqlObj = {};
  90. var subTable = {};
  91. var subTableNameList = [];//SQL别名数组
  92. var isRepeat = false;//SQL别名是否重复
  93. var i = 0;
  94. var main = $('#main').val();
  95. if($.isEmpty(main)) return '';
  96. sqlObj.main = main;
  97. $('#sqlTable .subTableSqlTr').each(function(){
  98. var subTableName = $(this).find('.subTableName').val();
  99. subTableNameList[i++] = subTableName;
  100. var subSql = $(this).find('.subTableSql').val();
  101. subTable[subTableName] = subSql ;
  102. });
  103. //判断SQL别名是否重复
  104. for(var j = 0 ; j<=subTableNameList.length-2;j++){
  105. for(var k = j+1;k<=subTableNameList.length-1;k++){
  106. if(subTableNameList[j]==subTableNameList[k]){//存在重复别名
  107. isRepeat = true;
  108. }
  109. }
  110. }
  111. if(isRepeat){
  112. return isRepeat;
  113. }else{
  114. sqlObj.subTable = subTable;
  115. var subTableSql = JSON2.stringify(sqlObj);
  116. $('#sql').val(subTableSql);
  117. return subTableSql;
  118. }
  119. }
  120. function resetTable(){
  121. $("#tableId").val('');
  122. $("#tableName").val('');
  123. };
  124. function selectTable(){
  125. var callBack=function(tableId,tableName){
  126. $("#tableId").val(tableId);
  127. $("#tableName").val(tableName);
  128. }
  129. FormTableDialog({callBack:callBack});
  130. }
  131. </script>
  132. </head>
  133. <body >
  134. <div>
  135. <div class="tbar-title">
  136. <span class="tbar-label">在线表单编辑</span>
  137. </div>
  138. <div class="panel-toolbar">
  139. <div class="toolBar">
  140. <div class="group">
  141. <a class="link save" id="dataFormSave" href="javascript:;" onclick="submitData();"><span></span>保存</a>
  142. </div>
  143. <c:if test="${not empty sysWordTemplate.fileId}">
  144. <div class="l-bar-separator"></div>
  145. <div class="group">
  146. <a class="link preview" id="btnPreView" href="javascript:;" onclick="preview('${sysWordTemplate.alias}');"><span></span>预览</a>
  147. </div>
  148. </c:if>
  149. <div class="l-bar-separator"></div>
  150. <div class="group">
  151. <a class="link del" href="javascript:window.onbeforeunload = null;window.close()"><span></span>关闭</a>
  152. </div>
  153. <div class="l-bar-separator"></div>
  154. <div class="group">
  155. <a class="link run" href="javascript:;" onclick="submitData(true);"><span></span>下一步</a>
  156. </div>
  157. <a href="javascript:;" class="tipinfo"><span>编写SQL时,可以使用__PK__代替业务主键;<br>SQL中的别名,可以是字母下划线的组合,并且需要确保在当前记录中是唯一的。</span></a>
  158. </div>
  159. </div>
  160. </div>
  161. <div class="panel-body">
  162. <form id="frmWorkFlow" method="post" action="save.ht">
  163. <input id="id" type="hidden" name="id" value="${sysWordTemplate.id}" />
  164. <input id="fileId" type="hidden" name="fileId" value="${sysWordTemplate.fileId}" />
  165. <div class="panel-nav">
  166. <table cellpadding="0" cellspacing="0" border="0" class="table-detail">
  167. <tr>
  168. <th width="200px">名称:&nbsp;</th>
  169. <td><input id="name" type="text" name="name" validate="{required:true}" value="${sysWordTemplate.name}" class="inputText"/></td>
  170. </tr>
  171. <tr>
  172. <th>别名:&nbsp;</th>
  173. <td><input id="alias" type="text" name="alias" validate="{required:true}" value="${sysWordTemplate.alias}" class="inputText"/></td>
  174. </tr>
  175. <tr>
  176. <th>类型:&nbsp;</th>
  177. <td>
  178. <select name="type" id="type" class="inputText">
  179. <option value="0" <c:if test="${sysWordTemplate.type == 0}">selected="selected"</c:if>>自定义表</option>
  180. <option value="1" <c:if test="${sysWordTemplate.type == 1}">selected="selected"</c:if>>SQL</option>
  181. </select>
  182. <textarea style="display: none;" id="sql" name="sql">${sysWordTemplate.sql}</textarea>
  183. </td>
  184. </tr>
  185. <tr class="formOption">
  186. <th>表:&nbsp;</th>
  187. <td>
  188. <input type="text" id="tableName" class="inputText" name="tableName" value="${sysWordTemplate.tableName}" readonly="readonly">
  189. <input type="hidden" id="tableId" name="tableId" value="${sysWordTemplate.tableId}" validate="{required:true}">
  190. <a href='#' class='link search' onclick="selectTable()" ></a>
  191. <a href='#' class='link redo' style='margin-left:10px;' onclick="resetTable()"><span>重选</span></a>
  192. </td>
  193. </tr>
  194. <tr class="sqlOption">
  195. <th>数据源别名:&nbsp;</th>
  196. <td>
  197. <select name="dsAlias" id="dsAlias" class="inputText">
  198. <option value="LOCAL">本地数据源</option>
  199. <c:forEach items="${dsList}" var="ds">
  200. <option value="${ds.alias}" <c:if test="${sysWordTemplate.dsAlias eq ds.alias}">selected="selected"</c:if>>${ds.name}</option>
  201. </c:forEach>
  202. </select>
  203. </td>
  204. </tr>
  205. <tr class="sqlOption">
  206. <th>SQL:&nbsp;</th>
  207. <td>
  208. <div class="panel-toolbar">
  209. <div class="toolBar">
  210. <div class="group">
  211. <a id="btnAdd" class="link add"><span></span>添加</a>
  212. </div>
  213. </div>
  214. </div>
  215. <table cellpadding="0" cellspacing="0" border="0" class="table-detail" id="sqlTable">
  216. <tr>
  217. <th style="text-align: left;padding-left: 5px;width:120px;">别名:</th>
  218. <th style="text-align: left;padding-left: 10px;">SQL语句</th>
  219. <th style="text-align: center;width:65px;">操作</th>
  220. </tr>
  221. <tr>
  222. <td>main</td>
  223. <td><textarea style="width:99%;height:100px;" id="main" validate="{required:true}"></textarea></td>
  224. <td></td>
  225. </tr>
  226. </table>
  227. </td>
  228. </tr>
  229. </table>
  230. </div>
  231. </form>
  232. </div>
  233. <table class="hidden" id="subTableTemplate">
  234. <tr class="subTableSqlTr">
  235. <td><input type="text" class="inputText subTableName" validate="{required:true,variable:true}" value=""></td>
  236. <td><textarea style="width:99%;height:100px;" class="subTableSql" validate="{required:true}"></textarea></td>
  237. <td><a id="btnDel" class="link del delSubTableSql"><span></span>删除</a></td>
  238. </tr>
  239. </table>
  240. <jsp:include page="sysWordTemplateInc.jsp"></jsp:include>
  241. </body>
  242. </html>