diff --git a/app/coffee/modules/common/lightboxes.coffee b/app/coffee/modules/common/lightboxes.coffee index 17fe81bd..9ff7e739 100644 --- a/app/coffee/modules/common/lightboxes.coffee +++ b/app/coffee/modules/common/lightboxes.coffee @@ -371,6 +371,8 @@ CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService, status: status is_archived: false tags: [] + subject: "" + description: "" }) # Update texts for creation @@ -478,24 +480,32 @@ CreateEditUserstoryDirective = ($repo, $model, $rs, $rootScope, lightboxService, submitButton = $el.find(".submit-button") - $el.on "submit", "form", submit - - $el.on "click", ".close", (event) -> - event.preventDefault() - - $scope.$apply -> - $scope.us.revert() - - lightboxService.close($el) - - $el.keydown (event) -> - code = if event.keyCode then event.keyCode else event.which - if code == 27 + close = () => + if !$scope.us.isModified() lightboxService.close($el) $scope.$apply -> $scope.us.revert() + else + $confirm.ask($translate.instant("LIGHTBOX.CREATE_EDIT_US.CONFIRM_CLOSE")).then (result) -> + lightboxService.close($el) + $scope.us.revert() + result.finish() + + $el.on "submit", "form", submit + + $el.find('.close').on "click", (event) -> + event.preventDefault() + event.stopPropagation() + close() + + $el.keydown (event) -> + event.stopPropagation() + code = if event.keyCode then event.keyCode else event.which + if code == 27 + close() $scope.$on "$destroy", -> + $el.find('.close').off() $el.off() return {link: link} diff --git a/app/coffee/modules/taskboard/lightboxes.coffee b/app/coffee/modules/taskboard/lightboxes.coffee index 19ecb708..2c23966c 100644 --- a/app/coffee/modules/taskboard/lightboxes.coffee +++ b/app/coffee/modules/taskboard/lightboxes.coffee @@ -27,7 +27,7 @@ bindOnce = @.taiga.bindOnce debounce = @.taiga.debounce trim = @.taiga.trim -CreateEditTaskDirective = ($repo, $model, $rs, $rootscope, $loading, lightboxService, $translate, $q, attachmentsService) -> +CreateEditTaskDirective = ($repo, $model, $rs, $rootscope, $loading, lightboxService, $translate, $q, $confirm, attachmentsService) -> link = ($scope, $el, attrs) -> $scope.isNew = true @@ -100,15 +100,17 @@ CreateEditTaskDirective = ($repo, $model, $rs, $rootscope, $loading, lightboxSer _.pull($scope.task.tags, value) $scope.$on "taskform:new", (ctx, sprintId, usId) -> - $scope.task = { + $scope.task = $model.make_model('tasks', { project: $scope.projectId milestone: sprintId user_story: usId is_archived: false status: $scope.project.default_task_status assigned_to: null - tags: [] - } + tags: [], + subject: "", + description: "", + }) $scope.isNew = true $scope.attachments = Immutable.List() @@ -187,7 +189,30 @@ CreateEditTaskDirective = ($repo, $model, $rs, $rootscope, $loading, lightboxSer $el.on "submit", "form", submit + close = () => + if !$scope.task.isModified() + lightboxService.close($el) + $scope.$apply -> + $scope.task.revert() + else + $confirm.ask($translate.instant("LIGHTBOX.CREATE_EDIT_TASK.CONFIRM_CLOSE")).then (result) -> + lightboxService.close($el) + $scope.task.revert() + result.finish() + + $el.find('.close').on "click", (event) -> + event.preventDefault() + event.stopPropagation() + close() + + $el.keydown (event) -> + event.stopPropagation() + code = if event.keyCode then event.keyCode else event.which + if code == 27 + close() + $scope.$on "$destroy", -> + $el.find('.close').off() $el.off() return {link: link} @@ -250,6 +275,7 @@ module.directive("tgLbCreateEditTask", [ "lightboxService", "$translate", "$q", + "$tgConfirm", "tgAttachmentsService", CreateEditTaskDirective ]) diff --git a/app/locales/taiga/locale-en.json b/app/locales/taiga/locale-en.json index bf2476eb..234bb72e 100644 --- a/app/locales/taiga/locale-en.json +++ b/app/locales/taiga/locale-en.json @@ -1066,13 +1066,15 @@ "PLACEHOLDER_STATUS": "Task status", "OPTION_UNASSIGNED": "Unassigned", "PLACEHOLDER_SHORT_DESCRIPTION": "Type a short description", - "ACTION_EDIT": "Edit task" + "ACTION_EDIT": "Edit task", + "CONFIRM_CLOSE": "You have not saved changes.\nAre you sure you want to close the form?" }, "CREATE_EDIT_US": { "TITLE": "New US", "PLACEHOLDER_DESCRIPTION": "Please add descriptive text to help others better understand this US", "NEW_US": "New user story", - "EDIT_US": "Edit user story" + "EDIT_US": "Edit user story", + "CONFIRM_CLOSE": "You have not saved changes.\nAre you sure you want to close the form?" }, "DELETE_SPRINT": { "TITLE": "Delete sprint"