Adding Date field type to custom fields

stable
Chris Wilson 2015-09-01 12:33:59 +01:00
parent 5aabd0dee1
commit 9abd94ca1b
4 changed files with 33 additions and 5 deletions

View File

@ -148,6 +148,20 @@ CustomAttributeValueDirective = ($template, $selectedText, $compile) ->
$el.html(html) $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 = -> isEditable = ->
permissions = $scope.project.my_permissions permissions = $scope.project.my_permissions
requiredEditionPerm = $attrs.requiredEditionPerm requiredEditionPerm = $attrs.requiredEditionPerm
@ -156,6 +170,9 @@ CustomAttributeValueDirective = ($template, $selectedText, $compile) ->
saveAttributeValue = -> saveAttributeValue = ->
attributeValue.value = $el.find("input, textarea").val() attributeValue.value = $el.find("input, textarea").val()
if attributeValue.field_type == "DATE" and attributeValue.value != ''
return if moment(attributeValue.value).isValid() != true
$scope.$apply -> $scope.$apply ->
$ctrl.updateAttributeValue(attributeValue).then -> $ctrl.updateAttributeValue(attributeValue).then ->
render(attributeValue, false) render(attributeValue, false)
@ -164,7 +181,9 @@ CustomAttributeValueDirective = ($template, $selectedText, $compile) ->
if event.keyCode == 13 and event.currentTarget.type != "textarea" if event.keyCode == 13 and event.currentTarget.type != "textarea"
submit(event) submit(event)
else if event.keyCode == 27 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) ## Actions (on view mode)
$el.on "click", ".custom-field-value.read-mode", -> $el.on "click", ".custom-field-value.read-mode", ->

View File

@ -456,7 +456,8 @@
"ISSUE_DESCRIPTION": "Issues custom fields", "ISSUE_DESCRIPTION": "Issues custom fields",
"ISSUE_ADD": "Add a custom field in issues", "ISSUE_ADD": "Add a custom field in issues",
"FIELD_TYPE_TEXT": "Text", "FIELD_TYPE_TEXT": "Text",
"FIELD_TYPE_MULTI": "Multi-line" "FIELD_TYPE_MULTI": "Multi-line",
"FIELD_TYPE_DATE": "Date"
}, },
"PROJECT_VALUES": { "PROJECT_VALUES": {
"PAGE_TITLE": "{{sectionName}} - Project values - {{projectName}}", "PAGE_TITLE": "{{sectionName}} - Project values - {{projectName}}",

View File

@ -8,7 +8,7 @@ form.custom-field-single.editable
<% } %> <% } %>
div.custom-field-value div.custom-field-value
<% if (field_type=="MULTI") { %> <% if (field_type=="MULTI") { %>
textarea#custom-field-description(name="description") textarea#custom-field-description(name="description")
<%- value %> <%- value %>
@ -18,5 +18,13 @@ form.custom-field-single.editable
input#custom-field-description(name="description", type="text", value!="<%- value %>") 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 div.custom-field-options
a.icon.icon-floppy(href="", title="{{'COMMON.CUSTOM_ATTRIBUTES.SAVE' | translate}}") a.icon.icon-floppy(href="", title="{{'COMMON.CUSTOM_ATTRIBUTES.SAVE' | translate}}")

View File

@ -40,7 +40,7 @@ section.custom-fields-table.basic-table
ng-model="attr.description") ng-model="attr.description")
fieldset.custom-field-type fieldset.custom-field-type
select(ng-model="attr.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 fieldset.custom-options
div.custom-options-wrapper div.custom-options-wrapper
a.js-update-custom-field-button.icon.icon-floppy(href="", title="{{'ADMIN.CUSTOM_ATTRIBUTES.ACTION_UPDATE' | translate}}") 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") ng-model="newAttr.description")
fieldset.custom-field-type fieldset.custom-field-type
select(ng-model="newAttr.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 fieldset.custom-options
div.custom-options-wrapper div.custom-options-wrapper