123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544 |
- o2.widget = o2.widget || {};
- o2.widget.Calendar = o2.Calendar = new Class({
- Implements: [Options, Events],
- Extends: o2.widget.Common,
- options: {
- "style": "default",
- "path": o2.session.path+"/widget/$Calendar/" ,
- "defaultView": "day", //day, month, year
- "baseDate": new Date(),
- "secondEnable" : false,
- "timeSelectType" : "slider",
- "isTime": false,
- "isMulti": false,
- "before": null,
- "after": null,
- "timeOnly": false,
- "yearOnly" : false,
- "monthOnly": false,
- "defaultDate": null,
- "beforeCurrent": true,
- "clearEnable": true,
- "weekBegin": 0, //0表示周日,1表示周一
- "range": false,
- "rangeNodes": [],
- "rangeRule": "asc", //asc + , des -
- "target": null,
- // "enableDate": function (date) { //一个function,参数为日期,return true不可选
- // return date > new Date();
- // },
- // "enableHours": function (date) {
- // if( date > new Date() ){
- // return [];
- // }else{
- // return [[0, 8], [16, 24]];
- // }
- //}, //一个function, 参数为日期
- // "enableMinutes": null, //一个function, 参数为日期,hour
- // "enableSeconds": null, //一个function, 参数为日期,hour,minutes
- },
- initialize: function(node, options){
- Locale.use("zh-CHS");
- this.setOptions(options);
- this.options.defaultTime = ""+this.options.baseDate.getHours()+":"+this.options.baseDate.getMinutes()+":"+this.options.baseDate.getSeconds();
- this.path = o2.session.path+"/widget/$Calendar/";
- this.cssPath = o2.session.path+"/widget/$Calendar/"+this.options.style+"/css.wcss";
- this._loadCss();
- // this.options.containerPath = this.path+this.style+"/container.html";
- // this.options.dayPath = this.path+this.style+"/day.html";
- // this.options.monthPath = this.path+this.style+"/month.html";
- // this.options.yearPath = this.path+this.style+"/year.html";
- // this.options.timePath = this.path+this.style+"/time.html";
- if (!this.options.format){
- if (this.options.isTime){
- //this.options.format = Locale.get("Date").shortDate + " " + Locale.get("Date").shortTime;
- if(this.options.timeOnly){
- this.options.format="%H:%M";
- }
- else{
- this.options.format = Locale.get("Date").shortDate + " " + "%H:%M";
- }
- }else{
- this.options.format = Locale.get("Date").shortDate;
- }
- }
- this.options.containerPath = this.options.path+this.options.style+"/container.html";
- this.options.dayPath = this.options.path+this.options.style+"/day.html";
- this.options.monthPath = this.options.path+this.options.style+"/month.html";
- this.options.yearPath = this.options.path+this.options.style+"/year.html";
- this.options.timePath = this.options.path+this.options.style+"/time.html";
- this.today = new Date();
- this.currentView = this.options.defaultView;
- this.node = $(node);
- this.visible = false;
- this.setRange();
- this.container = this.createContainer();
- this.container.inject((this.options.target) || $(document.body));
- this.contentTable = this.createContentTable();
- this.contentTable.inject(this.contentDateNode);
- this.addEvents();
- this.container.set({
- styles: {
- "display": "none",
- "opacity": 1
- }
- });
- this.fireEvent("init");
- //this.move = true;
- //this.containerDrag = new Drag.Move(this.container);
- if( layout.mobile ){
- this.maskNode = new Element("div.maskNode",{
- styles : {
- "width": "100%",
- "height": "100%",
- "opacity": 0.6,
- "position": "absolute",
- "background-color": "#CCC",
- "top": "0px",
- "left": "0px",
- "z-index" : 150,
- "-webkit-user-select": "none",
- "-moz-user-select": "none",
- "user-select" : "none"
- },
- events : {
- "touchmove" : function(ev){
- ev.stopPropagation();
- ev.preventDefault();
- }
- }
- }).inject((this.options.target) || $(document.body));
- this.container.addEvents({
- "touchmove" : function(ev){
- ev.stopPropagation();
- ev.preventDefault();
- },
- "touchend" : function(ev){
- ev.stopPropagation();
- //ev.preventDefault();
- }
- })
- }
- },
- addEvents: function(){
- this.node.addEvent("focus", function(){
- this.show();
- }.bind(this));
- this.node.addEvent("click", function(){
- this.show();
- }.bind(this));
- this.prevNode.addEvent("click", function(){
- this.getPrev();
- }.bind(this));
- this.nextNode.addEvent("click", function(){
- this.getNext();
- }.bind(this));
- this.currentTextNode.addEvent("click", function(){
- this.changeView();
- }.bind(this));
- if( !layout.mobile ){
- this.titleNode.addEvent("mousedown", function(){
- this.move();
- }.bind(this));
- this.titleNode.addEvent("mouseup", function(){
- this.unmove();
- }.bind(this));
- }
- document.addEvent('mousedown', this.outsideClick.bind(this));
- },
- move: function(){
- this.containerDrag = new Drag.Move(this.container, {
- "onDrag": function(e){
- if (this.iframe){
- var p = this.container.getPosition();
- this.iframe.setStyles({
- "top": ""+p.y+"px",
- "left": ""+p.x+"px"
- });
- }
- }.bind(this)
- });
- },
- unmove: function(){
- this.container.removeEvents("mousedown");
- this.titleNode.addEvent("mousedown", function(){
- this.move();
- }.bind(this));
- },
- changeView: function(){
- var view = "day";
- switch (this.currentView) {
- case "day" :
- this.changeViewToMonth();
- break;
- case "month" :
- this.changeViewToYear();
- break;
- case "year" :
- if( this.options.yearOnly ){
- break;
- }else if( this.options.monthOnly ){
- this.changeViewToMonth();
- }else{
- this.changeViewToDay();
- }
- break;
- case "time" :
- this.changeViewToDay();
- //this.changeViewToDay();
- break;
- default :
- //nothing;
- }
- },
- changeViewToMonth: function(year){
- this.currentView = "month";
- if (!this.contentMonthTable){
- this.contentMonthTable = this.createContentTable();
- this.contentMonthTable.inject(this.contentDateNode);
- }
- if (this.contentTable) this.contentTable.setStyle("display", "none");
- if (this.contentYearTable) this.contentYearTable.setStyle("display", "none");
- if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "none");
- // if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "block");
- if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "table");
- var year = (year!=undefined) ? year : this.currentTextNode.retrieve("year");
- var month = this.currentTextNode.retrieve("month");
- this.showMonth(year, month);
- this.fireEvent("changeViewToMonth");
- },
- changeViewToYear: function(year){
- this.currentView = "year";
- if (!this.contentYearTable){
- this.contentYearTable = this.createContentTable();
- this.contentYearTable.inject(this.contentDateNode);
- }
- if (this.contentTable) this.contentTable.setStyle("display", "none");
- if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "none");
- if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "none");
- // if (this.contentYearTable) this.contentYearTable.setStyle("display", "block");
- if (this.contentYearTable) this.contentYearTable.setStyle("display", "table");
- this.showYear(year);
- this.fireEvent("changeViewToYear");
- },
- changeViewToDay: function(year, month){
- this.currentView = "day";
- if (!this.contentTable){
- this.contentTable = this.createContentTable();
- this.contentTable.inject(this.contentDateNode);
- }
- if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "none");
- if (this.contentYearTable) this.contentYearTable.setStyle("display", "none");
- if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "none");
- // if (this.contentTable) this.contentTable.setStyle("display", "block");
- if (this.contentTable) this.contentTable.setStyle("display", "table");
- this.showDay(year, month);
- this.showMonthYearButton();
- this.fireEvent("changeViewToDay");
- },
- hideMonthYearButton : function(){
- if(this.clearButton_month){
- this.clearButton_month.hide();
- }
- },
- showMonthYearButton : function(){
- if( this.options.clearEnable && this.buttonArea && !this.clearButton_month ){
- this.container.setStyle("height","auto");
- this.clearButton_month = new Element("div", {"text": o2.LP.widget.clear }).inject(this.buttonArea);
- this.clearButton_month.addEvent("click", function(){
- var t = this.node.get("value");
- this.node.set("value", "");
- if( t )this.fireEvent("change");
- this.fireEvent("clear");
- this.hide();
- }.bind(this));
- this.clearButton_month.setStyles(this.css.calendarMonthActionButton);
- }
- if(this.clearButton_month){
- this.clearButton_month.show();
- }
- },
- getNext: function(){
- switch (this.currentView) {
- case "time" :
- this.getNextDate();
- break;
- case "day" :
- this.getNextDay();
- break;
- case "month" :
- this.getNextMonth();
- break;
- case "year" :
- this.getNextYear();
- break;
- default :
- //nothing
- }
- },
- getPrev: function(){
- switch (this.currentView) {
- case "time" :
- this.getPrevDate();
- break;
- case "day" :
- this.getPrevDay();
- break;
- case "month" :
- this.getPrevMonth();
- break;
- case "year" :
- this.getPrevYear();
- break;
- default :
- //nothing
- }
- },
- getNextDate: function(){
- var date = this.currentTextNode.retrieve("date");
- if( this.currentView === "time" && this.options.enableDate ){
- var d = date.clone().increment("day", 1);
- if( !this.isEnableDate(d) )return;
- }
- // var year = this.currentTextNode.retrieve("year");
- // var month = this.currentTextNode.retrieve("month");
- // month--;
- // var day = this.currentTextNode.retrieve("day");
- // var date = new Date(year, month, day);
- date.increment("day", 1);
- this._setTimeTitle(null, date);
- if( this.options.enableHours || this.options.enableMinutes || this.options.enableSeconds ){
- this._resetTimeDate();
- }
- },
- getPrevDate: function(){
- var date = this.currentTextNode.retrieve("date");
- if( this.currentView === "time" && this.options.enableDate ){
- var d = date.clone().increment("day", -1);
- if( !this.isEnableDate(d) )return;
- }
- date.increment("day", -1);
- this._setTimeTitle(null, date);
- if( this.options.enableHours || this.options.enableMinutes || this.options.enableSeconds ){
- this._resetTimeDate();
- }
- },
- getNextDay: function(){
- var year = this.currentTextNode.retrieve("year");
- var month = this.currentTextNode.retrieve("month");
- month--;
- var date = new Date(year, month, 1);
- date.increment("month", 1);
- var thisYear = date.getFullYear();
- var thisMonth = date.getMonth();
- this._setDayTitle(null, thisYear, thisMonth);
- this._setDayDate(null,thisYear, thisMonth);
- this.fireEvent("changeViewToDay");
- },
- getPrevDay: function(){
- var year = this.currentTextNode.retrieve("year");
- var month = this.currentTextNode.retrieve("month");
- month--;
- var date = new Date(year, month, 1);
- date.increment("month", -1)
- var thisYear = date.getFullYear();
- var thisMonth = date.getMonth();
- this._setDayTitle(null, thisYear, thisMonth);
- this._setDayDate(null,thisYear, thisMonth);
- this.fireEvent("changeViewToDay");
- },
- getNextMonth: function(){
- var year = this.currentTextNode.retrieve("year");
- var date = new Date(year, 1, 1);
- date.increment("year", 1)
- var thisYear = date.getFullYear();
- this.showMonth(thisYear);
- this.fireEvent("changeViewToMonth");
- },
- getPrevMonth: function(){
- var year = this.currentTextNode.retrieve("year");
- var date = new Date(year, 1, 1);
- date.increment("year", -1)
- var thisYear = date.getFullYear();
- this.showMonth(thisYear);
- this.fireEvent("changeViewToMonth");
- },
- getNextYear: function(){
- var year = this.currentTextNode.retrieve("year");
- var date = new Date(year, 1, 1);
- date.increment("year", this.yearLength)
- var thisYear = date.getFullYear();
- this.showYear(thisYear);
- this.fireEvent("changeViewToYear");
- },
- getPrevYear: function(){
- var year = this.currentTextNode.retrieve("year");
- var date = new Date(year, 1, 1);
- date.increment("year", 0-this.yearLength)
- var thisYear = date.getFullYear();
- this.showYear(thisYear);
- this.fireEvent("changeViewToYear");
- },
- outsideClick: function(e) {
- if(this.visible) {
- var elementCoords, targetCoords, page;
- if ( !layout.inBrowser && layout.userLayout && layout.userLayout.scale && layout.userLayout.scale!==1){
- elementCoords = this.container.getCoordinates( this.options.target );
- targetCoords = this.node.getCoordinates( this.options.target );
- var containerSize = this.options.target.getPosition();
- page = e.page;
- // elementCoords.left = elementCoords.left * layout.userLayout.scale;
- // elementCoords.top = elementCoords.top * layout.userLayout.scale;
- //
- // targetCoords.left = targetCoords.left * layout.userLayout.scale;
- // targetCoords.top = targetCoords.top * layout.userLayout.scale;
- //
- // containerSize.x = containerSize.x * layout.userLayout.scale;
- // containerSize.y = containerSize.y * layout.userLayout.scale;
- page.x = page.x / layout.userLayout.scale - containerSize.x;
- page.y = page.y / layout.userLayout.scale - containerSize.y;
- }else{
- elementCoords = this.container.getCoordinates();
- targetCoords = this.node.getCoordinates();
- page = e.page;
- }
- if(((page.x < elementCoords.left || page.x > (elementCoords.left + elementCoords.width)) ||
- (page.y < elementCoords.top || page.y > (elementCoords.top + elementCoords.height))) &&
- ((page.x < targetCoords.left || page.x > (targetCoords.left + targetCoords.width)) ||
- (page.y < targetCoords.top || page.y > (targetCoords.top + targetCoords.height))) ) this.hide();
- }
- },
- hide: function(){
- if (this.visible){
- // if (!this.morph){
- // this.morph = new Fx.Morph(this.container, {"duration": 200});
- // }
- this.visible = false;
- // this.changeViewToDay();
- // this.morph.start({"opacity": 0}).chain(function(){
- this.container.setStyle("display", "none");
- if (this.iframe) this.iframe.destroy();
- if (layout.desktop.offices){
- Object.each(layout.desktop.offices, function(office){
- office.show();
- });
- }
- if( this.maskNode ){
- this.maskNode.hide();
- }
- // }.bind(this));
- this.fireEvent("hide");
- }
- },
- show: function(){
- if (!this.visible){
- var dStr = this.node.get("value");
- if (dStr && Date.isValid(dStr)){
- this.options.baseDate = Date.parse(dStr.substr(0,10));
- }
- if(this.options.timeOnly){
- this.currentView = "time";
- }
- else{
- this.currentView = this.options.defaultView;
- }
- switch (this.currentView) {
- case "day" :
- this.changeViewToDay();
- break;
- case "month" :
- //this.showMonth();
- this.changeViewToMonth();
- break;
- case "year" :
- if( this.options.yearOnly ){
- this.changeViewToYear()
- }else{
- this.showYear();
- }
- break;
- case "time" :
- //this.showTime(this.options.baseDate);
- this.changeViewToTime(this.options.defaultDate);
- //this.changeViewToTime(this.options.baseDate);
- break;
- default :
- this.showDay();
- }
- // if (!this.morph){
- // this.morph = new Fx.Morph(this.container, {"duration": 200});
- // }
- this.container.setStyle("display", "block");
- this.setPosition();
- // var p = this.container.getPosition();
- // var s = this.container.getSize();
- // var zidx = this.container.getStyle("z-index");
- // this.iframe = new Element("iframe", {"styles":{
- // "border": "0px",
- // "margin": "0px",
- // "padding": "0px",
- // "opacity": 0,
- // "z-index": (zidx) ? zidx-1 : 0,
- // "top": ""+p.y+"px",
- // "left": ""+p.x+"px",
- // "width": ""+s.x+"px",
- // "height": ""+s.y+"px",
- // "position": "absolute"
- // }}).inject(this.container, "before");
- if (layout.desktop.offices){
- Object.each(layout.desktop.offices, function(office){
- if (this.container.isOverlap(office.officeNode)){
- office.hide();
- }
- }.bind(this));
- }
- if( this.maskNode ){
- this.maskNode.show();
- }
- // this.morph.start({"opacity": 1}).chain(function(){
- this.visible = true;
- // }.bind(this));
- this.fireEvent("show");
- }
- },
- setPosition: function(){
- //if (this.container.position && (!layout || !layout.userLayout || !layout.userLayout.scale || layout.userLayout.scale===1) ){
- var postY = "bottom";
- var postX = "left";
- this.container.position({
- relativeTo: this.node,
- position: 'bottomLeft',
- edge: 'upperLeft'
- });
- // var offsetPNode = this.node.getOffsetParent();
- var cp = this.container.getPosition(this.options.target || null);
- var cSize = this.container.getSize();
- //var fp = (this.options.target) ? this.options.target.getPosition() : $(document.body).getPosition()
- var fsize = (this.options.target) ? this.options.target.getSize() : $(document.body).getSize();
- //if (cp.y+cSize.y>fsize.y+fp.y){
- if (cp.y+cSize.y>fsize.y){
- // this.container.position({
- // relativeTo: this.node,
- // position: 'upperLeft',
- // edge: 'bottomLeft'
- // });
- postY = "upper";
- }
- if( cp.x+cSize.x>fsize.x ){
- postX = "right";
- }
- if( postY === "upper" && postX === "left" ){
- this.container.position({
- relativeTo: this.node,
- position: 'upperLeft',
- edge: 'bottomLeft'
- });
- }else if( postX === "right" ){
- if( postY === "bottom" ){
- this.container.position({
- relativeTo: this.node,
- position: 'bottomRight',
- edge: 'upperRight'
- });
- }else{
- this.container.position({
- relativeTo: this.node,
- position: 'upperRight',
- edge: 'bottomRight'
- });
- }
- }
- this.postY = postY;
- this.postX = postX;
- // }else{
- // var p = this.node.getPosition(this.options.target || null);
- // var size = this.node.getSize();
- // var containerSize = this.container.getSize();
- // var bodySize = (this.options.target) ? this.options.target.getSize() : $(document.body).getSize(); //$(document.body).getSize();
- //
- // bodySize.x = bodySize.x * layout.userLayout.scale;
- // bodySize.y = bodySize.y * layout.userLayout.scale;
- //
- // var left = p.x;
- // left = left * layout.userLayout.scale;
- // if ((left + containerSize.x + 40) > bodySize.x){
- // left = bodySize.x - containerSize.x - 40;
- // }
- //
- // var top = p.y+size.y+2;
- // top = top * layout.userLayout.scale;
- // if( top + containerSize.y > bodySize.y ){
- // top = bodySize.y - containerSize.y ;
- // }
- //
- //
- // this.container.setStyle("top", top);
- // this.container.setStyle("left", left);
- // }
- },
- showYear: function(year){
- var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
- var date = new Date(thisYear, 1, 1);
- date.increment("year", -2);
- var beginYear = date.getFullYear();
- date.increment("year", this.yearLength-1);
- var endYear = date.getFullYear();
- this._setYearTitle(null, beginYear, endYear, thisYear);
- this._setYearDate(null, beginYear, endYear, thisYear);
- this.showMonthYearButton();
- // if (!this.move){
- // this.move = true;
- // this.containerDrag = new Drag.Move(this.container);
- // }
- },
- _setYearTitle:function(node, beginYear, endYear, thisYear){
- var thisNode = node || this.currentTextNode;
- thisNode.set("text", beginYear+"-"+endYear);
- thisNode.store("year", thisYear);
- this.setTitleStyle();
- },
- _setYearDate: function(table, beginYear, endYear, year){
- var yearTable = table || this.contentYearTable;
- var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
- var tbody = yearTable.getElement("tbody");
- var tds = tbody.getElements("td");
- tds.each(function(item, idx){
- var y = beginYear+idx;
- item.set("text", y);
- item.store("year", y);
- if (y==this.options.baseDate.getFullYear()){
- item.addClass("current_"+this.options.style);
- }else{
- item.removeClass("current_"+this.options.style);
- }
- if( this.options.enableDate ){
- if( !this.isEnableDate(y+"-01-01") && !this.isEnableDate(y+"-12-12") ){
- // item.addClass("disable_"+this.options.style);
- item.setStyles(this.css["disable_"+this.options.style]);
- }else{
- // item.removeClass("disable_"+this.options.style);
- item.setStyles(this.css["notdisable_"+this.options.style]);
- }
- }
- }.bind(this));
- },
- showMonth: function(year, month){
- var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
- var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
- this._setMonthTitle(null, thisYear, thisMonth);
- this._setMonthDate(null, thisYear, thisMonth);
- this.showMonthYearButton();
- // if (!this.move){
- // this.move = true;
- // this.containerDrag = new Drag.Move(this.container);
- // }
- },
- _setMonthTitle:function(node, year){
- var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
- var thisNode = node || this.currentTextNode;
- thisNode.set("text", thisYear);
- thisNode.store("year", thisYear);
- this.setTitleStyle();
- },
- _setMonthDate: function(table, year, month){
- //var months = Locale.get("Date").months;
- var months = o2.LP.widget.months;
- var monthTable = table || this.contentMonthTable;
- var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
- var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
- var tbody = monthTable.getElement("tbody");
- var tds = tbody.getElements("td");
- tds.each(function(item, idx){
- item.set("text", months[idx].substr(0,2));
- item.store("year", thisYear);
- item.store("month", idx);
- if ((thisYear==this.options.baseDate.getFullYear()) && (idx==this.options.baseDate.getMonth())){
- item.addClass("current_"+this.options.style);
- }else{
- item.removeClass("current_"+this.options.style);
- }
- if( this.options.enableDate ){
- var flag = false;
- var m = this.addZero(idx + 1, 2 );
- if (this.isEnableDate(thisYear+"-"+m+"-01")){
- flag = true;
- }else if(this.isEnableDate(thisYear+"-"+m+"-"+new Date(thisYear+"-"+m+"-01").get('lastdayofmonth'))){
- flag = true;
- }
- if( !flag ){
- // item.addClass("disable_"+this.options.style);
- item.setStyles(this.css["disable_"+this.options.style]);
- }else{
- // item.removeClass("disable_"+this.options.style);
- item.setStyles(this.css["notdisable_"+this.options.style]);
- }
- }
- }.bind(this));
- },
- showDay: function(year, month){
- this._setDayTitle(null, year, month);
- this._setDayWeekTitleTh();
- this._setDayDate(null, year, month);
- // if (!this.move){
- // this.move = true;
- // this.containerDrag = new Drag.Move(this.container);
- // }
- },
- _setDayTitle: function(node, year, month){
- var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
- var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
- thisMonth++;
- var text = thisYear+ o2.LP.widget.year +thisMonth+ o2.LP.widget.month;
- var thisNode = node || this.currentTextNode;
- thisNode.set("text", text);
- thisNode.store("year", thisYear);
- thisNode.store("month", thisMonth);
- this.setTitleStyle();
- },
- _setDayDate: function(table, year, month){
- var dayTable = table || this.contentTable;
- var baseDate = this.options.baseDate;
- if ((year!=undefined) && (month!=undefined)){
- baseDate = new Date();
- baseDate.setDate(1);
- baseDate.setFullYear(year);
- baseDate.setMonth(month);
- baseDate.setHours( this.options.baseDate.getHours() );
- baseDate.setMinutes( this.options.baseDate.getMinutes() );
- baseDate.setSeconds( this.options.baseDate.getSeconds() );
- }
- var tbody = dayTable.getElement("tbody");
- var tds = tbody.getElements("td");
- var firstDate = baseDate.clone();
- firstDate.setDate(1);
- // var day = firstDate.getDay();
- var day = (7 + firstDate.getDay() - this.options.weekBegin) % 7;
- var tmpDate = firstDate.clone();
- for (var i=day-1; i>=0; i--){
- if( this.options.enableDate ){
- if( !this.isEnableDate(firstDate) ){
- tds[i].addClass("disable_"+this.options.style);
- tds[i].setStyles(this.css["disable_"+this.options.style]);
- }else{
- tds[i].removeClass("disable_"+this.options.style);
- tds[i].setStyles(this.css["notdisable_"+this.options.style]);
- }
- }
- tmpDate.increment("day", -1);
- tds[i].set("text", tmpDate.getDate());
- tds[i].addClass("gray_"+this.options.style);
- tds[i].setStyles(this.css["gray_"+this.options.style]);
- tds[i].store("dateValue", tmpDate.toString());
- tds[i].removeClass("today_"+this.options.style);
- tds[i].removeClass("current_"+this.options.style);
- tds[i].removeClass("past_"+this.options.style);
- if( this.options.todayClass ){
- tds[i].removeClass( this.options.todayClass );
- }
- }
- for (var i=day; i<tds.length; i++){
- tds[i].set("text", firstDate.getDate());
- if( this.options.enableDate ){
- if( !this.isEnableDate(firstDate) ){
- // tds[i].addClass("disable_"+this.options.style);
- tds[i].setStyles(this.css["disable_"+this.options.style]);
- }else{
- // tds[i].removeClass("disable_"+this.options.style);
- tds[i].setStyles(this.css["notdisable_"+this.options.style]);
- }
- }
- if (firstDate.toString() == this.options.baseDate.toString()){
- tds[i].addClass("current_"+this.options.style);
- tds[i].setStyles(this.css["current_"+this.options.style]);
- tds[i].removeClass("past_"+this.options.style);
- tds[i].removeClass("gray_"+this.options.style);
- tds[i].setStyle("border", "1px solid #FFF");
- }else if (firstDate.getMonth()!=baseDate.getMonth()){
- tds[i].addClass("gray_"+this.options.style);
- tds[i].setStyles(this.css["gray_"+this.options.style]);
- tds[i].removeClass("current_"+this.options.style);
- tds[i].removeClass("past_"+this.options.style);
- tds[i].setStyle("border", "1px solid #FFF");
- }else{
- tds[i].setStyles(this.css["normal_"+this.options.style]);
- tds[i].removeClass("current_"+this.options.style);
- tds[i].removeClass("gray_"+this.options.style);
- tds[i].removeClass("past_"+this.options.style);
- tds[i].setStyle("border", "1px solid #FFF");
- }
- var tmp = firstDate.clone();
- if (tmp.clearTime().toString() == this.today.clearTime().toString()){
- tds[i].addClass("today_"+this.options.style);
- tds[i].removeClass("past_"+this.options.style);
- tds[i].setStyles(this.css["today_"+this.options.style]);
- tds[i].setStyle("border", "0px solid #AAA");
- if( this.options.todayClass ){
- tds[i].addClass( this.options.todayClass );
- }
- }else{
- tds[i].removeClass("today_"+this.options.style);
- if( this.options.todayClass ){
- tds[i].removeClass( this.options.todayClass );
- }
- }
- if (tmp.diff(this.today)>0){
- if (this.css["past_"+this.options.style]) tds[i].setStyles(this.css["past_"+this.options.style]);
- tds[i].addClass("past_"+this.options.style);
- }
- tds[i].store("dateValue", firstDate.toString());
- firstDate.increment("day", 1);
- }
- },
- changeViewToTime: function(date){
- this.currentView = "time";
- if (!this.contentTimeTable){
- this.contentTimeTable = this.createContentTable();
- this.contentTimeTable.inject(this.contentDateNode);
- }
- if (this.contentTable) this.contentTable.setStyle("display", "none");
- if (this.contentYearTable) this.contentYearTable.setStyle("display", "none");
- if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "none");
- if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "block");
- // if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "table");
- var thisDate = date || this.options.baseDate;
- this.showTime(thisDate);
- this.hideMonthYearButton();
- },
- showTime: function(date){
- var thisHour = (date || this.options.baseDate).getHours();
- var thisMinutes = (date || this.options.baseDate).getMinutes();
- var thisSeconds = (date || this.options.baseDate).getSeconds();
- // var times = this.options.defaultTime.split(":");
- //
- // var thisHour = (times[0]) ? times[0] : "0";
- // var thisMinutes = (times[1]) ? times[1] : "0";
- // var thisSeconds = (times[2]) ? times[2] : "0";
- this._setTimeTitle(null, date);
- if( this.options.style.indexOf("mobile") > -1 ){
- this._setTimeDate_mobile(null, thisHour, thisMinutes, thisSeconds);
- }else{
- this._setTimeDate(null, thisHour, thisMinutes, thisSeconds);
- }
- // if (this.move){
- // this.move = false;
- // this.container.removeEvents("mousedown");
- // }
- },
- _setTimeTitle: function(node, date){
- var thisDate = date || this.options.baseDate;
- var thisNode = node || this.currentTextNode;
- var y = thisDate.getFullYear();
- var m = thisDate.getMonth()+1;
- var d = thisDate.getDate();
- var text = "" + y + o2.LP.widget.year + m + o2.LP.widget.month + d + o2.LP.widget.date;
- if (this.options.timeOnly){
- thisNode.hide();
- if (this.prevNode) this.prevNode.hide();
- if (this.nextNode) this.nextNode.hide();
- }
- thisNode.set("text", text);
- thisNode.store("date", date);
- this.cDate = date;
- this.setTitleStyle();
- },
- _setTimeDate_mobile: function(node, h, m, s){
- var _self = this;
- this.itmeHNode = this.contentTimeTable.getElement(".MWF_calendar_time_h");
- this.itmeMNode = this.contentTimeTable.getElement(".MWF_calendar_time_m");
- this.itmeSNode = this.contentTimeTable.getElement(".MWF_calendar_time_s");
- this.showActionNode = this.contentTimeTable.getElement(".MWF_calendar_action_show");
- var calendar = this;
- var div, items;
- this.calculateCurrentHour(h);
- if( this.hMobileSelect ){
- this.itmeHNode.empty();
- this.hMobileSelect = null;
- }
- items = [];
- for( var i=0; i<24; i++ ) {
- div = new Element("div.hselect", {
- "text": this.addZero(i, 2),
- "styles": this.css.calendarTimeSelectItem_mobile
- }).inject(this.itmeHNode);
- div.store("d", i);
- if (!this.isEnableHour(this.cDate, i)){
- div.hide();
- }else{
- items.push(i);
- }
- }
- this.selectedHour = this.cHour; //this.addZero(h, 2 );
- this.hMobileSelect = new o2.Calendar.MobileSelect( this.itmeHNode.getParent(), {
- "lineHeight" : 40,
- "items" : items, //24,
- "currentItem" : parseInt( this.cHour ),
- "onChange": function(value){
- this.selectedHour = value; //this.addZero(value, 2 );
- this.cHour = this.selectedHour;
- if( this.options.enableMinutes )this._resetMinuteSelect_mobile();
- if( this.options.enableSeconds )this._resetSecondSelect_mobile();
- //this.showHNode.set("text", this.addZero(i, 2 ));
- //this.itmeHNode.getFirst().set("text", this.addZero(i, 2 ));
- }.bind(this)
- });
- this.hMobileSelect.load();
- this.calculateCurrentMinute(m);
- if( this.mMobileSelect ){
- this.itmeMNode.empty();
- this.mMobileSelect = null;
- }
- items = [];
- for (var i = 0; i < 60; i++) {
- div = new Element("div.mselect", {
- "text": this.addZero(i, 2),
- "styles": this.css.calendarTimeSelectItem_mobile
- }).inject(this.itmeMNode);
- div.store("d", i);
- if (!this.isEnableMinute(this.cDate, this.cHour, i)) {
- div.hide();
- }else{
- items.push(i);
- }
- }
- this.selectedMinute = this.cMinute; //this.addZero(m, 2);
- this.mMobileSelect = new o2.Calendar.MobileSelect(this.itmeMNode.getParent(), {
- "lineHeight": 40,
- "items": items, //60,
- "currentItem": parseInt(this.cMinute),
- "onChange": function (value) {
- this.selectedMinute = value; //this.addZero(value, 2);
- //this.showHNode.set("text", this.addZero(i, 2 ));
- //this.itmeHNode.getFirst().set("text", this.addZero(i, 2 ));
- this.cMinute = this.selectedMinute;
- if( this.options.enableSeconds )this._resetSecondSelect_mobile();
- }.bind(this)
- });
- this.mMobileSelect.load();
- if(this.options.secondEnable ){
- this.calculateCurrentSecond(s);
- if( this.sMobileSelect ){
- this.itmeSNode.empty();
- this.sMobileSelect = null;
- }
- items = [];
- for( var i=0; i<60; i++ ){
- div = new Element("div.sselect",{
- "text" : this.addZero(i, 2 ),
- "styles" : this.css.calendarTimeSelectItem_mobile
- }).inject( this.itmeSNode );
- div.store("d", i);
- if (!this.isEnableMinute(this.cDate, this.cHour, this.cMinute, i)) {
- div.hide();
- }else{
- items.push(i);
- }
- }
- this.selectedSecond = this.cSecond; //this.addZero(s, 2 );
- this.sMobileSelect = new o2.Calendar.MobileSelect( this.itmeSNode.getParent(), {
- "lineHeight" : 40,
- "items" : items, //60,
- "currentItem" : parseInt(this.cSecond),
- "onChange": function(value){
- this.selectedSecond = value; //this.addZero(value, 2 );
- //this.showHNode.set("text", this.addZero(i, 2 ));
- //this.itmeHNode.getFirst().set("text", this.addZero(i, 2 ));
- this.cSecond = this.selectedSecond;
- }.bind(this)
- });
- this.sMobileSelect.load();
- }else{
- this.itmeSNode.hide();
- }
- if( this.options.secondEnable ){
- this.contentTimeTable.getElements(".calendarTimeWheel_mobile").setStyle("width","33.3%");
- }else{
- this.contentTimeTable.getElements(".calendarTimeWheel_mobile").setStyle("width","50%");
- }
- if( this.options.secondEnable && this.showSNode ){
- this.showSNode.set("text", this.addZero( s.toInt(), 2) );
- }
- if (!this.okButton){
- this.okButton = new Element("button.mainColor_bg", {"text": o2.LP.widget.ok }).inject(this.showActionNode);
- this.okButton.addEvent("click", function(){
- this._selectTime();
- this.hide();
- }.bind(this));
- this.okButton.setStyles(this.css.calendarActionShowButton_mobile_ok);
- }
- if (!this.clearButton && this.options.clearEnable){
- this.clearButton = new Element("button", {"text": o2.LP.widget.clear }).inject(this.showActionNode);
- this.clearButton.addEvent("click", function(){
- var t = this.node.get("value");
- this.node.set("value", "");
- if( t )this.fireEvent("change");
- this.fireEvent("clear");
- this.hide();
- }.bind(this));
- this.clearButton.setStyles(this.css.calendarActionShowButton_mobile_cancel);
- }
- },
- _setTimeDate: function(node, h, m, s){
- if( !this.options.secondEnable ){
- var div = this.contentTimeTable.getElement(".MWF_calendar_time_s");
- if( div )div.hide();
- div = this.contentTimeTable.getElement(".MWF_calendar_time_show_s");
- if( div )div.hide();
- }
- this.itmeHNode = this.contentTimeTable.getElement(".MWF_calendar_time_h_slider");
- this.itmeMNode = this.contentTimeTable.getElement(".MWF_calendar_time_m_slider");
- this.itmeSNode = this.contentTimeTable.getElement(".MWF_calendar_time_s_slider");
- this.timeShowNode = this.contentTimeTable.getElement(".MWF_calendar_time_show");
- this.timeShowNode.addEvent("click", function(){
- this._selectTime();
- }.bind(this));
- this.showHNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_h");
- this.showMNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_m");
- this.showSNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_s");
- this.showActionNode = this.contentTimeTable.getElement(".MWF_calendar_action_show");
- var calendar = this;
- if ( COMMON.Browser.Platform.isMobile ){
- this.showHNode.set("text", this.addZero( h.toInt(), 2) );
- this.showMNode.set("text", this.addZero( m.toInt(), 2));
- if( this.options.secondEnable && this.showSNode ){
- this.showSNode.set("text", this.addZero( s.toInt(), 2) );
- }
- }else{
- if(this.options.timeSelectType === "select"){
- this.loadHourSelect(h);
- this.loadMinuteSelect(m);
- this.loadSecondSelect(s);
- }else {
- this.calculateCurrentHour(h);
- this.createDisabledNodes(this.itmeHNode, 24, "h");
- var hourChangehandler = o2.Calendar.antiShake( function ( value ){
- var value1 = Math.round(value);
- var nearValue = this.isEnableHour(this.cDate, value1, true);
- var v = nearValue === true ? value1 : nearValue;
- if( this.selectedHour === v )return;
- this.selectedHour = v;
- this.cHour = v;
- this.showHNode.set("text", this.addZero(v, 2));
- this.itmeHNode.getFirst().set("text", this.addZero(v, 2));
- if( this.options.enableMinutes ){
- this.calculateCurrentMinute();
- this.createDisabledNodes(this.itmeMNode, 60, "m");
- this.mSlider.set( this.cMinute );
- this.itmeMNode.getFirst().set("text", this.addZero( this.cMinute, 2));
- this.showMNode.set("text", this.addZero( this.cMinute, 2));
- }
- if( this.options.enableSeconds && this.sSlider ){
- this.calculateCurrentSecond();
- this.createDisabledNodes(this.itmeSNode, 60, "s");
- this.sSlider.set( this.cSecond );
- this.itmeSNode.getFirst().set("text", this.addZero( this.cSecond, 2));
- this.showSNode.set("text", this.addZero( this.cSecond, 2) );
- }
- }.bind(this), 200, this);
- this.hSlider = new Slider(this.itmeHNode, this.itmeHNode.getFirst(), {
- range: [0, 23],
- initialStep: this.cHour,
- onChange: function(value){
- hourChangehandler(value);
- }.bind(this)
- });
- // if( this.options.enableHours ){
- // this.hSlider.setRange( this.getEnableHourStartEnd(this.cDate) );
- // }
- this.itmeHNode.getFirst().set("text", this.addZero( this.cHour, 2));
- this.showHNode.set("text", this.addZero( this.cHour, 2) );
- this.calculateCurrentMinute(m);
- this.createDisabledNodes(this.itmeMNode, 60, "m");
- var minuteChangehandler = o2.Calendar.antiShake( function(value){
- var value1 = Math.round(value);
- var nearValue = this.isEnableMinute(this.cDate, this.cHour, value1, true);
- var v = nearValue === true ? value1 : nearValue;
- if( this.selectedMinute === v )return;
- this.selectedMinute = v;
- this.cMinute = v;
- this.showMNode.set("text", this.addZero( v, 2));
- this.itmeMNode.getFirst().set("text", this.addZero( v, 2));
- if( this.options.enableSeconds && this.sSlider ){
- this.calculateCurrentSecond();
- this.createDisabledNodes(this.itmeSNode, 60, "s");
- this.sSlider.set( this.cSecond );
- this.itmeSNode.getFirst().set("text", this.addZero( this.cSecond, 2));
- this.showSNode.set("text", this.addZero( this.cSecond, 2) );
- }
- }.bind(this), 200, this);
- this.mSlider = new Slider(this.itmeMNode, this.itmeMNode.getFirst(), {
- range: [0, 59],
- initialStep: this.cMinute,
- onChange: function(value){
- minuteChangehandler(value);
- }.bind(this)
- });
- this.itmeMNode.getFirst().set("text", this.addZero( this.cMinute, 2));
- this.showMNode.set("text", this.addZero( this.cMinute, 2));
- if( this.options.secondEnable && this.itmeSNode ){
- this.calculateCurrentSecond(s);
- this.createDisabledNodes(this.itmeSNode, 60, "s");
- var secondChangehandler = o2.Calendar.antiShake( function(value){
- var value1 = Math.round(value);
- var nearValue = this.isEnableSecond(this.cDate, this.cHour, this.cMinute, value1, true);
- var v = nearValue === true ? value1 : nearValue;
- if( this.selectedSecond === v )return;
- this.selectedSecond = v;
- this.cSecond = v;
- this.showSNode.set("text", this.addZero( v, 2));
- this.itmeSNode.getFirst().set("text", this.addZero( v, 2));
- }.bind(this), 200, this);
- this.sSlider = new Slider(this.itmeSNode, this.itmeSNode.getFirst(), {
- range: [0, 59],
- initialStep: this.cSecond,
- onChange: function(value){
- secondChangehandler(value);
- }.bind(this)
- });
- this.itmeSNode.getFirst().set("text", this.addZero( this.cSecond, 2));
- this.showSNode.set("text", this.addZero( this.cSecond, 2) );
- }
- // this.showHNode.set("text", this.addZero( h.toInt(), 2) );
- // this.showMNode.set("text", this.addZero( m.toInt(), 2));
- // if( this.options.secondEnable && this.showSNode ){
- // this.showSNode.set("text", this.addZero( s.toInt(), 2) );
- // }
- }
- }
- if (!this.okButton){
- this.okButton = new Element("button", {"text": o2.LP.widget.ok}).inject(this.showActionNode);
- this.okButton.addEvent("click", function(){
- this._selectTime();
- this.hide();
- }.bind(this));
- this.okButton.setStyles(this.css.calendarActionShowButton);
- }
- if (!this.clearButton && this.options.clearEnable){
- this.clearButton = new Element("button", {"text": o2.LP.widget.clear }).inject(this.showActionNode);
- this.clearButton.addEvent("click", function(){
- var t = this.node.get("value");
- this.node.set("value", "");
- if( t )this.fireEvent("change");
- this.fireEvent("clear");
- this.hide();
- }.bind(this));
- this.clearButton.setStyles(this.css.calendarActionShowButton);
- }
- },
- _resetTimeDate: function(){
- if( this.options.style.indexOf("mobile") > -1 ){
- if( this.options.enableHours )this._resetHourSelect_mobile();
- if( this.options.enableMinutes )this._resetMinuteSelect_mobile();
- if( this.options.enableSeconds )this._resetSecondSelect_mobile();
- }else{
- if(this.options.timeSelectType === "select"){
- if( this.options.enableHours )this.loadHourSelect();
- if( this.options.enableMinutes )this.loadMinuteSelect();
- if( this.options.enableSeconds )this.loadSecondSelect();
- }else {
- if( this.options.enableHours ){
- this.calculateCurrentHour();
- this.createDisabledNodes(this.itmeHNode, 24, "h");
- this.hSlider.set( this.cHour );
- this.itmeHNode.getFirst().set("text", this.addZero( this.cHour, 2));
- this.showHNode.set("text", this.addZero( this.cHour, 2) );
- }
- if( this.options.enableMinutes ){
- this.calculateCurrentMinute();
- this.createDisabledNodes(this.itmeMNode, 60, "m");
- this.mSlider.set( this.cMinute );
- this.itmeMNode.getFirst().set("text", this.addZero( this.cMinute, 2));
- this.showMNode.set("text", this.addZero( this.cMinute, 2));
- }
- if( this.options.enableSeconds && this.sSlider ){
- this.calculateCurrentSecond();
- this.createDisabledNodes(this.itmeSNode, 60, "s");
- this.sSlider.set( this.cSecond );
- this.itmeSNode.getFirst().set("text", this.addZero( this.cSecond, 2));
- this.showSNode.set("text", this.addZero( this.cSecond, 2) );
- }
- }
- }
- },
- _resetHourSelect_mobile: function(){
- if( this.options.enableHours ){
- this.calculateCurrentHour();
- var items = [];
- this.itmeHNode.getElements(".hselect").each(function(div, i){
- if( this.isEnableHour(this.cDate, div.retrieve("d")) ){
- items.push(i);
- div.show();
- }else{
- div.hide();
- }
- }.bind(this));
- this.selectedHour = this.cHour;
- this.hMobileSelect.resetItems(items, parseInt(this.cHour));
- }
- },
- _resetMinuteSelect_mobile: function(){
- if( this.options.enableMinutes ) {
- this.calculateCurrentMinute();
- var items = [];
- this.itmeMNode.getElements(".mselect").each(function(div, i){
- if( this.isEnableMinute(this.cDate, this.cHour, div.retrieve("d")) ){
- items.push(i);
- div.show();
- }else{
- div.hide();
- }
- }.bind(this));
- this.selectedMinute = this.cMinute;
- this.mMobileSelect.resetItems(items, parseInt(this.cMinute));
- }
- },
- _resetSecondSelect_mobile: function(){
- if( this.options.enableSeconds && this.options.secondEnable ){
- this.calculateCurrentSecond();
- var items = [];
- this.itmeSNode.getElements(".sselect").each(function(div, i){
- if( this.isEnableSecond(this.cDate, this.cHour, this.cMinute, div.retrieve("d")) ){
- items.push(i);
- div.show();
- }else{
- div.hide();
- }
- }.bind(this));
- this.selectedSecond = this.cSecond;
- if(this.sMobileSelect)this.sMobileSelect.resetItems(items, parseInt(this.cSecond));
- }
- },
- loadHourSelect: function (h) {
- this.itmeHNode = this.contentTimeTable.getElement(".MWF_calendar_time_h").empty();
- new Element("span",{"text": o2.LP.widget.hour + ":"}).inject(this.itmeHNode);
- this.itmeSelectHNode = new Element("select").inject(this.itmeHNode);
- this.calculateCurrentHour(h);
- for( var i=0; i<24; i++ ){
- if( this.isEnableHour(this.cDate, i) ){
- var opt = new Element("option",{
- "text" : this.addZero(i, 2 ),
- "value" : this.addZero(i, 2 ),
- "styles" : this.css.calendarTimeSelectItem_mobile
- }).inject( this.itmeSelectHNode );
- if (Browser.name === "firefox") {
- opt.addEvent( "mousedown", function(e){ e.stopPropagation(); });
- }
- if( i === this.cHour )opt.set("selected", true);
- }
- }
- // this.itmeSelectHNode.set("value",this.addZero( this.cHour, 2));
- this.showHNode.set("text", this.addZero( this.cHour, 2) );
- this.itmeSelectHNode.addEvent("change",function(){
- this.cHour = this.itmeSelectHNode.get("value").toInt();
- this.selectedHour = this.cHour;
- this.showHNode.set("text", this.itmeSelectHNode.get("value") );
- if( this.options.enableMinutes )this.loadMinuteSelect();
- if( this.options.enableSeconds )this.loadSecondSelect();
- }.bind(this));
- },
- loadMinuteSelect: function (m) {
- this.itmeMNode = this.contentTimeTable.getElement(".MWF_calendar_time_m").empty();
- new Element("span", {"text": o2.LP.widget.minute + ":"}).inject(this.itmeMNode);
- this.itmeSelectMNode = new Element("select").inject(this.itmeMNode);
- this.calculateCurrentMinute(m);
- for (var i = 0; i < 60; i++) {
- if (this.isEnableMinute(this.cDate, this.cHour || 0, i)) {
- var opt = new Element("option", {
- "text": this.addZero(i, 2),
- "value": this.addZero(i, 2),
- "styles": this.css.calendarTimeSelectItem_mobile
- }).inject(this.itmeSelectMNode);
- if (Browser.name === "firefox") {
- opt.addEvent( "mousedown", function(e){ e.stopPropagation(); });
- }
- if( i === this.cMinute )opt.set("selected", true);
- }
- }
- // this.itmeSelectMNode.set("value", this.addZero(this.cMinute, 2));
- this.showMNode.set("text", this.addZero( this.cMinute, 2) );
- this.itmeSelectMNode.addEvent("change", function () {
- this.cMinute = this.itmeSelectMNode.get("value").toInt();
- this.selectedMinute = this.cMinute;
- this.showMNode.set("text", this.itmeSelectMNode.get("value"));
- if( this.options.enableSeconds )this.loadSecondSelect();
- }.bind(this));
- },
- loadSecondSelect: function (s) {
- this.itmeSNode = this.contentTimeTable.getElement(".MWF_calendar_time_s").empty();
- this.cSecond = typeOf(s) !== "null" ? s.toInt() : 0;
- if( this.options.secondEnable && this.itmeSNode ){
- new Element("span",{"text":o2.LP.widget.second + ":"}).inject(this.itmeSNode);
- this.itmeSelectSNode = new Element("select").inject(this.itmeSNode);
- this.calculateCurrentSecond(s);
- for( var i=0; i<60; i++ ){
- if( this.isEnableSecond(this.cDate, this.cHour || 0, this.cMinute || 0, i) ){
- var opt = new Element("option",{
- "text" : this.addZero(i, 2 ),
- "value" : this.addZero(i, 2 ),
- "styles" : this.css.calendarTimeSelectItem_mobile,
- "events": { click: function(e){ e.stopPropagation(); e.preventDefault(); } }
- }).inject( this.itmeSelectSNode );
- if (Browser.name === "firefox") {
- opt.addEvent( "mousedown", function(e){ e.stopPropagation(); });
- }
- if( i === this.cSecond )opt.set("selected", true);
- }
- }
- // this.itmeSelectSNode.set("value",this.addZero( this.cSecond, 2));
- this.showSNode.set("text", this.addZero( this.cSecond, 2) );
- this.itmeSelectSNode.addEvent("change",function(){
- this.cSecond = this.itmeSelectSNode.get("value").toInt();
- this.selectedSecond = this.cSecond;
- this.showSNode.set("text", this.itmeSelectSNode.get("value") );
- }.bind(this));
- }
- },
- calculateCurrentHour: function(h){
- if( typeOf(h) !== "null" ){
- this.cHour = h.toInt();
- }else if( typeOf(this.selectedHour) !== "null" ){
- this.cHour = this.selectedHour;
- }else{
- this.cHour = 0;
- }
- if( !this.isEnableHour(this.cDate, this.cHour) ) {
- var eHours = this.getEnableHours(this.cDate);
- if( eHours.length ){
- this.cHour = typeOf( eHours[0] ) === "array" ? eHours[0][0] : eHours[0];
- }else{
- this.cHour = 0;
- }
- }
- this.selectedHour = this.cHour;
- return this.cHour;
- },
- calculateCurrentMinute: function(m){
- if( typeOf(m) !== "null" ){
- this.cMinute = m.toInt();
- }else if( typeOf(this.selectedMinute) !== "null" ){
- this.cMinute = this.selectedMinute;
- }else{
- this.cMinute = 0;
- }
- if( !this.isEnableMinute(this.cDate, this.cHour, this.cMinute) ){
- var eMinutes = this.getEnableMinutes(this.cDate, this.cHour);
- if( eMinutes.length ){
- this.cMinute = typeOf( eMinutes[0] ) === "array" ? eMinutes[0][0] : eMinutes[0]
- }else{
- this.cMinute = 0;
- }
- }
- this.selectedMinute = this.cMinute;
- return this.cMinute;
- },
- calculateCurrentSecond: function(s){
- if( typeOf(s) !== "null" ){
- this.cSecond = s.toInt();
- }else if( typeOf(this.selectedSecond) !== "null" ){
- this.cSecond = this.selectedSecond;
- }else{
- this.cSecond = 0;
- }
- if( !this.isEnableSecond(this.cDate, this.cHour, this.cMinute, this.cSecond) ){
- var eSeconds = this.getEnableSeconds(this.cDate, this.cHour, this.cMinute);
- if( eSeconds.length ){
- this.cSecond = typeOf( eSeconds[0] ) === "array" ? eSeconds[0][0] : eSeconds[0]
- }else{
- this.cSecond = 0;
- }
- }
- this.selectedSecond = this.cSecond;
- return this.cSecond;
- },
- createDisabledNodes: function(area, length, type){
- area.getElements(".disable_node").destroy();
- var array;
- switch(type){
- case "h": array = this.getDisabledHours(this.cDate); break;
- case "m": array = this.getDisabledMinutes(this.cDate, this.cHour || 0); break;
- case "s": array = this.getDisabledSeconds(this.cDate, this.cHour || 0, this.cMinute || 0); break;
- }
- if( !array || !array.length )return false;
- area.setStyle("position", "relative");
- if( typeOf(array[0]) === "array" ){
- for( var i=0; i< array.length; i++ ){
- this.createDisabledNode( area, length, array[i] );
- }
- }else{
- this.createDisabledNode( area, length, array );
- }
- },
- createDisabledNode: function(area, length, range){
- var s = area.getSize();
- var width = s.x / length * (range[1] - range[0] + 1);
- var left = s.x / length * range[0];
- new Element("div.disable_node", {
- styles: {
- "position": "absolute",
- "background": "#ccc",
- "width": width+"px",
- "height": s.y,
- "left": left,
- "top": "0px"
- }
- }).inject(area);
- },
- addZero : function( str, length ){
- var zero = "";
- str = str.toString();
- for( var i=0; i<length; i++ ){
- zero = zero + "0";
- }
- var s = zero + str;
- return s.substr(s.length - length, length );
- },
- _selectTime: function(){
- var date = this.currentTextNode.retrieve("date");
- var h = typeOf(this.selectedHour) !== "null" ? this.selectedHour : this.showHNode.get("text");
- var m = typeOf(this.selectedMinute) !== "null" ? this.selectedMinute : this.showMNode.get("text");
- date.setHours(h);
- date.setMinutes(m);
- if( this.options.secondEnable && ( typeOf(this.selectedSecond) !== "null" || this.showSNode) ){
- var s = typeOf(this.selectedSecond) !== "null" ? this.selectedSecond : this.showSNode.get("text");
- date.setSeconds(s);
- }
- if (!this.options.beforeCurrent){
- var now = new Date();
- if (date.getTime()-now.getTime()<0){
- alert( o2.LP.widget.dateGreaterThanCurrentNotice );
- this.node.focus();
- return false;
- }
- }
- var dv = date.format(this.options.format);
- if (this.fireEvent("queryComplate", [dv, date])){
- var t = this.node.get("value");
- this.options.defaultTime = ""+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
- this.node.set("value", dv);
- // this.node.focus();
- this.hide();
- if (t!=dv) this.fireEvent("change", [dv, date, t]);
- this.fireEvent("complate", [dv, date]);
- }
- },
- _selectDate: function(dateStr){
- if( this.options.yearOnly ){
- dateStr = dateStr+"-01-01"
- }else if( this.options.monthOnly ){
- dateStr = dateStr+"-01"
- }
- var date = new Date(dateStr);
- this.options.baseDate = date;
- var dv = date.format(this.options.format);
- if (this.options.isTime){
- this.changeViewToTime(date);
- }else{
- if (!this.options.beforeCurrent){
- var now = new Date();
- date.setHours(23,59,59);
- if (date.getTime()-now.getTime()<0){
- alert( o2.LP.widget.dateGreaterThanCurrentNotice );
- this.node.focus();
- return false;
- }
- }
- if (this.fireEvent("queryComplate", [dv, date])){
- var t = this.node.get("value");
- this.node.set("value", dv);
- this.hide();
- if (t!=dv) this.fireEvent("change", [dv, date, t]);
- this.fireEvent("complate", [dv, date, t]);
- }
- }
- },
- _setDayWeekTitleTh: function(table){
- var dayTable = table || this.contentTable;
- var thead = dayTable.getElement("thead");
- var cells = thead.getElements("th");
- if (this.css.calendarDaysContentTh) cells.setStyles(this.css.calendarDaysContentTh);
- //var days_abbr = Locale.get("Date").days_abbr;
- var days_abbr = o2.LP.widget.days_abbr;
- cells.each(function(item, idx){
- item.set("text", days_abbr[ (idx + this.options.weekBegin) % 7 ]);
- }.bind(this));
- return cells;
- },
- setTitleStyle: function(){
- if( this.options.enableDate ){
- if( this.currentView === "time" ){
- var date = this.currentTextNode.retrieve("date");
- if( this.isEnableDate(date.clone().decrement()) ){
- this.prevNode.setStyles(this.css["notdisable_"+this.options.style]);
- }else{
- this.prevNode.setStyles(this.css["disable_"+this.options.style]);
- }
- if( this.isEnableDate(date.clone().increment()) ){
- this.nextNode.setStyles(this.css["notdisable_"+this.options.style]);
- }else{
- this.nextNode.setStyles(this.css["disable_"+this.options.style]);
- }
- }else{
- this.prevNode.setStyles(this.css["notdisable_"+this.options.style]);
- this.nextNode.setStyles(this.css["notdisable_"+this.options.style]);
- }
- }
- },
- createContainer: function(){
- var div = null;
- var request = new Request.HTML({
- url: this.options.containerPath,
- method: "GET",
- async: false,
- onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
- div = responseTree[0];
- }
- });
- request.send();
- //this.containerNode = div.getElement(".MWF_calendar_container");
- this.titleNode = div.getElement(".MWF_calendar_title");
- this.prevNode = div.getElement(".MWF_calendar_prev");
- this.currentNode = div.getElement(".MWF_calendar_current");
- this.currentTextNode = div.getElement(".MWF_calendar_currentText");
- this.nextNode = div.getElement(".MWF_calendar_next");
- this.contentNode = div.getElement(".MWF_calendar_content");
- this.contentDateNode = div.getElement(".MWF_calendar_content_date");
- this.contentTimeNode = div.getElement(".MWF_calendar_content_time");
- this.buttonArea = div.getElement(".MWF_calendar_button_area");
- this.bottomNode = div.getElement(".MWF_calendar_bottom");
- div.setStyles(this.css.container);
- this.titleNode.setStyles(this.css.dateTitle);
- this.prevNode.setStyles(this.css.datePrev);
- this.currentNode.setStyles(this.css.dateCurrent);
- debugger;
- this.currentTextNode.setStyles(this.css.dateCurrentText);
- this.nextNode.setStyles(this.css.dateNext);
- this.contentNode.setStyles(this.css.calendarContent);
- if(this.buttonArea)this.buttonArea.setStyles(this.css.buttonArea);
- this.bottomNode.setStyles(this.css.dateBottom);
- return div;
- },
- createContentTable: function(){
- var table = null;
- var request = new Request.HTML({
- url: this.options[this.currentView+"Path"],
- method: "GET",
- async: false,
- onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
- table = responseTree[0];
- }
- });
- request.send();
- var tbody = table.getElement("tbody");
- if (tbody){
- var tds = tbody.getElements("td");
- var calendar = this;
- tds.addEvent("click", function(){
- switch (calendar.currentView) {
- case "day" :
- var d = this.retrieve("dateValue");
- if( calendar.isEnableDate(d) ){
- calendar._selectDate(d, this);
- }
- break;
- case "month" :
- var flag = true;
- if( calendar.options.enableDate ){
- flag = false;
- d = calendar.addZero(this.retrieve("month").toInt() + 1, 2 );
- var y = this.retrieve("year");
- if (calendar.isEnableDate(y+"-"+d+"-01")){
- flag = true;
- }else if(calendar.isEnableDate(y+"-"+d+"-"+new Date(y+"-"+d+"-01").get('lastdayofmonth'))){
- flag = true;
- }
- }
- if( flag ){
- if( calendar.options.monthOnly ){
- var m = calendar.addZero(this.retrieve("month").toInt() + 1, 2 );
- calendar._selectDate(this.retrieve("year")+"-"+ m , this);
- }else{
- calendar.changeViewToDay(this.retrieve("year"), this.retrieve("month"));
- }
- }
- break;
- case "year" :
- d = this.retrieve("year");
- if (calendar.isEnableDate(d+"-01-01") || calendar.isEnableDate(d+"-12-12")){
- if( calendar.options.yearOnly ){
- calendar._selectDate(this.retrieve("year"), this);
- }else{
- calendar.changeViewToMonth(this.retrieve("year"));
- }
- }
- break;
- case "time" :
- //nothing
- break;
- default :
- //nothing;
- }
- });
- switch (this.currentView) {
- case "day" :
- if (!table.display) table.display="";
- if (!table.style.display) table.style.display="";
- table.setStyles(this.css.calendarDaysContent);
- tds.setStyles(this.css.calendarDaysContentTd);
- break;
- case "month" :
- table.setStyles(this.css.calendarMonthsContent);
- tds.setStyles(this.css.calendarMonthsContentTd);
- break;
- case "year" :
- this.yearLength = tds.length;
- table.setStyles(this.css.calendarYearsContent);
- tds.setStyles(this.css.calendarYearsContentTd);
- break;
- case "time" :
- if( this.options.style.indexOf("mobile") > -1 ){
- var nodes = table.getElements(".calendarTimeContent_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeContent_mobile);
- nodes = table.getElements(".calendarTimeFixWidthNode_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeFixWidthNode_mobile);
- nodes = table.getElements(".calendarTimeWheels_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeWheels_mobile);
- nodes = table.getElements(".calendarTimeWheel_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeWheel_mobile);
- nodes = table.getElements(".calendarTimeSelectContainer_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectContainer_mobile);
- nodes = table.getElements(".calendarTimeSelectLine_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectLine_mobile);
- nodes = table.getElements(".calendarTimeShadowMask_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeShadowMask_mobile);
- var node = table.getElement(".MWF_calendar_action_show");
- if (node){
- node.setStyles(this.css.calendarActionShow);
- //var buttons = node.getElements("button");
- //buttons.setStyles(this.css.calendarActionShowButton);
- }
- }else{
- var nodes = table.getElements(".calendarTimeArea");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeArea);
- nodes = table.getElements(".calendarTimeSlider");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeSlider);
- nodes = table.getElements(".calendarTimeSliderKnob");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeSliderKnob);
- nodes = table.getElements(".calendarTimeShow");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeShow);
- nodes = table.getElements(".calendarTimeShowItem");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeShowItem);
- var node = table.getElement(".MWF_calendar_action_show");
- if (node){
- node.setStyles(this.css.calendarActionShow);
- var buttons = node.getElements("button");
- buttons.setStyles(this.css.calendarActionShowButton);
- }
- }
- break;
- default :
- //nothing;
- }
- tds.addEvent("mouseover", function(){
- var d;
- switch (calendar.currentView) {
- case "day" :
- d = this.retrieve("dateValue");
- if (calendar.isEnableDate(d)) this.setStyle("border", "1px solid #999999");
- break;
- case "month" :
- if( calendar.options.enableDate ){
- d = calendar.addZero(this.retrieve("month").toInt() + 1, 2 );
- var y = this.retrieve("year");
- if (calendar.isEnableDate(y+"-"+d+"-01")){
- this.setStyle("border", "1px solid #999999");
- }else if(calendar.isEnableDate(y+"-"+d+"-"+new Date(y+"-"+d+"-01").get('lastdayofmonth'))){
- this.setStyle("border", "1px solid #999999");
- }
- }else{
- this.setStyle("border", "1px solid #999999");
- }
- break;
- case "year" :
- d = this.retrieve("year");
- if (calendar.isEnableDate(d+"-01-01") || calendar.isEnableDate(d+"-12-12")) this.setStyle("border", "1px solid #999999");
- break;
- default:
- this.setStyle("border", "1px solid #999999");
- break;
- }
- });
- tds.addEvent("mouseout", function(){
- this.setStyle("border", "1px solid #FFF");
- // var d;
- // switch (calendar.currentView) {
- // case "day" :
- // d = this.retrieve("dateValue");
- // if (calendar.isEnableDate(d)) this.setStyle("border", "1px solid #FFF");
- // break;
- // default:
- // this.setStyle("border", "1px solid #FFF");
- // break;
- // }
- });
- }else{
- switch (this.currentView) {
- case "day" :
- table.setStyles(this.css.calendarDaysContent);
- tds.setStyles(this.css.calendarDaysContentTd);
- break;
- case "month" :
- table.setStyles(this.css.calendarMonthsContent);
- tds.setStyles(this.css.calendarMonthsContentTd);
- break;
- case "year" :
- this.yearLength = tds.length;
- table.setStyles(this.css.calendarYearsContent);
- tds.setStyles(this.css.calendarYearsContentTd);
- break;
- case "time" :
- if( this.options.style.indexOf("mobile") > -1 ){
- var nodes = table.getElements(".calendarTimeContent_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeContent_mobile);
- nodes = table.getElements(".calendarTimeFixWidthNode_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeFixWidthNode_mobile);
- nodes = table.getElements(".calendarTimeWheels_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeWheels_mobile);
- nodes = table.getElements(".calendarTimeWheel_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeWheel_mobile);
- nodes = table.getElements(".calendarTimeSelectContainer_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectContainer_mobile);
- nodes = table.getElements(".calendarTimeSelectLine_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectLine_mobile);
- nodes = table.getElements(".calendarTimeShadowMask_mobile");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeShadowMask_mobile);
- var node = table.getElement(".MWF_calendar_action_show");
- if (node){
- node.setStyles(this.css.calendarActionShow);
- //var buttons = node.getElements("button");
- //buttons.setStyles(this.css.calendarActionShowButton);
- }
- }else{
- var nodes = table.getElements(".calendarTimeArea");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeArea);
- nodes = table.getElements(".calendarTimeSlider");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeSlider);
- nodes = table.getElements(".calendarTimeSliderKnob");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeSliderKnob);
- nodes = table.getElements(".calendarTimeShow");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeShow);
- nodes = table.getElements(".calendarTimeShowItem");
- if (nodes.length) nodes.setStyles(this.css.calendarTimeShowItem);
- var node = table.getElement(".MWF_calendar_action_show");
- if (node){
- node.setStyles(this.css.calendarActionShow);
- var buttons = node.getElements("button");
- buttons.setStyles(this.css.calendarActionShowButton);
- }
- }
- break;
- default :
- //nothing;
- }
- }
- return table;
- },
- setRange: function(){
- if( this.options.datetimeRange && this.options.datetimeRange.length ){
- this.setDatetimeRange();
- }else{
- if(this.options.dateRange && this.options.dateRange.length){
- this.setDateRange();
- }
- if(this.options.timeRange && this.options.timeRange.length){
- this.setTimeRange();
- }
- }
- },
- setDatetimeRange: function(){
- var arr = this.options.datetimeRange;
- var _2dArray = typeOf(arr[0]) !== "array" ? [arr] : arr;
- if( !_2dArray[0][0] && !_2dArray[0][1] )return;
- this.datetimeRange = [];
- this.dateRange = [];
- this.dateOnlyRange = [];
- _2dArray.each(function(a){
- var ds, de, ds1, de1, de2;
- if(a[0])ds = typeOf(a[0]) === "date" ? a[0] : Date.parse(a[0]);
- if(a[1])de = typeOf(a[1]) === "date" ? a[1] : Date.parse(a[1]);
- this.datetimeRange.push([ds, de]);
- if(ds){
- ds1 = ds.clone().clearTime();
- }
- if(de){
- de1 = de.clone().set({hr:23, min:59, sec:59});
- de2 = de.clone().clearTime();
- }
- this.dateRange.push([ds1, de1]);
- this.dateOnlyRange.push([ds1, de2]);
- }.bind(this));
- this.options.enableDate = function (date) {
- var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
- d.clearTime();
- for( var i=0; i<this.dateRange.length; i++ ){
- var ar = this.dateRange[i];
- if( !ar[0] && this.isLessEquals(d, ar[1]) )return true;
- if( !ar[1] && this.isLessEquals(ar[0], d) )return true;
- if( this.isLessEquals(ar[0], d) && this.isLessEquals(d, ar[1]) )return true;
- }
- return false;
- }.bind(this);
- this.options.enableHours = function (date) {
- var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
- d.clearTime();
- var hours = [];
- for( var i=0; i<this.dateOnlyRange.length; i++ ){
- var ar = this.dateOnlyRange[i];
- var equal1 = this.isEquals(ar[0], d), equal2 = this.isEquals(d, ar[1]);
- if( equal1 || equal2){
- var s = equal1 ? this.datetimeRange[i][0].get("hr") : 0;
- var e = equal2 ? this.datetimeRange[i][1].get("hr") : 23;
- hours.push( [s, e] );
- }
- }
- return hours.length ? o2.Calendar.RangeArrayUtils.union(hours) : [0, 23];
- }.bind(this);
- this.options.enableMinutes = function (date, hour) {
- var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
- d.clearTime();
- var minutes = [];
- for( var i=0; i<this.dateOnlyRange.length; i++ ){
- var ar = this.dateOnlyRange[i];
- var ardt = this.datetimeRange[i];
- var equal1 = (this.isEquals(ar[0], d) && hour === ardt[0].get("hr"));
- var equal2 = (this.isEquals(d, ar[1]) && hour === ardt[1].get("hr"));
- if( equal1 || equal2 ){
- var s = equal1 ? ardt[0].get("min") : 0;
- var e = equal2 ? ardt[1].get("min") : 59;
- minutes.push( [s, e] );
- }
- }
- return minutes.length ? o2.Calendar.RangeArrayUtils.union(minutes) : [0, 59];
- }.bind(this);
- this.options.enableSeconds = function (date, hour, minute) {
- var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
- d.clearTime();
- var seconds = [];
- for( var i=0; i<this.dateOnlyRange.length; i++ ){
- var ar = this.dateOnlyRange[i];
- var ardt = this.datetimeRange[i];
- var equal1 = (this.isEquals(ar[0], d) && hour === ardt[0].get("hr") && minute === ardt[0].get("min"));
- var equal2 = (this.isEquals(d, ar[1]) && hour === ardt[1].get("hr") && minute === ardt[1].get("min"));
- if( equal1 || equal2 ){
- var s = equal1 ? ardt[0].get("sec") : 0;
- var e = equal2 ? ardt[1].get("sec") : 59;
- seconds.push( [s, e] );
- }
- }
- return seconds.length ? o2.Calendar.RangeArrayUtils.union(seconds) : [0, 59];
- }.bind(this);
- },
- setDateRange: function(){
- var arr = this.options.dateRange;
- var _2dArray = typeOf(arr[0]) !== "array" ? [arr] : arr;
- if( !_2dArray[0][0] && !_2dArray[0][1] )return;
- this.dateRange = [];
- _2dArray.each(function(a){
- var ds, de, ds1, de1;
- if(a[0])ds = typeOf(a[0]) === "date" ? a[0] : Date.parse(a[0]);
- if(a[1])de = typeOf(a[1]) === "date" ? a[1] : Date.parse(a[1]);
- if(ds)ds1 = ds.clearTime();
- if(de)de1 = de.set({hr:23, min:59, sec:59});
- this.dateRange.push([ds1, de1]);
- }.bind(this));
- this.options.enableDate = function (date) {
- var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
- d.clearTime();
- for( var i=0; i<this.dateRange.length; i++ ){
- var ar = this.dateRange[i];
- if( !ar[0] && this.isLessEquals(d, ar[1]) )return true;
- if( !ar[1] && this.isLessEquals(ar[0], d) )return true;
- if( this.isLessEquals(ar[0], d) && this.isLessEquals(d , ar[1]) )return true;
- }
- return false;
- }.bind(this);
- },
- setTimeRange: function(){
- var arr = this.options.timeRange;
- var _2dArray = typeOf(arr[0]) !== "array" ? [arr] : arr;
- if( !_2dArray[0][0] && !_2dArray[0][1] )return;
- this.datetimeRange2 = [];
- _2dArray.each(function(a){
- var ds, de, ds1, de1;
- if(a[0])ds = Date.parse("2020-01-01 "+a[0]);
- if(a[1])de = Date.parse("2020-01-01 "+a[1]);
- this.datetimeRange2.push([ds, de]);
- }.bind(this));
- this.options.enableHours = function (date) {
- // var d = typeOf(date) === "string" ? Date.parse(date) : date;
- if(this.hourRange)return this.hourRange;
- var hours = [];
- for( var i=0; i<this.datetimeRange2.length; i++ ){
- var ar = this.datetimeRange2[i];
- var s = ar[0] ? ar[0].get("hr") : 0;
- var e = ar[1] ? ar[1].get("hr") : 23;
- hours.push( [s, e] );
- }
- this.hourRange = o2.Calendar.RangeArrayUtils.union(hours);
- return this.hourRange;
- }.bind(this);
- this.options.enableMinutes = function (date, hour) {
- // var d = typeOf(date) === "string" ? Date.parse(date) : date;
- var minutes = [];
- for( var i=0; i<this.datetimeRange2.length; i++ ){
- var ar = this.datetimeRange2[i];
- var equal1 = (ar[0] && hour === ar[0].get("hr"));
- var equal2 = (ar[1] && hour === ar[1].get("hr"));
- if( equal1 || equal2 ){
- var s = equal1 ? ar[0].get("min") : 0;
- var e = equal2 ? ar[1].get("min") : 59;
- minutes.push( [s, e] );
- }
- }
- return minutes.length ? o2.Calendar.RangeArrayUtils.union(minutes) : [0, 59];
- }.bind(this);
- this.options.enableSeconds = function (date, hour, minute) {
- // var d = typeOf(date) === "string" ? Date.parse(date) : date;
- var seconds = [];
- for( var i=0; i<this.datetimeRange2.length; i++ ){
- var ar = this.datetimeRange2[i];
- var equal1 = (ar[0] && hour === ar[0].get("hr") && minute === ar[0].get("min"));
- var equal2 = (ar[1] && hour === ar[1].get("hr") && minute === ar[1].get("min"));
- if( equal1 || equal2 ){
- var s = equal1 ? ar[0].get("sec") : 0;
- var e = equal2 ? ar[1].get("sec") : 59;
- seconds.push( [s, e] );
- }
- }
- return seconds.length ? o2.Calendar.RangeArrayUtils.union(seconds) : [0, 59];
- }.bind(this);
- },
- isGreatEquals: function( d1, d2 ){
- return (d1 > d2) || ((d1 - d2) === 0);
- },
- isLessEquals: function( d1, d2 ){
- return (d1 < d2) || ((d1 - d2) === 0);
- },
- isEquals: function(d1, d2){
- return (d1 - d2) === 0;
- },
- isEnableDate: function(date){
- var fun = this.options.enableDate;
- if( fun && typeOf(fun) === "function" ){
- var d = typeOf( date ) === "string" ? new Date(date) : date;
- if( fun( d ) === false ){
- return false;
- }
- }
- return true;
- },
- getEnableHours: function(date){
- var fun = this.options.enableHours;
- if( fun && typeOf(fun) === "function" ){
- var d = typeOf( date ) === "string" ? new Date(date) : date;
- return fun( d );
- }
- return [0, 23];
- },
- getDisabledHours: function(date){
- var ar = this.getEnableHours(date);
- if( !ar || !ar.length || (ar[0] === 0 && ar[1] === 23) )return [];
- if( typeOf(ar[0]) !== "array" )ar = [ar];
- return o2.Calendar.RangeArrayUtils.complementary([0, 23], ar, null, 1);
- },
- // getEnableHourStartEnd: function(date){
- // var ar = this.getEnableHours(date);
- // return this._getEnableStartEnd( ar, 0, 23 );
- // },
- isEnableHour: function (thisDate, hour, nearly) {
- var hs = this.getEnableHours( thisDate );
- if( !hs || !hs.length || (hs[0] === 0 && hs[1] === 23) )return true;
- if( typeOf(hs[0]) === "array" ){
- for( var i=0; i< hs.length; i++ ){
- var dhs = hs[i];
- if( dhs[0] <= hour && hour <= dhs[1] )return true;
- }
- }else{
- if( hs[0] <= hour && hour <= hs[1] )return true;
- }
- return nearly ? o2.Calendar.findClosest( hs.flatten(), hour ) : false;
- },
- getEnableMinutes: function(date, h){
- var fun = this.options.enableMinutes;
- if( fun && typeOf(fun) === "function" ){
- var d = typeOf( date ) === "string" ? new Date(date) : date;
- return fun( d, h );
- }
- return [0, 59];
- },
- getDisabledMinutes: function(date, h){
- var ar = this.getEnableMinutes(date, h);
- if( !ar || !ar.length || (ar[0] === 0 && ar[1] === 59))return [];
- if( typeOf(ar[0]) !== "array" )ar = [ar];
- return o2.Calendar.RangeArrayUtils.complementary([0, 59], ar, null, 1);
- },
- isEnableMinute: function (thisDate, hour, minute, nearly) {
- var ms = this.getEnableMinutes( thisDate, hour );
- if( !ms || !ms.length || (ms[0] === 0 && ms[1] === 59))return true;
- if( typeOf(ms[0]) === "array" ){
- for( var i=0; i< ms.length; i++ ){
- var dms = ms[i];
- if( dms[0] <= minute && minute <= dms[1] )return true;
- }
- }else{
- if( ms[0] <= minute && minute <= ms[1] )return true;
- }
- return nearly ? o2.Calendar.findClosest( ms.flatten(), minute ) : false;
- },
- getEnableSeconds: function(date, h, m){
- var fun = this.options.enableSeconds;
- if( fun && typeOf(fun) === "function" ){
- var d = typeOf( date ) === "string" ? new Date(date) : date;
- return fun( d, h, m );
- }
- return [0, 59];
- },
- getDisabledSeconds: function(date, h, m){
- var ar = this.getEnableSeconds(date, h, m);
- if( !ar || !ar.length || (ar[0] === 0 && ar[1] === 59))return [];
- if( typeOf(ar[0]) !== "array" )ar = [ar];
- return o2.Calendar.RangeArrayUtils.complementary([0, 59], ar, null, 1);
- },
- isEnableSecond: function (thisDate, hour, minute, second, nearly) {
- var ss = this.getEnableSeconds( thisDate, hour, minute );
- if( !ss || !ss.length || (ss[0] === 0 && ss[1] === 59))return true;
- if( typeOf(ss[0]) === "array" ){
- for( var i=0; i< ss.length; i++ ){
- var dss = ss[i];
- if( dss[0] <= second && second <= dss[1] )return true;
- }
- }else{
- if( ss[0] <= second && second <= ss[1] )return true;
- }
- return nearly ? o2.Calendar.findClosest( ss.flatten(), second ) : false;
- },
- // _getEnableStartEnd: function( ar, start, end ){
- // if( !ar || !ar.length || (ar[0] === start && ar[1] === 23) )return [start, 23];
- // var s, e;
- // if( typeOf( ar[0] === "array" ) ){
- // ar.each(function(a, i){
- // s = i === 0 ? (a[0] || start ) : Math.min( s , a[0] || start );
- // e = i === 0 ? (a[1] || end ) : Math.max( e, a[1] || end );
- // })
- // }else{
- // s = ar[0] || start;
- // e = ar[1] || end;
- // }
- // return [s, e];
- // }
- });
- o2.Calendar.antiShake = function (fun, wait, bind){
- var time = null;
- return function (args){
- if(time){
- clearTimeout(time);
- }
- time = setTimeout(fun.call(bind, args), wait);
- }
- };
- o2.Calendar.findClosest = function(arr, target) {
- if (!arr.length) {
- return null; // 如果数组为空,返回null
- }
- var closest = arr[0];
- var minDiff = Math.abs(arr[0] - target);
- for (var i = 1; i < arr.length; i++) {
- var currentDiff = Math.abs(arr[i] - target);
- if (currentDiff < minDiff) {
- minDiff = currentDiff;
- closest = arr[i];
- }
- }
- return closest;
- }
- o2.Calendar.MobileSelect = new Class({
- Implements: [Options, Events],
- options: {
- "lineHeight" : 40, //每个item的高度
- "items": [],
- "ratio" : 1, //滑动距离倍率
- "currentItem" : 0
- },
- initialize: function (wheelNode, options) {
- this.setOptions( options );
- this.wheelNode = wheelNode;
- this.sliderNode = wheelNode.getFirst();
- this.options.itemIndex = this.options.items.indexOf(this.options.currentItem);
- if( this.options.itemIndex < 0 )this.options.itemIndex = 0;
- },
- load : function(){
- var _this = this;
- this.curDistance = 0;
- this.sliderNode.style.transform = "translate3d(0px, 80px, 0px)";
- this.wheelNode.addEventListener('touchstart', function (event) {
- _this.touch(event);
- }, false);
- this.wheelNode.addEventListener('touchend', function (event) {
- _this.touch(event);
- }, false);
- this.wheelNode.addEventListener('touchmove', function (event) {
- _this.touch(event);
- }, false);
- this.locatePostion( this.options.itemIndex );
- },
- touch: function (ev) {
- var sliderNode = this.sliderNode;
- ev = ev || window.event;
- switch (ev.type) {
- case "touchstart":
- this.startTime = new Date();
- this.startY = event.touches[0].clientY;
- this.oldMoveY = this.startY;
- break;
- case "touchend":
- this.moveEndY = event.changedTouches[0].clientY;
- this.overTime = new Date();
- var speed = (this.moveEndY - this.startY) / ( this.overTime - this.startTime );
- var ratio = 1;
- if( Math.abs(speed) > 0.7 ){
- ratio = 5;
- }else if( Math.abs(speed) < 0.2 ){
- ratio = 0.7
- }
- this.offsetSum = ( this.moveEndY - this.startY ) * this.options.ratio * ratio;
- this.updateCurDistance();
- this.curDistance = this.fixPosition(this.curDistance);
- this.movePosition( this.curDistance );
- this.oversizeBorder = - ( this.options.items.length - 3) * this.options.lineHeight;
- if (this.curDistance + this.offsetSum > 2 * this.options.lineHeight) {
- this.curDistance = 2 * this.options.lineHeight;
- setTimeout(function () {
- this.movePosition( this.curDistance );
- }.bind(this), 100);
- } else if (this.curDistance + this.offsetSum < this.oversizeBorder) {
- this.curDistance = this.oversizeBorder;
- setTimeout(function () {
- this.movePosition( this.curDistance );
- }.bind(this), 100);
- }
- var idx = this.getCurIndex();
- this.fireEvent( "change", [this.options.items[idx]]);
- break;
- case "touchmove":
- ev.preventDefault();
- this.moveY = event.touches[0].clientY;
- this.overTime = new Date();
- var speed = (this.moveY - this.oldMoveY) / ( this.overTime - this.oldOverTime );
- var ratio = 1;
- if( Math.abs(speed) > 0.7 ){
- ratio = 5;
- }else if( Math.abs(speed) < 0.2 ){
- ratio = 0.7
- }
- this.offset = ( this.moveY - this.oldMoveY ) * this.options.ratio * ratio;
- this.updateCurDistance();
- this.curDistance = this.curDistance + this.offset;
- this.movePosition( this.curDistance );
- this.oldMoveY = this.moveY;
- this.oldOverTime = this.overTime;
- break;
- }
- },
- resetItems: function( items, currentItem ){
- this.options.items = items;
- this.options.currentItem = currentItem;
- this.options.itemIndex = this.options.items.indexOf(this.options.currentItem);
- if( this.options.itemIndex < 0 )this.options.itemIndex = 0;
- this.oversizeBorder = - ( this.options.items.length - 3) * this.options.lineHeight;
- this.locatePostion( this.options.itemIndex );
- },
- calcDistance: function (index) {
- return 2 * this.options.lineHeight - index * this.options.lineHeight;
- },
- setCurDistance: function ( index ) {
- this.curDistance = this.calcDistance( index );
- this.movePosition( this.curDistance );
- },
- fixPosition: function (distance) {
- return -(this.getIndex(distance) - 2) * this.options.lineHeight;
- },
- getCurIndex : function(){
- return this.getIndex( this.curDistance );
- },
- getIndex: function (distance) {
- return Math.round((2 * this.options.lineHeight - distance) / this.options.lineHeight);
- },
- movePosition: function ( distance) {
- this.sliderNode.style.webkitTransform = 'translate3d(0,' + distance + 'px, 0)';
- this.sliderNode.style.transform = 'translate3d(0,' + distance + 'px, 0)';
- },
- locatePostion: function ( index ) {
- this.curDistance = this.calcDistance(index);
- this.movePosition( this.curDistance );
- },
- updateCurDistance: function () {
- this.curDistance = parseInt(this.sliderNode.style.transform.split(',')[1]);
- },
- getDistance: function () {
- return parseInt(this.sliderNode.style.transform.split(',')[1]);
- }
- });
- o2.Calendar.RangeArrayUtils = {
- //补集 range [ start, end ] rangeList [ [start1, end1], [ start2, end2 ] ... ]
- complementary : function( range, rangeList, type, offset ){
- if( !range )return range;
- var r = this.getRangeObject( range );
- if( !rangeList || rangeList.length == 0 )return this.parse( [r] , type);
- var unitedList = this.union( rangeList );
- var newRange = {};
- if( unitedList[0][0] > r.start ){
- newRange.start = r.start;
- }else if( r.end > unitedList[0][1] ){
- newRange.start = unitedList[0][1];
- unitedList.shift();
- }else{
- return [];
- }
- var newList = [];
- while( unitedList.length > 0 ){
- if( unitedList[0][0] >= r.end ){
- newRange.end = r.end;
- newList.push( Object.clone(newRange) );
- return this.parse( newList , type);
- }else if( r.end <= unitedList[0][1] ){
- newRange.end = unitedList[0][0];
- newList.push( Object.clone(newRange) );
- return this.parse( newList, type );
- }else{
- newRange.end = unitedList[0][0];
- newList.push( Object.clone(newRange) );
- newRange.start = unitedList[0][1];
- unitedList.shift();
- }
- }
- newRange.end = r.end;
- newList.push( Object.clone(newRange ));
- var array = this.parse( newList, type );
- if( offset ){
- return array.map(function (a) {
- if( a[0] !== r.start )a[0] = a[0] + offset;
- if( a[1] !== r.end )a[1] = a[1] - offset;
- return a;
- })
- }else{
- return array;
- }
- },
- //取区域并集rangeList [ [start1, end1], [ start2, end2 ] ... ]
- union : function( ranges, type ){
- if( !ranges || ranges.length == 0)return ranges; //this.parse(this.getRangeObject( ranges ) ) ;
- var rangeList = Array.clone( ranges );
- for( var i=0; i<rangeList.length; i++ ){
- rangeList[i] = this.getRangeObject( rangeList[i] );
- }
- rangeList.sort( function( a, b ){
- return a.start - b.start;
- });
- var newRangeList = [];
- var newRange = rangeList.shift();
- while( rangeList.length > 0 ){
- var nextRange = rangeList.shift();
- if( this.isIntersection( newRange, nextRange ) ){
- newRange.end = Math.max( newRange.end, nextRange.end );
- }else{
- newRangeList.push( Object.clone( newRange ) );
- newRange = nextRange;
- }
- }
- if( !nextRange ){
- newRangeList.push( Object.clone( newRange ) );
- }else if( this.isIntersection( newRange, nextRange ) ){
- newRange.end = Math.max( newRange.end, nextRange.end );
- newRangeList.push( Object.clone( newRange ) );
- }else{
- newRangeList.push( Object.clone( nextRange ) );
- }
- return this.parse( newRangeList, type );
- },
- //取区域交集rangeList [ [start1, end1], [ start2, end2 ] ... ],需要测试
- intersection: function( ranges, type ){
- if( !ranges || ranges.length == 0 )return ranges; //this.parse(this.getRangeObject( ranges ) ) ;
- if( ranges.length === 1 )return ranges[1];
- var rangeList = Array.clone( ranges );
- for( var i=0; i<rangeList.length; i++ ){
- rangeList[i] = this.getRangeObject( rangeList[i] );
- }
- rangeList.sort( function( a, b ){
- return a.start - b.start;
- });
- var newRange = rangeList.shift();
- while( rangeList.length > 0 ){
- var nextRange = rangeList.shift();
- if( this.isIntersection( newRange, nextRange ) ){
- newRange.start = nextRange.start;
- newRange.end = Math.min( newRange.end, nextRange.end );
- }else{
- return [];
- }
- }
- if( type && type === "date" ){
- return [ Date.parse(newRange.start), Date.parse(newRange.end) ];
- }else{
- return [newRange.start, newRange.end];
- }
- },
- //区域是否相交
- isIntersection : function( range1, range2 ){
- var r1 = typeOf( range1 ) === "object" ? range1 : this.getRangeObject( range1 );
- var r2 = typeOf( range2 ) === "object" ? range2 : this.getRangeObject( range2 );
- if( r1.start > r2.end )return false;
- if( r2.start > r1.end )return false;
- return true;
- },
- parse: function( objectList, type ){
- var list = [];
- for( var i=0; i<objectList.length; i++ ){
- var range = objectList[i];
- if( type && type == "date" ){
- list.push( [ Date.parse(range.start), Date.parse(range.end) ] );
- }else{
- list.push( [range.start, range.end] );
- }
- }
- return list;
- },
- getRangeObject: function( range ){
- return {
- start : Math.min( range[0], range[1] ),
- end : Math.max( range[0], range[1] )
- }
- }
- };
|