Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
Clean up Updates controller and improve the UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m committed Jul 1, 2013
1 parent 4d330a5 commit be7ad7c
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 142 deletions.
56 changes: 24 additions & 32 deletions app/controllers/administration/updates_controller.rb
Expand Up @@ -2,38 +2,16 @@ class Administration::UpdatesController < ApplicationController
before_filter :only_admins

def index
@updates = Update.where(complete: params[:complete] == 'true').order('created_at desc').page(params[:page])
@unapproved_groups = Group.find_all_by_approved(false)
@updates = toggle(Update).order('created_at desc').page(params[:page])
@unapproved_groups = Group.unapproved
end

def update
@update = Update.find(params[:id])
if params[:complete] == 'true'
if params[:commit]
if params[:update] and %w(true false).include?(params[:update][:child])
@update.child = (params[:update][:child] == 'true')
elsif @update.birthday and @update.birthday.year == 1800
flash[:warning] = t('people.child_alert', years: Setting.get(:system, :adult_age))
redirect_to administration_updates_path
return
end
if @update.do!
@update.update_attribute(:complete, true)
if params[:review]
redirect_to edit_person_path(@update.person, anchor: 'basics')
else
redirect_to administration_updates_path
end
else
render action: 'error', status: 500
end
else
@update.update_attribute(:complete, true)
redirect_to administration_updates_path
end
else
@update.update_attribute(:complete, false)
if @update.update_attributes!(update_params)
redirect_to administration_updates_path
else
render action: 'index'
end
end

Expand All @@ -45,11 +23,25 @@ def destroy

private

def only_admins
unless @logged_in.admin?(:manage_updates)
render text: t('only_admins'), layout: true, status: 401
return false
end
def update_params
params.require(:update).permit(:complete, :apply, :child)
end

def toggle(klass)
if params[:complete] == 'true'
@complete = true
klass.complete
else
@complete = false
klass.pending
end
end

def only_admins
unless @logged_in.admin?(:manage_updates)
render text: t('only_admins'), layout: true, status: 401
return false
end
end

end
24 changes: 24 additions & 0 deletions app/helpers/administration/updates_helper.rb
@@ -0,0 +1,24 @@
module Administration::UpdatesHelper

def update_row(object, key, before, after)
content_tag(:tr, class: 'update-row') do
content_tag(:td, class: 'strong') do
object.class.human_attribute_name(key)
end +
content_tag(:td, format_update_value(key, before)) +
content_tag(:td, content_tag(:div, '', class: 'right-icon')) +
content_tag(:td, format_update_value(key, after))
end
end

def format_update_value(key, value)
if [Date, Time, DateTime].include?(value.class)
value.to_s(:date)
elsif key =~ /phone|fax/
format_phone(value)
else
value
end
end

end
122 changes: 35 additions & 87 deletions app/views/administration/updates/index.html.erb
@@ -1,13 +1,16 @@
<% content_for :sidebar do %>
<h2>
<% if params[:complete] %><%= t('admin.updates.completed') %><% else %><%= t('admin.updates.pending_title') %><% end %>
Updates
<% if @complete %>
<%= t('admin.updates.completed_title') %>
<% else %>
<%= t('admin.updates.pending_title') %>
<% end %>
</h2>
<p><%= link_to t('admin.updates.show_status', status: params[:complete] ? t('admin.updates.pending_title') : t('admin.updates.complete')), complete: params[:complete].nil? %></p>
<p><%= link_to t('admin.updates.show_status', status: @complete ? t('admin.updates.pending_title') : t('admin.updates.complete')), complete: !@complete %></p>

<% if @logged_in.admin?(:manage_groups) %>
<h3><%= t('admin.updates.groups_pending') %></h3>
<% if not params[:complete] and @unapproved_groups.any? %>
<% if not @complete and @unapproved_groups.any? %>
<p><%= t('groups.following_are_pending_approval', count: @unapproved_groups.length) %> <%= raw @unapproved_groups.map { |g| link_to(h(g.name), group_path(id: g)) }.join(', ') %></p>
<% else %>
<p><%= t('admin.updates.none') %></p>
Expand All @@ -17,97 +20,53 @@

<h3><%= t('admin.updates.profile_updates') %></h3>

<%= will_paginate @updates, params: {complete: params[:complete]} %>
<%= will_paginate @updates, params: {complete: !@complete} %>

<table class="spaced">
<% @updates.each do |update| %>
<tr>
<td>
<% if update.person %>
<a href="<%= person_path(update.person) %>">
<%= render partial: 'people/thumbnail', locals: {person: update.person} %>
</a>
<% else %>
<%= image_tag 'clean/manoutline.tn.png', alt: '(' + t('admin.updates.person_deleted') + ')', class: 'icon thumbnail' %>
<% end %>
<%= render partial: 'people/thumbnail', locals: {person: update.person} %>
</td>
<td class="update">
<p>
<% if update.person %>
<%= link_to update.person.name, person_path(id: update.person) %>
<%= link_to update.person.name, update.person %>
<% else %>
'(<%= t('admin.updates.person_deleted') %>)'
(<%= t('admin.updates.person_deleted') %>)
<% end %>
<%= t('admin.updates.updated') %>
<%= update.created_at.to_s %>
<% if update.complete %>
<%= link_to t('admin.updates.mark_incomplete'), administration_update_path(update, complete: false), method: 'put' %>
<% else %>
<%= link_to t('admin.updates.mark_complete'), administration_update_path(update, complete: true), method: 'put' %> |
<%= link_to t('Delete'), administration_update_path(update), method: 'delete', confirm: t('are_you_sure') %>
<% end %>
</p>
<%= form_for update, url: administration_update_path(update), method: 'put' do |form| %>
<%= hidden_field_tag :complete, true %>
<%= form_for update, url: administration_update_path(update) do |form| %>
<%= hidden_field_tag 'update[apply]', true %>
<table>
<% if update.family_name %><tr class="update-row"><td><%= t('families.name') %>:</td><td><%= update.family.name %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= update.family_name %></td></tr><% end %>
<% if update.family_last_name %><tr class="update-row"><td><%= t('families.last_name') %>:</td><td><%= update.family.last_name %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= update.family_last_name %></td></tr><% end %>
<% if update.first_name %><tr class="update-row"><td><%= t('accounts.first_name') %>:</td><td><%= update.person.first_name %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= update.first_name %></td></tr><% end %>
<% if update.last_name %><tr class="update-row"><td><%= t('accounts.last_name') %>:</td><td><%= update.person.last_name %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= update.last_name %></td></tr><% end %>
<% if update.home_phone %><tr class="update-row"><td><%= t('privacies.home_phone') %>:</td><td><%= format_phone update.family.home_phone %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= format_phone update.home_phone %></td></tr><% end %>
<% if update.mobile_phone %><tr class="update-row"><td><%= t('privacies.mobile_phone') %>:</td><td><%= format_phone update.person.mobile_phone, :mobile %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= format_phone update.mobile_phone, :mobile %></td></tr><% end %>
<% if update.work_phone %><tr class="update-row"><td><%= t('privacies.work_phone') %>:</td><td><%= format_phone update.person.work_phone %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= format_phone update.work_phone %></td></tr><% end %>
<% if update.fax %><tr class="update-row"><td><%= t('privacies.fax') %>:</td><td><%= format_phone update.person.fax %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= format_phone update.fax %></td></tr><% end %>
<% if update.address1 %><tr class="update-row"><td><%= t('privacies.address') %>:</td><td><%= update.family.address1 %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= update.address1 %></td></tr><% end %>
<% if update.address2 %><tr class="update-row"><td><%= t('privacies.address2') %>:</td><td><%= update.family.address2 %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= update.address2 %></td></tr><% end %>
<% if update.city %><tr class="update-row"><td><%= t('search.city') %>:</td><td><%= update.family.city %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= update.city %></td></tr><% end %>
<% if update.state %><tr class="update-row"><td><%= t('search.state') %>:</td><td><%= update.family.state %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= update.state %></td></tr><% end %>
<% if update.zip %><tr class="update-row"><td><%= t('search.zip') %>:</td><td><%= update.family.zip %></td><td><div class="right-icon" style="width:10px;height:16px;"></td><td><%= update.zip %></td></tr><% end %>
<% if update.birthday %>
<tr class="update-row">
<td><%= t('search.birthday') %>:</td>
<td><%= update.person.birthday && update.person.birthday.to_s(:date) %></td>
<td><div class="right-icon" style="width:10px;height:16px;"></td>
<td><% unless update.birthday.year == 1800 %><%= update.birthday.to_s(:date) %><% end %></td>
</tr>
<% update.diff[:person].each do |key, (before, after)| %>
<%= update_row(update.person, key, before, after) %>
<% end %>
<% if !update.complete? and update.birthday and update.birthday.year == 1800 %>
<%# We're blanking out the birthday -- must know whether this is a child %>
<% update.diff[:family].each do |key, (before, after)| %>
<%= update_row(update.family, key, before, after) %>
<% end %>
<% if update.require_child_designation? %>
<tr>
<td><%= t('people.child') %>:</td>
<td></td>
<td></td>
<td>
<%= form.select :child, ['', [t('Answer_yes'), true], [t('Answer_no'), false]] %>
<td colspan="4">
<p><%= t('admin.updates.child_alert', years: Setting.get(:system, :adult_age)) %></p>
<p>
<label for="update_child" class="inline"><%= t('admin.updates.child') %></label>
<%= select_tag 'update[child]', options_for_select(t('admin.updates.child_select_options').invert) %>
</p>
</td>
</tr>
<% end %>
<% if update.anniversary %>
<tr class="update-row">
<td><%= t('privacies.anniversary') %>:</td>
<td><%= update.person.anniversary && update.person.anniversary.to_s(:date) %></td>
<td><div class="right-icon" style="width:10px;height:16px;"></td>
<td><% unless update.anniversary.year == 1800 %><%= update.anniversary.to_s(:date) %><% end %></td>
</tr>
<% end %>
<% update.custom_fields_as_hash.each do |key, val| %>
<% if val %>
<tr>
<td><%= key %>:</td>
<td></td>
<td></td>
<td>
<%= val %>
</td>
</tr>
<% end %>
<% end %>
<tr>
<td></td>
<td colspan="3">
<%= check_box_tag 'review', true, false %>
<%= label_tag 'review', t('admin.updates.review_changes'), class: 'inline' %><br/>
<%= form.submit t('Update') %>
<tr class="actions">
<td colspan="4">
<% if update.complete %>
<%= link_to t('admin.updates.mark_incomplete'), administration_update_path(update, 'update[complete]' => false), method: 'put', class: 'button' %>
<% else %>
<%= link_to_function t('admin.updates.apply'), "$(this).parents('form')[0].submit()", class: 'button primary' %>
<%= link_to t('admin.updates.mark_complete'), administration_update_path(update, 'update[complete]' => true), method: 'put', class: 'button' %>
<% end %>
<%= link_to t('Delete'), administration_update_path(update), method: 'delete', confirm: t('are_you_sure'), class: 'button' %>
</td>
</tr>
</table>
Expand All @@ -117,19 +76,8 @@
<% end %>
</table>

<%= will_paginate @updates, params: {complete: params[:complete]} %>
<%= will_paginate @updates, params: {complete: !@complete} %>
<% if @updates.empty? %>
<p><em><%= t('admin.updates.no_updates') %>!</em></p>
<% end %>

<script type="text/javascript">
$('.update-row').each(function(){
var elm = $(this);
var old_val = elm.children('td:eq(1)').html()
var new_val = elm.children('td:eq(3)').html()
if(old_val != new_val) {
elm.append('<td><span class="alert-icon"></span></td>')
}
});
</script>
34 changes: 30 additions & 4 deletions config/locales/en.yml
Expand Up @@ -70,7 +70,27 @@ en:
errors:
format: "%{message}"

activerecord:
activerecord:
attributes:
family:
name: Name
last_name: Last Name
home_phone: Home Phone
address1: Address Line 1
address2: Address Line 2
city: City
state: State
zip: Zipe
person:
first_name: First Name
last_name: Last Name
suffix: Suffix
gender: Gender
mobile_phone: Mobile Phone
work_phone: Work Phone
fax: Fax
birthday: Birthday
anniversary: Anniversary
errors:
models:
admin:
Expand Down Expand Up @@ -740,11 +760,18 @@ en:
syntax_description_html: Template syntax is <a href="http://wiki.github.com/tobi/liquid/liquid-for-designers">Liquid</a>. Special template parts to insert are
theme: Theme
updates:
apply: Apply
changed_email:
one: "%{count} changed email address"
other: "%{count} changed email addresses"
child: Is this a child?
child_alert: You must specify whether the person is a Child (under %{years}) or not to complete this update.
child_select_options:
'': You must select one.
true: 'Yes'
false: 'No'
complete: Complete
completed: Completed
completed_title: Completed Updates
groups_pending: Groups Pending Approval
mark_complete: Mark Complete
mark_incomplete: Mark Incomplete
Expand All @@ -753,7 +780,7 @@ en:
pending:
one: "%{count} pending update"
other: "%{count} pending updates"
pending_title: Pending
pending_title: Pending Updates
person_deleted: person deleted
per_day: Updates Per Day
profile_updates: Profile Updates
Expand Down Expand Up @@ -1393,7 +1420,6 @@ en:
changes_must_be_reviewed_html: Changes to the details below must be <strong>reviewed by staff</strong>. To request changes, enter the details below and click 'Submit.'
changes_submitted: Changes submitted.
child: Child
child_alert: You must specify whether the person is a Child (under %{years}) or not to complete this update.
click_to_send_verification_email: Send a password setup email to this user.
click_to_change_email_html: <a href="%{url}">Click here</a> to change this email address.
deleted_html: This person has been deleted. You can restore the record <a href="%{url}">here</a>.
Expand Down

0 comments on commit be7ad7c

Please sign in to comment.