init.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. //此文件为页面载入时需要初始化的内容以及事件
  2. jQuery(function(){
  3. /**
  4. * 判断对象disabled状态
  5. * @param obj 对象
  6. * @returns true/false
  7. */
  8. function isDisabled(obj) {
  9. if (obj.disabled) {
  10. return true;
  11. }
  12. return false;
  13. }
  14. //捕捉键盘事件
  15. jQuery(document).keydown(function(event){
  16. var el= event.target || event.srcElement;
  17. var iLen=0;
  18. var str="";
  19. if (event.keyCode == 9){//TAB
  20. return true;
  21. }
  22. if(event.keyCode==8){ //backspace
  23. return true;
  24. }
  25. if(event.keyCode==46){ //delete
  26. return true;
  27. }
  28. //处理组合键-快捷方式 ctrl+s、ctrl+y、ctrl+d、ctrl+m、ctrl+q
  29. //s=83 y=89 n=78 d=68 m=77 q=81
  30. if(event.ctrlKey && event.keyCode==83){
  31. $("a").each(function(){
  32. if(this.keycomb=='ctrl+s' && !isDisabled(this)){
  33. $(this).trigger("click");
  34. return true;
  35. }
  36. });
  37. }
  38. if(event.ctrlKey && event.keyCode==89){
  39. $("a").each(function(){
  40. if(this.keycomb=='ctrl+y' && !isDisabled(this)){
  41. $(this).trigger("click");
  42. return false;
  43. }
  44. });
  45. }
  46. if(event.ctrlKey && event.keyCode==76){
  47. $("a").each(function(){
  48. if(this.keycomb=='ctrl+l' && !isDisabled(this)){
  49. $(this).trigger("click");
  50. return false;
  51. }
  52. });
  53. }
  54. if(event.altKey && event.keyCode==81){
  55. $("a").each(function(){
  56. if(this.keycomb=='alt+q' && !isDisabled(this)){
  57. $(this).trigger("click");
  58. return true;
  59. }
  60. });
  61. }
  62. if(event.ctrlKey && event.keyCode==68){
  63. $("a").each(function(){
  64. if(this.keycomb=='ctrl+d' && !isDisabled(this)){
  65. $(this).trigger("click");
  66. return true;
  67. }
  68. });
  69. }
  70. if(event.ctrlKey && event.keyCode==77){
  71. $("a").each(function(){
  72. if(this.keycomb=='ctrl+m' && !isDisabled(this)){
  73. $(this).trigger("click");
  74. return true;
  75. }
  76. });
  77. }
  78. if(event.ctrlKey && event.keyCode==81){
  79. $("a").each(function(){
  80. if(this.keycomb=='ctrl+q' && !isDisabled(this)){
  81. $(this).trigger("click");
  82. return true;
  83. }
  84. });
  85. }
  86. //x=88 信息提示框关闭
  87. if(event.ctrlKey && event.keyCode==88){
  88. $("div.fwmessager-tool-close").each(function(){
  89. if(this.keycomb=='ctrl+x' && !isDisabled(this)){
  90. $(this).trigger("click");
  91. return true;
  92. }
  93. });
  94. $("a").each(function(){
  95. if(this.keycomb=='ctrl+x' && !isDisabled(this)){
  96. $(this).trigger("click");
  97. return true;
  98. }
  99. });
  100. }
  101. //单击回车调用TAB键
  102. if(jQuery(el).is('.textbox,.notpastebox,.datebox,.datetime,.floatbox,.numberbox,.chinessbox,.yearmonthbox,.timebox,.checkbox,.postbox,.phonebox,.idcardbox,.combobox,.zjtextbox,.fwcombox-text,.searchgridbox')){
  103. if (event.keyCode == 13) {
  104. event.keyCode = 9;
  105. return true;
  106. }
  107. }
  108. return true;
  109. });//jQuery(document).keydown 结束
  110. //处理按钮
  111. jQuery('.buttonlink',document).each(function(){
  112. var plain = $(this).attr("plain");
  113. if(plain=="false"||plain==null||plain==""){
  114. $(this).attr({"plain":"true"});
  115. $(this).linkbutton({plain:false});
  116. }
  117. });
  118. try {
  119. //导航栏固定 代码开始
  120. //以下的代码是为了把本页的导航栏提交到frame名为 navigation 的DIV
  121. //为了实现导航栏固定在最上方
  122. var obj_navigator_button = document.all._navigator_button;
  123. if(typeof document.all._menu_button != 'undefined'){
  124. if(typeof obj_navigator_button != 'undefined'){
  125. var obj = document.all._menu_button;
  126. jQuery(obj_navigator_button).html(obj.innerHTML);
  127. }
  128. }
  129. //获取同级的frames的DIV
  130. if(typeof self.parent.navigation!='undefined'){
  131. if(typeof self.parent.navigation._navigator!='undefined'){
  132. var obj_navigator = self.parent.navigation._navigator;
  133. var obj_content_navigator = jQuery("#content_navigator");
  134. if(typeof obj_content_navigator != 'undefined' ) {
  135. if(typeof obj_navigator != 'undefined'){ //存在就替换
  136. jQuery(obj_navigator).html(obj_content_navigator.html());
  137. obj_navigator_button = self.parent.navigation._navigator_button;
  138. if(typeof obj_navigator_button != 'undefined'){
  139. jQuery('a',obj_navigator_button).each(function(){
  140. var tmp = jQuery(this).attr('onclick')+'';
  141. if(tmp!=null&&tmp!=''){
  142. var iPos1 = tmp.indexOf('{')+1;
  143. var iPos2 = tmp.indexOf('}');
  144. var iLen = iPos2 - iPos1;
  145. tmp = tmp.substr(iPos1,iLen);
  146. tmp = "self.parent.workspace." + tmp;
  147. //这样处理的目的是为了另一层的FRAMES可以执行workspace的函数
  148. jQuery(this).removeAttr('onclick');
  149. try{
  150. jQuery(this).bind('click',function(){eval(tmp)});
  151. }catch(e){}
  152. }
  153. });
  154. }
  155. }else{
  156. //不存在就直接显示
  157. jQuery(document.all.content_navigator).css({display:'block'});
  158. }
  159. }else{
  160. if(typeof obj_navigator != 'undefined'){
  161. jQuery(obj_navigator).html('');
  162. }
  163. }
  164. }
  165. }else{
  166. //这种是针对frameset 内还有frameset的情况
  167. if(typeof self.parent.parent.navigation!='undefined'){
  168. //如果内嵌的frame/iframe是报表的话,不刷新到导航栏
  169. if(null != self.location && null != self.location.href && -1!=self.location.href.indexOf("/report.do")){
  170. //do nothing
  171. }else{
  172. var obj_navigator = self.parent.parent.navigation._navigator;
  173. var obj_content_navigator = jQuery("#content_navigator");
  174. if(obj_content_navigator.size()!=0){ //存在就替换
  175. jQuery(obj_navigator).html(obj_content_navigator.html());
  176. }
  177. }
  178. }
  179. }
  180. //导航栏固定 代码结束
  181. }catch (ex) {
  182. //jQuery(document.all.content_navigator).css({display:'block'});
  183. }
  184. });
  185. /**
  186. * 初始化通用树弹出框
  187. * @param options
  188. * root 树的根节点
  189. * whereCls 树节点的查询条件
  190. * selected 已选结构的机构代码orgcocde
  191. * bussFuncId 业务通办的业务ID
  192. */
  193. function FwOpenOrgTree(options){
  194. var w=350;
  195. var h=500;
  196. var l = (screen.Width-w)/2;
  197. var t = (screen.Height-h)/2;
  198. var transpage=contextPath + "/jsp/framework/orgTree.jsp?";
  199. var locStr = "dialogLeft:" + l + ";dialogTop:" + t;
  200. var position="status:0;help:0;dialogWidth:"+w+"px;dialogHeight:"+h+"px;"+locStr;
  201. options['_t']=new Date().getTime();
  202. var url=transpage+$.param(options,true);
  203. return showModalDialog(url,null,position);
  204. }
  205. /**
  206. * 验证提示框
  207. * e.g:
  208. * FWvalidateTip(document.wfForm.XM,"姓名输入不合法");
  209. *
  210. * FWvalidateTip("form[name='wfForm'] input[name='XM']","姓名输入不合法!");
  211. *
  212. * @param findObj jQuery查找串或对象
  213. * @param msg 提示信息
  214. */
  215. function FWvalidateTip(findObj,msg) {
  216. //延迟2秒
  217. var defaults = {content: {text: msg},
  218. hide: { delay:2000,
  219. event: false,
  220. inactive: 3000},
  221. position: {
  222. my: 'center left', // 默认显示在右侧
  223. at: 'center right'
  224. }
  225. };
  226. var $findObj = $(findObj);
  227. //距离浏览器窗口右边的距离
  228. var distance = document.body.clientWidth - $findObj.get(0).getBoundingClientRect().right;
  229. if(distance <= 200){//如果距离浏览器右边的距离少于200px,则提示信息在下方显示
  230. defaults.position = {
  231. my: 'top center',
  232. at: 'bottom center'
  233. };
  234. if($findObj.hasClass("fwcombox-arrow")){
  235. $findObj.prev().qtip(defaults).qtip("show");
  236. }else{
  237. $findObj.qtip(defaults).qtip("show");
  238. }
  239. }else{
  240. $findObj.qtip(defaults).qtip("show");
  241. }
  242. }
  243. /**
  244. * 有标题和关闭按钮的提示框
  245. * FWtipDialog(document.wfForm.XM,"错误提示","姓名输入不合法");
  246. *
  247. * FWtipDialog("form[name='wfForm'] input[name='XM']","错误提示","姓名输入不合法!");
  248. *
  249. * @param findObj jQuery查找串或对象ldn
  250. * @param titleStr 标题
  251. * @param msg 提示信息
  252. */
  253. function FWtipDialog(findObj,titleStr,msg) {
  254. var isTitle = true;
  255. if (jQuery.trim(msg) != ''){
  256. isTitle = false;
  257. }
  258. FWtip(findObj,msg ,{hide: {event: false},
  259. content:{title: {
  260. text: titleStr, // Give the tooltip a title using each elements text
  261. button: true
  262. },text: function() {
  263. return !isTitle ? msg : $(this).attr('title');
  264. }},
  265. position: {
  266. my: 'left center', // Use the corner...
  267. at: 'right center' // ...and opposite corner
  268. }}).qtip('show');
  269. }
  270. /**
  271. * 普通提示框,可以显示title属性内容,或提定要示的内容
  272. * e.g:
  273. * 给 a[title] 对象(对象必须有title属性)属性的title信息提示
  274. * FWtip('a[title]');
  275. *
  276. * 经 a[title] 对象加指定提示信息
  277. * FWtip('a[title]',"提示信息");
  278. *
  279. * @param findObj jQuery查找串或对象
  280. * @param msg 提示信息
  281. * @param options 参数
  282. * @returns qtip对象
  283. */
  284. function FWtip(findObj,msg,options) {
  285. var isTitle = true;
  286. var options2 = options == undefined || options == null ? {} : options;
  287. if (jQuery.trim(msg) != ''){
  288. isTitle = false;
  289. }
  290. var defaults = {content: {
  291. text: function() {
  292. return !isTitle ? msg : $(this).attr('title');
  293. }
  294. },
  295. position: {
  296. my: 'left center', // Use the corner...
  297. at: 'right center' // ...and opposite corner
  298. }};
  299. jQuery.extend(true,defaults,options2);
  300. return $(findObj).qtip(defaults);
  301. }
  302. /**
  303. * 动态内容提示框
  304. * e.g:
  305. * FWtipDynamic("a[name='tipMsg']",{ajax:{url:"请求链接"});
  306. *
  307. * FWtipDynamic("a[name='tipMsg']",{title:{text:'提示',button: true},ajax:{url:"请求链接"});
  308. *
  309. * @param findObj jQuery查找串或对象
  310. * @param options 参数
  311. * {
  312. title:{
  313. text: '提示',
  314. button: true
  315. },
  316. position:{
  317. at: 'bottom right',
  318. my: 'top left',
  319. viewport: $(window)
  320. }
  321. */
  322. function FWtipDynamic(findObj,options) {
  323. var defaultOptions = {
  324. title:{
  325. text: '提示',
  326. button: true
  327. },
  328. position:{
  329. at: 'bottom right',
  330. my: 'top left',
  331. viewport: $(window)
  332. },
  333. style:'ui-tooltip-wiki'
  334. };
  335. jQuery.extend(defaultOptions,options || {});
  336. $(findObj).each(function()
  337. {
  338. // We make use of the .each() loop to gain access to each element via the "this" keyword...
  339. $(this).qtip(
  340. {
  341. content: {
  342. text: '<img class="throbber" src="'+contextPath+'/js/ui/qtip/images/throbber.gif" alt="Loading..." />',
  343. ajax: defaultOptions.ajax || $(this).attr('rel'),
  344. title: defaultOptions.title
  345. },
  346. position: defaultOptions.position,
  347. show: {
  348. event: 'click',
  349. solo: true // Only show one tooltip at a time
  350. },
  351. hide: 'unfocus',
  352. style:defaultOptions.style
  353. })
  354. // Make sure it doesn't follow the link when we click it
  355. .click(function() { return false; });
  356. });
  357. defaultOptions = null;
  358. }
  359. /**
  360. * Job操类
  361. */
  362. function FwJob() {
  363. /**
  364. * 执行Job
  365. * @param jobId Job标识
  366. * @param key Job关键字
  367. * @param argsObj 传参
  368. */
  369. this.execute = function(jobId,key,argsObj) {
  370. var refresh = eval("job_"+jobId+"_refresh");
  371. if ($.trim(key) !='') {
  372. $("#"+jobId+"_key").val(key);
  373. }
  374. var args = {"_longTransID":""+jobId,"_longTransKey":$("#"+jobId+"_key").val()};
  375. args = jQuery.extend(args,argsObj);
  376. new Service({serviceId:'longProcessService',method:'scheduler',parameters:args})
  377. .sentAjax(function(data){
  378. if (data == '1') {
  379. FWalert('此任务已在执行中!');
  380. } else {
  381. FWalert('任务提交成功!');
  382. }
  383. FwJob.prototype.clearAllRefresh();
  384. var func = eval("FwJob.prototype.win_job_"+jobId+"_refresh");
  385. func();
  386. var t = setInterval("FwJob.prototype.win_job_"+jobId+"_refresh()",refresh);
  387. FwJob.prototype.__jobRefresh[jobId]=t;
  388. },function(data){
  389. FWalert(data);
  390. FwJob.prototype.clearAllRefresh();
  391. var t = setInterval("FwJob.prototype.win_job_"+jobId+"_refresh()",refresh);
  392. FwJob.prototype.__jobRefresh[jobId]=t;
  393. });
  394. };
  395. }
  396. FwJob.prototype.__jobRefresh = [];
  397. FwJob.prototype.__jobWin = [];
  398. FwJob.prototype.isComplete = function(jobId,key){
  399. var args = {"TRANSID":""+jobId,"KEY":key};
  400. new Service({serviceId:'longProcessService',method:'isComplete',parameters:args})
  401. .sentAjax(function(data){
  402. if (data == '2') {
  403. FwJob.prototype.clearRefresh(jobId);
  404. }
  405. },function(data){
  406. FwJob.prototype.clearRefresh(jobId);
  407. });
  408. };
  409. FwJob.prototype.clearAllRefresh = function(){
  410. for(i = 0;i< FwJob.prototype.__jobRefresh.length; i++){
  411. window.clearInterval(FwJob.prototype.__jobRefresh[i]);
  412. }
  413. };
  414. FwJob.prototype.clearRefresh = function(jobId){
  415. window.clearInterval(FwJob.prototype.__jobRefresh[jobId]);
  416. };
  417. var GBtn = {};
  418. function __btnClick(obj,doAction,delay) {
  419. var txt = $(obj).text();
  420. var times = delay != null && delay != undefined ? delay : 3;
  421. if(!obj.disabled) {
  422. GBtn[obj] = [];
  423. GBtn[obj]['i'] = times;
  424. if (typeof doAction === 'function') {
  425. var resp = doAction() ;
  426. resp = resp == null ? true : resp ;
  427. if (!resp) {
  428. return ;
  429. }
  430. $(obj).linkbutton("disable");
  431. if (times != -1) {
  432. $(obj).linkbutton({text:txt+" ("+times+"s)"});
  433. GBtn[obj]['t'] = setInterval("__btnClick.prototype.delay()", 1000);
  434. }
  435. } else {
  436. window.location.href = doAction;
  437. }
  438. }
  439. __btnClick.prototype.delay = function() {
  440. state = $.data(obj, 'linkbutton');
  441. if(state.options.disabled && GBtn[obj]['i'] > 0) {
  442. $(obj).linkbutton({text:txt + " ("+ GBtn[obj]['i'] +"s)"});
  443. GBtn[obj]['i'] = GBtn[obj]['i'] - 1;
  444. } else {
  445. clearInterval(GBtn[obj]['t']);
  446. $(obj).linkbutton("enable");
  447. $(obj).linkbutton({text:txt});
  448. //$(this).linkbutton('disable');
  449. }
  450. };
  451. }
  452. /**
  453. * 框架封装对象
  454. */
  455. var FW = {
  456. /**
  457. * 获取全局变量 (访问属性:private)
  458. * @returns {}
  459. */
  460. _getGVAR : function() {
  461. var twindow = this.getTopWindow(window);
  462. var rtn = null;
  463. try{
  464. rtn = twindow.top.frames['banner'].GVAR || {};
  465. }catch(e){
  466. rtn = window.HEAD_GVAR || {};
  467. }
  468. return rtn;
  469. },
  470. /**
  471. * 获取字典模式 (访问属性:public)
  472. * @@returns String
  473. */
  474. getDictMode : function() {
  475. return this._getGVAR().dictMode;
  476. },
  477. /**
  478. * 字典模式常量 (访问属性:public)
  479. */
  480. DICTMODES : {'SERVER':'server', //ajax获取
  481. 'LOCAL':'local' //本地缓存
  482. },
  483. /**
  484. * 获取顶层框窗口 (访问属性:public)
  485. * @param window self对象
  486. * @returns top window
  487. */
  488. getTopWindow:function(win) {
  489. var twindow = window;
  490. while(twindow.dialogArguments!=null || twindow.opener != null){
  491. while(twindow.dialogArguments!=null){
  492. twindow = twindow.dialogArguments;
  493. }
  494. while(twindow.opener != null){
  495. twindow = twindow.opener;
  496. }
  497. }
  498. return twindow;
  499. },
  500. /**
  501. * (访问属性:private)
  502. */
  503. _storeDict: function(dictName,dict) {
  504. var GVAR = this._getGVAR();
  505. GVAR.dicts[dictName] = dict;
  506. },
  507. /**
  508. * 获取字典信息 (访问属性:public)
  509. * @param dictName 字典名
  510. */
  511. getDict : function(dictName,whereCls) {
  512. var GVAR = this._getGVAR();
  513. if (GVAR.dicts[dictName] != null && !jQuery.isEmptyObject(GVAR.dicts[dictName])) {
  514. return GVAR.dicts[dictName];
  515. }
  516. var dict = {};
  517. jQuery.ajax({
  518. url:contextPath+'/jsp/framework/getDict.jsp'
  519. ,data:{dictName:dictName,whereCls:whereCls}
  520. ,cache:true
  521. ,type:'post'
  522. ,dataType:'json'
  523. ,async:false
  524. ,error:function (request, textStatus, errorThrown){alert("获取字典出错!");}
  525. ,success:function (data, textStatus){
  526. dict = data;
  527. }
  528. });
  529. if (dict != null && !jQuery.isEmptyObject(dict)) {
  530. this._storeDict(dictName, dict);
  531. }
  532. return dict;
  533. },
  534. /**
  535. * 字典是否存在
  536. * @param dictName 字典名
  537. */
  538. isExistsDict:function(dictName) {
  539. var GVAR = this._getGVAR();
  540. if (GVAR.dicts[dictName] != null && !jQuery.isEmptyObject(GVAR.dicts[dictName])) {
  541. return true;
  542. }
  543. return false;
  544. },
  545. showModalDialog:function(href,options) {
  546. var opt = options;
  547. if (opt == null || opt == undefined) {
  548. var w=600,h=400, l = (screen.Width-w)/2,t = (screen.Height-h)/2;
  549. var locStr = "dialogLeft:" + l + ";dialogTop:" + t;
  550. opt="status:0;help:0;dialogWidth:"+w+"px;dialogHeight:"+h+"px;"+locStr;
  551. }
  552. href += href.indexOf("?") > 0 ? "&" : "?" +"_t="+new Date().getTime();
  553. return showModalDialog(href,window,opt);
  554. }
  555. };