dialog.jsp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <%@page language="java" pageEncoding="UTF-8"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title></title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <%@include file="/commons/include/form.jsp"%>
  8. <link rel="stylesheet" type="text/css" href="../input.css">
  9. <script type="text/javascript" src="${ctx}/js/ueditor2/dialogs/internal.js"></script>
  10. <script type="text/javascript" src="${ctx}/js/jquery/plugins/jquery.dragdiv.js"></script>
  11. <link rel="stylesheet" href="${ctx}/js/jquery/plugins/jquery.dragdiv.css" type="text/css" />
  12. <link rel="stylesheet" href="${ctx}/js/tree/zTreeStyle.css" type="text/css" />
  13. <script type="text/javascript" src="${ctx}/js/tree/jquery.ztree.js"></script>
  14. <script type="text/javascript" src="${ctx}/js/util/easyTemplate.js"></script>
  15. <script type="text/javascript" src="${ctx}/js/util/json2.js"></script>
  16. <style type="text/css">
  17. .field-ul {
  18. width: 95%;
  19. height: 95%;
  20. margin: 0;
  21. padding: 0;
  22. overflow-y: auto;
  23. overflow-x: hidden;
  24. }
  25. .fields-div {
  26. float: left;
  27. border: 1px solid #828790;
  28. width: 160px;
  29. height: 260px;
  30. overflow: auto;
  31. }
  32. .domBtnDiv {
  33. display: block;
  34. margin-left: 5px;
  35. float: left;
  36. width: 380px;
  37. height: 260px;
  38. background-color: powderblue;
  39. overflow-y: auto;
  40. overflow-x: hidden;
  41. }
  42. #fieldContainer{
  43. height:70px;
  44. overflow-y:auto;
  45. overflow-x:hidden;
  46. }
  47. #fieldTable{
  48. margin:0;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <div id="inputPanel">
  54. <fieldset class="base">
  55. <legend>
  56. 查询设置
  57. </legend>
  58. <table width="90%">
  59. <tr>
  60. <th>查询类型:</th>
  61. <td colspan="2">
  62. <select id="query-type">
  63. <option value="0">--请选择--</option>
  64. <option value="querybtn">自定义查询</option>
  65. <option value="aliasbtn">别名脚本</option>
  66. </select>
  67. </td>
  68. </tr>
  69. <tr>
  70. <th>选择查询:</th>
  71. <td colspan="2">
  72. <select id="dialog-type" onchange="dialogChange()">
  73. <option value="0"></option>
  74. </select>
  75. </td>
  76. </tr>
  77. <tr>
  78. <th>选择子表:</th>
  79. <td>
  80. <select id="table-type">
  81. </select>
  82. </td>
  83. <td>&nbsp;</td>
  84. </tr>
  85. <tr>
  86. <td colspan="3">
  87. <div id="fieldContainer">
  88. <table id="fieldTable" width="90%">
  89. </table>
  90. </div>
  91. </td>
  92. </tr>
  93. </table>
  94. </fieldset>
  95. <fieldset class="base">
  96. <legend>
  97. 回填值设置
  98. </legend>
  99. <div class="fields-div">
  100. <ul id="fields-tree" class="ztree field-ul"></ul>
  101. </div>
  102. <div class="domBtnDiv"></div>
  103. </fieldset>
  104. </div>
  105. <textarea id="templateTr" style="display:none;">
  106. <#list data as a>
  107. <tr class="fieldTr">
  108. <td >
  109. <input type="checkbox" style="width:10%;float:left;" class="fieldCheck" />
  110. <!-- 条件字段 -->
  111. <input type="text" class="conditionField" style="width:25%;float:left;margin-right: 5px;" value="\${a.field}" readonly id="\${a.field}"/>
  112. <div class="fielddiv" style="display:none;">
  113. <select class="fieldSelect" style="width:30%;margin-right: 5px;">
  114. <option value="-1" controlType="-1" >--请选择--</option>
  115. </select>
  116. <input type="text" class="fieldValue" style="width:25%" value="--预设值--" onfocus="if (value==defaultValue)value=''" onblur="if(!value)value=defaultValue"/>
  117. </div>
  118. </td>
  119. </tr>
  120. </#list>
  121. </textarea>
  122. <textarea id="subtableTemplateOption" style="display:none;">
  123. <#list data as o>
  124. <option value="\${o.tableName}">\${o.tableDesc}</option>
  125. </#list>
  126. </textarea>
  127. </body>
  128. <script type="text/javascript">
  129. var obj = $(editor.curInput);
  130. var curNode = obj;
  131. var parent = obj.parent();
  132. var bodyObj=obj.parents('body');
  133. if(!curNode.is('select'))
  134. curNode=parent;
  135. var dragDiv;
  136. var selectOpt=[];
  137. var setting = {
  138. edit : {
  139. enable : true,
  140. showRemoveBtn : false,
  141. showRenameBtn : false,
  142. drag : {}
  143. },
  144. data : {
  145. keep : {
  146. parent : true,
  147. leaf : true
  148. },
  149. simpleData : {
  150. enable : true
  151. }
  152. },
  153. view : {
  154. selectedMulti : false
  155. }
  156. };
  157. $(function() {
  158. $('#query-type').change(function(){
  159. var type = $(this).val();
  160. getDialogs(type);
  161. });
  162. type = $(editor.curInput).get(0).getAttribute('queryType');
  163. if(type){
  164. $('#query-type').val(type);
  165. $('#query-type').trigger('change');
  166. }
  167. $('.fieldCheck','.fieldTr').live("click",function(){
  168. $(this).siblings('.fielddiv').each(function(){
  169. if($(this).css('display')!='none'){
  170. $(this).hide() ;
  171. }else{
  172. $(this).show() ;
  173. }
  174. });
  175. });
  176. });
  177. //编辑时绑定数据
  178. function bindData(dialogStr) {
  179. var dialogObj=dialogStr.replaceAll("'","\"");
  180. var dialog = $.parseJSON(dialogObj);
  181. if (!dialog) return;
  182. $("#dialog-type").find("option[value='" + dialog.name + "']").each(function() {
  183. $(this).attr("selected", "selected");
  184. dialogChange();
  185. });
  186. while(field=dialog.fields.pop()){
  187. var src=field.src,
  188. targets=field.target,target;
  189. while(target=targets.pop()){
  190. var item = $("span.item-span[itemId='"+target+"']").toggleClass("item-span item-span-Disabled");
  191. if(item.length>0){
  192. var node = {id:target, name: item.text()};
  193. addNode(src,node);
  194. }
  195. }
  196. }
  197. var dialogQueryArr = dialog.query;
  198. if(dialogQueryArr && dialogQueryArr.length>0){
  199. for(var i=0;i<dialogQueryArr.length;i++){
  200. var dialogQueryObj = dialogQueryArr[i];
  201. var isMain = dialogQueryObj.isMain ;
  202. $(":text#"+dialogQueryObj.condition,".fieldTr").each(function(){
  203. $(this).siblings(".fieldCheck").click() ;
  204. $(this).siblings('div.fielddiv').children('select').find("option[value='"+dialogQueryObj.trigger+"']").each(function(){
  205. var self = $(this);
  206. self.attr("selected","selected");
  207. var value = self.val();
  208. });
  209. if(dialogQueryObj.initValue!=''){
  210. $(this).siblings('div.fielddiv').children(':text').val(dialogQueryObj.initValue);
  211. }else{
  212. $(this).siblings('div.fielddiv').children(':text').val("--预设值--");
  213. }
  214. });
  215. }
  216. }
  217. var subtableName = dialog.subtableName;
  218. if(subtableName) $('#table-type').val(subtableName);
  219. };
  220. //添加树节点
  221. function addNode(id, node) {
  222. var zTree = $.fn.zTree.getZTreeObj('fields-tree');
  223. if (!zTree)
  224. return;
  225. var parentNode = zTree.getNodeByParam("id", id, null);
  226. if (parentNode)
  227. zTree.addNodes(parentNode, node);
  228. };
  229. //获取自定义查询
  230. var queryCache = {};
  231. function getDialogs(type) {
  232. var cache = queryCache[type];
  233. $("#dialog-type").empty();
  234. $("#dialog-type").append('<option value="0">--请选择--</option>');
  235. if(cache){
  236. for(var i=0;i<cache.length;i++){
  237. $("#dialog-type").append(cache[i]);
  238. }
  239. $("#dialog-type").trigger('change');
  240. return;
  241. }else {
  242. cache = [];
  243. }
  244. var url = '';
  245. if(type == 'querybtn'){
  246. url = '/platform/bpm/bpmFormQuery/getAllQueries.ht';
  247. }else if(type == 'aliasbtn'){
  248. url = '/platform/system/aliasScript/getAllAliasScripts.ht?enable=0&isReturnValue=1&scriptType=default';
  249. }
  250. if(!url) return;
  251. $.get(__ctx + url,function(data) {
  252. if (!data) return;
  253. if(type == 'querybtn'){
  254. for ( var i = 0, c; c = data[i++];) {
  255. var opt = $('<option value="'+c.alias+'" fields="'+c.returnFields
  256. +'" istable="'+c.istable+'" objname="'+c.objname+'" dsname="'+c.dsalias+'" >'+ c.name + '</option>');
  257. opt.attr("resultfield", c.resultfield.replaceAll('\"', "'"));
  258. opt.attr("conditionfield",c.conditionfield.replaceAll('\"', "'"));
  259. $("#dialog-type").append(opt);
  260. cache.push(opt);
  261. }
  262. }else if(type == 'aliasbtn'){
  263. for ( var i = 0, c; c = data[i++];) {
  264. var opt = $('<option value="'+c.aliasName+'" fields="'+c.returnFields
  265. +'">'+ c.aliasDesc + '</option>');
  266. var argument = c.argument;
  267. if(!argument) argument = '{}';
  268. var returnParamJson = c.returnParamJson;
  269. if(!returnParamJson) returnParamJson = '{}';
  270. opt.attr("conditionfield", argument.replaceAll('\"', "'"));
  271. opt.attr("resultfield",returnParamJson.replaceAll('\"', "'"));
  272. $("#dialog-type").append(opt);
  273. cache.push(opt);
  274. }
  275. }
  276. if(utils.isEmptyObject(queryCache)) getFileds(editor.tableId);
  277. queryCache[type] = cache;
  278. });
  279. };
  280. //选择不同的查询
  281. function dialogChange() {
  282. var condition_field = $("#condition-field");
  283. condition_field.empty();
  284. var dia = $("#dialog-type").find(":selected");
  285. var v = dia.attr("resultfield");
  286. var condStr = dia.attr("conditionfield");
  287. var type = $("#query-type").val();
  288. if (v) {
  289. var nodes = [];
  290. var fields = eval("("+v+")");
  291. var idName = 'field';
  292. var name = 'comment';
  293. if(type == 'aliasbtn'){
  294. idName = 'fieldName';
  295. name = 'fieldDesc';
  296. }
  297. for ( var i = 0; i < fields.length; i++) {
  298. var f = fields[i];
  299. nodes.push({
  300. id : f[idName],
  301. pid : 0,
  302. name : f[name],
  303. isParent : true,
  304. open : true
  305. });
  306. }
  307. $("span.item-span-Disabled").each(function() {
  308. $(this).toggleClass("item-span-Disabled");
  309. $(this).toggleClass("item-span");
  310. });
  311. var tree = $.fn.zTree.init($("#fields-tree"), setting, nodes);
  312. //设置拖拽 树对象
  313. if (dragDiv)
  314. dragDiv.dragdiv('bind', 'fields-tree');
  315. }
  316. if (condStr) {
  317. $('#fieldTable').empty();
  318. var jsonObj = eval("("+condStr+")"), html="";
  319. var conditionfield= [];
  320. for(var i=0; i<jsonObj.length;i++){
  321. var obj = jsonObj[i];
  322. if(obj.defaultType=="1"){
  323. conditionfield.push(obj);
  324. }else if(type == 'aliasbtn'){
  325. obj.field = obj.paraName;
  326. conditionfield.push(obj);
  327. }
  328. }
  329. //对于值是输入框的,生成“绑定参数”下拉框选项
  330. if(typeof(conditionfield)!="undefined" && conditionfield!=""){
  331. var template = $('textarea#templateTr').val() ;
  332. var templateTrHtml = easyTemplate(template,conditionfield).toString();
  333. $('#fieldTable').append(templateTrHtml);
  334. if(selectOpt.length!=0){
  335. for(var j=0;j<selectOpt.length;j++){
  336. $('#inputPanel table').find('.fieldSelect').append(selectOpt[j]);
  337. }
  338. }
  339. }
  340. }
  341. }
  342. dialog.onok = function() {
  343. var name = $("#dialog-type").val();
  344. var queryType = $('#query-type').val();
  345. if (!name) {
  346. curNode.removeAttr("querybtn");
  347. curNode.removeAttr("aliasbtn");
  348. curNode.removeAttr("dialog");
  349. return;
  350. };
  351. var zTree = $.fn.zTree.getZTreeObj("fields-tree"),
  352. nodes = zTree.getNodes(),fields=[];
  353. for(var i=0,c;c=nodes[i++];){
  354. if(!c.children)continue;
  355. var target=[],child=null;
  356. while(child=c.children.pop()){
  357. target.push(child.id);
  358. }
  359. if(target.length>0){
  360. var sub = {};
  361. sub.src = c.id;
  362. sub.target = target;
  363. }
  364. fields.push(sub);
  365. }
  366. //处理类型是输入框
  367. var queryArr = [] ;
  368. $(':checkbox:checked','table .fieldTr').each(function(){
  369. var queryObj = {} ;
  370. queryObj.condition = $(this).siblings(':text').attr('id') ;
  371. var selectobj=$(this).siblings('div.fielddiv').children('select').find(":selected");
  372. queryObj.trigger = selectobj.val();
  373. var controlType=selectobj.attr('controlType');
  374. queryObj.controlType=controlType;
  375. queryObj.isMain = selectobj.attr('isMain') ;
  376. var initvalue=$(this).siblings('div.fielddiv').children(':text').val();
  377. if(initvalue=="--预设值--"){
  378. initvalue="";
  379. }
  380. queryObj.initValue=initvalue;
  381. queryArr.push(queryObj);
  382. });
  383. var json={
  384. name:name,
  385. query:queryArr,
  386. fields:fields};
  387. json.subtableName = $('#table-type').val();
  388. var json2 = JSON2.stringify(json).replaceAll("\"","'") ;
  389. editor.curInput.setAttribute(queryType,json2);
  390. editor.curInput.setAttribute('queryType',queryType);
  391. editor.curInput = null;
  392. };
  393. //初始化字段面板
  394. function initFieldsDiv(data) {
  395. var mainTable = data.table, data = {};
  396. data.name = mainTable.tableDesc + '('+editor.getLang("customdialog.main")+')';
  397. data.id = mainTable.tableName;
  398. data.desc = mainTable.tableId;
  399. var formMainField=mainTable.tableName?$(bodyObj).find('[name*="'+mainTable.tableName+'"]'):[];
  400. var items = [];
  401. for ( var i = 0, c; c = mainTable.fieldList[i++];) {
  402. //判断当前字段是否在表单上显示,如果存在这显示,
  403. if(formMainField.length != 0 && removeObj(formMainField,c.fieldName))continue;
  404. var type=c.controlType;
  405. items.push({
  406. name : c.fieldDesc,
  407. id : c.fieldName,
  408. ctype : type
  409. });
  410. }
  411. //生成“绑定参数”行
  412. var opt;
  413. if(items){
  414. opt = '<optgroup label="主表字段"></optgroup>';
  415. selectOpt.push(opt);
  416. for(var i=0, c;c=items[i++];){
  417. opt='<option value="'+c.id+'" controlType="'+c.ctype+'" ismain=true >' + c.name+ '</option>';
  418. selectOpt.push(opt);
  419. }
  420. }
  421. var allSubItems = [];
  422. for ( var i = 0, c; c = mainTable.subTableList[i++];) {
  423. var sub = {};
  424. sub.name = c.tableDesc + '('+editor.getLang("customdialog.sub")+')';
  425. sub.id = c.tableName;
  426. sub.desc = c.tableId;
  427. var currSubField=$(bodyObj).find('[name*="'+c.tableName+'"]');
  428. var subItems = [];
  429. for ( var y = 0, t; t = c.fieldList[y++];) {
  430. //判断当前字段是否在表单上显示,如果存在这显示,不存在这不显示
  431. if(formMainField.length != 0 && removeObj(currSubField,t.fieldName))continue;
  432. var type=t.controlType;
  433. subItems.push({
  434. name : t.fieldDesc,
  435. id : t.fieldName,
  436. ctype : type
  437. });
  438. }
  439. sub.items = subItems;
  440. items.push(sub);
  441. allSubItems = allSubItems.concat(subItems);
  442. }
  443. //生成“绑定子表”行
  444. if($('#table-type').children().length>0) return;
  445. if($('#table-type').children().length<1) {
  446. template = $('#subtableTemplateOption').val() ;
  447. templateTrHtml = easyTemplate(template,mainTable.subTableList).toString();
  448. $('#table-type').append(templateTrHtml);
  449. }
  450. var parentTableClass = $(editor.curInput).closest('div[type="subtable"]') ;
  451. if(!parentTableClass || parentTableClass.length>0){
  452. //若为空,表示主表,则隐藏子表字段
  453. opt = '<optgroup label="子表字段"></optgroup>';
  454. selectOpt.push(opt);
  455. for(var i=0, c;c=allSubItems[i++];){
  456. opt='<option value="'+c.id+'" controlType="'+c.ctype+'" ismain=false >' + c.name+ '</option>';
  457. selectOpt.push(opt);
  458. }
  459. }
  460. data.items = items;
  461. //初始化字段面板
  462. dragDiv = $(".domBtnDiv").dragdiv('init',{data : data});
  463. var queryType = $('#query-type').val();
  464. var dialogStr = $(editor.curInput).get(0).getAttribute(queryType);
  465. if (dialogStr) {
  466. bindData(dialogStr);
  467. }
  468. };
  469. //加载字段面板
  470. function getFileds(tableId) {
  471. if (tableId) {
  472. var url = __ctx
  473. + '/platform/form/bpmFormTable/getTableById.ht';
  474. $.post(url, {incHide:true,tableId:tableId}, function(data) {
  475. initFieldsDiv(data);
  476. });
  477. } else { //编辑器设计表单时获取字段并验证字段
  478. var html = editor.getContent();
  479. var params = {};
  480. params.html = html;
  481. params.formDefId = editor.formDefId;
  482. params.incHide = true;
  483. $.post(__ctx + '/platform/form/bpmFormDef/validDesign.ht', params,
  484. function(data) {
  485. if (data.valid) {
  486. initFieldsDiv(data);
  487. } else {
  488. alert(data.errorMsg);
  489. }
  490. });
  491. }
  492. };
  493. //判断当前字段是否在表单上显示,如果存在这显示,不存在这不显示
  494. function removeObj(obj,id){
  495. //当前表单所有字段
  496. var AllField=$(obj);
  497. for( var i=0 ;i<AllField.length; i++){
  498. var formName=$(AllField[i]).attr("name");
  499. if(!formName)continue;
  500. var name=formName.split(":");
  501. if(name[2]==fieldName){
  502. return false;
  503. }else{
  504. continue;
  505. }
  506. }
  507. return true;
  508. }
  509. </script>
  510. </html>