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);
173 if(this.isInline) return;
175 this.picker().removeClass(['bottom', 'top']);
177 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
179 * place to the top of element!
183 this.picker().addClass('top');
184 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
189 this.picker().addClass('bottom');
191 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
196 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
202 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
204 var d = this.inputEl().getValue();
213 this.picker().show();
217 this.fireEvent('show', this, this.date);
222 if(this.isInline) return;
223 this.picker().hide();
224 this.fireEvent('hide', this, this.date);
228 onMousedown: function(e)
236 Roo.bootstrap.MonthField.superclass.keyup.call(this);
242 if (!this.picker().isVisible()){
243 if (e.keyCode == 27) // allow escape to hide and re-show picker
248 var dateChanged = false,
250 newDate, newViewDate;
252 // switch(e.keyCode){
253 // case 27: // escape
255 // e.preventDefault();
259 // if (!this.keyboardNavigation) break;
260 // dir = e.keyCode == 37 ? -1 : 1;
263 // newDate = this.moveYear(this.date, dir);
264 // newViewDate = this.moveYear(this.viewDate, dir);
265 // } else if (e.shiftKey){
266 // newDate = this.moveMonth(this.date, dir);
267 // newViewDate = this.moveMonth(this.viewDate, dir);
269 // newDate = new Date(this.date);
270 // newDate.setUTCDate(this.date.getUTCDate() + dir);
271 // newViewDate = new Date(this.viewDate);
272 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
274 // if (this.dateWithinRange(newDate)){
275 // this.date = newDate;
276 // this.viewDate = newViewDate;
277 // this.setValue(this.formatDate(this.date));
279 // e.preventDefault();
280 // dateChanged = true;
285 // if (!this.keyboardNavigation) break;
286 // dir = e.keyCode == 38 ? -1 : 1;
288 // newDate = this.moveYear(this.date, dir);
289 // newViewDate = this.moveYear(this.viewDate, dir);
290 // } else if (e.shiftKey){
291 // newDate = this.moveMonth(this.date, dir);
292 // newViewDate = this.moveMonth(this.viewDate, dir);
294 // newDate = new Date(this.date);
295 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
296 // newViewDate = new Date(this.viewDate);
297 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
299 // if (this.dateWithinRange(newDate)){
300 // this.date = newDate;
301 // this.viewDate = newViewDate;
302 // this.setValue(this.formatDate(this.date));
304 // e.preventDefault();
305 // dateChanged = true;
309 // this.setValue(this.formatDate(this.date));
311 // e.preventDefault();
314 // this.setValue(this.formatDate(this.date));
329 this.picker().remove();
334 Roo.apply(Roo.bootstrap.MonthField, {
353 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
354 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
359 Roo.apply(Roo.bootstrap.MonthField, {
363 cls: 'datepicker dropdown-menu roo-dynamic',
367 cls: 'datepicker-months',
371 cls: 'table-condensed',
373 Roo.bootstrap.DateField.content