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]);
138 return this.pickerEl;
141 fillMonths: function()
144 var months = this.picker().select('>.datepicker-months td', true).first();
146 months.dom.innerHTML = '';
152 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
155 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
264 dir = e.keyCode == 37 ? -1 : 1;
266 this.vIndex = this.vIndex + dir;
272 if(this.vIndex > 11){
276 Roo.log(this.vIndex);
278 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
284 dir = e.keyCode == 38 ? -1 : 1;
286 this.vIndex = this.vIndex + dir * 4;
292 if(this.vIndex > 11){
295 Roo.log(this.vIndex);
296 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
300 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
305 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
320 this.picker().remove();
325 Roo.apply(Roo.bootstrap.MonthField, {
344 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
345 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
350 Roo.apply(Roo.bootstrap.MonthField, {
354 cls: 'datepicker dropdown-menu roo-dynamic',
358 cls: 'datepicker-months',
362 cls: 'table-condensed',
364 Roo.bootstrap.DateField.content