app/views/permissions/edit.html.haml

Summary

Maintainability
Test Coverage
:ruby
  # is the user allowed to transfer AT LEAST 1 selected resource?
  some_can_be_transfered = @all_media_resources.accessible_by_user(current_user,:transfer).count >= 1
  
  # is the user allowed to transfer ALL selected resources?
  #all_can_be_transfered = @all_media_resources.count == @all_media_resources.accessible_by_user(current_user,:transfer).count
  
  # is the user allowed to manage AT LEAST 1 selected resource?
  some_can_be_managed = @media_resources.accessible_by_user(current_user, :manage).count >= 1

  # is the user allowed to manage ALL selected resource?
  #all_can_be_managed = @media_resources.accessible_by_user(current_user, :manage).count == @media_resources.count

.app

  = render "application/header"

  .app-body

    .app-body-title
      .ui-body-title
        .ui-body-title-label
          %h1.title-xl
            %i.icon-lock
            - case @action
            - when :view
              =_"Permissions"
            - when :edit
              =_"Edit permissions"
            = _"of"
            - if @media_resources.count == 1
              "#{@media_resources.first.title}"

            - else
              #{@media_resources.count}
              - if @media_resources.count != @all_media_resources.count
                #{_"out of"} #{@all_media_resources.count}
              = _"Inhalten"

        - case @action
        - when :view
          .ui-body-title-actions
            - if some_can_be_transfered
              =link_to edit_responsibilities_path(params.slice(:media_resource_id,:collection_id).merge({_action: "edit"})), id: "transfer-responsibilities", class: "button" do
                =_("Transfer responsibility")
              
            - if some_can_be_managed
              =link_to edit_permissions_path(params.slice(:media_resource_id,:collection_id).merge({_action: "edit"})), id: "edit-permissions",data: {manageable: true}, class: "primary-button" do
                =_("Edit permissions")

    .app-body-ui-container

      .bordered.ui-container.midtone.rounded.mbm

        = render :partial => "media_resources/selection",
                 :locals => {:media_resources => @media_resources.limit(100)}

      .ui-container.bright.bordered.rounded-right.rounded-bottom.pal

        %form#ui-rights-management{data: @data}

          .row
            .col1of2
              .ui-info-box
                - case @responsible_users.count
                - when 0
                  Keine verantwortliche Person!
                - when 1..1
                  %h2.title-l.ui-info-box-title Verantwortliche Person
                  %p.ui-info-box-intro.prm Die verantwortliche Person hat alle Berechtigungen zu den ausgewählten Inhalten und kann diese auch löschen.
                - when 2..3
                  %h2.title-l.ui-info-box-title Verantwortliche Personen
                  %p.ui-info-box-intro.prm Die verantwortliche Person hat alle Berechtigungen zu den ausgewählten Inhalten und kann diese auch löschen.
                - else
                  %h2.title-l.ui-info-box-title Es sind mehr als 3 verschiedene Personen für diese Inhalte verantwortlich.
                %ul.inline
                  - if @responsible_users.count <= 3
                    - @responsible_users.sort.each do |user|
                      - case @action
                      - when :edit
                        %li.person-tag= user
                      - when :view
                        %li
                          =link_to media_resources_path(search: user.person.fullname), class: "person-tag" do
                            = user
                        

            .col1of2
              %h2.title-l.ui-info-box-title Ihre Berechtigungen
              %p.ui-info-box-intro Sie, #{current_user}, haben gegenwärtig als Person oder als Mitglied einer Gruppe folgende Berechtigungen
              %ul.inline
                - action_map= {view: "Get metadata and previews", download: "Get full size", edit: "Edit metadata and add to Set", manage: "Edit permissions"}
                - [:view, :download, :edit, :manage].each do |action|
                  - if @media_resources.accessible_by_user(current_user,action).count == @media_resources.count
                    %li<>
                      =_(action_map[action])

          %hr.separator.light.mvl

          %h3.title-l.mbs Berechtigungen

          .ui-rights-management
            .pth
              .ui-preloader

          .ptl
            .form-footer
              .ui-actions

                - case @action
                - when :edit
                  = link_to @back_link, class: "link weak", title: _("Cancel") do
                    = _("Cancel")
                  - if @data[:manageable]
                    %button.primary-button.large{type: :submit, disabled: true}
                      = _("Save")

  .app-footer-push
= render :partial => "application/footer", :locals => {:clipboard => false}

:coffeescript

  jQuery ->
    new App.PermissionsController
      inline: $("#ui-rights-management")