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]);
137 return this.pickerEl;
140 fillMonths: function()
143 var months = this.picker().select('>.datepicker-months td', true).first();
145 months.dom.innerHTML = '';
151 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
154 months.createChild(month);
163 if(typeof(this.vIndex) != 'undefined' && this.value.length){
167 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
168 e.removeClass('active');
170 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
171 e.addClass('active');
178 if(this.isInline) return;
180 this.picker().removeClass(['bottom', 'top']);
182 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
184 * place to the top of element!
188 this.picker().addClass('top');
189 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
194 this.picker().addClass('bottom');
196 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
201 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
207 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
209 var d = this.inputEl().getValue();
218 this.picker().show();
219 this.picker().select('>.datepicker-months', true).first().show();
223 this.fireEvent('show', this, this.date);
228 if(this.isInline) return;
229 this.picker().hide();
230 this.fireEvent('hide', this, this.date);
234 onMousedown: function(e)
242 Roo.bootstrap.MonthField.superclass.keyup.call(this);
248 if (!this.picker().isVisible()){
249 if (e.keyCode == 27) // allow escape to hide and re-show picker
254 var dateChanged = false,
256 newDate, newViewDate;
258 // switch(e.keyCode){
259 // case 27: // escape
261 // e.preventDefault();
265 // if (!this.keyboardNavigation) break;
266 // dir = e.keyCode == 37 ? -1 : 1;
269 // newDate = this.moveYear(this.date, dir);
270 // newViewDate = this.moveYear(this.viewDate, dir);
271 // } else if (e.shiftKey){
272 // newDate = this.moveMonth(this.date, dir);
273 // newViewDate = this.moveMonth(this.viewDate, dir);
275 // newDate = new Date(this.date);
276 // newDate.setUTCDate(this.date.getUTCDate() + dir);
277 // newViewDate = new Date(this.viewDate);
278 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
280 // if (this.dateWithinRange(newDate)){
281 // this.date = newDate;
282 // this.viewDate = newViewDate;
283 // this.setValue(this.formatDate(this.date));
285 // e.preventDefault();
286 // dateChanged = true;
291 // if (!this.keyboardNavigation) break;
292 // dir = e.keyCode == 38 ? -1 : 1;
294 // newDate = this.moveYear(this.date, dir);
295 // newViewDate = this.moveYear(this.viewDate, dir);
296 // } else if (e.shiftKey){
297 // newDate = this.moveMonth(this.date, dir);
298 // newViewDate = this.moveMonth(this.viewDate, dir);
300 // newDate = new Date(this.date);
301 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
302 // newViewDate = new Date(this.viewDate);
303 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
305 // if (this.dateWithinRange(newDate)){
306 // this.date = newDate;
307 // this.viewDate = newViewDate;
308 // this.setValue(this.formatDate(this.date));
310 // e.preventDefault();
311 // dateChanged = true;
315 // this.setValue(this.formatDate(this.date));
317 // e.preventDefault();
320 // this.setValue(this.formatDate(this.date));
335 this.picker().remove();
340 Roo.apply(Roo.bootstrap.MonthField, {
359 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
360 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
365 Roo.apply(Roo.bootstrap.MonthField, {
369 cls: 'datepicker dropdown-menu roo-dynamic',
373 cls: 'datepicker-months',
377 cls: 'table-condensed',
379 Roo.bootstrap.DateField.content