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

Commit

Permalink
Major work on groups pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m committed Nov 12, 2010
1 parent 558e1b0 commit 40b607a
Show file tree
Hide file tree
Showing 21 changed files with 439 additions and 288 deletions.
8 changes: 5 additions & 3 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ def index
# /groups?category=Small+Groups
# /groups?name=college
elsif params[:category] or params[:name]
@categories = Group.category_names
conditions = []
conditions.add_condition ['hidden = ? and approved = ?', false, true] unless @logged_in.admin?(:manage_groups)
conditions.add_condition ['category = ?', params[:category]] if params[:category]
conditions.add_condition ['name like ?', '%' + params[:name] + '%'] if params[:name]
@groups = Group.find(:all, :conditions => conditions, :order => 'name')
conditions[1] = true # only hidden groups
@hidden_groups = Group.find(:all, :conditions => conditions, :order => 'name')
conditions_for_hidden = conditions.dup
conditions_for_hidden[1] = true # only hidden groups
@hidden_groups = Group.find(:all, :conditions => conditions_for_hidden, :order => 'name')
respond_to do |format|
format.html { render :action => 'search' }
format.js
Expand Down Expand Up @@ -94,6 +96,7 @@ def create
params[:group].cleanse 'address'
@group = Group.new(params[:group])
@group.creator = @logged_in
@group.photo = photo
if @group.save
if @logged_in.admin?(:manage_groups)
@group.update_attribute(:approved, true)
Expand All @@ -102,7 +105,6 @@ def create
@group.memberships.create(:person => @logged_in, :admin => true)
flash[:notice] = t('groups.created_pending_approval')
end
@group.photo = photo
redirect_to @group
else
@categories = Group.categories.keys
Expand Down
13 changes: 10 additions & 3 deletions app/controllers/memberships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def show

def index
@group = Group.find(params[:group_id])
@can_edit = @logged_in.can_edit?(@group)
if @logged_in.can_see?(@group)
@requests = @group.membership_requests
else
Expand Down Expand Up @@ -68,7 +69,10 @@ def destroy
@membership.destroy
end
end
redirect_back
respond_to do |format|
format.html { redirect_back }
format.js
end
end

def batch
Expand Down Expand Up @@ -104,12 +108,15 @@ def batch_on_group
@group = Group.find(params[:group_id])
group_people = @group.people
if @logged_in.can_edit?(@group)
@can_edit = true
if params[:ids] and params[:ids].is_a?(Array)
@added = []
params[:ids].each do |id|
if request.post?
person = Person.find(id)
unless params[:commit] == 'Ignore'
@group.memberships.create(:person => person) unless group_people.include?(person)
unless params[:commit] == 'Ignore' or group_people.include?(person)
@group.memberships.create(:person => person)
@added << person
end
@group.membership_requests.find_all_by_person_id(id).each { |r| r.destroy }
elsif request.delete?
Expand Down
2 changes: 1 addition & 1 deletion app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def linked?
def mapable?
# must look like ", OK 74137"
# TODO: this needs some work to be usable in other countries
location.to_s.any? && location =~ /,\s[A-Z]{2}\s+\d{5}/ ? true : false
location.to_s.any? && location =~ /\s[A-Z]{2}\s+\d{5}/ ? true : false
end

def address=(a)
Expand Down
84 changes: 62 additions & 22 deletions app/views/groups/_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,37 @@
<%= form.text_field :creator, :value => (@group.creator ? @group.creator.name : nil), :readonly => true, :name => 'creator_name' %><br/>
</div>

<h3><%= t('groups.picture') %></h3>
<div class="section">
<div class="form-field-hint"><%= t('groups.picture_hint') %></div>
<%= render :partial => 'photo' %>
<%= form.file_field :photo %><br/>
<% if !@group.new_record? and @group.photo.exists? %>
<%= link_to t('groups.remove_group_photo'), group_path(@group, :group => {:photo => 'remove'}), :method => 'put', :confirm => t('are_you_sure') %>
<br/>
<% end %>
<em><%= t('groups.click_save_changes_to_upload') %></em>
</div>

<h3><%= t('groups.meets') %></h3>
<div class="section">
<%= form.label :meets, t('groups.meets_when') %>
<div class="form-field-hint"><%= t('groups.meets_when_hint') %></div>
<%= form.text_field :meets %><br/>

<%= form.label :location, t('groups.location_address') %>
<div class="form-field-hint"><%= t('groups.location_address_hint') %></div>
<%= form.text_area :location, :rows => 3 %><br/>
<% if Setting.get(:services, :yahoo) %>
<div class="form-field-hint"><%= t('groups.location_address_hint') %></div>
<% end %>
<%= form.text_area :location, :rows => 3 %>
<div id="map-preview"></div>
<br/>

<%= form.label :directions, t('groups.directions') %>
<div class="form-field-hint"><%= t('groups.directions_hint') %></div>
<%= form.text_area :directions, :rows => 3 %>
</div>

<h3><%= t('groups.picture') %></h3>
<div class="section">
<div class="form-field-hint"><%= t('groups.picture_hint') %></div>
<%= render :partial => 'photo' %>
<%= form.file_field :photo %><br/>
<% if !@group.new_record? and @group.photo.exists? %>
<%= link_to t('groups.remove_group_photo'), group_path(@group, :group => {:photo => 'remove'}), :method => 'put', :confirm => t('are_you_sure') %>
<br/>
<% end %>
<em><%= t('groups.click_save_changes_to_upload') %></em>
</div>

<h3><%= t('groups.features') %></h3>
<div class="section">
<div class="form-field-hint"><%= t('groups.address_hint') %></div>
Expand Down Expand Up @@ -116,20 +120,20 @@
<div class="section">
<%= t('groups.the_settings_are_for_advanced_users') %><br/>
<%= form.label :link_code, t('groups.class_link_code') %>
<div class="form-field-hint"><%= t('groups.class_link_code_hint_html') %></div>
<%= form.text_field :link_code %>
<em><%= t('groups.separate_codes_with_space') %></em>
<%= form.label :parents_of, t('groups.parents_of') %>
<div class="form-field-hint"><%= t('groups.parents_of_hint') %></div>
<%= form.select :parents_of, [['(' + t('none') + ')', '']] + (Group.find_all_by_hidden(false, :order => 'name')-[@group]).map { |g| [g.name, g.id] } %>
<em>Membership will be auto-generated from parents of selected group's members.</em>
<em></em>

<%= form.label :cm_api_list_id, 'Campaign Monitor API List ID:' %>
You must follow all policies of Campaign Monitor, including
<a href="http://www.campaignmonitor.com/resources/entry/558/about-permission/">permission requirements</a>.<br/>
<%= link_to_function 'I agree. &raquo;'.html_safe, "$('#cm_section').show();$(this).hide();" %>
<%= form.label :cm_api_list_id, t('groups.campaign_monitor_sync') %>
<%= t('groups.campaign_monitor_policy_html') %><br/>
<%= link_to_function t('groups.i_agree'), "$('#cm_section').show();$(this).hide();$('#group_cm_api_list_id')[0].focus();" %>
<div id="cm_section" style="display:none;">
<em><%= t('groups.campaign_monitor_sync_help') %></em><br/>
<%= form.text_field :cm_api_list_id %>
<em>To sync with a Campaign Monitor subscriber list, paste the API List ID here.</em>
</div>

<%= form.label :hidden, t('groups.hidden_group') %>
Expand All @@ -139,9 +143,12 @@
</div>
<% end %>

<p><%= form.submit t('save_changes') %></p>
<p class="double-margin-top"><%= form.submit t('save_changes') %></p>
<% end %>
<% if Setting.get(:services, :yahoo) %>
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.4&amp;appid=<%= Setting.get(:services, :yahoo) %>"></script>
<% end %>
<script type="text/javascript">
function update_address(name) {
var address = name.toLowerCase().match(/[a-z0-9]+/g).join('');
Expand All @@ -152,6 +159,38 @@
alert('<%= t('groups.by_allow_anyone_to_join') %>');
}
}
function createMapMarker(address) {
var img = new YImage();
img.src = '/images/map_marker.gif';
img.size = new YSize(16, 28);
return new YMarker(address, img);
}
map = null;
function mapLocation() {
<%= Setting.get(:services, :yahoo) ? nil : 'return;' %>
var width = 350;
var height = 150;
if($('#group_location').val().match(/\s[A-Z]{2}\s+\d{5}/)) {
var address = $('#group_location').val();
if(map) {
map.removeMarkersAll();
} else {
$('#map-preview').html('').css('width', width+'px').css('height', height+'px');
map = new YMap('map-preview');
map.addZoomLong();
map.setMapType(YAHOO_MAP_REG);
map.addTypeControl();
map.disableKeyControls();
}
map.drawZoomAndCenter(address, 6);
map.addOverlay(createMapMarker(address));
} else {
$('#map-preview').html(
'<%= escape_javascript t('groups.unmapable_address') %>'
).css('width', 'auto').css('height', 'auto');
map = null;
}
}
function toggleAddressField() {
if($('#group_email').attr('checked')) {
$('#group_address_field').css('display', 'inline');
Expand All @@ -169,4 +208,5 @@
}
toggleAddressField();
toggleCalendarField();
observeFields(mapLocation, 2000, ['group_location']);
</script>
1 change: 1 addition & 0 deletions app/views/groups/_menu.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ul class="popup-menu">
<% if @logged_in.can_edit?(@group) %>
<li><%= link_to t('menus.group.edit'), edit_group_path(@group), :class => 'edit-icon' %></li>
<li><%= link_to t('menus.group.delete'), group_path(@group), :method => :delete, :confirm => t('are_you_sure'), :class => 'delete-icon' %></li>
<% end %>
</ul>
</div>
Expand Down
32 changes: 0 additions & 32 deletions app/views/groups/_people.erb

This file was deleted.

10 changes: 4 additions & 6 deletions app/views/groups/_person_groups.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
<% if not group.hidden? or @logged_in.admin?(:manage_groups) %>
<tr <% if group.hidden? %>class="grayed hidden-group" style="display:none;"<% end %>>
<td>
<% if group.photo.exists? %>
<%= image_tag group.photo.url(:tn), :alt => group.name, :class => 'no-border' %>
<% else %>
<%= image_tag 'clean/group.tn.png', :alt => group.name, :class => 'no-border' %>
<% end %>
<%= render :partial => 'thumbnail', :locals => {:group => group} %>
</td>
<td class="group">
<%= link_to group.name, group %><br/>
<%= link_to group.name, group %>
<% if group.private? %>(private)<% end %>
<br/>
<% if params[:controller] == 'people' and (me? or @logged_in.admin?(:manage_groups)) %>
<span>
<%= t('people.email') %>:
Expand Down
4 changes: 4 additions & 0 deletions app/views/groups/_thumbnail.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= link_to image_tag(
group.photo.exists? ? group.photo.url(:tn) : 'clean/group.tn.png',
:alt => group.name,
:class => 'icon'), group %>
15 changes: 5 additions & 10 deletions app/views/groups/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<% content_for :subnav do %>
<li><%= link_to image_tag('eye.png', :alt => t('groups.view_group'), :class => 'icon') + ' ' + t('groups.view_group'), @group %></li>
<li><%= link_to image_tag('delete.png', :alt => t('groups.delete_group'), :class => 'icon') + ' ' + t('groups.delete_group'), @group, :confirm => t('are_you_sure_cannot_be_undone'), :method => 'delete' %></li>
<% end %>
<% content_for :sidebar do %>
<div id="memberships">
<%= render :partial => 'memberships' %>
</div>

<p><%= link_to t('groups.back_to_group', :name => @group.name), @group, :class => 'left-icon' %></p>
<p class="double-margin-top">
<%= link_to t('groups.edit_members'), group_memberships_path(@group), :class => 'edit-icon' %>
</p>
<% end %>
<% if @group.private? %><%= render :partial => 'private' %><% end %>
<% if @group.hidden? %><%= render :partial => 'hidden' %><% end %>

<h1><%= t('groups.edit_group') %></h1>
<h2><%= t('groups.edit_group') %></h2>

<%= render :partial => 'form' %>
3 changes: 2 additions & 1 deletion app/views/groups/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<% content_for :sidebar do %>
<p><%= link_to t('groups.back_to_homepage'), groups_path %></p>
<% end %>


<h2><%= t('groups.new_group') %></h2>

<%= render :partial => 'form' %>
Loading

0 comments on commit 40b607a

Please sign in to comment.