Repository: syncope Updated Branches: refs/heads/master ed3d3c572 -> 96d95d213
[SYNCOPE-1058] datetime picker shown only if format contains time Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/96d95d21 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/96d95d21 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/96d95d21 Branch: refs/heads/master Commit: 96d95d213a347631f10ac4e73bb2408a5741f240 Parents: ed3d3c5 Author: Andrea Patricelli <andreapatrice...@apache.org> Authored: Thu Apr 13 13:11:53 2017 +0200 Committer: Andrea Patricelli <andreapatrice...@apache.org> Committed: Thu Apr 13 14:16:47 2017 +0200 ---------------------------------------------------------------------- .../console/panels/ParametersDetailsPanel.java | 10 ++-- .../app/js/directives/dynamicPlainAttribute.js | 17 +++--- .../app/views/dynamicPlainAttribute.html | 58 ++++++++++++++------ 3 files changed, 55 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/96d95d21/client/console/src/main/java/org/apache/syncope/client/console/panels/ParametersDetailsPanel.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/ParametersDetailsPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/ParametersDetailsPanel.java index 0affc22..18e1be3 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/panels/ParametersDetailsPanel.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/ParametersDetailsPanel.java @@ -18,9 +18,11 @@ */ package org.apache.syncope.client.console.panels; +import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.apache.syncope.client.console.commons.SchemaUtils; import org.apache.syncope.client.console.rest.SchemaRestClient; import org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel; @@ -81,14 +83,14 @@ public class ParametersDetailsPanel extends Panel { final FieldPanel panel; switch (schemaTO.getType()) { case Date: - final String dataPattern = schemaTO.getConversionPattern() == null + final String datePattern = schemaTO.getConversionPattern() == null ? SyncopeConstants.DEFAULT_DATE_PATTERN : schemaTO.getConversionPattern(); - if (dataPattern.contains("H")) { - panel = new AjaxDateTimeFieldPanel("panel", schemaTO.getKey(), new Model<Date>(), dataPattern); + if (StringUtils.containsIgnoreCase(datePattern, "H")) { + panel = new AjaxDateTimeFieldPanel("panel", schemaTO.getKey(), new Model<Date>(), datePattern); } else { - panel = new AjaxDateFieldPanel("panel", schemaTO.getKey(), new Model<Date>(), dataPattern); + panel = new AjaxDateFieldPanel("panel", schemaTO.getKey(), new Model<Date>(), datePattern); } break; case Boolean: http://git-wip-us.apache.org/repos/asf/syncope/blob/96d95d21/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js b/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js index f67b926..8ccaa02 100644 --- a/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js +++ b/client/enduser/src/main/resources/META-INF/resources/app/js/directives/dynamicPlainAttribute.js @@ -100,19 +100,20 @@ angular.module('self') $scope.isDate = function (x) { return x instanceof Date; }; - - var dateInMs = $scope.user.plainAttrs[schema.key].values[index]; - var temporaryDate = new Date(dateInMs * 1); - $scope.selectedDate = temporaryDate; $scope.languageid = $rootScope.languages.selectedLanguage.id; - $scope.languageFormat = $rootScope.languages.selectedLanguage.format; + $scope.isDateOnly = schema.conversionPattern.indexOf("H") === -1 + && schema.conversionPattern.indexOf("h") === -1; + $scope.languageFormat = $scope.isDateOnly + ? $rootScope.languages.selectedLanguage.format.replace(" HH:mm", "") + : $rootScope.languages.selectedLanguage.format; $scope.languageCulture = $rootScope.languages.selectedLanguage.culture; + // read date in milliseconds + $scope.selectedDate = new Date($scope.user.plainAttrs[schema.key].values[index] * 1); $scope.bindDateToModel = function (selectedDate, extendedDate) { if (selectedDate) { - var tmpdate = new Date(extendedDate); - var milliseconds = tmpdate.getTime(); - $scope.user.plainAttrs[schema.key].values[index] = milliseconds; + // save date in milliseconds + $scope.user.plainAttrs[schema.key].values[index] = new Date(extendedDate).getTime(); } }; break; http://git-wip-us.apache.org/repos/asf/syncope/blob/96d95d21/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html b/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html index b3b5822..e7b5bcc 100644 --- a/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html +++ b/client/enduser/src/main/resources/META-INF/resources/app/views/dynamicPlainAttribute.html @@ -20,7 +20,9 @@ under the License. <input ng-switch-when="String" class="form-control" type="text" ng-model="user.plainAttrs[schema.key].values[index]" ng-required="{{schema.mandatoryCondition}}" validate="true" - ng-disabled="schema.readonly || customReadonly(schema.key)" ng-init="initAttribute(schema, index)" name="{{schema.key}}"/> + ng-disabled="schema.readonly || customReadonly(schema.key)" + ng-init="initAttribute(schema, index)" + name="{{schema.key}}"/> <div ng-switch-when="Encrypted" class="input-group input-group-sm"> <span class="input-group-btn" ng-disabled="schema.readonly || customReadonly(schema.key)"> @@ -73,27 +75,46 @@ under the License. ng-required="{{schema.mandatoryCondition}}" ng-disabled="schema.readonly || customReadonly(schema.key)" ng-init="initAttribute(schema, index)" /> - </div> +</div> - <input ng-switch-when="Long" class="form-control" type="number" ng-model="user.plainAttrs[schema.key].values[index]" - ng-required="{{schema.mandatoryCondition}}" validate="true" - ng-init="initAttribute(schema, index)" name="{{schema.key}}"/> +<input ng-switch-when="Long" class="form-control" + type="number" + ng-model="user.plainAttrs[schema.key].values[index]" + ng-required="{{schema.mandatoryCondition}}" + ng-disabled="schema.readonly || customReadonly(schema.key)" + validate="true" + ng-init="initAttribute(schema, index)" + name="{{schema.key}}"/> - <input ng-switch-when="Double" class="form-control" type="number" ng-model="user.plainAttrs[schema.key].values[index]" +<input ng-switch-when="Double" class="form-control" type="number" ng-model="user.plainAttrs[schema.key].values[index]" ng-required="{{schema.mandatoryCondition}}" validate="true" + ng-disabled="schema.readonly || customReadonly(schema.key)" ng-init="initAttribute(schema, index)" name="{{schema.key}}"/> - <div ng-switch-when="Date" id="date"> - <input type="text" class="dateTimePicker" - id="dateTimePicker" - kendo-date-time-picker - ng-model="extendedDate" - ng-required="{{schema.mandatoryCondition}}" close-text="Close" - ng-init="initAttribute(schema, index)" - ng-change="bindDateToModel(selectedDate, extendedDate)" - ng-disabled="schema.readonly || customReadonly(schema.key)" - k-ng-model="selectedDate" - data-k-format=languageFormat +<div ng-switch-when="Date" id="date"> +<input type="text" class="dateTimePicker" + id="dateTimePicker" + kendo-date-time-picker + ng-show="!isDateOnly" + ng-model="extendedDate" + ng-required="{{schema.mandatoryCondition}}" close-text="Close" + ng-init="initAttribute(schema, index)" + ng-change="bindDateToModel(selectedDate, extendedDate)" +ng-disabled="schema.readonly || customReadonly(schema.key)" +k-ng-model="selectedDate" +data-k-format="languageFormat" +/> +<input type="text" class="datePicker" + id="datePicker" + kendo-date-picker + ng-show="isDateOnly" + ng-model="extendedDate" + ng-required="{{schema.mandatoryCondition}}" close-text="Close" + ng-init="initAttribute(schema, index)" + ng-change="bindDateToModel(selectedDate, extendedDate)" + ng-disabled="schema.readonly || customReadonly(schema.key)" + k-ng-model="selectedDate" + data-k-format="languageFormat" /> </div> @@ -120,7 +141,8 @@ under the License. <input ng-switch-default class="form-control" type="text" ng-model="user.plainAttrs[schema.key].values[index]" ng-required="{{schema.mandatoryCondition}}" - ng-disabled="schema.readonly || customReadonly(schema.key)" ng-init="initAttribute(schema, index)"/> + ng-disabled="schema.readonly || customReadonly(schema.key)" + ng-init="initAttribute(schema, index)"/> </div>