struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "mark xiao (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4076) struts2 core 2.1.8.1 framework defined tag:datepick issue
Date Wed, 22 May 2013 13:07:20 GMT

    [ https://issues.apache.org/jira/browse/WW-4076?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13664079#comment-13664079
] 

mark xiao commented on WW-4076:
-------------------------------

our team oever-wrote the struts2-jquery tag: datepicker
as following!

;(function($)
{

dpuuid = new Date().getTime();
$.extend($.datepicker._defaults,{formatSeparator:'/'});
$.extend($.datepicker, {
	_generateMonthYearHeader : function(inst, drawMonth, drawYear, minDate, maxDate,
			secondary, monthNames, monthNamesShort) {
		var changeMonth = this._get(inst, 'changeMonth');
		var changeYear = this._get(inst, 'changeYear');
		var showMonthAfterYear = this._get(inst, 'showMonthAfterYear');
		var html = '<div class="ui-datepicker-title">';
		var monthHtml = '';
		// month selection
		if (secondary || !changeMonth)
			monthHtml += '<span class="ui-datepicker-month">' + monthNames[drawMonth] + '</span>';
		else {
			var inMinYear = (minDate && minDate.getFullYear() == drawYear);
			var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
			monthHtml += '<select class="ui-datepicker-month" ' +
				'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\',
this, \'M\');" ' +
				'onclick="DP_jQuery_' + dpuuid + '.datepicker._clickMonthYear(\'#' + inst.id + '\');"'
+
				'>';
			for (var month = 0; month < 12; month++) {
				if ((!inMinYear || month >= minDate.getMonth()) &&
						(!inMaxYear || month <= maxDate.getMonth()))
					monthHtml += '<option value="' + month + '"' +
						(month == drawMonth ? ' selected="selected"' : '') +
						'>' + monthNamesShort[month] + '</option>';
			}
			monthHtml += '</select>';
		}
		if (!showMonthAfterYear)
			html += monthHtml + (secondary || !(changeMonth && changeYear) ? '&#xa0;' :
'');
		// year selection
		
		if (secondary || !changeYear)
			html += '<span class="ui-datepicker-year">' + '民國 ' + (drawYear-1911) + '</span>';
		else {
			// determine range of years to display
			var years = this._get(inst, 'yearRange').split(':');
			var thisYear = new Date().getFullYear();
			var determineYear = function(value) {
				var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :
					(value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :
					parseInt(value, 10)));
				return (isNaN(year) ? thisYear : year);
			};
			var year = determineYear(years[0]);
			var endYear = Math.max(year, determineYear(years[1] || ''));
			year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
			endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
			html += '<select class="ui-datepicker-year" ' +
				'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\',
this, \'Y\');" ' +
				'onclick="DP_jQuery_' + dpuuid + '.datepicker._clickMonthYear(\'#' + inst.id + '\');"'
+
				'>';
			for (; year <= endYear; year++) {
				html += '<option value="' + year + '"' +
					(year == drawYear ? ' selected="selected"' : '') +
					'>' + (year-1911) + '</option>';
			}
			html += '</select>';
		}
		html += this._get(inst, 'yearSuffix');
		if (showMonthAfterYear)
			html += (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '') + monthHtml;
		html += '</div>'; // Close datepicker_header
		return html;
	},
    _setDateFromField : function(inst)

    {
     
	   var dateFormat = this._get(inst, 'dateFormat');
       var separator = this._get(inst,'formatSeparator');
       var dates = inst.input ? inst.input.val() : null;
       inst.endDay = inst.endMonth = inst.endYear = null;

       var date = defaultDate = this._getDefaultDate(inst);
       
       var settings = this._getFormatConfig(inst);
       try

       {
		   if (!dates == '') {
			   var dateArr = dates.split(separator);
		   
               var year = parseInt(dateArr[0], 10) + 1911;

               var month = parseInt(dateArr[1], 10) - 1;

               var day = parseInt(dateArr[2], 10);
               date = new Date(year, month, day);
		   }
		   
		   //date = this.parseDate(dateFormat, dates, settings) || defaultDate;

       } catch (event)

       {
           this.log(event);

           date = defaultDate;

       }

       inst.selectedDay = date.getDate();

       inst.drawMonth = inst.selectedMonth = date.getMonth();

       inst.drawYear = inst.selectedYear = date.getFullYear();

       inst.currentDay = (dates ? date.getDate() : 0);

       inst.currentMonth = (dates ? date.getMonth() : 0);

       inst.currentYear = (dates ? date.getFullYear() : 0);
	   
       this._adjustInstDate(inst);

    },
	
    _formatDate : function(inst, day, month, year)

    {
    	var separator = this._get(inst,'formatSeparator');
       if (!day)

       {

           inst.currentDay = inst.selectedDay;

           inst.currentMonth = inst.selectedMonth;

           inst.currentYear = inst.selectedYear;

       }

       var date = (day ? (typeof day == 'object' ? day :

               this._daylightSavingAdjust(new Date(year, month, day))) :

              this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));

       return (date.getFullYear() - 1911) + separator +

              (date.getMonth() < 9 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1))
+ separator +

              (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());

    },
	/* Filter entered characters - based on date format. */
	_doKeyPress: function(event) {
		var inst = $.datepicker._getInst(event.target);
		if ($.datepicker._get(inst, 'constrainInput')) {
			//var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'formatSeperator'));
			var chars = '0123456789'+ $.datepicker._get(inst, 'formatSeparator');
			var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode);
			return event.ctrlKey || event.metaKey || (chr < ' ' || !chars || chars.indexOf(chr)
> -1);
		}
	}
});
	$.datepick.regional['zh-TW'] = {
		monthNames: ['一月','二月','三月','四月','五月','六月',
		'七月','八月','九月','十月','十一月','十二月'],
		monthNamesShort: ['一','二','三','四','五','六',
		'七','八','九','十','十一','十二'],
		dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
		dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'],
		dayNamesMin: ['日','一','二','三','四','五','六'],
		dateFormat: 'yyyy/mm/dd', firstDay: 1,
		renderer: $.extend({}, $.datepick.defaultRenderer,
			{month: $.datepick.defaultRenderer.month.
				replace(/monthHeader/, 'monthHeader:MM yyyy年')}),
		prevText: '&#x3c;上月', prevStatus: '顯示上月',
		prevJumpText: '&#x3c;&#x3c;', prevJumpStatus: '顯示上一年',
		nextText: '下月&#x3e;', nextStatus: '顯示下月',
		nextJumpText: '&#x3e;&#x3e;', nextJumpStatus: '顯示下一年',
		currentText: '今天', currentStatus: '顯示本月',
		todayText: '今天', todayStatus: '顯示本月',
		clearText: '清除', clearStatus: '清除已選日期',
		closeText: '關閉', closeStatus: '不改變目前的選擇',
		yearStatus: '選擇年份', monthStatus: '選擇月份',
		weekText: '周', weekStatus: '年內周次',
		dayStatus: '選擇 m月 d日, DD', defaultStatus: '請選擇日期',
		isRTL: false
	};
	$.datepick.setDefaults($.datepick.regional['zh-TW']);
window['DP_jQuery_' + dpuuid] = $;

})(jQuery);
                
> struts2 core 2.1.8.1 framework defined tag:datepick issue
> ---------------------------------------------------------
>
>                 Key: WW-4076
>                 URL: https://issues.apache.org/jira/browse/WW-4076
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - Tags
>    Affects Versions: 2.1.8.1
>         Environment: windows7
> SpringSource Tool Suite 2.6.1.RELEASE
> dynamic web module 2.4
> JRE 1.6.0_34
>            Reporter: mark xiao
>
> while using this modulized component to overwrite calendar 
> as our local/country calender year to add/minus 1911 between
> A.D. and ROC calendar year for browser interpreter(A.D.) 
> and browser user(ROC calendar).
> the following snippet would set back ROC year 99(A.D:2010)
> as ROC year 1999 (add extra 1900).
> even tried set dateFormat as yy/mm/dd or yyyy/mm/dd or yyy/mm/dd,
> they didn't work.
> try to set a judgement if (o.year.length == 2) skip the line below.
> ---snippet---
> jquery.struts2.js
> line1209
> $elem.val($.datepicker.formatDate(params.dateFormat, new Date(o.year, o.month, o.day)));
> ---
> could anyone tell me the formal solution?
> Thanks.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message