From 9abd94ca1b99c08bc86fc9c051f303e1703f8466 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 1 Sep 2015 12:33:59 +0100 Subject: [PATCH 1/2] Adding Date field type to custom fields --- .../modules/common/custom-field-values.coffee | 21 ++++++++++++++++++- app/locales/locale-en.json | 3 ++- .../custom-attribute-value-edit.jade | 10 ++++++++- .../admin/admin-custom-attributes.jade | 4 ++-- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/coffee/modules/common/custom-field-values.coffee b/app/coffee/modules/common/custom-field-values.coffee index 7e031615..1dad3100 100644 --- a/app/coffee/modules/common/custom-field-values.coffee +++ b/app/coffee/modules/common/custom-field-values.coffee @@ -148,6 +148,20 @@ CustomAttributeValueDirective = ($template, $selectedText, $compile) -> $el.html(html) + if attributeValue.field_type == "DATE" + + selectedDate = null + + $el.picker = new Pikaday( + field: $el.find('input')[0] + onSelect: (date) => + selectedDate = date + onOpen: => + $el.picker.setDate(selectedDate) if selectedDate? + firstDay: 1 + format: 'DD MMM YYYY' + ) + isEditable = -> permissions = $scope.project.my_permissions requiredEditionPerm = $attrs.requiredEditionPerm @@ -156,6 +170,9 @@ CustomAttributeValueDirective = ($template, $selectedText, $compile) -> saveAttributeValue = -> attributeValue.value = $el.find("input, textarea").val() + if attributeValue.field_type == "DATE" and attributeValue.value != '' + return if moment(attributeValue.value).isValid() != true + $scope.$apply -> $ctrl.updateAttributeValue(attributeValue).then -> render(attributeValue, false) @@ -164,7 +181,9 @@ CustomAttributeValueDirective = ($template, $selectedText, $compile) -> if event.keyCode == 13 and event.currentTarget.type != "textarea" submit(event) else if event.keyCode == 27 - render(attributeValue, false) + return if attributeValue.field_type == "DATE" and moment(attributeValue.value).isValid() != true + + render(attributeValue, false) ## Actions (on view mode) $el.on "click", ".custom-field-value.read-mode", -> diff --git a/app/locales/locale-en.json b/app/locales/locale-en.json index f9f7d90d..6014c43e 100644 --- a/app/locales/locale-en.json +++ b/app/locales/locale-en.json @@ -456,7 +456,8 @@ "ISSUE_DESCRIPTION": "Issues custom fields", "ISSUE_ADD": "Add a custom field in issues", "FIELD_TYPE_TEXT": "Text", - "FIELD_TYPE_MULTI": "Multi-line" + "FIELD_TYPE_MULTI": "Multi-line", + "FIELD_TYPE_DATE": "Date" }, "PROJECT_VALUES": { "PAGE_TITLE": "{{sectionName}} - Project values - {{projectName}}", diff --git a/app/partials/custom-attributes/custom-attribute-value-edit.jade b/app/partials/custom-attributes/custom-attribute-value-edit.jade index a03bebd6..5ac1edbd 100644 --- a/app/partials/custom-attributes/custom-attribute-value-edit.jade +++ b/app/partials/custom-attributes/custom-attribute-value-edit.jade @@ -8,7 +8,7 @@ form.custom-field-single.editable <% } %> div.custom-field-value - + <% if (field_type=="MULTI") { %> textarea#custom-field-description(name="description") <%- value %> @@ -18,5 +18,13 @@ form.custom-field-single.editable input#custom-field-description(name="description", type="text", value!="<%- value %>") <% } %> + <% if (field_type=="DATE" && value!="") { %> + input#custom-field-description(name="description", type="text", value!="<%- moment(value).format('DD MMM YYYY') %>") + <% } %> + + <% if (field_type=="DATE" && value=="") { %> + input#custom-field-description(name="description", type="text", value!="") + <% } %> + div.custom-field-options a.icon.icon-floppy(href="", title="{{'COMMON.CUSTOM_ATTRIBUTES.SAVE' | translate}}") diff --git a/app/partials/includes/modules/admin/admin-custom-attributes.jade b/app/partials/includes/modules/admin/admin-custom-attributes.jade index 9d4130b7..b26cf9f8 100644 --- a/app/partials/includes/modules/admin/admin-custom-attributes.jade +++ b/app/partials/includes/modules/admin/admin-custom-attributes.jade @@ -40,7 +40,7 @@ section.custom-fields-table.basic-table ng-model="attr.description") fieldset.custom-field-type select(ng-model="attr.field_type", - ng-options="e.id as e.name | translate for e in [{'id':'TEXT', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_TEXT'},{'id':'MULTI', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_MULTI'}]") + ng-options="e.id as e.name | translate for e in [{'id':'TEXT', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_TEXT'},{'id':'MULTI', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_MULTI'},{'id':'DATE', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_DATE'}]") fieldset.custom-options div.custom-options-wrapper a.js-update-custom-field-button.icon.icon-floppy(href="", title="{{'ADMIN.CUSTOM_ATTRIBUTES.ACTION_UPDATE' | translate}}") @@ -55,7 +55,7 @@ section.custom-fields-table.basic-table ng-model="newAttr.description") fieldset.custom-field-type select(ng-model="newAttr.field_type", - ng-options="e.id as e.name | translate for e in [{'id':'TEXT', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_TEXT'},{'id':'MULTI', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_MULTI'}]") + ng-options="e.id as e.name | translate for e in [{'id':'TEXT', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_TEXT'},{'id':'MULTI', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_MULTI'},{'id':'DATE', 'name': 'ADMIN.CUSTOM_FIELDS.FIELD_TYPE_DATE'}]") fieldset.custom-options div.custom-options-wrapper From 7c39dfbb8413634f9f71f6b31c10333bf422d9b2 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 7 Sep 2015 12:19:10 +0100 Subject: [PATCH 2/2] Adding internationalization to date selector --- .../modules/common/custom-field-values.coffee | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/app/coffee/modules/common/custom-field-values.coffee b/app/coffee/modules/common/custom-field-values.coffee index 1dad3100..4c8dd6be 100644 --- a/app/coffee/modules/common/custom-field-values.coffee +++ b/app/coffee/modules/common/custom-field-values.coffee @@ -118,10 +118,10 @@ CustomAttributesValuesDirective = ($templates, $storage) -> template: templateFn } -module.directive("tgCustomAttributesValues", ["$tgTemplate", "$tgStorage", CustomAttributesValuesDirective]) +module.directive("tgCustomAttributesValues", ["$tgTemplate", "$tgStorage", "$translate", CustomAttributesValuesDirective]) -CustomAttributeValueDirective = ($template, $selectedText, $compile) -> +CustomAttributeValueDirective = ($template, $selectedText, $compile, $translate) -> template = $template.get("custom-attributes/custom-attribute-value.html", true) templateEdit = $template.get("custom-attributes/custom-attribute-value-edit.html", true) @@ -158,9 +158,40 @@ CustomAttributeValueDirective = ($template, $selectedText, $compile) -> selectedDate = date onOpen: => $el.picker.setDate(selectedDate) if selectedDate? - firstDay: 1 - format: 'DD MMM YYYY' - ) + i18n: { + previousMonth: $translate.instant("COMMON.PICKERDATE.PREV_MONTH"), + nextMonth: $translate.instant("COMMON.PICKERDATE.NEXT_MONTH"), + months: [$translate.instant("COMMON.PICKERDATE.MONTHS.JAN"), + $translate.instant("COMMON.PICKERDATE.MONTHS.FEB"), + $translate.instant("COMMON.PICKERDATE.MONTHS.MAR"), + $translate.instant("COMMON.PICKERDATE.MONTHS.APR"), + $translate.instant("COMMON.PICKERDATE.MONTHS.MAY"), + $translate.instant("COMMON.PICKERDATE.MONTHS.JUN"), + $translate.instant("COMMON.PICKERDATE.MONTHS.JUL"), + $translate.instant("COMMON.PICKERDATE.MONTHS.AUG"), + $translate.instant("COMMON.PICKERDATE.MONTHS.SEP"), + $translate.instant("COMMON.PICKERDATE.MONTHS.OCT"), + $translate.instant("COMMON.PICKERDATE.MONTHS.NOV"), + $translate.instant("COMMON.PICKERDATE.MONTHS.DEC")], + weekdays: [$translate.instant("COMMON.PICKERDATE.WEEK_DAYS.SUN"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS.MON"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS.TUE"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS.WED"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS.THU"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS.FRI"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS.SAT")], + weekdaysShort: [$translate.instant("COMMON.PICKERDATE.WEEK_DAYS_SHORT.SUN"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS_SHORT.MON"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS_SHORT.TUE"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS_SHORT.WED"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS_SHORT.THU"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS_SHORT.FRI"), + $translate.instant("COMMON.PICKERDATE.WEEK_DAYS_SHORT.SAT")] + }, + isRTL: $translate.instant("COMMON.PICKERDATE.IS_RTL") == "true", + firstDay: parseInt($translate.instant("COMMON.PICKERDATE.FIRST_DAY_OF_WEEK"), 10), + format: $translate.instant("COMMON.PICKERDATE.FORMAT") + ) isEditable = -> permissions = $scope.project.my_permissions @@ -218,4 +249,4 @@ CustomAttributeValueDirective = ($template, $selectedText, $compile) -> restrict: "AE" } -module.directive("tgCustomAttributeValue", ["$tgTemplate", "$selectedText", "$compile", CustomAttributeValueDirective]) +module.directive("tgCustomAttributeValue", ["$tgTemplate", "$selectedText", "$compile", "$translate", CustomAttributeValueDirective])