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.isInline = false;
62 this.component = this.el.select('.add-on', true).first() || false;
63 this.component = (this.component && this.component.length === 0) ? false : this.component;
64 this.hasInput = this.component && this.inputEL().length;
66 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
68 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
70 this.picker().on('mousedown', this.onMousedown, this);
71 this.picker().on('click', this.onClick, this);
73 this.picker().addClass('datepicker-dropdown');
75 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
76 v.setStyle('width', '189px');
86 Roo.log('el!!!!!!!!!!!!!!!!!!!!!!!!!!1');
93 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
97 this.fireEvent('select', this, this.date);
111 var target = e.getTarget();
113 if(target.nodeName.toLowerCase() === 'i'){
114 target = Roo.get(target).dom.parentNode;
117 var nodeName = target.nodeName;
118 var className = target.className;
119 var html = target.innerHTML;
121 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
125 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
127 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
135 return this.pickerEl;
138 fillMonths: function()
141 var months = this.picker().select('>.datepicker-months td', true).first();
143 months.dom.innerHTML = '';
149 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
152 months.createChild(month);
161 if(typeof(this.vIndex) == 'undefined' && this.value.length){
162 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
165 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
166 e.removeClass('active');
168 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
169 e.addClass('active');
176 if(this.isInline) return;
178 this.picker().removeClass(['bottom', 'top']);
180 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
182 * place to the top of element!
186 this.picker().addClass('top');
187 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
192 this.picker().addClass('bottom');
194 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
199 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
205 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
207 var d = this.inputEl().getValue();
216 this.picker().show();
217 this.picker().select('>.datepicker-months', true).first().show();
221 this.fireEvent('show', this, this.date);
226 if(this.isInline) return;
227 this.picker().hide();
228 this.fireEvent('hide', this, this.date);
232 onMousedown: function(e)
240 Roo.bootstrap.MonthField.superclass.keyup.call(this);
246 if (!this.picker().isVisible()){
247 if (e.keyCode == 27) // allow escape to hide and re-show picker
261 dir = e.keyCode == 37 ? -1 : 1;
263 this.vIndex = this.vIndex + dir;
269 if(this.vIndex > 11){
273 if(isNaN(this.vIndex)){
277 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
283 dir = e.keyCode == 38 ? -1 : 1;
285 this.vIndex = this.vIndex + dir * 4;
291 if(this.vIndex > 11){
295 if(isNaN(this.vIndex)){
299 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
304 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
305 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
312 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
313 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
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