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.isInline = false;
64 this.component = this.el.select('.add-on', true).first() || false;
65 this.component = (this.component && this.component.length === 0) ? false : this.component;
66 this.hasInput = this.component && this.inputEL().length;
71 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
73 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
75 this.picker().on('mousedown', this.onMousedown, this);
76 this.picker().on('click', this.onClick, this);
78 this.picker().addClass('datepicker-dropdown');
80 this.startViewMode = this.viewMode;
82 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
83 v.setStyle('width', '189px');
96 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
100 this.fireEvent('select', this, this.date);
114 var target = e.getTarget();
116 if(target.nodeName.toLowerCase() === 'i'){
117 target = Roo.get(target).dom.parentNode;
120 var nodeName = target.nodeName;
121 var className = target.className;
122 var html = target.innerHTML;
124 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
128 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
130 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
137 return this.pickerEl;
140 fillMonths: function()
143 var months = this.picker().select('>.datepicker-months td', true).first();
145 months.dom.innerHTML = '';
151 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
154 months.createChild(month);
163 if(typeof(this.vIndex) == 'undefined' && this.value.length){
164 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
167 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
168 e.removeClass('active');
170 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
171 e.addClass('active');
178 if(this.isInline) return;
180 this.picker().removeClass(['bottom', 'top']);
182 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
184 * place to the top of element!
188 this.picker().addClass('top');
189 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
194 this.picker().addClass('bottom');
196 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
201 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
207 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
209 var d = this.inputEl().getValue();
218 this.picker().show();
219 this.picker().select('>.datepicker-months', true).first().show();
223 this.fireEvent('show', this, this.date);
228 if(this.isInline) return;
229 this.picker().hide();
230 this.fireEvent('hide', this, this.date);
234 onMousedown: function(e)
242 Roo.bootstrap.MonthField.superclass.keyup.call(this);
248 if (!this.picker().isVisible()){
249 if (e.keyCode == 27) // allow escape to hide and re-show picker
254 var dateChanged = false,
255 dir, day, month, year,
265 dir = e.keyCode == 37 ? -1 : 1;
267 newDate = new Date();
271 newDate.setUTCDate(this.date.getUTCDate() + dir);
272 newViewDate = new Date(this.viewDate);
273 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
280 if (!this.keyboardNavigation) break;
281 dir = e.keyCode == 38 ? -1 : 1;
283 newDate = this.moveYear(this.date, dir);
284 newViewDate = this.moveYear(this.viewDate, dir);
285 } else if (e.shiftKey){
286 newDate = this.moveMonth(this.date, dir);
287 newViewDate = this.moveMonth(this.viewDate, dir);
289 newDate = new Date(this.date);
290 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
291 newViewDate = new Date(this.viewDate);
292 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
294 if (this.dateWithinRange(newDate)){
296 this.viewDate = newViewDate;
297 this.setValue(this.formatDate(this.date));
304 this.setValue(this.formatDate(this.date));
309 this.setValue(this.formatDate(this.date));
324 this.picker().remove();
329 Roo.apply(Roo.bootstrap.MonthField, {
348 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
349 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
354 Roo.apply(Roo.bootstrap.MonthField, {
358 cls: 'datepicker dropdown-menu roo-dynamic',
362 cls: 'datepicker-months',
366 cls: 'table-condensed',
368 Roo.bootstrap.DateField.content