9 * @class Roo.bootstrap.MonthField
10 * @extends Roo.bootstrap.Input
11 * Bootstrap MonthField class
13 * @cfg {String} language default en
16 * Create a new MonthField
17 * @param {Object} config The config object
20 Roo.bootstrap.MonthField = function(config){
21 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
26 * Fires when this field show.
27 * @param {Roo.bootstrap.MonthField} this
28 * @param {Mixed} date The date value
33 * Fires when this field hide.
34 * @param {Roo.bootstrap.MonthField} this
35 * @param {Mixed} date The date value
40 * Fires when select a date.
41 * @param {Roo.bootstrap.MonthField} this
42 * @param {Mixed} date The date value
48 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
52 onRender: function(ct, position)
55 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
57 this.language = this.language || 'en';
58 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
59 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
61 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
62 this.format = this.format || 'F';
63 this.isInline = false;
65 this.component = this.el.select('.add-on', true).first() || false;
66 this.component = (this.component && this.component.length === 0) ? false : this.component;
67 this.hasInput = this.component && this.inputEL().length;
72 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
74 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
76 this.picker().on('mousedown', this.onMousedown, this);
77 this.picker().on('click', this.onClick, this);
79 this.picker().addClass('datepicker-dropdown');
81 this.startViewMode = this.viewMode;
83 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
84 v.setStyle('width', '189px');
98 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
102 this.fireEvent('select', this, this.date);
116 var target = e.getTarget();
118 if(target.nodeName.toLowerCase() === 'i'){
119 target = Roo.get(target).dom.parentNode;
122 var nodeName = target.nodeName;
123 var className = target.className;
124 var html = target.innerHTML;
126 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
129 this.viewDate.setUTCDate(1);
130 this.viewDate.setUTCMonth(Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html));
132 this.setValue(this.formatDate(this.viewDate));
139 return this.pickerEl;
142 fillMonths: function()
145 var months = this.picker().select('>.datepicker-months td', true).first();
147 months.dom.innerHTML = '';
153 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
156 months.createChild(month);
163 this.date = (typeof(this.date) === 'undefined' || ((typeof(this.date) === 'string') && !this.date.length)) ? this.UTCToday() : (typeof(this.date) === 'string') ? this.parseDate(this.date) : this.date;
165 if (this.date < this.startDate) {
166 this.viewDate = new Date(this.startDate);
167 } else if (this.date > this.endDate) {
168 this.viewDate = new Date(this.endDate);
170 this.viewDate = new Date(this.date);
183 if(this.isInline) return;
185 this.picker().removeClass(['bottom', 'top']);
187 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
189 * place to the top of element!
193 this.picker().addClass('top');
194 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
199 this.picker().addClass('bottom');
201 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
206 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
212 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
214 var d = this.inputEl().getValue();
223 this.picker().show();
227 this.fireEvent('show', this, this.date);
232 if(this.isInline) return;
233 this.picker().hide();
234 this.fireEvent('hide', this, this.date);
238 onMousedown: function(e)
246 Roo.bootstrap.MonthField.superclass.keyup.call(this);
252 if (!this.picker().isVisible()){
253 if (e.keyCode == 27) // allow escape to hide and re-show picker
258 var dateChanged = false,
260 newDate, newViewDate;
262 // switch(e.keyCode){
263 // case 27: // escape
265 // e.preventDefault();
269 // if (!this.keyboardNavigation) break;
270 // dir = e.keyCode == 37 ? -1 : 1;
273 // newDate = this.moveYear(this.date, dir);
274 // newViewDate = this.moveYear(this.viewDate, dir);
275 // } else if (e.shiftKey){
276 // newDate = this.moveMonth(this.date, dir);
277 // newViewDate = this.moveMonth(this.viewDate, dir);
279 // newDate = new Date(this.date);
280 // newDate.setUTCDate(this.date.getUTCDate() + dir);
281 // newViewDate = new Date(this.viewDate);
282 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
284 // if (this.dateWithinRange(newDate)){
285 // this.date = newDate;
286 // this.viewDate = newViewDate;
287 // this.setValue(this.formatDate(this.date));
289 // e.preventDefault();
290 // dateChanged = true;
295 // if (!this.keyboardNavigation) break;
296 // dir = e.keyCode == 38 ? -1 : 1;
298 // newDate = this.moveYear(this.date, dir);
299 // newViewDate = this.moveYear(this.viewDate, dir);
300 // } else if (e.shiftKey){
301 // newDate = this.moveMonth(this.date, dir);
302 // newViewDate = this.moveMonth(this.viewDate, dir);
304 // newDate = new Date(this.date);
305 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
306 // newViewDate = new Date(this.viewDate);
307 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
309 // if (this.dateWithinRange(newDate)){
310 // this.date = newDate;
311 // this.viewDate = newViewDate;
312 // this.setValue(this.formatDate(this.date));
314 // e.preventDefault();
315 // dateChanged = true;
319 // this.setValue(this.formatDate(this.date));
321 // e.preventDefault();
324 // this.setValue(this.formatDate(this.date));
339 this.picker().remove();
344 Roo.apply(Roo.bootstrap.MonthField, {
363 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
364 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
369 Roo.apply(Roo.bootstrap.MonthField, {
373 cls: 'datepicker dropdown-menu roo-dynamic',
377 cls: 'datepicker-months',
381 cls: 'table-condensed',
383 Roo.bootstrap.DateField.content