//////////////////////////////////////////////////////////////////////// // Класс окна //////////////////////////////////////////////////////////////////////// function CWindow(sID,sCaption,iWidth,iHeight,iLeft,iTop,bVisible,zIndex) { if(typeof(zIndex)=="undefined") zIndex = 0; // var domContainer = document.body; this.m_bUseFrame = true; if(document.addEventListener) this.m_bUseFrame = false; var domContainer = document.getElementById('window_place'); this.m_bCenter = (iLeft==-1 && iTop==-1)?true:false; if(!domContainer) { alert("Ошибка инициализации окна. Не найдено тело документа."); return; } var sVisible = ''; if(!bVisible) sVisible = 'hidden'; else sVisible = 'visible'; this.m_iBodyHeight = 0; this.m_bCanClose = true; this.m_sMsgClose = ""; this.SetMsgClose = function(sMsg) { this.m_sMsgClose = sMsg; } this.m_sID = sID; this.m_sMainID = sID+"_main"; this.m_sHeaderID = sID+"_header"; this.m_sCloseID = sID+"_close"; this.m_sContentID = sID+"_content"; this.m_iHeaderHeight = 25; this.m_iCloseWidth = 45; this.m_fnAfterClose = null; this.m_iHeight = iHeight; var domMainDiv = document.createElement("DIV"); domMainDiv.className = "wnd_main_div"; domMainDiv.style.width = iWidth+"px"; domMainDiv.style.height = iHeight+"px"; domMainDiv.style.left = iLeft+"px"; domMainDiv.style.top = iTop+"px"; domMainDiv.style.visibility = sVisible; domMainDiv.id = this.m_sMainID; if(zIndex) domMainDiv.style.zIndex = zIndex; domContainer.appendChild(domMainDiv); var domMainTab = document.createElement("TABLE"); domMainTab.cellspacing = 0; domMainTab.cellpadding = 0; domMainTab.border = 0; domMainTab.style.width = "100%"; domMainTab.style.height = "100%"; domMainDiv.appendChild(domMainTab); var domTabBody = document.createElement("TBODY"); domMainTab.appendChild(domTabBody); var domTRHeader = document.createElement("TR"); domTRHeader.style.height = this.m_iHeaderHeight+"px"; //domTRHeader.height = this.m_iHeaderHeight; domTRHeader.id = this.m_sHeaderID; domTRHeader.className = "wnd_header"; domTabBody.appendChild(domTRHeader); var domTDHeaderMain = document.createElement("TD"); domTDHeaderMain.innerHTML = sCaption; domTDHeaderMain.id = "wnd_caption_"+sID; domTDHeaderMain.style.width="100%"; domTRHeader.appendChild(domTDHeaderMain); var domTDClose = document.createElement("TD"); domTDClose.style.width = this.m_iCloseWidth+"px"; domTDClose.style.textAlign = "right"; domTRHeader.appendChild(domTDClose); var domClose = document.createElement('INPUT'); domClose.type = "button"; domClose.className = "wnd_close_button"; domClose.value = ""; domClose.onclick = CloseWnd; domClose.id = this.m_sCloseID; domClose.objWnd = this; domTDClose.appendChild(domClose); var domTRBody = document.createElement("TR"); domTRBody.className = "wnd_content"; domTRBody.style.height = (this.m_iHeight-this.m_iHeaderHeight)+"px"; domTabBody.appendChild(domTRBody); var domTDBody = document.createElement("TD"); domTDBody.colSpan = 2; //domTDBody.style.height = this.m_iHeight+"px"; domTDBody.id = this.m_sContentID; domTRBody.appendChild(domTDBody); this.m_objDrag = new CDraggable(this.m_sMainID,this.m_sHeaderID); this.SetContentClass = function(sClassName) { var domContent = document.getElementById(this.m_sContentID); if(domContent) domContent.className = sClassName; } this.Show = function() { var domMain = document.getElementById(this.m_sMainID); if(domMain) { if(this.m_bCenter) { this.CenterWindow(); this.m_objDrag.UpdatePosSize(); } domMain.style.visibility = 'visible'; domMain.style.display = 'block'; domMain.style.zIndex = 600; this.m_objDrag.UpdatePosSize(); ShowFrame(true,this.m_objDrag); } } this.Close = function() { var domMain = document.getElementById(this.m_sMainID); if(domMain) { if(!this.m_bCanClose) { if(this.m_sMsgClose && this.m_sMsgClose!="") alert(this.m_sMsgClose); return; } domMain.style.visibility = 'hidden'; domMain.style.display = 'none'; if(this.m_fnAfterClose!=null) this.m_fnAfterClose(); ShowFrame(false); } } this.SetCaption = function(sCaption) { domCaption = document.getElementById("wnd_caption_"+this.m_sID); if(domCaption) { domCaption.innerHTML = sCaption; } } } CWindow.prototype.SetCloseStatus = function(bClose) { this.m_bCanClose = bClose; } CWindow.prototype.GetBodyHeight = function() { return this.m_iBodyHeight; var domTD = document.getElementById(this.m_sContentID); if(domTD) return domTD.offsetHeight; return 0; } CWindow.prototype.SetDragRect = function(iLeft,iTop,iWidth,iHeight) { this.m_objDrag.SetRectBound(iLeft,iTop,iWidth,iHeight); } CWindow.prototype.SetContent = function(sContent,bUpdateWidth,bUpdateHeight) { var domMain = document.getElementById(this.m_sMainID); var domContent = document.getElementById(this.m_sContentID); if(!domContent || !domMain) return; if(typeof(bUpdateWidth)=="undefined") bUpdateWidth = true; if(typeof(bUpdateHeight)=="undefined") bUpdateHeight = true; domContent.innerHTML = sContent; if(bUpdateWidth) { domMain.style.width = domContent.offsetWidth+"px"; } if(bUpdateHeight) { domMain.style.height = (this.m_iHeaderHeight+domContent.offsetHeight+10)+"px"; } } CWindow.prototype.SetContentDom = function(domData) { var domMain = document.getElementById(this.m_sMainID); var domContent = document.getElementById(this.m_sContentID); if(!domContent || !domMain) return; domContent.appendChild(domData); var iWidth = domContent.offsetWidth+10; var iHeight = this.m_iHeaderHeight+domContent.offsetHeight+10; domMain.style.width = iWidth+"px"; domMain.style.height = iHeight+"px"; this.m_iBodyHeight = domContent.offsetHeight-2; if(this.m_bCenter) { this.CenterWindow(); } this.m_objDrag.UpdatePosSize(); } CWindow.prototype.Update = function() { var domMain = document.getElementById(this.m_sMainID); var domContent = document.getElementById(this.m_sContentID); if(!domContent || !domMain) return; var iWidth = domContent.offsetWidth+10; var iHeight = this.m_iHeaderHeight+domContent.offsetHeight+10; domMain.style.width = iWidth+"px"; domMain.style.height = iHeight+"px"; this.m_iBodyHeight = domContent.offsetHeight-2; this.m_objDrag.UpdatePosSize(); } CWindow.prototype.CenterWindow = function() { var domMain = document.getElementById(this.m_sMainID); var domContent = document.getElementById(this.m_sContentID); if(!domContent || !domMain) return; var iWidth = parseInt(domMain.style.width);//domContent.offsetWidth; var iHeight = parseInt(domMain.style.height);//(this.m_iHeaderHeight+domContent.offsetHeight+10); var iScrollTop= self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop); var iLeft = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth; iLeft = screen.width; iLeft /= 2; var iTop = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight; iTop = screen.height; iTop /= 2; iTop += iScrollTop; domMain.style.left = parseInt(iLeft-(iWidth/2))+"px"; domMain.style.top = parseInt(iTop-(iHeight/2))+"px"; } CWindow.prototype.SetAfterClose = function(fnData) { this.m_fnAfterClose = fnData; } function CloseWnd(objEvent) { if(window.event) objEvent = window.event; if(objEvent.srcElement!=undefined) domSrc = objEvent.srcElement; else domSrc = objEvent.target; if(!domSrc) return; if(!domSrc.objWnd) return; domSrc.objWnd.Close(); ShowFrame(false); } ////////////////////////////////////////////////////////////////////////////// // Класс окна сообщения типа confirm() ////////////////////////////////////////////////////////////////////////////// function CMsgBox(sID,sCaption,sText,iWidth,iHeight,iLeft,iTop,sYesB,sNoB,zIndex) { if(!sYesB) sYesB = "Да"; if(!sNoB) sNoB = "Нет"; this.m_objWnd = new CWindow(sID,sCaption,iWidth,iHeight,iLeft,iTop,true,zIndex); this.OnYes = function(){} this.OnNo = function(){} this.OnClickYes = function() { var objMsg = this.objMsg; if(!objMsg) return; if(objMsg.OnYes) { if(typeof(objMsg.OnYes)==='string') setTimeout(objMsg.OnYes,1); else objMsg.OnYes(); } ShowFrame(false); objMsg.Close(); } this.OnClickNo = function() { var objMsg = this.objMsg; if(!objMsg) return; if(objMsg.OnNo) { if(typeof(objMsg.OnNo)==='string') setTimeout(objMsg.OnNo,1); else objMsg.OnNo(); } ShowFrame(false); objMsg.Close(); } ///////////////////////////////////////////////////////////////////////// var domTable = document.createElement('TABLE'); var domBody = document.createElement('TBODY'); var domTRText = document.createElement('TR'); var domTDText = document.createElement('TD'); var domTRButton = document.createElement('TR'); var domTDButton = document.createElement('TD'); var domButtonYes = document.createElement('INPUT'); domButtonYes.type = 'button'; domButtonYes.value = sYesB; domButtonYes.className = 'msg_button FS_button'; domButtonYes.objWnd = this.m_objWnd; domButtonYes.objMsg = this; domButtonYes.onclick = this.OnClickYes; var domButtonNo = document.createElement('INPUT'); domButtonNo.type = 'button'; domButtonNo.value = sNoB; domButtonNo.className = 'msg_button FS_button'; domButtonNo.objWnd = this.m_objWnd; domButtonNo.objMsg = this; domButtonNo.onclick = this.OnClickNo; domTable.style.width="100%"; domTable.style.height="100%"; domTable.border=0; domTable.appendChild(domBody); domBody.appendChild(domTRText); domTDText.innerHTML = sText; domTDText.align = "center"; domTRText.appendChild(domTDText); domBody.appendChild(domTRButton); domTDButton.align="center"; domTDButton.appendChild(domButtonYes); domTDButton.appendChild(domButtonNo); domTRButton.appendChild(domTDButton); this.m_objWnd.SetContentDom(domTable); ///////////////////////////////////////////////////////////////////////// this.Show = function(){this.m_objWnd.Show();} this.Close = function(){this.m_objWnd.Close();} this.SetOnYes = function(fnYES) { this.OnYes = fnYES; } this.SetOnNo = function(fnNo) { if(fnNo) this.OnNo = fnNo; } } var g_iNumMsgBox = 0; var g_aBtMessages = Array(); function MsgBox(sCaption,sText,domBt,fnYes,fnNo,sYesB,sNoB,zIndex) { if(typeof(zIndex)=="undefined") zIndex = 0; if(!sYesB) sYesB = "Да"; if(!sNoB) sNoB = "Нет"; if(!g_aBtMessages[domBt]) { var objWnd = new CMsgBox('msgbox'+g_iNumMsgBox,sCaption,sText,250,100,-1,-1,sYesB,sNoB,zIndex); objWnd.SetOnYes(fnYes); objWnd.SetOnNo(fnNo); g_aBtMessages[domBt] = objWnd; g_iNumMsgBox++; } else { g_aBtMessages[domBt].SetOnYes(fnYes); g_aBtMessages[domBt].SetOnNo(fnNo); g_aBtMessages[domBt].Show(); } }