diff --git a/app/assets/javascripts/app/controllers/organization_profile.coffee b/app/assets/javascripts/app/controllers/organization_profile.coffee index 65db8b5c1..ad7890c68 100644 --- a/app/assets/javascripts/app/controllers/organization_profile.coffee +++ b/app/assets/javascripts/app/controllers/organization_profile.coffee @@ -153,7 +153,7 @@ class Object extends App.ControllerObserver elLocal.find('.js-userList').html(members) ) - if @organization.member_ids.length < @memberLimit + if @organization.member_ids.length <= @memberLimit @el.find('.js-showMoreMembers').parent().addClass('hidden') else @el.find('.js-showMoreMembers').parent().removeClass('hidden') diff --git a/app/assets/javascripts/app/controllers/widget/organization.coffee b/app/assets/javascripts/app/controllers/widget/organization.coffee index dc90b7611..574490cde 100644 --- a/app/assets/javascripts/app/controllers/widget/organization.coffee +++ b/app/assets/javascripts/app/controllers/widget/organization.coffee @@ -33,7 +33,7 @@ class App.WidgetOrganization extends App.Controller elLocal.find('.js-userList').html(members) ) - if @organization.member_ids.length < @memberLimit + if @organization.member_ids.length <= @memberLimit @el.find('.js-showMoreMembers').parent().addClass('hidden') else @el.find('.js-showMoreMembers').parent().removeClass('hidden') diff --git a/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee b/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee index ec51e6ca0..fa1cf4f2c 100644 --- a/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee +++ b/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee @@ -14,6 +14,7 @@ class App.ObjectOrganizationAutocompletion extends App.Controller 'click': 'stopPropagation' 'change .js-objectId': 'executeCallback' 'click .js-remove': 'removeThisToken' + 'click .js-showMoreMembers': 'showMoreMembers' elements: '.recipientList': 'recipientList' @@ -251,14 +252,42 @@ class App.ObjectOrganizationAutocompletion extends App.Controller objectCount: objectCount ) + showMoreMembers: (e) -> + @preventDefaultAndStopPropagation(e) + + memberElement = $(e.target).closest('.js-showMoreMembers') + oldMemberLimit = memberElement.attr('organization-member-limit') + newMemberLimit = (parseInt(oldMemberLimit / 25) + 1) * 25 + memberElement.attr('organization-member-limit', newMemberLimit) + + @renderMembers(memberElement, oldMemberLimit, newMemberLimit) + + renderMembers: (element, fromMemberLimit, toMemberLimit) -> + id = element.closest('.recipientList-organizationMembers').attr('organization-id') + organization = App.Organization.find(id) + + # only first 10 members else we would need more ajax requests + organization.members(fromMemberLimit, toMemberLimit, (users) => + for user in users + element.before(@buildObjectItem(user)) + + if element.closest('ul').hasClass('is-shown') + @showOrganizationMembers(undefined, element.closest('ul')) + ) + + if organization.member_ids.length <= toMemberLimit + element.addClass('hidden') + else + element.removeClass('hidden') + buildOrganizationMembers: (organization) => - organizationMemebers = $( App.view(@templateOrganizationItemMembers)( + organizationMembers = $( App.view(@templateOrganizationItemMembers)( organization: organization ) ) - if organization[@referenceAttribute] - for objectId in organization[@referenceAttribute] - object = App[@objectSingle].fullLocal(objectId) - organizationMemebers.append(@buildObjectItem(object)) + + @renderMembers(organizationMembers.find('.js-showMoreMembers'), 0, 10) + + organizationMembers buildObjectItem: (object) => icon = @objectIcon @@ -404,8 +433,7 @@ class App.ObjectOrganizationAutocompletion extends App.Controller e.stopPropagation() listEntry = $(e.currentTarget) - organizationId = listEntry.data('organization-id') - + organizationId = listEntry.data('organization-id') || listEntry.attr('organization-id') @organizationList = @$("[organization-id=#{ organizationId }]") return if !@organizationList.get(0) diff --git a/app/assets/javascripts/app/models/organization.coffee b/app/assets/javascripts/app/models/organization.coffee index 2189289f7..867189ba2 100644 --- a/app/assets/javascripts/app/models/organization.coffee +++ b/app/assets/javascripts/app/models/organization.coffee @@ -36,7 +36,7 @@ Using **Organisations** you can **group** customers. This has among others two i userResult = -> users = [] for user_id in member_ids - user = App.User.find(user_id) + user = App.User.fullLocal(user_id) continue if !user users.push(user) return users diff --git a/app/assets/javascripts/app/views/generic/object_search/item_organization_members.jst.eco b/app/assets/javascripts/app/views/generic/object_search/item_organization_members.jst.eco index eb5c080d6..3af3aba7c 100644 --- a/app/assets/javascripts/app/views/generic/object_search/item_organization_members.jst.eco +++ b/app/assets/javascripts/app/views/generic/object_search/item_organization_members.jst.eco @@ -4,4 +4,9 @@ <%- @Icon('arrow-left') %> <%- @T('Back') %> - \ No newline at end of file + +