diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-01-26 16:22:52 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-01-26 16:22:52 +0100 |
commit | e2e2fbbdc6b26e00101f5d4d1b05c0d076c817c2 (patch) | |
tree | 9bcee822e17e416dbf012f180d0abcdd309b6c51 /app | |
parent | af4a02e15a02481e23f9458ae0a430ec52c57417 (diff) |
Add a bit of AJAX to remove the just deleted row in call_history#index
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/call_histories_controller.rb | 5 | ||||
-rw-r--r-- | app/models/call_history.rb | 16 | ||||
-rw-r--r-- | app/views/call_histories/_index_core.html.haml | 61 | ||||
-rw-r--r-- | app/views/call_histories/destroy.js.erb | 1 |
4 files changed, 51 insertions, 32 deletions
diff --git a/app/controllers/call_histories_controller.rb b/app/controllers/call_histories_controller.rb index 5335ed3..2bfd4e3 100644 --- a/app/controllers/call_histories_controller.rb +++ b/app/controllers/call_histories_controller.rb @@ -44,7 +44,10 @@ class CallHistoriesController < ApplicationController if can?(:destroy, @call_history) @call_history.destroy m = method( :"#{@parent.class.name.underscore}_call_histories_url" ) - redirect_to m.(), :notice => t('call_histories.controller.successfuly_destroyed') + respond_to do |format| + format.html { redirect_to m.(), :notice => t('call_histories.controller.successfuly_destroyed')} + format.js + end end end diff --git a/app/models/call_history.rb b/app/models/call_history.rb index 4db056a..81342bd 100644 --- a/app/models/call_history.rb +++ b/app/models/call_history.rb @@ -3,6 +3,9 @@ class CallHistory < ActiveRecord::Base belongs_to :caller_account, :polymorphic => true belongs_to :callee_account, :polymorphic => true belongs_to :auth_account, :polymorphic => true + + validates :start_stamp, + :presence => true def display_number if self.entry_type == 'dialed' @@ -78,10 +81,11 @@ class CallHistory < ActiveRecord::Base end def display_call_date(date_format, date_today_format) - if self.start_stamp.strftime('%Y%m%d') == DateTime::now.strftime('%Y%m%d') + if self.start_stamp.to_date == Date.today return self.start_stamp.strftime(date_today_format) + else + return self.start_stamp.strftime(date_format) end - return self.start_stamp.strftime(date_format) end def display_duration @@ -129,6 +133,14 @@ class CallHistory < ActiveRecord::Base end + def voicemail_message? + begin + return self.call_historyable.voicemail_messages.where(:forwarded_by => self.caller_channel_uuid).any? + rescue + return nil + end + end + def voicemail_message begin return self.call_historyable.voicemail_messages.where(:forwarded_by => self.caller_channel_uuid).first diff --git a/app/views/call_histories/_index_core.html.haml b/app/views/call_histories/_index_core.html.haml index 4ebcad0..27c6d36 100644 --- a/app/views/call_histories/_index_core.html.haml +++ b/app/views/call_histories/_index_core.html.haml @@ -12,33 +12,35 @@ %tbody - for call_history in call_histories - - phone_number = call_history.display_number - - voicemail_message = call_history.voicemail_message - - if phone_number - - phone_book_entry = call_history.phone_book_entry_by_number(phone_number) - %tr + - if !call_history.display_number.blank? + - phone_book_entry = call_history.phone_book_entry_by_number(call_history.display_number) + %tr{:id => "call_history_id_#{call_history.id}"} %td - - if voicemail_message + - if call_history.voicemail_message? .voicemail-message - %a{:href => sip_account_voicemail_messages_path(@sip_account, :anchor => "message_#{voicemail_message.id}")} - = image_tag('icons/gs_envelope_16x.png', :class => 'display') + %a{:href => sip_account_voicemail_messages_path(@sip_account, :anchor => "message_#{call_history.voicemail_message.id}")} + = image_tag('icons/gs_envelope_16x.png') = call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) - - elsif call_history.entry_type == 'forwarded' - .call-forwarded= call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) - - if call_history.callee_account_type.to_s.downcase == 'voicemail' - = t("call_histories.index.voicemail") - - else - = call_history.destination_number - - elsif call_history.entry_type == 'dialed' - .call-placed= call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) - - elsif call_history.entry_type == 'received' - .call-received= call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) - - elsif call_history.entry_type == 'missed' - .call-missed= call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) - - else - .call-unknown - = t("call_histories.index.#{call_history.entry_type}") - = call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) + + - else + - case call_history.entry_type + - when 'forwarded' + .call-forwarded= call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) + - if call_history.callee_account_type.to_s.downcase == 'voicemail' + = t("call_histories.index.voicemail") + - else + = call_history.destination_number + - when 'dialed' + .call-placed= call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) + - when 'received' + .call-received= call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) + - when 'missed' + .call-missed= call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) + - else + .call-unknown + = t("call_histories.index.#{call_history.entry_type}") + = call_history.display_call_date(t("call_histories.index.date_format"), t("call_histories.index.date_today_format")) + - if call_history.forwarding_service && call_history.entry_type != 'forwarded' = t("call_histories.index.forwarded_by") = call_history.display_auth_account_name @@ -54,7 +56,7 @@ %a.name{:href => phone_book_phone_book_entry_path(phone_book_entry.phone_book, phone_book_entry), :itemprop => "name"}= display_name - else .name= display_name - .phone= phone_number + .phone= call_history.display_number %td - if call_history.display_duration .duration= call_history.display_duration @@ -65,7 +67,8 @@ = link_to t('call_histories.index.actions.call'), call_sip_account_call_history_path(@sip_account, call_history), :method => :put %td - if can? :destroy, call_history - / = link_to t('call_histories.index.actions.destroy'), sip_account_call_history_path(@sip_account, call_history), :method => :delete - %a.btn.btn-mini.btn-danger{"data-confirm" => t("#{call_history.class.name.underscore.pluralize}.actions.confirm_destroy"), "data-method" => "delete", :href => sip_account_call_history_path(@sip_account, call_history), :rel => "nofollow"} - %i.icon-trash.icon-white - =t('call_histories.index.actions.destroy') + = link_to "remove", [@sip_account, call_history], :method => :delete, :remote => true + / %a.btn.btn-mini.btn-danger{"data-confirm" => t("#{call_history.class.name.underscore.pluralize}.index.actions.confirm_destroy"), "data-method" => "delete", :href => sip_account_call_history_path(@sip_account, call_history), :rel => "nofollow", remote: true} + / %i.icon-trash.icon-white + / =t('call_histories.index.actions.destroy') + diff --git a/app/views/call_histories/destroy.js.erb b/app/views/call_histories/destroy.js.erb new file mode 100644 index 0000000..2d14ddb --- /dev/null +++ b/app/views/call_histories/destroy.js.erb @@ -0,0 +1 @@ +$('#call_history_id_<%= @call_history.id %>').remove();
\ No newline at end of file |