dialog.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. Namespace.register("com.hotent.ui");
  2. var _divDialog=1;
  3. com.hotent.ui.Dialog = function(title,width,height){
  4. {
  5. this.okHandler=null;
  6. this.id="div_" +_divDialog;
  7. var x=($(document.body).width()-width) /2;
  8. this.witdh=width;
  9. this.height=height;
  10. this.divWidth=this.width -20;
  11. this.divHeight=this.height -40;
  12. this.containHeight=this.divHeight-30;
  13. var str="<div style='position: relative;height:"+this.divHeight+"px;width:100%;'>" +
  14. "<div id='"+this.id+"' style=' height:"+this.containHeight+"px;width:100%;'></div>"+
  15. "<div class='dialogButton'>" +
  16. "<a href='#' id='btnOK_"+ _divDialog +"' class='button'><span class='left'></span><span class='right'>确定</span></a>&nbsp;&nbsp;" +
  17. "<a href='#' id='btnCancel_"+ _divDialog +"' class='button' style='margin-right:20px;'><span class='left'></span><span class='right'>取消</span></a>" +
  18. "</div>"+
  19. "</div>";
  20. this.dhxWins = new dhtmlXWindows();
  21. this.dhxWins.setSkin("dhx_skyblue");
  22. this.win = this.dhxWins.createWindow("win",x, 0, width, height);
  23. this.win.setText(title);
  24. this.win.denyResize();
  25. this.win.allowMove();
  26. this.win.button("minmax1").hide();
  27. this.win.attachHTMLString(str);
  28. var self=this;
  29. this.dhxWins.attachEvent("onClose", function(win){
  30. self.close();
  31. });
  32. $("#btnCancel_" + _divDialog).click(function(){
  33. self.close();
  34. });
  35. $("#btnOK_" + _divDialog).click(function(){
  36. if(self.okHandler!=null){
  37. self.okHandler(self );
  38. self.close();
  39. }
  40. });
  41. _divDialog++;
  42. }
  43. //设置事件处理
  44. this.setHandler=function(hanler)
  45. {
  46. this.okHandler=hanler;
  47. },
  48. //隐藏对话框
  49. this.hide=function()
  50. {
  51. var isModal = this.win.isModal();
  52. if(isModal)
  53. this.win.setModal(false);
  54. this.win.hide();
  55. },
  56. //显示对话框
  57. this.show=function()
  58. {
  59. this.win.setModal(true);
  60. this.win.show();
  61. },
  62. //关闭对话框
  63. this.close=function()
  64. {
  65. this.win.setModal(false);
  66. //this.win.close();
  67. this.dhxWins.unload();
  68. },
  69. //显示一个页面的DIV
  70. this.attachObject=function(objId)
  71. {
  72. var obj=$("#" + objId);
  73. obj.show();
  74. $("#" + this.id).append(obj);
  75. },
  76. //显示一个URL页面
  77. this.attachUrl=function(url)
  78. {
  79. var frameId="_frame_" + _divDialog;
  80. var url=url.getNewUrl();
  81. var len=$("#" + frameId).length;
  82. if(len==0)
  83. {
  84. var str="<iframe frameborder='0' id='"+frameId+"' src='"+url+"' width='100%' height='"+(this.divHeight-45)+"' ></iframe>";
  85. $("#" + this.id).append(str);
  86. }
  87. else{
  88. $("#" + frameId).attr("src",url);
  89. }
  90. },
  91. //获取IFRAME
  92. //IFRAME 中有个函数getFile
  93. //var iframe=winPic.getIframe();
  94. //var src=iframe.getFile();
  95. this.getIframe=function()
  96. {
  97. var frameId="_frame_" + _divDialog;
  98. return obj=document.frames[frameId];
  99. }
  100. };