migrate mailr 2.2.2 to 2.3.2
This commit is contained in:
parent
56039cc595
commit
ae789b1d84
23 changed files with 5 additions and 48 deletions
60
app/controllers/contact_group_controller.rb
Normal file
60
app/controllers/contact_group_controller.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
class Contacts::ContactGroupController < ApplicationController
|
||||
|
||||
uses_component_template_root
|
||||
|
||||
model :contact_group
|
||||
layout 'public'
|
||||
|
||||
def index
|
||||
redirect_to(:action=>"list")
|
||||
end
|
||||
|
||||
def list
|
||||
@contactgroup = ContactGroup.new
|
||||
@contactgroup.customer_id = logged_user
|
||||
@contactgroups = ContactGroup.find_by_user(logged_user)
|
||||
end
|
||||
|
||||
def add
|
||||
@contactgroup = ContactGroup.new
|
||||
@contactgroup.customer_id = logged_user
|
||||
render("/contact_group/edit")
|
||||
end
|
||||
|
||||
def delete
|
||||
contactgroup = ContactGroup.find(@params["id"])
|
||||
contactgroup.destroy
|
||||
redirect_to(:action=>"list")
|
||||
end
|
||||
|
||||
def edit
|
||||
@contactgroup = ContactGroup.find(@params["id"])
|
||||
end
|
||||
|
||||
def save
|
||||
begin
|
||||
if @params["contactgroup"]["id"].nil? or @params["contactgroup"]["id"] == ""
|
||||
# New contactgroup
|
||||
@contactgroup = ContactGroup.create(@params["contactgroup"])
|
||||
else
|
||||
# Edit existing
|
||||
@contactgroup = ContactGroup.find(@params["contactgroup"]["id"])
|
||||
@contactgroup.attributes = @params["contactgroup"]
|
||||
end
|
||||
|
||||
if @contactgroup.save
|
||||
redirect_to(:action=>"list")
|
||||
else
|
||||
render "/contact_group/edit"
|
||||
end
|
||||
rescue CDF::ValidationError => e
|
||||
logger.info("RESCUE")
|
||||
@contactgroup = e.entity
|
||||
render("/contact_group/edit")
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def secure_user?() true end
|
||||
|
||||
end
|
4
app/helpers/contact_group_helper.rb
Normal file
4
app/helpers/contact_group_helper.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
module ContactGroupHelper
|
||||
def link_save() "/contact_group/save" end
|
||||
def link_list() "/contact_group/list" end
|
||||
end
|
25
app/models/contact_group.rb
Normal file
25
app/models/contact_group.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
class ContactGroup < ActiveRecord::Base
|
||||
has_and_belongs_to_many :contacts, :class_name => "Contact", :join_table => "contact_contact_groups", :association_foreign_key => "contact_id", :foreign_key => "contact_group_id"
|
||||
|
||||
def ContactGroup.find_by_user(user_id)
|
||||
find_by_sql("select * from contact_groups where customer_id = #{user_id} order by name asc")
|
||||
end
|
||||
|
||||
protected
|
||||
def validate
|
||||
errors.add('name', :contactgroup_name_invalid) unless self.name =~ /^.{1,50}$/i
|
||||
end
|
||||
|
||||
def validate_on_create
|
||||
if ContactGroup.find_first(["name = '#{name}' and customer_id = #{user_id}"])
|
||||
errors.add("name", _('Please enter group name (1 to 50 characters)'))
|
||||
end
|
||||
end
|
||||
|
||||
def validate_on_update
|
||||
if ContactGroup.find_first(["name = '#{name}' and customer_id = #{user_id} and id <> #{id}"])
|
||||
errors.add("name", _('You already have contact group with this name'))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
24
app/views/contact_group/edit.rhtml
Normal file
24
app/views/contact_group/edit.rhtml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<h1><%=_('Edit/Create Contact Group')%></h1>
|
||||
<%=
|
||||
form_tag(
|
||||
link_save,
|
||||
'method' => 'post',
|
||||
'class' => 'two_columns'
|
||||
)
|
||||
%>
|
||||
<%= form_input(:hidden_field, 'contactgroup', 'id') %>
|
||||
<%= form_input(:hidden_field, 'contactgroup', 'customer_id') %>
|
||||
|
||||
<table>
|
||||
<%= form_input(:text_field, 'contactgroup', 'name', _('Name'), 'class'=>'two_columns') %>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td colspan=2 class="buttonBar">
|
||||
<input type="submit" name="Save" value="<%=_('Save')%>"/>
|
||||
<input type="button" value="<%=_('Back to groups')%>" onclick="window.location='<%=link_list%>'"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<%= end_form_tag %>
|
26
app/views/contact_group/list.rhtml
Normal file
26
app/views/contact_group/list.rhtml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<h1><%=_('Contact Groups')%></h1>
|
||||
|
||||
<form action="/contact_group/add" method="post">
|
||||
<%= hidden_field "contactgroup", "user_id" %>
|
||||
<table class="list">
|
||||
<tr>
|
||||
<th><%=_('Name')%></th>
|
||||
<th colspan=3> </th>
|
||||
</tr>
|
||||
<%
|
||||
for contactgroup in @contactgroups %>
|
||||
<tr class="even">
|
||||
<td><%= contactgroup.name %></td>
|
||||
<td><%= link_to(_('members'), :controller=>'contact', :action=>'list', :id=>contactgroup.id, :params=>{"mode"=>"groups"}) %></td>
|
||||
<td><%= link_to(_('edit'), :controller=>'/contacts/contact_group', :action=>'edit', :id=>contactgroup.id) %></td>
|
||||
<td><%= link_to(_('delete'), {:controller=>'/contacts/contact_group', :action=>'delete', :id=>contactgroup.id}, {:confirm=>sprintf(_('DELETE CONTACT GROUP \'%s\'?'), contactgroup.name)})%></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<td colspan=2 class="buttonBar">
|
||||
<input type="submit" value="<%=_('Add Contact Group')%>"/>
|
||||
<input type="button" value="<%=_('Back to folders')%>" onclick="window.location='/webmail/folders'">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
Loading…
Add table
Add a link
Reference in a new issue