diff --git a/app/coffee/modules/common/components.coffee b/app/coffee/modules/common/components.coffee index cfe55dc4..98e60bc3 100644 --- a/app/coffee/modules/common/components.coffee +++ b/app/coffee/modules/common/components.coffee @@ -433,7 +433,7 @@ module.directive("tgDeleteButton", ["$tgRepo", "$tgConfirm", "$tgNavUrls", "$tgL ## Editable subject directive ############################################################################# -EditableSubjectDirective = ($rootscope, $tgrepo, $confirm, $navurls, $location) -> +EditableSubjectDirective = ($rootscope, $tgrepo, $confirm, $navurls, $location, $loading) -> viewTemplate = _.template(""" <%- item.subject %> <% if (canEdit) { %> @@ -443,6 +443,9 @@ EditableSubjectDirective = ($rootscope, $tgrepo, $confirm, $navurls, $location) editTemplate = _.template(""" +
""") link = ($scope, $el, $attrs, $model) -> @@ -456,6 +459,19 @@ EditableSubjectDirective = ($rootscope, $tgrepo, $confirm, $navurls, $location) canEdit = $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1 $el.html(viewTemplate({item: $model.$modelValue, canEdit: canEdit})) + save = -> + $model.$modelValue.subject = $el.find('input').val() + $loading.start($el.find('.save-container')) + promise = $tgrepo.save($model.$modelValue) + promise.then -> + $rootscope.$broadcast("history:reload") + editing = false + $loading.finish($el.find('.save-container')) + render() + promise.then null, -> + $confirm.notify("error") + $loading.finish($el.find('.save-container')) + $scope.$watch $attrs.ngModel, (item) -> return if not item render() @@ -470,16 +486,12 @@ EditableSubjectDirective = ($rootscope, $tgrepo, $confirm, $navurls, $location) render() $el.find('input').focus() + $el.on "click", ".save", -> + save() + $el.on "keyup", "input", -> if event.keyCode == 13 - $model.$modelValue.subject = $el.find('input').val() - promise = $tgrepo.save($model.$modelValue) - promise.then -> - $rootscope.$broadcast("history:reload") - editing = false - render() - promise.then null, -> - $confirm.notify("error") + save() else if event.keyCode == 27 editing = false $model.$modelValue.revert() @@ -491,13 +503,13 @@ EditableSubjectDirective = ($rootscope, $tgrepo, $confirm, $navurls, $location) require: "ngModel" } -module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgNavUrls", "$tgLocation", EditableSubjectDirective]) +module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgNavUrls", "$tgLocation", "$tgLoading", EditableSubjectDirective]) ############################################################################# ## Editable subject directive ############################################################################# -EditableDescriptionDirective = ($rootscope, $tgrepo, $confirm, $navurls, $location, $compile) -> +EditableDescriptionDirective = ($rootscope, $tgrepo, $confirm, $navurls, $location, $compile, $loading) -> viewTemplate = _.template("""