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.format = this.format || 'F';
63 this.isInline = false;
65 this.component = this.el.select('.add-on', true).first() || false;
66 this.component = (this.component && this.component.length === 0) ? false : this.component;
67 this.hasInput = this.component && this.inputEL().length;
72 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
74 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
76 this.picker().on('mousedown', this.onMousedown, this);
77 this.picker().on('click', this.onClick, this);
79 this.picker().addClass('datepicker-dropdown');
81 this.startViewMode = this.viewMode;
83 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
84 v.setStyle('width', '189px');
99 var d = new Date(this.parseDate(v) ).clearTime();
101 if(isNaN(d.getTime())){
102 this.date = this.viewDate = '';
103 Roo.bootstrap.MonthField.superclass.setValue.call(this, '');
107 v = this.formatDate(d);
109 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
111 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
115 this.fireEvent('select', this, this.date);
122 return this.formatDate(this.date);
130 var target = e.getTarget();
132 if(target.nodeName.toLowerCase() === 'i'){
133 target = Roo.get(target).dom.parentNode;
136 var nodeName = target.nodeName;
137 var className = target.className;
138 var html = target.innerHTML;
140 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
143 this.viewDate.setUTCDate(1);
144 this.viewDate.setUTCMonth(Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html));
146 this.setValue(this.formatDate(this.viewDate));
153 return this.pickerEl;
156 fillMonths: function()
159 var months = this.picker().select('>.datepicker-months td', true).first();
161 months.dom.innerHTML = '';
167 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
170 months.createChild(month);
177 this.date = (typeof(this.date) === 'undefined' || ((typeof(this.date) === 'string') && !this.date.length)) ? this.UTCToday() : (typeof(this.date) === 'string') ? this.parseDate(this.date) : this.date;
179 if (this.date < this.startDate) {
180 this.viewDate = new Date(this.startDate);
181 } else if (this.date > this.endDate) {
182 this.viewDate = new Date(this.endDate);
184 this.viewDate = new Date(this.date);
197 if(this.isInline) return;
199 this.picker().removeClass(['bottom', 'top']);
201 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
203 * place to the top of element!
207 this.picker().addClass('top');
208 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
213 this.picker().addClass('bottom');
215 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
220 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
226 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
228 var d = this.inputEl().getValue();
237 this.picker().show();
241 this.fireEvent('show', this, this.date);
246 if(this.isInline) return;
247 this.picker().hide();
248 this.fireEvent('hide', this, this.date);
252 onMousedown: function(e)
260 Roo.bootstrap.MonthField.superclass.keyup.call(this);
266 if (!this.picker().isVisible()){
267 if (e.keyCode == 27) // allow escape to hide and re-show picker
272 var dateChanged = false,
274 newDate, newViewDate;
276 // switch(e.keyCode){
277 // case 27: // escape
279 // e.preventDefault();
283 // if (!this.keyboardNavigation) break;
284 // dir = e.keyCode == 37 ? -1 : 1;
287 // newDate = this.moveYear(this.date, dir);
288 // newViewDate = this.moveYear(this.viewDate, dir);
289 // } else if (e.shiftKey){
290 // newDate = this.moveMonth(this.date, dir);
291 // newViewDate = this.moveMonth(this.viewDate, dir);
293 // newDate = new Date(this.date);
294 // newDate.setUTCDate(this.date.getUTCDate() + dir);
295 // newViewDate = new Date(this.viewDate);
296 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
298 // if (this.dateWithinRange(newDate)){
299 // this.date = newDate;
300 // this.viewDate = newViewDate;
301 // this.setValue(this.formatDate(this.date));
303 // e.preventDefault();
304 // dateChanged = true;
309 // if (!this.keyboardNavigation) break;
310 // dir = e.keyCode == 38 ? -1 : 1;
312 // newDate = this.moveYear(this.date, dir);
313 // newViewDate = this.moveYear(this.viewDate, dir);
314 // } else if (e.shiftKey){
315 // newDate = this.moveMonth(this.date, dir);
316 // newViewDate = this.moveMonth(this.viewDate, dir);
318 // newDate = new Date(this.date);
319 // newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
320 // newViewDate = new Date(this.viewDate);
321 // newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
323 // if (this.dateWithinRange(newDate)){
324 // this.date = newDate;
325 // this.viewDate = newViewDate;
326 // this.setValue(this.formatDate(this.date));
328 // e.preventDefault();
329 // dateChanged = true;
333 // this.setValue(this.formatDate(this.date));
335 // e.preventDefault();
338 // this.setValue(this.formatDate(this.date));
353 this.picker().remove();
358 Roo.apply(Roo.bootstrap.MonthField, {
377 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
378 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
383 Roo.apply(Roo.bootstrap.MonthField, {
387 cls: 'datepicker dropdown-menu roo-dynamic',
391 cls: 'datepicker-months',
395 cls: 'table-condensed',
397 Roo.bootstrap.DateField.content