From 43f99e11a5736c25fdc0f3aa89a4fc5169fe8dfa Mon Sep 17 00:00:00 2001 From: Alain-es Date: Mon, 18 May 2015 15:54:50 +0100 Subject: [PATCH] Datepicker custom format --- .../datepicker/datepicker.controller.js | 21 ++++++++++++++++--- .../datepicker/datepicker.html | 2 +- .../PropertyEditors/DatePropertyEditor.cs | 13 +++++++++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.controller.js index 9ad177285ccb..eb49bc3b39ef 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.controller.js @@ -18,9 +18,16 @@ function dateTimePickerController($scope, notificationsService, assetsService, a //map the user config $scope.model.config = angular.extend(config, $scope.model.config); + $scope.datetimePickerValue = $scope.model.value; + //hide picker if clicking on the document $scope.hidePicker = function () { - $element.find("div:first").datetimepicker("hide"); + //$element.find("div:first").datetimepicker("hide"); + // Sometimes the statement above fails and generates errors in the browser console. The following statements fix that. + var dtp = $element.find("div:first"); + if (dtp && dtp.datetimepicker) { + dtp.datetimepicker("hide"); + } }; $(document).bind("click", $scope.hidePicker); @@ -67,8 +74,16 @@ function dateTimePickerController($scope, notificationsService, assetsService, a .datetimepicker($scope.model.config) .on("dp.change", applyDate); - //manually assign the date to the plugin - $element.find("div:first").datetimepicker("setValue", $scope.model.value ? $scope.model.value : null); + //manually assign the date to the plugin + if (!$scope.model.config.format) { + $element.find("div:first").datetimepicker("setValue", $scope.model.value ? $scope.model.value : null); + } + else { + $element.find("div:first").datetimepicker("setValue", $scope.model.value ? new Date($scope.model.value) : null); + if ($scope.model.value && $scope.model.config.format) { + $scope.datetimePickerValue = moment($scope.model.value).format($scope.model.config.format); + } + } //Ensure to remove the event handler when this instance is destroyted $scope.$on('$destroy', function () { diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.html index 95452e0f190c..b3e503eb4ae0 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker/datepicker.html @@ -1,7 +1,7 @@
diff --git a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs index 04a5890c2c0c..d49458d98e6d 100644 --- a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs @@ -23,9 +23,6 @@ public DatePropertyEditor() private IDictionary _defaultPreVals; - /// - /// Overridden because we ONLY support Date (no time) format and we don't have pre-values in the db. - /// public override IDictionary DefaultPreValues { get { return _defaultPreVals; } @@ -60,5 +57,15 @@ public override object ConvertDbToEditor(Property property, PropertyType propert } } + + protected override PreValueEditor CreatePreValueEditor() + { + return new DatePreValueEditor(); + } + + internal class DatePreValueEditor : PreValueEditor + { + public string DefaultValue { get; set; } + } } } \ No newline at end of file