form scratch
10
.gitignore
vendored
|
@ -1,7 +1,5 @@
|
|||
log
|
||||
.bundle
|
||||
db/*.sqlite3
|
||||
log/*.log
|
||||
tmp/
|
||||
config/database.yml
|
||||
.*.sw?
|
||||
config/site.rb
|
||||
tmp
|
||||
mail_temp
|
||||
.svn
|
||||
|
|
0
AUTHORS
Normal file → Executable file
6
Gemfile
|
@ -5,12 +5,12 @@ gem 'rails', '3.0.7'
|
|||
# Bundle edge Rails instead:
|
||||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||
|
||||
gem 'sqlite3-ruby',:require => 'sqlite3'
|
||||
#gem 'sqlite3-ruby',:require => 'sqlite3'
|
||||
gem 'arel'
|
||||
gem 'mysql2'
|
||||
gem 'mysql2' , '0.2.7'
|
||||
gem 'will_paginate'
|
||||
gem 'themes_for_rails'
|
||||
gem 'tmail'
|
||||
#gem 'tmail'
|
||||
|
||||
# Use unicorn as the web server
|
||||
# gem 'unicorn'
|
||||
|
|
25
Gemfile.lock
Executable file → Normal file
|
@ -27,20 +27,21 @@ GEM
|
|||
activemodel (= 3.0.7)
|
||||
activesupport (= 3.0.7)
|
||||
activesupport (3.0.7)
|
||||
arel (2.0.4)
|
||||
arel (2.0.10)
|
||||
builder (2.1.2)
|
||||
erubis (2.7.0)
|
||||
i18n (0.5.0)
|
||||
mail (2.2.18)
|
||||
mail (2.2.19)
|
||||
activesupport (>= 2.3.6)
|
||||
i18n (>= 0.4.0)
|
||||
mime-types (>= 1.16)
|
||||
treetop (>= 1.4.8)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
mime-types (1.16)
|
||||
mysql2 (0.2.7)
|
||||
polyglot (0.3.1)
|
||||
rack (1.2.2)
|
||||
rack-mount (0.7.3)
|
||||
rack (1.2.3)
|
||||
rack-mount (0.8.1)
|
||||
rack (>= 1.0.0)
|
||||
rack-test (0.5.7)
|
||||
rack (>= 1.0)
|
||||
rails (3.0.7)
|
||||
|
@ -56,18 +57,14 @@ GEM
|
|||
activesupport (= 3.0.7)
|
||||
rake (>= 0.8.7)
|
||||
thor (~> 0.14.4)
|
||||
rake (0.8.7)
|
||||
sqlite3 (1.3.3)
|
||||
sqlite3-ruby (1.3.3)
|
||||
sqlite3 (>= 1.3.3)
|
||||
rake (0.9.2)
|
||||
themes_for_rails (0.4.2)
|
||||
rails (~> 3.0.0)
|
||||
themes_for_rails
|
||||
thor (0.14.6)
|
||||
tmail (1.2.7.1)
|
||||
treetop (1.4.9)
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.24)
|
||||
tzinfo (0.3.29)
|
||||
will_paginate (2.3.15)
|
||||
|
||||
PLATFORMS
|
||||
|
@ -75,9 +72,7 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
arel
|
||||
mysql2
|
||||
mysql2 (= 0.2.7)
|
||||
rails (= 3.0.7)
|
||||
sqlite3-ruby
|
||||
themes_for_rails
|
||||
tmail
|
||||
will_paginate
|
||||
|
|
36
README.markdown
Normal file → Executable file
|
@ -1,8 +1,6 @@
|
|||
## Introduction
|
||||
_Mailr_ is a IMAP mail client based on _Ruby on Rails_ platform.
|
||||
|
||||
## Installation guide
|
||||
|
||||
**NOTE** All path and filenames are based on _Rails.root_ directory.
|
||||
|
||||
### Requirements
|
||||
|
@ -13,35 +11,17 @@ In _Rails 3_ all dependencies should be defined in file _Gemfile_. All needed ge
|
|||
|
||||
* Checkout the source code.
|
||||
|
||||
* If you need to override some of the default constants used in the application take a look at _config/default_site.rb_. Then create _config/site.rb_ that contains only the keys which you want to override. Example content of _config/site.rb_ is:
|
||||
|
||||
```ruby
|
||||
module CDF
|
||||
|
||||
LOCALCONFIG = {
|
||||
:imap_server => 'your.imap.server'
|
||||
}
|
||||
end
|
||||
```
|
||||
|
||||
* Configure SMTP settings
|
||||
|
||||
```ruby
|
||||
# initializers/smtp_settings.rb
|
||||
ActionMailer::Base.smtp_settings = {
|
||||
:address => "mail.example.com.py",
|
||||
:port => 26,
|
||||
:authentication => :plain,
|
||||
:enable_starttls_auto => true,
|
||||
:user_name => "emilio@example.com.py",
|
||||
:password => "yourpass"
|
||||
}
|
||||
```
|
||||
* Install all dependiences. Use _bundler_ for that.
|
||||
|
||||
* Prepare config/database.yml file (see _config/database.yml.example_).
|
||||
Check if proper gems (sqlite3/mysql/postgresql) are defined in _Gemfile_ and installed.
|
||||
Check if proper gems (sqlite3/mysql/postgresql) are defined in _Gemfile_ and installed.
|
||||
|
||||
* Migrate database (rake db:migrate)
|
||||
|
||||
* Use it.
|
||||
* Start rails server if applicable
|
||||
|
||||
* Point Your browser to application URL:
|
||||
For local access: http://localhost:3000
|
||||
For remote access: http://some_url/mailr
|
||||
|
||||
* Use it.
|
||||
|
|
0
Rakefile
Executable file → Normal file
0
UNLICENSE
Normal file → Executable file
195
app/controllers/application_controller.rb
Executable file → Normal file
|
@ -1,189 +1,24 @@
|
|||
# The filters added to this controller will be run for all controllers in the application.
|
||||
# Likewise will all the methods added be available for all controllers.
|
||||
require 'yaml'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
protect_from_forgery
|
||||
protect_from_forgery
|
||||
|
||||
before_filter :user_login_filter
|
||||
before_filter :add_scripts
|
||||
#before_filter :localize
|
||||
before_filter :load_defaults
|
||||
before_filter :set_locale
|
||||
|
||||
protected
|
||||
|
||||
#filter_parameter_logging :password #upgrade to Rails3
|
||||
def load_defaults
|
||||
@defaults = YAML::load(File.open(Rails.root.join('config','defaults.yml')))
|
||||
end
|
||||
|
||||
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
|
||||
def onload_function() "" end
|
||||
|
||||
private
|
||||
def add_scripts
|
||||
@additional_scripts = additional_scripts()
|
||||
@onload_function = onload_function()
|
||||
end
|
||||
|
||||
def user_login_filter
|
||||
if (secure_user? or secure_cust? )and logged_user.nil?
|
||||
|
||||
#upgrade Rails 3
|
||||
#session["return_to"] = request.request_uri
|
||||
logger.debug "*** return_to => #{request.fullpath}"
|
||||
session["return_to"] = request.fullpath
|
||||
|
||||
redirect_to :controller=>"/login", :action => "index"
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
alias login_required user_login_filter
|
||||
|
||||
def logged_user # returns customer id
|
||||
session['user']
|
||||
end
|
||||
|
||||
def logged_customer
|
||||
session['user']
|
||||
end
|
||||
|
||||
def localize
|
||||
# We will use instance vars for the locale so we can make use of them in
|
||||
# the templates.
|
||||
@charset = 'utf-8'
|
||||
headers['Content-Type'] = "text/html; charset=#{@charset}"
|
||||
# Here is a very simplified approach to extract the prefered language
|
||||
# from the request. If all fails, just use 'en_EN' as the default.
|
||||
temp = if request.env['HTTP_ACCEPT_LANGUAGE'].nil?
|
||||
[]
|
||||
else
|
||||
request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.split('-') rescue []
|
||||
end
|
||||
language = temp.slice(0)
|
||||
dialect = temp.slice(1)
|
||||
@language = language.nil? ? 'en' : language.downcase # default is en
|
||||
# If there is no dialect use the language code ('en' becomes 'en_EN').
|
||||
@dialect = dialect.nil? ? @language.upcase : dialect
|
||||
# The complete locale string consists of
|
||||
# language_DIALECT (en_EN, en_GB, de_DE, ...)
|
||||
@locale = "#{@language}_#{@dialect.upcase}"
|
||||
@htmllang = @language == @dialect ? @language : "#{@language}-#{@dialect}"
|
||||
# Finally, bind the textdomain to the locale. From now on every used
|
||||
# _('String') will get translated into the right language. (Provided
|
||||
# that we have a corresponding mo file in the right place).
|
||||
bindtextdomain('messages', "#{RAILS_ROOT}/locale", @locale, @charset)
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
def include_tinymce(mode="textareas",elements="")
|
||||
tinymce=''
|
||||
tinymce << '
|
||||
<script language="javascript" type="text/javascript" src="/tiny_mce/tiny_mce.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
tinyMCE.init({
|
||||
mode : "'
|
||||
tinymce << mode << '",'
|
||||
if mode == "exact"
|
||||
tinymce << 'elements : "' << elements << '",
|
||||
'
|
||||
end
|
||||
tinymce << '
|
||||
theme : "advanced",
|
||||
cleanup : true,
|
||||
width: "100%",
|
||||
remove_linebreaks : false,
|
||||
entity_encoding : "named",
|
||||
relative_urls : false,
|
||||
plugins : "table,save,advhr,advimage,advlink,iespell,preview,zoom,searchreplace,print,contextmenu,fullscreen,linkattach",
|
||||
theme_advanced_buttons1_add : "fontselect,fontsizeselect",
|
||||
theme_advanced_buttons2_add : "separator,preview,zoom",
|
||||
theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
|
||||
theme_advanced_buttons3_add_before : "tablecontrols,separator",
|
||||
theme_advanced_buttons3_add : "iespell,forecolor,backcolor,fullscreen",
|
||||
theme_advanced_source_editor_width : "700",
|
||||
theme_advanced_source_editor_height : "500",
|
||||
theme_advanced_styles : "Header 1=header1",
|
||||
theme_advanced_toolbar_location : "top",
|
||||
theme_advanced_toolbar_align : "left",
|
||||
theme_advanced_path_location : "none",
|
||||
extended_valid_elements : ""
|
||||
+"a[accesskey|charset|class|coords|href|hreflang|id|lang|name"
|
||||
+"|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup"
|
||||
+"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rel|rev"
|
||||
+"|shape|style|tabindex|title|target|type],"
|
||||
+"dd[class|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
|
||||
+"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],"
|
||||
+"div[align|class|id|lang|onclick"
|
||||
+"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
|
||||
+"|onmouseout|onmouseover|onmouseup|style|title],"
|
||||
+"dl[class|compact|id|lang|onclick|ondblclick|onkeydown"
|
||||
+"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
|
||||
+"|onmouseup|style|title],"
|
||||
+"dt[class|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
|
||||
+"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],"
|
||||
+"img[align|alt|border|class|height"
|
||||
+"|hspace|id|ismap|lang|longdesc|name|onclick|ondblclick|onkeydown"
|
||||
+"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
|
||||
+"|onmouseup|src|style|title|usemap|vspace|width],"
|
||||
+"script[charset|defer|language|src|type],"
|
||||
+"style[lang|media|title|type],"
|
||||
+"table[align|bgcolor|border|cellpadding|cellspacing|class"
|
||||
+"|frame|height|id|lang|onclick|ondblclick|onkeydown|onkeypress"
|
||||
+"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rules"
|
||||
+"|style|summary|title|width],"
|
||||
+"td[abbr|align|axis|bgcolor|char|charoff|class"
|
||||
+"|colspan|headers|height|id|lang|nowrap|onclick"
|
||||
+"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
|
||||
+"|onmouseout|onmouseover|onmouseup|rowspan|scope"
|
||||
+"|style|title|valign|width],"
|
||||
+"hr[align|class|id|lang|noshade|onclick"
|
||||
+"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
|
||||
+"|onmouseout|onmouseover|onmouseup|size|style|title|width],"
|
||||
+"font[class|color|face|id|lang|size|style|title],"
|
||||
+"span[align|class|class|id|lang|onclick|ondblclick|onkeydown"
|
||||
+"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
|
||||
+"|onmouseup|style|title]",
|
||||
external_link_list_url : "/cms/urlchoose/choose_tinymce",
|
||||
external_attachments_list_url : "/attachments/attachments/choose_tinymce",
|
||||
external_image_list_url : "/gallery/imgchoose/choose_tinymce",
|
||||
flash_external_list_url : "example_data/example_flash_list.js"
|
||||
});
|
||||
</script>'
|
||||
tinymce
|
||||
end
|
||||
|
||||
helper_method :include_tinymce
|
||||
|
||||
def include_simple_tinymce(mode="textareas",elements="")
|
||||
tinymce = ''
|
||||
tinymce << '<script language="javascript" type="text/javascript" src="/tiny_mce/tiny_mce.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
tinyMCE.init({
|
||||
mode : "'
|
||||
tinymce << mode << '",'
|
||||
if mode == "exact"
|
||||
tinymce << 'elements : "' << elements << '",
|
||||
'
|
||||
end
|
||||
tinymce << '
|
||||
theme : "default",
|
||||
width : "100%",
|
||||
auto_reset_designmode : true
|
||||
});
|
||||
</script>'
|
||||
tinymce
|
||||
end
|
||||
|
||||
def _(text)
|
||||
t text
|
||||
end
|
||||
|
||||
helper_method :include_simple_tinymce, :_
|
||||
def theme_resolver
|
||||
@defaults['theme']
|
||||
end
|
||||
|
||||
def set_locale
|
||||
I18n.locale = @defaults['locale'] || I18n.default_locale
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
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"] == ""
|
||||
# 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
|
|
@ -1,378 +0,0 @@
|
|||
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],
|
||||
:per_page => CDF::CONFIG[:contacts_per_page]
|
||||
else
|
||||
@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]],
|
||||
: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
|
||||
@contacts_for_group = Hash.new
|
||||
for contact in @contacts
|
||||
@contacts_for_group[contact.id] = 0 # initialize
|
||||
for gr in contact.groups
|
||||
if gr.contact_group_id.to_i == @group_id
|
||||
@contacts_for_group[contact.id] = 1 # checked
|
||||
end
|
||||
end
|
||||
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
|
||||
@contactgroups.each {|g|
|
||||
@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']
|
||||
session["return_to"] = url_for(:controller=>'/webmail/webmail',
|
||||
:action=>'folders',
|
||||
:msg_id=>retmsg)
|
||||
# parse string
|
||||
if i = cstr.index("<")
|
||||
name, email = cstr.slice(0, i), cstr.slice((i+1)..(cstr.strip().index(">")-1))
|
||||
fname = name.split().first
|
||||
lname = name.split().last if name.split().size() > 1
|
||||
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|
|
||||
groupSelected = false
|
||||
@contact.groups.each {|gr|
|
||||
if gr.contact_group_id.to_i == g.id.to_i
|
||||
groupSelected = true
|
||||
break
|
||||
end
|
||||
}
|
||||
if groupSelected
|
||||
@groups[g.id] = 1 # checked
|
||||
else
|
||||
@groups[g.id] = 0 # unchecked
|
||||
end
|
||||
}
|
||||
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
|
||||
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|
|
||||
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
|
||||
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
|
||||
emails << contact.email
|
||||
end
|
||||
# Check if contact is valid
|
||||
contact.valid?
|
||||
rescue CDF::ValidationError => e
|
||||
if not contact.errors.empty?
|
||||
["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)
|
||||
end
|
||||
end
|
||||
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"
|
||||
else
|
||||
# save
|
||||
begin
|
||||
for contact in @contacts
|
||||
Contact.create(contact.attributes)
|
||||
end
|
||||
# Set message for successful import
|
||||
flash["alert"] = Array.new
|
||||
flash["alert"] << l(:contact_addmultiple_success, @contacts.length.to_s)
|
||||
keep_flash()
|
||||
redirect_to(:action=>"list")
|
||||
rescue Exception => exc
|
||||
flash["errors"] << exc
|
||||
render :action => "import_preview"
|
||||
end
|
||||
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|
|
||||
ContactGroup.find(id).contacts.each {|c| @tos << c} if value == "1" } if params["groups_to"]
|
||||
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|
|
||||
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|
|
||||
contact = Contact.find(contact_id)
|
||||
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)
|
||||
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|
|
||||
groupSelected = false
|
||||
@contact.groups.each {|gr|
|
||||
if gr.contact_group_id.to_i == g.id.to_i
|
||||
groupSelected = true
|
||||
break
|
||||
end
|
||||
}
|
||||
if groupSelected
|
||||
@groups[g.id] = 1 # checked
|
||||
else
|
||||
@groups[g.id] = 0 # unchecked
|
||||
end
|
||||
}
|
||||
render :action => "new"
|
||||
end
|
||||
|
||||
# Insert or update
|
||||
def create
|
||||
if params["contact"]["id"] == ""
|
||||
# New contact
|
||||
@contact = Contact.create(params["contact"])
|
||||
else
|
||||
# Edit existing
|
||||
@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|
|
||||
includesCGroup = false
|
||||
tempGroups.each {|gr|
|
||||
if gr.contact_group_id.to_i == cgroup.id.to_i
|
||||
includesCGroup = true
|
||||
break
|
||||
end
|
||||
}
|
||||
if groups["#{cgroup.id}"] == "1" and not includesCGroup
|
||||
@contact.groups << cgroup
|
||||
end
|
||||
|
||||
if groups["#{cgroup.id}"] == "0" and includesCGroup
|
||||
@contact.groups.delete(cgroup)
|
||||
end
|
||||
}
|
||||
if @contact.save
|
||||
if params["paction"] == t(:save)
|
||||
redirect_to :action =>:index
|
||||
else
|
||||
redirect_to :action => :new
|
||||
end
|
||||
else
|
||||
loadLists
|
||||
@groups = Hash.new
|
||||
@contactgroups.each {|g|
|
||||
if @contact.groups.include?(g)
|
||||
@groups[g.id] = 1
|
||||
else
|
||||
@groups[g.id] = 0
|
||||
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()
|
||||
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>'
|
||||
end
|
||||
add_s
|
||||
end
|
||||
|
||||
def onload_function()
|
||||
if action_name == "choose"
|
||||
"javascript:respondToCaller();"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
private
|
||||
def select_layout
|
||||
if params["mode"] == "choose"
|
||||
@mode = "choose"
|
||||
@contactgroups = ContactGroup.find_by_user(logged_user)
|
||||
'chooser'
|
||||
elsif params["mode"] == "groups"
|
||||
@mode = "groups"
|
||||
'public'
|
||||
else
|
||||
@mode = "normal"
|
||||
'public'
|
||||
end
|
||||
end
|
||||
|
||||
def loadLists
|
||||
if @contactgroups.nil?
|
||||
@contactgroups = ContactGroup.find_by_user(logged_user)
|
||||
end
|
||||
end
|
||||
end
|
18
app/controllers/core_controller.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
class CoreController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
layout "simple"
|
||||
|
||||
def login
|
||||
end
|
||||
|
||||
def logout
|
||||
reset_session
|
||||
flash[:notice] = t(:user_logged_out)
|
||||
redirect_to :action => "login"
|
||||
end
|
||||
|
||||
def authenticate
|
||||
end
|
||||
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
require 'ezcrypto'
|
||||
class FoldersController < ApplicationController
|
||||
include ImapUtils
|
||||
|
||||
before_filter :login_required
|
||||
before_filter :load_imap_session
|
||||
after_filter :close_imap_session
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
layout 'public'
|
||||
|
||||
def index
|
||||
@folders = @mailbox.folders
|
||||
end
|
||||
|
||||
def create
|
||||
@mailbox.create_folder(CDF::CONFIG[:mail_inbox] + '.' + params[:folder])
|
||||
redirect_to folders_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@mailbox.delete_folder params[:id]
|
||||
redirect_to folders_path
|
||||
end
|
||||
end
|
|
@ -1,73 +0,0 @@
|
|||
require 'ezcrypto'
|
||||
require 'imapmailbox'
|
||||
|
||||
class LoginController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
if not(logged_user.nil?)
|
||||
redirect_to :controller =>"webmail", :action=>"index"
|
||||
else
|
||||
@login_user = Customer.new
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate
|
||||
if user = auth(params['login_user']["email"], params['login_user']["password"])
|
||||
session["user"] = user.id
|
||||
if CDF::CONFIG[:crypt_session_pass]
|
||||
session["wmp"] = EzCrypto::Key.encrypt_with_password(CDF::CONFIG[:encryption_password], CDF::CONFIG[:encryption_salt], params['login_user']["password"])
|
||||
else
|
||||
# dont use crypt
|
||||
session["wmp"] = params['login_user']["password"]
|
||||
end
|
||||
if session["return_to"]
|
||||
redirect_to(session["return_to"])
|
||||
session["return_to"] = nil
|
||||
else
|
||||
redirect_to :action=>"index"
|
||||
end
|
||||
else
|
||||
logger.debug "*** Not logged"
|
||||
@login_user = Customer.new
|
||||
flash["error"] = t :wrong_email_or_password
|
||||
redirect_to :action => "index"
|
||||
end
|
||||
end
|
||||
|
||||
def logout
|
||||
reset_session
|
||||
flash["status"] = t(:user_logged_out)
|
||||
redirect_to :action => "index"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def need_subdomain?() true end
|
||||
def secure_user?() false end
|
||||
|
||||
private
|
||||
|
||||
def auth(email, password)
|
||||
mailbox = IMAPMailbox.new(Rails.logger)
|
||||
logger.info "*** mailbox #{mailbox.inspect}"
|
||||
begin
|
||||
mailbox.connect(email, password)
|
||||
rescue Exception => exc
|
||||
logger.debug "*** auth/Mailbox Object => #{exc.message}"
|
||||
return nil
|
||||
end
|
||||
|
||||
mailbox.disconnect
|
||||
mailbox = nil
|
||||
if user = Customer.find_by_email(email)
|
||||
return user
|
||||
else
|
||||
# create record in database
|
||||
user = Customer.create("email"=>email)
|
||||
MailPref.create('customer_id' => user.id)
|
||||
return user
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,424 +0,0 @@
|
|||
require 'cdfmail'
|
||||
require 'net/smtp'
|
||||
require 'net/imap'
|
||||
require 'mail2screen'
|
||||
require 'ezcrypto'
|
||||
require 'imapmailbox'
|
||||
require 'imap_utils'
|
||||
|
||||
|
||||
class WebmailController < ApplicationController
|
||||
include ImapUtils
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
logger.info "*** WebmailController #{logger.inspect}"
|
||||
|
||||
# Administrative functions
|
||||
before_filter :login_required
|
||||
before_filter :obtain_cookies_for_search_and_nav, :only=>[:messages]
|
||||
before_filter :load_imap_session
|
||||
after_filter :close_imap_session
|
||||
|
||||
layout "public", :except => [:view_source, :download]
|
||||
|
||||
# model :filter, :expression, :mail_pref, :customer
|
||||
|
||||
BOOL_ON = "on"
|
||||
|
||||
def index
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
|
||||
def error_connection
|
||||
end
|
||||
|
||||
def refresh
|
||||
@mailbox.reload
|
||||
@folders = @mailbox.folders
|
||||
redirect_to(:action=>'messages')
|
||||
end
|
||||
|
||||
def messages
|
||||
session["return_to"] = nil
|
||||
@search_field = params['search_field']
|
||||
@search_value = params['search_value']
|
||||
|
||||
# handle sorting - tsort session field contains last reverse or no for field
|
||||
# and lsort - last sort field
|
||||
if session['tsort'].nil? or session['lsort'].nil?
|
||||
session['lsort'] = "DATE"
|
||||
session['tsort'] = {"DATE" => true, "FROM" => true, "SUBJECT" => true, "TO" => false}
|
||||
end
|
||||
|
||||
case operation_param
|
||||
when t(:copy) # copy
|
||||
msg_ids = []
|
||||
messages_param.each { |msg_id, bool|
|
||||
msg_ids << msg_id.to_i if bool == BOOL_ON and dst_folder != @folder_name } if messages_param
|
||||
folder.copy_multiple(msg_ids, dst_folder) if msg_ids.size > 0
|
||||
when t(:move) # move
|
||||
msg_ids = []
|
||||
messages_param.each { |msg_id, bool|
|
||||
msg_ids << msg_id.to_i if bool == BOOL_ON and dst_folder != @folder_name } if messages_param
|
||||
folder.move_multiple(msg_ids, dst_folder) if msg_ids.size > 0
|
||||
when t(:delete) # delete
|
||||
msg_ids = []
|
||||
messages_param.each { |msg_id, bool| msg_ids << msg_id.to_i if bool == BOOL_ON } if messages_param
|
||||
folder.delete_multiple(msg_ids) if msg_ids.size > 0
|
||||
when t(:mark_read) # mark as read
|
||||
messages_param.each { |msg_id, bool| msg = folder.mark_read(msg_id.to_i) if bool == BOOL_ON } if messages_param
|
||||
when t(:mark_unread) # mark as unread
|
||||
messages_param.each { |msg_id, bool| msg = folder.mark_unread(msg_id.to_i) if bool == BOOL_ON } if messages_param
|
||||
when "SORT"
|
||||
session['lsort'] = sort_query = params["scc"]
|
||||
session['tsort'][sort_query] = (session['tsort'][sort_query]? false : true)
|
||||
@search_field, @search_value = session['search_field'], session['search_value']
|
||||
when t(:search) # search
|
||||
session['search_field'] = @search_field
|
||||
session['search_value'] = @search_value
|
||||
when t(:show_all) # search
|
||||
session['search_field'] = @search_field = nil
|
||||
session['search_value'] = @search_value = nil
|
||||
else
|
||||
# get search criteria from session
|
||||
@search_field = session['search_field']
|
||||
@search_value = session['search_value']
|
||||
end
|
||||
|
||||
sort_query = session['lsort']
|
||||
reverse_sort = session['tsort'][sort_query]
|
||||
query = ["ALL"]
|
||||
@page = params["page"]
|
||||
@page ||= session['page']
|
||||
session['page'] = @page
|
||||
if @search_field and @search_value and not(@search_field.strip() == "") and not(@search_value.strip() == "")
|
||||
@pages = Paginator.new self, 0, get_mail_prefs.wm_rows, @page
|
||||
@messages = folder.messages_search([@search_field, @search_value], sort_query + (reverse_sort ? ' desc' : ' asc'))
|
||||
else
|
||||
@pages = Paginator.new self, folder.total, get_mail_prefs.wm_rows, @page
|
||||
@messages = folder.messages(@pages.current.first_item - 1, get_mail_prefs.wm_rows, sort_query + (reverse_sort ? ' desc' : ' asc'))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def delete
|
||||
@msg_id = msg_id_param.to_i
|
||||
folder.delete(@msg_id)
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
|
||||
def reply # not ready at all
|
||||
@msg_id = msg_id_param.to_i
|
||||
@imapmail = folder.message(@msg_id)
|
||||
fb = @imapmail.full_body
|
||||
@tmail = TMail::Mail.parse(fb)
|
||||
|
||||
@mail = prepare_mail
|
||||
@mail.reply(@tmail, fb, get_mail_prefs.mail_type)
|
||||
|
||||
render :action => 'compose'
|
||||
end
|
||||
|
||||
def forward
|
||||
@msg_id = msg_id_param.to_i
|
||||
@imapmail = folder.message(@msg_id)
|
||||
fb = @imapmail.full_body
|
||||
@tmail = TMail::Mail.parse(fb)
|
||||
|
||||
@mail = prepare_mail
|
||||
@mail.forward(@tmail, fb)
|
||||
|
||||
render :action => 'compose'
|
||||
end
|
||||
|
||||
def compose
|
||||
if @mail.nil?
|
||||
operation = operation_param
|
||||
if operation == t(:send)
|
||||
@mail = create_mail
|
||||
encmail = @mail.send_mail
|
||||
get_imap_session
|
||||
@mailbox.message_sent(encmail)
|
||||
|
||||
# delete temporary files (attachments)
|
||||
@mail.delete_attachments()
|
||||
render :action => :mailsent
|
||||
elsif operation == t(:add)
|
||||
@mail = create_mail
|
||||
if params['attachment']
|
||||
attachment = CDF::Attachment.new(@mail)
|
||||
attachment.file = params['attachment']
|
||||
end
|
||||
else
|
||||
# default - new email create
|
||||
@mail = create_mail
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def empty # empty trash folder (works for any one else :-))
|
||||
folder.messages(0, -1).each{ |message|
|
||||
folder.delete(message)
|
||||
}
|
||||
folder.expunge
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
|
||||
def message
|
||||
@msg_id = msg_id_param
|
||||
@imapmail = folder.message(@msg_id)
|
||||
folder.mark_read(@imapmail.uid) if @imapmail.unread
|
||||
@mail = TMail::Mail.parse(@imapmail.full_body)
|
||||
end
|
||||
|
||||
def download
|
||||
msg_id = msg_id_param
|
||||
imapmail = folder.message(msg_id)
|
||||
mail = TMail::Mail.parse(imapmail.full_body)
|
||||
|
||||
if mail.multipart?
|
||||
get_parts(mail).each { |part|
|
||||
return send_part(part) if part.header and part.header['content-type']['name'] == params['ctype']
|
||||
}
|
||||
render("webmail/noattachment")
|
||||
else
|
||||
render("webmail/noattachment")
|
||||
end
|
||||
end
|
||||
|
||||
def prefs
|
||||
@customer = Customer.find(logged_customer)
|
||||
@mailpref = MailPref.find_or_create_by_customer_id logged_customer
|
||||
|
||||
if params['op'] == _('Save')
|
||||
if params['customer']
|
||||
@customer.fname = params['customer']['fname']
|
||||
@customer.lname = params['customer']['lname']
|
||||
@customer.save
|
||||
end
|
||||
@mailpref.attributes = params["mailpref"]
|
||||
@mailpref.save
|
||||
session["wmimapseskey"] = nil
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
end
|
||||
|
||||
# Message filters management
|
||||
def filters
|
||||
end
|
||||
|
||||
def filter
|
||||
if params['op']
|
||||
@filter = Filter.new(params['filter'])
|
||||
@filter.customer_id = logged_customer
|
||||
params['expression'].each { |index, expr| @filter.expressions << Expression.new(expr) unless expr["expr_value"].nil? or expr["expr_value"].strip == "" }
|
||||
case params['op']
|
||||
when _('Add')
|
||||
@filter.expressions << Expression.new
|
||||
when _('Save')
|
||||
if params['filter']['id'] and params['filter']['id'] != ""
|
||||
@sf = Filter.find(params['filter']['id'])
|
||||
@sf.name, @sf.destination_folder = @filter.name, @filter.destination_folder
|
||||
@sf.expressions.each{|expr| Expression.delete(expr.id) }
|
||||
@filter.expressions.each {|expr| @sf.expressions << Expression.create(expr.attributes) }
|
||||
else
|
||||
@sf = Filter.create(@filter.attributes)
|
||||
@sf.order_num = @user.filters.size
|
||||
@filter.expressions.each {|expr| @sf.expressions << Expression.create(expr.attributes) }
|
||||
end
|
||||
# may be some validation will be needed
|
||||
@sf.save
|
||||
@user.serialize_to_file
|
||||
return redirect_to(:action=>"filters")
|
||||
end
|
||||
@expressions = @filter.expressions
|
||||
else
|
||||
@filter = Filter.find(params["id"]) if params["id"]
|
||||
@expressions = @filter.expressions
|
||||
end
|
||||
@destfolders = get_to_folders
|
||||
end
|
||||
|
||||
def filter_delete
|
||||
Filter.delete(params["id"])
|
||||
# reindex other filters
|
||||
@user = Customer.find(logged_customer)
|
||||
findex = 0
|
||||
@user.filters.each { |filter|
|
||||
findex = findex + 1
|
||||
filter.order_num = findex
|
||||
filter.save
|
||||
}
|
||||
@user.serialize_to_file
|
||||
redirect_to :action=>"filters"
|
||||
end
|
||||
|
||||
def filter_up
|
||||
filt = @user.filters.find(params['id'])
|
||||
ufilt = @user.filters.find_all("order_num = #{filt.order_num - 1}").first
|
||||
ufilt.order_num = ufilt.order_num + 1
|
||||
filt.order_num = filt.order_num - 1
|
||||
ufilt.save
|
||||
filt.save
|
||||
@user.serialize_to_file
|
||||
redirect_to :action=>"filters"
|
||||
end
|
||||
|
||||
def filter_down
|
||||
filt = Filter.find(params["id"])
|
||||
dfilt = @user.filters[filt.order_num]
|
||||
dfilt.order_num = dfilt.order_num - 1
|
||||
filt.order_num = filt.order_num + 1
|
||||
dfilt.save
|
||||
filt.save
|
||||
@user.serialize_to_file
|
||||
redirect_to :action=>"filters"
|
||||
end
|
||||
|
||||
def filter_add
|
||||
@filter = Filter.new
|
||||
@filter.expressions << Expression.new
|
||||
@expressions = @filter.expressions
|
||||
@destfolders = get_to_folders
|
||||
render "filter"
|
||||
end
|
||||
# end of filters
|
||||
|
||||
def view_source
|
||||
@msg_id = msg_id_param.to_i
|
||||
@imapmail = folder.message(@msg_id)
|
||||
@msg_source = CGI.escapeHTML(@imapmail.full_body).gsub("\n", "<br/>")
|
||||
end
|
||||
|
||||
def auto_complete_for_mail_to
|
||||
auto_complete_responder_for_contacts params[:mail][:to]
|
||||
end
|
||||
|
||||
def auto_complete_for_mail_cc
|
||||
auto_complete_responder_for_contacts params[:mail][:cc]
|
||||
end
|
||||
|
||||
def auto_complete_for_mail_bcc
|
||||
auto_complete_responder_for_contacts params[:mail][:bcc]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def auto_complete_responder_for_contacts(value)
|
||||
# first split by "," and take last name
|
||||
searchName = value.split(',').last.strip
|
||||
|
||||
# if there are 2 names search by them
|
||||
if searchName.split.size > 1
|
||||
fname, lname = searchName.split.first, searchName.split.last
|
||||
conditions = ['customer_id = ? and LOWER(fname) LIKE ? and LOWER(lname) like ?', logged_customer, fname.downcase + '%', lname.downcase + '%']
|
||||
else
|
||||
conditions = ['customer_id = ? and LOWER(fname) LIKE ?', logged_customer, searchName.downcase + '%']
|
||||
end
|
||||
@contacts = Contact.find(:all, :conditions => conditions, :order => 'fname ASC',:limit => 8)
|
||||
render :partial => 'contacts'
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def additional_scripts()
|
||||
@additional_css = ["webmail/webmail"]
|
||||
@additional_js = ["webmail"]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_to_folders
|
||||
res = Array.new
|
||||
@folders.each{|f| res << f unless f.name == CDF::CONFIG[:mail_sent] or f.name == CDF::CONFIG[:mail_inbox] }
|
||||
res
|
||||
end
|
||||
|
||||
|
||||
def create_mail
|
||||
m = CDF::Mail.new(user.mail_temporary_path)
|
||||
if params["mail"]
|
||||
ma = params["mail"]
|
||||
m.body, m.content_type, m.from, m.to, m.cc, m.bcc, m.subject = ma["body"], ma["content_type"], ma["from"], ma["to"], ma["cc"], ma["bcc"], ma["subject"]
|
||||
if params["att_files"]
|
||||
att_files, att_tfiles, att_ctypes = params["att_files"], params["att_tfiles"], params["att_ctypes"]
|
||||
att_files.each {|i, value|
|
||||
att = CDF::Attachment.new(m)
|
||||
att.filename, att.temp_filename, att.content_type = value, att_tfiles[i], att_ctypes[i]
|
||||
}
|
||||
end
|
||||
else
|
||||
m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type
|
||||
end
|
||||
m.customer_id = logged_customer
|
||||
m
|
||||
end
|
||||
|
||||
def prepare_mail
|
||||
m = CDF::Mail.new(user.mail_temporary_path)
|
||||
m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type
|
||||
m
|
||||
end
|
||||
|
||||
|
||||
def send_part(part)
|
||||
if part.content_type == "text/html"
|
||||
disposition = "inline"
|
||||
elsif part.content_type.include?("image/")
|
||||
disposition = "inline"
|
||||
else
|
||||
disposition = "attachment"
|
||||
end
|
||||
headers['Content-Length'] = part.body.size
|
||||
response.headers['Accept-Ranges'] = 'bytes'
|
||||
headers['Content-type'] = part.content_type.strip
|
||||
headers['Content-Disposition'] = disposition << %(; filename="#{part.header['content-type']['name']}")
|
||||
render :text => part.body
|
||||
end
|
||||
|
||||
def get_parts(mail)
|
||||
parts = Array.new
|
||||
parts << mail
|
||||
mail.parts.each { |part|
|
||||
if part.multipart?
|
||||
parts = parts.concat(get_parts(part))
|
||||
elsif part.content_type and part.content_type.include?("rfc822")
|
||||
parts = parts.concat(get_parts(TMail::Mail.parse(part.body))) << part
|
||||
else
|
||||
parts << part
|
||||
end
|
||||
}
|
||||
parts
|
||||
end
|
||||
|
||||
def obtain_cookies_for_search_and_nav
|
||||
@srch_class = ((cookies['_wmlms'] and cookies['_wmlms'] == 'closed') ? 'closed' : 'open')
|
||||
@srch_img_src = ((cookies['_wmlms'] and cookies['_wmlms'] == 'closed') ? 'closed' : 'opened')
|
||||
@ops_class = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'open')
|
||||
@ops_img_src = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'opened')
|
||||
end
|
||||
|
||||
###################################################################
|
||||
### Some fixed parameters and session variables
|
||||
###################################################################
|
||||
def folder
|
||||
@folders[@folder_name]
|
||||
end
|
||||
|
||||
def msg_id_param
|
||||
params["msg_id"]
|
||||
end
|
||||
|
||||
def messages_param
|
||||
params["messages"]
|
||||
end
|
||||
|
||||
def dst_folder
|
||||
params["cpdest"]
|
||||
end
|
||||
|
||||
def operation_param
|
||||
params["op"]
|
||||
end
|
||||
end
|
136
app/helpers/application_helper.rb
Executable file → Normal file
|
@ -1,138 +1,2 @@
|
|||
# The methods added to this helper will be available to all templates in the application.
|
||||
module ApplicationHelper
|
||||
include NavigationHelper
|
||||
|
||||
protected
|
||||
|
||||
def format_datetime(datetime)
|
||||
datetime.strftime "%d.%m.%Y %H:%M"
|
||||
end
|
||||
|
||||
def errors_base(form_name)
|
||||
errors = instance_variable_get("@#{form_name}").errors.on_base()
|
||||
errors_out = ""
|
||||
if errors
|
||||
errors = [errors] unless errors.is_a? Array
|
||||
errors.each do |e|
|
||||
errors_out << "<span class=\"error\">#{e}</span>"
|
||||
end
|
||||
end
|
||||
errors_out
|
||||
end
|
||||
|
||||
# Useful abstraction for form input fields - combines an input field with error message (if any)
|
||||
# and writes an appropriate style (for errors)
|
||||
# Usage:
|
||||
# form_input :text_field, 'postform', 'subject'
|
||||
# form_input :text_area, 'postform', 'text', 'Please enter text:', 'cols' => 80
|
||||
# form_input :hidden_field, 'postform', 'topic_id'
|
||||
def form_input(helper_method, form_name, field_name, prompt = field_name.capitalize, options = {})
|
||||
case helper_method.to_s
|
||||
when 'hidden_field'
|
||||
self.hidden_field(form_name, field_name)
|
||||
when /^.*button$/
|
||||
<<-EOL
|
||||
<tr><td class="button" colspan="2">
|
||||
#{self.send(helper_method, form_name, prompt, options)}
|
||||
</td></tr>
|
||||
EOL
|
||||
else
|
||||
field = (
|
||||
if :select == helper_method
|
||||
self.send(helper_method, form_name, field_name, options.delete('values'), options)
|
||||
elsif :collection_select == helper_method
|
||||
self.send(helper_method, form_name, field_name, options.delete('collection'), options.delete('value_method'), options.delete('text_method'), options)
|
||||
else
|
||||
self.send(helper_method, form_name, field_name, options)
|
||||
end)
|
||||
errors = instance_variable_get("@#{form_name}").errors[field_name] unless instance_variable_get("@#{form_name}").nil?
|
||||
errors = Array.new if errors.nil?
|
||||
errors_out = ""
|
||||
if errors
|
||||
errors = [errors] unless errors.is_a? Array
|
||||
errors.each do |e|
|
||||
errors_out << "<span class=\"error\">#{e}</span>"
|
||||
end
|
||||
end
|
||||
if options['class'] == 'two_columns'
|
||||
<<-EOL
|
||||
<tr class="two_columns">
|
||||
<td class="prompt"><label>#{prompt}:</label></td>
|
||||
<td class="value">#{field}#{errors_out}</td>
|
||||
</tr>
|
||||
EOL
|
||||
else
|
||||
<<-EOL
|
||||
<tr><td class="prompt"><strong>#{prompt}:</strong></td></tr>
|
||||
<tr><td class="value">#{field}#{errors_out}</td></tr>
|
||||
EOL
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Helper method that has the same signature as real input field helpers, but simply displays
|
||||
# the value of a given field enclosed within <p> </p> tags.
|
||||
# Usage:
|
||||
# <%= form_input :read_only_field, 'new_user', 'name', _('user_name')) %>
|
||||
def read_only_field(form_name, field_name, html_options)
|
||||
"<span #{attributes(html_options)}>#{instance_variable_get('@' + form_name)[field_name]}</span>"
|
||||
end
|
||||
|
||||
def submit_button(form_name, prompt, html_options)
|
||||
%{<input name="submit" type="submit" value="#{prompt}" />}
|
||||
end
|
||||
|
||||
# Converts a hash to XML attributes string. E.g.:
|
||||
# to_attributes('a' => 'aaa', 'b' => 1)
|
||||
# => 'a="aaa" b="1" '
|
||||
def attributes(hash)
|
||||
hash.keys.inject("") { |attrs, key| attrs + %{#{key}="#{hash[key]}" } }
|
||||
end
|
||||
|
||||
def initListClass
|
||||
@itClass = 1
|
||||
end
|
||||
|
||||
def popListClass
|
||||
ret = getListClass
|
||||
@itClass = @itClass + 1
|
||||
return ret
|
||||
end
|
||||
|
||||
def getListClass
|
||||
return "even" if @itClass%2 == 0
|
||||
return "odd" if @itClass%2 == 1
|
||||
end
|
||||
|
||||
def get_meta_info
|
||||
'<meta name="rating" content="General">'
|
||||
'<meta name="robots" content="Index, ALL">'
|
||||
'<meta name="description" content="">'
|
||||
'<meta name="keywords" content="">'
|
||||
'<meta name content="">'
|
||||
end
|
||||
|
||||
def user
|
||||
@user = Customer.find(@session["user"]) if @user.nil?
|
||||
@user
|
||||
end
|
||||
|
||||
def link_main
|
||||
link_to( t(:contacts), contacts_path)
|
||||
end
|
||||
|
||||
def alternator
|
||||
if @alternator.nil?
|
||||
@alternator = 1
|
||||
end
|
||||
|
||||
@alternator = -@alternator
|
||||
|
||||
if @alternator == -1
|
||||
return "even"
|
||||
else
|
||||
return "odd"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
module ContactGroupHelper
|
||||
def link_save() "/contact_group/save" end
|
||||
def link_list() "/contact_group/list" end
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
module ContactsHelper
|
||||
|
||||
end
|
2
app/helpers/core_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module CoreHelper
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
module FoldersHelper
|
||||
end
|
|
@ -1,60 +0,0 @@
|
|||
module NavigationHelper
|
||||
def link_back_to_messages
|
||||
link_to("«" << t(:back_to_message), :controller=>"webmail", :action=>"messages")
|
||||
end
|
||||
|
||||
def link_send_mail
|
||||
link_to( t(:compose), :controller=>"webmail", :action=>"compose")
|
||||
end
|
||||
|
||||
def link_mail_prefs
|
||||
link_to( t(:preferences), :controller=>"webmail", :action=>"prefs")
|
||||
end
|
||||
|
||||
def link_mail_filters
|
||||
link_to( t(:filters), :controller=>"webmail", :action=>"filters")
|
||||
end
|
||||
|
||||
def folder_manage_link(folder)
|
||||
if folder.name == CDF::CONFIG[:mail_trash] or folder.name == CDF::CONFIG[:mail_inbox] or folder.name == CDF::CONFIG[:mail_sent]
|
||||
short_fn(folder)
|
||||
else
|
||||
short_fn(folder) + ' ' + link_to(t(:delete), folder_path(folder.name), :method => :delete)
|
||||
end
|
||||
end
|
||||
|
||||
def link_import_preview() "/contacts/import_preview" end
|
||||
def link_main_index() root_url end
|
||||
def link_contact_import() url_for(:controller => :contacts, :action => :import) end
|
||||
def link_contact_choose() url_for(:controller => :contacts, :action => :choose) end
|
||||
|
||||
def link_contact_list
|
||||
link_to(t(:list), :controller => :contacts, :action => :index)
|
||||
end
|
||||
|
||||
def link_contact_add_one
|
||||
link_to(t(:add_one_contact), new_contact_path)
|
||||
end
|
||||
|
||||
def link_contact_add_multiple
|
||||
link_to(t(:add_multiple), :controller => :contacts, :action => "add_multiple")
|
||||
end
|
||||
|
||||
def link_contact_group_list
|
||||
link_to(t(:groups), :controller => :contact_group, :action => :index)
|
||||
end
|
||||
|
||||
def link_folders
|
||||
link_to( t(:folders), :controller=>:webmail, :action=>:messages)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def short_fn(folder)
|
||||
if folder.name.include? folder.delim
|
||||
folder.name.split(folder.delim).last
|
||||
else
|
||||
folder.name
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,167 +0,0 @@
|
|||
require 'cdfutils'
|
||||
require 'mail2screen'
|
||||
|
||||
module WebmailHelper
|
||||
include Mail2Screen
|
||||
def link_compose_new
|
||||
link_to(t(:compose_txt), :controller=>"webmail", :action=>"compose")
|
||||
end
|
||||
|
||||
def link_refresh
|
||||
link_to(t(:refresh), :controller=>"webmail", :action=>"refresh")
|
||||
end
|
||||
|
||||
def link_message_list
|
||||
link_to(_('Message list'), :controller=>"webmail", :action=>"messages")
|
||||
end
|
||||
|
||||
def link_reply_to_sender(msg_id)
|
||||
link_to(t(:reply), :controller=>"webmail", :action=>"reply", :params=>{"msg_id"=>msg_id})
|
||||
end
|
||||
|
||||
def link_forward_message(msg_id)
|
||||
link_to(t(:forward), :controller=>"webmail", :action=>"forward", :params=>{"msg_id"=>msg_id})
|
||||
end
|
||||
|
||||
def link_flag_for_deletion(msg_id)
|
||||
link_to(t(:delete), :controller=>"webmail", :action=>"delete", :params=>{"msg_id"=>msg_id})
|
||||
end
|
||||
|
||||
def link_view_source(msg_id)
|
||||
link_to(t(:view_source), {:controller=>"webmail", :action=>"view_source", :params=>{"msg_id"=>msg_id}}, {'target'=>"_blank"})
|
||||
end
|
||||
|
||||
def link_filter_add
|
||||
link_to(t(:add_filter), :controller=>'webmail', :action=>'filter_add')
|
||||
end
|
||||
|
||||
def folder_link(folder)
|
||||
return folder.name if folder.attribs.include?(:Noselect)
|
||||
folder_name = short_fn(folder)
|
||||
folder_name = t(folder_name.downcase.to_sym, :default => folder_name)
|
||||
title = folder.unseen > 0 ? "#{folder_name} (#{folder.unseen})" : "#{folder_name}"
|
||||
link = link_to title, :controller => 'webmail', :action => 'messages', :folder_name => folder.name
|
||||
link = content_tag('b', link) if folder.name == @folder_name
|
||||
link += raw(' ' + empty_trash_link(folder.name)) if folder.trash?
|
||||
logger.info link
|
||||
link
|
||||
end
|
||||
|
||||
def message_date(datestr)
|
||||
t = Time.now
|
||||
begin
|
||||
if datestr.kind_of?(String)
|
||||
d = (Time.rfc2822(datestr) rescue Time.parse(value)).localtime
|
||||
else
|
||||
d = datestr
|
||||
end
|
||||
if d.day == t.day and d.month == t.month and d.year == t.year
|
||||
d.strftime("%H:%M")
|
||||
else
|
||||
d.strftime("%Y-%m-%d")
|
||||
end
|
||||
rescue
|
||||
begin
|
||||
d = imap2time(datestr)
|
||||
if d.day == t.day and d.month == t.month and d.year == t.year
|
||||
d.strftime("%H:%M")
|
||||
else
|
||||
d.strftime("%Y-%m-%d")
|
||||
end
|
||||
rescue
|
||||
datestr
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def attachment(att, index)
|
||||
ret = "#{att.filename}"
|
||||
# todo: add link to delete attachment
|
||||
#ret <<
|
||||
ret << "<input type='hidden' name='att_files[#{index}]' value='#{att.filename}'/>"
|
||||
ret << "<input type='hidden' name='att_tfiles[#{index}]' value='#{att.temp_filename}'/>"
|
||||
ret << "<input type='hidden' name='att_ctypes[#{index}]' value='#{att.content_type}'/>"
|
||||
end
|
||||
|
||||
def link_filter_up(filter_id)
|
||||
link_to(_('Up'), :controller=>"webmail", :action=>"filter_up", :id=>filter_id)
|
||||
end
|
||||
|
||||
def link_filter_down(filter_id)
|
||||
link_to(_('Down'), :controller=>"webmail", :action=>"filter_down", :id=>filter_id)
|
||||
end
|
||||
|
||||
def link_filter_edit(filter_id)
|
||||
link_to(_('Edit'), :controller=>"webmail", :action=>"filter", :id=>filter_id)
|
||||
end
|
||||
|
||||
def link_filter_delete(filter_id)
|
||||
link_to(_('Delete'), :controller=>"webmail", :action=>"filter_delete", :id=>filter_id)
|
||||
end
|
||||
|
||||
def page_navigation_webmail(pages)
|
||||
nav = "<p class='paginator'><small>"
|
||||
|
||||
nav << "(#{pages.length} #{t :pages}) "
|
||||
|
||||
window_pages = pages.current.window.pages
|
||||
nav << "..." unless window_pages[0].first?
|
||||
for page in window_pages
|
||||
if pages.current == page
|
||||
nav << page.number.to_s << " "
|
||||
else
|
||||
nav << link_to(page.number, :controller=>"webmail", :action=>'messages', :page=>page.number) << " "
|
||||
end
|
||||
end
|
||||
nav << "..." unless window_pages[-1].last?
|
||||
nav << " "
|
||||
|
||||
nav << link_to(t(:first), :controller=>"webmail", :action=>'messages', :page=>@pages.first.number) << " | " unless @pages.current.first?
|
||||
nav << link_to(t(:prev), :controller=>"webmail", :action=>'messages', :page=>@pages.current.previous.number) << " | " if @pages.current.previous
|
||||
nav << link_to(t(:next), :controller=>"webmail", :action=>'messages', :page=>@pages.current.next.number) << " | " if @pages.current.next
|
||||
nav << link_to(t(:last), :controller=>"webmail", :action=>'messages', :page=>@pages.last.number) << " | " unless @pages.current.last?
|
||||
|
||||
nav << "</small></p>"
|
||||
|
||||
return nav
|
||||
end
|
||||
|
||||
def parse_subject(subject)
|
||||
begin
|
||||
if mime_encoded?(subject)
|
||||
if mime_decode(subject) == ''
|
||||
_('(No subject)')
|
||||
else
|
||||
mime_decode(subject)
|
||||
end
|
||||
else
|
||||
if from_qp(subject) == ''
|
||||
_('(No subject)')
|
||||
else
|
||||
from_qp(subject)
|
||||
end
|
||||
end
|
||||
rescue Exception => ex
|
||||
RAILS_DEFAULT_LOGGER.debug('Exception occured - #{ex}')
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
def message_size(size)
|
||||
if size / (1024*1024) > 0
|
||||
return "#{(size / (1024*1024)).round} MB"
|
||||
elsif size / 1024 > 0
|
||||
return "#{(size / (1024)).round} KB"
|
||||
else
|
||||
return "#{size} B"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def empty_trash_link(folder_name)
|
||||
link_to( "(#{t :empty})",
|
||||
{ :controller => "webmail", :action => "empty", :params=>{"folder_name"=>folder_name}},
|
||||
:confirm => t(:want_to_empty_trash_message))
|
||||
end
|
||||
end
|
|
@ -1,76 +0,0 @@
|
|||
require 'cdfutils'
|
||||
require_association 'contact_group'
|
||||
|
||||
class Contact < ActiveRecord::Base
|
||||
|
||||
validate :check_fname_and_lname, :check_mail_cannot_be_changed
|
||||
validate :check_email, :on => :create
|
||||
|
||||
has_and_belongs_to_many :groups, :class_name => "ContactGroup", :join_table => "contact_contact_groups", :association_foreign_key => "contact_group_id", :foreign_key => "contact_id"
|
||||
|
||||
# Finder methods follow
|
||||
def Contact.find_by_user(user_id)
|
||||
find(:all, :conditions => ["customer_id = ?", user_id], :order => "fname asc", :limit => 10)
|
||||
end
|
||||
|
||||
def Contact.find_by_user_email(user_id, email)
|
||||
find(:first, :conditions => ["customer_id = #{user_id} and email = ?", email])
|
||||
end
|
||||
|
||||
def Contact.find_by_group_user(user_id, grp_id)
|
||||
result = Array.new
|
||||
find(:all, :conditions => ["customer_id = ?", user_id], :order => "fname asc").each { |c|
|
||||
begin
|
||||
c.groups.find(grp_id)
|
||||
result << c
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
end
|
||||
}
|
||||
result
|
||||
end
|
||||
|
||||
scope :for_customer, lambda{ |customer_id| {:conditions => {:customer_id => customer_id}} }
|
||||
scope :letter, lambda{ |letter| {:conditions => ["contacts.fname LIKE ?", "#{letter}%"]} }
|
||||
|
||||
def Contact.find_by_user_letter(user_id, letter)
|
||||
find_by_sql("select * from contacts where customer_id=#{user_id} and substr(UPPER(fname),1,1) = '#{letter}' order by fname")
|
||||
end
|
||||
|
||||
def full_name
|
||||
"#{fname} #{lname}"
|
||||
end
|
||||
|
||||
def show_name
|
||||
"#{fname} #{lname}"
|
||||
end
|
||||
|
||||
def full_address
|
||||
"#{fname} #{lname}<#{email}>"
|
||||
end
|
||||
|
||||
protected
|
||||
def check_fname_and_lname
|
||||
errors.add 'fname', t(:validate_fname_error) unless self.fname =~ /^.{2,20}$/i
|
||||
errors.add 'lname', t(:validate_lname_error) unless self.lname =~ /^.{2,20}$/i
|
||||
end
|
||||
|
||||
def check_mail_cannot_be_changed
|
||||
# Contact e-mail cannot be changed
|
||||
unless self.new_record?
|
||||
old_record = Contact.find(self.id)
|
||||
errors.add 'email', t(:contact_cannot_be_changed) unless old_record.email == self.email
|
||||
end
|
||||
end
|
||||
|
||||
def check_mail
|
||||
# Contact e-mail cannot be changed, so we only need to validate it on create
|
||||
errors.add 'email', t(:validate_email_error) unless valid_email?(self.email)
|
||||
# Already existing e-mail in contacts for this user is not allowed
|
||||
if self.new_record?
|
||||
if Contact.find :first, :conditions => {:email => email, :customer_id => customer_id}
|
||||
errors.add('email', I18n.t(:email_exists))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
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"
|
||||
|
||||
validate :check_group_name
|
||||
validate :check_group_id, :on => :create
|
||||
validate :check_group_uniqness, :on => :update
|
||||
|
||||
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 check_group_name
|
||||
errors.add('name', t(:contactgroup_name_invalid)) unless self.name =~ /^.{1,50}$/i
|
||||
end
|
||||
|
||||
def check_group_id
|
||||
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 check_group_uniqness
|
||||
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
|
|
@ -1,32 +0,0 @@
|
|||
require_dependency 'maildropserializator'
|
||||
class Customer < ActiveRecord::Base
|
||||
include MaildropSerializator
|
||||
|
||||
has_many :filters, :order => "order_num"
|
||||
has_one :mail_pref
|
||||
attr_accessor :password
|
||||
|
||||
def mail_temporary_path
|
||||
"#{CDF::CONFIG[:mail_temp_path]}/#{self.email}"
|
||||
end
|
||||
|
||||
def friendlly_local_email
|
||||
encode_email("#{self.fname} #{self.lname}", check_for_domain(email))
|
||||
end
|
||||
|
||||
def mail_filter_path
|
||||
"#{CDF::CONFIG[:mail_filters_path]}/#{self.email}"
|
||||
end
|
||||
|
||||
def local_email
|
||||
self.email
|
||||
end
|
||||
|
||||
def check_for_domain(email)
|
||||
if email && !email.nil? && !email.include?("@") && CDF::CONFIG[:send_from_domain]
|
||||
email + "@" + CDF::CONFIG[:send_from_domain]
|
||||
else
|
||||
email
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,43 +0,0 @@
|
|||
require 'mail2screen'
|
||||
class ImapMessage < ActiveRecord::Base
|
||||
include Mail2Screen
|
||||
|
||||
def set_folder(folder)
|
||||
@folder = folder
|
||||
end
|
||||
|
||||
def full_body
|
||||
@folder.mailbox.imap.uid_fetch(uid, "BODY[]").first.attr["BODY[]"]
|
||||
end
|
||||
|
||||
def from_addr=(fa)
|
||||
self.from = fa.to_yaml
|
||||
self.from_flat = short_address(fa)
|
||||
end
|
||||
|
||||
def from_addr
|
||||
begin
|
||||
YAML::load(from)
|
||||
rescue Object
|
||||
from
|
||||
end
|
||||
end
|
||||
|
||||
def to_addr=(ta)
|
||||
self.to = ta.to_yaml
|
||||
self.to_flat = short_address(ta)
|
||||
end
|
||||
|
||||
def to_addr
|
||||
begin
|
||||
YAML::load(to)
|
||||
rescue Object
|
||||
to
|
||||
end
|
||||
end
|
||||
|
||||
def self.getAll(userName,folderName,sortOrder='date desc')
|
||||
self.all(:conditions => ["username = ? and folder_name = ?", userName, folderName],:order => sortOrder)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
# require_association 'customer'
|
||||
|
||||
class MailPref < ActiveRecord::Base
|
||||
belongs_to :customer
|
||||
|
||||
# def MailPref.find_by_customer(customer_id)
|
||||
# find :first, :conditions => (["customer_id = #{customer_id}"])
|
||||
# end
|
||||
end
|
0
app/views/contents_moved_to_original_theme_directory → app/views/contents_moved_to_olive_theme_directory
Normal file → Executable file
0
arts/logo2.xcf
Normal file → Executable file
0
arts/logo3.xcf
Normal file → Executable file
0
config.ru
Executable file → Normal file
25
config/application.rb
Executable file → Normal file
|
@ -15,9 +15,6 @@ module Mailr
|
|||
# Custom directories with classes and modules you want to be autoloadable.
|
||||
# config.autoload_paths += %W(#{config.root}/extras)
|
||||
|
||||
config.autoload_paths << Rails.root.join("vendor/ezcrypto-0.1.1/lib")
|
||||
config.autoload_paths << Rails.root.join("lib/webmail")
|
||||
|
||||
# Only load the plugins named here, in the order given (default is alphabetical).
|
||||
# :all can be used as a placeholder for all plugins not explicitly named.
|
||||
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
||||
|
@ -30,8 +27,8 @@ module Mailr
|
|||
# config.time_zone = 'Central Time (US & Canada)'
|
||||
|
||||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
||||
#config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
||||
#config.i18n.default_locale = :en
|
||||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
||||
# config.i18n.default_locale = :de
|
||||
|
||||
# JavaScript files you want as :defaults (application.js is always included).
|
||||
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
||||
|
@ -41,23 +38,5 @@ module Mailr
|
|||
|
||||
# Configure sensitive parameters which will be filtered from the log file.
|
||||
config.filter_parameters += [:password]
|
||||
|
||||
default_config_path = 'config/default_site'
|
||||
default_config = Rails.root.join(default_config_path)
|
||||
require default_config
|
||||
begin
|
||||
require Rails.root.join("config/site")
|
||||
CDF::CONFIG.update(CDF::LOCALCONFIG) if CDF::LOCALCONFIG
|
||||
rescue LoadError
|
||||
STDERR.puts 'WARNING: config/site.rb not found, using default settings from ' + default_config_path
|
||||
end
|
||||
|
||||
#if CONFIG[:locale] is nil then I18n.default_locale will be used
|
||||
config.i18n.default_locale = CDF::CONFIG[:locale]
|
||||
|
||||
require 'tmail_patch'
|
||||
$KCODE = 'u'
|
||||
require 'jcode'
|
||||
|
||||
end
|
||||
end
|
||||
|
|
0
config/boot.rb
Executable file → Normal file
0
config/database.yml.example
Normal file → Executable file
|
@ -1,52 +0,0 @@
|
|||
# Site-specific parameters
|
||||
# These are Mailr constants. If you want to overwrite
|
||||
# some of them - create file config/site.rb
|
||||
# containing new constants in LOCALCONFIG module variable - they
|
||||
# will overwrite default values. Example site.rb:
|
||||
#
|
||||
# module CDF
|
||||
# LOCALCONFIG = {
|
||||
# :mysql_version => '4.1',
|
||||
# :default_encoding => 'utf-8',
|
||||
# :imap_server => 'your.imap.server',
|
||||
# :imap_auth => 'LOGIN'
|
||||
# }
|
||||
# end
|
||||
|
||||
module CDF
|
||||
CONFIG = {
|
||||
:mysql_version => '4.0',
|
||||
:default_language => 'en',
|
||||
:default_encoding => 'ISO-8859-1',
|
||||
:mail_charset => 'ISO-8859-1',
|
||||
:mail_inbox => 'INBOX',
|
||||
:mail_trash => 'INBOX.Trash',
|
||||
:mail_sent => 'INBOX.Sent',
|
||||
:mail_bulk_sent => "INBOX.SentBulk",
|
||||
:mail_spam => "INBOX.Spam",
|
||||
:mail_temp_path => 'mail_temp',
|
||||
:mail_filters_path => '/home/vmail/mailfilters',
|
||||
:mail_send_types => {"Plain text" => "text/plain", "HTML"=>"text/html", "HTML and PlainText" => "multipart"},
|
||||
:mail_message_rows => [5, 10, 15, 20, 25, 30, 50],
|
||||
:mail_filters_fields => {'From' => '^From', 'To' => '^To', 'CC' => '^CC', 'Subject' => '^Subject', 'Body' => '^Body'},
|
||||
:mail_filters_expressions => ['contains', 'starts with'],
|
||||
:mail_search_fields => ['FROM', 'TO', 'CC', 'SUBJECT', 'BODY'],
|
||||
:temp_file_location => ".",
|
||||
:contacts_per_page => 15,
|
||||
:contact_letters => ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'],
|
||||
:upload_file_temp_path => "/tmp",
|
||||
:imap_server => 'localhost',
|
||||
:imap_use_ssl => false,
|
||||
:imap_port => 143,
|
||||
:imap_auth => 'PLAIN', # 'LOGIN', 'NOAUTH'
|
||||
:encryption_salt => 'EnCr1p10n$@lt',
|
||||
:encryption_password => '$0MeEncr1pt10nP@a$sw0rd',
|
||||
:debug_imap => false,
|
||||
:crypt_session_pass => true, # Set it to false (in site.rb) if you get any error messages like
|
||||
# "Unsupported cipher algorithm (aes-128-cbc)." - meaning that OpenSSL modules for crypt algo is not loaded. Setting it to false will store password in session in plain format!
|
||||
:send_from_domain => nil, # Set this variable to your domain name in site.rb if you make login to imap only with username (without '@domain')
|
||||
:imap_bye_timeout_retry_seconds => 2,
|
||||
:default_theme => 'original'
|
||||
}
|
||||
end
|
||||
|
2
config/defaults.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
theme: olive
|
||||
locale: en
|
0
config/environment.rb
Executable file → Normal file
0
config/environments/development.rb
Executable file → Normal file
0
config/environments/production.rb
Executable file → Normal file
0
config/environments/test.rb
Executable file → Normal file
0
config/initializers/backtrace_silencers.rb
Executable file → Normal file
0
config/initializers/inflections.rb
Executable file → Normal file
0
config/initializers/mime_types.rb
Executable file → Normal file
|
@ -1,36 +0,0 @@
|
|||
# config/initializers/pluralization.rb
|
||||
module I18n::Backend::Pluralization
|
||||
# rules taken from : http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html
|
||||
def pluralize(locale, entry, n)
|
||||
return entry unless entry.is_a?(Hash) && n
|
||||
if n == 0 && entry.has_key?(:zero)
|
||||
key = :zero
|
||||
else
|
||||
key = case locale
|
||||
when :pl # Polish
|
||||
n==1 ? :one : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? :few : :other
|
||||
when :cs, :sk # Czech, Slovak
|
||||
n==1 ? :one : (n>=2 && n<=4) ? :few : :other
|
||||
when lt # Lithuanian
|
||||
n%10==1 && n%100!=11 ? :one : n%10>=2 && (n%100<10 || n%100>=20) ? :few : :other
|
||||
when :lv # Latvian
|
||||
n%10==1 && n%100!=11 ? :one : n != 0 ? :few : :other
|
||||
when :ru, :uk, :sr, :hr # Russian, Ukrainian, Serbian, Croatian
|
||||
n%10==1 && n%100!=11 ? :one : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? :few : :other
|
||||
when :sl # Slovenian
|
||||
n%100==1 ? :one : n%100==2 ? :few : n%100==3 || n%100==4 ? :many : :other
|
||||
when :ro # Romanian
|
||||
n==1 ? :one : (n==0 || (n%100 > 0 && n%100 < 20)) ? :few : :other
|
||||
when :gd # Gaeilge
|
||||
n==1 ? :one : n==2 ? :two : :other;
|
||||
# add another language if you like...
|
||||
else
|
||||
n==1 ? :one : :other # default :en
|
||||
end
|
||||
end
|
||||
raise InvalidPluralizationData.new(entry, n) unless entry.has_key?(key)
|
||||
entry[key]
|
||||
end
|
||||
end
|
||||
|
||||
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
|
2
config/initializers/secret_token.rb
Executable file → Normal file
|
@ -4,4 +4,4 @@
|
|||
# If you change this key, all old signed cookies will become invalid!
|
||||
# Make sure the secret is at least 30 characters and all random,
|
||||
# no regular words or you'll be exposed to dictionary attacks.
|
||||
Mailr::Application.config.secret_token = 'ade84d567b0c637fd3547fd18b97d1677fd6ca3c5331e6ed1a1b13bb6a7823cc367cbe317caf102f29f8c35eb487ff3ca33e6321d037c14ebb055eb530841ff6'
|
||||
Mailr::Application.config.secret_token = 'f07b5830035b1471d3c008debde5c152077eaff97f0dfcebaf265fe96db24dc5af46eb27e149e3077df89d7dbe2eb088ab7ef7b0e8b496d7ca005e31f6dc3017'
|
||||
|
|
2
config/initializers/session_store.rb
Executable file → Normal file
|
@ -5,4 +5,4 @@ Mailr::Application.config.session_store :cookie_store, :key => '_mailr_session'
|
|||
# Use the database for sessions instead of the cookie-based default,
|
||||
# which shouldn't be used to store highly confidential information
|
||||
# (create the session table with "rails generate session_migration")
|
||||
# Rails3::Application.config.session_store :active_record_store
|
||||
# Mailr::Application.config.session_store :active_record_store
|
||||
|
|
|
@ -65,3 +65,6 @@ en:
|
|||
total_messages: Total messages
|
||||
unseen: Unseen
|
||||
please_login: Log in
|
||||
site_link: https://github.com/lmanolov/mailr
|
||||
user_logged_out: User was logged out
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ pl:
|
|||
filters: Filtry
|
||||
contacts: Kontakty
|
||||
search: Szukaj
|
||||
search_txt: Szukaj w polu wiadomości
|
||||
search_txt: ciąg znaków
|
||||
refresh: Odśwież
|
||||
operations: Akcje
|
||||
operations_txt: Akcje na zaznaczonych wiadomościach
|
||||
|
@ -70,3 +70,8 @@ pl:
|
|||
add_to_contacts: Dodaj do kontaktów
|
||||
want_to_empty_trash_message: Czy chcesz opróznic kosz?
|
||||
site_link: https://github.com/lmanolov/mailr
|
||||
marked_messages: zaznaczone wiadomości
|
||||
to_folder: do folderu
|
||||
message_field: Pole wiadomości
|
||||
no_messages_found: Nie znaleziono żadnych wiadomości
|
||||
|
||||
|
|
24
config/routes.rb
Executable file → Normal file
|
@ -1,26 +1,11 @@
|
|||
Mailr::Application.routes.draw do
|
||||
themes_for_rails
|
||||
|
||||
resources :folders
|
||||
resources :contacts do
|
||||
collection do
|
||||
get :add_multiple
|
||||
end
|
||||
member do
|
||||
get :add_from_mail
|
||||
end
|
||||
end
|
||||
themes_for_rails
|
||||
|
||||
resources :contact_groups
|
||||
match '/' => 'webmail#index'
|
||||
match 'webmail' => 'webmail#index'
|
||||
match 'webmail/:action' => 'webmail#index'
|
||||
match '/contact/:action' => 'contacts#index'
|
||||
match 'admin/main' => 'login#logout'
|
||||
match ':controller/service.wsdl' => '#wsdl'
|
||||
match '/:controller(/:action(/:id))'
|
||||
get "core/login"
|
||||
get "core/logout"
|
||||
post "core/authenticate"
|
||||
|
||||
end
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
@ -78,3 +63,4 @@ end
|
|||
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
||||
# Note: This route will make all actions in every controller accessible via GET requests.
|
||||
# match ':controller(/:action(/:id(.:format)))'
|
||||
end
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
class Init < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :customers do |t|
|
||||
t.string :fname, :lname, :email
|
||||
t.integer :customer_id
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :filters do |t|
|
||||
t.string :name, :destination_folder
|
||||
t.integer :customer_id, :order_num
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :expressions do |t|
|
||||
t.string :field_name, :operator, :expr_value
|
||||
t.integer :filter_id
|
||||
t.boolean :case_sensitive
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :mail_prefs do |t|
|
||||
t.string :mail_type
|
||||
t.integer :wm_rows, :default => 20
|
||||
t.integer :customer_id
|
||||
t.boolean :check_external_mail
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :contacts do |t|
|
||||
t.string :fname, :lname, :email, :hphone, :wphone, :mobile, :fax
|
||||
t.text :notes
|
||||
t.integer :customer_id
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :contact_groups do |t|
|
||||
t.string :name
|
||||
t.integer :customer_id
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :contact_contact_groups do |t|
|
||||
t.integer :contact_id, :contact_group_id
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :imap_messages do |t|
|
||||
t.string :folder_name, :username, :msg_id, :from, :from_flat, :to, :to_flat, :subject, :content_type
|
||||
t.integer :uid, :size
|
||||
t.boolean :unread
|
||||
t.datetime :date
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :imap_messages
|
||||
drop_table :contact_contact_groups
|
||||
drop_table :contact_groups
|
||||
drop_table :contacts
|
||||
drop_table :mail_prefs
|
||||
drop_table :expressions
|
||||
drop_table :filters
|
||||
drop_table :customers
|
||||
end
|
||||
end
|
96
db/schema.rb
|
@ -1,96 +0,0 @@
|
|||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20090107193228) do
|
||||
|
||||
create_table "contact_contact_groups", :force => true do |t|
|
||||
t.integer "contact_id"
|
||||
t.integer "contact_group_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "contact_groups", :force => true do |t|
|
||||
t.string "name"
|
||||
t.integer "customer_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "contacts", :force => true do |t|
|
||||
t.string "fname"
|
||||
t.string "lname"
|
||||
t.string "email"
|
||||
t.string "hphone"
|
||||
t.string "wphone"
|
||||
t.string "mobile"
|
||||
t.string "fax"
|
||||
t.text "notes"
|
||||
t.integer "customer_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "customers", :force => true do |t|
|
||||
t.string "fname"
|
||||
t.string "lname"
|
||||
t.string "email"
|
||||
t.integer "customer_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "expressions", :force => true do |t|
|
||||
t.string "field_name"
|
||||
t.string "operator"
|
||||
t.string "expr_value"
|
||||
t.integer "filter_id"
|
||||
t.boolean "case_sensitive"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "filters", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "destination_folder"
|
||||
t.integer "customer_id"
|
||||
t.integer "order_num"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "imap_messages", :force => true do |t|
|
||||
t.string "folder_name"
|
||||
t.string "username"
|
||||
t.string "msg_id"
|
||||
t.string "from"
|
||||
t.string "from_flat"
|
||||
t.string "to"
|
||||
t.string "to_flat"
|
||||
t.string "subject"
|
||||
t.string "content_type"
|
||||
t.integer "uid"
|
||||
t.integer "size"
|
||||
t.boolean "unread"
|
||||
t.datetime "date"
|
||||
end
|
||||
|
||||
create_table "mail_prefs", :force => true do |t|
|
||||
t.string "mail_type"
|
||||
t.integer "wm_rows", :default => 20
|
||||
t.integer "customer_id"
|
||||
t.boolean "check_external_mail"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
end
|
0
db/seeds.rb
Executable file → Normal file
0
doc/README_FOR_APP
Executable file → Normal file
183
lib/cdfutils.rb
|
@ -1,183 +0,0 @@
|
|||
MIME_ENCODED = /=\?([a-z\-0-9]*)\?[QB]\?([a-zA-Z0-9+\/=\_\-]+)\?=/i
|
||||
IMAP_EMAIL_ENVELOPE_FORMAT = /([a-zA-Z\-\.\_]*@[a-zA-Z\-\.\_]*)/
|
||||
IMAP_EMAIL_ENVELOPE_FORMAT2 = /(.*)<([a-zA-Z\-\.\_]*@[a-zA-Z\-\.\_]*)>/
|
||||
|
||||
require 'iconv'
|
||||
|
||||
def valid_email?(email)
|
||||
email.size < 100 && email =~ /.@.+\../ && email.count('@') == 1
|
||||
end
|
||||
|
||||
def mime_encoded?( str )
|
||||
return false if str.nil?
|
||||
not (MIME_ENCODED =~ str).nil?
|
||||
end
|
||||
|
||||
def from_qp(str, remove_underscore = true)
|
||||
return '' if str.nil?
|
||||
result = str.gsub(/=\r\n/, "")
|
||||
result = result.gsub(/_/, " ") if remove_underscore
|
||||
result.gsub!(/\r\n/m, $/)
|
||||
result.gsub!(/=([\da-fA-F]{2})/) { $1.hex.chr }
|
||||
result
|
||||
end
|
||||
|
||||
def mime_decode(str, remove_underscore = true)
|
||||
return '' if str.nil?
|
||||
str.gsub(MIME_ENCODED) {|s|
|
||||
enc = s.scan(MIME_ENCODED).flatten
|
||||
if /\?Q\?/i =~ s
|
||||
begin
|
||||
Iconv.conv("UTF-8", enc[0], from_qp(enc[1], remove_underscore))
|
||||
rescue
|
||||
from_qp(enc[1], remove_underscore)
|
||||
end
|
||||
else
|
||||
begin
|
||||
Iconv.conv("UTF-8", enc[0], enc[1].unpack("m*").to_s)
|
||||
rescue
|
||||
enc[1].unpack("m*").to_s
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def imap2friendlly_email(str)
|
||||
begin
|
||||
if str === IMAP_EMAIL_ENVELOPE_FORMAT
|
||||
email = str.scan(IMAP_EMAIL_ENVELOPE_FORMAT)[0][0]
|
||||
else
|
||||
email = str.scan(IMAP_EMAIL_ENVELOPE_FORMAT2)[0][0]
|
||||
end
|
||||
name = str.slice(0, str.rindex(email)-1)
|
||||
name = decode(name).to_s if mime_encoded?(name)
|
||||
return "#{name.nil? ? '' : name.strip}<#{email}>"
|
||||
rescue
|
||||
"Error parsing str - #{str.scan(IMAP_EMAIL_ENVELOPE_FORMAT)} - #{str.scan(IMAP_EMAIL_ENVELOPE_FORMAT2)}"
|
||||
end
|
||||
end
|
||||
|
||||
def imap2friendlly_name(str)
|
||||
begin
|
||||
email = str.scan(IMAP_EMAIL_ENVELOPE_FORMAT)[0][0]
|
||||
name = str.slice(0, str.rindex(email))
|
||||
if name.nil? or name.strip == ""
|
||||
return email
|
||||
else
|
||||
return name
|
||||
end
|
||||
rescue
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
def imap2friendlly_full_name(str)
|
||||
begin
|
||||
email = str.scan(IMAP_EMAIL_ENVELOPE_FORMAT)[0][0]
|
||||
name = str.slice(0, str.rindex(email))
|
||||
if name.nil? or name.strip == ""
|
||||
return email
|
||||
else
|
||||
return "#{name}<#{email}>"
|
||||
end
|
||||
rescue
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
def imap2name_only(str)
|
||||
email = str.scan(IMAP_EMAIL_ENVELOPE_FORMAT)[0][0]
|
||||
name = str.slice(0, str.rindex(email))
|
||||
return "#{name.nil? ? '' : name.strip}"
|
||||
end
|
||||
|
||||
def imap2time(str)
|
||||
begin
|
||||
vals = str.scan(/(...), (.?.) (...) (....) (..):(..):(..) (.*)/)[0]
|
||||
Time.local(vals[3],vals[2],vals[1],vals[4],vals[5],vals[6])
|
||||
rescue
|
||||
Time.now
|
||||
end
|
||||
end
|
||||
|
||||
def encode_email(names, email)
|
||||
nameen = ""
|
||||
names.each_byte { | ch | nameen = nameen +"=" + sprintf("%X",ch) }
|
||||
return "=?#{CDF::CONFIG[:mail_charset]}?Q?#{nameen}?= <#{email}>"
|
||||
end
|
||||
|
||||
# #############################
|
||||
# HTML utils
|
||||
# #############################
|
||||
def replace_tag(tag, attrs)
|
||||
replacements = {"body" => "",
|
||||
"/body" => "",
|
||||
"meta" => "",
|
||||
"/meta" => "",
|
||||
"head" => "",
|
||||
"/head" => "",
|
||||
"html" => "",
|
||||
"/html" => "",
|
||||
"title" => "<div class='notviscode'>",
|
||||
"/title" => "</div>",
|
||||
"div" => "",
|
||||
"/div" => "",
|
||||
"span" => "",
|
||||
"/span" => "",
|
||||
"layer" => "",
|
||||
"/layer" => "",
|
||||
"br" => "<br/>",
|
||||
"/br" => "<br/>",
|
||||
"iframe" => "",
|
||||
"/iframe" => "",
|
||||
"link" => "<xlink" << replace_attr(attrs) << ">",
|
||||
"/link" => "</xlink" << replace_attr(attrs) << ">",
|
||||
"style" => "<div class='notviscode'>",
|
||||
"/style" => "</div>",
|
||||
"script" => "<div class='notviscode'>",
|
||||
"/script" => "</div>" }
|
||||
replacements.fetch(tag.downcase, ("<" << tag.downcase << replace_attr(attrs) << ">"))
|
||||
end
|
||||
|
||||
def replace_attr(attrs)
|
||||
if attrs
|
||||
attrs.downcase.gsub("onload", "onfilter").
|
||||
gsub("onclick", "onfilter").
|
||||
gsub("onkeypress", "onfilter").
|
||||
gsub("javascript", "_javascript").
|
||||
gsub("JavaScript", "_javascript")
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def clear_html(text)
|
||||
attribute_key = /[\w:_-]+/
|
||||
attribute_value = /(?:[A-Za-z0-9\-_#\%\.,\/\:]+|(?:'[^']*?'|"[^"]*?"))/
|
||||
attribute = /(?:#{attribute_key}(?:\s*=\s*#{attribute_value})?)/
|
||||
attributes = /(?:#{attribute}(?:\s+#{attribute})*)/
|
||||
tag_key = attribute_key
|
||||
tag = %r{<([!/?\[]?(?:#{tag_key}|--))((?:\s+#{attributes})?\s*(?:[!/?\]]+|--)?)>}
|
||||
text.gsub(tag, '').gsub(/\s+/, ' ').strip
|
||||
CGI::escape(text)
|
||||
end
|
||||
|
||||
def strip_html(text)
|
||||
attribute_key = /[\w:_-]+/
|
||||
attribute_value = /(?:[A-Za-z0-9\-_#\%\.,\/\:]+|(?:'[^']*?'|"[^"]*?"))/
|
||||
attribute = /(?:#{attribute_key}(?:\s*=\s*#{attribute_value})?)/
|
||||
attributes = /(?:#{attribute}(?:\s+#{attribute})*)/
|
||||
tag_key = attribute_key
|
||||
tag = %r{<([!/?\[]?(?:#{tag_key}|--))((?:\s+#{attributes})?\s*(?:[!/?\]]+|--)?)>}
|
||||
res = text.gsub(tag) { |match|
|
||||
ret = ""
|
||||
match.scan(tag) { |token|
|
||||
ret << replace_tag(token[0], token[1])
|
||||
}
|
||||
ret
|
||||
}
|
||||
# remove doctype tags
|
||||
xattributes = /(?:#{attribute_value}(?:\s+#{attribute_value})*)/
|
||||
xtag = %r{<!#{tag_key}((?:\s+#{xattributes})?\s*(?:[!/?\]]+|--)?)>}
|
||||
res.gsub(xtag, '')
|
||||
end
|
|
@ -1,69 +0,0 @@
|
|||
module ImapUtils
|
||||
private
|
||||
|
||||
def load_imap_session
|
||||
return if ['error_connection'].include?(action_name)
|
||||
get_imap_session
|
||||
end
|
||||
|
||||
def get_imap_session
|
||||
begin
|
||||
@mailbox = IMAPMailbox.new(self.logger)
|
||||
uname = (get_mail_prefs.check_external_mail == 1 ? user.email : user.local_email)
|
||||
upass = get_upass
|
||||
@mailbox.connect(uname, upass)
|
||||
load_folders
|
||||
rescue Exception => ex
|
||||
# logger.error("Exception on loggin webmail session - #{ex} - #{ex.backtrace.join("\t\n")}")
|
||||
# render :action => "error_connection"
|
||||
render :text => ex.inspect, :content_type => 'text/plain'
|
||||
end
|
||||
end
|
||||
|
||||
def close_imap_session
|
||||
return if @mailbox.nil? or not(@mailbox.connected)
|
||||
@mailbox.disconnect
|
||||
@mailbox = nil
|
||||
end
|
||||
|
||||
def get_mail_prefs
|
||||
if not(@mailprefs)
|
||||
if not(@mailprefs = MailPref.find_by_customer_id(logged_customer))
|
||||
@mailprefs = MailPref.create("customer_id"=>logged_customer)
|
||||
end
|
||||
end
|
||||
@mailprefs
|
||||
end
|
||||
|
||||
def get_upass
|
||||
if CDF::CONFIG[:crypt_session_pass]
|
||||
EzCrypto::Key.decrypt_with_password(CDF::CONFIG[:encryption_password], CDF::CONFIG[:encryption_salt], session["wmp"])
|
||||
else
|
||||
# retrun it plain
|
||||
session["wmp"]
|
||||
end
|
||||
end
|
||||
|
||||
def load_folders
|
||||
if have_to_load_folders?()
|
||||
if params["folder_name"]
|
||||
@folder_name = params["folder_name"]
|
||||
else
|
||||
@folder_name = session["folder_name"] ? session["folder_name"] : CDF::CONFIG[:mail_inbox]
|
||||
end
|
||||
session["folder_name"] = @folder_name
|
||||
@folders = @mailbox.folders if @folders.nil?
|
||||
end
|
||||
end
|
||||
|
||||
def user
|
||||
@user = Customer.find(logged_customer) if @user.nil?
|
||||
@user
|
||||
end
|
||||
|
||||
def have_to_load_folders?
|
||||
return true if ['messages', 'delete', 'reply', 'forward', 'empty', 'message', 'download',
|
||||
'filter', 'filter_add', 'view_source', 'compose', 'prefs', 'filters'].include?(action_name)
|
||||
return false
|
||||
end
|
||||
end
|
0
lib/tasks/.gitkeep
Executable file → Normal file
|
@ -1,38 +0,0 @@
|
|||
module TMail
|
||||
class Mail
|
||||
def parse_header( f )
|
||||
name = field = nil
|
||||
unixfrom = nil
|
||||
|
||||
while line = f.gets
|
||||
case line
|
||||
when /\A[ \t]/ # continue from prev line
|
||||
raise SyntaxError, 'mail is began by space' unless field
|
||||
field << ' ' << line.strip
|
||||
|
||||
when /\A([^\: \t]+):\s*/ # new header line
|
||||
add_hf name, field if field
|
||||
name = $1
|
||||
field = $' #.strip
|
||||
|
||||
when /\A\-*\s*\z/ # end of header
|
||||
add_hf name, field if field
|
||||
name = field = nil
|
||||
break
|
||||
|
||||
when /\AFrom (\S+)/
|
||||
unixfrom = $1
|
||||
else
|
||||
# treat as continue from previos
|
||||
raise SyntaxError, 'mail is began by space' unless field
|
||||
field << ' ' << line.strip
|
||||
end
|
||||
end
|
||||
add_hf name, field if name
|
||||
|
||||
if unixfrom
|
||||
add_hf 'Return-Path', "<#{unixfrom}>" unless @header['return-path']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
class BouncedMail < ActiveRecord::Base
|
||||
belongs_to :customer
|
||||
belongs_to :contact
|
||||
|
||||
def BouncedMail.find_by_customer_contact(cust_id, contact_id)
|
||||
find_all(["customer_id = ? and contact_id = ?", cust_id, cotact_id], ["msg_date desc"])
|
||||
end
|
||||
end
|
|
@ -1,306 +0,0 @@
|
|||
require 'tmail'
|
||||
require 'net/smtp'
|
||||
require 'mail_transform'
|
||||
|
||||
module CDF
|
||||
end
|
||||
|
||||
class CDF::Mail
|
||||
#include ActionMailer::Quoting #upgrade to Rails3
|
||||
|
||||
def initialize(senderTempLocation)
|
||||
@attachments = Array.new
|
||||
@sender_temp_location = senderTempLocation
|
||||
@to_contacts = Array.new
|
||||
end
|
||||
|
||||
def customer_id() @customer_id end
|
||||
|
||||
def customer_id=(arg) @customer_id = arg end
|
||||
|
||||
def from() @from end
|
||||
|
||||
def from=(arg) @from = arg end
|
||||
|
||||
def to() @to end
|
||||
|
||||
def to=(arg) @to = arg end
|
||||
|
||||
def to_contacts() @to_contacts end
|
||||
|
||||
def to_contacts=(arg) @to_contacts = arg end
|
||||
|
||||
def toc=(arg)
|
||||
@to_contacts = Array.new
|
||||
arg.split(",").each { |token| @to_contacts << token.to_i unless token == "" or token.strip() == "undefined"} unless arg.nil? or arg == "undefined"
|
||||
end
|
||||
|
||||
def toc
|
||||
ret = String.new
|
||||
@to_contacts.each { |contact|
|
||||
ret << "," unless ret == ""
|
||||
if contact.kind_of?(Integer)
|
||||
ret << contact.to_s unless contact.nil? or contact == 0
|
||||
else
|
||||
ret << contact.id.to_s unless contact.nil? or contact.id.nil?
|
||||
end
|
||||
}
|
||||
ret
|
||||
end
|
||||
|
||||
def bcc() @bcc end
|
||||
|
||||
def bcc=(arg) @bcc = arg end
|
||||
|
||||
def cc() @cc end
|
||||
|
||||
def cc=(arg) @cc = arg end
|
||||
|
||||
def subject() @subject end
|
||||
|
||||
def subject=(arg) @subject = arg end
|
||||
|
||||
def attachments
|
||||
@attachments
|
||||
end
|
||||
|
||||
def add_attachment(attachment)
|
||||
@attachments << attachment
|
||||
end
|
||||
|
||||
def multipart?
|
||||
@attachments && @attachments.size > 0
|
||||
end
|
||||
|
||||
def delete_attachment(att_filename)
|
||||
@attachments.each { |att| att.delete_temp_data() if arr.filename == att_filename }
|
||||
@attachments.delete_if() { |att| att.filename == att_filename }
|
||||
end
|
||||
|
||||
def delete_attachments()
|
||||
@attachments.each { |att| att.delete_temp_data() }
|
||||
@attachments = Array.new
|
||||
end
|
||||
|
||||
def body() @body end
|
||||
|
||||
def body=(arg) @body = arg end
|
||||
|
||||
def content_type() @content_type end
|
||||
|
||||
def content_type=(arg) @content_type = arg end
|
||||
|
||||
def temp_location() @sender_temp_location end
|
||||
|
||||
def send_mail(db_msg_id = 0)
|
||||
m = TMail::Mail.new
|
||||
m.from, m.body = self.from, self.body
|
||||
m.date = Time.now
|
||||
m.subject, = quote_any_if_necessary("UTF-8", self.subject)
|
||||
m.to = decode_addresses(self.to)
|
||||
|
||||
m.cc, m.bcc = decode_addresses(self.cc), decode_addresses(self.bcc)
|
||||
|
||||
if multipart?
|
||||
m.set_content_type("multipart/mixed")
|
||||
p = TMail::Mail.new(TMail::StringPort.new(""))
|
||||
if @content_type.include?("text/plain") # here maybe we should encode in 7bit??!!
|
||||
prepare_text(p, self.content_type, self.body)
|
||||
elsif self.content_type.include?("text/html")
|
||||
prepare_html(p, self.content_type, self.body)
|
||||
elsif self.content_type.include?("multipart")
|
||||
prepare_alternative(p, self.body)
|
||||
end
|
||||
m.parts << p
|
||||
else
|
||||
if @content_type.include?("text/plain") # here maybe we should encode in 7bit??!!
|
||||
prepare_text(m, self.content_type, self.body)
|
||||
elsif self.content_type.include?("text/html")
|
||||
prepare_html(m, self.content_type, self.body)
|
||||
elsif self.content_type.include?("multipart")
|
||||
prepare_alternative(m, self.body)
|
||||
end
|
||||
end
|
||||
# attachments
|
||||
@attachments.each { |a|
|
||||
m.parts << a.encoded
|
||||
}
|
||||
encmail = m.encoded
|
||||
RAILS_DEFAULT_LOGGER.debug("Sending message \n #{encmail}")
|
||||
Net::SMTP.start(ActionMailer::Base.smtp_settings[:address], ActionMailer::Base.smtp_settings[:port],
|
||||
ActionMailer::Base.smtp_settings[:domain], ActionMailer::Base.smtp_settings[:user_name],
|
||||
ActionMailer::Base.smtp_settings[:password], ActionMailer::Base.smtp_settings[:authentication]) do |smtp|
|
||||
smtp.sendmail(encmail, m.from, m.destinations)
|
||||
end
|
||||
return encmail
|
||||
end
|
||||
|
||||
def forward(tmail, fb)
|
||||
decoded_subject = mime_encoded?(tmail.subject) ? mime_decode(tmail.subject) : tmail.subject
|
||||
self.subject = "[Fwd: #{decoded_subject}]"
|
||||
attachment = CDF::Attachment.new(self)
|
||||
attachment.body(tmail, fb)
|
||||
end
|
||||
|
||||
def reply(tmail, fb, type)
|
||||
decoded_subject = mime_encoded?(tmail.subject) ? mime_decode(tmail.subject) : tmail.subject
|
||||
self.subject = "Re: #{decoded_subject}"
|
||||
tm = tmail.create_reply
|
||||
self.to = tm.to
|
||||
footer = ""
|
||||
msg_id = ""
|
||||
mt = MailTransform.new
|
||||
self.body = mt.get_body(tmail, type)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def delimeter
|
||||
if self.content_type == "text/plain"
|
||||
"\n"
|
||||
else
|
||||
"<br/>"
|
||||
end
|
||||
end
|
||||
|
||||
def text2html(str) CGI.escapeHTML(str).gsub("\n", "<br/>") end
|
||||
|
||||
def html2text(txt)
|
||||
clear_html(txt)
|
||||
end
|
||||
|
||||
def prepare_text(msg, ctype, bdy)
|
||||
msg.set_content_type(ctype, nil, {"charset"=>"utf-8"})
|
||||
msg.transfer_encoding = "8bit"
|
||||
msg.body = bdy
|
||||
end
|
||||
|
||||
def prepare_html(msg, ctype, bdy)
|
||||
msg.set_content_type(ctype, nil, {"charset"=>"utf8"})
|
||||
msg.transfer_encoding = "8bit"
|
||||
msg.body = bdy
|
||||
end
|
||||
|
||||
def prepare_alternative(msg, bdy)
|
||||
bound = ::TMail.new_boundary
|
||||
|
||||
msg.set_content_type("multipart/alternative", nil, {"charset"=>"utf8", "boundary"=>bound})
|
||||
msg.transfer_encoding = "8bit"
|
||||
|
||||
ptext = TMail::Mail.new(TMail::StringPort.new(""))
|
||||
phtml = TMail::Mail.new(TMail::StringPort.new(""))
|
||||
|
||||
prepare_text(ptext, "text/plain", html2text(bdy))
|
||||
prepare_html(phtml, "text/html", bdy)
|
||||
|
||||
msg.parts << ptext
|
||||
msg.parts << phtml
|
||||
end
|
||||
|
||||
def decode_addresses(str)
|
||||
ret = String.new
|
||||
str.split(",").each { |addr|
|
||||
if addr.slice(0,4) == "Grp+"
|
||||
grp_id = addr.scan(/Grp\+([0-9]*):(.*)/)[0][0]
|
||||
ContactGroup.find(:first, :conditions=>['customer_id = ? and id = ?', @customer_id, grp_id]).contacts.each { |contact|
|
||||
ret << "," if not(ret == "")
|
||||
@to_contacts << contact unless contact.nil?
|
||||
ret << contact.full_address
|
||||
ad, = quote_any_address_if_necessary(CDF::CONFIG[:mail_charset], contact.full_address)
|
||||
ret << ad
|
||||
}
|
||||
else
|
||||
ret << "," if not(ret == "")
|
||||
ad, = quote_any_address_if_necessary(CDF::CONFIG[:mail_charset], addr) if not(addr.nil? or addr == "")
|
||||
ret << ad if not(addr.nil? or addr == "")
|
||||
end
|
||||
} unless str.nil? or str.strip() == ""
|
||||
ret
|
||||
end
|
||||
end
|
||||
|
||||
class CDF::Attachment
|
||||
|
||||
def initialize(arg)
|
||||
@mail = arg
|
||||
@mail.add_attachment(self)
|
||||
@index = @mail.attachments.size - 1
|
||||
end
|
||||
|
||||
def filename=(arg)
|
||||
@filename = arg.tr('\\/:*?"\'<>|', '__________')
|
||||
end
|
||||
|
||||
def filename() @filename end
|
||||
|
||||
def temp_filename=(arg) @temp_filename = arg end
|
||||
|
||||
def temp_filename() @temp_filename end
|
||||
|
||||
def content_type=(arg) @content_type = arg end
|
||||
|
||||
def content_type() @content_type end
|
||||
|
||||
def delete_temp_data()
|
||||
File.delete(self.temp_filename)
|
||||
end
|
||||
|
||||
def file
|
||||
File.open(self.temp_filename, "rb") { |fp| fp.read }
|
||||
end
|
||||
|
||||
def file=(data)
|
||||
return if data.size == 0
|
||||
@content_type = data.content_type
|
||||
self.filename = data.original_filename.scan(/[^\\]*$/).first
|
||||
self.temp_filename = "#{@mail.temp_location}/#{@filename}"
|
||||
check_store_path
|
||||
data.rewind
|
||||
File.open(@temp_filename, "wb") { |f| f.write(data.read) }
|
||||
end
|
||||
|
||||
def body(data, fb)
|
||||
@content_type = "message/rfc822"
|
||||
filename = data.content_type['filename']
|
||||
self.filename = filename.nil? ? (mime_encoded?(data.subject) ? mime_decode(data.subject) : data.subject) : filename
|
||||
self.temp_filename = "#{@mail.temp_location}/#{@filename}"
|
||||
check_store_path
|
||||
File.open(@temp_filename, "wb") { |f| f.write(fb) }
|
||||
end
|
||||
|
||||
def check_store_path()
|
||||
path = ""
|
||||
"#{@mail.temp_location}".split(File::SEPARATOR).each { |p|
|
||||
path << p
|
||||
begin
|
||||
Dir.mkdir(path)
|
||||
rescue
|
||||
end
|
||||
path << File::SEPARATOR
|
||||
}
|
||||
end
|
||||
|
||||
def encoded
|
||||
p = TMail::Mail.new(TMail::StringPort.new(""))
|
||||
data = self.file
|
||||
p.body = data
|
||||
if @content_type.include?("text/plain") # here maybe we should encode in 7bit??!!
|
||||
p.set_content_type(@content_type, nil, {"charset"=>"utf-8"})
|
||||
p.transfer_encoding = "8bit"
|
||||
elsif @content_type.include?("text/html")
|
||||
p.set_content_type(@content_type, nil, {"charset"=>"utf8"})
|
||||
p.transfer_encoding = "8bit"
|
||||
elsif @content_type.include?("rfc822")
|
||||
p.set_content_type(@content_type, nil, {"charset"=>"utf8"})
|
||||
p.set_disposition("inline;")
|
||||
p.transfer_encoding = "8bit"
|
||||
else
|
||||
p.set_content_type(@content_type, nil, {"name"=>@filename})
|
||||
p.set_disposition("inline; filename=#{@filename}") unless @filename.nil?
|
||||
p.set_disposition("inline;") if @filename.nil?
|
||||
p.transfer_encoding='Base64'
|
||||
p.body = TMail::Base64.folding_encode(data)
|
||||
end
|
||||
return p
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
require 'maildropserializator'
|
||||
Customer.class_eval do
|
||||
include MaildropSerializator
|
||||
has_many :filters, :order => "order_num", :dependent => true
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
class Expression < ActiveRecord::Base
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
class Filter < ActiveRecord::Base
|
||||
has_many :expressions
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
require 'mail2screen'
|
||||
class ImapMessage < ActiveRecord::Base
|
||||
include Mail2Screen
|
||||
|
||||
def set_folder(folder)
|
||||
@folder = folder
|
||||
end
|
||||
|
||||
def full_body
|
||||
@folder.mailbox.imap.uid_fetch(uid, "BODY[]").first.attr["BODY[]"]
|
||||
end
|
||||
|
||||
def from_addr=(fa)
|
||||
self.from = fa.to_yaml
|
||||
self.from_flat = short_address(fa)
|
||||
end
|
||||
|
||||
def from_addr
|
||||
begin
|
||||
YAML::load(from)
|
||||
rescue Object
|
||||
from
|
||||
end
|
||||
end
|
||||
|
||||
def to_addr=(ta)
|
||||
self.to = ta.to_yaml
|
||||
self.to_flat = short_address(ta)
|
||||
end
|
||||
|
||||
def to_addr
|
||||
begin
|
||||
YAML::load(to)
|
||||
rescue Object
|
||||
to
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,526 +0,0 @@
|
|||
# Copyright (c) 2005, Benjamin Stiglitz
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# Modifications (c) 2005 by littlegreen
|
||||
#
|
||||
require 'net/imap'
|
||||
|
||||
Net::IMAP.debug = true if CDF::CONFIG[:debug_imap]
|
||||
|
||||
class Net::IMAP
|
||||
class PlainAuthenticator
|
||||
def process(data)
|
||||
return "\0#{@user}\0#{@password}"
|
||||
end
|
||||
|
||||
private
|
||||
def initialize(user, password)
|
||||
@user = user
|
||||
@password = password
|
||||
end
|
||||
end
|
||||
add_authenticator('PLAIN', PlainAuthenticator)
|
||||
|
||||
class Address
|
||||
def to_s
|
||||
if(name)
|
||||
"#{name} #{mailbox}@#{host}"
|
||||
else
|
||||
"#{mailbox}@#{host}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class AuthenticationError < RuntimeError
|
||||
end
|
||||
|
||||
class IMAPMailbox
|
||||
attr_reader :connected
|
||||
attr_accessor :selected_mailbox
|
||||
cattr_accessor :logger
|
||||
|
||||
def initialize(logger)
|
||||
@selected_mailbox = ''
|
||||
@folders = {}
|
||||
@connected = false
|
||||
@logger = logger
|
||||
end
|
||||
|
||||
def connect(username, password)
|
||||
#logger.debug "*** connect: @connected"
|
||||
unless @connected
|
||||
use_ssl = CDF::CONFIG[:imap_use_ssl] ? true : false
|
||||
port = CDF::CONFIG[:imap_port] || (use_ssl ? 993 : 143)
|
||||
# logger.debug "*** IMAP params: use_ssl => #{use_ssl}, port => #{port}"
|
||||
begin
|
||||
@imap = Net::IMAP.new(CDF::CONFIG[:imap_server], port, use_ssl)
|
||||
rescue Net::IMAP::ByeResponseError => bye
|
||||
# make a timeout and retry
|
||||
begin
|
||||
System.sleep(CDF::CONFIG[:imap_bye_timeout_retry_seconds])
|
||||
@imap = Net::IMAP.new(CDF::CONFIG[:imap_server], port, use_ssl)
|
||||
rescue Error => ex
|
||||
# logger.error "Error on authentication!"
|
||||
# logger.error bye.backtrace.join("\n")
|
||||
raise AuthenticationError.new
|
||||
end
|
||||
rescue Net::IMAP::NoResponseError => noresp
|
||||
# logger.error "Error on authentication!"
|
||||
# logger.error noresp.backtrace.join("\n")
|
||||
raise AuthenticationError.new
|
||||
rescue Net::IMAP::BadResponseError => bad
|
||||
# logger.error "Error on authentication!"
|
||||
# logger.error bad.backtrace.join("\n")
|
||||
raise AuthenticationError.new
|
||||
rescue Net::IMAP::ResponseError => resp
|
||||
# logger.error "Error on authentication!"
|
||||
# logger.error resp.backtrace.join("\n")
|
||||
raise AuthenticationError.new
|
||||
end
|
||||
@username = username
|
||||
begin
|
||||
# logger.error "IMAP authentication - #{CDF::CONFIG[:imap_auth]}."
|
||||
if CDF::CONFIG[:imap_auth] == 'NOAUTH'
|
||||
@imap.login(username, password)
|
||||
else
|
||||
@imap.authenticate(CDF::CONFIG[:imap_auth], username, password)
|
||||
end
|
||||
@connected = true
|
||||
rescue Exception => ex
|
||||
# logger.error "Error on authentication!"
|
||||
# logger.error ex.backtrace.join("\n")
|
||||
raise AuthenticationError.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def imap
|
||||
@imap
|
||||
end
|
||||
|
||||
# Function chnage password works only if root has run imap_backend
|
||||
# and users courier-authlib utility authtest - from courier-imap version 4.0.1
|
||||
def change_password(username, password, new_password)
|
||||
ret = ""
|
||||
cin, cout, cerr = Open3.popen3("/usr/sbin/authtest #{username} #{password} #{new_password}")
|
||||
ret << cerr.gets
|
||||
if ret.include?("Password change succeeded.")
|
||||
return true
|
||||
else
|
||||
logger.error "[!] Error on change password! - #{ret}"
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def disconnect
|
||||
if @connected
|
||||
@imap.logout
|
||||
#@imap.disconnect
|
||||
@imap = nil
|
||||
@connected = false
|
||||
end
|
||||
end
|
||||
|
||||
def [](mailboxname)
|
||||
@last_folder = IMAPFolderList.new(self, @username)[mailboxname]
|
||||
end
|
||||
|
||||
def folders
|
||||
# reference just to stop GC
|
||||
@folder_list ||= IMAPFolderList.new(self, @username)
|
||||
@folder_list
|
||||
end
|
||||
|
||||
def reload
|
||||
@folder_list.reload if @folder_list
|
||||
end
|
||||
|
||||
def create_folder(name)
|
||||
# begin
|
||||
@imap.create(Net::IMAP.encode_utf7(name))
|
||||
reload
|
||||
# rescue Exception=>e
|
||||
# end
|
||||
end
|
||||
|
||||
def delete_folder(name)
|
||||
begin
|
||||
@imap.delete(folders[name].utf7_name)
|
||||
reload
|
||||
rescue Exception=>e
|
||||
logger.error("Exception on delete #{name} folder #{e}")
|
||||
end
|
||||
end
|
||||
|
||||
def message_sent(message)
|
||||
# ensure we have sent folder
|
||||
begin
|
||||
@imap.create(CDF::CONFIG[:mail_sent])
|
||||
rescue Exception=>e
|
||||
end
|
||||
begin
|
||||
@imap.append(CDF::CONFIG[:mail_sent], message)
|
||||
folders[CDF::CONFIG[:mail_sent]].cached = false if folders[CDF::CONFIG[:mail_sent]]
|
||||
rescue Exception=>e
|
||||
logger.error("Error on append - #{e}")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def message_bulk(message)
|
||||
# ensure we have sent folder
|
||||
begin
|
||||
@imap.create(CDF::CONFIG[:mail_bulk_sent])
|
||||
rescue Exception=>e
|
||||
end
|
||||
begin
|
||||
@imap.append(CDF::CONFIG[:mail_bulk_sent], message)
|
||||
folders[CDF::CONFIG[:mail_sent]].cached = false if folders[CDF::CONFIG[:mail_bulk_sent]]
|
||||
rescue Exception=>e
|
||||
logger.error("Error on bulk - #{e}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class IMAPFolderList
|
||||
include Enumerable
|
||||
cattr_accessor :logger
|
||||
|
||||
def initialize(mailbox, username)
|
||||
@mailbox = mailbox
|
||||
@folders = Hash.new
|
||||
@username = username
|
||||
end
|
||||
|
||||
def each
|
||||
refresh if @folders.empty?
|
||||
#@folders.each_value { |folder| yield folder }
|
||||
# We want to allow sorted access; for now only (FIXME)
|
||||
|
||||
@folders.sort.each { |pair| yield pair.last }
|
||||
end
|
||||
|
||||
def reload
|
||||
refresh
|
||||
end
|
||||
|
||||
def [](name)
|
||||
refresh if @folders.empty?
|
||||
@folders[name]
|
||||
end
|
||||
|
||||
private
|
||||
def refresh
|
||||
@folders = {}
|
||||
result = @mailbox.imap.list('', '*')
|
||||
if result
|
||||
result.each do |info|
|
||||
folder = IMAPFolder.new(@mailbox, info.name, @username, info.attr, info.delim)
|
||||
@folders[folder.name] = folder
|
||||
end
|
||||
else
|
||||
# if there are no folders subscribe to INBOX - this is on first use
|
||||
@mailbox.imap.subscribe(CDF::CONFIG[:mail_inbox])
|
||||
# try again to list them - we should find INBOX
|
||||
@mailbox.imap.list('', '*').each do |info|
|
||||
@folders[info.name] = IMAPFolder.new(@mailbox, info.name, @username, info.attr, info.delim)
|
||||
end
|
||||
end
|
||||
@folders
|
||||
end
|
||||
end
|
||||
|
||||
class IMAPFolder
|
||||
attr_reader :mailbox
|
||||
attr_reader :name
|
||||
attr_reader :utf7_name
|
||||
attr_reader :username
|
||||
attr_reader :delim
|
||||
attr_reader :attribs
|
||||
|
||||
attr_writer :cached
|
||||
attr_writer :mcached
|
||||
|
||||
cattr_accessor :logger
|
||||
|
||||
@@fetch_attr = ['ENVELOPE','BODYSTRUCTURE', 'FLAGS', 'UID', 'RFC822.SIZE']
|
||||
|
||||
def initialize(mailbox, utf7_name, username, attribs, delim)
|
||||
@mailbox = mailbox
|
||||
@utf7_name = utf7_name
|
||||
@name = Net::IMAP.decode_utf7 utf7_name
|
||||
@username = username
|
||||
@messages = Array.new
|
||||
@delim = delim
|
||||
@attribs = attribs
|
||||
@cached = false
|
||||
@mcached = false
|
||||
end
|
||||
|
||||
def activate
|
||||
if(@mailbox.selected_mailbox != @name)
|
||||
@mailbox.selected_mailbox = @name
|
||||
@mailbox.imap.select(@utf7_name)
|
||||
load_total_unseen if !@cached
|
||||
end
|
||||
end
|
||||
|
||||
# Just delete message without interaction with Trash folder
|
||||
def delete(message)
|
||||
activate
|
||||
uid = (message.kind_of?(Integer) ? message : message.uid)
|
||||
@mailbox.imap.uid_store(uid, "+FLAGS", :Deleted)
|
||||
@mailbox.imap.expunge
|
||||
# Sync with trash cannot be made - new uid generated - so just delete message from current folder
|
||||
ImapMessage.delete_all(["username = ? and folder_name = ? and uid = ?", @username, @name, uid])
|
||||
@cached = false
|
||||
end
|
||||
|
||||
# Deleted messages - move to trash folder
|
||||
def delete_multiple(uids)
|
||||
# ensure we have trash folder
|
||||
begin
|
||||
@mailbox.imap.create(CDF::CONFIG[:mail_trash])
|
||||
rescue
|
||||
end
|
||||
move_multiple(uids, CDF::CONFIG[:mail_trash])
|
||||
end
|
||||
|
||||
def copy(message, dst_folder)
|
||||
uid = (message.kind_of?(Integer) ? message : message.uid)
|
||||
activate
|
||||
@mailbox.imap.uid_copy(uid, dst_folder)
|
||||
@mailbox.folders[dst_folder].cached = false if @mailbox.folders[dst_folder]
|
||||
@mailbox.folders[dst_folder].mcached = false if @mailbox.folders[dst_folder]
|
||||
end
|
||||
|
||||
def copy_multiple(message_uids, dst_folder)
|
||||
activate
|
||||
@mailbox.imap.uid_copy(message_uids, dst_folder)
|
||||
@mailbox.folders[dst_folder].cached = false if @mailbox.folders[dst_folder]
|
||||
@mailbox.folders[dst_folder].mcached = false if @mailbox.folders[dst_folder]
|
||||
end
|
||||
|
||||
def move(message, dst_folder)
|
||||
uid = (message.kind_of?(Integer) ? message : message.uid)
|
||||
activate
|
||||
@mailbox.imap.uid_copy(uid, dst_folder)
|
||||
@mailbox.imap.uid_store(uid, "+FLAGS", :Deleted)
|
||||
@mailbox.folders[dst_folder].cached = false if @mailbox.folders[dst_folder]
|
||||
@mailbox.folders[dst_folder].mcached = false if @mailbox.folders[dst_folder]
|
||||
@mailbox.imap.expunge
|
||||
ImapMessage.delete_all(["username = ? and folder_name = ? and uid = ? ", @username, @name, uid])
|
||||
@cached = false
|
||||
@mcached = false
|
||||
end
|
||||
|
||||
def move_multiple(message_uids, dst_folder)
|
||||
activate
|
||||
@mailbox.imap.uid_copy(message_uids, @mailbox.folders[dst_folder].utf7_name)
|
||||
@mailbox.imap.uid_store(message_uids, "+FLAGS", :Deleted)
|
||||
@mailbox.folders[dst_folder].cached = false if @mailbox.folders[dst_folder]
|
||||
@mailbox.folders[dst_folder].mcached = false if @mailbox.folders[dst_folder]
|
||||
@mailbox.imap.expunge
|
||||
ImapMessage.delete_all(["username = ? and folder_name = ? and uid in ( ? )", @username, @name, message_uids])
|
||||
@cached = false
|
||||
@mcached = false
|
||||
end
|
||||
|
||||
def mark_read(message_uid)
|
||||
activate
|
||||
cached = ImapMessage.find(:first, :conditions => ["username = ? and folder_name = ? and uid = ?", @username, @name, message_uid])
|
||||
if cached.unread
|
||||
cached.unread = false
|
||||
cached.save
|
||||
@mailbox.imap.select(@name)
|
||||
@mailbox.imap.uid_store(message_uid, "+FLAGS", :Seen)
|
||||
@unseen_messages = @unseen_messages - 1
|
||||
end
|
||||
end
|
||||
|
||||
def mark_unread(message_uid)
|
||||
activate
|
||||
cached = ImapMessage.find(:first, :conditions => ["username = ? and folder_name = ? and uid = ?", @username, @name, message_uid])
|
||||
if !cached.unread
|
||||
cached.unread = true
|
||||
cached.save
|
||||
@mailbox.imap.select(@name)
|
||||
@mailbox.imap.uid_store(message_uid, "-FLAGS", :Seen)
|
||||
@unseen_messages = @unseen_messages + 1
|
||||
end
|
||||
end
|
||||
|
||||
def expunge
|
||||
activate
|
||||
@mailbox.imap.expunge
|
||||
end
|
||||
|
||||
def synchronize_cache(offset=0, limit = 10)
|
||||
to = limit+offset
|
||||
startSync = Time.now
|
||||
activate
|
||||
startUidFetch = Time.now
|
||||
|
||||
#Count all messages
|
||||
count = @mailbox.imap.fetch(1..-1, "UID")
|
||||
to = count.size if count.size < to
|
||||
|
||||
|
||||
range = (offset..to)
|
||||
#logger.info range.inspect
|
||||
|
||||
server_messages = @mailbox.imap.fetch(range, "(UID FLAGS)")
|
||||
#server_messages = @mailbox.imap.uid_fetch(sequence_uids, ["UID", "FLAGS"])
|
||||
|
||||
startDbFetch = Time.now
|
||||
cached_messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name])
|
||||
|
||||
cached_unread_uids = Array.new
|
||||
cached_read_uids = Array.new
|
||||
uids_to_be_deleted = Array.new
|
||||
|
||||
cached_messages.each { |msg|
|
||||
cached_unread_uids << msg.uid if msg.unread
|
||||
cached_read_uids << msg.uid unless msg.unread
|
||||
uids_to_be_deleted << msg.uid
|
||||
}
|
||||
|
||||
uids_to_be_fetched = Array.new
|
||||
server_msg_uids = Array.new
|
||||
|
||||
uids_unread = Array.new
|
||||
uids_read = Array.new
|
||||
|
||||
server_messages.each { |server_msg|
|
||||
uid, flags = server_msg.attr['UID'], server_msg.attr['FLAGS']
|
||||
server_msg_uids << uid
|
||||
unless uids_to_be_deleted.include?(uid)
|
||||
uids_to_be_fetched << uid
|
||||
else
|
||||
if flags.member?(:Seen) && cached_unread_uids.include?(uid)
|
||||
uids_read << uid
|
||||
elsif !flags.member?(:Seen) && cached_read_uids.include?(uid)
|
||||
uids_unread << uid
|
||||
end
|
||||
end
|
||||
uids_to_be_deleted.delete(uid)
|
||||
} unless server_messages.nil?
|
||||
|
||||
ImapMessage.delete_all(["username = ? and folder_name = ? and uid in ( ? )", @username, @name, uids_to_be_deleted]) unless uids_to_be_deleted.empty?
|
||||
ImapMessage.update_all('unread = 0', ["username = ? and folder_name = ? and uid in ( ? )", @username, @name, uids_read]) unless uids_read.empty?
|
||||
ImapMessage.update_all('unread = 1', ["username = ? and folder_name = ? and uid in ( ? )", @username, @name, uids_unread]) unless uids_unread.empty?
|
||||
|
||||
|
||||
# fetch and store not cached messages
|
||||
unless uids_to_be_fetched.empty?
|
||||
# logger.debug("About to fetch #{uids_to_be_fetched.join(",")}")
|
||||
uids_to_be_fetched.each_slice(20) do |slice|
|
||||
fetch_uids(slice)
|
||||
end
|
||||
end
|
||||
#FIX: @mcached = true
|
||||
# logger.debug("Synchonization done for folder #{@name} in #{Time.now - startSync} ms.")
|
||||
end
|
||||
|
||||
def fetch_uids(uids)
|
||||
imapres = @mailbox.imap.uid_fetch(uids, @@fetch_attr)
|
||||
imapres.each { |cache|
|
||||
envelope = cache.attr['ENVELOPE'];
|
||||
message = ImapMessage.create( :folder_name => @name,
|
||||
:username => @username,
|
||||
:msg_id => envelope.message_id,
|
||||
:uid => cache.attr['UID'],
|
||||
:from_addr => envelope.from,
|
||||
:to_addr => envelope.to,
|
||||
:subject => envelope.subject,
|
||||
:content_type => cache.attr['BODYSTRUCTURE'].multipart? ? 'multipart' : 'text',
|
||||
:date => envelope.date,
|
||||
:unread => !(cache.attr['FLAGS'].member? :Seen),
|
||||
:size => cache.attr['RFC822.SIZE'])
|
||||
}
|
||||
end
|
||||
|
||||
def messages(offset = 0, limit = 10, sort = 'date desc')
|
||||
# Synchronize first retrieval time
|
||||
synchronize_cache(offset+1, limit) #unless @mcached
|
||||
|
||||
if limit == -1
|
||||
@messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name], :order => sort)
|
||||
else
|
||||
@messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name], :order => sort )
|
||||
end
|
||||
end
|
||||
|
||||
def messages_search(query = ["ALL"], sort = 'date desc')
|
||||
activate
|
||||
uids = @mailbox.imap.uid_search(query)
|
||||
if uids.size > 1
|
||||
ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ? and uid in ( ? )", @username, @name, uids], :order => sort )
|
||||
elsif uids.size == 1
|
||||
ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ? and uid = ? ", @username, @name, uids.first], :order => sort )
|
||||
else
|
||||
return Array.new
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def message(uid)
|
||||
activate
|
||||
message = ImapMessage.find(:first, :conditions => ["username = ? and folder_name = ? and uid = ?", @username, @name, uid])
|
||||
message.set_folder(self)
|
||||
message
|
||||
end
|
||||
|
||||
def unseen
|
||||
activate
|
||||
load_total_unseen if !@cached
|
||||
@unseen_messages
|
||||
end
|
||||
|
||||
def total
|
||||
activate
|
||||
load_total_unseen if !@cached
|
||||
@total_messages
|
||||
end
|
||||
|
||||
def load_total_unseen
|
||||
stat = @mailbox.imap.status(@utf7_name, ["MESSAGES", "UNSEEN"])
|
||||
@total_messages, @unseen_messages = stat["MESSAGES"], stat['UNSEEN']
|
||||
@cached = true
|
||||
end
|
||||
|
||||
def update_status
|
||||
@status ||= @mailbox.imap.status(@utf7_name, ["MESSAGES"])
|
||||
end
|
||||
|
||||
def subscribe
|
||||
@mailbox.imap.subscribe(@utf7_name)
|
||||
end
|
||||
|
||||
def trash?
|
||||
self.name == CDF::CONFIG[:mail_trash]
|
||||
end
|
||||
end
|
|
@ -1,171 +0,0 @@
|
|||
require 'cdfutils'
|
||||
module Mail2Screen
|
||||
def mail2html(mail, msg_id)
|
||||
footer = ""
|
||||
parsed_body = create_body(mail, msg_id, footer)
|
||||
|
||||
ret = "<table class='messageheader' border='0' cellpadding='0' cellspacing='0' >\n"
|
||||
ret << "<tbody>\n"
|
||||
ret << " <tr><td class='label' nowrap='nowrap'>#{t :from}:</td><td>#{address(mail.from_addrs, @msg_id)}</td></tr>\n"
|
||||
ret << " <tr><td class='label' nowrap='nowrap'>#{t :to}:</td><td>#{address(mail.to_addrs, @msg_id)}</td></tr>\n"
|
||||
if @mail.cc_addrs
|
||||
ret << " <tr><td class='label' nowrap='nowrap'>#{t :cc}:</td><td>#{address(mail.cc_addrs, @msg_id)}</td></tr>\n"
|
||||
end
|
||||
if @mail.bcc_addrs
|
||||
ret << " <tr><td class='label' nowrap='nowrap'>#{t :bcc}:</td><td>#{address(mail.bcc_addrs, @msg_id)}</td></tr>\n"
|
||||
end
|
||||
ret << " <tr><td class='label' nowrap='nowrap'>#{t :subject}:</td><td>#{h(mime_encoded?(mail.subject) ? mime_decode(mail.subject) : mail.subject)}</dd>\n"
|
||||
ret << " <tr><td class='label' nowrap='nowrap'>#{t :date}:</td><td>#{h message_date(mail.date)}</td></tr>\n"
|
||||
if footer != ''
|
||||
ret << " <tr><td class='label' nowrap='nowrap'>#{image_tag('attachment.png')}</td><td>#{footer}</td></tr>\n"
|
||||
end
|
||||
ret << " </tbody>\n"
|
||||
ret << "</table>\n"
|
||||
|
||||
ret << "<div class='msgpart'>\n"
|
||||
ret << parsed_body
|
||||
ret << "</div>\n"
|
||||
end
|
||||
|
||||
def create_body(mail, msg_id, footer)
|
||||
charset = (mail.charset.nil? ? 'iso-8859-1' : mail.charset)
|
||||
if mail.multipart?
|
||||
ret = ""
|
||||
if mail.content_type == 'multipart/alternative'
|
||||
# take only HTML part
|
||||
mail.parts.each { |part|
|
||||
if part.content_type == "text/html" or part.multipart?
|
||||
ret << create_body(part, msg_id, footer)
|
||||
end
|
||||
}
|
||||
return ret
|
||||
else
|
||||
mail.parts.each { |part|
|
||||
if part.multipart?
|
||||
ret << create_body(part, msg_id, footer)
|
||||
else
|
||||
footer << ", " if footer != ''
|
||||
footer << add_attachment(part.header['content-type'], msg_id)
|
||||
if part.content_type == "text/plain" or part.content_type.nil?
|
||||
charset = (part.charset.nil? ? charset : mail.charset)
|
||||
ret << add_text(part, part.transfer_encoding, charset)
|
||||
elsif part.content_type == "text/html"
|
||||
charset = (part.charset.nil? ? charset : mail.charset)
|
||||
ret << add_html(part, part.transfer_encoding, charset)
|
||||
elsif part.content_type.include?("image/")
|
||||
ctype = part.header['content-type']
|
||||
ret << add_image(ctype, msg_id)
|
||||
elsif part.content_type.include?("message/rfc822")
|
||||
ret << "<br/>#{_('Follows attached message')}:<hr/>" << mail2html(TMail::Mail.parse(part.body), msg_id)
|
||||
end
|
||||
end
|
||||
}
|
||||
return ret
|
||||
end
|
||||
else
|
||||
ret = ""
|
||||
if mail.content_type == "text/plain" or mail.content_type.nil?
|
||||
ret << add_text(mail, mail.transfer_encoding, charset)
|
||||
elsif mail.content_type == "text/html"
|
||||
ret << add_html(mail, mail.transfer_encoding, charset)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
def add_text(part, encoding, charset)
|
||||
CGI.escapeHTML(decode_part_text("#{part}", encoding, charset)).gsub(/\r\n/,"<br/>").gsub(/\r/, "<br/>").gsub(/\n/,"<br/>")
|
||||
end
|
||||
|
||||
def add_html(part, encoding, charset)
|
||||
strip_html(decode_part_text("#{part}", encoding, charset))
|
||||
end
|
||||
|
||||
def decode_part_text(part_str, encoding, charset)
|
||||
# Parse mail
|
||||
header, text = "", ""
|
||||
|
||||
# Get header and body
|
||||
#Content-type: text/plain; charset="ISO-8859-1"
|
||||
#Content-transfer-encoding: quoted-printable
|
||||
isBody = false
|
||||
part_str.each_line { |line|
|
||||
if isBody
|
||||
text << line
|
||||
else
|
||||
if line.strip == ""
|
||||
isBody = true
|
||||
else
|
||||
header << line
|
||||
end
|
||||
end
|
||||
}
|
||||
# Manage encoding
|
||||
if not(encoding.nil?) and encoding.downcase == "quoted-printable"
|
||||
ret = from_qp(text)
|
||||
elsif not(encoding.nil?) and encoding.downcase == "base64"
|
||||
ret = "#{text.unpack("m")}"
|
||||
else
|
||||
ret = text
|
||||
end
|
||||
# manage charset
|
||||
if ret.nil? or charset.nil? or charset.downcase == "utf-8"
|
||||
return ret
|
||||
else
|
||||
begin
|
||||
return Iconv.conv("UTF-8",charset.downcase, ret)
|
||||
rescue Exception => ex
|
||||
RAILS_DEFAULT_LOGGER.debug("Exception occured #{ex}\n#{ex.backtrace.join('\n')}")
|
||||
return ret
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_attachment(content_type, msg_id)
|
||||
filename = (content_type.nil? or content_type['name'].nil? ? "" : content_type['name'])
|
||||
if filename == ""
|
||||
""
|
||||
else
|
||||
"<span class='attachment'> <a href='/webmail/download?msg_id=#{msg_id}&ctype=" << CGI.escape(filename) << "'>#{filename}</a></span>"
|
||||
end
|
||||
end
|
||||
|
||||
def add_image(content_type, msg_id)
|
||||
filename = (content_type.nil? or content_type['name'].nil? ? "" : content_type['name'])
|
||||
"<hr/><span class='attachment'><br/><img src='/webmail/download?msg_id=#{msg_id}&ctype=" << CGI.escape(filename) << "' alt='#{filename}'/></span>"
|
||||
end
|
||||
|
||||
def friendly_address(addr)
|
||||
addr.kind_of?(Net::IMAP::Address) ? ((addr.name.nil? or addr.name.strip == "") ? "#{addr.mailbox}@#{addr.host}" : "#{(mime_encoded?(addr.name.strip) ? mime_decode(addr.name.to_s): addr.name.to_s)}<#{addr.mailbox}@#{addr.host}>") : ((addr.name.nil? or addr.name.strip == "") ? "#{addr.spec}" : "#{(mime_encoded?(addr.name.strip) ? mime_decode(addr.name.to_s): addr.name.to_s)}<#{addr.spec}>")
|
||||
end
|
||||
|
||||
def friendly_address_or_name(addr)
|
||||
if addr.kind_of?(Net::IMAP::Address)
|
||||
((addr.name.nil? or addr.name.to_s == "") ? "#{addr.mailbox}@#{addr.host}" : (mime_encoded?(addr.name.to_s) ? mime_decode(addr.name.to_s): addr.name.to_s))
|
||||
else
|
||||
((addr.nil? or addr.to_s == "") ? "#{addr.to_s}" : (mime_encoded?(addr.to_s) ? mime_decode(addr.to_s): addr.to_s))
|
||||
end
|
||||
end
|
||||
|
||||
def add_to_contact(addr, msg_id)
|
||||
" <a href='/contact/add_from_mail?cstr=#{CGI.escape(friendly_address(addr))}&retmsg=#{msg_id}'>"+t(:add_to_contacts)
|
||||
end
|
||||
|
||||
def short_address(addresses)
|
||||
ret = ""
|
||||
addresses.each { |addr| #split(/,\s*/)
|
||||
ret << "," unless ret == ""
|
||||
ret << CGI.escapeHTML(friendly_address_or_name(addr))
|
||||
} unless addresses.nil?
|
||||
ret
|
||||
end
|
||||
|
||||
def address(addresses, msg_id)
|
||||
ret = ""
|
||||
addresses.each { |addr| #split(/,\s*/)
|
||||
ret << "," unless ret == ""
|
||||
ret << CGI.escapeHTML(friendly_address_or_name(addr)) << add_to_contact(addr, msg_id)
|
||||
} unless addresses.nil?
|
||||
return ret
|
||||
end
|
||||
end
|
|
@ -1,75 +0,0 @@
|
|||
require 'mail2screen'
|
||||
|
||||
class MailTransform
|
||||
include Mail2Screen
|
||||
|
||||
def get_body(tmail, type)
|
||||
@mail = tmail
|
||||
footer = ""
|
||||
msg_id = ""
|
||||
ret = mail2html(tmail, msg_id)
|
||||
ret = ret.gsub(/<br\/>/,"\n").gsub(/ /, " ").gsub(/</, "<").gsub(/>/, ">").gsub(/&/, "&").gsub(/<hr\/>/, "\n").gsub(/\n/, "\n> ") if type == 'text/plain'
|
||||
ret = ret.gsub(/\r\n/,"<br/>").gsub(/\r/, "<br/>").gsub(/\n/,"<br/>").gsub(/<br\/>/, "<br/>> ") unless type == 'text/plain'
|
||||
return ret
|
||||
end
|
||||
|
||||
def mail2html(mail, msg_id)
|
||||
footer = ""
|
||||
parsed_body = create_body(mail, msg_id, footer)
|
||||
|
||||
ret = "-----Original Message-----\n#{_('From')}:#{address(mail.from_addrs, @msg_id)}\n"
|
||||
ret << "#{_('To')}:#{address(mail.to_addrs, @msg_id)}\n"
|
||||
if @mail.cc_addrs
|
||||
ret << " #{_('CC')}:#{address(mail.cc_addrs, @msg_id)}\n"
|
||||
end
|
||||
if @mail.bcc_addrs
|
||||
ret << "#{_('BCC')}:#{address(mail.bcc_addrs, @msg_id)}\n"
|
||||
end
|
||||
ret << "#{_('Subject')}:#{mime_encoded?(mail.subject) ? mime_decode(mail.subject) : mail.subject}\n"
|
||||
ret << "#{_('Date')}:#{message_date(mail.date)}\n"
|
||||
ret << "\n"
|
||||
ret << "\n"
|
||||
ret << parsed_body
|
||||
ret << "\n"
|
||||
end
|
||||
|
||||
def message_date(datestr)
|
||||
t = Time.now
|
||||
begin
|
||||
if datestr.kind_of?(String)
|
||||
d = (Time.rfc2822(datestr) rescue Time.parse(value)).localtime
|
||||
else
|
||||
d = datestr
|
||||
end
|
||||
if d.day == t.day and d.month == t.month and d.year == t.year
|
||||
d.strftime("%H:%M")
|
||||
else
|
||||
d.strftime("%Y-%m-%d")
|
||||
end
|
||||
rescue
|
||||
begin
|
||||
d = imap2time(datestr)
|
||||
if d.day == t.day and d.month == t.month and d.year == t.year
|
||||
d.strftime("%H:%M")
|
||||
else
|
||||
d.strftime("%Y-%m-%d")
|
||||
end
|
||||
rescue
|
||||
datestr
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Overwrite some staff
|
||||
def add_to_contact(addr, msg_id)
|
||||
""
|
||||
end
|
||||
def add_attachment(content_type, msg_id)
|
||||
""
|
||||
end
|
||||
|
||||
def add_image(content_type, msg_id)
|
||||
""
|
||||
end
|
||||
|
||||
end
|
|
@ -1,51 +0,0 @@
|
|||
module MaildropSerializator
|
||||
def serialize_to_file
|
||||
mail_drop_filter = File.new(self.mail_filter_path, "w")
|
||||
for filter in filters
|
||||
mail_drop_filter << "# filter '#{filter.name}'\n"
|
||||
mail_drop_filter << "if (#{filter_expressions(filter)})\n"
|
||||
mail_drop_filter << "{\n"
|
||||
mail_drop_filter << " exception {\n"
|
||||
mail_drop_filter << " to #{dest_folder(filter)}\n"
|
||||
mail_drop_filter << " }\n"
|
||||
mail_drop_filter << "}\n"
|
||||
end
|
||||
mail_drop_filter.close()
|
||||
end
|
||||
|
||||
private
|
||||
def dest_folder(filter)
|
||||
'$DEFAULT/'<<filter.destination_folder.sub(Regexp.new("(#{CDF::CONFIG[:mail_inbox]})(.*)"), '\2')<<"/"
|
||||
end
|
||||
|
||||
def escape_expr_value(text)
|
||||
text.gsub(".", "\\.").gsub("*", "\\*").gsub("[", "\\[").gsub("]", "\\]").gsub("(", "\\(").gsub(")", "\\)").
|
||||
gsub("?", "\\?")
|
||||
end
|
||||
|
||||
def filter_expressions(filter)
|
||||
fe = ""
|
||||
for exp in filter.expressions
|
||||
post_flag = "h"
|
||||
fe << " && " unless fe == ""
|
||||
if exp.field_name == "^Body"
|
||||
fe << "/"
|
||||
post_flag = "b"
|
||||
else
|
||||
fe << "/#{exp.field_name}:"
|
||||
end
|
||||
if exp.operator == 'contains'
|
||||
fe << ".*(#{escape_expr_value(exp.expr_value)})/"
|
||||
else
|
||||
# starts with
|
||||
fe << "[ ]*(#{escape_expr_value(exp.expr_value)}).*/"
|
||||
end
|
||||
if exp.case_sensitive == 1
|
||||
fe << "D" << post_flag
|
||||
else
|
||||
fe << post_flag
|
||||
end
|
||||
end
|
||||
fe
|
||||
end
|
||||
end
|
|
@ -1,4 +0,0 @@
|
|||
# Webmail mapping
|
||||
map.connect 'webmail', :controller => 'webmail/webmail', :action => 'messages'
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
class VirtualEmail < ActiveRecord::Base
|
||||
def self.table_name() "cdf.wm_virtual" end
|
||||
end
|
0
public/404.html
Executable file → Normal file
0
public/422.html
Executable file → Normal file
0
public/500.html
Executable file → Normal file
0
public/favicon.ico
Executable file → Normal file
Before Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 76 KiB |
0
themes/original/images/rails.png → public/images/rails.png
Executable file → Normal file
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
0
public/robots.txt
Executable file → Normal file
14
test/functional/core_controller_test.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'test_helper'
|
||||
|
||||
class CoreControllerTest < ActionController::TestCase
|
||||
test "should get login" do
|
||||
get :login
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get logout" do
|
||||
get :logout
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
end
|
0
test/performance/browsing_test.rb
Executable file → Normal file
0
test/test_helper.rb
Executable file → Normal file
4
test/unit/helpers/core_helper_test.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class CoreHelperTest < ActionView::TestCase
|
||||
end
|
0
themes/olive/README.olive
Normal file → Executable file
0
themes/olive/images/.gitkeep
Normal file → Executable file
0
themes/olive/images/key.png
Normal file → Executable file
Before Width: | Height: | Size: 612 B After Width: | Height: | Size: 612 B |
0
themes/olive/images/logo_small.png
Normal file → Executable file
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
0
themes/olive/javascripts/.gitkeep
Normal file → Executable file
2
themes/olive/javascripts/application.js
Executable file
|
@ -0,0 +1,2 @@
|
|||
// Place your application-specific JavaScript functions and classes here
|
||||
// This file is automatically included by javascript_include_tag :defaults
|
|
@ -1,52 +0,0 @@
|
|||
|
||||
var fieldTo = ""
|
||||
var fieldToc = ""
|
||||
var fieldCC = ""
|
||||
var fieldBCC = ""
|
||||
|
||||
function respondTo(str) {
|
||||
if (fieldTo == "") fieldTo += str
|
||||
else fieldTo += "," + str
|
||||
}
|
||||
|
||||
function respondTo(str, contactId) {
|
||||
if (fieldTo == "") fieldTo += str
|
||||
else fieldTo += "," + str
|
||||
|
||||
if (fieldToc == "") fieldToc += contactId
|
||||
else fieldToc += "," + contactId
|
||||
}
|
||||
|
||||
function respondCC(str) {
|
||||
if (fieldCC == "") fieldCC += str
|
||||
else fieldCC += "," + str
|
||||
}
|
||||
|
||||
function respondBCC(str) {
|
||||
if (fieldBCC == "") fieldBCC += str
|
||||
else fieldBCC += "," + str
|
||||
}
|
||||
|
||||
function respondToCaller() {
|
||||
if (window.opener) {
|
||||
doc = window.opener.document;
|
||||
setAddrField(getFormFieldPoint(doc, 'mail_to'), fieldTo);
|
||||
setAddrField(getFormFieldPoint(doc, 'mail_toc'), fieldToc);
|
||||
setAddrField(getFormFieldPoint(doc, 'mail_cc'), fieldCC);
|
||||
setAddrField(getFormFieldPoint(doc, 'mail_bcc'), fieldBCC);
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
function getFormFieldPoint(doc, id) {
|
||||
if ( doc.getElementById ) elem = doc.getElementById( id );
|
||||
else if ( doc.all ) elem = doc.eval( "document.all." + id );
|
||||
return elem
|
||||
}
|
||||
|
||||
function setAddrField(fld, value) {
|
||||
if (value != "") {
|
||||
if (fld.value == "") fld.value = value;
|
||||
else fld.value += "," + value;
|
||||
}
|
||||
}
|
965
themes/olive/javascripts/controls.js
vendored
Executable file
|
@ -0,0 +1,965 @@
|
|||
// script.aculo.us controls.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009
|
||||
|
||||
// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
||||
// (c) 2005-2009 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
|
||||
// (c) 2005-2009 Jon Tirsen (http://www.tirsen.com)
|
||||
// Contributors:
|
||||
// Richard Livsey
|
||||
// Rahul Bhargava
|
||||
// Rob Wills
|
||||
//
|
||||
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
||||
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
||||
|
||||
// Autocompleter.Base handles all the autocompletion functionality
|
||||
// that's independent of the data source for autocompletion. This
|
||||
// includes drawing the autocompletion menu, observing keyboard
|
||||
// and mouse events, and similar.
|
||||
//
|
||||
// Specific autocompleters need to provide, at the very least,
|
||||
// a getUpdatedChoices function that will be invoked every time
|
||||
// the text inside the monitored textbox changes. This method
|
||||
// should get the text for which to provide autocompletion by
|
||||
// invoking this.getToken(), NOT by directly accessing
|
||||
// this.element.value. This is to allow incremental tokenized
|
||||
// autocompletion. Specific auto-completion logic (AJAX, etc)
|
||||
// belongs in getUpdatedChoices.
|
||||
//
|
||||
// Tokenized incremental autocompletion is enabled automatically
|
||||
// when an autocompleter is instantiated with the 'tokens' option
|
||||
// in the options parameter, e.g.:
|
||||
// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
|
||||
// will incrementally autocomplete with a comma as the token.
|
||||
// Additionally, ',' in the above example can be replaced with
|
||||
// a token array, e.g. { tokens: [',', '\n'] } which
|
||||
// enables autocompletion on multiple tokens. This is most
|
||||
// useful when one of the tokens is \n (a newline), as it
|
||||
// allows smart autocompletion after linebreaks.
|
||||
|
||||
if(typeof Effect == 'undefined')
|
||||
throw("controls.js requires including script.aculo.us' effects.js library");
|
||||
|
||||
var Autocompleter = { };
|
||||
Autocompleter.Base = Class.create({
|
||||
baseInitialize: function(element, update, options) {
|
||||
element = $(element);
|
||||
this.element = element;
|
||||
this.update = $(update);
|
||||
this.hasFocus = false;
|
||||
this.changed = false;
|
||||
this.active = false;
|
||||
this.index = 0;
|
||||
this.entryCount = 0;
|
||||
this.oldElementValue = this.element.value;
|
||||
|
||||
if(this.setOptions)
|
||||
this.setOptions(options);
|
||||
else
|
||||
this.options = options || { };
|
||||
|
||||
this.options.paramName = this.options.paramName || this.element.name;
|
||||
this.options.tokens = this.options.tokens || [];
|
||||
this.options.frequency = this.options.frequency || 0.4;
|
||||
this.options.minChars = this.options.minChars || 1;
|
||||
this.options.onShow = this.options.onShow ||
|
||||
function(element, update){
|
||||
if(!update.style.position || update.style.position=='absolute') {
|
||||
update.style.position = 'absolute';
|
||||
Position.clone(element, update, {
|
||||
setHeight: false,
|
||||
offsetTop: element.offsetHeight
|
||||
});
|
||||
}
|
||||
Effect.Appear(update,{duration:0.15});
|
||||
};
|
||||
this.options.onHide = this.options.onHide ||
|
||||
function(element, update){ new Effect.Fade(update,{duration:0.15}) };
|
||||
|
||||
if(typeof(this.options.tokens) == 'string')
|
||||
this.options.tokens = new Array(this.options.tokens);
|
||||
// Force carriage returns as token delimiters anyway
|
||||
if (!this.options.tokens.include('\n'))
|
||||
this.options.tokens.push('\n');
|
||||
|
||||
this.observer = null;
|
||||
|
||||
this.element.setAttribute('autocomplete','off');
|
||||
|
||||
Element.hide(this.update);
|
||||
|
||||
Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
|
||||
Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
|
||||
},
|
||||
|
||||
show: function() {
|
||||
if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
|
||||
if(!this.iefix &&
|
||||
(Prototype.Browser.IE) &&
|
||||
(Element.getStyle(this.update, 'position')=='absolute')) {
|
||||
new Insertion.After(this.update,
|
||||
'<iframe id="' + this.update.id + '_iefix" '+
|
||||
'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
|
||||
'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
|
||||
this.iefix = $(this.update.id+'_iefix');
|
||||
}
|
||||
if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
|
||||
},
|
||||
|
||||
fixIEOverlapping: function() {
|
||||
Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
|
||||
this.iefix.style.zIndex = 1;
|
||||
this.update.style.zIndex = 2;
|
||||
Element.show(this.iefix);
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.stopIndicator();
|
||||
if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
|
||||
if(this.iefix) Element.hide(this.iefix);
|
||||
},
|
||||
|
||||
startIndicator: function() {
|
||||
if(this.options.indicator) Element.show(this.options.indicator);
|
||||
},
|
||||
|
||||
stopIndicator: function() {
|
||||
if(this.options.indicator) Element.hide(this.options.indicator);
|
||||
},
|
||||
|
||||
onKeyPress: function(event) {
|
||||
if(this.active)
|
||||
switch(event.keyCode) {
|
||||
case Event.KEY_TAB:
|
||||
case Event.KEY_RETURN:
|
||||
this.selectEntry();
|
||||
Event.stop(event);
|
||||
case Event.KEY_ESC:
|
||||
this.hide();
|
||||
this.active = false;
|
||||
Event.stop(event);
|
||||
return;
|
||||
case Event.KEY_LEFT:
|
||||
case Event.KEY_RIGHT:
|
||||
return;
|
||||
case Event.KEY_UP:
|
||||
this.markPrevious();
|
||||
this.render();
|
||||
Event.stop(event);
|
||||
return;
|
||||
case Event.KEY_DOWN:
|
||||
this.markNext();
|
||||
this.render();
|
||||
Event.stop(event);
|
||||
return;
|
||||
}
|
||||
else
|
||||
if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
|
||||
(Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
|
||||
|
||||
this.changed = true;
|
||||
this.hasFocus = true;
|
||||
|
||||
if(this.observer) clearTimeout(this.observer);
|
||||
this.observer =
|
||||
setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
this.changed = false;
|
||||
this.hasFocus = true;
|
||||
this.getUpdatedChoices();
|
||||
},
|
||||
|
||||
onHover: function(event) {
|
||||
var element = Event.findElement(event, 'LI');
|
||||
if(this.index != element.autocompleteIndex)
|
||||
{
|
||||
this.index = element.autocompleteIndex;
|
||||
this.render();
|
||||
}
|
||||
Event.stop(event);
|
||||
},
|
||||
|
||||
onClick: function(event) {
|
||||
var element = Event.findElement(event, 'LI');
|
||||
this.index = element.autocompleteIndex;
|
||||
this.selectEntry();
|
||||
this.hide();
|
||||
},
|
||||
|
||||
onBlur: function(event) {
|
||||
// needed to make click events working
|
||||
setTimeout(this.hide.bind(this), 250);
|
||||
this.hasFocus = false;
|
||||
this.active = false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
if(this.entryCount > 0) {
|
||||
for (var i = 0; i < this.entryCount; i++)
|
||||
this.index==i ?
|
||||
Element.addClassName(this.getEntry(i),"selected") :
|
||||
Element.removeClassName(this.getEntry(i),"selected");
|
||||
if(this.hasFocus) {
|
||||
this.show();
|
||||
this.active = true;
|
||||
}
|
||||
} else {
|
||||
this.active = false;
|
||||
this.hide();
|
||||
}
|
||||
},
|
||||
|
||||
markPrevious: function() {
|
||||
if(this.index > 0) this.index--;
|
||||
else this.index = this.entryCount-1;
|
||||
this.getEntry(this.index).scrollIntoView(true);
|
||||
},
|
||||
|
||||
markNext: function() {
|
||||
if(this.index < this.entryCount-1) this.index++;
|
||||
else this.index = 0;
|
||||
this.getEntry(this.index).scrollIntoView(false);
|
||||
},
|
||||
|
||||
getEntry: function(index) {
|
||||
return this.update.firstChild.childNodes[index];
|
||||
},
|
||||
|
||||
getCurrentEntry: function() {
|
||||
return this.getEntry(this.index);
|
||||
},
|
||||
|
||||
selectEntry: function() {
|
||||
this.active = false;
|
||||
this.updateElement(this.getCurrentEntry());
|
||||
},
|
||||
|
||||
updateElement: function(selectedElement) {
|
||||
if (this.options.updateElement) {
|
||||
this.options.updateElement(selectedElement);
|
||||
return;
|
||||
}
|
||||
var value = '';
|
||||
if (this.options.select) {
|
||||
var nodes = $(selectedElement).select('.' + this.options.select) || [];
|
||||
if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
|
||||
} else
|
||||
value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
|
||||
|
||||
var bounds = this.getTokenBounds();
|
||||
if (bounds[0] != -1) {
|
||||
var newValue = this.element.value.substr(0, bounds[0]);
|
||||
var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
|
||||
if (whitespace)
|
||||
newValue += whitespace[0];
|
||||
this.element.value = newValue + value + this.element.value.substr(bounds[1]);
|
||||
} else {
|
||||
this.element.value = value;
|
||||
}
|
||||
this.oldElementValue = this.element.value;
|
||||
this.element.focus();
|
||||
|
||||
if (this.options.afterUpdateElement)
|
||||
this.options.afterUpdateElement(this.element, selectedElement);
|
||||
},
|
||||
|
||||
updateChoices: function(choices) {
|
||||
if(!this.changed && this.hasFocus) {
|
||||
this.update.innerHTML = choices;
|
||||
Element.cleanWhitespace(this.update);
|
||||
Element.cleanWhitespace(this.update.down());
|
||||
|
||||
if(this.update.firstChild && this.update.down().childNodes) {
|
||||
this.entryCount =
|
||||
this.update.down().childNodes.length;
|
||||
for (var i = 0; i < this.entryCount; i++) {
|
||||
var entry = this.getEntry(i);
|
||||
entry.autocompleteIndex = i;
|
||||
this.addObservers(entry);
|
||||
}
|
||||
} else {
|
||||
this.entryCount = 0;
|
||||
}
|
||||
|
||||
this.stopIndicator();
|
||||
this.index = 0;
|
||||
|
||||
if(this.entryCount==1 && this.options.autoSelect) {
|
||||
this.selectEntry();
|
||||
this.hide();
|
||||
} else {
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addObservers: function(element) {
|
||||
Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
|
||||
Event.observe(element, "click", this.onClick.bindAsEventListener(this));
|
||||
},
|
||||
|
||||
onObserverEvent: function() {
|
||||
this.changed = false;
|
||||
this.tokenBounds = null;
|
||||
if(this.getToken().length>=this.options.minChars) {
|
||||
this.getUpdatedChoices();
|
||||
} else {
|
||||
this.active = false;
|
||||
this.hide();
|
||||
}
|
||||
this.oldElementValue = this.element.value;
|
||||
},
|
||||
|
||||
getToken: function() {
|
||||
var bounds = this.getTokenBounds();
|
||||
return this.element.value.substring(bounds[0], bounds[1]).strip();
|
||||
},
|
||||
|
||||
getTokenBounds: function() {
|
||||
if (null != this.tokenBounds) return this.tokenBounds;
|
||||
var value = this.element.value;
|
||||
if (value.strip().empty()) return [-1, 0];
|
||||
var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
|
||||
var offset = (diff == this.oldElementValue.length ? 1 : 0);
|
||||
var prevTokenPos = -1, nextTokenPos = value.length;
|
||||
var tp;
|
||||
for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
|
||||
tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
|
||||
if (tp > prevTokenPos) prevTokenPos = tp;
|
||||
tp = value.indexOf(this.options.tokens[index], diff + offset);
|
||||
if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;
|
||||
}
|
||||
return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
|
||||
}
|
||||
});
|
||||
|
||||
Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
|
||||
var boundary = Math.min(newS.length, oldS.length);
|
||||
for (var index = 0; index < boundary; ++index)
|
||||
if (newS[index] != oldS[index])
|
||||
return index;
|
||||
return boundary;
|
||||
};
|
||||
|
||||
Ajax.Autocompleter = Class.create(Autocompleter.Base, {
|
||||
initialize: function(element, update, url, options) {
|
||||
this.baseInitialize(element, update, options);
|
||||
this.options.asynchronous = true;
|
||||
this.options.onComplete = this.onComplete.bind(this);
|
||||
this.options.defaultParams = this.options.parameters || null;
|
||||
this.url = url;
|
||||
},
|
||||
|
||||
getUpdatedChoices: function() {
|
||||
this.startIndicator();
|
||||
|
||||
var entry = encodeURIComponent(this.options.paramName) + '=' +
|
||||
encodeURIComponent(this.getToken());
|
||||
|
||||
this.options.parameters = this.options.callback ?
|
||||
this.options.callback(this.element, entry) : entry;
|
||||
|
||||
if(this.options.defaultParams)
|
||||
this.options.parameters += '&' + this.options.defaultParams;
|
||||
|
||||
new Ajax.Request(this.url, this.options);
|
||||
},
|
||||
|
||||
onComplete: function(request) {
|
||||
this.updateChoices(request.responseText);
|
||||
}
|
||||
});
|
||||
|
||||
// The local array autocompleter. Used when you'd prefer to
|
||||
// inject an array of autocompletion options into the page, rather
|
||||
// than sending out Ajax queries, which can be quite slow sometimes.
|
||||
//
|
||||
// The constructor takes four parameters. The first two are, as usual,
|
||||
// the id of the monitored textbox, and id of the autocompletion menu.
|
||||
// The third is the array you want to autocomplete from, and the fourth
|
||||
// is the options block.
|
||||
//
|
||||
// Extra local autocompletion options:
|
||||
// - choices - How many autocompletion choices to offer
|
||||
//
|
||||
// - partialSearch - If false, the autocompleter will match entered
|
||||
// text only at the beginning of strings in the
|
||||
// autocomplete array. Defaults to true, which will
|
||||
// match text at the beginning of any *word* in the
|
||||
// strings in the autocomplete array. If you want to
|
||||
// search anywhere in the string, additionally set
|
||||
// the option fullSearch to true (default: off).
|
||||
//
|
||||
// - fullSsearch - Search anywhere in autocomplete array strings.
|
||||
//
|
||||
// - partialChars - How many characters to enter before triggering
|
||||
// a partial match (unlike minChars, which defines
|
||||
// how many characters are required to do any match
|
||||
// at all). Defaults to 2.
|
||||
//
|
||||
// - ignoreCase - Whether to ignore case when autocompleting.
|
||||
// Defaults to true.
|
||||
//
|
||||
// It's possible to pass in a custom function as the 'selector'
|
||||
// option, if you prefer to write your own autocompletion logic.
|
||||
// In that case, the other options above will not apply unless
|
||||
// you support them.
|
||||
|
||||
Autocompleter.Local = Class.create(Autocompleter.Base, {
|
||||
initialize: function(element, update, array, options) {
|
||||
this.baseInitialize(element, update, options);
|
||||
this.options.array = array;
|
||||
},
|
||||
|
||||
getUpdatedChoices: function() {
|
||||
this.updateChoices(this.options.selector(this));
|
||||
},
|
||||
|
||||
setOptions: function(options) {
|
||||
this.options = Object.extend({
|
||||
choices: 10,
|
||||
partialSearch: true,
|
||||
partialChars: 2,
|
||||
ignoreCase: true,
|
||||
fullSearch: false,
|
||||
selector: function(instance) {
|
||||
var ret = []; // Beginning matches
|
||||
var partial = []; // Inside matches
|
||||
var entry = instance.getToken();
|
||||
var count = 0;
|
||||
|
||||
for (var i = 0; i < instance.options.array.length &&
|
||||
ret.length < instance.options.choices ; i++) {
|
||||
|
||||
var elem = instance.options.array[i];
|
||||
var foundPos = instance.options.ignoreCase ?
|
||||
elem.toLowerCase().indexOf(entry.toLowerCase()) :
|
||||
elem.indexOf(entry);
|
||||
|
||||
while (foundPos != -1) {
|
||||
if (foundPos == 0 && elem.length != entry.length) {
|
||||
ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
|
||||
elem.substr(entry.length) + "</li>");
|
||||
break;
|
||||
} else if (entry.length >= instance.options.partialChars &&
|
||||
instance.options.partialSearch && foundPos != -1) {
|
||||
if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
|
||||
partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
|
||||
elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
|
||||
foundPos + entry.length) + "</li>");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foundPos = instance.options.ignoreCase ?
|
||||
elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
|
||||
elem.indexOf(entry, foundPos + 1);
|
||||
|
||||
}
|
||||
}
|
||||
if (partial.length)
|
||||
ret = ret.concat(partial.slice(0, instance.options.choices - ret.length));
|
||||
return "<ul>" + ret.join('') + "</ul>";
|
||||
}
|
||||
}, options || { });
|
||||
}
|
||||
});
|
||||
|
||||
// AJAX in-place editor and collection editor
|
||||
// Full rewrite by Christophe Porteneuve <tdd@tddsworld.com> (April 2007).
|
||||
|
||||
// Use this if you notice weird scrolling problems on some browsers,
|
||||
// the DOM might be a bit confused when this gets called so do this
|
||||
// waits 1 ms (with setTimeout) until it does the activation
|
||||
Field.scrollFreeActivate = function(field) {
|
||||
setTimeout(function() {
|
||||
Field.activate(field);
|
||||
}, 1);
|
||||
};
|
||||
|
||||
Ajax.InPlaceEditor = Class.create({
|
||||
initialize: function(element, url, options) {
|
||||
this.url = url;
|
||||
this.element = element = $(element);
|
||||
this.prepareOptions();
|
||||
this._controls = { };
|
||||
arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!!
|
||||
Object.extend(this.options, options || { });
|
||||
if (!this.options.formId && this.element.id) {
|
||||
this.options.formId = this.element.id + '-inplaceeditor';
|
||||
if ($(this.options.formId))
|
||||
this.options.formId = '';
|
||||
}
|
||||
if (this.options.externalControl)
|
||||
this.options.externalControl = $(this.options.externalControl);
|
||||
if (!this.options.externalControl)
|
||||
this.options.externalControlOnly = false;
|
||||
this._originalBackground = this.element.getStyle('background-color') || 'transparent';
|
||||
this.element.title = this.options.clickToEditText;
|
||||
this._boundCancelHandler = this.handleFormCancellation.bind(this);
|
||||
this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this);
|
||||
this._boundFailureHandler = this.handleAJAXFailure.bind(this);
|
||||
this._boundSubmitHandler = this.handleFormSubmission.bind(this);
|
||||
this._boundWrapperHandler = this.wrapUp.bind(this);
|
||||
this.registerListeners();
|
||||
},
|
||||
checkForEscapeOrReturn: function(e) {
|
||||
if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) return;
|
||||
if (Event.KEY_ESC == e.keyCode)
|
||||
this.handleFormCancellation(e);
|
||||
else if (Event.KEY_RETURN == e.keyCode)
|
||||
this.handleFormSubmission(e);
|
||||
},
|
||||
createControl: function(mode, handler, extraClasses) {
|
||||
var control = this.options[mode + 'Control'];
|
||||
var text = this.options[mode + 'Text'];
|
||||
if ('button' == control) {
|
||||
var btn = document.createElement('input');
|
||||
btn.type = 'submit';
|
||||
btn.value = text;
|
||||
btn.className = 'editor_' + mode + '_button';
|
||||
if ('cancel' == mode)
|
||||
btn.onclick = this._boundCancelHandler;
|
||||
this._form.appendChild(btn);
|
||||
this._controls[mode] = btn;
|
||||
} else if ('link' == control) {
|
||||
var link = document.createElement('a');
|
||||
link.href = '#';
|
||||
link.appendChild(document.createTextNode(text));
|
||||
link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler;
|
||||
link.className = 'editor_' + mode + '_link';
|
||||
if (extraClasses)
|
||||
link.className += ' ' + extraClasses;
|
||||
this._form.appendChild(link);
|
||||
this._controls[mode] = link;
|
||||
}
|
||||
},
|
||||
createEditField: function() {
|
||||
var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
|
||||
var fld;
|
||||
if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {
|
||||
fld = document.createElement('input');
|
||||
fld.type = 'text';
|
||||
var size = this.options.size || this.options.cols || 0;
|
||||
if (0 < size) fld.size = size;
|
||||
} else {
|
||||
fld = document.createElement('textarea');
|
||||
fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows);
|
||||
fld.cols = this.options.cols || 40;
|
||||
}
|
||||
fld.name = this.options.paramName;
|
||||
fld.value = text; // No HTML breaks conversion anymore
|
||||
fld.className = 'editor_field';
|
||||
if (this.options.submitOnBlur)
|
||||
fld.onblur = this._boundSubmitHandler;
|
||||
this._controls.editor = fld;
|
||||
if (this.options.loadTextURL)
|
||||
this.loadExternalText();
|
||||
this._form.appendChild(this._controls.editor);
|
||||
},
|
||||
createForm: function() {
|
||||
var ipe = this;
|
||||
function addText(mode, condition) {
|
||||
var text = ipe.options['text' + mode + 'Controls'];
|
||||
if (!text || condition === false) return;
|
||||
ipe._form.appendChild(document.createTextNode(text));
|
||||
};
|
||||
this._form = $(document.createElement('form'));
|
||||
this._form.id = this.options.formId;
|
||||
this._form.addClassName(this.options.formClassName);
|
||||
this._form.onsubmit = this._boundSubmitHandler;
|
||||
this.createEditField();
|
||||
if ('textarea' == this._controls.editor.tagName.toLowerCase())
|
||||
this._form.appendChild(document.createElement('br'));
|
||||
if (this.options.onFormCustomization)
|
||||
this.options.onFormCustomization(this, this._form);
|
||||
addText('Before', this.options.okControl || this.options.cancelControl);
|
||||
this.createControl('ok', this._boundSubmitHandler);
|
||||
addText('Between', this.options.okControl && this.options.cancelControl);
|
||||
this.createControl('cancel', this._boundCancelHandler, 'editor_cancel');
|
||||
addText('After', this.options.okControl || this.options.cancelControl);
|
||||
},
|
||||
destroy: function() {
|
||||
if (this._oldInnerHTML)
|
||||
this.element.innerHTML = this._oldInnerHTML;
|
||||
this.leaveEditMode();
|
||||
this.unregisterListeners();
|
||||
},
|
||||
enterEditMode: function(e) {
|
||||
if (this._saving || this._editing) return;
|
||||
this._editing = true;
|
||||
this.triggerCallback('onEnterEditMode');
|
||||
if (this.options.externalControl)
|
||||
this.options.externalControl.hide();
|
||||
this.element.hide();
|
||||
this.createForm();
|
||||
this.element.parentNode.insertBefore(this._form, this.element);
|
||||
if (!this.options.loadTextURL)
|
||||
this.postProcessEditField();
|
||||
if (e) Event.stop(e);
|
||||
},
|
||||
enterHover: function(e) {
|
||||
if (this.options.hoverClassName)
|
||||
this.element.addClassName(this.options.hoverClassName);
|
||||
if (this._saving) return;
|
||||
this.triggerCallback('onEnterHover');
|
||||
},
|
||||
getText: function() {
|
||||
return this.element.innerHTML.unescapeHTML();
|
||||
},
|
||||
handleAJAXFailure: function(transport) {
|
||||
this.triggerCallback('onFailure', transport);
|
||||
if (this._oldInnerHTML) {
|
||||
this.element.innerHTML = this._oldInnerHTML;
|
||||
this._oldInnerHTML = null;
|
||||
}
|
||||
},
|
||||
handleFormCancellation: function(e) {
|
||||
this.wrapUp();
|
||||
if (e) Event.stop(e);
|
||||
},
|
||||
handleFormSubmission: function(e) {
|
||||
var form = this._form;
|
||||
var value = $F(this._controls.editor);
|
||||
this.prepareSubmission();
|
||||
var params = this.options.callback(form, value) || '';
|
||||
if (Object.isString(params))
|
||||
params = params.toQueryParams();
|
||||
params.editorId = this.element.id;
|
||||
if (this.options.htmlResponse) {
|
||||
var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
|
||||
Object.extend(options, {
|
||||
parameters: params,
|
||||
onComplete: this._boundWrapperHandler,
|
||||
onFailure: this._boundFailureHandler
|
||||
});
|
||||
new Ajax.Updater({ success: this.element }, this.url, options);
|
||||
} else {
|
||||
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
|
||||
Object.extend(options, {
|
||||
parameters: params,
|
||||
onComplete: this._boundWrapperHandler,
|
||||
onFailure: this._boundFailureHandler
|
||||
});
|
||||
new Ajax.Request(this.url, options);
|
||||
}
|
||||
if (e) Event.stop(e);
|
||||
},
|
||||
leaveEditMode: function() {
|
||||
this.element.removeClassName(this.options.savingClassName);
|
||||
this.removeForm();
|
||||
this.leaveHover();
|
||||
this.element.style.backgroundColor = this._originalBackground;
|
||||
this.element.show();
|
||||
if (this.options.externalControl)
|
||||
this.options.externalControl.show();
|
||||
this._saving = false;
|
||||
this._editing = false;
|
||||
this._oldInnerHTML = null;
|
||||
this.triggerCallback('onLeaveEditMode');
|
||||
},
|
||||
leaveHover: function(e) {
|
||||
if (this.options.hoverClassName)
|
||||
this.element.removeClassName(this.options.hoverClassName);
|
||||
if (this._saving) return;
|
||||
this.triggerCallback('onLeaveHover');
|
||||
},
|
||||
loadExternalText: function() {
|
||||
this._form.addClassName(this.options.loadingClassName);
|
||||
this._controls.editor.disabled = true;
|
||||
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
|
||||
Object.extend(options, {
|
||||
parameters: 'editorId=' + encodeURIComponent(this.element.id),
|
||||
onComplete: Prototype.emptyFunction,
|
||||
onSuccess: function(transport) {
|
||||
this._form.removeClassName(this.options.loadingClassName);
|
||||
var text = transport.responseText;
|
||||
if (this.options.stripLoadedTextTags)
|
||||
text = text.stripTags();
|
||||
this._controls.editor.value = text;
|
||||
this._controls.editor.disabled = false;
|
||||
this.postProcessEditField();
|
||||
}.bind(this),
|
||||
onFailure: this._boundFailureHandler
|
||||
});
|
||||
new Ajax.Request(this.options.loadTextURL, options);
|
||||
},
|
||||
postProcessEditField: function() {
|
||||
var fpc = this.options.fieldPostCreation;
|
||||
if (fpc)
|
||||
$(this._controls.editor)['focus' == fpc ? 'focus' : 'activate']();
|
||||
},
|
||||
prepareOptions: function() {
|
||||
this.options = Object.clone(Ajax.InPlaceEditor.DefaultOptions);
|
||||
Object.extend(this.options, Ajax.InPlaceEditor.DefaultCallbacks);
|
||||
[this._extraDefaultOptions].flatten().compact().each(function(defs) {
|
||||
Object.extend(this.options, defs);
|
||||
}.bind(this));
|
||||
},
|
||||
prepareSubmission: function() {
|
||||
this._saving = true;
|
||||
this.removeForm();
|
||||
this.leaveHover();
|
||||
this.showSaving();
|
||||
},
|
||||
registerListeners: function() {
|
||||
this._listeners = { };
|
||||
var listener;
|
||||
$H(Ajax.InPlaceEditor.Listeners).each(function(pair) {
|
||||
listener = this[pair.value].bind(this);
|
||||
this._listeners[pair.key] = listener;
|
||||
if (!this.options.externalControlOnly)
|
||||
this.element.observe(pair.key, listener);
|
||||
if (this.options.externalControl)
|
||||
this.options.externalControl.observe(pair.key, listener);
|
||||
}.bind(this));
|
||||
},
|
||||
removeForm: function() {
|
||||
if (!this._form) return;
|
||||
this._form.remove();
|
||||
this._form = null;
|
||||
this._controls = { };
|
||||
},
|
||||
showSaving: function() {
|
||||
this._oldInnerHTML = this.element.innerHTML;
|
||||
this.element.innerHTML = this.options.savingText;
|
||||
this.element.addClassName(this.options.savingClassName);
|
||||
this.element.style.backgroundColor = this._originalBackground;
|
||||
this.element.show();
|
||||
},
|
||||
triggerCallback: function(cbName, arg) {
|
||||
if ('function' == typeof this.options[cbName]) {
|
||||
this.options[cbName](this, arg);
|
||||
}
|
||||
},
|
||||
unregisterListeners: function() {
|
||||
$H(this._listeners).each(function(pair) {
|
||||
if (!this.options.externalControlOnly)
|
||||
this.element.stopObserving(pair.key, pair.value);
|
||||
if (this.options.externalControl)
|
||||
this.options.externalControl.stopObserving(pair.key, pair.value);
|
||||
}.bind(this));
|
||||
},
|
||||
wrapUp: function(transport) {
|
||||
this.leaveEditMode();
|
||||
// Can't use triggerCallback due to backward compatibility: requires
|
||||
// binding + direct element
|
||||
this._boundComplete(transport, this.element);
|
||||
}
|
||||
});
|
||||
|
||||
Object.extend(Ajax.InPlaceEditor.prototype, {
|
||||
dispose: Ajax.InPlaceEditor.prototype.destroy
|
||||
});
|
||||
|
||||
Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, {
|
||||
initialize: function($super, element, url, options) {
|
||||
this._extraDefaultOptions = Ajax.InPlaceCollectionEditor.DefaultOptions;
|
||||
$super(element, url, options);
|
||||
},
|
||||
|
||||
createEditField: function() {
|
||||
var list = document.createElement('select');
|
||||
list.name = this.options.paramName;
|
||||
list.size = 1;
|
||||
this._controls.editor = list;
|
||||
this._collection = this.options.collection || [];
|
||||
if (this.options.loadCollectionURL)
|
||||
this.loadCollection();
|
||||
else
|
||||
this.checkForExternalText();
|
||||
this._form.appendChild(this._controls.editor);
|
||||
},
|
||||
|
||||
loadCollection: function() {
|
||||
this._form.addClassName(this.options.loadingClassName);
|
||||
this.showLoadingText(this.options.loadingCollectionText);
|
||||
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
|
||||
Object.extend(options, {
|
||||
parameters: 'editorId=' + encodeURIComponent(this.element.id),
|
||||
onComplete: Prototype.emptyFunction,
|
||||
onSuccess: function(transport) {
|
||||
var js = transport.responseText.strip();
|
||||
if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check
|
||||
throw('Server returned an invalid collection representation.');
|
||||
this._collection = eval(js);
|
||||
this.checkForExternalText();
|
||||
}.bind(this),
|
||||
onFailure: this.onFailure
|
||||
});
|
||||
new Ajax.Request(this.options.loadCollectionURL, options);
|
||||
},
|
||||
|
||||
showLoadingText: function(text) {
|
||||
this._controls.editor.disabled = true;
|
||||
var tempOption = this._controls.editor.firstChild;
|
||||
if (!tempOption) {
|
||||
tempOption = document.createElement('option');
|
||||
tempOption.value = '';
|
||||
this._controls.editor.appendChild(tempOption);
|
||||
tempOption.selected = true;
|
||||
}
|
||||
tempOption.update((text || '').stripScripts().stripTags());
|
||||
},
|
||||
|
||||
checkForExternalText: function() {
|
||||
this._text = this.getText();
|
||||
if (this.options.loadTextURL)
|
||||
this.loadExternalText();
|
||||
else
|
||||
this.buildOptionList();
|
||||
},
|
||||
|
||||
loadExternalText: function() {
|
||||
this.showLoadingText(this.options.loadingText);
|
||||
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
|
||||
Object.extend(options, {
|
||||
parameters: 'editorId=' + encodeURIComponent(this.element.id),
|
||||
onComplete: Prototype.emptyFunction,
|
||||
onSuccess: function(transport) {
|
||||
this._text = transport.responseText.strip();
|
||||
this.buildOptionList();
|
||||
}.bind(this),
|
||||
onFailure: this.onFailure
|
||||
});
|
||||
new Ajax.Request(this.options.loadTextURL, options);
|
||||
},
|
||||
|
||||
buildOptionList: function() {
|
||||
this._form.removeClassName(this.options.loadingClassName);
|
||||
this._collection = this._collection.map(function(entry) {
|
||||
return 2 === entry.length ? entry : [entry, entry].flatten();
|
||||
});
|
||||
var marker = ('value' in this.options) ? this.options.value : this._text;
|
||||
var textFound = this._collection.any(function(entry) {
|
||||
return entry[0] == marker;
|
||||
}.bind(this));
|
||||
this._controls.editor.update('');
|
||||
var option;
|
||||
this._collection.each(function(entry, index) {
|
||||
option = document.createElement('option');
|
||||
option.value = entry[0];
|
||||
option.selected = textFound ? entry[0] == marker : 0 == index;
|
||||
option.appendChild(document.createTextNode(entry[1]));
|
||||
this._controls.editor.appendChild(option);
|
||||
}.bind(this));
|
||||
this._controls.editor.disabled = false;
|
||||
Field.scrollFreeActivate(this._controls.editor);
|
||||
}
|
||||
});
|
||||
|
||||
//**** DEPRECATION LAYER FOR InPlace[Collection]Editor! ****
|
||||
//**** This only exists for a while, in order to let ****
|
||||
//**** users adapt to the new API. Read up on the new ****
|
||||
//**** API and convert your code to it ASAP! ****
|
||||
|
||||
Ajax.InPlaceEditor.prototype.initialize.dealWithDeprecatedOptions = function(options) {
|
||||
if (!options) return;
|
||||
function fallback(name, expr) {
|
||||
if (name in options || expr === undefined) return;
|
||||
options[name] = expr;
|
||||
};
|
||||
fallback('cancelControl', (options.cancelLink ? 'link' : (options.cancelButton ? 'button' :
|
||||
options.cancelLink == options.cancelButton == false ? false : undefined)));
|
||||
fallback('okControl', (options.okLink ? 'link' : (options.okButton ? 'button' :
|
||||
options.okLink == options.okButton == false ? false : undefined)));
|
||||
fallback('highlightColor', options.highlightcolor);
|
||||
fallback('highlightEndColor', options.highlightendcolor);
|
||||
};
|
||||
|
||||
Object.extend(Ajax.InPlaceEditor, {
|
||||
DefaultOptions: {
|
||||
ajaxOptions: { },
|
||||
autoRows: 3, // Use when multi-line w/ rows == 1
|
||||
cancelControl: 'link', // 'link'|'button'|false
|
||||
cancelText: 'cancel',
|
||||
clickToEditText: 'Click to edit',
|
||||
externalControl: null, // id|elt
|
||||
externalControlOnly: false,
|
||||
fieldPostCreation: 'activate', // 'activate'|'focus'|false
|
||||
formClassName: 'inplaceeditor-form',
|
||||
formId: null, // id|elt
|
||||
highlightColor: '#ffff99',
|
||||
highlightEndColor: '#ffffff',
|
||||
hoverClassName: '',
|
||||
htmlResponse: true,
|
||||
loadingClassName: 'inplaceeditor-loading',
|
||||
loadingText: 'Loading...',
|
||||
okControl: 'button', // 'link'|'button'|false
|
||||
okText: 'ok',
|
||||
paramName: 'value',
|
||||
rows: 1, // If 1 and multi-line, uses autoRows
|
||||
savingClassName: 'inplaceeditor-saving',
|
||||
savingText: 'Saving...',
|
||||
size: 0,
|
||||
stripLoadedTextTags: false,
|
||||
submitOnBlur: false,
|
||||
textAfterControls: '',
|
||||
textBeforeControls: '',
|
||||
textBetweenControls: ''
|
||||
},
|
||||
DefaultCallbacks: {
|
||||
callback: function(form) {
|
||||
return Form.serialize(form);
|
||||
},
|
||||
onComplete: function(transport, element) {
|
||||
// For backward compatibility, this one is bound to the IPE, and passes
|
||||
// the element directly. It was too often customized, so we don't break it.
|
||||
new Effect.Highlight(element, {
|
||||
startcolor: this.options.highlightColor, keepBackgroundImage: true });
|
||||
},
|
||||
onEnterEditMode: null,
|
||||
onEnterHover: function(ipe) {
|
||||
ipe.element.style.backgroundColor = ipe.options.highlightColor;
|
||||
if (ipe._effect)
|
||||
ipe._effect.cancel();
|
||||
},
|
||||
onFailure: function(transport, ipe) {
|
||||
alert('Error communication with the server: ' + transport.responseText.stripTags());
|
||||
},
|
||||
onFormCustomization: null, // Takes the IPE and its generated form, after editor, before controls.
|
||||
onLeaveEditMode: null,
|
||||
onLeaveHover: function(ipe) {
|
||||
ipe._effect = new Effect.Highlight(ipe.element, {
|
||||
startcolor: ipe.options.highlightColor, endcolor: ipe.options.highlightEndColor,
|
||||
restorecolor: ipe._originalBackground, keepBackgroundImage: true
|
||||
});
|
||||
}
|
||||
},
|
||||
Listeners: {
|
||||
click: 'enterEditMode',
|
||||
keydown: 'checkForEscapeOrReturn',
|
||||
mouseover: 'enterHover',
|
||||
mouseout: 'leaveHover'
|
||||
}
|
||||
});
|
||||
|
||||
Ajax.InPlaceCollectionEditor.DefaultOptions = {
|
||||
loadingCollectionText: 'Loading options...'
|
||||
};
|
||||
|
||||
// Delayed observer, like Form.Element.Observer,
|
||||
// but waits for delay after last key input
|
||||
// Ideal for live-search fields
|
||||
|
||||
Form.Element.DelayedObserver = Class.create({
|
||||
initialize: function(element, delay, callback) {
|
||||
this.delay = delay || 0.5;
|
||||
this.element = $(element);
|
||||
this.callback = callback;
|
||||
this.timer = null;
|
||||
this.lastValue = $F(this.element);
|
||||
Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
|
||||
},
|
||||
delayedListener: function(event) {
|
||||
if(this.lastValue == $F(this.element)) return;
|
||||
if(this.timer) clearTimeout(this.timer);
|
||||
this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000);
|
||||
this.lastValue = $F(this.element);
|
||||
},
|
||||
onTimerEvent: function() {
|
||||
this.timer = null;
|
||||
this.callback(this.element, $F(this.element));
|
||||
}
|
||||
});
|
974
themes/olive/javascripts/dragdrop.js
vendored
Executable file
|
@ -0,0 +1,974 @@
|
|||
// script.aculo.us dragdrop.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009
|
||||
|
||||
// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
||||
//
|
||||
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
||||
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
||||
|
||||
if(Object.isUndefined(Effect))
|
||||
throw("dragdrop.js requires including script.aculo.us' effects.js library");
|
||||
|
||||
var Droppables = {
|
||||
drops: [],
|
||||
|
||||
remove: function(element) {
|
||||
this.drops = this.drops.reject(function(d) { return d.element==$(element) });
|
||||
},
|
||||
|
||||
add: function(element) {
|
||||
element = $(element);
|
||||
var options = Object.extend({
|
||||
greedy: true,
|
||||
hoverclass: null,
|
||||
tree: false
|
||||
}, arguments[1] || { });
|
||||
|
||||
// cache containers
|
||||
if(options.containment) {
|
||||
options._containers = [];
|
||||
var containment = options.containment;
|
||||
if(Object.isArray(containment)) {
|
||||
containment.each( function(c) { options._containers.push($(c)) });
|
||||
} else {
|
||||
options._containers.push($(containment));
|
||||
}
|
||||
}
|
||||
|
||||
if(options.accept) options.accept = [options.accept].flatten();
|
||||
|
||||
Element.makePositioned(element); // fix IE
|
||||
options.element = element;
|
||||
|
||||
this.drops.push(options);
|
||||
},
|
||||
|
||||
findDeepestChild: function(drops) {
|
||||
deepest = drops[0];
|
||||
|
||||
for (i = 1; i < drops.length; ++i)
|
||||
if (Element.isParent(drops[i].element, deepest.element))
|
||||
deepest = drops[i];
|
||||
|
||||
return deepest;
|
||||
},
|
||||
|
||||
isContained: function(element, drop) {
|
||||
var containmentNode;
|
||||
if(drop.tree) {
|
||||
containmentNode = element.treeNode;
|
||||
} else {
|
||||
containmentNode = element.parentNode;
|
||||
}
|
||||
return drop._containers.detect(function(c) { return containmentNode == c });
|
||||
},
|
||||
|
||||
isAffected: function(point, element, drop) {
|
||||
return (
|
||||
(drop.element!=element) &&
|
||||
((!drop._containers) ||
|
||||
this.isContained(element, drop)) &&
|
||||
((!drop.accept) ||
|
||||
(Element.classNames(element).detect(
|
||||
function(v) { return drop.accept.include(v) } ) )) &&
|
||||
Position.within(drop.element, point[0], point[1]) );
|
||||
},
|
||||
|
||||
deactivate: function(drop) {
|
||||
if(drop.hoverclass)
|
||||
Element.removeClassName(drop.element, drop.hoverclass);
|
||||
this.last_active = null;
|
||||
},
|
||||
|
||||
activate: function(drop) {
|
||||
if(drop.hoverclass)
|
||||
Element.addClassName(drop.element, drop.hoverclass);
|
||||
this.last_active = drop;
|
||||
},
|
||||
|
||||
show: function(point, element) {
|
||||
if(!this.drops.length) return;
|
||||
var drop, affected = [];
|
||||
|
||||
this.drops.each( function(drop) {
|
||||
if(Droppables.isAffected(point, element, drop))
|
||||
affected.push(drop);
|
||||
});
|
||||
|
||||
if(affected.length>0)
|
||||
drop = Droppables.findDeepestChild(affected);
|
||||
|
||||
if(this.last_active && this.last_active != drop) this.deactivate(this.last_active);
|
||||
if (drop) {
|
||||
Position.within(drop.element, point[0], point[1]);
|
||||
if(drop.onHover)
|
||||
drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
|
||||
|
||||
if (drop != this.last_active) Droppables.activate(drop);
|
||||
}
|
||||
},
|
||||
|
||||
fire: function(event, element) {
|
||||
if(!this.last_active) return;
|
||||
Position.prepare();
|
||||
|
||||
if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active))
|
||||
if (this.last_active.onDrop) {
|
||||
this.last_active.onDrop(element, this.last_active.element, event);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
if(this.last_active)
|
||||
this.deactivate(this.last_active);
|
||||
}
|
||||
};
|
||||
|
||||
var Draggables = {
|
||||
drags: [],
|
||||
observers: [],
|
||||
|
||||
register: function(draggable) {
|
||||
if(this.drags.length == 0) {
|
||||
this.eventMouseUp = this.endDrag.bindAsEventListener(this);
|
||||
this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
|
||||
this.eventKeypress = this.keyPress.bindAsEventListener(this);
|
||||
|
||||
Event.observe(document, "mouseup", this.eventMouseUp);
|
||||
Event.observe(document, "mousemove", this.eventMouseMove);
|
||||
Event.observe(document, "keypress", this.eventKeypress);
|
||||
}
|
||||
this.drags.push(draggable);
|
||||
},
|
||||
|
||||
unregister: function(draggable) {
|
||||
this.drags = this.drags.reject(function(d) { return d==draggable });
|
||||
if(this.drags.length == 0) {
|
||||
Event.stopObserving(document, "mouseup", this.eventMouseUp);
|
||||
Event.stopObserving(document, "mousemove", this.eventMouseMove);
|
||||
Event.stopObserving(document, "keypress", this.eventKeypress);
|
||||
}
|
||||
},
|
||||
|
||||
activate: function(draggable) {
|
||||
if(draggable.options.delay) {
|
||||
this._timeout = setTimeout(function() {
|
||||
Draggables._timeout = null;
|
||||
window.focus();
|
||||
Draggables.activeDraggable = draggable;
|
||||
}.bind(this), draggable.options.delay);
|
||||
} else {
|
||||
window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
|
||||
this.activeDraggable = draggable;
|
||||
}
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
this.activeDraggable = null;
|
||||
},
|
||||
|
||||
updateDrag: function(event) {
|
||||
if(!this.activeDraggable) return;
|
||||
var pointer = [Event.pointerX(event), Event.pointerY(event)];
|
||||
// Mozilla-based browsers fire successive mousemove events with
|
||||
// the same coordinates, prevent needless redrawing (moz bug?)
|
||||
if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
|
||||
this._lastPointer = pointer;
|
||||
|
||||
this.activeDraggable.updateDrag(event, pointer);
|
||||
},
|
||||
|
||||
endDrag: function(event) {
|
||||
if(this._timeout) {
|
||||
clearTimeout(this._timeout);
|
||||
this._timeout = null;
|
||||
}
|
||||
if(!this.activeDraggable) return;
|
||||
this._lastPointer = null;
|
||||
this.activeDraggable.endDrag(event);
|
||||
this.activeDraggable = null;
|
||||
},
|
||||
|
||||
keyPress: function(event) {
|
||||
if(this.activeDraggable)
|
||||
this.activeDraggable.keyPress(event);
|
||||
},
|
||||
|
||||
addObserver: function(observer) {
|
||||
this.observers.push(observer);
|
||||
this._cacheObserverCallbacks();
|
||||
},
|
||||
|
||||
removeObserver: function(element) { // element instead of observer fixes mem leaks
|
||||
this.observers = this.observers.reject( function(o) { return o.element==element });
|
||||
this._cacheObserverCallbacks();
|
||||
},
|
||||
|
||||
notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag'
|
||||
if(this[eventName+'Count'] > 0)
|
||||
this.observers.each( function(o) {
|
||||
if(o[eventName]) o[eventName](eventName, draggable, event);
|
||||
});
|
||||
if(draggable.options[eventName]) draggable.options[eventName](draggable, event);
|
||||
},
|
||||
|
||||
_cacheObserverCallbacks: function() {
|
||||
['onStart','onEnd','onDrag'].each( function(eventName) {
|
||||
Draggables[eventName+'Count'] = Draggables.observers.select(
|
||||
function(o) { return o[eventName]; }
|
||||
).length;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
var Draggable = Class.create({
|
||||
initialize: function(element) {
|
||||
var defaults = {
|
||||
handle: false,
|
||||
reverteffect: function(element, top_offset, left_offset) {
|
||||
var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02;
|
||||
new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur,
|
||||
queue: {scope:'_draggable', position:'end'}
|
||||
});
|
||||
},
|
||||
endeffect: function(element) {
|
||||
var toOpacity = Object.isNumber(element._opacity) ? element._opacity : 1.0;
|
||||
new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
|
||||
queue: {scope:'_draggable', position:'end'},
|
||||
afterFinish: function(){
|
||||
Draggable._dragging[element] = false
|
||||
}
|
||||
});
|
||||
},
|
||||
zindex: 1000,
|
||||
revert: false,
|
||||
quiet: false,
|
||||
scroll: false,
|
||||
scrollSensitivity: 20,
|
||||
scrollSpeed: 15,
|
||||
snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] }
|
||||
delay: 0
|
||||
};
|
||||
|
||||
if(!arguments[1] || Object.isUndefined(arguments[1].endeffect))
|
||||
Object.extend(defaults, {
|
||||
starteffect: function(element) {
|
||||
element._opacity = Element.getOpacity(element);
|
||||
Draggable._dragging[element] = true;
|
||||
new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
|
||||
}
|
||||
});
|
||||
|
||||
var options = Object.extend(defaults, arguments[1] || { });
|
||||
|
||||
this.element = $(element);
|
||||
|
||||
if(options.handle && Object.isString(options.handle))
|
||||
this.handle = this.element.down('.'+options.handle, 0);
|
||||
|
||||
if(!this.handle) this.handle = $(options.handle);
|
||||
if(!this.handle) this.handle = this.element;
|
||||
|
||||
if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) {
|
||||
options.scroll = $(options.scroll);
|
||||
this._isScrollChild = Element.childOf(this.element, options.scroll);
|
||||
}
|
||||
|
||||
Element.makePositioned(this.element); // fix IE
|
||||
|
||||
this.options = options;
|
||||
this.dragging = false;
|
||||
|
||||
this.eventMouseDown = this.initDrag.bindAsEventListener(this);
|
||||
Event.observe(this.handle, "mousedown", this.eventMouseDown);
|
||||
|
||||
Draggables.register(this);
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
|
||||
Draggables.unregister(this);
|
||||
},
|
||||
|
||||
currentDelta: function() {
|
||||
return([
|
||||
parseInt(Element.getStyle(this.element,'left') || '0'),
|
||||
parseInt(Element.getStyle(this.element,'top') || '0')]);
|
||||
},
|
||||
|
||||
initDrag: function(event) {
|
||||
if(!Object.isUndefined(Draggable._dragging[this.element]) &&
|
||||
Draggable._dragging[this.element]) return;
|
||||
if(Event.isLeftClick(event)) {
|
||||
// abort on form elements, fixes a Firefox issue
|
||||
var src = Event.element(event);
|
||||
if((tag_name = src.tagName.toUpperCase()) && (
|
||||
tag_name=='INPUT' ||
|
||||
tag_name=='SELECT' ||
|
||||
tag_name=='OPTION' ||
|
||||
tag_name=='BUTTON' ||
|
||||
tag_name=='TEXTAREA')) return;
|
||||
|
||||
var pointer = [Event.pointerX(event), Event.pointerY(event)];
|
||||
var pos = this.element.cumulativeOffset();
|
||||
this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
|
||||
|
||||
Draggables.activate(this);
|
||||
Event.stop(event);
|
||||
}
|
||||
},
|
||||
|
||||
startDrag: function(event) {
|
||||
this.dragging = true;
|
||||
if(!this.delta)
|
||||
this.delta = this.currentDelta();
|
||||
|
||||
if(this.options.zindex) {
|
||||
this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
|
||||
this.element.style.zIndex = this.options.zindex;
|
||||
}
|
||||
|
||||
if(this.options.ghosting) {
|
||||
this._clone = this.element.cloneNode(true);
|
||||
this._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
|
||||
if (!this._originallyAbsolute)
|
||||
Position.absolutize(this.element);
|
||||
this.element.parentNode.insertBefore(this._clone, this.element);
|
||||
}
|
||||
|
||||
if(this.options.scroll) {
|
||||
if (this.options.scroll == window) {
|
||||
var where = this._getWindowScroll(this.options.scroll);
|
||||
this.originalScrollLeft = where.left;
|
||||
this.originalScrollTop = where.top;
|
||||
} else {
|
||||
this.originalScrollLeft = this.options.scroll.scrollLeft;
|
||||
this.originalScrollTop = this.options.scroll.scrollTop;
|
||||
}
|
||||
}
|
||||
|
||||
Draggables.notify('onStart', this, event);
|
||||
|
||||
if(this.options.starteffect) this.options.starteffect(this.element);
|
||||
},
|
||||
|
||||
updateDrag: function(event, pointer) {
|
||||
if(!this.dragging) this.startDrag(event);
|
||||
|
||||
if(!this.options.quiet){
|
||||
Position.prepare();
|
||||
Droppables.show(pointer, this.element);
|
||||
}
|
||||
|
||||
Draggables.notify('onDrag', this, event);
|
||||
|
||||
this.draw(pointer);
|
||||
if(this.options.change) this.options.change(this);
|
||||
|
||||
if(this.options.scroll) {
|
||||
this.stopScrolling();
|
||||
|
||||
var p;
|
||||
if (this.options.scroll == window) {
|
||||
with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; }
|
||||
} else {
|
||||
p = Position.page(this.options.scroll);
|
||||
p[0] += this.options.scroll.scrollLeft + Position.deltaX;
|
||||
p[1] += this.options.scroll.scrollTop + Position.deltaY;
|
||||
p.push(p[0]+this.options.scroll.offsetWidth);
|
||||
p.push(p[1]+this.options.scroll.offsetHeight);
|
||||
}
|
||||
var speed = [0,0];
|
||||
if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity);
|
||||
if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity);
|
||||
if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity);
|
||||
if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity);
|
||||
this.startScrolling(speed);
|
||||
}
|
||||
|
||||
// fix AppleWebKit rendering
|
||||
if(Prototype.Browser.WebKit) window.scrollBy(0,0);
|
||||
|
||||
Event.stop(event);
|
||||
},
|
||||
|
||||
finishDrag: function(event, success) {
|
||||
this.dragging = false;
|
||||
|
||||
if(this.options.quiet){
|
||||
Position.prepare();
|
||||
var pointer = [Event.pointerX(event), Event.pointerY(event)];
|
||||
Droppables.show(pointer, this.element);
|
||||
}
|
||||
|
||||
if(this.options.ghosting) {
|
||||
if (!this._originallyAbsolute)
|
||||
Position.relativize(this.element);
|
||||
delete this._originallyAbsolute;
|
||||
Element.remove(this._clone);
|
||||
this._clone = null;
|
||||
}
|
||||
|
||||
var dropped = false;
|
||||
if(success) {
|
||||
dropped = Droppables.fire(event, this.element);
|
||||
if (!dropped) dropped = false;
|
||||
}
|
||||
if(dropped && this.options.onDropped) this.options.onDropped(this.element);
|
||||
Draggables.notify('onEnd', this, event);
|
||||
|
||||
var revert = this.options.revert;
|
||||
if(revert && Object.isFunction(revert)) revert = revert(this.element);
|
||||
|
||||
var d = this.currentDelta();
|
||||
if(revert && this.options.reverteffect) {
|
||||
if (dropped == 0 || revert != 'failure')
|
||||
this.options.reverteffect(this.element,
|
||||
d[1]-this.delta[1], d[0]-this.delta[0]);
|
||||
} else {
|
||||
this.delta = d;
|
||||
}
|
||||
|
||||
if(this.options.zindex)
|
||||
this.element.style.zIndex = this.originalZ;
|
||||
|
||||
if(this.options.endeffect)
|
||||
this.options.endeffect(this.element);
|
||||
|
||||
Draggables.deactivate(this);
|
||||
Droppables.reset();
|
||||
},
|
||||
|
||||
keyPress: function(event) {
|
||||
if(event.keyCode!=Event.KEY_ESC) return;
|
||||
this.finishDrag(event, false);
|
||||
Event.stop(event);
|
||||
},
|
||||
|
||||
endDrag: function(event) {
|
||||
if(!this.dragging) return;
|
||||
this.stopScrolling();
|
||||
this.finishDrag(event, true);
|
||||
Event.stop(event);
|
||||
},
|
||||
|
||||
draw: function(point) {
|
||||
var pos = this.element.cumulativeOffset();
|
||||
if(this.options.ghosting) {
|
||||
var r = Position.realOffset(this.element);
|
||||
pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY;
|
||||
}
|
||||
|
||||
var d = this.currentDelta();
|
||||
pos[0] -= d[0]; pos[1] -= d[1];
|
||||
|
||||
if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) {
|
||||
pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
|
||||
pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
|
||||
}
|
||||
|
||||
var p = [0,1].map(function(i){
|
||||
return (point[i]-pos[i]-this.offset[i])
|
||||
}.bind(this));
|
||||
|
||||
if(this.options.snap) {
|
||||
if(Object.isFunction(this.options.snap)) {
|
||||
p = this.options.snap(p[0],p[1],this);
|
||||
} else {
|
||||
if(Object.isArray(this.options.snap)) {
|
||||
p = p.map( function(v, i) {
|
||||
return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this));
|
||||
} else {
|
||||
p = p.map( function(v) {
|
||||
return (v/this.options.snap).round()*this.options.snap }.bind(this));
|
||||
}
|
||||
}}
|
||||
|
||||
var style = this.element.style;
|
||||
if((!this.options.constraint) || (this.options.constraint=='horizontal'))
|
||||
style.left = p[0] + "px";
|
||||
if((!this.options.constraint) || (this.options.constraint=='vertical'))
|
||||
style.top = p[1] + "px";
|
||||
|
||||
if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
|
||||
},
|
||||
|
||||
stopScrolling: function() {
|
||||
if(this.scrollInterval) {
|
||||
clearInterval(this.scrollInterval);
|
||||
this.scrollInterval = null;
|
||||
Draggables._lastScrollPointer = null;
|
||||
}
|
||||
},
|
||||
|
||||
startScrolling: function(speed) {
|
||||
if(!(speed[0] || speed[1])) return;
|
||||
this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed];
|
||||
this.lastScrolled = new Date();
|
||||
this.scrollInterval = setInterval(this.scroll.bind(this), 10);
|
||||
},
|
||||
|
||||
scroll: function() {
|
||||
var current = new Date();
|
||||
var delta = current - this.lastScrolled;
|
||||
this.lastScrolled = current;
|
||||
if(this.options.scroll == window) {
|
||||
with (this._getWindowScroll(this.options.scroll)) {
|
||||
if (this.scrollSpeed[0] || this.scrollSpeed[1]) {
|
||||
var d = delta / 1000;
|
||||
this.options.scroll.scrollTo( left + d*this.scrollSpeed[0], top + d*this.scrollSpeed[1] );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000;
|
||||
this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000;
|
||||
}
|
||||
|
||||
Position.prepare();
|
||||
Droppables.show(Draggables._lastPointer, this.element);
|
||||
Draggables.notify('onDrag', this);
|
||||
if (this._isScrollChild) {
|
||||
Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer);
|
||||
Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000;
|
||||
Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000;
|
||||
if (Draggables._lastScrollPointer[0] < 0)
|
||||
Draggables._lastScrollPointer[0] = 0;
|
||||
if (Draggables._lastScrollPointer[1] < 0)
|
||||
Draggables._lastScrollPointer[1] = 0;
|
||||
this.draw(Draggables._lastScrollPointer);
|
||||
}
|
||||
|
||||
if(this.options.change) this.options.change(this);
|
||||
},
|
||||
|
||||
_getWindowScroll: function(w) {
|
||||
var T, L, W, H;
|
||||
with (w.document) {
|
||||
if (w.document.documentElement && documentElement.scrollTop) {
|
||||
T = documentElement.scrollTop;
|
||||
L = documentElement.scrollLeft;
|
||||
} else if (w.document.body) {
|
||||
T = body.scrollTop;
|
||||
L = body.scrollLeft;
|
||||
}
|
||||
if (w.innerWidth) {
|
||||
W = w.innerWidth;
|
||||
H = w.innerHeight;
|
||||
} else if (w.document.documentElement && documentElement.clientWidth) {
|
||||
W = documentElement.clientWidth;
|
||||
H = documentElement.clientHeight;
|
||||
} else {
|
||||
W = body.offsetWidth;
|
||||
H = body.offsetHeight;
|
||||
}
|
||||
}
|
||||
return { top: T, left: L, width: W, height: H };
|
||||
}
|
||||
});
|
||||
|
||||
Draggable._dragging = { };
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
var SortableObserver = Class.create({
|
||||
initialize: function(element, observer) {
|
||||
this.element = $(element);
|
||||
this.observer = observer;
|
||||
this.lastValue = Sortable.serialize(this.element);
|
||||
},
|
||||
|
||||
onStart: function() {
|
||||
this.lastValue = Sortable.serialize(this.element);
|
||||
},
|
||||
|
||||
onEnd: function() {
|
||||
Sortable.unmark();
|
||||
if(this.lastValue != Sortable.serialize(this.element))
|
||||
this.observer(this.element)
|
||||
}
|
||||
});
|
||||
|
||||
var Sortable = {
|
||||
SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/,
|
||||
|
||||
sortables: { },
|
||||
|
||||
_findRootElement: function(element) {
|
||||
while (element.tagName.toUpperCase() != "BODY") {
|
||||
if(element.id && Sortable.sortables[element.id]) return element;
|
||||
element = element.parentNode;
|
||||
}
|
||||
},
|
||||
|
||||
options: function(element) {
|
||||
element = Sortable._findRootElement($(element));
|
||||
if(!element) return;
|
||||
return Sortable.sortables[element.id];
|
||||
},
|
||||
|
||||
destroy: function(element){
|
||||
element = $(element);
|
||||
var s = Sortable.sortables[element.id];
|
||||
|
||||
if(s) {
|
||||
Draggables.removeObserver(s.element);
|
||||
s.droppables.each(function(d){ Droppables.remove(d) });
|
||||
s.draggables.invoke('destroy');
|
||||
|
||||
delete Sortable.sortables[s.element.id];
|
||||
}
|
||||
},
|
||||
|
||||
create: function(element) {
|
||||
element = $(element);
|
||||
var options = Object.extend({
|
||||
element: element,
|
||||
tag: 'li', // assumes li children, override with tag: 'tagname'
|
||||
dropOnEmpty: false,
|
||||
tree: false,
|
||||
treeTag: 'ul',
|
||||
overlap: 'vertical', // one of 'vertical', 'horizontal'
|
||||
constraint: 'vertical', // one of 'vertical', 'horizontal', false
|
||||
containment: element, // also takes array of elements (or id's); or false
|
||||
handle: false, // or a CSS class
|
||||
only: false,
|
||||
delay: 0,
|
||||
hoverclass: null,
|
||||
ghosting: false,
|
||||
quiet: false,
|
||||
scroll: false,
|
||||
scrollSensitivity: 20,
|
||||
scrollSpeed: 15,
|
||||
format: this.SERIALIZE_RULE,
|
||||
|
||||
// these take arrays of elements or ids and can be
|
||||
// used for better initialization performance
|
||||
elements: false,
|
||||
handles: false,
|
||||
|
||||
onChange: Prototype.emptyFunction,
|
||||
onUpdate: Prototype.emptyFunction
|
||||
}, arguments[1] || { });
|
||||
|
||||
// clear any old sortable with same element
|
||||
this.destroy(element);
|
||||
|
||||
// build options for the draggables
|
||||
var options_for_draggable = {
|
||||
revert: true,
|
||||
quiet: options.quiet,
|
||||
scroll: options.scroll,
|
||||
scrollSpeed: options.scrollSpeed,
|
||||
scrollSensitivity: options.scrollSensitivity,
|
||||
delay: options.delay,
|
||||
ghosting: options.ghosting,
|
||||
constraint: options.constraint,
|
||||
handle: options.handle };
|
||||
|
||||
if(options.starteffect)
|
||||
options_for_draggable.starteffect = options.starteffect;
|
||||
|
||||
if(options.reverteffect)
|
||||
options_for_draggable.reverteffect = options.reverteffect;
|
||||
else
|
||||
if(options.ghosting) options_for_draggable.reverteffect = function(element) {
|
||||
element.style.top = 0;
|
||||
element.style.left = 0;
|
||||
};
|
||||
|
||||
if(options.endeffect)
|
||||
options_for_draggable.endeffect = options.endeffect;
|
||||
|
||||
if(options.zindex)
|
||||
options_for_draggable.zindex = options.zindex;
|
||||
|
||||
// build options for the droppables
|
||||
var options_for_droppable = {
|
||||
overlap: options.overlap,
|
||||
containment: options.containment,
|
||||
tree: options.tree,
|
||||
hoverclass: options.hoverclass,
|
||||
onHover: Sortable.onHover
|
||||
};
|
||||
|
||||
var options_for_tree = {
|
||||
onHover: Sortable.onEmptyHover,
|
||||
overlap: options.overlap,
|
||||
containment: options.containment,
|
||||
hoverclass: options.hoverclass
|
||||
};
|
||||
|
||||
// fix for gecko engine
|
||||
Element.cleanWhitespace(element);
|
||||
|
||||
options.draggables = [];
|
||||
options.droppables = [];
|
||||
|
||||
// drop on empty handling
|
||||
if(options.dropOnEmpty || options.tree) {
|
||||
Droppables.add(element, options_for_tree);
|
||||
options.droppables.push(element);
|
||||
}
|
||||
|
||||
(options.elements || this.findElements(element, options) || []).each( function(e,i) {
|
||||
var handle = options.handles ? $(options.handles[i]) :
|
||||
(options.handle ? $(e).select('.' + options.handle)[0] : e);
|
||||
options.draggables.push(
|
||||
new Draggable(e, Object.extend(options_for_draggable, { handle: handle })));
|
||||
Droppables.add(e, options_for_droppable);
|
||||
if(options.tree) e.treeNode = element;
|
||||
options.droppables.push(e);
|
||||
});
|
||||
|
||||
if(options.tree) {
|
||||
(Sortable.findTreeElements(element, options) || []).each( function(e) {
|
||||
Droppables.add(e, options_for_tree);
|
||||
e.treeNode = element;
|
||||
options.droppables.push(e);
|
||||
});
|
||||
}
|
||||
|
||||
// keep reference
|
||||
this.sortables[element.identify()] = options;
|
||||
|
||||
// for onupdate
|
||||
Draggables.addObserver(new SortableObserver(element, options.onUpdate));
|
||||
|
||||
},
|
||||
|
||||
// return all suitable-for-sortable elements in a guaranteed order
|
||||
findElements: function(element, options) {
|
||||
return Element.findChildren(
|
||||
element, options.only, options.tree ? true : false, options.tag);
|
||||
},
|
||||
|
||||
findTreeElements: function(element, options) {
|
||||
return Element.findChildren(
|
||||
element, options.only, options.tree ? true : false, options.treeTag);
|
||||
},
|
||||
|
||||
onHover: function(element, dropon, overlap) {
|
||||
if(Element.isParent(dropon, element)) return;
|
||||
|
||||
if(overlap > .33 && overlap < .66 && Sortable.options(dropon).tree) {
|
||||
return;
|
||||
} else if(overlap>0.5) {
|
||||
Sortable.mark(dropon, 'before');
|
||||
if(dropon.previousSibling != element) {
|
||||
var oldParentNode = element.parentNode;
|
||||
element.style.visibility = "hidden"; // fix gecko rendering
|
||||
dropon.parentNode.insertBefore(element, dropon);
|
||||
if(dropon.parentNode!=oldParentNode)
|
||||
Sortable.options(oldParentNode).onChange(element);
|
||||
Sortable.options(dropon.parentNode).onChange(element);
|
||||
}
|
||||
} else {
|
||||
Sortable.mark(dropon, 'after');
|
||||
var nextElement = dropon.nextSibling || null;
|
||||
if(nextElement != element) {
|
||||
var oldParentNode = element.parentNode;
|
||||
element.style.visibility = "hidden"; // fix gecko rendering
|
||||
dropon.parentNode.insertBefore(element, nextElement);
|
||||
if(dropon.parentNode!=oldParentNode)
|
||||
Sortable.options(oldParentNode).onChange(element);
|
||||
Sortable.options(dropon.parentNode).onChange(element);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onEmptyHover: function(element, dropon, overlap) {
|
||||
var oldParentNode = element.parentNode;
|
||||
var droponOptions = Sortable.options(dropon);
|
||||
|
||||
if(!Element.isParent(dropon, element)) {
|
||||
var index;
|
||||
|
||||
var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only});
|
||||
var child = null;
|
||||
|
||||
if(children) {
|
||||
var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap);
|
||||
|
||||
for (index = 0; index < children.length; index += 1) {
|
||||
if (offset - Element.offsetSize (children[index], droponOptions.overlap) >= 0) {
|
||||
offset -= Element.offsetSize (children[index], droponOptions.overlap);
|
||||
} else if (offset - (Element.offsetSize (children[index], droponOptions.overlap) / 2) >= 0) {
|
||||
child = index + 1 < children.length ? children[index + 1] : null;
|
||||
break;
|
||||
} else {
|
||||
child = children[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dropon.insertBefore(element, child);
|
||||
|
||||
Sortable.options(oldParentNode).onChange(element);
|
||||
droponOptions.onChange(element);
|
||||
}
|
||||
},
|
||||
|
||||
unmark: function() {
|
||||
if(Sortable._marker) Sortable._marker.hide();
|
||||
},
|
||||
|
||||
mark: function(dropon, position) {
|
||||
// mark on ghosting only
|
||||
var sortable = Sortable.options(dropon.parentNode);
|
||||
if(sortable && !sortable.ghosting) return;
|
||||
|
||||
if(!Sortable._marker) {
|
||||
Sortable._marker =
|
||||
($('dropmarker') || Element.extend(document.createElement('DIV'))).
|
||||
hide().addClassName('dropmarker').setStyle({position:'absolute'});
|
||||
document.getElementsByTagName("body").item(0).appendChild(Sortable._marker);
|
||||
}
|
||||
var offsets = dropon.cumulativeOffset();
|
||||
Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'});
|
||||
|
||||
if(position=='after')
|
||||
if(sortable.overlap == 'horizontal')
|
||||
Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'});
|
||||
else
|
||||
Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'});
|
||||
|
||||
Sortable._marker.show();
|
||||
},
|
||||
|
||||
_tree: function(element, options, parent) {
|
||||
var children = Sortable.findElements(element, options) || [];
|
||||
|
||||
for (var i = 0; i < children.length; ++i) {
|
||||
var match = children[i].id.match(options.format);
|
||||
|
||||
if (!match) continue;
|
||||
|
||||
var child = {
|
||||
id: encodeURIComponent(match ? match[1] : null),
|
||||
element: element,
|
||||
parent: parent,
|
||||
children: [],
|
||||
position: parent.children.length,
|
||||
container: $(children[i]).down(options.treeTag)
|
||||
};
|
||||
|
||||
/* Get the element containing the children and recurse over it */
|
||||
if (child.container)
|
||||
this._tree(child.container, options, child);
|
||||
|
||||
parent.children.push (child);
|
||||
}
|
||||
|
||||
return parent;
|
||||
},
|
||||
|
||||
tree: function(element) {
|
||||
element = $(element);
|
||||
var sortableOptions = this.options(element);
|
||||
var options = Object.extend({
|
||||
tag: sortableOptions.tag,
|
||||
treeTag: sortableOptions.treeTag,
|
||||
only: sortableOptions.only,
|
||||
name: element.id,
|
||||
format: sortableOptions.format
|
||||
}, arguments[1] || { });
|
||||
|
||||
var root = {
|
||||
id: null,
|
||||
parent: null,
|
||||
children: [],
|
||||
container: element,
|
||||
position: 0
|
||||
};
|
||||
|
||||
return Sortable._tree(element, options, root);
|
||||
},
|
||||
|
||||
/* Construct a [i] index for a particular node */
|
||||
_constructIndex: function(node) {
|
||||
var index = '';
|
||||
do {
|
||||
if (node.id) index = '[' + node.position + ']' + index;
|
||||
} while ((node = node.parent) != null);
|
||||
return index;
|
||||
},
|
||||
|
||||
sequence: function(element) {
|
||||
element = $(element);
|
||||
var options = Object.extend(this.options(element), arguments[1] || { });
|
||||
|
||||
return $(this.findElements(element, options) || []).map( function(item) {
|
||||
return item.id.match(options.format) ? item.id.match(options.format)[1] : '';
|
||||
});
|
||||
},
|
||||
|
||||
setSequence: function(element, new_sequence) {
|
||||
element = $(element);
|
||||
var options = Object.extend(this.options(element), arguments[2] || { });
|
||||
|
||||
var nodeMap = { };
|
||||
this.findElements(element, options).each( function(n) {
|
||||
if (n.id.match(options.format))
|
||||
nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode];
|
||||
n.parentNode.removeChild(n);
|
||||
});
|
||||
|
||||
new_sequence.each(function(ident) {
|
||||
var n = nodeMap[ident];
|
||||
if (n) {
|
||||
n[1].appendChild(n[0]);
|
||||
delete nodeMap[ident];
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
serialize: function(element) {
|
||||
element = $(element);
|
||||
var options = Object.extend(Sortable.options(element), arguments[1] || { });
|
||||
var name = encodeURIComponent(
|
||||
(arguments[1] && arguments[1].name) ? arguments[1].name : element.id);
|
||||
|
||||
if (options.tree) {
|
||||
return Sortable.tree(element, arguments[1]).children.map( function (item) {
|
||||
return [name + Sortable._constructIndex(item) + "[id]=" +
|
||||
encodeURIComponent(item.id)].concat(item.children.map(arguments.callee));
|
||||
}).flatten().join('&');
|
||||
} else {
|
||||
return Sortable.sequence(element, arguments[1]).map( function(item) {
|
||||
return name + "[]=" + encodeURIComponent(item);
|
||||
}).join('&');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Returns true if child is contained within element
|
||||
Element.isParent = function(child, element) {
|
||||
if (!child.parentNode || child == element) return false;
|
||||
if (child.parentNode == element) return true;
|
||||
return Element.isParent(child.parentNode, element);
|
||||
};
|
||||
|
||||
Element.findChildren = function(element, only, recursive, tagName) {
|
||||
if(!element.hasChildNodes()) return null;
|
||||
tagName = tagName.toUpperCase();
|
||||
if(only) only = [only].flatten();
|
||||
var elements = [];
|
||||
$A(element.childNodes).each( function(e) {
|
||||
if(e.tagName && e.tagName.toUpperCase()==tagName &&
|
||||
(!only || (Element.classNames(e).detect(function(v) { return only.include(v) }))))
|
||||
elements.push(e);
|
||||
if(recursive) {
|
||||
var grandchildren = Element.findChildren(e, only, recursive, tagName);
|
||||
if(grandchildren) elements.push(grandchildren);
|
||||
}
|
||||
});
|
||||
|
||||
return (elements.length>0 ? elements.flatten() : []);
|
||||
};
|
||||
|
||||
Element.offsetSize = function (element, type) {
|
||||
return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')];
|
||||
};
|
1123
themes/olive/javascripts/effects.js
vendored
Executable file
|
@ -1,349 +0,0 @@
|
|||
// Copyright (c) 2005 Thomas Fuchs (http://mir.aculo.us)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
Effect2 = {}
|
||||
|
||||
/* ------------- transitions ------------- */
|
||||
|
||||
Effect2.Transitions = {}
|
||||
Effect2.Transitions.linear = function(pos) {
|
||||
return pos;
|
||||
}
|
||||
Effect2.Transitions.sinoidal = function(pos) {
|
||||
return (-Math.cos(pos*Math.PI)/2) + 0.5;
|
||||
}
|
||||
Effect2.Transitions.reverse = function(pos) {
|
||||
return 1-pos;
|
||||
}
|
||||
Effect2.Transitions.flicker = function(pos) {
|
||||
return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random(0.25);
|
||||
}
|
||||
Effect2.Transitions.wobble = function(pos) {
|
||||
return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
|
||||
}
|
||||
|
||||
/* ------------- core effects ------------- */
|
||||
|
||||
Effect2.Base = function() {};
|
||||
Effect2.Base.prototype = {
|
||||
setOptions: function(options) {
|
||||
this.options = {
|
||||
transition: Effect2.Transitions.sinoidal,
|
||||
duration: 1.0, // seconds
|
||||
fps: 25.0, // max. 100fps
|
||||
sync: false, // true for combining
|
||||
from: 0.0,
|
||||
to: 1.0
|
||||
}.extend(options || {});
|
||||
},
|
||||
start: function(options) {
|
||||
this.setOptions(options || {});
|
||||
this.currentFrame = 0;
|
||||
this.startOn = new Date().getTime();
|
||||
this.finishOn = this.startOn + (this.options.duration*1000);
|
||||
if(this.options.beforeStart) this.options.beforeStart(this);
|
||||
if(!this.options.sync) this.loop();
|
||||
},
|
||||
loop: function() {
|
||||
timePos = new Date().getTime();
|
||||
if(timePos >= this.finishOn) {
|
||||
this.render(this.options.to);
|
||||
if(this.finish) this.finish();
|
||||
if(this.options.afterFinish) this.options.afterFinish(this);
|
||||
return;
|
||||
}
|
||||
pos = (timePos - this.startOn) / (this.finishOn - this.startOn);
|
||||
frame = Math.round(pos * this.options.fps * this.options.duration);
|
||||
if(frame > this.currentFrame) {
|
||||
this.render(pos);
|
||||
this.currentFrame = frame;
|
||||
}
|
||||
this.timeout = setTimeout(this.loop.bind(this), 10);
|
||||
},
|
||||
render: function(pos) {
|
||||
if(this.options.transition) pos = this.options.transition(pos);
|
||||
pos = pos * (this.options.to-this.options.from);
|
||||
pos += this.options.from;
|
||||
if(this.options.beforeUpdate) this.options.beforeUpdate(this);
|
||||
if(this.update) this.update(pos);
|
||||
if(this.options.afterUpdate) this.options.afterUpdate(this);
|
||||
},
|
||||
cancel: function() {
|
||||
if(this.timeout) clearTimeout(this.timeout);
|
||||
}
|
||||
}
|
||||
|
||||
Effect2.Parallel = Class.create();
|
||||
Effect2.Parallel.prototype = (new Effect2.Base()).extend({
|
||||
initialize: function(effects) {
|
||||
this.effects = effects || [];
|
||||
this.start(arguments[1]);
|
||||
},
|
||||
update: function(position) {
|
||||
for (var i = 0; i < this.effects.length; i++)
|
||||
this.effects[i].render(position);
|
||||
},
|
||||
finish: function(position) {
|
||||
for (var i = 0; i < this.effects.length; i++)
|
||||
if(this.effects[i].finish) this.effects[i].finish(position);
|
||||
}
|
||||
});
|
||||
|
||||
Effect2.Opacity = Class.create();
|
||||
Effect2.Opacity.prototype = (new Effect2.Base()).extend({
|
||||
initialize: function() {
|
||||
this.element = $(arguments[0] || document.rootElement);
|
||||
options = {
|
||||
from: 0.0,
|
||||
to: 1.0
|
||||
}.extend(arguments[1] || {});
|
||||
this.start(options);
|
||||
},
|
||||
update: function(position) {
|
||||
this.setOpacity(position);
|
||||
},
|
||||
setOpacity: function(opacity) {
|
||||
opacity = (opacity == 1) ? 0.99999 : opacity;
|
||||
this.element.style.opacity = opacity;
|
||||
this.element.style.filter = "alpha(opacity:"+opacity*100+")";
|
||||
}
|
||||
});
|
||||
|
||||
Effect2.MoveBy = Class.create();
|
||||
Effect2.MoveBy.prototype = (new Effect2.Base()).extend({
|
||||
initialize: function(element, toTop, toLeft) {
|
||||
this.element = $(element);
|
||||
this.originalTop =
|
||||
this.element.style.top ? parseFloat(this.element.style.top) : 0;
|
||||
this.originalLeft =
|
||||
this.element.style.left ? parseFloat(this.element.style.left) : 0;
|
||||
this.toTop = toTop;
|
||||
this.toLeft = toLeft;
|
||||
if(this.element.style.position == "")
|
||||
this.element.style.position = "relative";
|
||||
this.start(arguments[3]);
|
||||
},
|
||||
update: function(position) {
|
||||
topd = this.toTop * position + this.originalTop;
|
||||
leftd = this.toLeft * position + this.originalLeft;
|
||||
this.setPosition(topd, leftd);
|
||||
},
|
||||
setPosition: function(topd, leftd) {
|
||||
this.element.style.top = topd + "px";
|
||||
this.element.style.left = leftd + "px";
|
||||
}
|
||||
});
|
||||
|
||||
Effect2.Scale = Class.create();
|
||||
Effect2.Scale.prototype = (new Effect2.Base()).extend({
|
||||
initialize: function(element, percent) {
|
||||
this.element = $(element)
|
||||
options = {
|
||||
scaleX: true,
|
||||
scaleY: true,
|
||||
scaleContent: true,
|
||||
scaleFromCenter: false,
|
||||
scaleMode: 'box', // 'box' or 'contents'
|
||||
scaleFrom: 100.0
|
||||
}.extend(arguments[2] || {});
|
||||
this.originalTop = this.element.offsetTop;
|
||||
this.originalLeft = this.element.offsetLeft;
|
||||
if (this.element.style.fontSize=="") this.sizeEm = 1.0;
|
||||
if (this.element.style.fontSize && this.element.style.fontSize.indexOf("em")>0)
|
||||
this.sizeEm = parseFloat(this.element.style.fontSize);
|
||||
this.factor = (percent/100.0) - (options.scaleFrom/100.0);
|
||||
if(options.scaleMode=='box') {
|
||||
this.originalHeight = this.element.clientHeight;
|
||||
this.originalWidth = this.element.clientWidth;
|
||||
} else
|
||||
if(options.scaleMode=='contents') {
|
||||
this.originalHeight = this.element.scrollHeight;
|
||||
this.originalWidth = this.element.scrollWidth;
|
||||
}
|
||||
this.start(options);
|
||||
},
|
||||
|
||||
update: function(position) {
|
||||
currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
|
||||
if(this.options.scaleContent && this.sizeEm)
|
||||
this.element.style.fontSize = this.sizeEm*currentScale + "em";
|
||||
this.setDimensions(
|
||||
this.originalWidth * currentScale,
|
||||
this.originalHeight * currentScale);
|
||||
},
|
||||
|
||||
setDimensions: function(width, height) {
|
||||
if(this.options.scaleX) this.element.style.width = width + 'px';
|
||||
if(this.options.scaleY) this.element.style.height = height + 'px';
|
||||
if(this.options.scaleFromCenter) {
|
||||
topd = (height - this.originalHeight)/2;
|
||||
leftd = (width - this.originalWidth)/2;
|
||||
if(this.element.style.position=='absolute') {
|
||||
if(this.options.scaleY) this.element.style.top = this.originalTop-topd + "px";
|
||||
if(this.options.scaleX) this.element.style.left = this.originalLeft-leftd + "px";
|
||||
} else {
|
||||
if(this.options.scaleY) this.element.style.top = -topd + "px";
|
||||
if(this.options.scaleX) this.element.style.left = -leftd + "px";
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* ------------- prepackaged effects ------------- */
|
||||
|
||||
Effect2.Fade = function(element) {
|
||||
options = {
|
||||
from: 1.0,
|
||||
to: 0.0,
|
||||
afterFinish: function(effect)
|
||||
{ Element.hide(effect.element);
|
||||
effect.setOpacity(1); }
|
||||
}.extend(arguments[1] || {});
|
||||
new Effect2.Opacity(element,options);
|
||||
}
|
||||
|
||||
Effect2.Appear = function(element) {
|
||||
options = {
|
||||
from: 0.0,
|
||||
to: 1.0,
|
||||
beforeStart: function(effect)
|
||||
{ effect.setOpacity(0);
|
||||
Element.show(effect.element); },
|
||||
afterUpdate: function(effect)
|
||||
{ Element.show(effect.element); }
|
||||
}.extend(arguments[1] || {});
|
||||
new Effect2.Opacity(element,options);
|
||||
}
|
||||
|
||||
Effect2.Puff = function(element) {
|
||||
new Effect2.Parallel(
|
||||
[ new Effect2.Scale(element, 200, { sync: true, scaleFromCenter: true }),
|
||||
new Effect2.Opacity(element, { sync: true, to: 0.0, from: 1.0 } ) ],
|
||||
{ duration: 1.0,
|
||||
afterUpdate: function(effect)
|
||||
{ effect.effects[0].element.style.position = 'absolute'; },
|
||||
afterFinish: function(effect)
|
||||
{ Element.hide(effect.effects[0].element); }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Effect2.BlindUp = function(element) {
|
||||
$(element).style.overflow = 'hidden';
|
||||
new Effect2.Scale(element, 0,
|
||||
{ scaleContent: false,
|
||||
scaleX: false,
|
||||
afterFinish: function(effect)
|
||||
{ Element.hide(effect.element) }
|
||||
}.extend(arguments[1] || {})
|
||||
);
|
||||
}
|
||||
|
||||
Effect2.BlindDown = function(element) {
|
||||
$(element).style.height = '0px';
|
||||
$(element).style.overflow = 'hidden';
|
||||
Element.show(element);
|
||||
new Effect2.Scale(element, 100,
|
||||
{ scaleContent: false,
|
||||
scaleX: false,
|
||||
scaleMode: 'contents',
|
||||
scaleFrom: 0
|
||||
}.extend(arguments[1] || {})
|
||||
);
|
||||
}
|
||||
|
||||
Effect2.SwitchOff = function(element) {
|
||||
new Effect2.Appear(element,
|
||||
{ duration: 0.4,
|
||||
transition: Effect2.Transitions.flicker,
|
||||
afterFinish: function(effect)
|
||||
{ effect.element.style.overflow = 'hidden';
|
||||
new Effect2.Scale(effect.element, 1,
|
||||
{ duration: 0.3, scaleFromCenter: true,
|
||||
scaleX: false, scaleContent: false,
|
||||
afterUpdate: function(effect) {
|
||||
if(effect.element.style.position=="")
|
||||
effect.element.style.position = 'relative'; },
|
||||
afterFinish: function(effect) { Element.hide(effect.element); }
|
||||
} )
|
||||
}
|
||||
} )
|
||||
}
|
||||
|
||||
Effect2.DropOut = function(element) {
|
||||
new Effect2.Parallel(
|
||||
[ new Effect2.MoveBy(element, 100, 0, { sync: true }),
|
||||
new Effect2.Opacity(element, { sync: true, to: 0.0, from: 1.0 } ) ],
|
||||
{ duration: 0.5,
|
||||
afterFinish: function(effect)
|
||||
{ Element.hide(effect.effects[0].element); }
|
||||
});
|
||||
}
|
||||
|
||||
Effect2.Shake = function(element) {
|
||||
new Effect2.MoveBy(element, 0, 20,
|
||||
{ duration: 0.05, afterFinish: function(effect) {
|
||||
new Effect2.MoveBy(effect.element, 0, -40,
|
||||
{ duration: 0.1, afterFinish: function(effect) {
|
||||
new Effect2.MoveBy(effect.element, 0, 40,
|
||||
{ duration: 0.1, afterFinish: function(effect) {
|
||||
new Effect2.MoveBy(effect.element, 0, -40,
|
||||
{ duration: 0.1, afterFinish: function(effect) {
|
||||
new Effect2.MoveBy(effect.element, 0, 40,
|
||||
{ duration: 0.1, afterFinish: function(effect) {
|
||||
new Effect2.MoveBy(effect.element, 0, -20,
|
||||
{ duration: 0.05, afterFinish: function(effect) {
|
||||
}}) }}) }}) }}) }}) }});
|
||||
}
|
||||
|
||||
Effect2.SlideDown = function(element) {
|
||||
$(element).style.height = '0px';
|
||||
$(element).style.overflow = 'hidden';
|
||||
$(element).firstChild.style.position = 'relative';
|
||||
Element.show(element);
|
||||
new Effect2.Scale(element, 100,
|
||||
{ scaleContent: false,
|
||||
scaleX: false,
|
||||
scaleMode: 'contents',
|
||||
scaleFrom: 0,
|
||||
afterUpdate: function(effect)
|
||||
{ effect.element.firstChild.style.bottom =
|
||||
(effect.originalHeight - effect.element.clientHeight) + 'px'; }
|
||||
}.extend(arguments[1] || {})
|
||||
);
|
||||
}
|
||||
|
||||
Effect2.SlideUp = function(element) {
|
||||
$(element).style.overflow = 'hidden';
|
||||
$(element).firstChild.style.position = 'relative';
|
||||
Element.show(element);
|
||||
new Effect2.Scale(element, 0,
|
||||
{ scaleContent: false,
|
||||
scaleX: false,
|
||||
afterUpdate: function(effect)
|
||||
{ effect.element.firstChild.style.bottom =
|
||||
(effect.originalHeight - effect.element.clientHeight) + 'px'; },
|
||||
afterFinish: function(effect)
|
||||
{ Element.hide(effect.element); }
|
||||
}.extend(arguments[1] || {})
|
||||
);
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
function changeLoc(loc) {
|
||||
window.location = loc
|
||||
}
|
||||
function getCookie(name) {
|
||||
var prefix = name + "=";
|
||||
var cStr = document.cookie;
|
||||
var start = cStr.indexOf(prefix);
|
||||
if (start == -1) {
|
||||
return null;
|
||||
}
|
||||
var end = cStr.indexOf(";", start + prefix.length);
|
||||
if (end == -1) {
|
||||
end = cStr.length;
|
||||
}
|
||||
var value = cStr.substring(start + prefix.length, end);
|
||||
return unescape(value);
|
||||
}
|
||||
function setCookie(name, value, expiration) {
|
||||
document.cookie = name + "=" + value + "; expires=" + expiration;
|
||||
}
|
||||
function toggleCheckbox(checkBox) {
|
||||
var element = document.getElementById(checkBox.id);
|
||||
if (element.value == "1" || element.checked) {
|
||||
element.checked = false;
|
||||
element.value = "0";
|
||||
} else {
|
||||
element.checked = true;
|
||||
element.value = "1";
|
||||
}
|
||||
}
|
||||
function toggleChkbox(checkBox) {
|
||||
if (checkBox.checked) {
|
||||
checkBox.checked = true;
|
||||
} else {
|
||||
checkBox.checked = false;
|
||||
}
|
||||
}
|
||||
function toggle_list(id) {
|
||||
ul = "ul_" + id;
|
||||
img = "img_" + id;
|
||||
hid = "h_" + id;
|
||||
ulElement = document.getElementById(ul);
|
||||
imgElement = document.getElementById(img);
|
||||
hiddenElement = document.getElementById(hid);
|
||||
if (ulElement) {
|
||||
if (ulElement.className == 'closed') {
|
||||
ulElement.className = "open";
|
||||
imgElement.src = "/themes/original/images/list_opened.gif";
|
||||
hiddenElement.value = "1"
|
||||
} else {
|
||||
ulElement.className = "closed";
|
||||
imgElement.src = "/themes/original/images/list_closed.gif";
|
||||
hiddenElement.value = "0"
|
||||
}
|
||||
}
|
||||
}
|
||||
function toggle_layer(id) {
|
||||
lElement = document.getElementById(id);
|
||||
imgElement = document.getElementById("img_" + id);
|
||||
if (lElement) {
|
||||
if (lElement.className == 'closed') {
|
||||
lElement.className = "open";
|
||||
imgElement.src = "/themes/original/images/list_opened.gif";
|
||||
return true;
|
||||
} else {
|
||||
lElement.className = "closed";
|
||||
imgElement.src = "/themes/original/images/list_closed.gif";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function toggle_layer_status(id) {
|
||||
lElement = document.getElementById(id);
|
||||
if (lElement) {
|
||||
if (lElement.className == 'closed') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function toggle_text(id) {
|
||||
if (document.getElementById) elem = document.getElementById(id);
|
||||
else if (document.all) elem = eval("document.all." + id);
|
||||
else return false;
|
||||
if (!elem) return true;
|
||||
elemStyle = elem.style;
|
||||
if (elemStyle.display != "block") {
|
||||
elemStyle.display = "block"
|
||||
} else {
|
||||
elemStyle.display = "none"
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function getFF(id) {
|
||||
if (document.getElementById) elem = document.getElementById(id);
|
||||
else if (document.all) elem = document.eval("document.all." + id);
|
||||
return elem
|
||||
}
|
||||
function setFF(id, value) {
|
||||
if (getFF(id)) getFF(id).value = value;
|
||||
}
|
||||
function setCFF(id) {
|
||||
if (getFF(id)) getFF(id).checked = true;
|
||||
}
|
||||
function updateSUFromC(btnName) {
|
||||
var suem = getCookie('_cdf_em');
|
||||
var sueg = getCookie('_cdf_gr');
|
||||
if (suem != "" && suem != null && suem != "undefined") {
|
||||
setFF('sup_email', suem);
|
||||
setFF('signup_submit_button', btnName);
|
||||
}
|
||||
if (sueg && sueg != "") {
|
||||
if (sueg.indexOf(",") < 0 && sueg != "") {
|
||||
gr_id = sueg;
|
||||
setCFF('supgr_' + gr_id);
|
||||
} else while ((i = sueg.indexOf(",")) >= 0) {
|
||||
gr_id = sueg.substring(0, i);
|
||||
sueg = sueg.substring(i + 1);
|
||||
setCFF('supgr_' + gr_id);
|
||||
}
|
||||
if (sueg.indexOf(",") < 0 && sueg != "") {
|
||||
gr_id = sueg;
|
||||
setCFF('supgr_' + gr_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
function updateLUEfC() {
|
||||
var suem = getCookie('_cdf_em');
|
||||
if (suem != "" && suem != null && suem != "undefined") {
|
||||
setFF('login_user_email', suem);
|
||||
}
|
||||
}
|
||||
function replaceHRFST(ifrm) {
|
||||
var o = ifrm;
|
||||
var w = null;
|
||||
if (o.contentWindow) {
|
||||
w = o.contentWindow;
|
||||
} else if (window.frames && window.frames[o.id].window) {
|
||||
w = window.frames[o.id];
|
||||
} else return;
|
||||
var doc = w.document;
|
||||
if (!doc.getElementsByTagName) return;
|
||||
var anchors = doc.getElementsByTagName("a");
|
||||
for (var i = 0; i < anchors.length; i++) {
|
||||
var anchor = anchors[i];
|
||||
if (anchor.getAttribute("href")) anchor.target = "_top";
|
||||
}
|
||||
iHeight = doc.body.scrollHeight;
|
||||
ifrm.style.height = iHeight + "px"
|
||||
}
|
||||
function rs(n, u, w, h, x) {
|
||||
args = "width=" + w + ",height=" + h + ",resizable=yes,scrollbars=yes,status=0";
|
||||
remote = window.open(u, n, args);
|
||||
if (remote != null && remote.opener == null) remote.opener = self;
|
||||
if (x == 1) return remote;
|
||||
}
|
||||
function wizard_step_onclick(direction, alt_url) {
|
||||
if (document.forms[0]) {
|
||||
direction_elem = '';
|
||||
if (document.getElementById) {
|
||||
direction_elem = document.getElementById('wiz_dir');
|
||||
} else if (document.all) {
|
||||
direction_elem = document.eval("document.all.wiz_dir");
|
||||
}
|
||||
if (direction_elem) {
|
||||
direction_elem.value = direction;
|
||||
}
|
||||
if (document.forms[0].onsubmit) {
|
||||
document.forms[0].onsubmit();
|
||||
}
|
||||
document.forms[0].submit();
|
||||
} else {
|
||||
window.location = alt_url;
|
||||
}
|
||||
}
|
||||
function toggle_adtype(ad_type) {
|
||||
toggle_text('upload_banner_label');
|
||||
toggle_text('upload_banner');
|
||||
toggle_text('radio1_label');
|
||||
toggle_text('radio1');
|
||||
toggle_text('radio2_label');
|
||||
toggle_text('radio2');
|
||||
toggle_text('adtitle_label');
|
||||
toggle_text('adtitle');
|
||||
toggle_text('adtext_label');
|
||||
toggle_text('adtext');
|
||||
toggle_text('banner_size_label');
|
||||
toggle_text('banner_size');
|
||||
}
|
||||
function show_date_as_local_time() {
|
||||
var spans = document.getElementsByTagName('span');
|
||||
for (var i = 0; i < spans.length; i++) if (spans[i].className.match(/\bLOCAL_TIME\b/i)) {
|
||||
system_date = new Date(Date.parse(spans[i].innerHTML));
|
||||
if (system_date.getHours() >= 12) {
|
||||
adds = ' PM';
|
||||
h = system_date.getHours() - 12;
|
||||
} else {
|
||||
adds = ' AM';
|
||||
h = system_date.getHours();
|
||||
}
|
||||
spans[i].innerHTML = h + ":" + (system_date.getMinutes() + "").replace(/\b(\d)\b/g, '0$1') + adds;
|
||||
}
|
||||
}
|
||||
function PopupPic(sPicURL, sWidth, sHeight) {
|
||||
window.open("/popup.htm?" + sPicURL, "", "resizable=1,HEIGHT=" + sHeight + ",WIDTH=" + sWidth + ",scrollbars=yes");
|
||||
}
|
||||
function open_link(target, location) {
|
||||
if (target == 'blank') {
|
||||
window.open(location);
|
||||
} else {
|
||||
window.top.location = location;
|
||||
}
|
||||
}
|
|
@ -1,201 +0,0 @@
|
|||
function changeLoc(loc) { window.location = loc }
|
||||
function getCookie(name) {
|
||||
var prefix = name + "=";
|
||||
var cStr = document.cookie;
|
||||
var start = cStr.indexOf(prefix);
|
||||
if (start==-1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var end = cStr.indexOf(";", start+prefix.length);
|
||||
if (end==-1) { end=cStr.length; }
|
||||
|
||||
var value=cStr.substring(start+prefix.length, end);
|
||||
return unescape(value);
|
||||
}
|
||||
function setCookie(name, value, expiration) {
|
||||
document.cookie = name+"="+value+"; expires="+expiration;
|
||||
}
|
||||
function toggleCheckbox(checkBox) {
|
||||
var element = document.getElementById(checkBox.id);
|
||||
if (element.value == "1" || element.checked) {
|
||||
element.checked = false;
|
||||
element.value = "0";
|
||||
} else {
|
||||
element.checked = true;
|
||||
element.value = "1";
|
||||
}
|
||||
}
|
||||
function toggleChkbox(checkBox) {
|
||||
if (checkBox.checked) {
|
||||
checkBox.checked = true;
|
||||
} else {
|
||||
checkBox.checked = false;
|
||||
}
|
||||
}
|
||||
function toggle_list(id){
|
||||
ul = "ul_" + id;
|
||||
img = "img_" + id;
|
||||
hid = "h_" + id;
|
||||
ulElement = document.getElementById(ul);
|
||||
imgElement = document.getElementById(img);
|
||||
hiddenElement = document.getElementById(hid);
|
||||
if (ulElement){
|
||||
if (ulElement.className == 'closed'){
|
||||
ulElement.className = "open";
|
||||
imgElement.src = "/themes/original/images/list_opened.gif";
|
||||
hiddenElement.value = "1"
|
||||
}else{
|
||||
ulElement.className = "closed";
|
||||
imgElement.src = "/themes/original/images/list_closed.gif";
|
||||
hiddenElement.value = "0"
|
||||
}
|
||||
}
|
||||
}
|
||||
function toggle_layer(id) {
|
||||
lElement = document.getElementById(id);
|
||||
imgElement = document.getElementById("img_" + id);
|
||||
if (lElement){
|
||||
if (lElement.className == 'closed'){
|
||||
lElement.className = "open";
|
||||
imgElement.src = "/themes/original/images/list_opened.gif";
|
||||
return true;
|
||||
}else{
|
||||
lElement.className = "closed";
|
||||
imgElement.src = "/themes/original/images/list_closed.gif";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function toggle_layer_status(id) {
|
||||
lElement = document.getElementById(id);
|
||||
if (lElement){
|
||||
if (lElement.className == 'closed'){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function toggle_text(id){
|
||||
if ( document.getElementById )
|
||||
elem = document.getElementById( id );
|
||||
else if ( document.all )
|
||||
elem = eval( "document.all." + id );
|
||||
else
|
||||
return false;
|
||||
|
||||
if(!elem) return true;
|
||||
|
||||
elemStyle = elem.style;
|
||||
if ( elemStyle.display != "block" ) {
|
||||
elemStyle.display = "block"
|
||||
} else {
|
||||
elemStyle.display = "none"
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function getFF(id) {
|
||||
if ( document.getElementById ) elem = document.getElementById( id );
|
||||
else if ( document.all ) elem = document.eval( "document.all." + id );
|
||||
return elem
|
||||
}
|
||||
function setFF(id, value) {if(getFF(id))getFF(id).value=value;}
|
||||
function setCFF(id) {if(getFF(id))getFF(id).checked=true;}
|
||||
function updateSUFromC(btnName) {
|
||||
var suem = getCookie('_cdf_em');var sueg = getCookie('_cdf_gr');
|
||||
if (suem != "" && suem != null && suem != "undefined") { setFF('sup_email', suem); setFF('signup_submit_button',btnName); }
|
||||
|
||||
if (sueg && sueg != "") {
|
||||
if (sueg.indexOf(",") < 0 && sueg != "") { gr_id = sueg; setCFF('supgr_'+gr_id);
|
||||
} else while ((i = sueg.indexOf(",")) >= 0) { gr_id = sueg.substring(0,i); sueg = sueg.substring(i+1); setCFF('supgr_'+gr_id); }
|
||||
if (sueg.indexOf(",") < 0 && sueg != "") { gr_id = sueg; setCFF('supgr_'+gr_id);}
|
||||
}
|
||||
}
|
||||
function updateLUEfC() {
|
||||
var suem = getCookie('_cdf_em');
|
||||
if (suem != "" && suem != null && suem != "undefined") { setFF('login_user_email', suem); }
|
||||
}
|
||||
function replaceHRFST(ifrm) {
|
||||
var o = ifrm;
|
||||
var w = null;
|
||||
if (o.contentWindow) {
|
||||
// For IE5.5 and IE6
|
||||
w = o.contentWindow;
|
||||
} else if (window.frames && window.frames[o.id].window) {
|
||||
w = window.frames[o.id];
|
||||
} else return;
|
||||
var doc = w.document;
|
||||
if (!doc.getElementsByTagName) return;
|
||||
var anchors = doc.getElementsByTagName("a");
|
||||
for (var i=0; i<anchors.length; i++) {
|
||||
var anchor = anchors[i];
|
||||
if (anchor.getAttribute("href")) anchor.target = "_top";
|
||||
}
|
||||
iHeight = doc.body.scrollHeight;
|
||||
ifrm.style.height = iHeight + "px"
|
||||
}
|
||||
function rs(n,u,w,h,x){
|
||||
args="width="+w+",height="+h+",resizable=yes,scrollbars=yes,status=0";
|
||||
remote=window.open(u,n,args);
|
||||
if(remote != null && remote.opener == null) remote.opener = self;
|
||||
if(x == 1) return remote;
|
||||
}
|
||||
function wizard_step_onclick(direction, alt_url) {
|
||||
if(document.forms[0]) {
|
||||
direction_elem='';
|
||||
|
||||
if ( document.getElementById ) {
|
||||
direction_elem = document.getElementById( 'wiz_dir' );
|
||||
} else if ( document.all ) {
|
||||
direction_elem = document.eval( "document.all.wiz_dir");
|
||||
}
|
||||
if(direction_elem) {
|
||||
direction_elem.value = direction;
|
||||
}
|
||||
if (document.forms[0].onsubmit) {
|
||||
document.forms[0].onsubmit();
|
||||
}
|
||||
document.forms[0].submit();
|
||||
} else {
|
||||
window.location=alt_url;
|
||||
}
|
||||
}
|
||||
function toggle_adtype(ad_type){
|
||||
toggle_text('upload_banner_label');
|
||||
toggle_text('upload_banner');
|
||||
toggle_text('radio1_label');
|
||||
toggle_text('radio1');
|
||||
toggle_text('radio2_label');
|
||||
toggle_text('radio2');
|
||||
toggle_text('adtitle_label');
|
||||
toggle_text('adtitle');
|
||||
toggle_text('adtext_label');
|
||||
toggle_text('adtext');
|
||||
toggle_text('banner_size_label');
|
||||
toggle_text('banner_size');
|
||||
|
||||
}
|
||||
function show_date_as_local_time() {
|
||||
var spans = document.getElementsByTagName('span');
|
||||
for (var i=0; i<spans.length; i++)
|
||||
if (spans[i].className.match(/\bLOCAL_TIME\b/i)) {
|
||||
system_date = new Date(Date.parse(spans[i].innerHTML));
|
||||
if (system_date.getHours() >= 12) { adds = ' PM'; h = system_date.getHours() - 12; }
|
||||
else { adds = ' AM'; h = system_date.getHours(); }
|
||||
spans[i].innerHTML = h + ":" + (system_date.getMinutes()+"").replace(/\b(\d)\b/g, '0$1') + adds;
|
||||
}
|
||||
}
|
||||
function PopupPic(sPicURL,sWidth,sHeight) {
|
||||
window.open( "/popup.htm?"+sPicURL, "", "resizable=1,HEIGHT="+sHeight+",WIDTH="+sWidth+",scrollbars=yes");
|
||||
}
|
||||
|
||||
function open_link(target, location){
|
||||
if (target == 'blank'){
|
||||
window.open(location);
|
||||
} else {
|
||||
window.top.location = location;
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
var config = new HTMLArea.Config(); // create a new configuration object
|
||||
// having all the default values
|
||||
config.width = '520px';
|
||||
config.pageStyle =
|
||||
'body { font-family: verdana,sans-serif; font-size: 12px } ';
|
||||
|
||||
config.toolbar = [
|
||||
[ "fontname", "fontsize","formatblock","bold", "italic", "underline", "separator", "insertimage", "createlink"],
|
||||
["justifyleft", "justifycenter", "justifyright", "justifyfull", "separator", "forecolor", "hilitecolor", "separator", "popupeditor", "htmlmode"]
|
||||
];
|
||||
config.statusBar = false;
|
||||
|
||||
var configView = new HTMLArea.Config(); // create a new configuration object
|
||||
// having all the default values
|
||||
configView.width = '670px';
|
||||
configView.pageStyle =
|
||||
'body { font-family: verdana,sans-serif; font-size: 12px } ';
|
||||
|
||||
configView.toolbar = [];
|
||||
configView.statusBar = false;
|
||||
configView.readonly = true;
|
|
@ -1,76 +0,0 @@
|
|||
#! /usr/bin/perl -w
|
||||
|
||||
jsTrim("prototype_src.js", "prototype.js");
|
||||
jsTrim("global_src.js", "global.js");
|
||||
#jsTrim("jscripts/tiny_mce/themes/simple/editor_template_src.js", "jscripts/tiny_mce/themes/simple/editor_template.js");
|
||||
#jsTrim("jscripts/tiny_mce/themes/default/editor_template_src.js", "jscripts/tiny_mce/themes/default/editor_template.js");
|
||||
#jsTrim("jscripts/tiny_mce/themes/advanced/editor_template_src.js", "jscripts/tiny_mce/themes/advanced/editor_template.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/advhr/editor_plugin_src.js", "jscripts/tiny_mce/plugins/advhr/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/advimage/editor_plugin_src.js", "jscripts/tiny_mce/plugins/advimage/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/advlink/editor_plugin_src.js", "jscripts/tiny_mce/plugins/advlink/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/emotions/editor_plugin_src.js", "jscripts/tiny_mce/plugins/emotions/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/flash/editor_plugin_src.js", "jscripts/tiny_mce/plugins/flash/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/iespell/editor_plugin_src.js", "jscripts/tiny_mce/plugins/iespell/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/insertdatetime/editor_plugin_src.js", "jscripts/tiny_mce/plugins/insertdatetime/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/preview/editor_plugin_src.js", "jscripts/tiny_mce/plugins/preview/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/print/editor_plugin_src.js", "jscripts/tiny_mce/plugins/print/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/save/editor_plugin_src.js", "jscripts/tiny_mce/plugins/save/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/searchreplace/editor_plugin_src.js", "jscripts/tiny_mce/plugins/searchreplace/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/zoom/editor_plugin_src.js", "jscripts/tiny_mce/plugins/zoom/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/table/editor_plugin_src.js", "jscripts/tiny_mce/plugins/table/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/contextmenu/editor_plugin_src.js", "jscripts/tiny_mce/plugins/contextmenu/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/paste/editor_plugin_src.js", "jscripts/tiny_mce/plugins/paste/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/fullscreen/editor_plugin_src.js", "jscripts/tiny_mce/plugins/fullscreen/editor_plugin.js");
|
||||
#jsTrim("jscripts/tiny_mce/plugins/directionality/editor_plugin_src.js", "jscripts/tiny_mce/plugins/directionality/editor_plugin.js");
|
||||
|
||||
sub jsTrim {
|
||||
my $inFile = $_[0];
|
||||
my $outFile = $_[1];
|
||||
my $comment = '';
|
||||
my $content = '';
|
||||
|
||||
# Load input file
|
||||
open(FILE, "<$inFile");
|
||||
undef $/;
|
||||
$content = <FILE>;
|
||||
close(FILE);
|
||||
|
||||
if ($content =~ s#^\s*(/\*.*?\*/)##s or $content =~ s#^\s*(//.*?)\n\s*[^/]##s) {
|
||||
$comment = "$1\n";
|
||||
}
|
||||
|
||||
local $^W;
|
||||
|
||||
# removing C/C++ - style comments:
|
||||
$content =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
|
||||
|
||||
# save string literals
|
||||
my @strings = ();
|
||||
$content =~ s/("(\\.|[^"\\])*"|'(\\.|[^'\\])*')/push(@strings, "$1");'__CMPRSTR_'.$#strings.'__';/egs;
|
||||
|
||||
# remove C-style comments
|
||||
$content =~ s#/\*.*?\*/##gs;
|
||||
# remove C++-style comments
|
||||
$content =~ s#//.*?\n##gs;
|
||||
# removing leading/trailing whitespace:
|
||||
#$content =~ s#(?:(?:^|\n)\s+|\s+(?:$|\n))##gs;
|
||||
# removing newlines:
|
||||
#$content =~ s#\r?\n##gs;
|
||||
|
||||
# removing other whitespace (between operators, etc.) (regexp-s stolen from Mike Hall's JS Crunchinator)
|
||||
$content =~ s/\s+/ /gs; # condensing whitespace
|
||||
#$content =~ s/^\s(.*)/$1/gs; # condensing whitespace
|
||||
#$content =~ s/(.*)\s$/$1/gs; # condensing whitespace
|
||||
$content =~ s/\s([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])/$1/gs;
|
||||
$content =~ s/([\x21\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5d\x5c\x7b\x7c\x7d\x7e])\s/$1/gs;
|
||||
|
||||
# restore string literals
|
||||
$content =~ s/__CMPRSTR_([0-9]+)__/$strings[$1]/egs;
|
||||
|
||||
# Write to ouput file
|
||||
open(FILE, ">$outFile");
|
||||
flock(FILE, 2);
|
||||
seek(FILE, 0, 2);
|
||||
print FILE $comment, $content;
|
||||
close(FILE);
|
||||
}
|
6001
themes/olive/javascripts/prototype.js
vendored
Executable file
521
themes/olive/javascripts/prototype_src.js
vendored
|
@ -1,521 +0,0 @@
|
|||
var Prototype = {
|
||||
Version: '1.2.1'
|
||||
};
|
||||
|
||||
var Class = {
|
||||
create: function() {
|
||||
return function() {
|
||||
this.initialize.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var Abstract = new Object();
|
||||
Object.prototype.extend = function(object) {
|
||||
for (property in object) {
|
||||
this[property] = object[property];
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Function.prototype.bind = function(object) {
|
||||
var method = this;
|
||||
return function() {
|
||||
method.apply(object, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
Function.prototype.bindAsEventListener = function(object) {
|
||||
var method = this;
|
||||
return function(event) {
|
||||
method.call(object, event || window.event);
|
||||
}
|
||||
};
|
||||
|
||||
Number.prototype.toColorPart = function() {
|
||||
var digits = this.toString(16);
|
||||
if (this < 16) return '0' + digits;
|
||||
return digits;
|
||||
};
|
||||
|
||||
var Try = {
|
||||
these: function() {
|
||||
var returnValue;
|
||||
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var lambda = arguments[i];
|
||||
try {
|
||||
returnValue = lambda();
|
||||
break;
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
};
|
||||
|
||||
var PeriodicalExecuter = Class.create();
|
||||
PeriodicalExecuter.prototype = {
|
||||
initialize: function(callback, frequency) {
|
||||
this.callback = callback;
|
||||
this.frequency = frequency;
|
||||
this.currentlyExecuting = false;
|
||||
|
||||
this.registerCallback();
|
||||
},
|
||||
|
||||
registerCallback: function() {
|
||||
setTimeout(this.onTimerEvent.bind(this), this.frequency * 1000);
|
||||
},
|
||||
|
||||
onTimerEvent: function() {
|
||||
if (!this.currentlyExecuting) {
|
||||
try {
|
||||
this.currentlyExecuting = true;
|
||||
this.callback();
|
||||
} finally {
|
||||
this.currentlyExecuting = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.registerCallback();
|
||||
}
|
||||
};
|
||||
function $() {
|
||||
var elements = new Array();
|
||||
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var element = arguments[i];
|
||||
if (typeof element == 'string')
|
||||
element = document.getElementById(element);
|
||||
|
||||
if (arguments.length == 1)
|
||||
return element;
|
||||
|
||||
elements.push(element);
|
||||
}
|
||||
|
||||
return elements;
|
||||
};
|
||||
if (!Array.prototype.push) {
|
||||
Array.prototype.push = function() {
|
||||
var startLength = this.length;
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
this[startLength + i] = arguments[i];
|
||||
return this.length;
|
||||
};
|
||||
};
|
||||
|
||||
if (!Function.prototype.apply) {
|
||||
// Based on code from http://www.youngpup.net/
|
||||
Function.prototype.apply = function(object, parameters) {
|
||||
var parameterStrings = new Array();
|
||||
if (!object) object = window;
|
||||
if (!parameters) parameters = new Array();
|
||||
|
||||
for (var i = 0; i < parameters.length; i++)
|
||||
parameterStrings[i] = 'x[' + i + ']';
|
||||
|
||||
object.__apply__ = this;
|
||||
var result = eval('obj.__apply__(' +
|
||||
parameterStrings[i].join(', ') + ')');
|
||||
object.__apply__ = null;
|
||||
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
var Ajax = {
|
||||
getTransport: function() {
|
||||
return Try.these(
|
||||
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
|
||||
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
|
||||
function() {return new XMLHttpRequest()}
|
||||
) || false;
|
||||
},
|
||||
|
||||
emptyFunction: function() {}
|
||||
};
|
||||
|
||||
Ajax.Base = function() {};
|
||||
Ajax.Base.prototype = {
|
||||
setOptions: function(options) {
|
||||
this.options = {
|
||||
method: 'post',
|
||||
asynchronous: true,
|
||||
parameters: ''
|
||||
}.extend(options || {});
|
||||
}
|
||||
};
|
||||
|
||||
Ajax.Request = Class.create();
|
||||
Ajax.Request.Events =
|
||||
['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
|
||||
|
||||
Ajax.Request.prototype = (new Ajax.Base()).extend({
|
||||
initialize: function(url, options) {
|
||||
this.transport = Ajax.getTransport();
|
||||
this.setOptions(options);
|
||||
|
||||
try {
|
||||
if (this.options.method == 'get')
|
||||
url += '?' + this.options.parameters + '&_=';
|
||||
|
||||
this.transport.open(this.options.method, url,
|
||||
this.options.asynchronous);
|
||||
|
||||
if (this.options.asynchronous) {
|
||||
this.transport.onreadystatechange = this.onStateChange.bind(this);
|
||||
setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
|
||||
}
|
||||
|
||||
this.transport.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
this.transport.setRequestHeader('X-Prototype-Version', Prototype.Version);
|
||||
|
||||
if (this.options.method == 'post') {
|
||||
this.transport.setRequestHeader('Connection', 'close');
|
||||
this.transport.setRequestHeader('Content-type',
|
||||
'application/x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
this.transport.send(this.options.method == 'post' ?
|
||||
this.options.parameters + '&_=' : null);
|
||||
|
||||
} catch (e) {
|
||||
}
|
||||
},
|
||||
|
||||
onStateChange: function() {
|
||||
var readyState = this.transport.readyState;
|
||||
if (readyState != 1)
|
||||
this.respondToReadyState(this.transport.readyState);
|
||||
},
|
||||
|
||||
respondToReadyState: function(readyState) {
|
||||
var event = Ajax.Request.Events[readyState];
|
||||
(this.options['on' + event] || Ajax.emptyFunction)(this.transport);
|
||||
}
|
||||
});
|
||||
|
||||
Ajax.Updater = Class.create();
|
||||
Ajax.Updater.prototype = (new Ajax.Base()).extend({
|
||||
initialize: function(container, url, options) {
|
||||
this.container = $(container);
|
||||
this.setOptions(options);
|
||||
|
||||
if (this.options.asynchronous) {
|
||||
this.onComplete = this.options.onComplete;
|
||||
this.options.onComplete = this.updateContent.bind(this);
|
||||
}
|
||||
|
||||
this.request = new Ajax.Request(url, this.options);
|
||||
|
||||
if (!this.options.asynchronous)
|
||||
this.updateContent();
|
||||
},
|
||||
|
||||
updateContent: function() {
|
||||
if (this.options.insertion) {
|
||||
new this.options.insertion(this.container,
|
||||
this.request.transport.responseText);
|
||||
} else {
|
||||
this.container.innerHTML = this.request.transport.responseText;
|
||||
}
|
||||
|
||||
if (this.onComplete) {
|
||||
setTimeout((function() {this.onComplete(this.request)}).bind(this), 10);
|
||||
}
|
||||
}
|
||||
});
|
||||
var Field = {
|
||||
clear: function() {
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
$(arguments[i]).value = '';
|
||||
},
|
||||
|
||||
focus: function(element) {
|
||||
$(element).focus();
|
||||
},
|
||||
|
||||
present: function() {
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
if ($(arguments[i]).value == '') return false;
|
||||
return true;
|
||||
},
|
||||
|
||||
select: function(element) {
|
||||
$(element).select();
|
||||
},
|
||||
|
||||
activate: function(element) {
|
||||
$(element).focus();
|
||||
$(element).select();
|
||||
}
|
||||
};
|
||||
var Form = {
|
||||
serialize: function(form) {
|
||||
var elements = Form.getElements($(form));
|
||||
var queryComponents = new Array();
|
||||
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var queryComponent = Form.Element.serialize(elements[i]);
|
||||
if (queryComponent)
|
||||
queryComponents.push(queryComponent);
|
||||
}
|
||||
|
||||
return queryComponents.join('&');
|
||||
},
|
||||
|
||||
getElements: function(form) {
|
||||
form = $(form);
|
||||
var elements = new Array();
|
||||
|
||||
for (tagName in Form.Element.Serializers) {
|
||||
var tagElements = form.getElementsByTagName(tagName);
|
||||
for (var j = 0; j < tagElements.length; j++)
|
||||
elements.push(tagElements[j]);
|
||||
}
|
||||
return elements;
|
||||
},
|
||||
|
||||
disable: function(form) {
|
||||
var elements = Form.getElements(form);
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var element = elements[i];
|
||||
element.blur();
|
||||
element.disable = 'true';
|
||||
}
|
||||
},
|
||||
|
||||
focusFirstElement: function(form) {
|
||||
form = $(form);
|
||||
var elements = Form.getElements(form);
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var element = elements[i];
|
||||
if (element.type != 'hidden' && !element.disabled) {
|
||||
Field.activate(element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
reset: function(form) {
|
||||
$(form).reset();
|
||||
}
|
||||
};
|
||||
|
||||
Form.Element = {
|
||||
serialize: function(element) {
|
||||
element = $(element);
|
||||
var method = element.tagName.toLowerCase();
|
||||
var parameter = Form.Element.Serializers[method](element);
|
||||
|
||||
if (parameter)
|
||||
return encodeURIComponent(parameter[0]) + '=' +
|
||||
encodeURIComponent(parameter[1]);
|
||||
},
|
||||
|
||||
getValue: function(element) {
|
||||
element = $(element);
|
||||
var method = element.tagName.toLowerCase();
|
||||
var parameter = Form.Element.Serializers[method](element);
|
||||
|
||||
if (parameter)
|
||||
return parameter[1];
|
||||
}
|
||||
};
|
||||
|
||||
Form.Element.Serializers = {
|
||||
input: function(element) {
|
||||
switch (element.type.toLowerCase()) {
|
||||
case 'hidden':
|
||||
case 'password':
|
||||
case 'text':
|
||||
return Form.Element.Serializers.textarea(element);
|
||||
case 'checkbox':
|
||||
case 'radio':
|
||||
return Form.Element.Serializers.inputSelector(element);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
inputSelector: function(element) {
|
||||
if (element.checked)
|
||||
return [element.name, element.value];
|
||||
},
|
||||
|
||||
textarea: function(element) {
|
||||
return [element.name, element.value];
|
||||
},
|
||||
|
||||
select: function(element) {
|
||||
var index = element.selectedIndex;
|
||||
var value = element.options[index].value || element.options[index].text;
|
||||
return [element.name, (index >= 0) ? value : ''];
|
||||
}
|
||||
};
|
||||
|
||||
var $F = Form.Element.getValue;
|
||||
|
||||
Abstract.TimedObserver = function() {};
|
||||
Abstract.TimedObserver.prototype = {
|
||||
initialize: function(element, frequency, callback) {
|
||||
this.frequency = frequency;
|
||||
this.element = $(element);
|
||||
this.callback = callback;
|
||||
|
||||
this.lastValue = this.getValue();
|
||||
this.registerCallback();
|
||||
},
|
||||
|
||||
registerCallback: function() {
|
||||
setTimeout(this.onTimerEvent.bind(this), this.frequency * 1000);
|
||||
},
|
||||
|
||||
onTimerEvent: function() {
|
||||
var value = this.getValue();
|
||||
if (this.lastValue != value) {
|
||||
this.callback(this.element, value);
|
||||
this.lastValue = value;
|
||||
}
|
||||
|
||||
this.registerCallback();
|
||||
}
|
||||
};
|
||||
|
||||
Form.Element.Observer = Class.create();
|
||||
Form.Element.Observer.prototype = (new Abstract.TimedObserver()).extend({
|
||||
getValue: function() {
|
||||
return Form.Element.getValue(this.element);
|
||||
}
|
||||
});
|
||||
|
||||
Form.Observer = Class.create();
|
||||
Form.Observer.prototype = (new Abstract.TimedObserver()).extend({
|
||||
getValue: function() {
|
||||
return Form.serialize(this.element);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementsByClassName = function(className) {
|
||||
var children = document.getElementsByTagName('*') || document.all;
|
||||
var elements = new Array();
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
var classNames = child.className.split(' ');
|
||||
for (var j = 0; j < classNames.length; j++) {
|
||||
if (classNames[j] == className) {
|
||||
elements.push(child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return elements;
|
||||
};
|
||||
|
||||
var Element = {
|
||||
toggle: function() {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var element = $(arguments[i]);
|
||||
element.style.display =
|
||||
(element.style.display == 'none' ? '' : 'none');
|
||||
}
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var element = $(arguments[i]);
|
||||
element.style.display = 'none';
|
||||
}
|
||||
},
|
||||
|
||||
show: function() {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var element = $(arguments[i]);
|
||||
element.style.display = '';
|
||||
}
|
||||
},
|
||||
|
||||
remove: function(element) {
|
||||
element = $(element);
|
||||
element.parentNode.removeChild(element);
|
||||
},
|
||||
|
||||
getHeight: function(element) {
|
||||
element = $(element);
|
||||
return element.offsetHeight;
|
||||
}
|
||||
};
|
||||
|
||||
var Toggle = new Object();
|
||||
Toggle.display = Element.toggle;
|
||||
|
||||
Abstract.Insertion = function(adjacency) {
|
||||
this.adjacency = adjacency;
|
||||
};
|
||||
|
||||
Abstract.Insertion.prototype = {
|
||||
initialize: function(element, content) {
|
||||
this.element = $(element);
|
||||
this.content = content;
|
||||
|
||||
if (this.adjacency && this.element.insertAdjacentHTML) {
|
||||
this.element.insertAdjacentHTML(this.adjacency, this.content);
|
||||
} else {
|
||||
this.range = this.element.ownerDocument.createRange();
|
||||
if (this.initializeRange) this.initializeRange();
|
||||
this.fragment = this.range.createContextualFragment(this.content);
|
||||
this.insertContent();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var Insertion = new Object();
|
||||
|
||||
Insertion.Before = Class.create();
|
||||
Insertion.Before.prototype = (new Abstract.Insertion('beforeBegin')).extend({
|
||||
initializeRange: function() {
|
||||
this.range.setStartBefore(this.element);
|
||||
},
|
||||
|
||||
insertContent: function() {
|
||||
this.element.parentNode.insertBefore(this.fragment, this.element);
|
||||
}
|
||||
});
|
||||
|
||||
Insertion.Top = Class.create();
|
||||
Insertion.Top.prototype = (new Abstract.Insertion('afterBegin')).extend({
|
||||
initializeRange: function() {
|
||||
this.range.selectNodeContents(this.element);
|
||||
this.range.collapse(true);
|
||||
},
|
||||
|
||||
insertContent: function() {
|
||||
this.element.insertBefore(this.fragment, this.element.firstChild);
|
||||
}
|
||||
});
|
||||
|
||||
Insertion.Bottom = Class.create();
|
||||
Insertion.Bottom.prototype = (new Abstract.Insertion('beforeEnd')).extend({
|
||||
initializeRange: function() {
|
||||
this.range.selectNodeContents(this.element);
|
||||
this.range.collapse(this.element);
|
||||
},
|
||||
|
||||
insertContent: function() {
|
||||
this.element.appendChild(this.fragment);
|
||||
}
|
||||
});
|
||||
|
||||
Insertion.After = Class.create();
|
||||
Insertion.After.prototype = (new Abstract.Insertion('afterEnd')).extend({
|
||||
initializeRange: function() {
|
||||
this.range.setStartAfter(this.element);
|
||||
},
|
||||
|
||||
insertContent: function() {
|
||||
this.element.parentNode.insertBefore(this.fragment,
|
||||
this.element.nextSibling);
|
||||
}
|
||||
});
|
191
themes/olive/javascripts/rails.js
Executable file
|
@ -0,0 +1,191 @@
|
|||
(function() {
|
||||
// Technique from Juriy Zaytsev
|
||||
// http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
|
||||
function isEventSupported(eventName) {
|
||||
var el = document.createElement('div');
|
||||
eventName = 'on' + eventName;
|
||||
var isSupported = (eventName in el);
|
||||
if (!isSupported) {
|
||||
el.setAttribute(eventName, 'return;');
|
||||
isSupported = typeof el[eventName] == 'function';
|
||||
}
|
||||
el = null;
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
function isForm(element) {
|
||||
return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
|
||||
}
|
||||
|
||||
function isInput(element) {
|
||||
if (Object.isElement(element)) {
|
||||
var name = element.nodeName.toUpperCase()
|
||||
return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
|
||||
}
|
||||
else return false
|
||||
}
|
||||
|
||||
var submitBubbles = isEventSupported('submit'),
|
||||
changeBubbles = isEventSupported('change')
|
||||
|
||||
if (!submitBubbles || !changeBubbles) {
|
||||
// augment the Event.Handler class to observe custom events when needed
|
||||
Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
|
||||
function(init, element, eventName, selector, callback) {
|
||||
init(element, eventName, selector, callback)
|
||||
// is the handler being attached to an element that doesn't support this event?
|
||||
if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
|
||||
(!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
|
||||
// "submit" => "emulated:submit"
|
||||
this.eventName = 'emulated:' + this.eventName
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (!submitBubbles) {
|
||||
// discover forms on the page by observing focus events which always bubble
|
||||
document.on('focusin', 'form', function(focusEvent, form) {
|
||||
// special handler for the real "submit" event (one-time operation)
|
||||
if (!form.retrieve('emulated:submit')) {
|
||||
form.on('submit', function(submitEvent) {
|
||||
var emulated = form.fire('emulated:submit', submitEvent, true)
|
||||
// if custom event received preventDefault, cancel the real one too
|
||||
if (emulated.returnValue === false) submitEvent.preventDefault()
|
||||
})
|
||||
form.store('emulated:submit', true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (!changeBubbles) {
|
||||
// discover form inputs on the page
|
||||
document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
|
||||
// special handler for real "change" events
|
||||
if (!input.retrieve('emulated:change')) {
|
||||
input.on('change', function(changeEvent) {
|
||||
input.fire('emulated:change', changeEvent, true)
|
||||
})
|
||||
input.store('emulated:change', true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function handleRemote(element) {
|
||||
var method, url, params;
|
||||
|
||||
var event = element.fire("ajax:before");
|
||||
if (event.stopped) return false;
|
||||
|
||||
if (element.tagName.toLowerCase() === 'form') {
|
||||
method = element.readAttribute('method') || 'post';
|
||||
url = element.readAttribute('action');
|
||||
params = element.serialize();
|
||||
} else {
|
||||
method = element.readAttribute('data-method') || 'get';
|
||||
url = element.readAttribute('href');
|
||||
params = {};
|
||||
}
|
||||
|
||||
new Ajax.Request(url, {
|
||||
method: method,
|
||||
parameters: params,
|
||||
evalScripts: true,
|
||||
|
||||
onComplete: function(request) { element.fire("ajax:complete", request); },
|
||||
onSuccess: function(request) { element.fire("ajax:success", request); },
|
||||
onFailure: function(request) { element.fire("ajax:failure", request); }
|
||||
});
|
||||
|
||||
element.fire("ajax:after");
|
||||
}
|
||||
|
||||
function handleMethod(element) {
|
||||
var method = element.readAttribute('data-method'),
|
||||
url = element.readAttribute('href'),
|
||||
csrf_param = $$('meta[name=csrf-param]')[0],
|
||||
csrf_token = $$('meta[name=csrf-token]')[0];
|
||||
|
||||
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
|
||||
element.parentNode.insert(form);
|
||||
|
||||
if (method !== 'post') {
|
||||
var field = new Element('input', { type: 'hidden', name: '_method', value: method });
|
||||
form.insert(field);
|
||||
}
|
||||
|
||||
if (csrf_param) {
|
||||
var param = csrf_param.readAttribute('content'),
|
||||
token = csrf_token.readAttribute('content'),
|
||||
field = new Element('input', { type: 'hidden', name: param, value: token });
|
||||
form.insert(field);
|
||||
}
|
||||
|
||||
form.submit();
|
||||
}
|
||||
|
||||
|
||||
document.on("click", "*[data-confirm]", function(event, element) {
|
||||
var message = element.readAttribute('data-confirm');
|
||||
if (!confirm(message)) event.stop();
|
||||
});
|
||||
|
||||
document.on("click", "a[data-remote]", function(event, element) {
|
||||
if (event.stopped) return;
|
||||
handleRemote(element);
|
||||
event.stop();
|
||||
});
|
||||
|
||||
document.on("click", "a[data-method]", function(event, element) {
|
||||
if (event.stopped) return;
|
||||
handleMethod(element);
|
||||
event.stop();
|
||||
});
|
||||
|
||||
document.on("submit", function(event) {
|
||||
var element = event.findElement(),
|
||||
message = element.readAttribute('data-confirm');
|
||||
if (message && !confirm(message)) {
|
||||
event.stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
var inputs = element.select("input[type=submit][data-disable-with]");
|
||||
inputs.each(function(input) {
|
||||
input.disabled = true;
|
||||
input.writeAttribute('data-original-value', input.value);
|
||||
input.value = input.readAttribute('data-disable-with');
|
||||
});
|
||||
|
||||
var element = event.findElement("form[data-remote]");
|
||||
if (element) {
|
||||
handleRemote(element);
|
||||
event.stop();
|
||||
}
|
||||
});
|
||||
|
||||
document.on("ajax:after", "form", function(event, element) {
|
||||
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
|
||||
inputs.each(function(input) {
|
||||
input.value = input.readAttribute('data-original-value');
|
||||
input.removeAttribute('data-original-value');
|
||||
input.disabled = false;
|
||||
});
|
||||
});
|
||||
|
||||
Ajax.Responders.register({
|
||||
onCreate: function(request) {
|
||||
var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
|
||||
|
||||
if (csrf_meta_tag) {
|
||||
var header = 'X-CSRF-Token',
|
||||
token = csrf_meta_tag.readAttribute('content');
|
||||
|
||||
if (!request.options.requestHeaders) {
|
||||
request.options.requestHeaders = {};
|
||||
}
|
||||
request.options.requestHeaders[header] = token;
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
|
@ -1,47 +0,0 @@
|
|||
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var Scriptaculous = {
|
||||
Version: '1.5_rc3',
|
||||
require: function(libraryName) {
|
||||
// inserting via DOM fails in Safari 2.0, so brute force approach
|
||||
document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
|
||||
},
|
||||
load: function() {
|
||||
if((typeof Prototype=='undefined') ||
|
||||
parseFloat(Prototype.Version.split(".")[0] + "." +
|
||||
Prototype.Version.split(".")[1]) < 1.4)
|
||||
throw("script.aculo.us requires the Prototype JavaScript framework >= 1.4.0");
|
||||
var scriptTags = document.getElementsByTagName("script");
|
||||
for(var i=0;i<scriptTags.length;i++) {
|
||||
if(scriptTags[i].src && scriptTags[i].src.match(/scriptaculous\.js(\?.*)?$/)) {
|
||||
var path = scriptTags[i].src.replace(/scriptaculous\.js(\?.*)?$/,'');
|
||||
this.require(path + 'effects.js');
|
||||
this.require(path + 'dragdrop.js');
|
||||
this.require(path + 'controls.js');
|
||||
this.require(path + 'slider.js');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Scriptaculous.load();
|