mirror of
https://github.com/github/rails.git
synced 2026-01-12 08:08:31 -05:00
Compare commits
47 Commits
2.3.14.git
...
v2.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff56137073 | ||
|
|
4adf56b153 | ||
|
|
ca29de5d1f | ||
|
|
9d8cc60ec3 | ||
|
|
5b72c9b697 | ||
|
|
3639c0bfa7 | ||
|
|
5e55ed1951 | ||
|
|
2f7c073f19 | ||
|
|
8be7d960f2 | ||
|
|
56220ab607 | ||
|
|
24ead54f2b | ||
|
|
085ebf0368 | ||
|
|
24dbd4b958 | ||
|
|
dff4ab9ca5 | ||
|
|
011a525de0 | ||
|
|
7a9c48c1cb | ||
|
|
4f20a15e9c | ||
|
|
9c42d1945c | ||
|
|
49797f77f6 | ||
|
|
12c7fef5f1 | ||
|
|
591560c641 | ||
|
|
af57ccb468 | ||
|
|
afc7fceefc | ||
|
|
0f89ed5636 | ||
|
|
7d3efe72b4 | ||
|
|
80e6aaed83 | ||
|
|
9fb3c8412e | ||
|
|
b88d394ce7 | ||
|
|
98199eb3bc | ||
|
|
453931cac5 | ||
|
|
5d3a14a936 | ||
|
|
42c9d37273 | ||
|
|
f7a8e39400 | ||
|
|
76b54c5eae | ||
|
|
fa7151cc0d | ||
|
|
b55fc0fc08 | ||
|
|
8789394f0e | ||
|
|
3eb0d2973a | ||
|
|
6bfd0ac48b | ||
|
|
78e374d4ec | ||
|
|
9fab882b91 | ||
|
|
3e79dbd3f9 | ||
|
|
b401c281ac | ||
|
|
5140bbd0d3 | ||
|
|
a5609cd3cf | ||
|
|
0b424da08e | ||
|
|
f58b0b2bd7 |
@@ -1,10 +1,7 @@
|
||||
*2.2.1 [RC2] (November 14th, 2008)*
|
||||
*2.2 (November 21st, 2008)*
|
||||
|
||||
* Turn on STARTTLS if it is available in Net::SMTP (added in Ruby 1.8.7) and the SMTP server supports it (This is required for Gmail's SMTP server) #1336 [Grant Hollingworth]
|
||||
|
||||
|
||||
*2.2.0 [RC1] (October 24th, 2008)*
|
||||
|
||||
* Add layout functionality to mailers [Pratik]
|
||||
|
||||
Mailer layouts behaves just like controller layouts, except layout names need to
|
||||
|
||||
@@ -55,7 +55,7 @@ spec = Gem::Specification.new do |s|
|
||||
s.rubyforge_project = "actionmailer"
|
||||
s.homepage = "http://www.rubyonrails.org"
|
||||
|
||||
s.add_dependency('actionpack', '= 2.2.1' + PKG_BUILD)
|
||||
s.add_dependency('actionpack', '= 2.2.2' + PKG_BUILD)
|
||||
|
||||
s.has_rdoc = true
|
||||
s.requirements << 'none'
|
||||
|
||||
@@ -549,7 +549,12 @@ module ActionMailer #:nodoc:
|
||||
end
|
||||
|
||||
def render_message(method_name, body)
|
||||
if method_name.respond_to?(:content_type)
|
||||
@current_template_content_type = method_name.content_type
|
||||
end
|
||||
render :file => method_name, :body => body
|
||||
ensure
|
||||
@current_template_content_type = nil
|
||||
end
|
||||
|
||||
def render(opts)
|
||||
@@ -568,7 +573,11 @@ module ActionMailer #:nodoc:
|
||||
end
|
||||
|
||||
def default_template_format
|
||||
:html
|
||||
if @current_template_content_type
|
||||
Mime::Type.lookup(@current_template_content_type).to_sym
|
||||
else
|
||||
:html
|
||||
end
|
||||
end
|
||||
|
||||
def candidate_for_layout?(options)
|
||||
@@ -588,7 +597,9 @@ module ActionMailer #:nodoc:
|
||||
end
|
||||
|
||||
def initialize_template_class(assigns)
|
||||
ActionView::Base.new(view_paths, assigns, self)
|
||||
template = ActionView::Base.new(view_paths, assigns, self)
|
||||
template.template_format = default_template_format
|
||||
template
|
||||
end
|
||||
|
||||
def sort_parts(parts, order = [])
|
||||
|
||||
@@ -2,7 +2,7 @@ module ActionMailer
|
||||
module VERSION #:nodoc:
|
||||
MAJOR = 2
|
||||
MINOR = 2
|
||||
TINY = 1
|
||||
TINY = 2
|
||||
|
||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||
end
|
||||
|
||||
1
actionmailer/test/fixtures/auto_layout_mailer/multipart.text.html.erb
vendored
Normal file
1
actionmailer/test/fixtures/auto_layout_mailer/multipart.text.html.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
text/html multipart
|
||||
1
actionmailer/test/fixtures/auto_layout_mailer/multipart.text.plain.erb
vendored
Normal file
1
actionmailer/test/fixtures/auto_layout_mailer/multipart.text.plain.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
text/plain multipart
|
||||
1
actionmailer/test/fixtures/layouts/auto_layout_mailer.text.erb
vendored
Normal file
1
actionmailer/test/fixtures/layouts/auto_layout_mailer.text.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
text/plain layout - <%= yield %>
|
||||
@@ -20,6 +20,12 @@ class AutoLayoutMailer < ActionMailer::Base
|
||||
from "tester@example.com"
|
||||
body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" })
|
||||
end
|
||||
|
||||
def multipart(recipient)
|
||||
recipients recipient
|
||||
subject "You have a mail"
|
||||
from "tester@example.com"
|
||||
end
|
||||
end
|
||||
|
||||
class ExplicitLayoutMailer < ActionMailer::Base
|
||||
@@ -56,6 +62,17 @@ class LayoutMailerTest < Test::Unit::TestCase
|
||||
assert_equal "Hello from layout Inside", mail.body.strip
|
||||
end
|
||||
|
||||
def test_should_pickup_multipart_layout
|
||||
mail = AutoLayoutMailer.create_multipart(@recipient)
|
||||
assert_equal 2, mail.parts.size
|
||||
|
||||
assert_equal 'text/plain', mail.parts.first.content_type
|
||||
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
|
||||
|
||||
assert_equal 'text/html', mail.parts.last.content_type
|
||||
assert_equal "Hello from layout text/html multipart", mail.parts.last.body
|
||||
end
|
||||
|
||||
def test_should_pickup_layout_given_to_render
|
||||
mail = AutoLayoutMailer.create_spam(@recipient)
|
||||
assert_equal "Spammer layout Hello, Earth", mail.body.strip
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
*2.2.1 [RC2] (November 14th, 2008)*
|
||||
*2.2 (November 21st, 2008)*
|
||||
|
||||
* Deprecated the :file default for ActionView#render to prepare for 2.3's new :partial default [DHH]
|
||||
|
||||
* Restore backwards compatible functionality for setting relative_url_root. Include deprecation
|
||||
|
||||
@@ -28,9 +30,6 @@
|
||||
|
||||
* Fixed bug with asset timestamping when using relative_url_root #1265 [Joe Goldwasser]
|
||||
|
||||
|
||||
*2.2.0 [RC1] (October 24th, 2008)*
|
||||
|
||||
* Fix incorrect closing CDATA delimiter and that HTML::Node.parse would blow up on unclosed CDATA sections [packagethief]
|
||||
|
||||
* Added stale? and fresh_when methods to provide a layer of abstraction above request.fresh? and friends [DHH]. Example:
|
||||
|
||||
@@ -80,7 +80,7 @@ spec = Gem::Specification.new do |s|
|
||||
s.has_rdoc = true
|
||||
s.requirements << 'none'
|
||||
|
||||
s.add_dependency('activesupport', '= 2.2.1' + PKG_BUILD)
|
||||
s.add_dependency('activesupport', '= 2.2.2' + PKG_BUILD)
|
||||
|
||||
s.require_path = 'lib'
|
||||
s.autorequire = 'action_controller'
|
||||
|
||||
@@ -25,7 +25,7 @@ module Mime
|
||||
# These are the content types which browsers can generate without using ajax, flash, etc
|
||||
# i.e. following a link, getting an image or posting a form. CSRF protection
|
||||
# only needs to protect against these types.
|
||||
@@browser_generated_types = Set.new [:html, :url_encoded_form, :multipart_form]
|
||||
@@browser_generated_types = Set.new [:html, :url_encoded_form, :multipart_form, :text]
|
||||
cattr_reader :browser_generated_types
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ module Mime
|
||||
end
|
||||
|
||||
# Returns true if Action Pack should check requests using this Mime Type for possible request forgery. See
|
||||
# ActionController::RequestForgerProtection.
|
||||
# ActionController::RequestForgeryProtection.
|
||||
def verify_request?
|
||||
browser_generated?
|
||||
end
|
||||
|
||||
@@ -74,6 +74,7 @@ module ActionController
|
||||
def polymorphic_url(record_or_hash_or_array, options = {})
|
||||
if record_or_hash_or_array.kind_of?(Array)
|
||||
record_or_hash_or_array = record_or_hash_or_array.compact
|
||||
record_or_hash_or_array = record_or_hash_or_array[0] if record_or_hash_or_array.size == 1
|
||||
end
|
||||
|
||||
record = extract_record(record_or_hash_or_array)
|
||||
|
||||
@@ -106,12 +106,8 @@ module ActionController
|
||||
# argument
|
||||
class PositionalArgumentsWithAdditionalParams < PositionalArguments
|
||||
def guard_conditions
|
||||
[
|
||||
"args.size == #{route.segment_keys.size + 1}",
|
||||
"!args.last.has_key?(:anchor)",
|
||||
"!args.last.has_key?(:port)",
|
||||
"!args.last.has_key?(:host)"
|
||||
]
|
||||
["args.size == #{route.segment_keys.size + 1}"] +
|
||||
UrlRewriter::RESERVED_OPTIONS.collect{ |key| "!args.last.has_key?(:#{key})" }
|
||||
end
|
||||
|
||||
# This case uses almost the same code as positional arguments,
|
||||
|
||||
@@ -168,6 +168,7 @@ module ActionController
|
||||
#
|
||||
@module.module_eval <<-end_eval # We use module_eval to avoid leaks
|
||||
def #{selector}(*args)
|
||||
|
||||
#{generate_optimisation_block(route, kind)}
|
||||
|
||||
opts = if args.empty? || Hash === args.first
|
||||
|
||||
@@ -2,7 +2,7 @@ module ActionPack #:nodoc:
|
||||
module VERSION #:nodoc:
|
||||
MAJOR = 2
|
||||
MINOR = 2
|
||||
TINY = 1
|
||||
TINY = 2
|
||||
|
||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||
end
|
||||
|
||||
@@ -43,7 +43,7 @@ require 'action_view/base'
|
||||
require 'action_view/partials'
|
||||
require 'action_view/template_error'
|
||||
|
||||
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en-US.yml"
|
||||
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
|
||||
|
||||
require 'action_view/helpers'
|
||||
|
||||
|
||||
@@ -240,6 +240,11 @@ module ActionView #:nodoc:
|
||||
local_assigns ||= {}
|
||||
|
||||
if options.is_a?(String)
|
||||
ActiveSupport::Deprecation.warn(
|
||||
"Calling render with a string will render a partial from Rails 2.3. " +
|
||||
"Change this call to render(:file => '#{options}', :locals => locals_hash)."
|
||||
)
|
||||
|
||||
render(:file => options, :locals => local_assigns)
|
||||
elsif options == :update
|
||||
update_page(&block)
|
||||
@@ -317,7 +322,8 @@ module ActionView #:nodoc:
|
||||
template
|
||||
elsif template = self.view_paths[template_file_name]
|
||||
template
|
||||
elsif @_render_stack.first && template = self.view_paths["#{template_file_name}.#{@_render_stack.first.format_and_extension}"]
|
||||
elsif (first_render = @_render_stack.first) && first_render.respond_to?(:format_and_extension) &&
|
||||
(template = self.view_paths["#{template_file_name}.#{first_render.format_and_extension}"])
|
||||
template
|
||||
elsif template_format == :js && template = self.view_paths["#{template_file_name}.html"]
|
||||
@template_format = :html
|
||||
|
||||
@@ -151,7 +151,7 @@ module ActionView
|
||||
# javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr.js
|
||||
# javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js
|
||||
def javascript_path(source)
|
||||
JavaScriptTag.create(self, @controller, source).public_path
|
||||
JavaScriptTag.new(self, @controller, source).public_path
|
||||
end
|
||||
alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route
|
||||
|
||||
@@ -314,7 +314,7 @@ module ActionView
|
||||
# stylesheet_path "http://www.railsapplication.com/css/style" # => http://www.railsapplication.com/css/style.css
|
||||
# stylesheet_path "http://www.railsapplication.com/css/style.js" # => http://www.railsapplication.com/css/style.css
|
||||
def stylesheet_path(source)
|
||||
StylesheetTag.create(self, @controller, source).public_path
|
||||
StylesheetTag.new(self, @controller, source).public_path
|
||||
end
|
||||
alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route
|
||||
|
||||
@@ -411,7 +411,7 @@ module ActionView
|
||||
# image_path("/icons/edit.png") # => /icons/edit.png
|
||||
# image_path("http://www.railsapplication.com/img/edit.png") # => http://www.railsapplication.com/img/edit.png
|
||||
def image_path(source)
|
||||
ImageTag.create(self, @controller, source).public_path
|
||||
ImageTag.new(self, @controller, source).public_path
|
||||
end
|
||||
alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
|
||||
|
||||
@@ -527,20 +527,6 @@ module ActionView
|
||||
Cache = {}
|
||||
CacheGuard = Mutex.new
|
||||
|
||||
def self.create(template, controller, source, include_host = true)
|
||||
CacheGuard.synchronize do
|
||||
key = if controller.respond_to?(:request)
|
||||
[self, controller.request.protocol,
|
||||
ActionController::Base.asset_host,
|
||||
ActionController::Base.relative_url_root,
|
||||
source, include_host]
|
||||
else
|
||||
[self, ActionController::Base.asset_host, source, include_host]
|
||||
end
|
||||
Cache[key] ||= new(template, controller, source, include_host).freeze
|
||||
end
|
||||
end
|
||||
|
||||
ProtocolRegexp = %r{^[-a-z]+://}.freeze
|
||||
|
||||
def initialize(template, controller, source, include_host = true)
|
||||
@@ -551,8 +537,16 @@ module ActionView
|
||||
@controller = controller
|
||||
@source = source
|
||||
@include_host = include_host
|
||||
@cache_key = if controller.respond_to?(:request)
|
||||
[self.class.name,controller.request.protocol,
|
||||
ActionController::Base.asset_host,
|
||||
ActionController::Base.relative_url_root,
|
||||
source, include_host]
|
||||
else
|
||||
[self.class.name,ActionController::Base.asset_host, source, include_host]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def public_path
|
||||
compute_public_path(@source)
|
||||
end
|
||||
@@ -585,20 +579,32 @@ module ActionView
|
||||
# roots. Rewrite the asset path for cache-busting asset ids. Include
|
||||
# asset host, if configured, with the correct request protocol.
|
||||
def compute_public_path(source)
|
||||
source += ".#{extension}" if missing_extension?(source)
|
||||
unless source =~ ProtocolRegexp
|
||||
source = "/#{directory}/#{source}" unless source[0] == ?/
|
||||
source = rewrite_asset_path(source)
|
||||
source = prepend_relative_url_root(source)
|
||||
if source =~ ProtocolRegexp
|
||||
source += ".#{extension}" if missing_extension?(source)
|
||||
source = prepend_asset_host(source)
|
||||
source
|
||||
else
|
||||
CacheGuard.synchronize do
|
||||
Cache[@cache_key] ||= begin
|
||||
source += ".#{extension}" if missing_extension?(source) || file_exists_with_extension?(source)
|
||||
source = "/#{directory}/#{source}" unless source[0] == ?/
|
||||
source = rewrite_asset_path(source)
|
||||
source = prepend_relative_url_root(source)
|
||||
source = prepend_asset_host(source)
|
||||
source
|
||||
end
|
||||
end
|
||||
end
|
||||
source = prepend_asset_host(source)
|
||||
source
|
||||
end
|
||||
|
||||
|
||||
def missing_extension?(source)
|
||||
extension && (File.extname(source).blank? || File.exist?(File.join(ASSETS_DIR, directory, "#{source}.#{extension}")))
|
||||
extension && File.extname(source).blank?
|
||||
end
|
||||
|
||||
|
||||
def file_exists_with_extension?(source)
|
||||
extension && File.exist?(File.join(ASSETS_DIR, directory, "#{source}.#{extension}"))
|
||||
end
|
||||
|
||||
def prepend_relative_url_root(source)
|
||||
relative_url_root = ActionController::Base.relative_url_root
|
||||
if request? && @include_host && source !~ %r{^#{relative_url_root}/}
|
||||
@@ -735,7 +741,7 @@ module ActionView
|
||||
end
|
||||
|
||||
def tag_sources
|
||||
expand_sources.collect { |source| tag_class.create(@template, @controller, source, false) }
|
||||
expand_sources.collect { |source| tag_class.new(@template, @controller, source, false) }
|
||||
end
|
||||
|
||||
def joined_contents
|
||||
|
||||
@@ -131,7 +131,7 @@ module ActionView
|
||||
# * <tt>:order</tt> - Set to an array containing <tt>:day</tt>, <tt>:month</tt> and <tt>:year</tt> do
|
||||
# customize the order in which the select fields are shown. If you leave out any of the symbols, the respective
|
||||
# select will not be shown (like when you set <tt>:discard_xxx => true</tt>. Defaults to the order defined in
|
||||
# the respective locale (e.g. [:year, :month, :day] in the en-US locale that ships with Rails).
|
||||
# the respective locale (e.g. [:year, :month, :day] in the en locale that ships with Rails).
|
||||
# * <tt>:include_blank</tt> - Include a blank option in every select field so it's possible to set empty
|
||||
# dates.
|
||||
# * <tt>:default</tt> - Set a default date if the affected date isn't set or is nil.
|
||||
|
||||
@@ -31,9 +31,6 @@ module ActionView
|
||||
# to use all basic AJAX functionality. For the Scriptaculous-based
|
||||
# JavaScript helpers, like visual effects, autocompletion, drag and drop
|
||||
# and so on, you should use the method described above.
|
||||
# * Use <tt><%= define_javascript_functions %></tt>: this will copy all the
|
||||
# JavaScript support functions within a single script block. Not
|
||||
# recommended.
|
||||
#
|
||||
# For documentation on +javascript_include_tag+ see
|
||||
# ActionView::Helpers::AssetTagHelper.
|
||||
|
||||
@@ -1,963 +0,0 @@
|
||||
// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
||||
// (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
|
||||
// (c) 2005-2007 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;
|
||||
},
|
||||
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));
|
||||
}
|
||||
});
|
||||
@@ -1,972 +0,0 @@
|
||||
// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
||||
// (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
|
||||
//
|
||||
// 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 = Position.cumulativeOffset(this.element);
|
||||
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.element._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
|
||||
if (!this.element._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.element._originallyAbsolute)
|
||||
Position.relativize(this.element);
|
||||
delete this.element._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 = Position.cumulativeOffset(this.element);
|
||||
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){
|
||||
var s = Sortable.options(element);
|
||||
|
||||
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.id] = 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 = Position.cumulativeOffset(dropon);
|
||||
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')];
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ module ActionView
|
||||
module TagHelper
|
||||
include ERB::Util
|
||||
|
||||
BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple).to_set
|
||||
BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked).to_set
|
||||
BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym))
|
||||
|
||||
# Returns an empty HTML tag of type +name+ which by default is XHTML
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"en-US":
|
||||
"en":
|
||||
number:
|
||||
# Used in number_with_delimiter()
|
||||
# These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
|
||||
@@ -29,7 +29,9 @@ module ActionView
|
||||
stack.push(self)
|
||||
|
||||
# This is only used for TestResponse to set rendered_template
|
||||
view.instance_variable_set(:@_first_render, self) unless view.instance_variable_get(:@_first_render)
|
||||
unless is_a?(InlineTemplate) || view.instance_variable_get(:@_first_render)
|
||||
view.instance_variable_set(:@_first_render, self)
|
||||
end
|
||||
|
||||
view.send(:_evaluate_assigns_and_ivars)
|
||||
view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type)
|
||||
|
||||
@@ -291,11 +291,13 @@ class ActionCacheTest < Test::Unit::TestCase
|
||||
ActionController::Base.use_accept_header = old_use_accept_header
|
||||
end
|
||||
|
||||
def test_action_cache_with_store_options
|
||||
MockTime.expects(:now).returns(12345).once
|
||||
@controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once
|
||||
@controller.expects(:write_fragment).with('hostname.com/action_caching_test', '12345.0', :expires_in => 1.hour).once
|
||||
get :index
|
||||
uses_mocha 'test action cache' do
|
||||
def test_action_cache_with_store_options
|
||||
MockTime.expects(:now).returns(12345).once
|
||||
@controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once
|
||||
@controller.expects(:write_fragment).with('hostname.com/action_caching_test', '12345.0', :expires_in => 1.hour).once
|
||||
get :index
|
||||
end
|
||||
end
|
||||
|
||||
def test_action_cache_with_custom_cache_path
|
||||
|
||||
@@ -48,7 +48,8 @@ class BaseCgiTest < Test::Unit::TestCase
|
||||
# some developers have grown accustomed to using comma in cookie values.
|
||||
@alt_cookie_fmt_request_hash = {"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}
|
||||
@cgi = CGI.new
|
||||
@cgi.stubs(:env_table).returns(@request_hash)
|
||||
class << @cgi; attr_accessor :env_table end
|
||||
@cgi.env_table = @request_hash
|
||||
@request = ActionController::CgiRequest.new(@cgi)
|
||||
end
|
||||
|
||||
|
||||
@@ -180,6 +180,12 @@ uses_mocha 'polymorphic URL helpers' do
|
||||
polymorphic_url([nil, @article])
|
||||
end
|
||||
|
||||
def test_with_array_containing_single_name
|
||||
@article.save
|
||||
expects(:articles_url)
|
||||
polymorphic_url([:articles])
|
||||
end
|
||||
|
||||
# TODO: Needs to be updated to correctly know about whether the object is in a hash or not
|
||||
def xtest_with_hash
|
||||
expects(:article_url).with(@article)
|
||||
|
||||
@@ -39,7 +39,7 @@ class TestController < ActionController::Base
|
||||
render :action => 'hello_world'
|
||||
end
|
||||
before_filter :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs
|
||||
|
||||
|
||||
def handle_last_modified_and_etags
|
||||
fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ])
|
||||
end
|
||||
@@ -246,6 +246,15 @@ class TestController < ActionController::Base
|
||||
:locals => { :local_name => name }
|
||||
end
|
||||
|
||||
def helper_method_to_render_to_string(*args)
|
||||
render_to_string(*args)
|
||||
end
|
||||
helper_method :helper_method_to_render_to_string
|
||||
|
||||
def render_html_only_partial_within_inline
|
||||
render :inline => "Hello world <%= helper_method_to_render_to_string :partial => 'test/partial_with_only_html_version' %>"
|
||||
end
|
||||
|
||||
def formatted_html_erb
|
||||
end
|
||||
|
||||
@@ -337,6 +346,11 @@ class TestController < ActionController::Base
|
||||
render :text => "Hi web users! #{@stuff}"
|
||||
end
|
||||
|
||||
def render_to_string_with_inline_and_render
|
||||
render_to_string :inline => "<%= 'dlrow olleh'.reverse %>"
|
||||
render :template => "test/hello_world"
|
||||
end
|
||||
|
||||
def rendering_with_conflicting_local_vars
|
||||
@name = "David"
|
||||
def @template.name() nil end
|
||||
@@ -855,7 +869,10 @@ class RenderTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_render_xml
|
||||
get :render_xml_hello
|
||||
assert_deprecated do
|
||||
get :render_xml_hello
|
||||
end
|
||||
|
||||
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
|
||||
assert_equal "application/xml", @response.content_type
|
||||
end
|
||||
@@ -889,7 +906,10 @@ class RenderTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_render_xml_with_layouts
|
||||
get :builder_layout_test
|
||||
assert_deprecated do
|
||||
get :builder_layout_test
|
||||
end
|
||||
|
||||
assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
|
||||
end
|
||||
|
||||
@@ -908,6 +928,11 @@ class RenderTest < Test::Unit::TestCase
|
||||
assert_equal "The value of foo is: ::this is a test::\n", @response.body
|
||||
end
|
||||
|
||||
def test_render_to_string_inline
|
||||
get :render_to_string_with_inline_and_render
|
||||
assert_template "test/hello_world"
|
||||
end
|
||||
|
||||
def test_nested_rendering
|
||||
@controller = Fun::GamesController.new
|
||||
get :hello_world
|
||||
@@ -924,6 +949,11 @@ class RenderTest < Test::Unit::TestCase
|
||||
assert_equal "Goodbye, Local David", @response.body
|
||||
end
|
||||
|
||||
def test_rendering_html_only_partial_within_inline_with_js
|
||||
get :render_html_only_partial_within_inline, :format => :js
|
||||
assert_equal "Hello world partial with only html version", @response.body
|
||||
end
|
||||
|
||||
def test_should_render_formatted_template
|
||||
get :formatted_html_erb
|
||||
assert_equal 'formatted html erb', @response.body
|
||||
@@ -1368,7 +1398,7 @@ class EtagRenderTest < Test::Unit::TestCase
|
||||
assert_equal "200 OK", @response.status
|
||||
assert !@response.body.empty?
|
||||
end
|
||||
|
||||
|
||||
def test_render_should_not_set_etag_when_last_modified_has_been_specified
|
||||
get :render_hello_world_with_last_modified_set
|
||||
assert_equal "200 OK", @response.status
|
||||
@@ -1382,7 +1412,7 @@ class EtagRenderTest < Test::Unit::TestCase
|
||||
expected_etag = etag_for('hello david')
|
||||
assert_equal expected_etag, @response.headers['ETag']
|
||||
@response = ActionController::TestResponse.new
|
||||
|
||||
|
||||
@request.if_none_match = expected_etag
|
||||
get :render_hello_world_from_variable
|
||||
assert_equal "304 Not Modified", @response.status
|
||||
@@ -1403,28 +1433,31 @@ class EtagRenderTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_etag_should_govern_renders_with_layouts_too
|
||||
get :builder_layout_test
|
||||
assert_deprecated do
|
||||
get :builder_layout_test
|
||||
end
|
||||
|
||||
assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
|
||||
assert_equal etag_for("<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n"), @response.headers['ETag']
|
||||
end
|
||||
|
||||
|
||||
def test_etag_with_bang_should_set_etag
|
||||
get :conditional_hello_with_bangs
|
||||
assert_equal @expected_bang_etag, @response.headers["ETag"]
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
|
||||
def test_etag_with_bang_should_obey_if_none_match
|
||||
@request.if_none_match = @expected_bang_etag
|
||||
get :conditional_hello_with_bangs
|
||||
assert_response :not_modified
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
def etag_for(text)
|
||||
%("#{Digest::MD5.hexdigest(text)}")
|
||||
end
|
||||
|
||||
|
||||
def expand_key(args)
|
||||
ActiveSupport::Cache.expand_cache_key(args)
|
||||
end
|
||||
@@ -1467,13 +1500,13 @@ class LastModifiedRenderTest < Test::Unit::TestCase
|
||||
assert !@response.body.blank?
|
||||
assert_equal @last_modified, @response.headers['Last-Modified']
|
||||
end
|
||||
|
||||
|
||||
def test_request_with_bang_gets_last_modified
|
||||
get :conditional_hello_with_bangs
|
||||
assert_equal @last_modified, @response.headers['Last-Modified']
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
|
||||
def test_request_with_bang_obeys_last_modified
|
||||
@request.if_modified_since = @last_modified
|
||||
get :conditional_hello_with_bangs
|
||||
|
||||
@@ -735,11 +735,7 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
|
||||
file = params['file']
|
||||
foo = params['foo']
|
||||
|
||||
if RUBY_VERSION > '1.9'
|
||||
assert_kind_of File, file
|
||||
else
|
||||
assert_kind_of Tempfile, file
|
||||
end
|
||||
assert_kind_of Tempfile, file
|
||||
|
||||
assert_equal 'file.txt', file.original_filename
|
||||
assert_equal "text/plain", file.content_type
|
||||
@@ -753,11 +749,9 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
|
||||
assert_equal 'bar', params['foo']
|
||||
|
||||
file = params['file']
|
||||
if RUBY_VERSION > '1.9'
|
||||
assert_kind_of File, file
|
||||
else
|
||||
assert_kind_of Tempfile, file
|
||||
end
|
||||
|
||||
assert_kind_of Tempfile, file
|
||||
|
||||
assert_equal 'file.txt', file.original_filename
|
||||
assert_equal "text/plain", file.content_type
|
||||
assert ('a' * 20480) == file.read
|
||||
|
||||
@@ -706,12 +706,13 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do
|
||||
port = options.delete(:port) || 80
|
||||
port_string = port == 80 ? '' : ":#{port}"
|
||||
|
||||
host = options.delete(:host) || "named.route.test"
|
||||
anchor = "##{options.delete(:anchor)}" if options.key?(:anchor)
|
||||
protocol = options.delete(:protocol) || "http"
|
||||
host = options.delete(:host) || "named.route.test"
|
||||
anchor = "##{options.delete(:anchor)}" if options.key?(:anchor)
|
||||
|
||||
path = routes.generate(options)
|
||||
|
||||
only_path ? "#{path}#{anchor}" : "http://#{host}#{port_string}#{path}#{anchor}"
|
||||
only_path ? "#{path}#{anchor}" : "#{protocol}://#{host}#{port_string}#{path}#{anchor}"
|
||||
end
|
||||
|
||||
def request
|
||||
@@ -1726,6 +1727,11 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do
|
||||
assert_equal "http://some.example.com/people/5", controller.send(:show_url, 5, :host=>"some.example.com")
|
||||
end
|
||||
|
||||
def test_named_route_url_method_with_protocol
|
||||
controller = setup_named_route_test
|
||||
assert_equal "https://named.route.test/people/5", controller.send(:show_url, 5, :protocol => "https")
|
||||
end
|
||||
|
||||
def test_named_route_url_method_with_ordered_parameters
|
||||
controller = setup_named_route_test
|
||||
assert_equal "http://named.route.test/people/go/7/hello/joe/5",
|
||||
|
||||
@@ -606,7 +606,7 @@ class CleanBacktraceTest < Test::Unit::TestCase
|
||||
def test_should_reraise_the_same_object
|
||||
exception = Test::Unit::AssertionFailedError.new('message')
|
||||
clean_backtrace { raise exception }
|
||||
rescue => caught
|
||||
rescue Exception => caught
|
||||
assert_equal exception.object_id, caught.object_id
|
||||
assert_equal exception.message, caught.message
|
||||
end
|
||||
@@ -616,7 +616,7 @@ class CleanBacktraceTest < Test::Unit::TestCase
|
||||
exception = Test::Unit::AssertionFailedError.new('message')
|
||||
exception.set_backtrace ["#{path}/abc", "#{path}/assertions/def"]
|
||||
clean_backtrace { raise exception }
|
||||
rescue => caught
|
||||
rescue Exception => caught
|
||||
assert_equal ["#{path}/abc"], caught.backtrace
|
||||
end
|
||||
|
||||
|
||||
1
actionpack/test/fixtures/test/_partial_with_only_html_version.html.erb
vendored
Normal file
1
actionpack/test/fixtures/test/_partial_with_only_html_version.html.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
partial with only html version
|
||||
@@ -10,37 +10,37 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase
|
||||
@object_name = 'book'
|
||||
stubs(:content_tag).returns 'content_tag'
|
||||
|
||||
I18n.stubs(:t).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
|
||||
I18n.stubs(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
|
||||
I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
|
||||
I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
|
||||
end
|
||||
|
||||
def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message
|
||||
I18n.expects(:translate).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never
|
||||
error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en-US')
|
||||
I18n.expects(:translate).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never
|
||||
error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en')
|
||||
end
|
||||
|
||||
def test_error_messages_for_given_no_header_option_it_translates_header_message
|
||||
I18n.expects(:t).with(:'header', :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message'
|
||||
I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message'
|
||||
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
|
||||
error_messages_for(:object => @object, :locale => 'en-US')
|
||||
error_messages_for(:object => @object, :locale => 'en')
|
||||
end
|
||||
|
||||
def test_error_messages_for_given_a_message_option_it_does_not_translate_message
|
||||
I18n.expects(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).never
|
||||
I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).never
|
||||
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
|
||||
error_messages_for(:object => @object, :message => 'message', :locale => 'en-US')
|
||||
error_messages_for(:object => @object, :message => 'message', :locale => 'en')
|
||||
end
|
||||
|
||||
def test_error_messages_for_given_no_message_option_it_translates_message
|
||||
I18n.expects(:t).with(:'body', :locale => 'en-US', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
|
||||
I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
|
||||
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
|
||||
error_messages_for(:object => @object, :locale => 'en-US')
|
||||
error_messages_for(:object => @object, :locale => 'en')
|
||||
end
|
||||
|
||||
def test_error_messages_for_given_object_name_it_translates_object_name
|
||||
I18n.expects(:t).with(:header, :locale => 'en-US', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved"
|
||||
I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved"
|
||||
I18n.expects(:t).with(@object_name, :default => @object_name, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name
|
||||
error_messages_for(:object => @object, :locale => 'en-US', :object_name => @object_name)
|
||||
error_messages_for(:object => @object, :locale => 'en', :object_name => @object_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -648,4 +648,10 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase
|
||||
ensure
|
||||
ActionController::Base.asset_host = nil
|
||||
end
|
||||
|
||||
def test_assert_css_and_js_of_the_same_name_return_correct_extension
|
||||
assert_dom_equal(%(/collaboration/hieraki/javascripts/foo.js), javascript_path("foo"))
|
||||
assert_dom_equal(%(/collaboration/hieraki/stylesheets/foo.css), stylesheet_path("foo"))
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,30 +12,42 @@ uses_mocha 'TestTemplateRecompilation' do
|
||||
|
||||
def test_template_gets_compiled
|
||||
assert_equal 0, @compiled_templates.instance_methods.size
|
||||
assert_equal "Hello world!", render("test/hello_world.erb")
|
||||
assert_deprecated do
|
||||
assert_equal "Hello world!", render("test/hello_world.erb")
|
||||
end
|
||||
assert_equal 1, @compiled_templates.instance_methods.size
|
||||
end
|
||||
|
||||
def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
|
||||
assert_equal 0, @compiled_templates.instance_methods.size
|
||||
assert_equal "Hello world!", render("test/hello_world.erb")
|
||||
assert_equal "Hello world!", render("test/hello_world.erb", {:foo => "bar"})
|
||||
assert_deprecated do
|
||||
assert_equal "Hello world!", render("test/hello_world.erb")
|
||||
assert_equal "Hello world!", render("test/hello_world.erb", {:foo => "bar"})
|
||||
end
|
||||
assert_equal 2, @compiled_templates.instance_methods.size
|
||||
end
|
||||
|
||||
def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns
|
||||
assert_equal 0, @compiled_templates.instance_methods.size
|
||||
assert_equal "Hello world!", render("test/hello_world.erb")
|
||||
ActionView::Template.any_instance.expects(:compile!).never
|
||||
assert_equal "Hello world!", render("test/hello_world.erb")
|
||||
assert_deprecated do
|
||||
assert_equal "Hello world!", render("test/hello_world.erb")
|
||||
ActionView::Template.any_instance.expects(:compile!).never
|
||||
assert_equal "Hello world!", render("test/hello_world.erb")
|
||||
end
|
||||
end
|
||||
|
||||
def test_compiled_template_will_always_be_recompiled_when_eager_loaded_templates_is_off
|
||||
ActionView::PathSet::Path.expects(:eager_load_templates?).times(4).returns(false)
|
||||
assert_equal 0, @compiled_templates.instance_methods.size
|
||||
assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb")
|
||||
|
||||
assert_deprecated do
|
||||
assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb")
|
||||
end
|
||||
|
||||
ActionView::Template.any_instance.expects(:compile!).times(3)
|
||||
3.times { assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") }
|
||||
assert_deprecated do
|
||||
3.times { assert_equal "Hello world!", render("#{FIXTURE_LOAD_PATH}/test/hello_world.erb") }
|
||||
end
|
||||
assert_equal 1, @compiled_templates.instance_methods.size
|
||||
end
|
||||
|
||||
|
||||
@@ -41,11 +41,11 @@ class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase
|
||||
key, count = *expected
|
||||
to = @from + diff
|
||||
|
||||
options = {:locale => 'en-US', :scope => :'datetime.distance_in_words'}
|
||||
options = {:locale => 'en', :scope => :'datetime.distance_in_words'}
|
||||
options[:count] = count if count
|
||||
|
||||
I18n.expects(:t).with(key, options)
|
||||
distance_of_time_in_words(@from, to, include_seconds, :locale => 'en-US')
|
||||
distance_of_time_in_words(@from, to, include_seconds, :locale => 'en')
|
||||
end
|
||||
|
||||
def test_distance_of_time_pluralizations
|
||||
@@ -78,36 +78,36 @@ class DateHelperSelectTagsI18nTests < Test::Unit::TestCase
|
||||
|
||||
uses_mocha 'date_helper_select_tags_i18n_tests' do
|
||||
def setup
|
||||
I18n.stubs(:translate).with(:'date.month_names', :locale => 'en-US').returns Date::MONTHNAMES
|
||||
I18n.stubs(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES
|
||||
end
|
||||
|
||||
# select_month
|
||||
|
||||
def test_select_month_given_use_month_names_option_does_not_translate_monthnames
|
||||
I18n.expects(:translate).never
|
||||
select_month(8, :locale => 'en-US', :use_month_names => Date::MONTHNAMES)
|
||||
select_month(8, :locale => 'en', :use_month_names => Date::MONTHNAMES)
|
||||
end
|
||||
|
||||
def test_select_month_translates_monthnames
|
||||
I18n.expects(:translate).with(:'date.month_names', :locale => 'en-US').returns Date::MONTHNAMES
|
||||
select_month(8, :locale => 'en-US')
|
||||
I18n.expects(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES
|
||||
select_month(8, :locale => 'en')
|
||||
end
|
||||
|
||||
def test_select_month_given_use_short_month_option_translates_abbr_monthnames
|
||||
I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en-US').returns Date::ABBR_MONTHNAMES
|
||||
select_month(8, :locale => 'en-US', :use_short_month => true)
|
||||
I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en').returns Date::ABBR_MONTHNAMES
|
||||
select_month(8, :locale => 'en', :use_short_month => true)
|
||||
end
|
||||
|
||||
# date_or_time_select
|
||||
|
||||
def test_date_or_time_select_given_an_order_options_does_not_translate_order
|
||||
I18n.expects(:translate).never
|
||||
datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en-US')
|
||||
datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en')
|
||||
end
|
||||
|
||||
def test_date_or_time_select_given_no_order_options_translates_order
|
||||
I18n.expects(:translate).with(:'date.order', :locale => 'en-US').returns [:year, :month, :day]
|
||||
datetime_select('post', 'updated_at', :locale => 'en-US')
|
||||
I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day]
|
||||
datetime_select('post', 'updated_at', :locale => 'en')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -238,6 +238,7 @@ class FormTagHelperTest < ActionView::TestCase
|
||||
def test_boolean_options
|
||||
assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
|
||||
assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
|
||||
assert_dom_equal %(<input type="checkbox" />), tag(:input, :type => "checkbox", :checked => false)
|
||||
assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true)
|
||||
assert_dom_equal %(<select id="people_" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people[]", "<option>david</option>", :multiple => true)
|
||||
assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => nil)
|
||||
|
||||
@@ -13,42 +13,42 @@ class NumberHelperI18nTests < Test::Unit::TestCase
|
||||
@percentage_defaults = { :delimiter => '' }
|
||||
@precision_defaults = { :delimiter => '' }
|
||||
|
||||
I18n.backend.store_translations 'en-US', :number => { :format => @number_defaults,
|
||||
I18n.backend.store_translations 'en', :number => { :format => @number_defaults,
|
||||
:currency => { :format => @currency_defaults }, :human => @human_defaults }
|
||||
end
|
||||
|
||||
def test_number_to_currency_translates_currency_formats
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults)
|
||||
I18n.expects(:translate).with(:'number.currency.format', :locale => 'en-US',
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
||||
I18n.expects(:translate).with(:'number.currency.format', :locale => 'en',
|
||||
:raise => true).returns(@currency_defaults)
|
||||
number_to_currency(1, :locale => 'en-US')
|
||||
number_to_currency(1, :locale => 'en')
|
||||
end
|
||||
|
||||
def test_number_with_precision_translates_number_formats
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults)
|
||||
I18n.expects(:translate).with(:'number.precision.format', :locale => 'en-US',
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
||||
I18n.expects(:translate).with(:'number.precision.format', :locale => 'en',
|
||||
:raise => true).returns(@precision_defaults)
|
||||
number_with_precision(1, :locale => 'en-US')
|
||||
number_with_precision(1, :locale => 'en')
|
||||
end
|
||||
|
||||
def test_number_with_delimiter_translates_number_formats
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults)
|
||||
number_with_delimiter(1, :locale => 'en-US')
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
||||
number_with_delimiter(1, :locale => 'en')
|
||||
end
|
||||
|
||||
def test_number_to_percentage_translates_number_formats
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults)
|
||||
I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en-US',
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
||||
I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en',
|
||||
:raise => true).returns(@percentage_defaults)
|
||||
number_to_percentage(1, :locale => 'en-US')
|
||||
number_to_percentage(1, :locale => 'en')
|
||||
end
|
||||
|
||||
def test_number_to_human_size_translates_human_formats
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en-US', :raise => true).returns(@number_defaults)
|
||||
I18n.expects(:translate).with(:'number.human.format', :locale => 'en-US',
|
||||
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
||||
I18n.expects(:translate).with(:'number.human.format', :locale => 'en',
|
||||
:raise => true).returns(@human_defaults)
|
||||
# can't be called with 1 because this directly returns without calling I18n.translate
|
||||
number_to_human_size(1025, :locale => 'en-US')
|
||||
number_to_human_size(1025, :locale => 'en')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,9 @@ class ViewRenderTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_render_file
|
||||
assert_equal "Hello world!", @view.render("test/hello_world.erb")
|
||||
assert_deprecated do
|
||||
assert_equal "Hello world!", @view.render("test/hello_world.erb")
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_file_not_using_full_path
|
||||
@@ -16,11 +18,15 @@ class ViewRenderTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_render_file_without_specific_extension
|
||||
assert_equal "Hello world!", @view.render("test/hello_world")
|
||||
assert_deprecated do
|
||||
assert_equal "Hello world!", @view.render("test/hello_world")
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_file_at_top_level
|
||||
assert_equal 'Elastica', @view.render('/shared')
|
||||
assert_deprecated do
|
||||
assert_equal 'Elastica', @view.render('/shared')
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_file_with_full_path
|
||||
@@ -29,20 +35,28 @@ class ViewRenderTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_render_file_with_instance_variables
|
||||
assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_ivar.erb")
|
||||
assert_deprecated do
|
||||
assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_ivar.erb")
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_file_with_locals
|
||||
locals = { :secret => 'in the sauce' }
|
||||
assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_locals.erb", locals)
|
||||
assert_deprecated do
|
||||
assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_locals.erb", locals)
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_file_not_using_full_path_with_dot_in_path
|
||||
assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar")
|
||||
assert_deprecated do
|
||||
assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar")
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_has_access_current_template
|
||||
assert_equal "test/template.erb", @view.render("test/template.erb")
|
||||
assert_deprecated do
|
||||
assert_equal "test/template.erb", @view.render("test/template.erb")
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_update
|
||||
|
||||
@@ -10,12 +10,12 @@ class TranslationHelperTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_delegates_to_i18n_setting_the_raise_option
|
||||
I18n.expects(:translate).with(:foo, :locale => 'en-US', :raise => true)
|
||||
translate :foo, :locale => 'en-US'
|
||||
I18n.expects(:translate).with(:foo, :locale => 'en', :raise => true)
|
||||
translate :foo, :locale => 'en'
|
||||
end
|
||||
|
||||
def test_returns_missing_translation_message_wrapped_into_span
|
||||
expected = '<span class="translation_missing">en-US, foo</span>'
|
||||
expected = '<span class="translation_missing">en, foo</span>'
|
||||
assert_equal expected, translate(:foo)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
*2.2.1 [RC2] (November 14th, 2008)*
|
||||
*2.2 (November 21st, 2008)*
|
||||
|
||||
* Ensure indices don't flip order in schema.rb #1266 [Jordi Bunster]
|
||||
|
||||
* Fixed that serialized strings should never be type-casted (i.e. turning "Yes" to a boolean) #857 [Andreas Korth]
|
||||
|
||||
|
||||
*2.2.0 [RC1] (October 24th, 2008)*
|
||||
|
||||
* Skip collection ids reader optimization if using :finder_sql [Jeremy Kemper]
|
||||
|
||||
* Add Model#delete instance method, similar to Model.delete class method. #1086 [Hongli Lai]
|
||||
|
||||
@@ -171,7 +171,7 @@ spec = Gem::Specification.new do |s|
|
||||
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
||||
end
|
||||
|
||||
s.add_dependency('activesupport', '= 2.2.1' + PKG_BUILD)
|
||||
s.add_dependency('activesupport', '= 2.2.2' + PKG_BUILD)
|
||||
|
||||
s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite"
|
||||
s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite"
|
||||
|
||||
@@ -78,4 +78,4 @@ require 'active_record/connection_adapters/abstract_adapter'
|
||||
require 'active_record/schema_dumper'
|
||||
|
||||
require 'active_record/i18n_interpolation_deprecation'
|
||||
I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en-US.yml'
|
||||
I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
|
||||
|
||||
@@ -8,11 +8,10 @@ module ActiveRecord
|
||||
current_object = @owner.send(@reflection.through_reflection.name)
|
||||
|
||||
if current_object
|
||||
klass.destroy(current_object)
|
||||
@owner.clear_association_cache
|
||||
current_object.update_attributes(construct_join_attributes(new_value))
|
||||
else
|
||||
@owner.send(@reflection.through_reflection.name, klass.send(:create, construct_join_attributes(new_value)))
|
||||
end
|
||||
|
||||
@owner.send(@reflection.through_reflection.name, klass.send(:create, construct_join_attributes(new_value)))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1612,9 +1612,17 @@ module ActiveRecord #:nodoc:
|
||||
end
|
||||
end
|
||||
|
||||
def default_select(qualified)
|
||||
if qualified
|
||||
quoted_table_name + '.*'
|
||||
else
|
||||
'*'
|
||||
end
|
||||
end
|
||||
|
||||
def construct_finder_sql(options)
|
||||
scope = scope(:find)
|
||||
sql = "SELECT #{options[:select] || (scope && scope[:select]) || ((options[:joins] || (scope && scope[:joins])) && quoted_table_name + '.*') || '*'} "
|
||||
sql = "SELECT #{options[:select] || (scope && scope[:select]) || default_select(options[:joins] || (scope && scope[:joins]))} "
|
||||
sql << "FROM #{(scope && scope[:from]) || options[:from] || quoted_table_name} "
|
||||
|
||||
add_joins!(sql, options[:joins], scope)
|
||||
|
||||
@@ -31,7 +31,7 @@ module ActiveRecord
|
||||
include QueryCache
|
||||
include ActiveSupport::Callbacks
|
||||
define_callbacks :checkout, :checkin
|
||||
checkout :reset!
|
||||
|
||||
@@row_even = true
|
||||
|
||||
def initialize(connection, logger = nil) #:nodoc:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
en-US:
|
||||
en:
|
||||
activerecord:
|
||||
errors:
|
||||
# The values :model, :attribute and :value are always available for interpolation
|
||||
@@ -11,11 +11,9 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
def assert_date_from_db(expected, actual, message = nil)
|
||||
# SQL Server doesn't have a separate column type just for dates,
|
||||
# SybaseAdapter doesn't have a separate column type just for dates,
|
||||
# so the time is in the string and incorrectly formatted
|
||||
if current_adapter?(:SQLServerAdapter)
|
||||
assert_equal expected.strftime("%Y/%m/%d 00:00:00"), actual.strftime("%Y/%m/%d 00:00:00")
|
||||
elsif current_adapter?(:SybaseAdapter)
|
||||
if current_adapter?(:SybaseAdapter)
|
||||
assert_equal expected.to_s, actual.to_date.to_s, message
|
||||
else
|
||||
assert_equal expected.to_s, actual.to_s, message
|
||||
|
||||
@@ -2,7 +2,7 @@ module ActiveRecord
|
||||
module VERSION #:nodoc:
|
||||
MAJOR = 2
|
||||
MINOR = 2
|
||||
TINY = 1
|
||||
TINY = 2
|
||||
|
||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||
end
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
require "cases/helper"
|
||||
require 'models/default'
|
||||
require 'models/post'
|
||||
require 'models/task'
|
||||
|
||||
class SqlServerAdapterTest < ActiveRecord::TestCase
|
||||
class TableWithRealColumn < ActiveRecord::Base; end
|
||||
|
||||
fixtures :posts, :tasks
|
||||
|
||||
def setup
|
||||
@connection = ActiveRecord::Base.connection
|
||||
end
|
||||
|
||||
def teardown
|
||||
@connection.execute("SET LANGUAGE us_english") rescue nil
|
||||
end
|
||||
|
||||
def test_real_column_has_float_type
|
||||
assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type
|
||||
end
|
||||
|
||||
# SQL Server 2000 has a bug where some unambiguous date formats are not
|
||||
# correctly identified if the session language is set to german
|
||||
def test_date_insertion_when_language_is_german
|
||||
@connection.execute("SET LANGUAGE deutsch")
|
||||
|
||||
assert_nothing_raised do
|
||||
Task.create(:starting => Time.utc(2000, 1, 31, 5, 42, 0), :ending => Date.new(2006, 12, 31))
|
||||
end
|
||||
end
|
||||
|
||||
def test_indexes_with_descending_order
|
||||
# Make sure we have an index with descending order
|
||||
@connection.execute "CREATE INDEX idx_credit_limit ON accounts (credit_limit DESC)" rescue nil
|
||||
assert_equal ["credit_limit"], @connection.indexes('accounts').first.columns
|
||||
ensure
|
||||
@connection.execute "DROP INDEX accounts.idx_credit_limit"
|
||||
end
|
||||
|
||||
def test_execute_without_block_closes_statement
|
||||
assert_all_statements_used_are_closed do
|
||||
@connection.execute("SELECT 1")
|
||||
end
|
||||
end
|
||||
|
||||
def test_execute_with_block_closes_statement
|
||||
assert_all_statements_used_are_closed do
|
||||
@connection.execute("SELECT 1") do |sth|
|
||||
assert !sth.finished?, "Statement should still be alive within block"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_insert_with_identity_closes_statement
|
||||
assert_all_statements_used_are_closed do
|
||||
@connection.insert("INSERT INTO accounts ([id], [firm_id],[credit_limit]) values (999, 1, 50)")
|
||||
end
|
||||
end
|
||||
|
||||
def test_insert_without_identity_closes_statement
|
||||
assert_all_statements_used_are_closed do
|
||||
@connection.insert("INSERT INTO accounts ([firm_id],[credit_limit]) values (1, 50)")
|
||||
end
|
||||
end
|
||||
|
||||
def test_active_closes_statement
|
||||
assert_all_statements_used_are_closed do
|
||||
@connection.active?
|
||||
end
|
||||
end
|
||||
|
||||
def assert_all_statements_used_are_closed(&block)
|
||||
existing_handles = []
|
||||
ObjectSpace.each_object(DBI::StatementHandle) {|handle| existing_handles << handle}
|
||||
GC.disable
|
||||
|
||||
yield
|
||||
|
||||
used_handles = []
|
||||
ObjectSpace.each_object(DBI::StatementHandle) {|handle| used_handles << handle unless existing_handles.include? handle}
|
||||
|
||||
assert_block "No statements were used within given block" do
|
||||
used_handles.size > 0
|
||||
end
|
||||
|
||||
ObjectSpace.each_object(DBI::StatementHandle) do |handle|
|
||||
assert_block "Statement should have been closed within given block" do
|
||||
handle.finished?
|
||||
end
|
||||
end
|
||||
ensure
|
||||
GC.enable
|
||||
end
|
||||
end
|
||||
@@ -667,7 +667,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
|
||||
end
|
||||
|
||||
def test_count_with_include
|
||||
if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
|
||||
if current_adapter?(:SybaseAdapter)
|
||||
assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "len(comments.body) > 15")
|
||||
elsif current_adapter?(:OpenBaseAdapter)
|
||||
assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "length(FETCHBLOB(comments.body)) > 15")
|
||||
|
||||
@@ -3,9 +3,11 @@ require 'models/club'
|
||||
require 'models/member'
|
||||
require 'models/membership'
|
||||
require 'models/sponsor'
|
||||
require 'models/organization'
|
||||
require 'models/member_detail'
|
||||
|
||||
class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
||||
fixtures :members, :clubs, :memberships, :sponsors
|
||||
fixtures :members, :clubs, :memberships, :sponsors, :organizations
|
||||
|
||||
def setup
|
||||
@member = members(:groucho)
|
||||
@@ -120,4 +122,40 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
||||
clubs(:moustache_club).send(:private_method)
|
||||
@member.club.send(:private_method)
|
||||
end
|
||||
|
||||
def test_assigning_to_has_one_through_preserves_decorated_join_record
|
||||
@organization = organizations(:nsa)
|
||||
assert_difference 'MemberDetail.count', 1 do
|
||||
@member_detail = MemberDetail.new(:extra_data => 'Extra')
|
||||
@member.member_detail = @member_detail
|
||||
@member.organization = @organization
|
||||
end
|
||||
assert_equal @organization, @member.organization
|
||||
assert @organization.members.include?(@member)
|
||||
assert_equal 'Extra', @member.member_detail.extra_data
|
||||
end
|
||||
|
||||
def test_reassigning_has_one_through
|
||||
@organization = organizations(:nsa)
|
||||
@new_organization = organizations(:discordians)
|
||||
|
||||
assert_difference 'MemberDetail.count', 1 do
|
||||
@member_detail = MemberDetail.new(:extra_data => 'Extra')
|
||||
@member.member_detail = @member_detail
|
||||
@member.organization = @organization
|
||||
end
|
||||
assert_equal @organization, @member.organization
|
||||
assert_equal 'Extra', @member.member_detail.extra_data
|
||||
assert @organization.members.include?(@member)
|
||||
assert !@new_organization.members.include?(@member)
|
||||
|
||||
assert_no_difference 'MemberDetail.count' do
|
||||
@member.organization = @new_organization
|
||||
end
|
||||
assert_equal @new_organization, @member.organization
|
||||
assert_equal 'Extra', @member.member_detail.extra_data
|
||||
assert !@organization.members.include?(@member)
|
||||
assert @new_organization.members.include?(@member)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -428,9 +428,6 @@ class BasicsTest < ActiveRecord::TestCase
|
||||
end
|
||||
|
||||
def test_preserving_date_objects
|
||||
# SQL Server doesn't have a separate column type just for dates, so all are returned as time
|
||||
return true if current_adapter?(:SQLServerAdapter)
|
||||
|
||||
if current_adapter?(:SybaseAdapter, :OracleAdapter)
|
||||
# Sybase ctlib does not (yet?) support the date type; use datetime instead.
|
||||
# Oracle treats all dates/times as Time.
|
||||
@@ -777,8 +774,8 @@ class BasicsTest < ActiveRecord::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
# Oracle, SQLServer, and Sybase do not have a TIME datatype.
|
||||
unless current_adapter?(:SQLServerAdapter, :OracleAdapter, :SybaseAdapter)
|
||||
# Oracle, and Sybase do not have a TIME datatype.
|
||||
unless current_adapter?(:OracleAdapter, :SybaseAdapter)
|
||||
def test_utc_as_time_zone
|
||||
Topic.default_timezone = :utc
|
||||
attributes = { "bonus_time" => "5:42:00AM" }
|
||||
@@ -1157,8 +1154,8 @@ class BasicsTest < ActiveRecord::TestCase
|
||||
end
|
||||
|
||||
def test_attributes_on_dummy_time
|
||||
# Oracle, SQL Server, and Sybase do not have a TIME datatype.
|
||||
return true if current_adapter?(:SQLServerAdapter, :OracleAdapter, :SybaseAdapter)
|
||||
# Oracle, and Sybase do not have a TIME datatype.
|
||||
return true if current_adapter?(:OracleAdapter, :SybaseAdapter)
|
||||
|
||||
attributes = {
|
||||
"bonus_time" => "5:42:00AM"
|
||||
@@ -1874,7 +1871,7 @@ class BasicsTest < ActiveRecord::TestCase
|
||||
assert_equal "integer", xml.elements["//parent-id"].attributes['type']
|
||||
assert_equal "true", xml.elements["//parent-id"].attributes['nil']
|
||||
|
||||
if current_adapter?(:SybaseAdapter, :SQLServerAdapter, :OracleAdapter)
|
||||
if current_adapter?(:SybaseAdapter, :OracleAdapter)
|
||||
assert_equal last_read_in_current_timezone, xml.elements["//last-read"].text
|
||||
assert_equal "datetime" , xml.elements["//last-read"].attributes['type']
|
||||
else
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
require "cases/helper"
|
||||
|
||||
# Without using prepared statements, it makes no sense to test
|
||||
# BLOB data with SQL Server, because the length of a statement is
|
||||
# limited to 8KB.
|
||||
#
|
||||
# Without using prepared statements, it makes no sense to test
|
||||
# BLOB data with DB2 or Firebird, because the length of a statement
|
||||
# is limited to 32KB.
|
||||
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
|
||||
unless current_adapter?(:SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
|
||||
require 'models/binary'
|
||||
|
||||
class BinaryTest < ActiveRecord::TestCase
|
||||
|
||||
@@ -78,7 +78,7 @@ class DefaultTest < ActiveRecord::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter, :FirebirdAdapter, :OpenBaseAdapter, :OracleAdapter)
|
||||
if current_adapter?(:PostgreSQLAdapter, :FirebirdAdapter, :OpenBaseAdapter, :OracleAdapter)
|
||||
def test_default_integers
|
||||
default = Default.new
|
||||
assert_instance_of Fixnum, default.positive_integer
|
||||
|
||||
@@ -9,32 +9,32 @@ class ActiveRecordI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_translated_model_attributes
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:attributes => {:topic => {:title => 'topic title attribute'} } }
|
||||
I18n.backend.store_translations 'en', :activerecord => {:attributes => {:topic => {:title => 'topic title attribute'} } }
|
||||
assert_equal 'topic title attribute', Topic.human_attribute_name('title')
|
||||
end
|
||||
|
||||
def test_translated_model_attributes_with_sti
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:attributes => {:reply => {:title => 'reply title attribute'} } }
|
||||
I18n.backend.store_translations 'en', :activerecord => {:attributes => {:reply => {:title => 'reply title attribute'} } }
|
||||
assert_equal 'reply title attribute', Reply.human_attribute_name('title')
|
||||
end
|
||||
|
||||
def test_translated_model_attributes_with_sti_fallback
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:attributes => {:topic => {:title => 'topic title attribute'} } }
|
||||
I18n.backend.store_translations 'en', :activerecord => {:attributes => {:topic => {:title => 'topic title attribute'} } }
|
||||
assert_equal 'topic title attribute', Reply.human_attribute_name('title')
|
||||
end
|
||||
|
||||
def test_translated_model_names
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:models => {:topic => 'topic model'} }
|
||||
I18n.backend.store_translations 'en', :activerecord => {:models => {:topic => 'topic model'} }
|
||||
assert_equal 'topic model', Topic.human_name
|
||||
end
|
||||
|
||||
def test_translated_model_names_with_sti
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:models => {:reply => 'reply model'} }
|
||||
I18n.backend.store_translations 'en', :activerecord => {:models => {:reply => 'reply model'} }
|
||||
assert_equal 'reply model', Reply.human_name
|
||||
end
|
||||
|
||||
def test_translated_model_names_with_sti_fallback
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:models => {:topic => 'topic model'} }
|
||||
I18n.backend.store_translations 'en', :activerecord => {:models => {:topic => 'topic model'} }
|
||||
assert_equal 'topic model', Reply.human_name
|
||||
end
|
||||
end
|
||||
|
||||
@@ -59,13 +59,13 @@ class InheritanceTest < ActiveRecord::TestCase
|
||||
|
||||
def test_a_bad_type_column
|
||||
#SQLServer need to turn Identity Insert On before manually inserting into the Identity column
|
||||
if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
|
||||
if current_adapter?(:SybaseAdapter)
|
||||
Company.connection.execute "SET IDENTITY_INSERT companies ON"
|
||||
end
|
||||
Company.connection.insert "INSERT INTO companies (id, #{QUOTED_TYPE}, name) VALUES(100, 'bad_class!', 'Not happening')"
|
||||
|
||||
#We then need to turn it back Off before continuing.
|
||||
if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
|
||||
if current_adapter?(:SybaseAdapter)
|
||||
Company.connection.execute "SET IDENTITY_INSERT companies OFF"
|
||||
end
|
||||
assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) }
|
||||
|
||||
@@ -200,9 +200,9 @@ end
|
||||
# blocks, so separate script called by Kernel#system is needed.
|
||||
# (See exec vs. async_exec in the PostgreSQL adapter.)
|
||||
|
||||
# TODO: The SQL Server, Sybase, and OpenBase adapters currently have no support for pessimistic locking
|
||||
# TODO: The Sybase, and OpenBase adapters currently have no support for pessimistic locking
|
||||
|
||||
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :OpenBaseAdapter)
|
||||
unless current_adapter?(:SybaseAdapter, :OpenBaseAdapter)
|
||||
class PessimisticLockingTest < ActiveRecord::TestCase
|
||||
self.use_transactional_fixtures = false
|
||||
fixtures :people, :readers
|
||||
|
||||
@@ -271,9 +271,9 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||
Person.connection.drop_table table_name rescue nil
|
||||
end
|
||||
|
||||
# SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL
|
||||
# Sybase, and SQLite3 will not allow you to add a NOT NULL
|
||||
# column to a table without a default value.
|
||||
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :SQLiteAdapter)
|
||||
unless current_adapter?(:SybaseAdapter, :SQLiteAdapter)
|
||||
def test_add_column_not_null_without_default
|
||||
Person.connection.create_table :testings do |t|
|
||||
t.column :foo, :string
|
||||
@@ -410,7 +410,7 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||
assert_equal Fixnum, bob.age.class
|
||||
assert_equal Time, bob.birthday.class
|
||||
|
||||
if current_adapter?(:SQLServerAdapter, :OracleAdapter, :SybaseAdapter)
|
||||
if current_adapter?(:OracleAdapter, :SybaseAdapter)
|
||||
# Sybase, and Oracle don't differentiate between date/time
|
||||
assert_equal Time, bob.favorite_day.class
|
||||
else
|
||||
@@ -851,10 +851,6 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||
# - SQLite3 stores a float, in violation of SQL
|
||||
assert_kind_of BigDecimal, b.value_of_e
|
||||
assert_equal BigDecimal("2.71828182845905"), b.value_of_e
|
||||
elsif current_adapter?(:SQLServer)
|
||||
# - SQL Server rounds instead of truncating
|
||||
assert_kind_of Fixnum, b.value_of_e
|
||||
assert_equal 3, b.value_of_e
|
||||
else
|
||||
# - SQL standard is an integer
|
||||
assert_kind_of Fixnum, b.value_of_e
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
require "cases/helper"
|
||||
require 'active_record/schema'
|
||||
|
||||
if ActiveRecord::Base.connection.supports_migrations?
|
||||
class Order < ActiveRecord::Base
|
||||
self.table_name = '[order]'
|
||||
end
|
||||
|
||||
class TableNameTest < ActiveRecord::TestCase
|
||||
self.use_transactional_fixtures = false
|
||||
|
||||
# Ensures Model.columns works when using SQLServer escape characters.
|
||||
# Enables legacy schemas using SQL reserved words as table names.
|
||||
# Should work with table names with spaces as well ('table name').
|
||||
def test_escaped_table_name
|
||||
assert_nothing_raised do
|
||||
ActiveRecord::Base.connection.select_all 'SELECT * FROM [order]'
|
||||
end
|
||||
assert_equal '[order]', Order.table_name
|
||||
assert_equal 5, Order.columns.length
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -9,7 +9,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
@old_load_path, @old_backend = I18n.load_path, I18n.backend
|
||||
I18n.load_path.clear
|
||||
I18n.backend = I18n::Backend::Simple.new
|
||||
I18n.backend.store_translations('en-US', :activerecord => {:errors => {:messages => {:custom => nil}}})
|
||||
I18n.backend.store_translations('en', :activerecord => {:errors => {:messages => {:custom => nil}}})
|
||||
end
|
||||
|
||||
def teardown
|
||||
@@ -165,7 +165,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
def test_errors_full_messages_translates_human_attribute_name_for_model_attributes
|
||||
@topic.errors.instance_variable_set :@errors, { 'title' => ['empty'] }
|
||||
I18n.expects(:translate).with(:"topic.title", :default => ['Title'], :scope => [:activerecord, :attributes], :count => 1).returns('Title')
|
||||
@topic.errors.full_messages :locale => 'en-US'
|
||||
@topic.errors.full_messages :locale => 'en'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -429,8 +429,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_confirmation_of w/o mocha
|
||||
|
||||
def test_validates_confirmation_of_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:confirmation => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:confirmation => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
|
||||
|
||||
Topic.validates_confirmation_of :title
|
||||
@topic.title_confirmation = 'foo'
|
||||
@@ -439,7 +439,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_confirmation_of_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
|
||||
|
||||
Topic.validates_confirmation_of :title
|
||||
@topic.title_confirmation = 'foo'
|
||||
@@ -450,8 +450,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_acceptance_of w/o mocha
|
||||
|
||||
def test_validates_acceptance_of_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:accepted => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:accepted => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
|
||||
|
||||
Topic.validates_acceptance_of :title, :allow_nil => false
|
||||
@topic.valid?
|
||||
@@ -459,7 +459,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_acceptance_of_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
|
||||
|
||||
Topic.validates_acceptance_of :title, :allow_nil => false
|
||||
@topic.valid?
|
||||
@@ -469,8 +469,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_presence_of w/o mocha
|
||||
|
||||
def test_validates_presence_of_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:blank => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:blank => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
|
||||
|
||||
Topic.validates_presence_of :title
|
||||
@topic.valid?
|
||||
@@ -478,7 +478,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_presence_of_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
|
||||
|
||||
Topic.validates_presence_of :title
|
||||
@topic.valid?
|
||||
@@ -488,8 +488,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_length_of :within w/o mocha
|
||||
|
||||
def test_validates_length_of_within_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:too_short => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:too_short => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
|
||||
|
||||
Topic.validates_length_of :title, :within => 3..5
|
||||
@topic.valid?
|
||||
@@ -497,7 +497,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_length_of_within_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
|
||||
|
||||
Topic.validates_length_of :title, :within => 3..5
|
||||
@topic.valid?
|
||||
@@ -507,8 +507,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_length_of :is w/o mocha
|
||||
|
||||
def test_validates_length_of_within_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
||||
|
||||
Topic.validates_length_of :title, :is => 5
|
||||
@topic.valid?
|
||||
@@ -516,7 +516,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_length_of_within_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
||||
|
||||
Topic.validates_length_of :title, :is => 5
|
||||
@topic.valid?
|
||||
@@ -526,8 +526,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_uniqueness_of w/o mocha
|
||||
|
||||
def test_validates_length_of_within_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
||||
|
||||
Topic.validates_length_of :title, :is => 5
|
||||
@topic.valid?
|
||||
@@ -535,7 +535,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_length_of_within_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
||||
|
||||
Topic.validates_length_of :title, :is => 5
|
||||
@topic.valid?
|
||||
@@ -546,8 +546,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_format_of w/o mocha
|
||||
|
||||
def test_validates_format_of_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:invalid => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:invalid => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
||||
|
||||
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
|
||||
@topic.valid?
|
||||
@@ -555,7 +555,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_format_of_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
||||
|
||||
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
|
||||
@topic.valid?
|
||||
@@ -565,8 +565,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_inclusion_of w/o mocha
|
||||
|
||||
def test_validates_inclusion_of_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:inclusion => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:inclusion => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
|
||||
|
||||
Topic.validates_inclusion_of :title, :in => %w(a b c)
|
||||
@topic.valid?
|
||||
@@ -574,7 +574,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_inclusion_of_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
|
||||
|
||||
Topic.validates_inclusion_of :title, :in => %w(a b c)
|
||||
@topic.valid?
|
||||
@@ -584,8 +584,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_exclusion_of w/o mocha
|
||||
|
||||
def test_validates_exclusion_of_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:exclusion => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:exclusion => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}}
|
||||
|
||||
Topic.validates_exclusion_of :title, :in => %w(a b c)
|
||||
@topic.title = 'a'
|
||||
@@ -594,7 +594,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_exclusion_of_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}}
|
||||
|
||||
Topic.validates_exclusion_of :title, :in => %w(a b c)
|
||||
@topic.title = 'a'
|
||||
@@ -605,8 +605,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_numericality_of without :only_integer w/o mocha
|
||||
|
||||
def test_validates_numericality_of_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
||||
|
||||
Topic.validates_numericality_of :title
|
||||
@topic.title = 'a'
|
||||
@@ -615,7 +615,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_numericality_of_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
||||
|
||||
Topic.validates_numericality_of :title, :only_integer => true
|
||||
@topic.title = 'a'
|
||||
@@ -626,8 +626,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_numericality_of with :only_integer w/o mocha
|
||||
|
||||
def test_validates_numericality_of_only_integer_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
||||
|
||||
Topic.validates_numericality_of :title, :only_integer => true
|
||||
@topic.title = 'a'
|
||||
@@ -636,7 +636,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_numericality_of_only_integer_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
||||
|
||||
Topic.validates_numericality_of :title, :only_integer => true
|
||||
@topic.title = 'a'
|
||||
@@ -647,8 +647,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_numericality_of :odd w/o mocha
|
||||
|
||||
def test_validates_numericality_of_odd_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:odd => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:odd => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:odd => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:odd => 'global message'}}}
|
||||
|
||||
Topic.validates_numericality_of :title, :only_integer => true, :odd => true
|
||||
@topic.title = 0
|
||||
@@ -657,7 +657,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_numericality_of_odd_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:odd => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:odd => 'global message'}}}
|
||||
|
||||
Topic.validates_numericality_of :title, :only_integer => true, :odd => true
|
||||
@topic.title = 0
|
||||
@@ -668,8 +668,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_numericality_of :less_than w/o mocha
|
||||
|
||||
def test_validates_numericality_of_less_than_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:less_than => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:less_than => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}}
|
||||
|
||||
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
|
||||
@topic.title = 1
|
||||
@@ -678,7 +678,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_numericality_of_less_than_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}}
|
||||
|
||||
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
|
||||
@topic.title = 1
|
||||
@@ -690,8 +690,8 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
# validates_associated w/o mocha
|
||||
|
||||
def test_validates_associated_finds_custom_model_key_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:replies => {:invalid => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:replies => {:invalid => 'custom message'}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
||||
|
||||
Topic.validates_associated :replies
|
||||
replied_topic.valid?
|
||||
@@ -699,7 +699,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_associated_finds_global_default_translation
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
||||
|
||||
Topic.validates_associated :replies
|
||||
replied_topic.valid?
|
||||
@@ -707,7 +707,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validations_with_message_symbol_must_translate
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:custom_error => "I am a custom error"}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:custom_error => "I am a custom error"}}}
|
||||
Topic.validates_presence_of :title, :message => :custom_error
|
||||
@topic.title = nil
|
||||
@topic.valid?
|
||||
@@ -715,7 +715,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_with_message_symbol_must_translate_per_attribute
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:custom_error => "I am a custom error"}}}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:custom_error => "I am a custom error"}}}}}}
|
||||
Topic.validates_presence_of :title, :message => :custom_error
|
||||
@topic.title = nil
|
||||
@topic.valid?
|
||||
@@ -723,7 +723,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_validates_with_message_symbol_must_translate_per_model
|
||||
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:models => {:topic => {:custom_error => "I am a custom error"}}}}
|
||||
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:custom_error => "I am a custom error"}}}}
|
||||
Topic.validates_presence_of :title, :message => :custom_error
|
||||
@topic.title = nil
|
||||
@topic.valid?
|
||||
@@ -743,7 +743,7 @@ class ActiveRecordValidationsGenerateMessageI18nTests < Test::Unit::TestCase
|
||||
def setup
|
||||
reset_callbacks Topic
|
||||
@topic = Topic.new
|
||||
I18n.backend.store_translations :'en-US', {
|
||||
I18n.backend.store_translations :'en', {
|
||||
:activerecord => {
|
||||
:errors => {
|
||||
:messages => {
|
||||
|
||||
5
activerecord/test/fixtures/organizations.yml
vendored
Normal file
5
activerecord/test/fixtures/organizations.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
nsa:
|
||||
name: No Such Agency
|
||||
discordians:
|
||||
name: Discordians
|
||||
|
||||
@@ -6,4 +6,6 @@ class Member < ActiveRecord::Base
|
||||
has_one :favourite_club, :through => :memberships, :conditions => ["memberships.favourite = ?", true], :source => :club
|
||||
has_one :sponsor, :as => :sponsorable
|
||||
has_one :sponsor_club, :through => :sponsor
|
||||
has_one :member_detail
|
||||
has_one :organization, :through => :member_detail
|
||||
end
|
||||
4
activerecord/test/models/member_detail.rb
Normal file
4
activerecord/test/models/member_detail.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class MemberDetail < ActiveRecord::Base
|
||||
belongs_to :member
|
||||
belongs_to :organization
|
||||
end
|
||||
4
activerecord/test/models/organization.rb
Normal file
4
activerecord/test/models/organization.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class Organization < ActiveRecord::Base
|
||||
has_many :member_details
|
||||
has_many :members, :through => :member_details
|
||||
end
|
||||
@@ -197,6 +197,12 @@ ActiveRecord::Schema.define do
|
||||
t.string :name
|
||||
end
|
||||
|
||||
create_table :member_details, :force => true do |t|
|
||||
t.integer :member_id
|
||||
t.integer :organization_id
|
||||
t.string :extra_data
|
||||
end
|
||||
|
||||
create_table :memberships, :force => true do |t|
|
||||
t.datetime :joined_on
|
||||
t.integer :club_id, :member_id
|
||||
@@ -249,6 +255,10 @@ ActiveRecord::Schema.define do
|
||||
t.integer :shipping_customer_id
|
||||
end
|
||||
|
||||
create_table :organizations, :force => true do |t|
|
||||
t.string :name
|
||||
end
|
||||
|
||||
create_table :owners, :primary_key => :owner_id ,:force => true do |t|
|
||||
t.string :name
|
||||
end
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
ActiveRecord::Schema.define do
|
||||
create_table :table_with_real_columns, :force => true do |t|
|
||||
t.column :real_number, :real
|
||||
end
|
||||
end
|
||||
@@ -1,10 +1,7 @@
|
||||
*2.2.1 [RC2] (November 14th, 2008)*
|
||||
*2.2 (November 21st, 2008)*
|
||||
|
||||
* Fixed that ActiveResource#post would post an empty string when it shouldn't be posting anything #525 [Paolo Angelini]
|
||||
|
||||
|
||||
*2.2.0 [RC1] (October 24th, 2008)*
|
||||
|
||||
* Add ActiveResource::Base#to_xml and ActiveResource::Base#to_json. #1011 [Rasik Pandey, Cody Fauser]
|
||||
|
||||
* Add ActiveResource::Base.find(:last). [#754 state:resolved] (Adrian Mugnolo)
|
||||
|
||||
@@ -65,7 +65,7 @@ spec = Gem::Specification.new do |s|
|
||||
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
||||
end
|
||||
|
||||
s.add_dependency('activesupport', '= 2.2.1' + PKG_BUILD)
|
||||
s.add_dependency('activesupport', '= 2.2.2' + PKG_BUILD)
|
||||
|
||||
s.require_path = 'lib'
|
||||
s.autorequire = 'active_resource'
|
||||
|
||||
@@ -2,7 +2,7 @@ module ActiveResource
|
||||
module VERSION #:nodoc:
|
||||
MAJOR = 2
|
||||
MINOR = 2
|
||||
TINY = 1
|
||||
TINY = 2
|
||||
|
||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||
end
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
*2.2.1 [RC2] (November 14th, 2008)*
|
||||
*2.2 (November 21st, 2008)*
|
||||
|
||||
* TimeZone offset tests: use current_period, to ensure TimeZone#utc_offset is up-to-date [Geoff Buesing]
|
||||
|
||||
* Update bundled TZInfo to 0.3.12 [Geoff Buesing]
|
||||
|
||||
* Increment the version of our altered memcache-client to prevent confusion caused when the 1.5.0 gem is installed.
|
||||
|
||||
@@ -6,9 +10,6 @@
|
||||
|
||||
* Make I18n::Backend::Simple reload its translations in development mode [DHH/Sven Fuchs]
|
||||
|
||||
|
||||
*2.2.0 [RC1] (October 24th, 2008)*
|
||||
|
||||
* TimeWithZone#freeze: preload instance variables so that we can actually freeze [Geoff Buesing]
|
||||
|
||||
* Fix Brasilia timezone #1180 [Marcus Derencius, Kane]
|
||||
@@ -57,7 +58,7 @@
|
||||
|
||||
* Added TimeZone #=~, to support matching zones by regex in time_zone_select. #195 [Ernie Miller]
|
||||
|
||||
* Added Array#second through Array#tenth as aliases for Array#[1] through Array#[9] [DHH]
|
||||
* Added Array#second through Array#fifth as aliases for Array#[1] through Array#[4] + Array#forty_two as alias for Array[41] [DHH]
|
||||
|
||||
* Added test/do declaration style testing to ActiveSupport::TestCase [DHH via Jay Fields]
|
||||
|
||||
|
||||
@@ -58,4 +58,4 @@ require 'active_support/secure_random'
|
||||
|
||||
require 'active_support/rescuable'
|
||||
|
||||
I18n.load_path << File.dirname(__FILE__) + '/active_support/locale/en-US.yml'
|
||||
I18n.load_path << File.dirname(__FILE__) + '/active_support/locale/en.yml'
|
||||
|
||||
@@ -43,29 +43,9 @@ module ActiveSupport #:nodoc:
|
||||
self[4]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[5]</tt>.
|
||||
def sixth
|
||||
self[5]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[6]</tt>.
|
||||
def seventh
|
||||
self[6]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[7]</tt>.
|
||||
def eighth
|
||||
self[7]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[8]</tt>.
|
||||
def ninth
|
||||
self[8]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[9]</tt>.
|
||||
def tenth
|
||||
self[9]
|
||||
# Equal to <tt>self[41]</tt>. Also known as accessing "the reddit".
|
||||
def forty_two
|
||||
self[41]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,6 +78,10 @@ class Module
|
||||
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
|
||||
end
|
||||
|
||||
if options[:prefix] == true && options[:to].to_s =~ /^[^a-z_]/
|
||||
raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
|
||||
end
|
||||
|
||||
prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_"
|
||||
|
||||
methods.each do |method|
|
||||
|
||||
@@ -6,7 +6,7 @@ require 'rexml/entity'
|
||||
# This fix is identical to rexml-expansion-fix version 1.0.1
|
||||
|
||||
# Earlier versions of rexml defined REXML::Version, newer ones REXML::VERSION
|
||||
unless (defined?(REXML::VERSION) ? REXML::VERSION : REXML::Version) > "3.1.7.2"
|
||||
unless REXML::Document.respond_to?(:entity_expansion_limit=)
|
||||
module REXML
|
||||
class Entity < Child
|
||||
undef_method :unnormalized
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require 'active_support/duration'
|
||||
|
||||
module ActiveSupport #:nodoc:
|
||||
module CoreExtensions #:nodoc:
|
||||
module Time #:nodoc:
|
||||
|
||||
@@ -313,6 +313,12 @@ module ActiveSupport #:nodoc:
|
||||
nesting = expanded_path[(expanded_root.size)..-1]
|
||||
nesting = nesting[1..-1] if nesting && nesting[0] == ?/
|
||||
next if nesting.blank?
|
||||
nesting_camel = nesting.camelize
|
||||
begin
|
||||
qualified_const_defined?(nesting_camel)
|
||||
rescue NameError
|
||||
next
|
||||
end
|
||||
|
||||
[
|
||||
nesting.camelize,
|
||||
@@ -499,7 +505,7 @@ module ActiveSupport #:nodoc:
|
||||
initial_constants = if qualified_const_defined?(mod_name)
|
||||
mod_name.constantize.local_constant_names
|
||||
else
|
||||
[]
|
||||
[]
|
||||
end
|
||||
else
|
||||
raise Argument, "#{desc.inspect} does not describe a module!"
|
||||
|
||||
@@ -134,7 +134,6 @@ module ActiveSupport
|
||||
# "octopus".pluralize # => "octopi"
|
||||
# "sheep".pluralize # => "sheep"
|
||||
# "words".pluralize # => "words"
|
||||
# "the blue mailman".pluralize # => "the blue mailmen"
|
||||
# "CamelOctopus".pluralize # => "CamelOctopi"
|
||||
def pluralize(word)
|
||||
result = word.to_s.dup
|
||||
@@ -154,7 +153,6 @@ module ActiveSupport
|
||||
# "octopi".singularize # => "octopus"
|
||||
# "sheep".singluarize # => "sheep"
|
||||
# "word".singularize # => "word"
|
||||
# "the blue mailmen".singularize # => "the blue mailman"
|
||||
# "CamelOctopi".singularize # => "CamelOctopus"
|
||||
def singularize(word)
|
||||
result = word.to_s.dup
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
en-US:
|
||||
en:
|
||||
date:
|
||||
formats:
|
||||
# Use the strftime parameters for formats.
|
||||
@@ -20,9 +20,9 @@ rescue Gem::LoadError
|
||||
end
|
||||
|
||||
begin
|
||||
gem 'tzinfo', '~> 0.3.11'
|
||||
gem 'tzinfo', '~> 0.3.12'
|
||||
rescue Gem::LoadError
|
||||
$:.unshift "#{File.dirname(__FILE__)}/vendor/tzinfo-0.3.11"
|
||||
$:.unshift "#{File.dirname(__FILE__)}/vendor/tzinfo-0.3.12"
|
||||
end
|
||||
|
||||
# TODO I18n gem has not been released yet
|
||||
|
||||
@@ -11,7 +11,7 @@ require 'i18n/exceptions'
|
||||
module I18n
|
||||
@@backend = nil
|
||||
@@load_path = nil
|
||||
@@default_locale = :'en-US'
|
||||
@@default_locale = :'en'
|
||||
@@exception_handler = :default_exception_handler
|
||||
|
||||
class << self
|
||||
@@ -25,7 +25,7 @@ module I18n
|
||||
@@backend = backend
|
||||
end
|
||||
|
||||
# Returns the current default locale. Defaults to 'en-US'
|
||||
# Returns the current default locale. Defaults to 'en'
|
||||
def default_locale
|
||||
@@default_locale
|
||||
end
|
||||
@@ -57,7 +57,7 @@ module I18n
|
||||
# files which are either named *.rb and contain plain Ruby Hashes or are
|
||||
# named *.yml and contain YAML data. So for the SimpleBackend clients may
|
||||
# register translation files like this:
|
||||
# I18n.load_path << 'path/to/locale/en-US.yml'
|
||||
# I18n.load_path << 'path/to/locale/en.yml'
|
||||
def load_path
|
||||
@@load_path ||= []
|
||||
end
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
require 'tzinfo/timezone_definition'
|
||||
|
||||
module TZInfo
|
||||
module Definitions
|
||||
module America
|
||||
module Argentina
|
||||
module San_Juan
|
||||
include TimezoneDefinition
|
||||
|
||||
timezone 'America/Argentina/San_Juan' do |tz|
|
||||
tz.offset :o0, -16444, 0, :LMT
|
||||
tz.offset :o1, -15408, 0, :CMT
|
||||
tz.offset :o2, -14400, 0, :ART
|
||||
tz.offset :o3, -14400, 3600, :ARST
|
||||
tz.offset :o4, -10800, 0, :ART
|
||||
tz.offset :o5, -10800, 3600, :ARST
|
||||
tz.offset :o6, -14400, 0, :WART
|
||||
|
||||
tz.transition 1894, 10, :o1, 52123666111, 21600
|
||||
tz.transition 1920, 5, :o2, 1453467407, 600
|
||||
tz.transition 1930, 12, :o3, 7278935, 3
|
||||
tz.transition 1931, 4, :o2, 19411461, 8
|
||||
tz.transition 1931, 10, :o3, 7279889, 3
|
||||
tz.transition 1932, 3, :o2, 19414141, 8
|
||||
tz.transition 1932, 11, :o3, 7281038, 3
|
||||
tz.transition 1933, 3, :o2, 19417061, 8
|
||||
tz.transition 1933, 11, :o3, 7282133, 3
|
||||
tz.transition 1934, 3, :o2, 19419981, 8
|
||||
tz.transition 1934, 11, :o3, 7283228, 3
|
||||
tz.transition 1935, 3, :o2, 19422901, 8
|
||||
tz.transition 1935, 11, :o3, 7284323, 3
|
||||
tz.transition 1936, 3, :o2, 19425829, 8
|
||||
tz.transition 1936, 11, :o3, 7285421, 3
|
||||
tz.transition 1937, 3, :o2, 19428749, 8
|
||||
tz.transition 1937, 11, :o3, 7286516, 3
|
||||
tz.transition 1938, 3, :o2, 19431669, 8
|
||||
tz.transition 1938, 11, :o3, 7287611, 3
|
||||
tz.transition 1939, 3, :o2, 19434589, 8
|
||||
tz.transition 1939, 11, :o3, 7288706, 3
|
||||
tz.transition 1940, 3, :o2, 19437517, 8
|
||||
tz.transition 1940, 7, :o3, 7289435, 3
|
||||
tz.transition 1941, 6, :o2, 19441285, 8
|
||||
tz.transition 1941, 10, :o3, 7290848, 3
|
||||
tz.transition 1943, 8, :o2, 19447501, 8
|
||||
tz.transition 1943, 10, :o3, 7293038, 3
|
||||
tz.transition 1946, 3, :o2, 19455045, 8
|
||||
tz.transition 1946, 10, :o3, 7296284, 3
|
||||
tz.transition 1963, 10, :o2, 19506429, 8
|
||||
tz.transition 1963, 12, :o3, 7315136, 3
|
||||
tz.transition 1964, 3, :o2, 19507645, 8
|
||||
tz.transition 1964, 10, :o3, 7316051, 3
|
||||
tz.transition 1965, 3, :o2, 19510565, 8
|
||||
tz.transition 1965, 10, :o3, 7317146, 3
|
||||
tz.transition 1966, 3, :o2, 19513485, 8
|
||||
tz.transition 1966, 10, :o3, 7318241, 3
|
||||
tz.transition 1967, 4, :o2, 19516661, 8
|
||||
tz.transition 1967, 10, :o3, 7319294, 3
|
||||
tz.transition 1968, 4, :o2, 19519629, 8
|
||||
tz.transition 1968, 10, :o3, 7320407, 3
|
||||
tz.transition 1969, 4, :o2, 19522541, 8
|
||||
tz.transition 1969, 10, :o4, 7321499, 3
|
||||
tz.transition 1974, 1, :o5, 128142000
|
||||
tz.transition 1974, 5, :o4, 136605600
|
||||
tz.transition 1988, 12, :o5, 596948400
|
||||
tz.transition 1989, 3, :o4, 605066400
|
||||
tz.transition 1989, 10, :o5, 624423600
|
||||
tz.transition 1990, 3, :o4, 636516000
|
||||
tz.transition 1990, 10, :o5, 656478000
|
||||
tz.transition 1991, 3, :o6, 667792800
|
||||
tz.transition 1991, 5, :o4, 673588800
|
||||
tz.transition 1991, 10, :o5, 687927600
|
||||
tz.transition 1992, 3, :o4, 699415200
|
||||
tz.transition 1992, 10, :o5, 719377200
|
||||
tz.transition 1993, 3, :o4, 731469600
|
||||
tz.transition 1999, 10, :o3, 938919600
|
||||
tz.transition 2000, 3, :o4, 952052400
|
||||
tz.transition 2004, 5, :o6, 1085972400
|
||||
tz.transition 2004, 7, :o4, 1090728000
|
||||
tz.transition 2007, 12, :o5, 1198983600
|
||||
tz.transition 2008, 3, :o4, 1205632800
|
||||
tz.transition 2008, 10, :o5, 1224385200
|
||||
tz.transition 2009, 3, :o4, 1237082400
|
||||
tz.transition 2009, 10, :o5, 1255834800
|
||||
tz.transition 2010, 3, :o4, 1269136800
|
||||
tz.transition 2010, 10, :o5, 1287284400
|
||||
tz.transition 2011, 3, :o4, 1300586400
|
||||
tz.transition 2011, 10, :o5, 1318734000
|
||||
tz.transition 2012, 3, :o4, 1332036000
|
||||
tz.transition 2012, 10, :o5, 1350788400
|
||||
tz.transition 2013, 3, :o4, 1363485600
|
||||
tz.transition 2013, 10, :o5, 1382238000
|
||||
tz.transition 2014, 3, :o4, 1394935200
|
||||
tz.transition 2014, 10, :o5, 1413687600
|
||||
tz.transition 2015, 3, :o4, 1426384800
|
||||
tz.transition 2015, 10, :o5, 1445137200
|
||||
tz.transition 2016, 3, :o4, 1458439200
|
||||
tz.transition 2016, 10, :o5, 1476586800
|
||||
tz.transition 2017, 3, :o4, 1489888800
|
||||
tz.transition 2017, 10, :o5, 1508036400
|
||||
tz.transition 2018, 3, :o4, 1521338400
|
||||
tz.transition 2018, 10, :o5, 1540090800
|
||||
tz.transition 2019, 3, :o4, 1552788000
|
||||
tz.transition 2019, 10, :o5, 1571540400
|
||||
tz.transition 2020, 3, :o4, 1584237600
|
||||
tz.transition 2020, 10, :o5, 1602990000
|
||||
tz.transition 2021, 3, :o4, 1616292000
|
||||
tz.transition 2021, 10, :o5, 1634439600
|
||||
tz.transition 2022, 3, :o4, 1647741600
|
||||
tz.transition 2022, 10, :o5, 1665889200
|
||||
tz.transition 2023, 3, :o4, 1679191200
|
||||
tz.transition 2023, 10, :o5, 1697338800
|
||||
tz.transition 2024, 3, :o4, 1710640800
|
||||
tz.transition 2024, 10, :o5, 1729393200
|
||||
tz.transition 2025, 3, :o4, 1742090400
|
||||
tz.transition 2025, 10, :o5, 1760842800
|
||||
tz.transition 2026, 3, :o4, 1773540000
|
||||
tz.transition 2026, 10, :o5, 1792292400
|
||||
tz.transition 2027, 3, :o4, 1805594400
|
||||
tz.transition 2027, 10, :o5, 1823742000
|
||||
tz.transition 2028, 3, :o4, 1837044000
|
||||
tz.transition 2028, 10, :o5, 1855191600
|
||||
tz.transition 2029, 3, :o4, 1868493600
|
||||
tz.transition 2029, 10, :o5, 1887246000
|
||||
tz.transition 2030, 3, :o4, 1899943200
|
||||
tz.transition 2030, 10, :o5, 1918695600
|
||||
tz.transition 2031, 3, :o4, 1931392800
|
||||
tz.transition 2031, 10, :o5, 1950145200
|
||||
tz.transition 2032, 3, :o4, 1963447200
|
||||
tz.transition 2032, 10, :o5, 1981594800
|
||||
tz.transition 2033, 3, :o4, 1994896800
|
||||
tz.transition 2033, 10, :o5, 2013044400
|
||||
tz.transition 2034, 3, :o4, 2026346400
|
||||
tz.transition 2034, 10, :o5, 2044494000
|
||||
tz.transition 2035, 3, :o4, 2057796000
|
||||
tz.transition 2035, 10, :o5, 2076548400
|
||||
tz.transition 2036, 3, :o4, 2089245600
|
||||
tz.transition 2036, 10, :o5, 2107998000
|
||||
tz.transition 2037, 3, :o4, 2120695200
|
||||
tz.transition 2037, 10, :o5, 2139447600
|
||||
tz.transition 2038, 3, :o4, 29586043, 12
|
||||
tz.transition 2038, 10, :o5, 19725709, 8
|
||||
tz.transition 2039, 3, :o4, 29590411, 12
|
||||
tz.transition 2039, 10, :o5, 19728621, 8
|
||||
tz.transition 2040, 3, :o4, 29594779, 12
|
||||
tz.transition 2040, 10, :o5, 19731589, 8
|
||||
tz.transition 2041, 3, :o4, 29599147, 12
|
||||
tz.transition 2041, 10, :o5, 19734501, 8
|
||||
tz.transition 2042, 3, :o4, 29603515, 12
|
||||
tz.transition 2042, 10, :o5, 19737413, 8
|
||||
tz.transition 2043, 3, :o4, 29607883, 12
|
||||
tz.transition 2043, 10, :o5, 19740325, 8
|
||||
tz.transition 2044, 3, :o4, 29612335, 12
|
||||
tz.transition 2044, 10, :o5, 19743237, 8
|
||||
tz.transition 2045, 3, :o4, 29616703, 12
|
||||
tz.transition 2045, 10, :o5, 19746149, 8
|
||||
tz.transition 2046, 3, :o4, 29621071, 12
|
||||
tz.transition 2046, 10, :o5, 19749117, 8
|
||||
tz.transition 2047, 3, :o4, 29625439, 12
|
||||
tz.transition 2047, 10, :o5, 19752029, 8
|
||||
tz.transition 2048, 3, :o4, 29629807, 12
|
||||
tz.transition 2048, 10, :o5, 19754941, 8
|
||||
tz.transition 2049, 3, :o4, 29634259, 12
|
||||
tz.transition 2049, 10, :o5, 19757853, 8
|
||||
tz.transition 2050, 3, :o4, 29638627, 12
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,86 @@
|
||||
require 'tzinfo/timezone_definition'
|
||||
|
||||
module TZInfo
|
||||
module Definitions
|
||||
module America
|
||||
module Argentina
|
||||
module San_Juan
|
||||
include TimezoneDefinition
|
||||
|
||||
timezone 'America/Argentina/San_Juan' do |tz|
|
||||
tz.offset :o0, -16444, 0, :LMT
|
||||
tz.offset :o1, -15408, 0, :CMT
|
||||
tz.offset :o2, -14400, 0, :ART
|
||||
tz.offset :o3, -14400, 3600, :ARST
|
||||
tz.offset :o4, -10800, 0, :ART
|
||||
tz.offset :o5, -10800, 3600, :ARST
|
||||
tz.offset :o6, -14400, 0, :WART
|
||||
|
||||
tz.transition 1894, 10, :o1, 52123666111, 21600
|
||||
tz.transition 1920, 5, :o2, 1453467407, 600
|
||||
tz.transition 1930, 12, :o3, 7278935, 3
|
||||
tz.transition 1931, 4, :o2, 19411461, 8
|
||||
tz.transition 1931, 10, :o3, 7279889, 3
|
||||
tz.transition 1932, 3, :o2, 19414141, 8
|
||||
tz.transition 1932, 11, :o3, 7281038, 3
|
||||
tz.transition 1933, 3, :o2, 19417061, 8
|
||||
tz.transition 1933, 11, :o3, 7282133, 3
|
||||
tz.transition 1934, 3, :o2, 19419981, 8
|
||||
tz.transition 1934, 11, :o3, 7283228, 3
|
||||
tz.transition 1935, 3, :o2, 19422901, 8
|
||||
tz.transition 1935, 11, :o3, 7284323, 3
|
||||
tz.transition 1936, 3, :o2, 19425829, 8
|
||||
tz.transition 1936, 11, :o3, 7285421, 3
|
||||
tz.transition 1937, 3, :o2, 19428749, 8
|
||||
tz.transition 1937, 11, :o3, 7286516, 3
|
||||
tz.transition 1938, 3, :o2, 19431669, 8
|
||||
tz.transition 1938, 11, :o3, 7287611, 3
|
||||
tz.transition 1939, 3, :o2, 19434589, 8
|
||||
tz.transition 1939, 11, :o3, 7288706, 3
|
||||
tz.transition 1940, 3, :o2, 19437517, 8
|
||||
tz.transition 1940, 7, :o3, 7289435, 3
|
||||
tz.transition 1941, 6, :o2, 19441285, 8
|
||||
tz.transition 1941, 10, :o3, 7290848, 3
|
||||
tz.transition 1943, 8, :o2, 19447501, 8
|
||||
tz.transition 1943, 10, :o3, 7293038, 3
|
||||
tz.transition 1946, 3, :o2, 19455045, 8
|
||||
tz.transition 1946, 10, :o3, 7296284, 3
|
||||
tz.transition 1963, 10, :o2, 19506429, 8
|
||||
tz.transition 1963, 12, :o3, 7315136, 3
|
||||
tz.transition 1964, 3, :o2, 19507645, 8
|
||||
tz.transition 1964, 10, :o3, 7316051, 3
|
||||
tz.transition 1965, 3, :o2, 19510565, 8
|
||||
tz.transition 1965, 10, :o3, 7317146, 3
|
||||
tz.transition 1966, 3, :o2, 19513485, 8
|
||||
tz.transition 1966, 10, :o3, 7318241, 3
|
||||
tz.transition 1967, 4, :o2, 19516661, 8
|
||||
tz.transition 1967, 10, :o3, 7319294, 3
|
||||
tz.transition 1968, 4, :o2, 19519629, 8
|
||||
tz.transition 1968, 10, :o3, 7320407, 3
|
||||
tz.transition 1969, 4, :o2, 19522541, 8
|
||||
tz.transition 1969, 10, :o4, 7321499, 3
|
||||
tz.transition 1974, 1, :o5, 128142000
|
||||
tz.transition 1974, 5, :o4, 136605600
|
||||
tz.transition 1988, 12, :o5, 596948400
|
||||
tz.transition 1989, 3, :o4, 605066400
|
||||
tz.transition 1989, 10, :o5, 624423600
|
||||
tz.transition 1990, 3, :o4, 636516000
|
||||
tz.transition 1990, 10, :o5, 656478000
|
||||
tz.transition 1991, 3, :o6, 667792800
|
||||
tz.transition 1991, 5, :o4, 673588800
|
||||
tz.transition 1991, 10, :o5, 687927600
|
||||
tz.transition 1992, 3, :o4, 699415200
|
||||
tz.transition 1992, 10, :o5, 719377200
|
||||
tz.transition 1993, 3, :o4, 731469600
|
||||
tz.transition 1999, 10, :o3, 938919600
|
||||
tz.transition 2000, 3, :o4, 952052400
|
||||
tz.transition 2004, 5, :o6, 1085972400
|
||||
tz.transition 2004, 7, :o4, 1090728000
|
||||
tz.transition 2007, 12, :o5, 1198983600
|
||||
tz.transition 2008, 3, :o4, 1205632800
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user