From aad51572a6c75a4cbd2d44804b82f634a4ddd732 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 27 Jun 2013 20:58:33 +0200 Subject: Add the possiblity to search the phone_books in the Switchboard#view --- app/serializers/phone_book_entry_serializer.rb | 14 ++++++++++++++ app/serializers/switchboard_serializer.rb | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 app/serializers/phone_book_entry_serializer.rb (limited to 'app/serializers') diff --git a/app/serializers/phone_book_entry_serializer.rb b/app/serializers/phone_book_entry_serializer.rb new file mode 100644 index 0000000..ac25832 --- /dev/null +++ b/app/serializers/phone_book_entry_serializer.rb @@ -0,0 +1,14 @@ +class PhoneBookEntrySerializer < ActiveModel::Serializer + embed :ids, :include => true + + attributes :id, :first_name, :last_name, :organization, :search_result_display + has_many :phone_numbers + + def search_result_display + result = "#{object.last_name}, #{object.first_name}".strip.gsub(/^, /,'').gsub(/,$/,'') + if result.blank? + result = "#{object.organization}" + end + return result + end +end diff --git a/app/serializers/switchboard_serializer.rb b/app/serializers/switchboard_serializer.rb index 7ad7792..8a8bd42 100644 --- a/app/serializers/switchboard_serializer.rb +++ b/app/serializers/switchboard_serializer.rb @@ -1,7 +1,7 @@ class SwitchboardSerializer < ActiveModel::Serializer embed :ids, :include => true - attributes :id, :name, :show_avatars, :blind_transfer_activated, :attended_transfer_activated + attributes :id, :name, :show_avatars, :blind_transfer_activated, :attended_transfer_activated, :search_activated has_many :switchboard_entries has_many :sip_accounts, :through => :switchboard_entries has_many :phone_numbers -- cgit v1.2.3