Fixed date and time picker.

This commit is contained in:
Sipke Schoorstra 2015-12-02 23:27:46 +01:00
parent c4f961105d
commit 33484ae31a
44 changed files with 3452 additions and 40 deletions

View File

@ -189,6 +189,12 @@
],
"output": "Scripts/jquery.fileupload-full.js"
},
{
"inputs": [
"Assets/Js/Calendars/jquery.calendars.all.js"
],
"output": "Scripts/jquery.calendars.all.js"
},
{
"inputs": [
"Assets/Js/Calendars/jquery.calendars.picker.js",

View File

@ -496,6 +496,8 @@
<Content Include="Scripts\jquery-ui.min.js" />
<Content Include="Scripts\jquery.blockui.js" />
<Content Include="Scripts\jquery.blockui.min.js" />
<Content Include="Scripts\jquery.calendars.all.js" />
<Content Include="Scripts\jquery.calendars.all.min.js" />
<Content Include="Scripts\jquery.calendars.picker.full.js" />
<Content Include="Scripts\jquery.calendars.picker.full.min.js" />
<Content Include="Scripts\jquery.colorbox.js" />
@ -812,6 +814,15 @@
<Content Include="Assets\Less\Bootstrap\type.less" />
<Content Include="Assets\Less\Bootstrap\wells.less" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\CalendarsPickerLocalization.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\EditorTemplates\DateTimeEditor.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\TimeEntryLocalization.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,4 @@
margin-left: 2px;
}
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImpxdWVyeS50aW1lZW50cnkuY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSxBQUxBLDZCQUFBO0FBQ0E7Q0FDQSx1QkFBQTtDQUNBLGlCQUFBO0NBQ0EiLCJmaWxlIjoianF1ZXJ5LnRpbWVlbnRyeS5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyIvKiBUaW1lRW50cnkgc3R5bGVzIHYyLjAuMCAqL1xuLnRpbWVFbnRyeS1jb250cm9sIHtcblx0dmVydGljYWwtYWxpZ246IG1pZGRsZTtcblx0bWFyZ2luLWxlZnQ6IDJweDtcbn1cbiJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ== */
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImpxdWVyeS50aW1lZW50cnkuY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSxBQUxBLDZCQUFBO0FBQ0E7Q0FDQSx1QkFBQTtDQUNBLGlCQUFBO0NBQ0EiLCJmaWxlIjoianF1ZXJ5LnRpbWVlbnRyeS5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyIvKiBUaW1lRW50cnkgc3R5bGVzIHYyLjAuMCAqL1xyXG4udGltZUVudHJ5LWNvbnRyb2wge1xyXG5cdHZlcnRpY2FsLWFsaWduOiBtaWRkbGU7XHJcblx0bWFyZ2luLWxlZnQ6IDJweDtcclxufVxyXG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= */

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,178 @@
@using Orchard.Localization.Services
@using Orchard.Utility.Extensions;
@using System.Globalization
@using System.Web.Hosting;
@{
// Prevent the shape from being rendered twice in the same request.
if (WorkContext.GetState<object>("CalendarsPickerLocalization") != null) {
return;
}
WorkContext.SetState("CalendarsPickerLocalization", new object());
Script.Require("jQueryCalendars_Picker");
var dateTimeFormatProvider = WorkContext.Resolve<IDateTimeFormatProvider>();
var calendarManager = WorkContext.Resolve<ICalendarManager>();
var currentCulture = CultureInfo.GetCultureInfo(WorkContext.CurrentCulture);
var currentCalendar = currentCulture.Calendar;
if (!String.IsNullOrEmpty(WorkContext.CurrentCalendar)) {
currentCalendar = calendarManager.GetCalendarByName(WorkContext.CurrentCalendar);
}
// Map the .NET calendar implementation in use to one of the jQuery Calendars implementations, using Gregorian as the default fallback.
// NOTE: The following .NET calendars are lack corresponding implementations in jQuery Calendars at this time:
// * ChineseLunisolarCalendar
// * JapaneseCalendar
// * JapaneseLunisolarCalendar
// * KoreanCalendar
// * KoreanLunisolarCalendar
// * TaiwanLunisolarCalendar
string calendarName = "gregorian";
switch (WorkContext.CurrentCalendar) {
case "HebrewCalendar":
calendarName = "hebrew";
break;
case "HijriCalendar":
calendarName = "islamic";
break;
case "JulianCalendar":
calendarName = "julian";
break;
case "PersianCalendar":
calendarName = "persian";
break;
case "TaiwanCalendar":
calendarName = "taiwan";
break;
case "ThaiBuddhistCalendar":
calendarName = "thai";
break;
case "UmAlQuraCalendar":
calendarName = "ummalqura";
break;
}
string includedLocalization = null;
// If we're using the Gregorian calendar we can reliably localize it using with
// values obtained from IDateTimeFormatProvider (which by default uses the CultureDateTimeFormatProvider
// implementation which uses the localizations built into the .NET Framework). If
// using a different calendar, it's more reliable to use the appropriate localization
// shipped with jQuery Calendars if there is one, and only fall back on IDateTimeFormatProvider
// if necessary.
if (calendarName != "gregorian") {
// Include the appropriate calendar module.
Script.Include(String.Format("calendars/jquery.calendars.{0}.min.js", calendarName), String.Format("calendars/jquery.calendars.{0}.js", calendarName)).AtFoot();
// Look for a matching localization module and include it if found.
var c = currentCulture;
do {
var localizationFileName = String.Format("calendars/jquery.calendars.{0}-{1}.js", calendarName, c.Name);
if (File.Exists(HostingEnvironment.MapPath(String.Format("~/Modules/Orchard.jQuery/Scripts/{0}", localizationFileName)))) {
Script.Include(localizationFileName).AtFoot();
includedLocalization = c.Name;
break;
}
c = c.Parent;
} while (c != c.Parent);
}
// Determine the date format to use (convert from short date format string of current culture into jQuery Calendars format string).
// http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
// http://keith-wood.name/calendarsPicker.html#format
var dateFormat = dateTimeFormatProvider.ShortDateFormat.ReplaceAll(new Dictionary<string, string>() {
{"dddd", "DD" },
{"ddd", "D" },
{"MMMM", "MM" },
{"MMM", "M" },
{"MM", "mm" },
{"M", "m" },
{"yyyyy", "yyyy" }, // Five-digit year is not supported by jQuery Calendars; convert to four-digit.
{"yyyy", "yyyy" }, // Four-digit year included to not be touched by three-digit year replacement below.
{"yyy", "yyyy" }, // Three-digit year is not supported by jQuery Calendars; convert to four-digit.
{"yy", "yy" }, // Two-digit year included to not be touched by one-digit year replacement below.
{"y", "yy" }, // Year without leading zero is not supported by jQuery Calendars; convert to two-digit.
{"gg", "" }, // Period and era are not supported by jQuery Calendars.
{"g", "" },// Period and era are not supported by jQuery Calendars.
{"K", "" }, // Time zone is not supported by jQuery Calendars.
});
}
@functions {
private string FormatJsList(string[] strings) {
return String.Join(", ", strings.Select(s => String.Format("'{0}'", HttpUtility.JavaScriptStringEncode(s.Trim()))));
}
}
<script type="text/javascript">
//<![CDATA[
$(function() {
var dateFormat = '@HttpUtility.JavaScriptStringEncode(dateFormat)';
var calendarName = '@HttpUtility.JavaScriptStringEncode(calendarName)';
var localizationName = '';
@if (includedLocalization != null) {
<text>localizationName = '@HttpUtility.JavaScriptStringEncode(includedLocalization)';</text>
}
else {
// No localization module was loaded. Instead we initialize the default calendar
// localization with values obtained from IDateTimeFormatProvider.
var monthNames = FormatJsList(dateTimeFormatProvider.MonthNames.ToArray());
var monthNamesShort = FormatJsList(dateTimeFormatProvider.MonthNamesShort.ToArray());
var dayNames = FormatJsList(dateTimeFormatProvider.DayNames.ToArray());
var dayNamesShort = FormatJsList(dateTimeFormatProvider.DayNamesShort.ToArray());
var dayNamesMin = FormatJsList(dateTimeFormatProvider.DayNamesMin.ToArray());
var firstDay = Convert.ToInt32(dateTimeFormatProvider.FirstDay);
<text>
localizationName = '@HttpUtility.JavaScriptStringEncode(currentCulture.Name)';
$.calendars.calendars.@(calendarName).prototype.regionalOptions[localizationName] = {
monthNames: [@Html.Raw(monthNames)], // Names of months for drop-down and formatting
monthNamesShort: [@Html.Raw(monthNamesShort)], // Short namese of months
dayNames: [@Html.Raw(dayNames)], // Names of days
dayNamesShort: [@Html.Raw(dayNamesShort)], // Short names of days
dayNamesMin: [@Html.Raw(dayNamesMin)], // Column headings for days starting at Sunday
dateFormat: '@HttpUtility.JavaScriptStringEncode(dateFormat)', // See format options on parseDate
firstDay: @firstDay, // First day of the week
isRTL: @(currentCulture.TextInfo.IsRightToLeft ? "true" : "false") // True if right-to-left language, false if left-to-right
};
</text>
}
$.calendarsPicker.regionalOptions[localizationName] = {
prevText: '@HttpUtility.JavaScriptStringEncode(T("Prev").Text)', // Display text for previous month link
prevStatus: '@HttpUtility.JavaScriptStringEncode(T("Show the previous month").Text)', // Tooltip text for previous month link
prevJumpText: '@HttpUtility.JavaScriptStringEncode(T("<<").Text)', // Display text for previous year link
prevJumpStatus: '@HttpUtility.JavaScriptStringEncode(T("Show the previous year").Text)', // Tooltip text for previous year link
nextText: '@HttpUtility.JavaScriptStringEncode(T("Next").Text)', // Display text for next month link
nextStatus: '@HttpUtility.JavaScriptStringEncode(T("Show the next month").Text)', // Tooltip text for next month link
nextJumpText: '@HttpUtility.JavaScriptStringEncode(T(">>").Text)', // Display text for next year link
nextJumpStatus: '@HttpUtility.JavaScriptStringEncode(T("Show the next year").Text)', // Tooltip text for next year link
currentText: '@HttpUtility.JavaScriptStringEncode(T("Current").Text)', // Display text for current month link
currentStatus: '@HttpUtility.JavaScriptStringEncode(T("Show the current month").Text)', // Tooltip text for current month link
todayText: '@HttpUtility.JavaScriptStringEncode(T("Today").Text)', // Display text for today link
todayStatus: '@HttpUtility.JavaScriptStringEncode(T("Show today's month").Text)', // Tooltip text for today link
clearText: '@HttpUtility.JavaScriptStringEncode(T("Clear").Text)', // Display text for clear link
clearStatus: '@HttpUtility.JavaScriptStringEncode(T("Clear the date field").Text)', // Tooltip text for clear link
closeText: '@HttpUtility.JavaScriptStringEncode(T("Done").Text)', // Display text for close link
closeStatus: '@HttpUtility.JavaScriptStringEncode(T("Close the datepicker").Text)', // Tooltip text for close link
yearStatus: '@HttpUtility.JavaScriptStringEncode(T("Change the year").Text)', // Tooltip text for year drop-down
monthStatus: '@HttpUtility.JavaScriptStringEncode(T("Change the month").Text)', // Tooltip text for month drop-down
weekText: '@HttpUtility.JavaScriptStringEncode(T("Wk").Text)', // Display text for week of the year column header
weekStatus: '@HttpUtility.JavaScriptStringEncode(T("Week of the year").Text)', // Tooltip text for week of the year column header
dayStatus: '@HttpUtility.JavaScriptStringEncode(T(String.Format("Select {0}", dateFormat)).Text)', // Tooltip text for selectable days
defaultStatus: '@HttpUtility.JavaScriptStringEncode(T("Select a date").Text)', // Tooltip text for areas of the datepicker not covered by one of the other statuses above
isRTL: @(currentCulture.TextInfo.IsRightToLeft ? "true" : "false") // True if right-to-left language, false if left-to-right
};
$.calendarsPicker.setDefaults($.calendarsPicker.regionalOptions[localizationName]);
$.calendarsPicker.setDefaults({
calendar: $.calendars.instance(calendarName, localizationName),
dateFormat: dateFormat
});
})
//]]>
</script>

View File

@ -0,0 +1,55 @@
@model Orchard.Core.Common.ViewModels.DateTimeEditor
@{
Style.Require("jQueryCalendars_Picker");
Style.Require("jQueryTimeEntry");
Style.Require("jQueryDateTimeEditor");
Script.Require("jQueryCalendars_Picker").AtFoot();
Script.Require("jQueryTimeEntry").AtFoot();
}
@if (Model.ShowDate) {
<label class="forpicker" for="@Html.FieldIdFor(m => Model.Date)">@T("Date")</label>
<span class="date">@Html.TextBoxFor(m => m.Date, new { placeholder = T("Date").Text, @class = "text" })</span>
}
@if (Model.ShowTime) {
<label class="forpicker" for="@Html.FieldIdFor(m => Model.Time)">@T("Time")</label>
<span class="time">@Html.TextBoxFor(m => m.Time, new { placeholder = T("Time").Text, @class = "text" })</span>
}
@if (Model.ShowDate) { <text>@Html.ValidationMessageFor(m => m.Date)</text> }
@if (Model.ShowTime) { <text>@Html.ValidationMessageFor(m => m.Time)</text> }
@using (Script.Foot()) {
@* Generate the localization scripts. *@
if (Model.ShowDate) { @Display.CalendarsPickerLocalization() }
if (Model.ShowTime) { @Display.TimeEntryLocalization() }
<script type="text/javascript">
//<![CDATA[
$(function () {
@if (Model.ShowDate) {
<text>
$("#@Html.FieldIdFor(m => Model.Date)").calendarsPicker({
showAnim: "",
renderer: $.extend({}, $.calendarsPicker.themeRollerRenderer, {
picker: "<div {popup:start} id='ui-datepicker-div'{popup:end} class='ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all{inline:start} ui-datepicker-inline{inline:end}'><div class='ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all'>{link:prev}{link:today}{link:next}</div>{months}{popup:start}{popup:end}<div class='ui-helper-clearfix'></div></div>",
month: "<div class='ui-datepicker-group'><div class='ui-datepicker-month ui-helper-clearfix'>{monthHeader:MM yyyy}</div><table class='ui-datepicker-calendar'><thead>{weekHeader}</thead><tbody>{weeks}</tbody></table></div>"
})
});
</text>
}
@if (Model.ShowTime) {
<text>
$("#@Html.FieldIdFor(m => Model.Time)").timeEntry();
</text>
}
});
//]]>
</script>
}

View File

@ -0,0 +1,49 @@
@using Orchard.Localization.Services
@using Orchard.Utility.Extensions;
@using System.Globalization
@using System.Web.Hosting;
@{
// Prevent the shape from being rendered twice in the same request.
if (WorkContext.GetState<object>("TimeEntryLocalization") != null) {
return;
}
WorkContext.SetState("TimeEntryLocalization", new object());
Script.Require("jQueryTimeEntry");
var currentCulture = CultureInfo.GetCultureInfo(WorkContext.CurrentCulture);
var dateTimeFormatProvider = WorkContext.Resolve<IDateTimeFormatProvider>();
var amPmNames = FormatJsList(dateTimeFormatProvider.AmPmDesignators.ToArray());
}
@functions {
private string FormatJsList(string[] strings) {
return String.Join(", ", strings.Select(s => String.Format("'{0}'", HttpUtility.JavaScriptStringEncode(s.Trim()))));
}
}
<script type="text/javascript">
//<![CDATA[
$(function() {
$.timeEntry.regionalOptions['@HttpUtility.JavaScriptStringEncode(currentCulture.Name)'] = {
show24Hours: @(dateTimeFormatProvider.Use24HourTime ? "true" : "false"),
separator: '@HttpUtility.JavaScriptStringEncode(dateTimeFormatProvider.TimeSeparator)',
ampmPrefix: '@HttpUtility.JavaScriptStringEncode(dateTimeFormatProvider.AmPmPrefix)',
ampmNames: [@Html.Raw(amPmNames)],
spinnerTexts: [
'@HttpUtility.JavaScriptStringEncode(T("Now").Text)',
'@HttpUtility.JavaScriptStringEncode(T("Previous field").Text)',
'@HttpUtility.JavaScriptStringEncode(T("Next field").Text)',
'@HttpUtility.JavaScriptStringEncode(T("Increment").Text)',
'@HttpUtility.JavaScriptStringEncode(T("Decrement").Text)'
]
};
$.timeEntry.setDefaults($.timeEntry.regionalOptions['@HttpUtility.JavaScriptStringEncode(currentCulture.Name)']);
$.timeEntry.setDefaults({
spinnerImage: '@HttpUtility.JavaScriptStringEncode(Url.Content("~/Modules/Orchard.jQuery/Styles/images/spinnerDefault.png"))'
});
})
//]]>
</script>

View File

@ -5,9 +5,7 @@
Style.Require("jQueryUI_Calendars_Picker");
Style.Require("jQueryTimeEntry");
Style.Require("jQueryDateTimeEditor");
Script.Require("jQueryCalendars_All").AtFoot();
Script.Require("jQueryCalendars_Picker_Ext").AtFoot();
Script.Require("jQueryCalendars_Picker").AtFoot();
Script.Require("jQueryTimeEntry").AtFoot();
}