From 4409cfbbfc59e2a81a210a65420890a51d3eec6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Hermida?= Date: Tue, 7 Aug 2018 14:40:55 +0200 Subject: [PATCH] Fix create due dates --- .../modules/admin/project-values.coffee | 51 +++++++++++++++---- .../admin/project-due-date-status.jade | 48 ++++++++++++++--- 2 files changed, 82 insertions(+), 17 deletions(-) diff --git a/app/coffee/modules/admin/project-values.coffee b/app/coffee/modules/admin/project-values.coffee index 0475db37..2482f699 100644 --- a/app/coffee/modules/admin/project-values.coffee +++ b/app/coffee/modules/admin/project-values.coffee @@ -33,7 +33,6 @@ bindOnce = @.taiga.bindOnce debounce = @.taiga.debounce getDefaulColorList = @.taiga.getDefaulColorList - module = angular.module("taigaAdmin") ############################################################################# @@ -270,9 +269,8 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame, $tra $scope.newValue.order = if $scope.maxValueOrder then $scope.maxValueOrder + 1 else 1 promise = $repo.create(valueType, $scope.newValue) - promise.then (data) => + promise.then (data) -> target.addClass("hidden") - $scope.values.push(data) $scope.maxValueOrder = data.order initializeNewValue() @@ -329,11 +327,6 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame, $tra target = angular.element(event.currentTarget) saveValue(target) - $el.on "click", ".save", (event) -> - event.preventDefault() - target = angular.element(event.currentTarget) - saveValue(target) - $el.on "click", ".cancel", (event) -> event.preventDefault() target = angular.element(event.currentTarget) @@ -387,6 +380,17 @@ ProjectDueDatesValues = ($log, $repo, $confirm, $location, animationFrame, $tran $translate, $rootscope, projectService) linkDueDateStatusValue = ($scope, $el, $attrs) -> + valueType = $attrs.type + + initializeNewValue = -> + $scope.newValue = { + "name": "" + "days_to_due": 0 + "sign": 1 + } + + initializeNewValue() + _setDaysToDue = (value) -> value.days_to_due = value.days_to_due_abs * value.sign @@ -394,7 +398,31 @@ ProjectDueDatesValues = ($log, $repo, $confirm, $location, animationFrame, $tran target = angular.element(event.currentTarget) row = target.parents(".row.table-main") formEl = target.parents("form") - return formEl.scope().value + if not formEl.scope().value + return formEl.scope().newValue + else + return formEl.scope().value + + saveNewValue = (target) -> + formEl = target.parents("form") + form = formEl.checksley() + return if not form.validate() + + $scope.newValue.project = $scope.project.id + + $scope.newValue.order = if $scope.maxValueOrder then $scope.maxValueOrder + 1 else 1 + + promise = $repo.create(valueType, $scope.newValue) + promise.then (data) -> + target.addClass("hidden") + data.days_to_due_abs = data.days_to_due + data.sign = 1 + $scope.values.push(data) + + initializeNewValue() + + promise.then null, (data) -> + form.setErrors(data) $el.on "input", ".days-to-due-abs", (event) -> event.preventDefault() @@ -409,6 +437,11 @@ ProjectDueDatesValues = ($log, $repo, $confirm, $location, animationFrame, $tran value.sign = value.sign * -1 _setDaysToDue(value) + $el.on "click", ".add-new-due-date", debounce 2000, (event) -> + event.preventDefault() + target = $el.find(".new-value") + saveNewValue(target) + return { link: ($scope, $el, $attrs) -> parentDirective.link($scope, $el, $attrs) diff --git a/app/partials/includes/modules/admin/project-due-date-status.jade b/app/partials/includes/modules/admin/project-due-date-status.jade index 23f68f5e..a72695cd 100644 --- a/app/partials/includes/modules/admin/project-due-date-status.jade +++ b/app/partials/includes/modules/admin/project-due-date-status.jade @@ -25,10 +25,10 @@ section.colors-table.admin-status-table span {{ value.name }} div.thresold-column - span(ng-if="value.days_to_due_abs != null") {{ value.days_to_due_abs }} + span(ng-if="value.days_to_due != null") {{ value.days_to_due_abs }} div.before-after-column - span(ng-if="value.days_to_due_abs", ng-switch="value.days_to_due >= 0") + span(ng-if="value.days_to_due", ng-switch="value.days_to_due >= 0") span(ng-switch-when="true") {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.BEFORE' | translate }} span(ng-switch-when="false") {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.AFTER' | translate }} @@ -63,7 +63,12 @@ section.colors-table.admin-status-table ) div.thresold-column(ng-if="!value.by_default") - input.days-to-due-abs(type="number", min="0", name="days_to_due_abs", ng-model="value.days_to_due_abs") + input.days-to-due-abs( + type="number" + data-type="digits" + min="0" + name="days_to_due" + ng-model="value.days_to_due_abs") div.before-after-column div.before-after-selector(ng-if="!value.by_default && value.days_to_due_abs != 0") @@ -97,7 +102,7 @@ section.colors-table.admin-status-table a.cancel(href="", title="{{'COMMON.CANCEL' | translate}}") tg-svg.cancel(svg-icon="icon-close") - form + form(tg-bind-scope) div.row.table-main.new-value.hidden div.color-column( tg-color-selection @@ -117,16 +122,43 @@ section.colors-table.admin-status-table ) div.thresold-column - input( - name="days_to_due" + input.days-to-due-abs( type="number" + data-type="digits" + min="0" + name="days_to_due_abs" placeholder="{{'ADMIN.STATUS.PLACEHOLDER_DAYS_TO_DUE_DATE' | translate}}" - ng-model="newValue.days_to_due" + ng-model="newValue.days_to_due_abs" data-required="true" ) + div.before-after-column + div.before-after-selector(ng-if="newValue.days_to_due_abs && newValue.days_to_due_abs != 0") + .before-after-selector-single(ng-class="{'checked': newValue.sign > 0 }") + input( + type='radio' + id="due-date-status-before" + name="due-date-status-after" + ng-model="newValue.sign" + value="1" + ) + label.days-to-due-sign( + for="due-date-status-before", + ) {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.BEFORE' | translate }} + .before-after-selector-single(ng-class="{'checked': newValue.sign < 0}") + input( + type='radio' + id="due-date-status-after" + name="due-date-status-after" + ng-model="newValue.sign" + value="-1" + ) + label.days-to-due-sign( + for="due-date-status-after", + ) {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.AFTER' | translate }} + div.options-column - a.add-new.e2e-save(href="", title="{{'COMMON.ADD' | translate}}") + a.add-new-due-date.e2e-save(href="", title="{{'COMMON.ADD' | translate}}") tg-svg(svg-icon="icon-save") a.delete-new(href="", title="{{'COMMON.CANCEL' | translate}}")