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;
69 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
71 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
73 this.picker().on('mousedown', this.onMousedown, this);
74 this.picker().on('click', this.onClick, this);
76 this.picker().addClass('datepicker-dropdown');
88 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
92 this.fireEvent('select', this, this.date);
106 var target = e.getTarget();
108 if(target.nodeName.toLowerCase() === 'i'){
109 target = Roo.get(target).dom.parentNode;
112 var nodeName = target.nodeName;
113 var className = target.className;
114 var html = target.innerHTML;
116 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
120 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
122 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
130 return this.pickerEl;
133 fillMonths: function()
136 var months = this.picker().select('>.datepicker-months td', true).first();
138 months.dom.innerHTML = '';
144 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
147 months.createChild(month);
156 if(typeof(this.vIndex) == 'undefined' && this.value.length){
157 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
160 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
161 e.removeClass('active');
163 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
164 e.addClass('active');
171 if(this.isInline) return;
173 this.picker().removeClass(['bottom', 'top']);
175 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
177 * place to the top of element!
181 this.picker().addClass('top');
182 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
187 this.picker().addClass('bottom');
189 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
194 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
200 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
202 var d = this.inputEl().getValue();
211 this.picker().show();
212 this.picker().select('>.datepicker-months', true).first().show();
216 this.fireEvent('show', this, this.date);
221 if(this.isInline) return;
222 this.picker().hide();
223 this.fireEvent('hide', this, this.date);
227 onMousedown: function(e)
235 Roo.bootstrap.MonthField.superclass.keyup.call(this);
241 if (!this.picker().isVisible()){
242 if (e.keyCode == 27) // allow escape to hide and re-show picker
256 dir = e.keyCode == 37 ? -1 : 1;
258 this.vIndex = this.vIndex + dir;
264 if(this.vIndex > 11){
268 if(isNaN(this.vIndex)){
272 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
278 dir = e.keyCode == 38 ? -1 : 1;
280 this.vIndex = this.vIndex + dir * 4;
286 if(this.vIndex > 11){
290 if(isNaN(this.vIndex)){
294 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
299 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
300 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
307 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
308 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
324 this.picker().remove();
329 Roo.apply(Roo.bootstrap.MonthField, {
340 style: 'width: 189px;'
349 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
350 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
355 Roo.apply(Roo.bootstrap.MonthField, {
359 cls: 'datepicker dropdown-menu roo-dynamic',
363 cls: 'datepicker-months',
367 cls: 'table-condensed',
369 Roo.bootstrap.DateField.content