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);
164 if(typeof(this.vIndex) != 'undefined' && this.value.length){
165 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
168 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
169 e.removeClass('active');
171 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
172 e.addClass('active');
179 if(this.isInline) return;
181 this.picker().removeClass(['bottom', 'top']);
183 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
185 * place to the top of element!
189 this.picker().addClass('top');
190 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
195 this.picker().addClass('bottom');
197 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
202 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
208 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
210 var d = this.inputEl().getValue();
219 this.picker().show();
220 this.picker().select('>.datepicker-months', true).first().show();
224 this.fireEvent('show', this, this.date);
229 if(this.isInline) return;
230 this.picker().hide();
231 this.fireEvent('hide', this, this.date);
235 onMousedown: function(e)
243 Roo.bootstrap.MonthField.superclass.keyup.call(this);
249 if (!this.picker().isVisible()){
250 if (e.keyCode == 27) // allow escape to hide and re-show picker
255 var dateChanged = false,
257 newDate, newViewDate;
259 // switch(e.keyCode){
260 // case 27: // escape
262 // e.preventDefault();
266 // if (!this.keyboardNavigation) break;
267 // dir = e.keyCode == 37 ? -1 : 1;
270 // newDate = this.moveYear(this.date, dir);
271 // newViewDate = this.moveYear(this.viewDate, dir);
272 // } else if (e.shiftKey){
273 // newDate = this.moveMonth(this.date, dir);
274 // newViewDate = this.moveMonth(this.viewDate, dir);
276 // newDate = new Date(this.date);
277 // newDate.setUTCDate(this.date.getUTCDate() + dir);
278 // newViewDate = new Date(this.viewDate);
279 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
281 // if (this.dateWithinRange(newDate)){
282 // this.date = newDate;
283 // this.viewDate = newViewDate;
284 // this.setValue(this.formatDate(this.date));
286 // e.preventDefault();
287 // dateChanged = true;
292 // if (!this.keyboardNavigation) break;
293 // dir = e.keyCode == 38 ? -1 : 1;
295 // newDate = this.moveYear(this.date, dir);
296 // newViewDate = this.moveYear(this.viewDate, dir);
297 // } else if (e.shiftKey){
298 // newDate = this.moveMonth(this.date, dir);
299 // newViewDate = this.moveMonth(this.viewDate, dir);
301 // newDate = new Date(this.date);
302 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
303 // newViewDate = new Date(this.viewDate);
304 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
306 // if (this.dateWithinRange(newDate)){
307 // this.date = newDate;
308 // this.viewDate = newViewDate;
309 // this.setValue(this.formatDate(this.date));
311 // e.preventDefault();
312 // dateChanged = true;
316 // this.setValue(this.formatDate(this.date));
318 // e.preventDefault();
321 // this.setValue(this.formatDate(this.date));
336 this.picker().remove();
341 Roo.apply(Roo.bootstrap.MonthField, {
360 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
361 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
366 Roo.apply(Roo.bootstrap.MonthField, {
370 cls: 'datepicker dropdown-menu roo-dynamic',
374 cls: 'datepicker-months',
378 cls: 'table-condensed',
380 Roo.bootstrap.DateField.content