fw.win.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /**
  2. * @author herong 对话框组件
  3. */
  4. var CFWWin = _FW.fCreateClass();
  5. /**
  6. * 对话框组件API
  7. */
  8. CFWWin.prototype = {
  9. /**
  10. * 初始化
  11. */
  12. fInitialize : function(options) {
  13. },
  14. /**
  15. * 处理控件重新布局(调整控件大小和位置,如果原先控件是隐藏的,那么可能需要手动调用它来重新调整)。
  16. * 需要布局的,手动调用这个,传入父级dom,比如外层div,或者form
  17. *
  18. * @param oFindObj(必需)
  19. * 控件对象 使用举例: CFW.oWin.fnResizeObject(findObj);
  20. */
  21. fnResizeObject : function(findObj) {
  22. // 查找节点对象里面的所有需要重新调整的节点
  23. $('.fwresize', findObj).trigger('fwresize');
  24. },
  25. /**
  26. * 关闭DIV
  27. *
  28. * @param sDivID(必需)
  29. * 网页DIV的ID 使用举例: CFW.oWin.fnDivClose(sDivID);
  30. */
  31. fnDivClose : function(sTabId) {
  32. var tabId = "#" + sTabId;
  33. $(tabId).fwwindow('close');
  34. // $(tabId).hide();
  35. },
  36. /**
  37. * 打开DIV
  38. *
  39. * @param sDivID(必需)
  40. * 网页DIV的ID 使用举例: CFW.oWin.fnDivOpen(sDivID);
  41. */
  42. fnDivOpen : function(sTabId) {
  43. var tabId = "#" + sTabId;
  44. $(tabId).fwwindow('open');
  45. // $(tabId).show();
  46. },
  47. /**
  48. * 提示消息
  49. *
  50. * @param sMsg
  51. * 消息 应用实例
  52. *
  53. * <pre>
  54. * CFW.oWin.fnAlert(&quot;hello world!&quot;);
  55. * </pre>
  56. */
  57. fnAlert : function(sMsg) {
  58. alert(sMsg);
  59. },
  60. /**
  61. * 提示窗口(带样式)
  62. *
  63. * @param sMsg
  64. * 消息 应用实例
  65. * @param mArgs
  66. * 参数。窗口宽度(dialogWidth),窗口高度(dialogHeight)
  67. *
  68. * <pre>
  69. * CFW.oWin.fnAlertStyle(&quot;hello world!&quot;);
  70. * 或
  71. * var mArgs = {'dialogWidth':'500px','dialogHeight':'250px'};
  72. * CFW.oWin.fnAlertStyle(&quot;hello world!&quot;, &quot;mArgs&quot;);
  73. * </pre>
  74. */
  75. fnAlertStyle : function(sMsg, mArgs) {
  76. if(mArgs==null){
  77. mArgs={type:'AppMsg'};
  78. }
  79. this._fnAlert(sMsg, mArgs);
  80. },
  81. /**
  82. * 提交form需要跟 <hnisi:htmlBack> 配合起来使用
  83. *
  84. * @param sf
  85. * 需要提交的foem
  86. * @param callBackFunction
  87. * 回调函数
  88. *
  89. * <pre>
  90. * CFW.oWin.fnSubmitForm(&quot;cxtjForm&quot;,&quot;testFresh()&quot;);
  91. * </pre>
  92. */
  93. fnSubmitForm : function(sf,callBackFunction) {
  94. if(sf==null||sf==""){
  95. alert("请输入要提交的Form");
  96. return;
  97. }
  98. var form = document.getElementsByName(sf)[0];
  99. if(callBackFunction==null){
  100. callBackFunction = "";
  101. }
  102. var height=$(window).height();
  103. document.getElementById("div_body").style.display="none";
  104. var formTarget = form.target;
  105. var backseq=$("#callBackFunction").attr("SEQ");
  106. form.target = "callIframe_"+backseq;
  107. //$("#callIframe_"+backseq).height(height);
  108. form.submit();
  109. //根据iframe中的内容高度来设置iframe高度
  110. $("#callIframe_"+backseq).css("height","auto");
  111. $("#"+form.target).unbind("load").load(function(){
  112. var mainheight = $(this).contents().height();//页面内容的高度
  113. var availHeight=document.documentElement.clientHeight;//工作区页面的高度
  114. //alert("mainheight="+mainheight+"-------------------availHeight="+availHeight+"-------"+"-backseq---"+backseq);
  115. var contntH=mainheight;
  116. if(availHeight>mainheight){
  117. contntH=availHeight;
  118. }else{
  119. contntH=mainheight;
  120. }
  121. contntH=contntH-30;
  122. $(this).height(contntH);
  123. if($(this).attr("contentHeight")==undefined){
  124. $(this).attr("contentHeight",contntH);
  125. }
  126. var doc = document, p = window;
  127. while(p = p.parent){
  128. var frameId=$("iframe",p.document.getElementById('add_back_div')).attr("id");
  129. if(frameId!="callIframe_"+backseq && contntH!=0 && frameId.indexOf("callIframe_")>-1){$("iframe",p.document.getElementById('add_back_div')).css("height",contntH+100);}
  130. if(p == top){ break; }
  131. }
  132. });
  133. form.target =formTarget;
  134. document.getElementById("callBackFunction").value=callBackFunction;
  135. document.getElementById("add_back_div").style.display="block";
  136. },
  137. /**
  138. * 返回提交页面需要跟 <hnisi:htmlBack> 配合起来使用
  139. *
  140. * @param step
  141. * 返回前几个页面
  142. *
  143. * <pre>
  144. * CFW.oWin.fnGoCallBack(1);
  145. * </pre>
  146. */
  147. fnGoCallBack : function(step) {
  148. if(step==null){
  149. step = 1;
  150. }
  151. try{
  152. var win=window;
  153. for(var i=0;i<step;i++){
  154. win = win.parent;
  155. }
  156. win.document.getElementById("div_body").style.display="inline";
  157. win.document.getElementById("add_back_div").style.display="none";
  158. var obj = win.document.getElementById("callBackFunction");
  159. var callBackFunction = "";
  160. if(obj!=null && typeof(obj)=='object'){
  161. callBackFunction=obj.value;
  162. }
  163. if(callBackFunction!=""){
  164. win.eval("setTimeout(function(){"+callBackFunction+";},150)");
  165. }
  166. win.document.getElementById("callBackFunction").value="";
  167. //win.document.getElementById("callIframe_"+win.document.getElementById("callBackFunction").SEQ).src="about:blank";
  168. ///*
  169. if($("iframe",win.document.getElementById('add_back_div')).length>0){
  170. var frameId=$("iframe",win.parent.document.getElementById('add_back_div')).attr("id");
  171. var contentHeight=$("#"+frameId,win.parent.document.getElementById('add_back_div')).attr("contentHeight");
  172. $("#"+frameId,win.parent.document.getElementById('add_back_div')).height(contentHeight);
  173. }
  174. //*/
  175. }catch(e){
  176. }
  177. },
  178. /**
  179. * 确认提示对话窗口(带样式)
  180. *
  181. * @param sMsg
  182. * 消息
  183. * @param mArgs
  184. * 参数。窗口宽度(dialogWidth),窗口高度(dialogHeight)
  185. * <pre>
  186. * CFW.oWin.fnConfirmStyle(&quot;是否打印&quot;);
  187. *
  188. * 或
  189. *
  190. * var mArgs = {'dialogWidth':'500px','dialogHeight':'250px'};
  191. * CFW.oWin.fnConfirmStyle(&quot;是否打印&quot;,mArgs);
  192. * </pre>
  193. */
  194. fnConfirmStyle : function(sMsg, mArgs) {
  195. return this._fnConfirm(sMsg, mArgs);
  196. },
  197. /**
  198. * 提示消息
  199. *
  200. * @param sMsg
  201. * 消息
  202. * @param fnCallback
  203. * 回调函数 应用实例
  204. *
  205. * <pre>
  206. * CFW.oWin.fnConfirm(&quot;是否打印&quot;, function(bResult) {
  207. * if (bResult) {
  208. *
  209. * } else {
  210. *
  211. * }
  212. * });
  213. * </pre>
  214. */
  215. fnConfirm : function(sMsg, fnCallback) {
  216. // jQuery.fwmessager.confirm(msg,fn);
  217. //var fun = fun = window[fnCallback];
  218. if (window.confirm(sMsg)) {
  219. if (fnCallback) {
  220. fnCallback.call(this,true);
  221. }
  222. } else if (fnCallback) {
  223. fnCallback.call(this,false);
  224. }
  225. return false;
  226. },
  227. /**
  228. * 通用机构树弹出框
  229. *
  230. * @param oOptions
  231. * 必须,JSON对象,具有属性 1. root:机构树的顶端机构的机构代码,例如'4419' 2. whereCls :
  232. * 树节点的查询条件,一般是'1=1'。 3. selected 已选结构的机构代码orgcocde 4. bussFuncId
  233. * 业务通办的业务ID
  234. * @return JSON对象,具有属性 1.title 机构名 2.key 机构代码
  235. *
  236. * <pre>
  237. * 例子:
  238. * var rst = CFW.oWin.fnOpenOrgTree({root:orgCode,whereCls:'1=1'});
  239. * if(!rst){//如果选择机构节点,则不处理
  240. * return ;
  241. * }else{
  242. * document.qForm.ORGNAME.value = rst.title;
  243. * document.qForm.BAE001.value = rst.key;
  244. * }
  245. * </pre>
  246. */
  247. fnOpenOrgTree : function(oOptions) {
  248. var w = 350;
  249. var h = 500;
  250. var l = (screen.Width - w) / 2;
  251. var t = (screen.Height - h) / 2;
  252. var transpage = contextPath + "/jsp/framework/orgTree.jsp?";
  253. var locStr = "dialogLeft:" + l + ";dialogTop:" + t;
  254. var position = "status:0;help:0;dialogWidth:" + w + "px;dialogHeight:"
  255. + h + "px;" + locStr;
  256. oOptions['_t'] = new Date().getTime();
  257. var url = transpage + $.param(oOptions, true);
  258. return showModalDialog(url, null, position);
  259. },
  260. _fnAlert : function(msg, args) {
  261. var parentdiv=$('<div></div>'); //创建一个父div
  262. parentdiv.attr('id','_exceptionWindow'); //给父div设置id
  263. parentdiv.addClass('window'); //添加css样式
  264. parentdiv.css('display','none');
  265. var msgdiv=$('<div></div>'); //创建一个子div
  266. msgdiv.attr('id','div_exception_context'); //给子div设置id
  267. msgdiv.css({
  268. "width":"100%",
  269. "height":"100%"
  270. }); //添加css样式
  271. msgdiv.appendTo(parentdiv); //将子div添加到父div中
  272. var resultMsg = '<iframe name="_exceptionFrame" src="" width="100%" height="100%" frameborder="0"></iframe>';
  273. msgdiv.empty().append(resultMsg);
  274. var dialogdiv=$('<div></div>'); //创建一个子div
  275. dialogdiv.attr('id','divMsgDialogBtn'); //给子div设置id
  276. dialogdiv.addClass('wfDialogBtn exception-btn-background'); //添加css样式
  277. dialogdiv.css('display','block');
  278. var confirmYbutton;
  279. var confirmNbutton;
  280. var closebutton;
  281. if(args['confrim'] == '1'){
  282. confirmYbutton=$('<a></a>'); //创建一个关闭按钮
  283. confirmYbutton.attr('id','btn_confirm_yes');
  284. confirmYbutton.addClass('buttonlink'); //添加css样式
  285. confirmYbutton.attr('href','javascript:void(0);');
  286. confirmYbutton.attr('keycomb','');
  287. confirmYbutton.attr({"plain":"true"});
  288. confirmYbutton.text('确认');
  289. confirmYbutton.appendTo(dialogdiv);
  290. confirmNbutton=$('<a></a>'); //创建一个关闭按钮
  291. confirmNbutton.attr('id','btn_confirm_no');
  292. confirmNbutton.addClass('buttonlink'); //添加css样式
  293. confirmNbutton.attr('href','javascript:void(0);');
  294. confirmNbutton.attr('keycomb','');
  295. confirmNbutton.attr({"plain":"true"});
  296. confirmNbutton.text('取消');
  297. confirmNbutton.appendTo(dialogdiv);
  298. }else{
  299. closebutton=$('<a></a>'); //创建一个关闭按钮
  300. closebutton.attr('id','btn_exception_close');
  301. closebutton.addClass('buttonlink'); //添加css样式
  302. closebutton.attr('href','javascript:void(0);');
  303. closebutton.attr('keycomb','');
  304. closebutton.attr({"plain":"true"});
  305. closebutton.text('关闭');
  306. closebutton.appendTo(dialogdiv);
  307. }
  308. dialogdiv.appendTo(parentdiv); //将子div添加到父div中
  309. parentdiv.appendTo('body');
  310. parentdiv.fwwindow({
  311. title: '提示',
  312. noheader:true,
  313. width: 600,
  314. modal: true,
  315. shadow: false,
  316. closed: true,
  317. closable : false,
  318. height: 340
  319. });
  320. if(args['confrim'] == '1'){
  321. confirmYbutton.linkbutton({plain:false});
  322. confirmYbutton.unbind('click').click(function(){
  323. parentdiv.fwwindow('close');
  324. $('[name=exceptionForm]').remove();
  325. parentdiv.fwwindow('destroy');
  326. return 1;
  327. });
  328. confirmNbutton.linkbutton({plain:false});
  329. confirmNbutton.unbind('click').click(function(){
  330. parentdiv.fwwindow('close');
  331. $('[name=exceptionForm]').remove();
  332. parentdiv.fwwindow('destroy');
  333. return 0;
  334. });
  335. }else{
  336. closebutton.linkbutton({plain:false});
  337. closebutton.unbind('click').click(function(){
  338. parentdiv.fwwindow('close');
  339. $('[name=exceptionForm]').remove();
  340. parentdiv.fwwindow('destroy');
  341. return 1;
  342. });
  343. }
  344. var frag = document.createDocumentFragment();
  345. var form = document.createElement("form");
  346. form.name="exceptionForm";
  347. form.action=contextPath + '/jsp/framework/alert.jsp?t='+new Date().getTime();
  348. form.target='_exceptionFrame';
  349. var str =" <input type=\"hidden\" name=\"type\" value=\""+args.type+"\"> ";
  350. str+=" <input type=\"hidden\" name=\"msg\" value=\""+msg+"\"> ";
  351. form.innerHTML=str;
  352. frag.appendChild(form);
  353. document.body.appendChild(frag);
  354. form.submit();
  355. parentdiv.fwwindow('open');
  356. },
  357. _fnConfirm : function(msg, args) {
  358. args = args || {};
  359. args['confrim'] = '1';
  360. return this._fnAlert(msg, args);
  361. }
  362. };