Sha256: 4daac179304aca7dd01668720a28145ebf8b86e6c057164c316b72f2d2e2e988

Contents?: true

Size: 1.97 KB

Versions: 12

Compression:

Stored size: 1.97 KB

Contents

module UcbRails
  module Renderer
    
    class LdapPersonSearchResultLink < Base
      attr_accessor :entry
      
      def initialize(template, entry, options={})
        super template, options
        self.entry = entry
      end
      
      def html
        exists? ? exists_html : button(text, :mini, :primary, link_options)
      end
      
      private
      
      def exists?
        ldap_person_search_existing_uids.include?(entry.uid.to_s)
      end
      
      def exists_html
        params["result-link-exists-text"] || 'Exists'
      end
      
      def text
        @text ||= params["result-link-text"].presence || "Add"
      end
      
      def link_options
        {
          class: classes,
          url: item_url,
          data: {
            remote: remote,
            method: http_method,
            uid: entry.uid,
            first_name: entry.first_name,
            last_name: entry.last_name,
            email: entry.email,
          }
        }
      end
      
      def classes
        ['result-link', params['result-link-class'].presence, default_class].select(&:presence)
      end
      
      # default class if no url, no result-link-class
      def default_class
        return nil if url_param.present?
        return nil if params['result-link-class'].present?
        'result-link-default'
      end
      
      def item_url
        url_param.present? ? url_and_person_params : '#'
      end
      
      def remote
        url_param.present?
      end

      def http_method
        params['result-link-http-method'] || :get
      end
      
      def url_param
        params["result-link-url"]
      end
      
      def url_and_person_params
        connector = url_param.include?("?") ? '&' : '?'
        "#{url_param}#{connector}#{person_params.to_query}"
      end
      
      def person_params
        {
          uid: entry.uid,
          first_name: entry.first_name,
          last_name: entry.last_name,
        }
      end
    end
    
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ucb_rails-0.0.14 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.13 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.12 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.11 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.10 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.9 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.8 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.7 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.6 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.5 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.4 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb
ucb_rails-0.0.3 app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb