| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198 |
- AUI.add('aui-datepicker-base', function(A) {
- var Lang = A.Lang,
- isBoolean = Lang.isBoolean,
- isFunction = Lang.isFunction,
-
- CALENDAR = 'calendar',
- CONTENT_BOX = 'contentBox',
- CURRENT_NODE = 'currentNode',
- FORMATTER = 'formatter',
- SELECT_MULTIPLE_DATES = 'selectMultipleDates',
- SET_VALUE = 'setValue',
-
- DATEPICKER = 'date-picker';
-
- var DatePicker = A.Component.create({
- NAME: DATEPICKER,
-
- ATTRS: {
- /**
- * <a href="Calendar.html">Calendar</a> configuration Object.</a>
- *
- * @attribute calendar
- * @default {}
- * @type Object
- */
- calendar: {
- setter: '_setCalendar',
- value: {}
- },
-
- /**
- * Function to format the array of the selected dates before set the
- * value of the input.
- *
- * @attribute formatter
- * @default function(dates) { return dates.formatted.join(','); }
- * @type function
- */
- formatter: {
- value: function(dates) {
- return dates.formatted.join(',');
- },
- validator: isFunction
- },
-
- /**
- * If true set the selected date with the correct
- * <a href="Calendar.html#config_dateFormat">dateFormat</a> to the
- * value of the input field which is hosting the Calendar.
- *
- * @attribute setValue
- * @default true
- * @type boolean
- */
- setValue: {
- value: true,
- validator: isBoolean
- },
-
- /**
- * If true is able To Do stacking with another overlays.
- *
- * @attribute stack
- * @default true
- * @type boolean
- */
- stack: {
- lazyAdd: false,
- value: true,
- setter: '_setStack',
- validator: isBoolean
- },
-
- showOn: {
- value: 'mousedown'
- },
-
- hideOn: {
- value: 'mousedown'
- }
- },
-
- EXTENDS: A.OverlayContext,
-
- prototype: {
- /**
- * Construction logic executed during Datepicker instantiation. Lifecycle.
- *
- * @method initializer
- * @protected
- */
- initializer: function() {
- var instance = this;
-
- instance.calendar = new A.Calendar(
- instance.get(CALENDAR)
- );
- },
-
- /**
- * Bind the events on the Datepicker UI. Lifecycle.
- *
- * @method bindUI
- * @protected
- */
- bindUI: function() {
- var instance = this;
-
- DatePicker.superclass.bindUI.apply(this, arguments);
-
- instance.on('show', instance._onShowOverlay);
- instance.after('calendar:select', instance._afterSelectDate);
-
- // Set the value of the trigger with the Calendar current date
- if (instance.get(SET_VALUE)) {
- instance._setTriggerValue(
- instance.calendar._getSelectEventData().date
- );
- }
- },
-
- /**
- * Descructor lifecycle implementation for the Datepicker class.
- * Purges events attached to the node (and all child nodes).
- *
- * @method destructor
- * @protected
- */
- destructor: function() {
- var instance = this;
-
- instance.calendar.destroy();
- },
-
- /**
- * Fires when a date is selected on the Calendar.
- *
- * @method _afterSelectDate
- * @param {Event} event
- * @protected
- */
- _afterSelectDate: function(event) {
- var instance = this;
-
- if (!instance.calendar.get(SELECT_MULTIPLE_DATES)) {
- instance.hide();
- }
-
- if (instance.get(SET_VALUE)) {
- instance._setTriggerValue(event.date);
- }
- },
-
- /**
- * Fires before the DatePicker overlay show. Responsible to invoke the
- * render phase of the Calendar.
- *
- * @method _onShowOverlay
- * @param {Event} event
- * @protected
- */
- _onShowOverlay: function(event) {
- var instance = this;
-
- instance._renderCalendar();
- },
-
- /**
- * Render the Calendar used inside the DatePicker.
- *
- * @method _renderCalendar
- * @protected
- */
- _renderCalendar: function() {
- var instance = this;
-
- instance.calendar.render(
- instance.get(CONTENT_BOX)
- );
- },
-
- /**
- * Setter for the <a href="DatePicker.html#calendar">calendar</a>
- * attribute.
- *
- * @method _setCalendar
- * @param {String} eventType Event type
- * @protected
- * @return {}
- */
- _setCalendar: function(val) {
- var instance = this;
-
- A.mix(val, {
- bubbleTargets: instance
- });
-
- return val;
- },
-
- /**
- * Setter for the <a href="Calendar.html#config_stack">stack</a> attribute.
- *
- * @method _setStack
- * @param {boolean} value
- * @protected
- * @return {boolean}
- */
- _setStack: function(value) {
- var instance = this;
-
- if (value) {
- A.DatepickerManager.register(instance);
- }
- else {
- A.DatepickerManager.remove(instance);
- }
-
- return value;
- },
-
- /**
- * Set the value of the trigger input with the date information.
- *
- * @method _setTriggerValue
- * @param {Object} dateObj Object containing date information
- * @protected
- */
- _setTriggerValue: function(dateObj) {
- var instance = this;
-
- var value = instance.get(FORMATTER).apply(instance, [dateObj]);
-
- instance.get(CURRENT_NODE).val(value);
- }
- }
- });
-
- A.DatePicker = DatePicker;
-
- /**
- * A base class for DatepickerManager:
- *
- * @param config {Object} Object literal specifying widget configuration properties.
- *
- * @class DatepickerManager
- * @constructor
- * @extends OverlayManager
- * @static
- */
- A.DatepickerManager = new A.OverlayManager({
- /**
- * ZIndex default value passed to the
- * <a href="OverlayManager.html#config_zIndexBase">zIndexBase</a> of
- * <a href="OverlayManager.html">OverlayManager</a>.
- *
- * @attribute zIndexBase
- * @default 1000
- * @type Number
- */
- zIndexBase: 1000
- });
-
- }, '@VERSION@' ,{requires:['aui-calendar','aui-overlay-context'], skinnable:true});
- AUI.add('aui-datepicker-select', function(A) {
- /**
- * The DatePickerSelect Utility
- *
- * @module aui-calendar
- * @submodule aui-calendar-datepicker-select
- */
-
- var Lang = A.Lang,
- isArray = Lang.isArray,
-
- nodeSetter = function(v) {
- return A.one(v);
- },
-
- createSelect = function() {
- return A.Node.create(SELECT_TPL);
- },
-
- DOC = A.config.doc,
-
- APPEND_ORDER = 'appendOrder',
- BLANK = '',
- BODY = 'body',
- BOUNDING_BOX = 'boundingBox',
- BUTTON = 'button',
- BUTTON_NODE = 'buttonNode',
- BUTTONITEM = 'buttonitem',
- CALENDAR = 'calendar',
- CLEARFIX = 'clearfix',
- CONTENT = 'content',
- CONTENT_BOX = 'contentBox',
- CURRENT_DAY = 'currentDay',
- CURRENT_MONTH = 'currentMonth',
- CURRENT_YEAR = 'currentYear',
- DATA_COMPONENT_ID = 'data-auiComponentID',
- DATEPICKER = 'datepicker',
- DAY = 'day',
- DAY_NODE = 'dayNode',
- DAY_NODE_NAME = 'dayNodeName',
- DISABLED = 'disabled',
- DISPLAY = 'display',
- DOT = '.',
- HELPER = 'helper',
- LOCALE = 'locale',
- ID = 'id',
- MAX_DATE = 'maxDate',
- MIN_DATE = 'minDate',
- MONTH = 'month',
- MONTH_NODE = 'monthNode',
- MONTH_NODE_NAME = 'monthNodeName',
- NAME = 'name',
- NULLABLE_DAY = 'nullableDay',
- NULLABLE_MONTH = 'nullableMonth',
- NULLABLE_YEAR = 'nullableYear',
- OPTION = 'option',
- POPULATE_DAY = 'populateDay',
- POPULATE_MONTH = 'populateMonth',
- POPULATE_YEAR = 'populateYear',
- SELECT = 'select',
- SELECTED = 'selected',
- SELECT_WRAPPER_NODE = 'selectWrapperNode',
- SPACE = ' ',
- SRC_NODE = 'srcNode',
- TRIGGER = 'trigger',
- WRAPPER = 'wrapper',
- YEAR = 'year',
- YEAR_NODE = 'yearNode',
- YEAR_NODE_NAME = 'yearNodeName',
- YEAR_RANGE = 'yearRange',
-
- getClassName = A.getClassName,
-
- CSS_BUTTONITEM = getClassName(BUTTONITEM),
- CSS_DATEPICKER = getClassName(DATEPICKER),
- CSS_DATEPICKER_BUTTON_WRAPPER = getClassName(DATEPICKER, BUTTON, WRAPPER),
- CSS_DATEPICKER_DAY = getClassName(DATEPICKER, DAY),
- CSS_DATEPICKER_DISPLAY = getClassName(DATEPICKER, DISPLAY),
- CSS_DATEPICKER_DISPLAY_CONTENT = getClassName(DATEPICKER, DISPLAY, CONTENT),
- CSS_DATEPICKER_MONTH = getClassName(DATEPICKER, MONTH),
- CSS_DATEPICKER_SELECT_WRAPPER = getClassName(DATEPICKER, SELECT, WRAPPER),
- CSS_DATEPICKER_YEAR = getClassName(DATEPICKER, YEAR),
- CSS_HELPER_CLEARFIX = getClassName(HELPER, CLEARFIX),
-
- SELECT_TPL = '<select></select>',
- SELECT_OPTION_TPL = '<option></option>',
- WRAPPER_BUTTON_TPL = '<div class="'+ CSS_DATEPICKER_BUTTON_WRAPPER +'"></div>',
- WRAPPER_SELECT_TPL = '<div class='+ CSS_DATEPICKER_SELECT_WRAPPER +'></div>';
-
- /**
- * <p><img src="assets/images/aui-calendar-datepicker-select/main.png"/></p>
- *
- * A base class for DatePickerSelect, providing:
- * <ul>
- * <li>Widget Lifecycle (initializer, renderUI, bindUI, syncUI, destructor)</li>
- * <li>Select a date from Calendar to select elements</li>
- * </ul>
- *
- * Quick Example:<br/>
- *
- * <pre><code>var instance = new A.DatePickerSelect({
- * srcNode: '#srcNodeId',
- * calendar: {
- * // locale: 'pt-br',
- * dateFormat: '%m/%d/%y',
- * yearRange: [ 1970, 2009 ]
- * }
- * }).render();
- * </code></pre>
- *
- * Check the list of <a href="DatePickerSelect.html#configattributes">Configuration Attributes</a> available for
- * DatePickerSelect.
- *
- * @class DatePickerSelect
- * @param config {Object} Object literal specifying widget configuration properties.
- * @constructor
- * @extends Component
- */
- var DatePickerSelect = A.Component.create(
- {
- /**
- * Static property provides a string to identify the class.
- *
- * @property DatePickerSelect.NAME
- * @type String
- * @static
- */
- NAME: DATEPICKER,
-
- /**
- * Static property used to define the default attribute
- * configuration for the DatePickerSelect.
- *
- * @property DatePickerSelect.ATTRS
- * @type Object
- * @static
- */
- ATTRS: {
- /**
- * The order the selects elements are appended to the
- * <a href="DatePickerSelect.html#config_srcNode">srcNode</a>.
- *
- * @attribute appendOrder
- * @default [ 'm', 'd', 'y' ]
- * @type Array
- */
- appendOrder: {
- validator: isArray,
- value: [ 'm', 'd', 'y' ]
- },
-
- /**
- * DOM Node to display the button of the DatePickerSelect. If not
- * specified try to query using HTML_PARSER an element inside
- * contentBox which matches <code>aui-buttonitem</code>.
- *
- * @attribute buttonNode
- * @default Generated div element.
- * @type String
- */
- buttonNode: {},
-
- /**
- * <a href="Calendar.html">Calendar</a> configuration Object.</a>
- *
- * @attribute calendar
- * @default {}
- * @type Object
- */
- calendar: {
- value: {}
- },
-
- /**
- * DOM Node to display the day of the DatePickerSelect. If not
- * specified try to query using HTML_PARSER an element inside
- * contentBox which matches <code>aui-datepicker-year</code>.
- *
- * @attribute dayNode
- * @default Generated div element.
- * @type String | Node
- */
- dayNode: {
- setter: nodeSetter,
- valueFn: createSelect
- },
-
- /**
- * Name attribute used on the
- * <a href="DatePickerSelect.html#config_dayNode">dayNode</a>.
- *
- * @attribute dayNodeName
- * @default day
- * @type String
- */
- dayNodeName: {
- valueFn: function() {
- return this.get(DAY_NODE).get(NAME) || DAY;
- }
- },
-
- /**
- * DOM Node to display the month of the DatePickerSelect. If not
- * specified try to query using HTML_PARSER an element inside
- * contentBox which matches <code>aui-datepicker-year</code>.
- *
- * @attribute monthNode
- * @default Generated div element.
- * @type String | Node
- */
- monthNode: {
- setter: nodeSetter,
- valueFn: createSelect
- },
-
- /**
- * Name attribute used on the
- * <a href="DatePickerSelect.html#config_monthNode">monthNode</a>.
- *
- * @attribute monthNodeName
- * @default month
- * @type String
- */
- monthNodeName: {
- valueFn: function() {
- return this.get(MONTH_NODE).get(NAME) || MONTH;
- }
- },
-
- /**
- * If true the select element for the day will be nullable
- *
- * @attribute nullableDay
- * @default false
- * @type boolean
- */
- nullableDay: {
- value: false
- },
-
- /**
- * If true the select element for the month will be nullable
- *
- * @attribute nullableMonth
- * @default false
- * @type boolean
- */
- nullableMonth: {
- value: false
- },
-
- /**
- * If true the select element for the year will be nullable
- *
- * @attribute nullableYear
- * @default false
- * @type boolean
- */
- nullableYear: {
- value: false
- },
-
- /**
- * If true the select element for the days will be automatic
- * populated.
- *
- * @attribute populateDay
- * @default true
- * @type boolean
- */
- populateDay: {
- value: true
- },
-
- /**
- * If true the select element for the month will be automatic
- * populated.
- *
- * @attribute populateMonth
- * @default true
- * @type boolean
- */
- populateMonth: {
- value: true
- },
-
- /**
- * If true the select element for the year will be automatic
- * populated.
- *
- * @attribute populateYear
- * @default true
- * @type boolean
- */
- populateYear: {
- value: true
- },
-
- /**
- * DOM Node to display the selects of the DatePickerSelect. If not
- * specified try to query using HTML_PARSER an element inside
- * contentBox which matches <code>aui-datepicker-select-wrapper</code>.
- *
- * @attribute selectWrapperNode
- * @default Generated div element.
- * @type String
- */
- selectWrapperNode: {
- valueFn: function() {
- return A.Node.create(WRAPPER_SELECT_TPL);
- }
- },
-
- /**
- * Trigger element to open the calendar. Inherited from
- * <a href="OverlayContext.html#config_trigger">OverlayContext</a>.
- *
- * @attribute trigger
- * @default Generated HTLM div element
- * @type {Node | String}
- */
- trigger: {
- setter: function(value) {
- if (value instanceof A.NodeList) {
- return value;
- }
- else if (Lang.isString(value)) {
- return A.all(value);
- }
-
- return new A.NodeList(value);
- },
- valueFn: function() {
- return A.NodeList.create(WRAPPER_BUTTON_TPL);
- }
- },
-
- /**
- * DOM Node to display the year of the DatePickerSelect. If not
- * specified try to query using HTML_PARSER an element inside
- * contentBox which matches <code>aui-datepicker-year</code>.
- *
- * @attribute yearNode
- * @default Generated div element.
- * @type String | Node
- */
- yearNode: {
- setter: nodeSetter,
- valueFn: createSelect
- },
-
- /**
- * Name attribute used on the
- * <a href="DatePickerSelect.html#config_yearNode">yearNode</a>.
- *
- * @attribute yearNodeName
- * @default year
- * @type String
- */
- yearNodeName: {
- valueFn: function() {
- return this.get(YEAR_NODE).get(NAME) || YEAR;
- }
- },
-
- /**
- * Year range to be displayed on the year select element. By default
- * it displays from -10 to +10 years from the current year.
- *
- * @attribute yearRange
- * @default [ year - 10, year + 10 ]
- * @type Array
- */
- yearRange: {
- validator: isArray,
- valueFn: function() {
- var year = new Date().getFullYear();
-
- return [ year - 10, year + 10 ];
- }
- }
- },
-
- /**
- * Object hash, defining how attribute values are to be parsed from
- * markup contained in the widget's content box.
- *
- * @property DatePickerSelect.HTML_PARSER
- * @type Object
- * @static
- */
- HTML_PARSER: {
- buttonNode: DOT + CSS_BUTTONITEM,
- dayNode: DOT + CSS_DATEPICKER_DAY,
- monthNode: DOT + CSS_DATEPICKER_MONTH,
- selectWrapperNode: DOT + CSS_DATEPICKER_SELECT_WRAPPER,
- trigger: DOT + CSS_DATEPICKER_BUTTON_WRAPPER,
- yearNode: DOT + CSS_DATEPICKER_YEAR
- },
-
- EXTENDS: A.Component,
-
- prototype: {
- /**
- * Bind the events on the DatePickerSelect UI. Lifecycle.
- *
- * @method bindUI
- * @protected
- */
- bindUI: function() {
- var instance = this;
-
- instance._bindSelectEvents();
-
- instance.after('calendar:clear', instance._afterClearDate);
- instance.after('calendar:select', instance._afterSelectDate);
- },
-
- /**
- * Descructor lifecycle implementation for the Datepicker class.
- * Purges events attached to the node (and all child nodes).
- *
- * @method destructor
- * @protected
- */
- destructor: function() {
- var instance = this;
-
- instance.datePicker.destroy();
- },
-
- /**
- * Create the DOM structure for the DatePickerSelect. Lifecycle.
- *
- * @method renderUI
- * @protected
- */
- renderUI: function() {
- var instance = this;
-
- instance._renderElements();
- instance._renderTriggerButton();
- instance._renderCalendar();
- },
-
- /**
- * Sync the DatePickerSelect UI. Lifecycle.
- *
- * @method syncUI
- * @protected
- */
- syncUI: function() {
- var instance = this;
-
- instance._syncSelectsUI();
- },
-
- /**
- * Fires when a None is selected on the Calendar.
- *
- * @method _afterClearDate
- * @param {Event} event
- * @protected
- */
- _afterClearDate: function(event) {
- var instance = this;
-
- if (instance.get(NULLABLE_DAY) && instance.get(NULLABLE_MONTH) && instance.get(NULLABLE_YEAR)) {
- instance.get(DAY_NODE).val(-1);
- instance.get(MONTH_NODE).val(-1);
- instance.get(YEAR_NODE).val(-1);
- }
- },
-
- /**
- * Fires when a date is selected on the Calendar.
- *
- * @method _afterSelectDate
- * @param {Event} event
- * @protected
- */
- _afterSelectDate: function(event) {
- var instance = this;
-
- if (event.date.normal.length) {
- instance._syncSelectsUI();
- }
- },
-
- /**
- * Bind events on each select element (change, keypress, etc).
- *
- * @method _bindSelectEvents
- * @protected
- */
- _bindSelectEvents: function() {
- var instance = this;
-
- var selects = instance.get(SELECT_WRAPPER_NODE).all(SELECT);
-
- selects.on('change', instance._onSelectChange, instance);
- selects.on('keypress', instance._onSelectChange, instance);
- },
-
- /**
- * Gets an Array with the field elements in the correct order defined
- * on <a href="DatePickerSelect.html#config_appendOrder">appendOrder</a>.
- *
- * @method _getAppendOrder
- * @protected
- * @return {Array}
- */
- _getAppendOrder: function() {
- var instance = this;
-
- var appendOrder = instance.get(APPEND_ORDER);
- var id = instance.get(ID);
-
- var mapping = {
- d: instance.get(DAY_NODE),
- m: instance.get(MONTH_NODE),
- y: instance.get(YEAR_NODE)
- };
-
- var firstField = mapping[ appendOrder[0] ];
- var secondField = mapping[ appendOrder[1] ];
- var thirdField = mapping[ appendOrder[2] ];
-
- firstField.setAttribute(DATA_COMPONENT_ID, id);
- secondField.setAttribute(DATA_COMPONENT_ID, id);
- thirdField.setAttribute(DATA_COMPONENT_ID, id);
-
- return [ firstField, secondField, thirdField ];
- },
-
- /**
- * Fired on any select change.
- *
- * @method _onSelectChange
- * @param {EventFacade} event
- * @protected
- */
- _onSelectChange: function(event) {
- var instance = this;
-
- var target = event.currentTarget || event.target;
-
- var monthChanged = target.test(DOT + CSS_DATEPICKER_MONTH);
- var yearChanged = target.test(DOT + CSS_DATEPICKER_YEAR);
-
- var currentDay = instance.get(DAY_NODE).val();
- var currentMonth = instance.get(MONTH_NODE).val();
- var currentYear = instance.get(YEAR_NODE).val();
-
- var validDay = (currentDay > -1);
- var validMonth = (currentMonth > -1);
- var validYear = (currentYear > -1);
-
- if (validDay) {
- instance.calendar.set(CURRENT_DAY, currentDay);
- }
-
- if (validMonth) {
- instance.calendar.set(CURRENT_MONTH, currentMonth);
- }
-
- if (validYear) {
- instance.calendar.set(CURRENT_YEAR, currentYear);
- }
-
- if (monthChanged || yearChanged) {
- instance._uiSetCurrentMonth();
-
- if (validDay) {
- instance._selectCurrentDay();
- }
- }
-
- if (validDay) {
- instance.calendar.selectCurrentDate();
- }
-
- if (!validDay || !validMonth || !validYear) {
- instance.calendar.clear();
- }
- },
-
- /**
- * Populate the day select element with the correct data.
- *
- * @method _populateDays
- * @protected
- */
- _populateDays: function() {
- var instance = this;
-
- if (instance.get(POPULATE_DAY)) {
- instance._populateSelect(
- instance.get(DAY_NODE),
- 1,
- instance.calendar.getDaysInMonth(),
- null,
- null,
- instance.get(NULLABLE_DAY)
- );
- }
- },
-
- /**
- * Populate the month select element with the correct data.
- *
- * @method _populateMonths
- * @protected
- */
- _populateMonths: function() {
- var instance = this;
-
- var localeMap = instance.calendar._getLocaleMap();
- var monthLabels = localeMap.B;
-
- if (instance.get(POPULATE_MONTH)) {
- instance._populateSelect(
- instance.get(MONTH_NODE),
- 0,
- (monthLabels.length - 1),
- monthLabels,
- null,
- instance.get(NULLABLE_MONTH)
- );
- }
- },
-
- /**
- * Populate the year select element with the correct data.
- *
- * @method _populateYears
- * @protected
- */
- _populateYears: function() {
- var instance = this;
-
- var yearRange = instance.get(YEAR_RANGE);
-
- if (instance.get(POPULATE_YEAR)) {
- instance._populateSelect(
- instance.get(YEAR_NODE),
- yearRange[0],
- yearRange[1],
- null,
- null,
- instance.get(NULLABLE_YEAR)
- );
- }
- },
-
- /**
- * Populate a select element with the data passed on the params.
- *
- * @method _populateSelect
- * @param {HTMLSelectElement} select Select to be populated
- * @param {Number} fromIndex Index to start
- * @param {Number} toIndex Index to end
- * @param {Object} values Object with labels to be used as content of each
- * option. Optional.
- * @protected
- * @return {String}
- */
- _populateSelect: function(select, fromIndex, toIndex, labels, values, nullable) {
- var i = 0;
- var index = fromIndex;
-
- var selectEl = A.Node.getDOMNode(select);
-
- select.empty();
- labels = labels || [];
- values = values || [];
-
- if (nullable) {
- selectEl.options[0] = new Option(BLANK, -1);
-
- i++;
- }
-
- while (index <= toIndex) {
- var value = values[index] || index;
- var label = labels[index] || index;
-
- selectEl.options[i] = new Option(label, index);
-
- i++;
- index++;
- }
- },
-
- /**
- * Populate each select element with the correct data for the day, month
- * and year.
- *
- * @method _populateSelects
- * @protected
- */
- _populateSelects: function() {
- var instance = this;
-
- instance._populateDays();
- instance._populateMonths();
- instance._populateYears();
-
- // restricting dates based on the selects values
- var monthOptions = instance.get(MONTH_NODE).all(OPTION);
- var yearOptions = instance.get(YEAR_NODE).all(OPTION);
-
- var mLength = monthOptions.size() - 1;
- var yLength = yearOptions.size() - 1;
-
- var firstMonth = monthOptions.item(0).val();
- var firstYear = yearOptions.item(0).val();
- var lastMonth = monthOptions.item(mLength).val();
- var lastYear = yearOptions.item(yLength).val();
-
- var maxMonthDays = instance.calendar.getDaysInMonth(lastYear, lastMonth);
-
- var minDate = new Date(firstYear, firstMonth, 1);
- var maxDate = new Date(lastYear, lastMonth, maxMonthDays);
-
- instance.calendar.set(MAX_DATE, maxDate);
- instance.calendar.set(MIN_DATE, minDate);
- },
-
- _renderCalendar: function() {
- var instance = this;
-
- var datePickerConfig = {
- calendar: instance.get(CALENDAR),
- trigger: instance.get(TRIGGER).item(0)
- };
-
- var datePicker = new A.DatePicker(datePickerConfig).render();
-
- datePicker.addTarget(instance);
-
- instance.datePicker = datePicker;
- instance.calendar = datePicker.calendar;
- },
-
- /**
- * Render DOM elements for the DatePickerSelect.
- *
- * @method _renderElements
- * @protected
- */
- _renderElements: function() {
- var instance = this;
-
- var boundingBox = instance.get(BOUNDING_BOX);
- var contentBox = instance.get(CONTENT_BOX);
-
- var dayNode = instance.get(DAY_NODE);
- var monthNode = instance.get(MONTH_NODE);
- var yearNode = instance.get(YEAR_NODE);
-
- dayNode.addClass(CSS_DATEPICKER_DAY);
- monthNode.addClass(CSS_DATEPICKER_MONTH);
- yearNode.addClass(CSS_DATEPICKER_YEAR);
-
- boundingBox.addClass(CSS_DATEPICKER_DISPLAY);
- boundingBox.addClass(CSS_HELPER_CLEARFIX);
-
- contentBox.addClass(CSS_DATEPICKER_DISPLAY_CONTENT);
-
- // setting name of the fields
- monthNode.set(NAME, instance.get(MONTH_NODE_NAME));
- yearNode.set(NAME, instance.get(YEAR_NODE_NAME));
- dayNode.set(NAME, instance.get(DAY_NODE_NAME));
-
- if (!monthNode.inDoc(A.config.doc)) {
- // append elements
- var selectWrapper = instance.get(SELECT_WRAPPER_NODE);
- var orderedFields = instance._getAppendOrder();
-
- // this textNode is to prevent layout shifting only
- // simulate the default browser space between inputs/selects on re-append
- var textNode = A.one(
- DOC.createTextNode(SPACE)
- );
-
- selectWrapper.append(orderedFields[0]);
- selectWrapper.append( textNode.clone() );
- selectWrapper.append(orderedFields[1]);
- selectWrapper.append( textNode );
- selectWrapper.append(orderedFields[2]);
-
- contentBox.append(selectWrapper);
- }
- },
-
- /**
- * Render DOM element for the trigger button of the DatePickerSelect.
- *
- * @method _renderTriggerButton
- * @protected
- */
- _renderTriggerButton: function() {
- var instance = this;
-
- var trigger = instance.get(TRIGGER).item(0);
-
- instance._buttonItem = new A.ButtonItem(
- {
- boundingBox: instance.get(BUTTON_NODE),
- icon: CALENDAR
- }
- );
-
- instance.get(CONTENT_BOX).append(trigger);
-
- trigger.setAttribute(DATA_COMPONENT_ID, instance.get(ID));
-
- if ( trigger.test(DOT + CSS_DATEPICKER_BUTTON_WRAPPER) ) {
- // use Button if the user doesn't specify a trigger
- instance._buttonItem.render(trigger);
- }
- },
-
- /**
- * Select the current day on the respective input field.
- *
- * @method _selectCurrentDay
- * @protected
- */
- _selectCurrentDay: function() {
- var instance = this;
-
- var currentDate = instance.calendar.getCurrentDate();
-
- instance.get(DAY_NODE).val(
- String(currentDate.getDate())
- );
- },
-
- /**
- * Select the current month on the respective input field.
- *
- * @method _selectCurrentMonth
- * @protected
- */
- _selectCurrentMonth: function() {
- var instance = this;
-
- var currentDate = instance.calendar.getCurrentDate();
-
- instance.get(MONTH_NODE).val(
- String(currentDate.getMonth())
- );
- },
-
- /**
- * Select the current year on the respective input field.
- *
- * @method _selectCurrentYear
- * @protected
- */
- _selectCurrentYear: function() {
- var instance = this;
-
- var currentDate = instance.calendar.getCurrentDate();
-
- instance.get(YEAR_NODE).val(
- String(currentDate.getFullYear())
- );
- },
-
- /**
- * Sync the UI of each DOM Select element.
- *
- * @method _syncSelectsUI
- * @protected
- */
- _syncSelectsUI: function() {
- var instance = this;
-
- instance._populateSelects();
- instance._selectCurrentDay();
- instance._selectCurrentMonth();
- instance._selectCurrentYear();
- },
-
- /**
- * Fired after
- * <a href="DatePickerSelect.html#config_currentMonth">currentMonth</a> is set.
- *
- * @method _uiSetCurrentMonth
- * @param {EventFacade} event
- * @protected
- */
- _uiSetCurrentMonth: function(value) {
- var instance = this;
-
- instance._populateDays();
- },
-
- /**
- * Fired after
- * <a href="DatePickerSelect.html#config_disabled">disabled</a> is set.
- *
- * @method _afterDisabledChangeDatePicker
- * @param {EventFacade} event
- * @protected
- */
- _uiSetDisabled: function(disabled) {
- var instance = this;
-
- DatePickerSelect.superclass._uiSetDisabled.apply(instance, arguments);
-
- instance.get(DAY_NODE).set('disabled', disabled);
- instance.get(MONTH_NODE).set('disabled', disabled);
- instance.get(YEAR_NODE).set('disabled', disabled);
-
- instance.datePicker.set(DISABLED, disabled);
-
- instance._buttonItem.set(DISABLED, disabled);
- instance._buttonItem.StateInteraction.set(DISABLED, disabled);
- }
- }
- }
- );
-
- A.DatePickerSelect = DatePickerSelect;
-
- }, '@VERSION@' ,{requires:['aui-datepicker-base','aui-button-item'], skinnable:true});
-
-
- AUI.add('aui-datepicker', function(A){}, '@VERSION@' ,{skinnable:true, use:['aui-datepicker-base','aui-datepicker-select']});
|