calendar-base-min.js revision 9724a6e829470b07523eddcd9df488b799e57a6a
YUI.add("calendar-base",function(c){var D=c.ClassNameManager.getClassName,q="calendar",j=D(q,"grid"),d=D(q,"left-grid"),x=D(q,"right-grid"),z=D(q,"body"),p=D(q,"header"),m=D(q,"header-label"),r=D(q,"weekdayrow"),B=D(q,"weekday"),v=D(q,"column-hidden"),e=D(q,"day-selected"),g=D(q,"selection-disabled"),k=D(q,"row"),C=D(q,"day"),b=D(q,"prevmonth-day"),s=D(q,"nextmonth-day"),y=D(q,"anchor"),G=D(q,"pane"),i=c.Lang,t=c.Node,l=t.create,u=c.substitute,f=c.each,F=c.Array.hasValue,w=c.Array.indexOf,E=c.Object.hasKey,a=c.Object.setValue,h=c.Object.owns,o=c.Object.isEmpty,n=c.DataType.Date;function A(H){A.superclass.constructor.apply(this,arguments);}c.CalendarBase=c.extend(A,c.Widget,{_paneProperties:{},_paneNumber:1,_calendarId:c.guid(q),_selectedDates:{},_rules:{},_filterFunction:null,_storedDateCells:{},initializer:function(){},renderUI:function(){var H=this.get("contentBox");H.appendChild(this._initCalendarHTML(this.get("date")));if(this.get("showPrevMonth")){this._afterShowPrevMonthChange();}if(this.get("showNextMonth")){this._afterShowNextMonthChange();}this._renderCustomRules();this._renderSelectedDates();},bindUI:function(){this.after("dateChange",this._afterDateChange);this.after("showPrevMonthChange",this._afterShowPrevMonthChange);this.after("showNextMonthChange",this._afterShowNextMonthChange);this.after("headerRendererChange",this._afterHeaderRendererChange);this.after("customRendererChange",this._afterCustomRendererChange);this._bindCalendarEvents();},syncUI:function(){if(this.get("showPrevMonth")){this._afterShowPrevMonthChange();}if(this.get("showNextMonth")){this._afterShowNextMonthChange();}},_getSelectedDatesList:function(){var H=[];f(this._selectedDates,function(I){f(I,function(J){f(J,function(K){H.push(K);},this);},this);},this);return H;},_getSelectedDatesInMonth:function(I){var H=I.getFullYear(),J=I.getMonth();if(E(this._selectedDates,H)&&E(this._selectedDates[H],J)){return c.Object.values(this._selectedDates[H][J]);}else{return[];}},_renderSelectedDate:function(H){if(this._isDateVisible(H)){this._dateToNode(H).addClass(e);}},_renderUnselectedDate:function(H){if(this._isDateVisible(H)){this._dateToNode(H).removeClass(e);}},_isDateVisible:function(H){var I=this.get("date"),J=n.addMonths(I,this._paneNumber-1),K=this._normalizeDate(H).getTime();if(I.getTime()<=K&&K<=J){return true;}else{return false;}},_isNumInList:function(I,K){if(K=="all"){return true;}else{var J=K.split(",");for(val in J){var H=J[val].split("-");if(H.length==2&&I>=parseInt(H[0])&&I<=parseInt(H[1])){return true;}else{if(H.length==1&&(parseInt(J[val])==I)){return true;}}}return false;}},_getRulesForDate:function(K){var J=K.getFullYear(),M=K.getMonth(),I=K.getDate(),L=K.getDay(),N=this._rules,H=[];for(years in N){if(this._isNumInList(J,years)){if(i.isString(N[years])){H.push(N[years]);}else{for(months in N[years]){if(this._isNumInList(M,months)){if(i.isString(N[years][months])){H.push(N[years][months]);}else{for(dates in N[years][months]){if(this._isNumInList(I,dates)){if(i.isString(N[years][months][dates])){H.push(N[years][months][dates]);}else{for(days in N[years][months][dates]){if(this._isNumInList(L,days)){if(i.isString(N[years][months][dates][days])){H.push(N[years][months][dates][days]);}}}}}}}}}}}}return H;},_matchesRule:function(H,I){return(w(this._getRulesForDate(H),I)>=0);},_canBeSelected:function(J){var H=this.get("enabledDatesRule"),I=this.get("disabledDatesRule");if(H){return this._matchesRule(J,H);}else{if(I){return !this._matchesRule(J,I);}else{return true;}}},selectDates:function(H){if(n.isValidDate(H)){this._addDateToSelection(H);}else{if(i.isArray(H)){this._addDatesToSelection(H);}}},deselectDates:function(H){if(H==null){this._clearSelection();}else{if(n.isValidDate(H)){this._removeDateFromSelection(H);}else{if(i.isArray(H)){this._removeDatesFromSelection(H);}}}},_addDateToSelection:function(K,I){if(this._canBeSelected(K)){var J=K.getFullYear(),L=K.getMonth(),H=K.getDate();if(E(this._selectedDates,J)){if(E(this._selectedDates[J],L)){this._selectedDates[J][L][H]=K;}else{this._selectedDates[J][L]={};this._selectedDates[J][L][H]=K;}}else{this._selectedDates[J]={};this._selectedDates[J][L]={};this._selectedDates[J][L][H]=K;}this._selectedDates=a(this._selectedDates,[J,L,H],K);this._renderSelectedDate(K);if(I==null){this._fireSelectionChange();}}},_addDatesToSelection:function(H){f(H,this._addDateToSelection,this);this._fireSelectionChange();},_addDateRangeToSelection:function(H,L){var J=H.getTime(),I=L.getTime();if(J>I){var M=J;J=I;I=M;}for(var K=J;K<=I;K+=86400000){this._addDateToSelection(new Date(K),K);}this._fireSelectionChange();},_removeDateFromSelection:function(K,I){var J=K.getFullYear(),L=K.getMonth(),H=K.getDate();if(E(this._selectedDates,J)&&E(this._selectedDates[J],L)&&E(this._selectedDates[J][L],H)){delete this._selectedDates[J][L][H];this._renderUnselectedDate(K);if(I==null){this._fireSelectionChange();}}},_removeDatesFromSelection:function(H){f(H,this._removeDateDromSelection);this._fireSelectionChange();},_removeDateRangeFromSelection:function(H,L){var J=H.getTime(),I=L.getTime();for(var K=J;K<=I;K+=86400000){this._removeDateFromSelection(new Date(K),K);}this._fireSelectionChange();},_clearSelection:function(H){this._selectedDates={};this.get("contentBox").all("."+e).removeClass(e);if(!H){this._fireSelectionChange();}},_fireSelectionChange:function(){this.fire("selectionChange",{newSelection:this._getSelectedDatesList()});},_restoreModifiedCells:function(){var H=this.get("contentBox");for(id in this._storedDateCells){H.one("#"+id).replace(this._storedDateCells[id]);delete this._storedDateCells[id];}},_renderCustomRules:function(){this.get("contentBox").all("."+C+",."+s).removeClass(g);if(!o(this._rules)){var K=this.get("enabledDatesRule"),J=this.get("disabledDatesRule");for(var I=0;I<this._paneNumber;I++){var H=n.addMonths(this.get("date"),I);var L=n.listOfDatesInMonth(H);f(L,function(M){var O=this._getRulesForDate(M);if(O.length>0){var N=this._dateToNode(M);if((K&&!(w(O,K)>=0))||(J&&(w(O,J)>=0))){N.addClass(g);
}if(i.isFunction(this._filterFunction)){this._storedDateCells[N.get("id")]=N.cloneNode(true);this._filterFunction(M,N,O);}}},this);}}},_renderSelectedDates:function(){this.get("contentBox").all("."+e).removeClass(e);for(var I=0;I<this._paneNumber;I++){var H=n.addMonths(this.get("date"),I);var J=this._getSelectedDatesInMonth(H);f(J,function(K){this._dateToNode(K).addClass(e);},this);}},_dateToNode:function(N){var H=N.getDate(),J=0,K=H%7,L=(12+N.getMonth()-this.get("date").getMonth())%12,I=this._calendarId+"_pane_"+L,M=this._paneProperties[I].cutoffCol;switch(K){case (0):if(M>=6){J=12;}else{J=5;}break;case (1):J=6;break;case (2):if(M>0){J=7;}else{J=0;}break;case (3):if(M>1){J=8;}else{J=1;}break;case (4):if(M>2){J=9;}else{J=2;}break;case (5):if(M>3){J=10;}else{J=3;}break;case (6):if(M>4){J=11;}else{J=4;}break;}return(this.get("contentBox").one("#"+this._calendarId+"_pane_"+L+"_"+J+"_"+H));},_nodeToDate:function(L){var I=L.get("id").split("_"),J=parseInt(I[8]),H=parseInt(I[10]);var K=n.addMonths(this.get("date"),J);year=K.getFullYear();month=K.getMonth();return new Date(year,month,H,12,0,0,0);},_bindCalendarEvents:function(){},_normalizeDate:function(H){return new Date(H.getFullYear(),H.getMonth(),1,12,0,0,0);},_getCutoffColumn:function(I,J){var K=this._normalizeDate(I).getDay()-J;var H=6-(K+7)%7;return H;},_turnPrevMonthOn:function(L){var K=L.get("id"),I=this._paneProperties[K].paneDate,J=n.daysInMonth(n.addMonths(I,-1));if(!this._paneProperties[K].hasOwnProperty("daysInPrevMonth")){this._paneProperties[K].daysInPrevMonth=0;}if(J!=this._paneProperties[K].daysInPrevMonth){this._paneProperties[K].daysInPrevMonth=J;for(var H=5;H>=0;H--){L.one("#"+K+"_"+H+"_"+(H-5)).setContent(J--);}}},_turnPrevMonthOff:function(J){var I=J.get("id");this._paneProperties[I].daysInPrevMonth=0;for(var H=5;H>=0;H--){J.one("#"+I+"_"+H+"_"+(H-5)).setContent("&nbsp;");}},_cleanUpNextMonthCells:function(I){var H=I.get("id");I.one("#"+H+"_6_29").removeClass(s);I.one("#"+H+"_7_30").removeClass(s);I.one("#"+H+"_8_31").removeClass(s);I.one("#"+H+"_0_30").removeClass(s);I.one("#"+H+"_1_31").removeClass(s);},_turnNextMonthOn:function(N){var I=1,M=N.get("id"),J=this._paneProperties[M].daysInMonth,L=this._paneProperties[M].cutoffCol;for(var H=J-22;H<L+7;H++){N.one("#"+M+"_"+H+"_"+(H+23)).setContent(I++).addClass(s);}var K=L;if(J==31&&(L<=1)){K=2;}else{if(J==30&&L==0){K=1;}}for(var H=K;H<L+7;H++){N.one("#"+M+"_"+H+"_"+(H+30)).setContent(I++).addClass(s);}},_turnNextMonthOff:function(M){var L=M.get("id"),I=this._paneProperties[L].daysInMonth,K=this._paneProperties[L].cutoffCol;for(var H=I-22;H<=12;H++){M.one("#"+L+"_"+H+"_"+(H+23)).setContent("&nbsp;").addClass(s);}var J=0;if(I==31&&(K<=1)){J=2;}else{if(I==30&&K==0){J=1;}}for(var H=J;H<=12;H++){M.one("#"+L+"_"+H+"_"+(H+30)).setContent("&nbsp;").addClass(s);}},_afterShowNextMonthChange:function(){var H=this.get("contentBox"),I=H.one("#"+this._calendarId+"_pane_"+(this._paneNumber-1));this._cleanUpNextMonthCells(I);if(this.get("showNextMonth")){this._turnNextMonthOn(I);}else{this._turnNextMonthOff(I);}},_afterShowPrevMonthChange:function(){var I=this.get("contentBox"),H=I.one("#"+this._calendarId+"_pane_"+0);if(this.get("showPrevMonth")){this._turnPrevMonthOn(H);}else{this._turnPrevMonthOff(H);}},_afterHeaderRendererChange:function(){var H=this.get("contentBox").one("."+p).one("h4");H.setContent(this._updateCalendarHeader(this.get("date")));},_afterCustomRendererChange:function(){this._renderCustomRules();},_afterDateChange:function(){var J=this.get("contentBox"),L=J.one("."+p).one("h4"),K=J.all("."+j),I=this.get("date"),H=0;J.setStyle("visibility","hidden");L.setContent(this._updateCalendarHeader(I));this._restoreModifiedCells();K.each(function(M){this._rerenderCalendarPane(n.addMonths(I,H++),M);},this);this._afterShowPrevMonthChange();this._afterShowNextMonthChange();this._renderCustomRules();this._renderSelectedDates();J.setStyle("visibility","visible");},_initCalendarPane:function(K,N){var U="",W=this.get("strings.very_short_weekdays")||["Su","Mo","Tu","We","Th","Fr","Sa"],H=this.get("strings.first_weekday")||0,S=this._getCutoffColumn(K,H),I=n.daysInMonth(K),R=["","","","","",""],P={};P["weekday_row"]="";for(var T=H;T<=H+6;T++){P["weekday_row"]+=u(A.WEEKDAY_TEMPLATE,{weekdayname:W[T%7]});}P["weekday_row_template"]=u(A.WEEKDAY_ROW_TEMPLATE,P);for(var X=0;X<=5;X++){for(var M=0;M<=12;M++){var L=7*X-5+M;var Q=N+"_"+M+"_"+L;var V=C;if(L<1){V=b;}else{if(L>I){V=s;}}if(L<1||L>I){L="&nbsp;";}var O=(M>=S&&M<(S+7))?"":v;R[X]+=u(A.CALDAY_TEMPLATE,{day_content:L,calendar_col_class:"calendar_col"+M,calendar_col_visibility_class:O,calendar_day_class:V,calendar_day_id:Q});}}P["body_template"]="";f(R,function(Y){P["body_template"]+=u(A.CALDAY_ROW_TEMPLATE,{calday_row:Y});});P["calendar_pane_id"]=N;var J=u(u(A.CALENDAR_GRID_TEMPLATE,P),A.CALENDAR_STRINGS);this._paneProperties[N]={cutoffCol:S,daysInMonth:I,paneDate:K};return J;},_rerenderCalendarPane:function(O,J){var H=this.get("strings.first_weekday")||0,N=this._getCutoffColumn(O,H),I=n.daysInMonth(O),L=J.get("id");J.setStyle("visibility","hidden");for(var K=0;K<=12;K++){var M=J.all("."+"calendar_col"+K);M.removeClass(v);if(K<N||K>=(N+7)){M.addClass(v);}else{switch(K){case 0:var P=J.one("#"+L+"_0_30");if(I>=30){P.setContent("30");P.removeClass(s).addClass(C);}else{P.setContent("&nbsp;");P.addClass(s).addClass(C);}break;case 1:var P=J.one("#"+L+"_1_31");if(I>=31){P.setContent("31");P.removeClass(s).addClass(C);}else{P.setContent("&nbsp;");P.removeClass(C).addClass(s);}break;case 6:var P=J.one("#"+L+"_6_29");if(I>=29){P.setContent("29");P.removeClass(s).addClass(C);}else{P.setContent("&nbsp;");P.removeClass(C).addClass(s);}break;case 7:var P=J.one("#"+L+"_7_30");if(I>=30){P.setContent("30");P.removeClass(s).addClass(C);}else{P.setContent("&nbsp;");P.removeClass(C).addClass(s);}break;case 8:var P=J.one("#"+L+"_8_31");if(I>=31){P.setContent("31");P.removeClass(s).addClass(C);}else{P.setContent("&nbsp;");P.removeClass(C).addClass(s);}break;}}}this._paneProperties[L].cutoffCol=N;
this._paneProperties[L].daysInMonth=I;this._paneProperties[L].paneDate=O;J.setStyle("visibility","visible");},_updateCalendarHeader:function(J){var I="",H=this.get("headerRenderer");if(c.Lang.isString(H)){I=n.format(J,{format:H});}else{if(H instanceof Function){I=H.call(this,J);}}return I;},_initCalendarHeader:function(H){return u(u(A.HEADER_TEMPLATE,{calheader:this._updateCalendarHeader(H)}),A.CALENDAR_STRINGS);},_initCalendarHTML:function(K){var J={},H=0;J["header_template"]=this._initCalendarHeader(K);J["calendar_id"]=this._calendarId;J["body_template"]=u(u(A.CONTENT_TEMPLATE,J),A.CALENDAR_STRINGS);function L(){var M=this._initCalendarPane(n.addMonths(K,H),J["calendar_id"]+"_pane_"+H);H++;return M;}var I=J["body_template"].replace(/\{calendar_grid_template\}/g,c.bind(L,this));this._paneNumber=H;return I;}},{CALENDAR_STRINGS:{calendar_grid_class:j,calendar_body_class:z,calendar_hd_class:p,calendar_hd_label_class:m,calendar_weekdayrow_class:r,calendar_weekday_class:B,calendar_row_class:k,calendar_day_class:C,calendar_dayanchor_class:y,calendar_pane_class:G,calendar_right_grid_class:x,calendar_left_grid_class:d},CONTENT_TEMPLATE:'<div class="yui3-g {calendar_pane_class}" id="{calendar_id}">'+"{header_template}"+'<div class="yui3-u-1">'+"{calendar_grid_template}"+"</div>"+"</div>",ONE_PANE_TEMPLATE:'<div class="yui3-g {calendar_pane_class}" id="{calendar_id}">'+"{header_template}"+'<div class="yui3-u-1 yui3-calendar-main-grid">'+"{calendar_grid_template}"+"</div>"+"</div>",TWO_PANE_TEMPLATE:'<div class="yui3-g {calendar_pane_class}" id="{calendar_id}">'+"{header_template}"+'<div class="yui3-u-1-2">'+'<div class = "{calendar_left_grid_class}">'+"{calendar_grid_template}"+"</div>"+"</div>"+'<div class="yui3-u-1-2">'+'<div class = "{calendar_right_grid_class}">'+"{calendar_grid_template}"+"</div>"+"</div>"+"</div>",THREE_PANE_TEMPLATE:'<div class="yui3-g {calendar_pane_class}" id="{calendar_id}">'+"{header_template}"+'<div class="yui3-u-1-3">'+'<div class = "{calendar_left_grid_class}">'+"{calendar_grid_template}"+"</div>"+"</div>"+'<div class="yui3-u-1-3">'+"{calendar_grid_template}"+"</div>"+'<div class="yui3-u-1-3">'+'<div class = "{calendar_right_grid_class}">'+"{calendar_grid_template}"+"</div>"+"</div>"+"</div>",CALENDAR_GRID_TEMPLATE:'<table class="{calendar_grid_class}" id="{calendar_pane_id}">'+"<thead>"+"{weekday_row_template}"+"</thead>"+"<tbody>"+"{body_template}"+"</tbody>"+"</table>",HEADER_TEMPLATE:'<div class="yui3-g {calendar_hd_class}">'+'<div class="yui3-u {calendar_hd_label_class}">'+"<h4>"+"{calheader}"+"</h4>"+"</div>"+"</div>",WEEKDAY_ROW_TEMPLATE:'<tr class="{calendar_weekdayrow_class}">'+"{weekday_row}"+"</tr>",CALDAY_ROW_TEMPLATE:'<tr class="{calendar_row_class}">'+"{calday_row}"+"</tr>",WEEKDAY_TEMPLATE:'<th class="{calendar_weekday_class}">{weekdayname}</th>',CALDAY_TEMPLATE:'<td class="{calendar_col_class} {calendar_day_class} {calendar_col_visibility_class}" id="{calendar_day_id}">'+"{day_content}"+"</td>",NAME:"calendarBase",ATTRS:{date:{value:new Date(),setter:function(I){var H=this._normalizeDate(I);if(n.areEqual(H,this.get("date"))){return this.get("date");}}},showPrevMonth:{value:false},showNextMonth:{value:false},strings:{valueFn:function(){return c.Intl.get("calendar-base");}},headerRenderer:{value:"%B %Y"},enabledDatesRule:{value:null},disabledDatesRule:{value:null},selectedDates:{readOnly:true,getter:function(H){return(this._getSelectedDatesList());}},customRenderer:{value:{},setter:function(H){this._rules=H.rules;this._filterFunction=H.filterFunction;}}}});},"@VERSION@",{requires:["widget","substitute","datatype-date","datatype-date-math","cssgrids"],lang:["en","ru"]});