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, {
50 onRender: function(ct, position)
53 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
55 this.language = this.language || 'en';
56 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
57 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
59 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
60 this.format = this.format || 'F';
61 this.isInline = false;
63 this.component = this.el.select('.add-on', true).first() || false;
64 this.component = (this.component && this.component.length === 0) ? false : this.component;
65 this.hasInput = this.component && this.inputEL().length;
70 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
72 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
74 this.picker().on('mousedown', this.onMousedown, this);
75 this.picker().on('click', this.onClick, this);
77 this.picker().addClass('datepicker-dropdown');
79 this.startViewMode = this.viewMode;
81 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
82 v.setStyle('width', '189px');
95 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
99 this.fireEvent('select', this, this.date);
113 var target = e.getTarget();
115 if(target.nodeName.toLowerCase() === 'i'){
116 target = Roo.get(target).dom.parentNode;
119 var nodeName = target.nodeName;
120 var className = target.className;
121 var html = target.innerHTML;
123 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
127 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
129 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
136 return this.pickerEl;
139 fillMonths: function()
142 var months = this.picker().select('>.datepicker-months td', true).first();
144 months.dom.innerHTML = '';
150 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
153 months.createChild(month);
162 if(typeof(this.vIndex) != 'undefined' && this.value.length){
166 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
167 e.removeClass('active');
169 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
170 e.addClass('active');
177 if(this.isInline) return;
179 this.picker().removeClass(['bottom', 'top']);
181 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
183 * place to the top of element!
187 this.picker().addClass('top');
188 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
193 this.picker().addClass('bottom');
195 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
200 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
206 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
208 var d = this.inputEl().getValue();
217 this.picker().show();
218 this.picker().select('>.datepicker-months', true).first().show();
222 this.fireEvent('show', this, this.date);
227 if(this.isInline) return;
228 this.picker().hide();
229 this.fireEvent('hide', this, this.date);
233 onMousedown: function(e)
241 Roo.bootstrap.MonthField.superclass.keyup.call(this);
247 if (!this.picker().isVisible()){
248 if (e.keyCode == 27) // allow escape to hide and re-show picker
253 var dateChanged = false,
255 newDate, newViewDate;
257 // switch(e.keyCode){
258 // case 27: // escape
260 // e.preventDefault();
264 // if (!this.keyboardNavigation) break;
265 // dir = e.keyCode == 37 ? -1 : 1;
268 // newDate = this.moveYear(this.date, dir);
269 // newViewDate = this.moveYear(this.viewDate, dir);
270 // } else if (e.shiftKey){
271 // newDate = this.moveMonth(this.date, dir);
272 // newViewDate = this.moveMonth(this.viewDate, dir);
274 // newDate = new Date(this.date);
275 // newDate.setUTCDate(this.date.getUTCDate() + dir);
276 // newViewDate = new Date(this.viewDate);
277 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
279 // if (this.dateWithinRange(newDate)){
280 // this.date = newDate;
281 // this.viewDate = newViewDate;
282 // this.setValue(this.formatDate(this.date));
284 // e.preventDefault();
285 // dateChanged = true;
290 // if (!this.keyboardNavigation) break;
291 // dir = e.keyCode == 38 ? -1 : 1;
293 // newDate = this.moveYear(this.date, dir);
294 // newViewDate = this.moveYear(this.viewDate, dir);
295 // } else if (e.shiftKey){
296 // newDate = this.moveMonth(this.date, dir);
297 // newViewDate = this.moveMonth(this.viewDate, dir);
299 // newDate = new Date(this.date);
300 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
301 // newViewDate = new Date(this.viewDate);
302 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
304 // if (this.dateWithinRange(newDate)){
305 // this.date = newDate;
306 // this.viewDate = newViewDate;
307 // this.setValue(this.formatDate(this.date));
309 // e.preventDefault();
310 // dateChanged = true;
314 // this.setValue(this.formatDate(this.date));
316 // e.preventDefault();
319 // this.setValue(this.formatDate(this.date));
334 this.picker().remove();
339 Roo.apply(Roo.bootstrap.MonthField, {
358 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
359 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
364 Roo.apply(Roo.bootstrap.MonthField, {
368 cls: 'datepicker dropdown-menu roo-dynamic',
372 cls: 'datepicker-months',
376 cls: 'table-condensed',
378 Roo.bootstrap.DateField.content