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');
78 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
79 v.setStyle('width', '189px');
92 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
96 this.fireEvent('select', this, this.date);
110 var target = e.getTarget();
112 if(target.nodeName.toLowerCase() === 'i'){
113 target = Roo.get(target).dom.parentNode;
116 var nodeName = target.nodeName;
117 var className = target.className;
118 var html = target.innerHTML;
120 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
124 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
126 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
134 return this.pickerEl;
137 fillMonths: function()
140 var months = this.picker().select('>.datepicker-months td', true).first();
142 months.dom.innerHTML = '';
148 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
151 months.createChild(month);
160 if(typeof(this.vIndex) == 'undefined' && this.value.length){
161 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
164 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
165 e.removeClass('active');
167 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
168 e.addClass('active');
175 if(this.isInline) return;
177 this.picker().removeClass(['bottom', 'top']);
179 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
181 * place to the top of element!
185 this.picker().addClass('top');
186 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
191 this.picker().addClass('bottom');
193 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
198 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
204 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
206 var d = this.inputEl().getValue();
215 this.picker().show();
216 this.picker().select('>.datepicker-months', true).first().show();
220 this.fireEvent('show', this, this.date);
225 if(this.isInline) return;
226 this.picker().hide();
227 this.fireEvent('hide', this, this.date);
231 onMousedown: function(e)
239 Roo.bootstrap.MonthField.superclass.keyup.call(this);
245 if (!this.picker().isVisible()){
246 if (e.keyCode == 27) // allow escape to hide and re-show picker
260 dir = e.keyCode == 37 ? -1 : 1;
262 this.vIndex = this.vIndex + dir;
268 if(this.vIndex > 11){
272 if(isNaN(this.vIndex)){
276 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
282 dir = e.keyCode == 38 ? -1 : 1;
284 this.vIndex = this.vIndex + dir * 4;
290 if(this.vIndex > 11){
294 if(isNaN(this.vIndex)){
298 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
303 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
304 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
311 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
312 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
328 this.picker().remove();
333 Roo.apply(Roo.bootstrap.MonthField, {
352 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
353 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
358 Roo.apply(Roo.bootstrap.MonthField, {
362 cls: 'datepicker dropdown-menu roo-dynamic',
366 cls: 'datepicker-months',
370 cls: 'table-condensed',
372 Roo.bootstrap.DateField.content