### # Copyright (C) 2014 Andrey Antukh # Copyright (C) 2014 Jesús Espino Garcia # Copyright (C) 2014 David Barragán Merino # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # File: modules/admin/lightboxes.coffee ### taiga = @.taiga module = angular.module("taigaKanban") ############################################################################# ## Create Members Lightbox Directive ############################################################################# CreateMembersDirective = ($rs, $rootScope, $confirm) -> template = _.template("""
""") # i18n link = ($scope, $el, $attrs) -> createFieldSet = -> ctx = {roleList: $scope.roles} return template(ctx) resetForm = -> $el.find("form > fieldset").remove() title = $el.find("h2") fieldSet = createFieldSet() title.after(fieldSet) $scope.$on "membersform:new", -> resetForm() $el.removeClass("hidden") $scope.$on "$destroy", -> $el.off() # Dom Event Handlers $el.on "click", ".close", (event) -> event.preventDefault() $el.addClass("hidden") $el.on "click", ".delete-fieldset", (event) -> event.preventDefault() target = angular.element(event.currentTarget) fieldSet = target.parent() fieldSet.remove() $el.find('.add-fieldset').show() $el.on "click", ".add-fieldset", (event) -> event.preventDefault() target = angular.element(event.currentTarget) fieldSet = target.parent() target.removeClass("icon-plus add-fieldset").addClass("icon-delete delete-fieldset") newFieldSet = createFieldSet() fieldSet.after(newFieldSet) if $el.find('fieldset').length == 6 $el.find('.add-fieldset').hide() $el.on "click", ".button-green", (event) -> event.preventDefault() onSuccess = (data) -> $el.addClass("hidden") $confirm.notify("success") $rootScope.$broadcast("membersform:new:success") onError = (data) -> $el.addClass("hidden") $confirm.notify("error") $rootScope.$broadcast("membersform:new:error") form = $el.find("form").checksley() if not form.validate() return fieldSets = $el.find("form > fieldset") invitations = _.map fieldSets, (fs) -> fieldset = angular.element(fs) return { email: fieldset.children("input").val() role_id: fieldset.children("select").val() project_id: $scope.project.id } $rs.memberships.bulkCreateMemberships(invitations).then(onSuccess, onError) return {link: link} module.directive("tgLbCreateMembers", ["$tgResources", "$rootScope", "$tgConfirm", CreateMembersDirective])