themes_for_rails integrated with original theme
This commit is contained in:
parent
573356a3a4
commit
921de13cc0
95 changed files with 511 additions and 208 deletions
|
@ -12,6 +12,11 @@ class ApplicationController < ActionController::Base
|
|||
#filter_parameter_logging :password #upgrade to Rails3
|
||||
|
||||
protected
|
||||
|
||||
def theme_resolver
|
||||
CDF::CONFIG[:theme] || CDF::CONFIG[:default_theme]
|
||||
end
|
||||
|
||||
def secure_user?() true end
|
||||
def secure_cust?() false end
|
||||
def additional_scripts() "" end
|
||||
|
|
|
@ -1,28 +1,32 @@
|
|||
class ContactGroupsController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
layout 'public'
|
||||
|
||||
|
||||
|
||||
def index
|
||||
@contact_group = ContactGroup.new
|
||||
@contact_group.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"] == ""
|
||||
|
@ -33,7 +37,7 @@ class ContactGroupsController < ApplicationController
|
|||
@contactgroup = ContactGroup.find(@params["contactgroup"]["id"])
|
||||
@contactgroup.attributes = @params["contactgroup"]
|
||||
end
|
||||
|
||||
|
||||
if @contactgroup.save
|
||||
redirect_to(:action=>"list")
|
||||
else
|
||||
|
@ -45,8 +49,8 @@ class ContactGroupsController < ApplicationController
|
|||
render("/contact_group/edit")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def secure_user?() true end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
class ContactsController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
layout :select_layout
|
||||
|
||||
|
||||
def index
|
||||
if params[:letter] && params[:letter].any?
|
||||
@contacts = Contact.for_customer(logged_user).letter(params[:letter]).paginate :page => params[:page],
|
||||
|
@ -9,14 +12,14 @@ class ContactsController < ApplicationController
|
|||
@contacts = Contact.for_customer(logged_user).paginate :page => params[:page], :per_page => CDF::CONFIG[:contacts_per_page]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def listLetter
|
||||
letters = CDF::CONFIG[:contact_letters]
|
||||
@contact_pages = Paginator.new(self, Contact.count(
|
||||
["customer_id = %s and substr(UPPER(fname),1,1) = '%s'", logged_user, letters[params['id'].to_i]]), CDF::CONFIG[:contacts_per_page], params['page'])
|
||||
@contacts = Contact.find(:all, :conditions=>["customer_id = %s and substr(UPPER(fname),1,1) = '%s'", logged_user, letters[params['id'].to_i]],
|
||||
@contacts = Contact.find(:all, :conditions=>["customer_id = %s and substr(UPPER(fname),1,1) = '%s'", logged_user, letters[params['id'].to_i]],
|
||||
:order=>['fname'], :limit=>CDF::CONFIG[:contacts_per_page], :offset=>@contact_pages.current.offset)
|
||||
|
||||
|
||||
if params["mode"] == "groups"
|
||||
if params["group_id"] and not params["group_id"].nil? and not params["group_id"] == ''
|
||||
@group_id = params["group_id"].to_i
|
||||
|
@ -31,17 +34,17 @@ class ContactsController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
render :action => "list"
|
||||
end
|
||||
|
||||
|
||||
def new
|
||||
@contact = Contact.new
|
||||
@contact.customer_id = logged_user
|
||||
|
||||
|
||||
# load related lists
|
||||
loadLists
|
||||
|
||||
|
||||
# Init groups: because of checkbox
|
||||
# Set all to 0 => unchecked
|
||||
@groups = Hash.new
|
||||
|
@ -49,12 +52,12 @@ class ContactsController < ApplicationController
|
|||
@groups[g.id] = 0
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def add_multiple
|
||||
@contact = Contact.new
|
||||
@contact["file_type"] = "1"
|
||||
end
|
||||
|
||||
|
||||
def add_from_mail
|
||||
cstr = params['cstr']
|
||||
retmsg = params['retmsg']
|
||||
|
@ -69,13 +72,13 @@ class ContactsController < ApplicationController
|
|||
else
|
||||
fname, lname, email = "", "", cstr
|
||||
end
|
||||
|
||||
|
||||
if @contact = Contact.find_by_user_email(logged_user, email)
|
||||
# load related lists
|
||||
loadLists
|
||||
|
||||
|
||||
@contact.fname, @contact.lname = fname, lname
|
||||
|
||||
|
||||
# groups = @contact.groups
|
||||
@groups = Hash.new
|
||||
@contactgroups.each {|g|
|
||||
|
@ -95,82 +98,82 @@ class ContactsController < ApplicationController
|
|||
else
|
||||
@contact = Contact.new("fname"=>fname, "lname" => lname, "email" => email)
|
||||
@contact.customer_id = logged_user
|
||||
|
||||
|
||||
# load related lists
|
||||
loadLists
|
||||
|
||||
|
||||
# Init groups: because of checkbox
|
||||
# Set all to 0 => unchecked
|
||||
@groups = Hash.new
|
||||
@contactgroups.each {|g|
|
||||
@groups[g.id] = 0
|
||||
}
|
||||
end
|
||||
end
|
||||
render :action => "new"
|
||||
end
|
||||
|
||||
|
||||
def import_preview
|
||||
file = params["contact"]["data"]
|
||||
|
||||
|
||||
flash["errors"] = Array.new
|
||||
|
||||
|
||||
if file.size == 0
|
||||
flash["errors"] << _('You haven\'t selected file or the file is empty')
|
||||
@contact = Contact.new
|
||||
@contact["file_type"] = params["contact"]["file_type"]
|
||||
render :action => "add_multiple"
|
||||
end
|
||||
|
||||
|
||||
file_type = params["contact"]["file_type"]
|
||||
if file_type.nil? or file_type == '1'
|
||||
separator = ','
|
||||
else
|
||||
separator = /\t/
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
@contacts = Array.new
|
||||
emails = Array.new
|
||||
|
||||
file.each {|line|
|
||||
|
||||
file.each {|line|
|
||||
cdata = line.strip.chomp.split(separator)
|
||||
cont = Contact.new
|
||||
cont.fname = cdata[0].to_s.strip.chomp
|
||||
cont.lname = cdata[1].to_s.strip.chomp
|
||||
cont.email = cdata[2].to_s.strip.chomp
|
||||
|
||||
|
||||
# Check for duplicate emails in the file
|
||||
if emails.include?(cont.email)
|
||||
flash["errors"] << sprintf(_('Contact %'), file.lineno.to_s) + ": " + _('The e-mail duplicates the e-mail of another record!')
|
||||
else
|
||||
else
|
||||
emails << cont.email
|
||||
end
|
||||
|
||||
|
||||
@contacts << cont
|
||||
}
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
def import
|
||||
contacts_count = params["contact"].length
|
||||
contacts_to_import = params["contact"]
|
||||
@contacts = Array.new
|
||||
emails = Array.new
|
||||
|
||||
|
||||
flash["errors"] = Array.new
|
||||
|
||||
|
||||
for i in 0...contacts_count
|
||||
contact = Contact.new
|
||||
contact.customer_id = logged_user
|
||||
contact.fname = contacts_to_import[i.to_s]["fname"]
|
||||
contact.lname = contacts_to_import[i.to_s]["lname"]
|
||||
contact.email = contacts_to_import[i.to_s]["email"]
|
||||
|
||||
|
||||
begin
|
||||
# Check for duplicate emails in the submitted data
|
||||
if emails.include?(contact.email)
|
||||
flash["errors"] << sprintf(_('Contact %'), (i+1).to_s) + ": " + _('The e-mail duplicates the e-mail of another record!')
|
||||
else
|
||||
else
|
||||
emails << contact.email
|
||||
end
|
||||
# Check if contact is valid
|
||||
|
@ -180,7 +183,7 @@ class ContactsController < ApplicationController
|
|||
["fname", "lname", "email"].each do |attr|
|
||||
attr_errors = contact.errors.on(attr)
|
||||
attr_errors = [attr_errors] unless attr_errors.nil? or attr_errors.is_a? Array
|
||||
|
||||
|
||||
if not attr_errors.nil?
|
||||
attr_errors.each do |msg|
|
||||
flash["errors"] << l(:contact_addmultiple_errorforcontact, (i+1).to_s) + ": " + l(msg)
|
||||
|
@ -189,10 +192,10 @@ class ContactsController < ApplicationController
|
|||
end
|
||||
end
|
||||
end # rescue
|
||||
|
||||
|
||||
@contacts << contact
|
||||
end # for
|
||||
|
||||
|
||||
# If there are validation errors - display them
|
||||
if not flash["errors"].nil? and not flash["errors"].empty?
|
||||
render :action => "import_preview"
|
||||
|
@ -214,49 +217,49 @@ class ContactsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def choose
|
||||
if params["mode"] == "groups"
|
||||
save_groups
|
||||
end
|
||||
|
||||
|
||||
@tos, @ccs, @bccs = Array.new, Array.new, Array.new
|
||||
|
||||
|
||||
params["contacts_to"].each{ |id,value| @tos << Contact.find(id) if value == "1" } if params["contacts_to"]
|
||||
params["contacts_cc"].each{ |id,value| @ccs << Contact.find(id) if value == "1" } if params["contacts_cc"]
|
||||
params["contacts_bcc"].each{ |id,value| @bccs << Contact.find(id) if value == "1" } if params["contacts_bcc"]
|
||||
|
||||
params["groups_to"].each{ |id,value|
|
||||
|
||||
params["groups_to"].each{ |id,value|
|
||||
ContactGroup.find(id).contacts.each {|c| @tos << c} if value == "1" } if params["groups_to"]
|
||||
params["groups_cc"].each{ |id,value|
|
||||
params["groups_cc"].each{ |id,value|
|
||||
ContactGroup.find(id).contacts.each {|c| @ccs << c} if value == "1" } if params["groups_cc"]
|
||||
params["groups_bcc"].each{ |id,value|
|
||||
params["groups_bcc"].each{ |id,value|
|
||||
ContactGroup.find(id).contacts.each {|c| @bccs << c} if value == "1" } if params["groups_bcc"]
|
||||
end
|
||||
|
||||
|
||||
def save_groups
|
||||
contacts_for_group = params["contacts_for_group"]
|
||||
group_id = params["group_id"]
|
||||
contact_group = ContactGroup.find(group_id)
|
||||
|
||||
|
||||
contacts_for_group.each { |contact_id,value|
|
||||
|
||||
|
||||
contacts_for_group.each { |contact_id,value|
|
||||
contact = Contact.find(contact_id)
|
||||
if value == "1" and not contact_group.contacts.include?(contact)
|
||||
contact_group.contacts << contact
|
||||
if value == "1" and not contact_group.contacts.include?(contact)
|
||||
contact_group.contacts << contact
|
||||
end
|
||||
if value == "0" and contact_group.contacts.include?(contact)
|
||||
contact_group.contacts.delete(contact)
|
||||
if value == "0" and contact_group.contacts.include?(contact)
|
||||
contact_group.contacts.delete(contact)
|
||||
end
|
||||
}
|
||||
redirect_to(:action=>"index", :id=>group_id, :params=>{"mode"=>params["mode"]})
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@contact = Contact.find(params["id"])
|
||||
# load related lists
|
||||
loadLists
|
||||
|
||||
|
||||
# groups = @contact.groups
|
||||
@groups = Hash.new
|
||||
@contactgroups.each {|g|
|
||||
|
@ -272,10 +275,10 @@ class ContactsController < ApplicationController
|
|||
else
|
||||
@groups[g.id] = 0 # unchecked
|
||||
end
|
||||
}
|
||||
}
|
||||
render :action => "new"
|
||||
end
|
||||
|
||||
|
||||
# Insert or update
|
||||
def create
|
||||
if params["contact"]["id"] == ""
|
||||
|
@ -286,14 +289,14 @@ class ContactsController < ApplicationController
|
|||
@contact = Contact.find(params["contact"]["id"])
|
||||
@contact.attributes = params["contact"]
|
||||
end
|
||||
|
||||
|
||||
@contactgroups = ContactGroup.find_by_user(logged_user)
|
||||
# Groups displayed
|
||||
groups = params['groups']
|
||||
tempGroups = Array.new
|
||||
tempGroups.concat(@contact.groups)
|
||||
|
||||
@contactgroups.each { |cgroup|
|
||||
|
||||
@contactgroups.each { |cgroup|
|
||||
includesCGroup = false
|
||||
tempGroups.each {|gr|
|
||||
if gr.contact_group_id.to_i == cgroup.id.to_i
|
||||
|
@ -304,7 +307,7 @@ class ContactsController < ApplicationController
|
|||
if groups["#{cgroup.id}"] == "1" and not includesCGroup
|
||||
@contact.groups << cgroup
|
||||
end
|
||||
|
||||
|
||||
if groups["#{cgroup.id}"] == "0" and includesCGroup
|
||||
@contact.groups.delete(cgroup)
|
||||
end
|
||||
|
@ -323,34 +326,34 @@ class ContactsController < ApplicationController
|
|||
@groups[g.id] = 1
|
||||
else
|
||||
@groups[g.id] = 0
|
||||
end
|
||||
end
|
||||
}
|
||||
render :action => :new
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def delete
|
||||
Contact.destroy(params['id'])
|
||||
redirect_to(:action=>'index')
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def secure_user?() true end
|
||||
def additional_scripts()
|
||||
def additional_scripts()
|
||||
add_s = ''
|
||||
if action_name == "choose"
|
||||
add_s<<'<script type="text/javascript" src="/javascripts/global.js"></script>'
|
||||
add_s<<'<script type="text/javascript" src="/javascripts/contact_choose.js"></script>'
|
||||
add_s<<'<script type="text/javascript" src="/javascripts/global.js"></script>'
|
||||
add_s<<'<script type="text/javascript" src="/javascripts/contact_choose.js"></script>'
|
||||
end
|
||||
add_s
|
||||
end
|
||||
|
||||
add_s
|
||||
end
|
||||
|
||||
def onload_function()
|
||||
if action_name == "choose"
|
||||
"javascript:respondToCaller();"
|
||||
"javascript:respondToCaller();"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
end
|
||||
private
|
||||
def select_layout
|
||||
|
@ -366,7 +369,7 @@ class ContactsController < ApplicationController
|
|||
'public'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def loadLists
|
||||
if @contactgroups.nil?
|
||||
@contactgroups = ContactGroup.find_by_user(logged_user)
|
||||
|
|
|
@ -6,6 +6,8 @@ class FoldersController < ApplicationController
|
|||
before_filter :load_imap_session
|
||||
after_filter :close_imap_session
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
layout 'public'
|
||||
|
||||
def index
|
||||
|
|
|
@ -3,6 +3,8 @@ require 'imapmailbox'
|
|||
|
||||
class LoginController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
if not(logged_user.nil?)
|
||||
redirect_to :controller =>"webmail", :action=>"index"
|
||||
|
|
|
@ -10,6 +10,8 @@ require 'imap_utils'
|
|||
class WebmailController < ApplicationController
|
||||
include ImapUtils
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
logger.info "*** WebmailController #{logger.inspect}"
|
||||
|
||||
# Administrative functions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue