Do the first version of 'add memberships' feature
parent
5e9bd682aa
commit
9056b944c8
|
@ -0,0 +1,118 @@
|
|||
###
|
||||
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
|
||||
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# File: modules/admin/lightboxes.coffee
|
||||
###
|
||||
|
||||
taiga = @.taiga
|
||||
|
||||
module = angular.module("taigaKanban")
|
||||
|
||||
|
||||
#############################################################################
|
||||
## Create Members Lightbox Directive
|
||||
#############################################################################
|
||||
|
||||
CreateMembersDirective = ($repo, $rootScope, $q, $confirm) ->
|
||||
template = _.template("""
|
||||
<fieldset>
|
||||
<input type="email" placeholder="Type an Email" data-required="true" />
|
||||
<select data-required="true">
|
||||
<% _.each(roleList, function(role) { %>
|
||||
<option value="<%- role.id %>"><%- role.name %></option>
|
||||
<% }); %>
|
||||
</select>
|
||||
<a class="icon icon-plus" href=""></a>
|
||||
<fieldset>
|
||||
""") # i18n
|
||||
|
||||
createFieldSet = ($ctrl) ->
|
||||
ctx = {roleList: $ctrl.scope.project.roles}
|
||||
return template(ctx)
|
||||
|
||||
link = ($scope, $el, $attrs) ->
|
||||
$ctrl = $el.controller()
|
||||
|
||||
title = $el.find("h2")
|
||||
fieldSet = createFieldSet($ctrl)
|
||||
title.after(fieldSet)
|
||||
|
||||
$scope.$on "membersform:new", ->
|
||||
$el.removeClass("hidden")
|
||||
|
||||
$scope.$on "$destroy", ->
|
||||
$el.off()
|
||||
|
||||
# Dom Event Handlers
|
||||
$el.on "click", ".close", (event) ->
|
||||
event.preventDefault()
|
||||
$el.addClass("hidden")
|
||||
|
||||
$el.on "click", ".icon-delete", (event) ->
|
||||
event.preventDefault()
|
||||
target = angular.element(event.currentTarget)
|
||||
fieldSet = target.parent()
|
||||
|
||||
fieldSet.remove()
|
||||
|
||||
$el.on "click", ".icon-plus", (event) ->
|
||||
event.preventDefault()
|
||||
target = angular.element(event.currentTarget)
|
||||
fieldSet = target.parent()
|
||||
|
||||
target.removeClass("icon-plus").addClass("icon-delete")
|
||||
newFieldSet = createFieldSet($ctrl)
|
||||
fieldSet.after(newFieldSet)
|
||||
|
||||
$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
|
||||
|
||||
form = angular.element($el.find("form"))
|
||||
fieldSets = form.children("fieldset")
|
||||
|
||||
invitations = _.map fieldSets, (fs) ->
|
||||
fieldset = angular.element(fs)
|
||||
return {
|
||||
email: fieldset.children("input").val()
|
||||
role: fieldset.children("select").val()
|
||||
project: $ctrl.scope.project.id
|
||||
}
|
||||
|
||||
promises = _.map invitations, (inv) ->
|
||||
return $repo.create("memberships", inv)
|
||||
|
||||
$q.all(promises).then(onSuccess, onError)
|
||||
|
||||
return {link: link}
|
||||
|
||||
module.directive("tgLbCreateMembers", ["$tgRepo", "$rootScope", "$q", "$tgConfirm",
|
||||
CreateMembersDirective])
|
|
@ -16,7 +16,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# File: modules/admin/project-profile.coffee TODO
|
||||
# File: modules/admin/memberships.coffee
|
||||
###
|
||||
|
||||
taiga = @.taiga
|
||||
|
@ -42,7 +42,7 @@ class MembershipsController extends mixOf(taiga.Controller, taiga.PageMixin, tai
|
|||
"$location"
|
||||
]
|
||||
|
||||
constructor: (@scope, @rootScope, @repo, @confirm, @rs, @params, @q, @location) ->
|
||||
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location) ->
|
||||
@scope.sectionName = "Memberships" #i18n
|
||||
@scope.project = {}
|
||||
@scope.filters = {}
|
||||
|
@ -51,6 +51,8 @@ class MembershipsController extends mixOf(taiga.Controller, taiga.PageMixin, tai
|
|||
promise.then null, ->
|
||||
console.log "FAIL" #TODO
|
||||
|
||||
@scope.$on("membersform:new:success", @.onNewMembers)
|
||||
|
||||
loadProject: ->
|
||||
return @rs.projects.get(@scope.projectId).then (project) =>
|
||||
@scope.project = project
|
||||
|
@ -78,6 +80,13 @@ class MembershipsController extends mixOf(taiga.Controller, taiga.PageMixin, tai
|
|||
filters.page = 1 if not filters.page
|
||||
return filters
|
||||
|
||||
addNewMembers: ->
|
||||
@rootscope.$broadcast("membersform:new")
|
||||
|
||||
onNewMembers: ->
|
||||
@.loadMembers()
|
||||
|
||||
|
||||
module.controller("MembershipsController", MembershipsController)
|
||||
|
||||
|
||||
|
@ -367,7 +376,7 @@ MembershipsMemberRoleSelectorDirective = ($log, $repo, $confirm) ->
|
|||
template = _.template("""
|
||||
<select>
|
||||
<% _.each(roleList, function(role) { %>
|
||||
<option value=<%- role.id %> <% if(selectedRole === role.id){ %>selected="selected"<% } %>>
|
||||
<option value="<%- role.id %>" <% if(selectedRole === role.id){ %>selected="selected"<% } %>>
|
||||
<%- role.name %>
|
||||
</option>
|
||||
<% }); %>
|
||||
|
|
|
@ -13,12 +13,12 @@ block content
|
|||
header
|
||||
include views/components/mainTitle
|
||||
|
||||
a.button.button-green(title="Add new member" href="")
|
||||
a.button.button-green(title="Add new member" href="" ng-click="ctrl.addNewMembers()")
|
||||
span.text + New member
|
||||
|
||||
include views/modules/admin/admin-membership-table
|
||||
|
||||
div.paginator.memberships-paginator
|
||||
|
||||
div.lightbox.ligbox_add-member
|
||||
div.lightbox.ligbox_add-member.hidden(tg-lb-create-members)
|
||||
include views/modules/lightbox_add-member
|
||||
|
|
|
@ -2,21 +2,6 @@ a.close(href="", title="close")
|
|||
span.icon.icon-delete
|
||||
form
|
||||
h2.title New Member
|
||||
fieldset
|
||||
input(type="email", placeholder="Email")
|
||||
select
|
||||
option Front
|
||||
option Role
|
||||
option UX
|
||||
a.icon.icon-delete(href="")
|
||||
|
||||
fieldset
|
||||
input(type="email", placeholder="Email")
|
||||
select
|
||||
option Front
|
||||
option Role
|
||||
option UX
|
||||
a.icon.icon-plus(href="")
|
||||
|
||||
a.button.button-green(href="", title="Save")
|
||||
span Create
|
||||
|
|
|
@ -147,7 +147,6 @@
|
|||
}
|
||||
|
||||
.ligbox_add-member {
|
||||
display: none;
|
||||
fieldset {
|
||||
@include clearfix;
|
||||
margin-bottom: 1rem;
|
||||
|
|
Loading…
Reference in New Issue