//Класс окна class TWin { constructor(dialog,path) { this.dialog=dialog; //Показывать окно как диалог (без возможности изменения размеров) if(typeof path !== 'undefined') this.path=path; else this.path='../resources'; this.disableClosing=false; this.closed=false; //Закрыли (те. удалили из родителя и детей и из DOM) this.onClose=null; //слушатель закрытия окна this.childs=new Array(); //Подчинёные окна this.parent=null; //родительское окно this.name="TWin"; this.tWinId=0; this.dx=0; this.dy=0; this.sel=false; this.obj=null; //user data this.div=document.createElement('div'); //Окно this.divsh=document.createElement('div'); //Тень для модального окна this.tbl=null; this.h0=null; this.ca=null; this.co=null; this.shadow = false; //Показывать ли тень вокруг окошка this.uid=getUID(); //Уникальныйидентификатор this.pBarCnt=0; //Прогресс бар this.pBarDiv=null; //Прогресс бар this.fnResizeListener=null; } addResizeListener(func) { this.fnResizeListener=func; this.fnResizeListener(); } onResize(x,y) { let win=this; return function(e){ if(!e) e = window.event; win.dx=e.pageX || e.x win.dy=e.pageY || e.y document.onmousedown = function() { if(win.fnResizeListener!=null) win.fnResizeListener(); return false; }; document.onmousemove = function(e) { if(!e) e = window.event; let x2 = e.pageX || e.x; let y2 = e.pageY || e.y; let w=parseInt(win.div.style.width)-(win.dx-x2)*x; let h=parseInt(win.div.style.height)-(win.dy-y2)*y; if(w<0)w=0; if(h<0)h=0; win.setWidth(w+"px"); win.setHeight(h+"px"); if(x<0)win.div.style.left=parseInt(win.div.style.left)-(win.dx-x2)+"px"; if(y<0)win.div.style.top=parseInt(win.div.style.top)-(win.dy-y2)+"px"; win.dx=x2; win.dy=y2; if(win.fnResizeListener!=null) win.fnResizeListener(); return false; }; document.onmouseup = function() { document.onmousedown = null; document.onmousemove = MMove//null; if(win.fnResizeListener!=null) win.fnResizeListener(); return false; }; return false; }; } Close() //Закрыть и удалить окно из родителя и менеджера { if(this.disableClosing) return; //Переместил перед удалением компонент так как бывает нужно поработать с ними перед удалением if(this.onClose!=null) { this.onClose(); } this.hide(true); this.setParent(null); for(let i=0;i'; hd+=' '; hd+=' '; //hd+='  '; hd+=' '; hd+=' '; hd+=' X'; hd+=' '; hd+=' '; hd+=''; let str=''; str+=''; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+='
'+hd+'
 
'; */ /* let str=''; str+=''; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+='
'; */ let str=''; str+=''; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+=' '; str+='
'+(this.disableClosing ? '' : '
')+'
'; //создаём невидемую тень this.divsh.style.cssText="display: none; position: fixed; top:0; left:0; height: 100%; width: 100%; background: rgba(0,0,0,0.3);"; this.divsh.onclick=function(win){return function(){ win.Close(); };}(this); document.body.appendChild( this.divsh ); //Создаём родительский элемент для окна this.div = document.createElement('div'); this.div.setAttribute("id","TWin_"+this.tWinId); this.div.style.cssText="position:absolute; height:50px; width:640px;"; this.div.innerHTML=str; document.body.appendChild( this.div ); this.tbl=document.getElementById('TWin_TBL_'+this.tWinId); this.h0=document.getElementById('TWin_H0_'+this.tWinId); this.co=document.getElementById('TWin_Co_'+this.tWinId); this.ca=document.getElementById('TWin_Ca_'+this.tWinId); this.setSel(); this.div.onmousedown=(e)=>this.setSel(); //Кнопка закрыть окно let obj=document.getElementById('TWin_CL_'+this.tWinId); if(obj!=null){ //obj.onclick=function(win){return function(){ win.Close(); };}(this); obj.onclick=(function(){ this.Close(); }).bind(this); } if(!this.dialog) { document.getElementById('TWin_B_'+this.tWinId).onmousedown=this.onResize(0,1); document.getElementById('TWin_T_'+this.tWinId).onmousedown=this.onResize(0,-1); document.getElementById('TWin_BR_'+this.tWinId).onmousedown=this.onResize(1,1); document.getElementById('TWin_TL_'+this.tWinId).onmousedown=this.onResize(-1,-1); document.getElementById('TWin_BL_'+this.tWinId).onmousedown=this.onResize(-1,1); document.getElementById('TWin_R_'+this.tWinId).onmousedown=this.onResize(1,0); document.getElementById('TWin_L_'+this.tWinId).onmousedown=this.onResize(-1,0); document.getElementById('TWin_TR_'+this.tWinId).onmousedown=this.onResize(1,-1); } this.setMove(document.getElementById('TWin_H0_'+this.tWinId)); //this.setMove(document.getElementById('TWin_H1_'+this.tWinId)); //this.setMove(document.getElementById('TWin_H2_'+this.tWinId)); //this.setMove(document.getElementById('TWin_H3_'+this.tWinId)); this.setLeftTop(x,y); } getCaption() { return document.getElementById('TWin_Ca_'+this.tWinId); } setCaption(val) { if(val==null) val=''; let obj=document.getElementById('TWin_Ca_'+this.tWinId); if (typeof val === 'string' || val instanceof String) obj.innerHTML=val; else obj.appendChild(val); } //Присвоить содержимое в виде строки setContent(html) { let obj=document.getElementById('TWin_Co_'+this.tWinId); if(obj!=null) { obj.innerHTML=html; if(this.tbl.offsetHeight>this.div.offsetHeight) this.div.style.height=this.tbl.offsetHeight+"px"; if(this.tbl.offsetWidth>this.div.offsetWidth) this.div.style.width=this.tbl.offsetWidth+"px"; } } //Выбрать (активизировать) окно setSel() { for(let i=0;ithis.div.offsetWidth) this.div.style.width=this.tbl.offsetWidth+"px" }; getWidth(){ if(this.tbl!=null) return parseInt(this.tbl.offsetWidth); else return 0; }; setHeight(h) { if(h==null || h=='') return; h=''+h; if(h.indexOf('%')>-1) h=(this.div.parentNode.offsetHeight/100*parseInt(h)); this.co.style.height=(parseInt(h)-20-this.h0.offsetHeight)+"px"; this.div.style.height=parseInt(h)+'px'; if(this.tbl.offsetHeight>this.div.offsetHeight) this.div.style.height=this.tbl.offsetHeight+"px"; }; //Подстроить размер окна по содержимому /*adjustHeight() { }*/ //Подгрузить содержимое окна из указаного места //json - объект который передастца в виде JSON строки по URL //func - функция которая выполниться после загрузки данных в форму load(url,json,func,tr) { this.loadBody(url,"POST",json,func,tr); console.error('Please use the "loadBody" function.'); }; loadBody(url,method,json,func,tr) { this.showProgressBar(); let r=createRequestObject(); r.onreadystatechange = function(r,w,thiz,func) { return function(){ if(r.readyState == 4){ if(tr) w.innerHTML=trts(r.responseText); else w.innerHTML=r.responseText; thiz.hideProgressBar(); if(func !== undefined && func!=null) func(); //Для подстройки формы под новый размер, а то showProgressBar не по размеру было thiz.div.style.width=thiz.tbl.offsetWidth+"px" thiz.div.style.height=thiz.tbl.offsetHeight+"px"; thiz.setCenter(); } } }(r,this.co,this,func,tr) r.open( method, url, true ); r.setRequestHeader("Cache-Control", "no-cache, no-store, must-revalidate"); r.setRequestHeader("Pragma", "no-cache"); r.setRequestHeader("Expires", "0"); if(json!=null) r.send(JSON.stringify(json)); }else { r.open( "GET", url, true ); r.send(); } }; //Переместить окно на передний план (Обычно при щелчке на нём) setWinZ(s) { let i; this.setZ(g_wins.getMaxZ()+2); //+2 это для тени if(s && this.parent!=null) //Переносим текущий элемент в 0й элемент массива детей родительского { var tmp=this.parent.childs[0]; for(i=1;i0;i--) if(this.childs[i-1]!=null) this.childs[i-1].setWinZ(false) //Забыл зачем это делаю } setParent(w) { if(this.parent!=null) { for(let i=0;i'; //var eDiv=document.getElementById('eDiv'+this.uid); this.div.appendChild(this.pBarDiv); } } //Спрятать прогрес бар hideProgressBar() { this.pBarCnt--; if(this.pBarCnt<=0) { if(this.pBarDiv!==null) deleteHTML(this.pBarDiv); this.pBarCnt=0; this.pBarDiv=null; } } } class TWins { constructor() { this.mas = new Array(); } add(win) //Добавить окно в список { this.mas.push(win); return this.mas.length-1; }; getMaxZ() //Получить максимальный Z индекс { var z=100; //По умолчанию for(var i=0;iz) z=this.mas[i].getZ(); return z; }; getSel() //Получить выделенное окно { for(var i=0;i