BusQueryRuleEdit.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /**
  2. * 数据模板构造方法
  3. */
  4. var BusQueryRuleEdit = function() {
  5. }
  6. // 属性及函数
  7. BusQueryRuleEdit.prototype = {
  8. /**
  9. * 初始化
  10. */
  11. init : function() {
  12. var _self = this;
  13. this.initDisplaySetting();
  14. this.initSortField();
  15. this.initFilter();
  16. // this.initExportField();
  17. this.selectTr();
  18. // 绑定选择排序点击事件
  19. $("#selectSort").click(function() {
  20. _self.selectSort(_self)
  21. });
  22. },
  23. initDisplaySetting : function() {
  24. var tbl = '#displayFieldTbl';
  25. // 处理选择
  26. this.handChange(tbl);
  27. this.handClick(tbl);
  28. var tr = $($("#displayFieldTemplate .table-detail")[0]).clone(true,
  29. true);
  30. var displayFieldVal = $("#displayField").val();
  31. if ($.isEmpty(displayFieldVal))
  32. return;
  33. var displayField = $.parseJSON(displayFieldVal);
  34. var sb = new StringBuffer(),
  35. fieldRightEl = $("[var='fieldRight']", tr),
  36. hideFieldRightEl = $('<td var="fieldRight" class="hidden"></td>');
  37. for (var i = 0, c; c = displayField[i++];) {
  38. $("[var='index']", tr).html(i);
  39. $("[var='name']", tr).html(c.name);
  40. $("input[var='variable']", tr).attr("value", c.variable);
  41. $("input[var='type']", tr).attr("value", c.type);
  42. $("input[var='style']", tr).attr("value", c.style);
  43. $("input[var='desc']", tr).attr("value", c.desc);
  44. for (var j = 0, k; k = c.right[j++];) {
  45. var rightHtml = this.getHtmlTd(k);
  46. if (k.s == 0) {
  47. if(!k.srid)
  48. fieldRightEl.html(rightHtml);
  49. else{
  50. hideFieldRightEl.html(rightHtml);
  51. fieldRightEl.after(hideFieldRightEl);
  52. }
  53. } else if (k.s == 1) {
  54. $("[var='printRight']", tr).html(rightHtml);
  55. }
  56. }
  57. sb.append(tr.html());
  58. }
  59. $(tbl).append(sb.toString());
  60. },
  61. /**
  62. * 设置每行的显示的权限
  63. *
  64. * @param v
  65. * 权限简称
  66. * @param full
  67. * 权限全称
  68. */
  69. getHtmlTd : function(k) {
  70. var v = k.type,
  71. rightId = k.id,
  72. rightName = k.name,
  73. rightScript = k.script,
  74. srid = k.srid||"",
  75. source = k.source?JSON.stringify(k.source).replaceAll("\"","\'"):"";
  76. if(rightScript||rightScript=="undefined")
  77. rightScript = "";
  78. var aryTd = [
  79. '<select name="displayFieldRight" class="change_right" var="right" >',
  80. '<option value="none" '
  81. + (v == 'none' ? 'selected="selected"' : '')
  82. + ' >无</option>',
  83. '<option value="everyone"'
  84. + (v == 'everyone' ? 'selected="selected"' : '')
  85. + '>所有人</option>',
  86. '<option value="user"'
  87. + (v == 'user' ? 'selected="selected"' : '')
  88. + '>用户</option>',
  89. '<option value="role"'
  90. + (v == 'role' ? 'selected="selected"' : '')
  91. + '>角色</option>',
  92. '<option value="org"'
  93. + (v == 'org' ? 'selected="selected"' : '')
  94. + '>组织</option>',
  95. '<option value="orgMgr"'
  96. + (v == 'orgMgr' ? 'selected="selected"' : '')
  97. + '>组织负责人</option>',
  98. '<option value="pos"'
  99. + (v == 'pos' ? 'selected="selected"' : '')
  100. + '>岗位</option>',
  101. '<option value="script"'
  102. + (v == 'script' ? 'selected="selected"' : '')
  103. + '>脚本</option>',
  104. '</select>',
  105. '<span name="displayFieldRight_span" '
  106. + (v == 'script' || v == 'none' || v == 'everyone'
  107. ? 'style="display: none;" '
  108. : '') + '>',
  109. '<input type="hidden" var="rightId" value="' + rightId + '">',
  110. '<textarea readonly="readonly" var="rightName" cols="40" rows="3">'
  111. + rightName + '</textarea>',
  112. '<a class="link-get" href="javascript:;"><span class="link-btn">选择</span></a>',
  113. '</span>',
  114. '<span class="displayFieldRight_script_span" '
  115. + (v != 'script' ? 'style="display: none;" ' : '')
  116. + '>',
  117. '<textarea cols="40" rows="3" var="rightScript" >'+ rightScript + '</textarea>',
  118. '<input type="hidden" var="srid" value="' + srid + '" />',
  119. '<input type="hidden" var="source" value=\"' + source + '\" />',
  120. '<a href="javascript:;" name="btnScript" class="link var" title="常用脚本" onclick="__DataTemplate__.selectScript(this,false)">常用脚本</a>',
  121. '</span>'];
  122. return aryTd.join('');
  123. },
  124. /**
  125. * 选中行或反选
  126. *
  127. * @return void
  128. */
  129. selectTr : function() {
  130. $("tr.odd,tr.even").each(function() {
  131. $(this).bind("mousedown", function(event) {
  132. if (event.target.tagName == "TD") {
  133. var strFilter = 'input:checkbox[class="pk"],input:radio[class="pk"]';
  134. var obj = $(this).find(strFilter);
  135. if (obj.length == 1) {
  136. var state = obj.attr("checked");
  137. obj.attr("checked", !state);
  138. }
  139. }
  140. });
  141. });
  142. },
  143. /**
  144. * 处理选择改变
  145. */
  146. handChange : function(obj) {
  147. var _self = this;
  148. $(obj).delegate("select.change_right", "change", function() {
  149. var me = $(this), spanObj = me.next(), nextSpanObj = spanObj.next();
  150. _self.showSpan(me.val(), spanObj);
  151. var txtObj = $("textarea", spanObj), idObj = $("input:hidden",
  152. spanObj);
  153. txtObj.val("");
  154. idObj.val("");
  155. var nextTxtObj = $("textarea", nextSpanObj);
  156. nextTxtObj.val("");
  157. });
  158. },
  159. /**
  160. * 显示权限的span
  161. */
  162. showSpan : function(permissionType, spanObj) {
  163. switch (permissionType) {
  164. case "user" :
  165. case "role" :
  166. case "org" :
  167. case "orgMgr" :
  168. case "pos" :
  169. spanObj.show();
  170. spanObj.next().hide();
  171. break;
  172. case "script" :
  173. spanObj.hide();
  174. spanObj.next().show();
  175. break;
  176. case "everyone" :
  177. case "none" :
  178. spanObj.hide();
  179. spanObj.next().hide();
  180. break;
  181. }
  182. },
  183. /**
  184. * 处理选择
  185. */
  186. handClick : function(obj) {
  187. $(obj).delegate("a.link-get", "click", function() {
  188. var me = $(this), txtObj = me.prev(), idObj = txtObj.prev(), selObj = me
  189. .parent().prev(), selType = selObj.val();
  190. // 选择回调
  191. var callback = function(ids, names) {
  192. txtObj.val(names);
  193. idObj.val(ids);
  194. };
  195. switch (selType) {
  196. case "user" :
  197. UserDialog({
  198. callback : callback
  199. });
  200. break;
  201. case "role" :
  202. RoleDialog({
  203. callback : callback
  204. });
  205. break;
  206. case "org" :
  207. case "orgMgr" :
  208. OrgDialog({
  209. callback : callback
  210. });
  211. break;
  212. case "pos" :
  213. PosDialog({
  214. callback : callback
  215. });
  216. break;
  217. }
  218. });
  219. },
  220. //====导出字段=====
  221. initExportField:function(){
  222. var tbl = '#exportFieldTbl';
  223. // 处理选择
  224. this.handChange(tbl);
  225. this.handClick(tbl);
  226. var tr = $($("#exportFieldTemplate .table-detail")[0]).clone(true,
  227. true);
  228. var tabletr = $($("#exportFieldTemplate .table-list")[0]).clone(true,
  229. true);
  230. var tableVal = $("#exportField").val();
  231. if ($.isEmpty(tableVal))
  232. return;
  233. var table = $.parseJSON(tableVal);
  234. var sb = new StringBuffer();
  235. for (var l = 0, t; t = table[l++];) {
  236. $("input[var='tablename']", tabletr).val(t.tableName);
  237. $("input[var='tabledesc']", tabletr).val(t.tableDesc);
  238. $("input[var='ismain']", tabletr).val(t.isMain);
  239. $("[var='table']", tabletr).html(t.tableDesc+'('+t.tableName+")");
  240. sb.append(tabletr.html());
  241. for (var i = 0, c; c = t.fields[i++];) {
  242. $("[var='index']", tr).html(i);
  243. $("[var='name']", tr).html(c.name);
  244. $("input[var='type']", tr).attr("value", c.type);
  245. $("input[var='style']", tr).attr("value", c.style);
  246. $("input[var='desc']", tr).attr("value", c.desc);
  247. $("input[var='tablename']", tr).attr("value", c.tableName);
  248. $("input[var='ismain']", tr).attr("value", c.isMain);
  249. for (var j = 0, k; k = c.right[j++];) {
  250. var rightHtml = this.getHtmlTd(k.type, k.id, k.name, k.script);
  251. if (k.s == 2) {
  252. $("[var='exportRight']", tr).html(rightHtml);
  253. }
  254. }
  255. sb.append(tr.html());
  256. }
  257. }
  258. $(tbl).append(sb.toString());
  259. },
  260. // =====================排序==============================================================================
  261. /**
  262. * 初始化排序
  263. */
  264. initSortField : function() {
  265. var tr = $($("#sortTemplate .table-detail tr")[0]).clone(true, true);
  266. var sortFieldVal = $("#sortField").val();
  267. if ($.isEmpty(sortFieldVal))
  268. return;
  269. var sortField = $.parseJSON(sortFieldVal);
  270. for (var i = 0, c; c = sortField[i++];) {
  271. try {
  272. $("[var='name']", tr).html(c.name);
  273. $("[var='desc']", tr).html(c.desc);
  274. $("[var='source']", tr).html(c.source);
  275. $("[var='sort']", tr).val(c.sort);;
  276. } catch (e) {
  277. }
  278. var tr1 = tr.clone(true, true);
  279. $("#sortTbl tbody").append(tr1);
  280. }
  281. },
  282. /**
  283. * 选择排序
  284. *
  285. * @param {}
  286. * _self
  287. */
  288. selectSort : function(_self) {
  289. var tr = $($("#sortTemplate .table-detail tr")[0]).clone(true, true);
  290. $("#sort-columnsTbl input:[name='select']:checked").each(function() {
  291. var me = $(this), name = me.attr("fieldname"), desc = me
  292. .attr("fielddesc");
  293. var obj = $('#sortTbl');
  294. // 查找该字段是否存在
  295. if (_self.isExistName(obj,'name',name)) {
  296. $("[var='name']", tr).html(name);
  297. $("[var='desc']", tr).html(desc);
  298. var tr1 = tr.clone(true, true);
  299. $("#sortTbl tbody").append(tr1);
  300. }
  301. });
  302. },
  303. /**
  304. * 判断选择是否存在
  305. */
  306. isExistName : function(obj,o,name) {
  307. var rtn = true;
  308. obj.find("[var='"+o+"']").each(function() {
  309. var me = $(this), n = me.html();
  310. if (n == name) {
  311. rtn = false;
  312. return true;
  313. }
  314. });
  315. return rtn;
  316. },
  317. // =====================过滤条件==============================================================================
  318. /**
  319. * 初始化过滤条件
  320. */
  321. initFilter : function() {
  322. this.handChange('#filterTbl');
  323. this.handClick('#filterTbl');
  324. var tr = $($("#filterTemplate .table-detail tr")[0]).clone(true, true);
  325. var filterFieldVal = $("#filterField").val();
  326. if ($.isEmpty(filterFieldVal))
  327. return;
  328. var filterField = $.parseJSON(filterFieldVal);
  329. var sb = new StringBuffer();
  330. for (var i = 0, c; c = filterField[i++];) {
  331. var filter = {};
  332. filter.name = c.name;
  333. filter.key = c.key;
  334. filter.type = c.type;
  335. filter.condition = c.condition;
  336. filter.right = c.right;
  337. this.addFilterTr(tr, filter)
  338. }
  339. },
  340. /**
  341. * 增加过滤行的tr
  342. *
  343. * @param {}
  344. * tr
  345. * @param {}
  346. * conf
  347. */
  348. addFilterTr : function(tr, conf) {
  349. var name = conf.name, key = conf.key, type = conf.type,condition = conf.condition, right = conf.right;
  350. if(condition&& typeof condition =="object")
  351. condition = JSON.stringify(condition);
  352. $("[var='name']", tr).html(name);
  353. $("[var='key']", tr).html(key);
  354. $("[var='type']", tr).val(type);
  355. $("[var='typeshow']", tr).html(type==2?'SQL':'条件脚本');
  356. $("[var='condition']", tr).val(condition);
  357. var filterRightEl = $("[var='filterRight']", tr),
  358. hideFieldRightEl = $('<td var="filterRight" class="hidden"></td>');
  359. for (var j = 0, k; k = right[j++];) {
  360. var rightHtml = this.getHtmlTd(k);
  361. if (k.s == 3) {
  362. if(!k.srid)
  363. filterRightEl.html(rightHtml);
  364. else{
  365. hideFieldRightEl.html(rightHtml);
  366. filterRightEl.after(hideFieldRightEl);
  367. }
  368. }
  369. }
  370. var tr1 = tr.clone(true, true);
  371. $("#filterTbl tbody").append(tr1);
  372. },
  373. /**
  374. * 增加过滤条件
  375. */
  376. addFilter : function(conf) {
  377. var _self = this, tableName = $('#tableName').val(),
  378. tr = $($("#filterTemplate .table-detail tr")[0]).clone(
  379. true, true);
  380. var right = {};
  381. right.type = 'none';
  382. right.id = '';
  383. right.name = '';
  384. right.script = '';
  385. this.filterDialog({
  386. tableName : tableName,
  387. callback : function(rtn) {
  388. if (rtn) {
  389. var filter = {},
  390. type= rtn.type,
  391. condition = (type==2?rtn.condition:JSON2.stringify(rtn.condition));
  392. filter.name = rtn.name;
  393. filter.key = rtn.key;
  394. filter.type = type;
  395. filter.condition = condition;
  396. filter.right = right;
  397. _self.addFilterTr(tr, filter);
  398. }
  399. }
  400. });
  401. },
  402. /**
  403. * 过滤的窗口
  404. *
  405. * @param {}
  406. * conf
  407. */
  408. filterDialog : function(conf) {
  409. var dialogWidth = 750;
  410. var dialogHeight = 500;
  411. conf = $.extend({}, {
  412. dialogWidth : dialogWidth,
  413. dialogHeight : dialogHeight,
  414. help : 0,
  415. status : 0,
  416. scroll : 0,
  417. center : 1
  418. }, conf);
  419. var winArgs = "dialogWidth=" + conf.dialogWidth + "px;dialogHeight="
  420. + conf.dialogHeight + "px;help=" + conf.help + ";status="
  421. + conf.status + ";scroll=" + conf.scroll + ";center="
  422. + conf.center;
  423. var url = __ctx
  424. + "/platform/bus/busQueryRule/filterDialog.ht?tableName="
  425. + conf.tableName;
  426. url = url.getNewUrl();
  427. /*var rtn = window.showModalDialog(url, conf, winArgs);
  428. if (rtn && conf.callback) {
  429. conf.callback.call(this, rtn);
  430. }*/
  431. var that =this;
  432. /*KILLDIALOG*/
  433. DialogUtil.open({
  434. height:conf.dialogHeight,
  435. width: conf.dialogWidth,
  436. title : '',
  437. url: url,
  438. isResize: true,
  439. //自定义参数
  440. conf: conf,
  441. sucCall:function(rtn){
  442. if (rtn && conf.callback) {
  443. conf.callback.call(that, rtn);
  444. }
  445. }
  446. });
  447. },
  448. /**
  449. * 删除过滤条件
  450. */
  451. delFilter : function() {
  452. this.delSelectTr("filterTbl");
  453. },
  454. /**
  455. * 编辑过滤条件
  456. */
  457. editFilter : function(obj) {
  458. var tr = $(obj).parents("tr"), filter = {};
  459. filter.name = $("[var='name']", tr).html();
  460. filter.key = $("[var='key']", tr).html();
  461. filter.type = $("[var='type']", tr).val();
  462. filter.condition = $("[var='condition']", tr).val();
  463. this.editFilterDialog(tr, filter)
  464. },
  465. /**
  466. * 编辑过滤条件窗口
  467. *
  468. * @param {}
  469. * tr
  470. * @param {}
  471. * filter
  472. */
  473. editFilterDialog : function(tr, filter) {
  474. var _self = this,
  475. tableName = $('#tableName').val();
  476. this.filterDialog({
  477. tableName : tableName,
  478. filter : filter,
  479. callback : function(rtn) {
  480. if (rtn) {
  481. var type =rtn.type;
  482. var condition = (type==2?rtn.condition:JSON2.stringify(rtn.condition));
  483. $("[var='name']", tr).html(rtn.name);
  484. $("[var='key']", tr).html(rtn.key);
  485. $("[var='type']", tr).val(type);
  486. $("[var='typeshow']", tr).html(type==2?'SQL':'条件脚本');
  487. $("[var='condition']", tr).val(condition);
  488. }
  489. }
  490. });
  491. },
  492. // =====================通用的处理方法==============================================================================
  493. /**
  494. * 切换分页
  495. */
  496. switchNeedPage : function(obj) {
  497. var me = $(obj), pagSize = $("#spanPageSize");
  498. var isNeedPage = me.val();
  499. if (isNeedPage == 1) {
  500. pagSize.show();
  501. } else {
  502. pagSize.hide();
  503. }
  504. },
  505. /**
  506. * 删除TR
  507. */
  508. delTr : function(obj) {
  509. $(obj).closest("tr").remove();
  510. },
  511. /**
  512. * 删除选择的tr
  513. *
  514. * @param {}
  515. * obj 选择的tr的ID
  516. */
  517. delSelectTr : function(obj) {
  518. var _self = this;
  519. $("#" + obj + " input:[name='select']:checked").each(function() {
  520. _self.delTr(this);
  521. });
  522. },
  523. /**
  524. * 上下移动
  525. *
  526. * @param {}
  527. * obj
  528. * @param {}
  529. * isUp 是否上移
  530. */
  531. moveTr : function(obj, isUp) {
  532. var thisTr = $(obj).parents("tr");
  533. if (isUp) {
  534. var prevTr = $(thisTr).prev();
  535. if (prevTr) {
  536. thisTr.insertBefore(prevTr);
  537. }
  538. } else {
  539. var nextTr = $(thisTr).next();
  540. if (nextTr) {
  541. thisTr.insertAfter(nextTr);
  542. }
  543. }
  544. },
  545. /**
  546. * 选择脚本
  547. *
  548. * @param {}
  549. * obj
  550. */
  551. selectScript : function(obj, isNext) {
  552. var linkObj = $(obj), txtObj = {};
  553. if (isNext)
  554. txtObj = linkObj.next()[0];
  555. else
  556. txtObj = linkObj.prev()[0];
  557. if (txtObj) {
  558. ScriptDialog({
  559. callback : function(script) {
  560. $.insertText(txtObj, script);
  561. }
  562. });
  563. }
  564. },
  565. /**
  566. * 处理选择字段赋值
  567. *
  568. * @param {}
  569. * obj
  570. */
  571. handSelect : function(obj) {
  572. $(obj).delegate("select[var='name']", "change", function() {
  573. var me = $(this), text = me.children('option:selected').text();
  574. tr = me.closest("tr");
  575. var desc = $("[var='desc']", tr);
  576. desc.val(text);
  577. });
  578. }
  579. };
  580. var __BusQueryRule__ = new BusQueryRuleEdit();// 默认生成一个对象