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 {String} oldvalue The old value
43 * @param {String} newvalue The new value
49 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
51 onRender: function(ct, position)
54 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
56 this.language = this.language || 'en';
57 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
58 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
60 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
61 this.isInline = false;
63 this.component = this.el.select('.add-on', true).first() || false;
64 this.component = (this.component && this.component.length === 0) ? false : this.component;
65 this.hasInput = this.component && this.inputEL().length;
67 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
69 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
71 this.picker().on('mousedown', this.onMousedown, this);
72 this.picker().on('click', this.onClick, this);
74 this.picker().addClass('datepicker-dropdown');
76 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
77 v.setStyle('width', '189px');
90 setValue: function(v, suppressEvent)
92 var o = this.getValue();
94 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
98 if(suppressEvent !== true){
99 this.fireEvent('select', this, o, v);
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');
183 this.picker().removeClass(['bottom', 'top']);
185 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
187 * place to the top of element!
191 this.picker().addClass('top');
192 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
197 this.picker().addClass('bottom');
199 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
204 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
210 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
212 var d = this.inputEl().getValue();
221 this.picker().show();
222 this.picker().select('>.datepicker-months', true).first().show();
226 this.fireEvent('show', this, this.date);
234 this.picker().hide();
235 this.fireEvent('hide', this, this.date);
239 onMousedown: function(e)
247 Roo.bootstrap.MonthField.superclass.keyup.call(this);
253 if (!this.picker().isVisible()){
254 if (e.keyCode == 27) {// allow escape to hide and re-show picker
269 dir = e.keyCode == 37 ? -1 : 1;
271 this.vIndex = this.vIndex + dir;
277 if(this.vIndex > 11){
281 if(isNaN(this.vIndex)){
285 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
291 dir = e.keyCode == 38 ? -1 : 1;
293 this.vIndex = this.vIndex + dir * 4;
299 if(this.vIndex > 11){
303 if(isNaN(this.vIndex)){
307 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]);
320 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
321 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
337 this.picker().remove();
342 Roo.apply(Roo.bootstrap.MonthField, {
361 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
362 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
367 Roo.apply(Roo.bootstrap.MonthField, {
371 cls: 'datepicker dropdown-menu roo-dynamic',
375 cls: 'datepicker-months',
379 cls: 'table-condensed',
381 Roo.bootstrap.DateField.content