From 9abd94ca1b99c08bc86fc9c051f303e1703f8466 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 1 Sep 2015 12:33:59 +0100 Subject: [PATCH] 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