/** * TarihBilesenSistem Sinif tanimi * * yilBilesen : 2007,2008 vs, deger iceren HTML bilesen veya tanimlayicisi, bos olamaz. * ayBilesen : [1..12] arasinda deger iceren HTML bilesen veya tanimlayicisi,bos olamaz. * gunBilesen : gun degerinin alinacagi HTML SELECT bilesen veya tanimlayicisi,bos olamaz. */ function TarihBilesenSistem(yilBilesen,ayBilesen,gunBilesen){ // parametrelerin null olmamasini sagla!: if(typeof yilBilesen=="undefined" || yilBilesen==null ||typeof ayBilesen=="undefined" || ayBilesen==null ||typeof gunBilesen=="undefined" || gunBilesen==null){ // hata var, kodu kullanan uzmani uyar!: var mesaj="new TarihBilesenSistem(yilBilesen,ayBilesen,gunBilesen) -> gecerli yilBilesen,ayBilesen veya gunBilesen degeri verMEdiniz!;" alert(mesaj); throw mesaj; } this.yilBilesen=yilBilesen; if(typeof yilBilesen=="string") this.yilBilesen=document.getElementById(yilBilesen); this.ayBilesen=ayBilesen; if(typeof ayBilesen=="string") this.ayBilesen=document.getElementById(ayBilesen); this.gunBilesen=gunBilesen; if(typeof gunBilesen=="string") this.gunBilesen=document.getElementById(gunBilesen); // degisim dinleyicileri ekle!: this.yilDegisti=function(){ // gecerlilik sinamasi yap!: var sonuc = true; // gunBilesen bir kombo ise yeni duzenlenmeli!: if(typeof this.gunBilesen.options!="undefined") this.gunSecimKombosuDuzenle(this.gunBilesen,this.ayBilesen.value,this.yilBilesen.value); return sonuc; }; this.ayDegisti=function(){ // gecerlilik sinamasi yap!: var sonuc = true; // gunBilesen bir kombo ise yeni duzenlenmeli!: if(typeof this.gunBilesen.options!="undefined") this.gunSecimKombosuDuzenle(this.gunBilesen,this.ayBilesen.value,this.yilBilesen.value); return sonuc; }; this.gunDegisti=function(){ // gecerlilik sinamasi yap!: var sonuc = true; return sonuc; }; this.yilBilesen.tarihBilesenSistem=this; this.ayBilesen.tarihBilesenSistem=this; this.gunBilesen.tarihBilesenSistem=this; // yordam baglayici yordam!: this.yordamBagla=function(nesne,yordamDizi){ // bir dizi yordami pespese calistirmak icin tek bir yordam olusturur. return function(){ try{ var sonuc=true; for(var i=0;i"+e); } }; } // bilesenlerin onChange eylemelerini duzenle!: this.yilBilesen.onchange=this.yordamBagla(this.yilBilesen,[this.yilBilesen.onchange,function(){ try{ var sonuc=this.tarihBilesenSistem.yilDegisti(); if(sonuc==false){ // gunBilesen degerini degistirerek hatayi gider!: this.tarihBilesenSistem.gunBilesen.value=1; this.tarihBilesenSistem.uyariMesajVer(); this.tarihBilesenSistem.gunBilesen.focus(); } return sonuc; }catch(e){ // tarih bilesenlerinden herhangibiri sayisal deger icermiyor } return false; }]); this.ayBilesen.onchange=this.yordamBagla(this.ayBilesen,[this.ayBilesen.onchange,function(){ try{ var sonuc=this.tarihBilesenSistem.ayDegisti(); if(sonuc==false){ // gunBilesen degerini degistirerek hatayi gider!: this.tarihBilesenSistem.gunBilesen.value=1; this.tarihBilesenSistem.uyariMesajVer(); this.tarihBilesenSistem.gunBilesen.focus(); } return sonuc; }catch(e){ // tarih bilesenlerinden herhangibiri sayisal deger icermiyor } return false; }]); this.gunBilesen.onchange=this.yordamBagla(this.gunBilesen,[this.gunBilesen.onchange,function(){ try{ var sonuc=this.tarihBilesenSistem.gunDegisti(); if(sonuc==false){ // gunBilesen degerini degistirerek hatayi gider!: this.tarihBilesenSistem.gunBilesen.value=1; this.tarihBilesenSistem.uyariMesajVer(); this.tarihBilesenSistem.gunBilesen.focus(); } return sonuc; }catch(e){ // tarih bilesenlerinden herhangibiri sayisal deger icermiyor } return false; }]); this.uyariMesajVer=function(){ var mesaj=this.UYARI_MESAJ; if(typeof this.uyariMesaj!="undefined") mesaj= this.uyariMesaj; if(mesaj!=null) alert(mesaj); } } /** * Bilesenler icindeki degerlerin dogru olup olmadigi incelenir. * Bilesenlerin degerleri sayisal degilse hata firlatir. */ TarihBilesenSistem.prototype.tarihGecerliMi=function(){ var tarihGecerli=true; if(this.yilBilesen.value==0 || this.ayBilesen.value==0 || this.ayBilesen.value==-1 || this.gunBilesen.value==0) return true; var yilD=parseInt(this.yilBilesen.value); //if(!isNan(yilD)) throw "Yil sayisal degerde degil"; var ayD=parseInt(this.ayBilesen.value); //if(!isNan(ayD)) throw "Ay sayisal degerde degil"; var gunD=parseInt(this.gunBilesen.value); //if(!isNan(gunD)) throw "Gun sayisal degerde degil"; // js ay 0 dan basliyor!: var tarih=new Date(yilD,ayD-1,gunD); var yilDY=tarih.getFullYear(); var ayDY=tarih.getMonth()+1; var gunDY=tarih.getDate(); window.status="ayD:"+ayD+" gunD:"+gunD+" ayDY:"+ayDY+" gunDY:"+gunDY; // editordeki yil,ay ve gun elde edilen tarihden farkli ise gun degeri 1 olsun ve uyari verilsin!: if(yilDY!=yilD || ayD!=ayDY || gunD!=gunDY) tarihGecerli=false; return tarihGecerli; } /** * Verilen ay ve yil icin gunBilesen secim kutusu doldurulur. Eger onceden secim kutusunda * bir secim yapildiysa, o degerin yeni secim listesinde etkin olup olmadigina bakilir. Etkin * degilse "1" degeri atanir. * gunBilesen : gun degerinin alinacagi HTML SELECT bilesen * ayDeger : sayisal ay degeridir [1..12] * yilDeger : sayisal yil degeridir; 2007,2008 vs */ TarihBilesenSistem.prototype.gunSecimKombosuDuzenle=function (gunBilesen,ayDeger,yilDeger){ var seciliOlan=gunBilesen.value; if(seciliOlan==null || seciliOlan==""){ seciliOlan=1; } //window.status+=" secili olan:"+seciliOlan; // secim Listesini bosalt!: for(var i=gunBilesen.options.length-1;i>0;i--) { gunBilesen.remove(i); } // miladi olarak en fazla 31 gun olabilir!: var gunUstSinir=31; var isSelectedSet = false; for(var i=0;i