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 var v = Roo.bootstrap.MonthField.dates[this.language].months[Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html)];
140 return this.pickerEl;
143 fillMonths: function()
146 var months = this.picker().select('>.datepicker-months td', true).first();
148 months.dom.innerHTML = '';
154 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
157 months.createChild(month);
174 if(this.isInline) return;
176 this.picker().removeClass(['bottom', 'top']);
178 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
180 * place to the top of element!
184 this.picker().addClass('top');
185 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
190 this.picker().addClass('bottom');
192 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
197 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
203 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
205 var d = this.inputEl().getValue();
214 this.picker().show();
215 this.picker().select('>.datepicker-months', true).first().show();
219 this.fireEvent('show', this, this.date);
224 if(this.isInline) return;
225 this.picker().hide();
226 this.fireEvent('hide', this, this.date);
230 onMousedown: function(e)
238 Roo.bootstrap.MonthField.superclass.keyup.call(this);
244 if (!this.picker().isVisible()){
245 if (e.keyCode == 27) // allow escape to hide and re-show picker
250 var dateChanged = false,
252 newDate, newViewDate;
254 // switch(e.keyCode){
255 // case 27: // escape
257 // e.preventDefault();
261 // if (!this.keyboardNavigation) break;
262 // dir = e.keyCode == 37 ? -1 : 1;
265 // newDate = this.moveYear(this.date, dir);
266 // newViewDate = this.moveYear(this.viewDate, dir);
267 // } else if (e.shiftKey){
268 // newDate = this.moveMonth(this.date, dir);
269 // newViewDate = this.moveMonth(this.viewDate, dir);
271 // newDate = new Date(this.date);
272 // newDate.setUTCDate(this.date.getUTCDate() + dir);
273 // newViewDate = new Date(this.viewDate);
274 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
276 // if (this.dateWithinRange(newDate)){
277 // this.date = newDate;
278 // this.viewDate = newViewDate;
279 // this.setValue(this.formatDate(this.date));
281 // e.preventDefault();
282 // dateChanged = true;
287 // if (!this.keyboardNavigation) break;
288 // dir = e.keyCode == 38 ? -1 : 1;
290 // newDate = this.moveYear(this.date, dir);
291 // newViewDate = this.moveYear(this.viewDate, dir);
292 // } else if (e.shiftKey){
293 // newDate = this.moveMonth(this.date, dir);
294 // newViewDate = this.moveMonth(this.viewDate, dir);
296 // newDate = new Date(this.date);
297 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
298 // newViewDate = new Date(this.viewDate);
299 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
301 // if (this.dateWithinRange(newDate)){
302 // this.date = newDate;
303 // this.viewDate = newViewDate;
304 // this.setValue(this.formatDate(this.date));
306 // e.preventDefault();
307 // dateChanged = true;
311 // this.setValue(this.formatDate(this.date));
313 // e.preventDefault();
316 // this.setValue(this.formatDate(this.date));
331 this.picker().remove();
336 Roo.apply(Roo.bootstrap.MonthField, {
355 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
356 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
361 Roo.apply(Roo.bootstrap.MonthField, {
365 cls: 'datepicker dropdown-menu roo-dynamic',
369 cls: 'datepicker-months',
373 cls: 'table-condensed',
375 Roo.bootstrap.DateField.content