Merge pull request #634 from artlepool/master

Adding Date field type to custom fields
stable
Juanfran 2015-09-09 12:17:28 +02:00
commit 6b837d2067
4 changed files with 67 additions and 8 deletions

View File

@ -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)
@ -148,6 +148,51 @@ 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?
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
requiredEditionPerm = $attrs.requiredEditionPerm
@ -156,6 +201,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 +212,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", ->
@ -199,4 +249,4 @@ CustomAttributeValueDirective = ($template, $selectedText, $compile) ->
restrict: "AE"
}
module.directive("tgCustomAttributeValue", ["$tgTemplate", "$selectedText", "$compile", CustomAttributeValueDirective])
module.directive("tgCustomAttributeValue", ["$tgTemplate", "$selectedText", "$compile", "$translate", CustomAttributeValueDirective])

View File

@ -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}}",

View File

@ -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}}")

View File

@ -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