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');
91 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
95 this.fireEvent('select', this, this.date);
109 var target = e.getTarget();
111 if(target.nodeName.toLowerCase() === 'i'){
112 target = Roo.get(target).dom.parentNode;
115 var nodeName = target.nodeName;
116 var className = target.className;
117 var html = target.innerHTML;
119 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
123 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
125 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
133 return this.pickerEl;
136 fillMonths: function()
139 var months = this.picker().select('>.datepicker-months td', true).first();
141 months.dom.innerHTML = '';
147 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
150 months.createChild(month);
159 if(typeof(this.vIndex) == 'undefined' && this.value.length){
160 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
163 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
164 e.removeClass('active');
166 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
167 e.addClass('active');
174 if(this.isInline) return;
176 this.picker().removeClass(['bottom', 'top']);
178 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
180 * place to the top of element!
184 this.picker().addClass('top');
185 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
190 this.picker().addClass('bottom');
192 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
197 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
203 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
205 var d = this.inputEl().getValue();
214 this.picker().show();
215 this.picker().select('>.datepicker-months', true).first().show();
219 this.fireEvent('show', this, this.date);
224 if(this.isInline) return;
225 this.picker().hide();
226 this.fireEvent('hide', this, this.date);
230 onMousedown: function(e)
238 Roo.bootstrap.MonthField.superclass.keyup.call(this);
244 if (!this.picker().isVisible()){
245 if (e.keyCode == 27) // allow escape to hide and re-show picker
259 dir = e.keyCode == 37 ? -1 : 1;
261 this.vIndex = this.vIndex + dir;
267 if(this.vIndex > 11){
271 if(isNaN(this.vIndex)){
275 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
281 dir = e.keyCode == 38 ? -1 : 1;
283 this.vIndex = this.vIndex + dir * 4;
289 if(this.vIndex > 11){
293 if(isNaN(this.vIndex)){
297 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
302 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
303 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
310 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
311 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
324 this.fireEvent("specialkey", this, e);
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