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');
97 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
101 this.fireEvent('select', this, this.date);
115 var target = e.getTarget();
117 if(target.nodeName.toLowerCase() === 'i'){
118 target = Roo.get(target).dom.parentNode;
121 var nodeName = target.nodeName;
122 var className = target.className;
123 var html = target.innerHTML;
125 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
129 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
131 var v = Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex];
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);
169 if(this.isInline) return;
171 this.picker().removeClass(['bottom', 'top']);
173 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
175 * place to the top of element!
179 this.picker().addClass('top');
180 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
185 this.picker().addClass('bottom');
187 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
192 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
198 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
200 var d = this.inputEl().getValue();
209 this.picker().show();
210 this.picker().select('>.datepicker-months', true).first().show();
214 this.fireEvent('show', this, this.date);
219 if(this.isInline) return;
220 this.picker().hide();
221 this.fireEvent('hide', this, this.date);
225 onMousedown: function(e)
233 Roo.bootstrap.MonthField.superclass.keyup.call(this);
239 if (!this.picker().isVisible()){
240 if (e.keyCode == 27) // allow escape to hide and re-show picker
245 var dateChanged = false,
247 newDate, newViewDate;
249 // switch(e.keyCode){
250 // case 27: // escape
252 // e.preventDefault();
256 // if (!this.keyboardNavigation) break;
257 // dir = e.keyCode == 37 ? -1 : 1;
260 // newDate = this.moveYear(this.date, dir);
261 // newViewDate = this.moveYear(this.viewDate, dir);
262 // } else if (e.shiftKey){
263 // newDate = this.moveMonth(this.date, dir);
264 // newViewDate = this.moveMonth(this.viewDate, dir);
266 // newDate = new Date(this.date);
267 // newDate.setUTCDate(this.date.getUTCDate() + dir);
268 // newViewDate = new Date(this.viewDate);
269 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
271 // if (this.dateWithinRange(newDate)){
272 // this.date = newDate;
273 // this.viewDate = newViewDate;
274 // this.setValue(this.formatDate(this.date));
276 // e.preventDefault();
277 // dateChanged = true;
282 // if (!this.keyboardNavigation) break;
283 // dir = e.keyCode == 38 ? -1 : 1;
285 // newDate = this.moveYear(this.date, dir);
286 // newViewDate = this.moveYear(this.viewDate, dir);
287 // } else if (e.shiftKey){
288 // newDate = this.moveMonth(this.date, dir);
289 // newViewDate = this.moveMonth(this.viewDate, dir);
291 // newDate = new Date(this.date);
292 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
293 // newViewDate = new Date(this.viewDate);
294 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
296 // if (this.dateWithinRange(newDate)){
297 // this.date = newDate;
298 // this.viewDate = newViewDate;
299 // this.setValue(this.formatDate(this.date));
301 // e.preventDefault();
302 // dateChanged = true;
306 // this.setValue(this.formatDate(this.date));
308 // e.preventDefault();
311 // this.setValue(this.formatDate(this.date));
326 this.picker().remove();
331 Roo.apply(Roo.bootstrap.MonthField, {
350 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
351 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
356 Roo.apply(Roo.bootstrap.MonthField, {
360 cls: 'datepicker dropdown-menu roo-dynamic',
364 cls: 'datepicker-months',
368 cls: 'table-condensed',
370 Roo.bootstrap.DateField.content