rails 1.1.6 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rails might be problematic. Click here for more details.
- data/CHANGELOG +267 -2
- data/MIT-LICENSE +1 -1
- data/README +62 -63
- data/Rakefile +26 -15
- data/bin/process/inspector +3 -0
- data/configs/databases/frontbase.yml +28 -0
- data/configs/databases/mysql.yml +3 -2
- data/configs/databases/oracle.yml +10 -1
- data/configs/databases/sqlite3.yml +3 -0
- data/configs/lighttpd.conf +1 -0
- data/configs/routes.rb +1 -0
- data/environments/boot.rb +4 -3
- data/environments/environment.rb +9 -2
- data/environments/production.rb +1 -1
- data/helpers/application.rb +5 -2
- data/html/404.html +27 -5
- data/html/500.html +27 -5
- data/html/javascripts/controls.js +41 -23
- data/html/javascripts/dragdrop.js +105 -76
- data/html/javascripts/effects.js +293 -163
- data/html/javascripts/prototype.js +897 -389
- data/lib/breakpoint.rb +31 -1
- data/lib/breakpoint_client.rb +5 -5
- data/lib/code_statistics.rb +1 -1
- data/lib/commands/performance/profiler.rb +25 -9
- data/lib/commands/plugin.rb +69 -23
- data/lib/commands/process/inspector.rb +68 -0
- data/lib/commands/process/reaper.rb +88 -69
- data/lib/commands/process/spawner.rb +148 -33
- data/lib/commands/runner.rb +27 -6
- data/lib/commands/server.rb +18 -9
- data/lib/commands/servers/base.rb +19 -0
- data/lib/commands/servers/lighttpd.rb +20 -18
- data/lib/commands/servers/mongrel.rb +65 -0
- data/lib/console_sandbox.rb +2 -2
- data/lib/dispatcher.rb +67 -11
- data/lib/fcgi_handler.rb +52 -34
- data/lib/initializer.rb +190 -111
- data/lib/rails/version.rb +2 -2
- data/lib/rails_generator/base.rb +82 -24
- data/lib/rails_generator/commands.rb +87 -25
- data/lib/rails_generator/generated_attribute.rb +42 -0
- data/lib/rails_generator/generators/applications/app/app_generator.rb +13 -10
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +1 -2
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +10 -8
- data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +1 -1
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +4 -4
- data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +1 -1
- data/lib/rails_generator/generators/components/migration/templates/migration.rb +1 -1
- data/lib/rails_generator/generators/components/model/USAGE +19 -12
- data/lib/rails_generator/generators/components/model/model_generator.rb +4 -0
- data/lib/rails_generator/generators/components/model/templates/fixtures.yml +8 -2
- data/lib/rails_generator/generators/components/model/templates/migration.rb +3 -1
- data/lib/rails_generator/generators/components/observer/USAGE +15 -0
- data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
- data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +10 -0
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +4 -0
- data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
- data/lib/rails_generator/generators/components/resource/resource_generator.rb +76 -0
- data/lib/rails_generator/generators/components/resource/templates/USAGE +18 -0
- data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
- data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +11 -0
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +20 -0
- data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/resource/templates/migration.rb +13 -0
- data/lib/rails_generator/generators/components/resource/templates/model.rb +2 -0
- data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +10 -0
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +10 -1
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +11 -7
- data/lib/rails_generator/generators/components/scaffold/templates/layout.rhtml +5 -1
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +2 -2
- data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +1 -1
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +2 -2
- data/lib/rails_generator/generators/components/scaffold_resource/USAGE +29 -0
- data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +92 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +79 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +11 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +57 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +17 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +13 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +2 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +74 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +10 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/view_edit.rhtml +19 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/view_index.rhtml +24 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/view_new.rhtml +18 -0
- data/lib/rails_generator/generators/components/scaffold_resource/templates/view_show.rhtml +10 -0
- data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +7 -1
- data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +5 -4
- data/lib/rails_generator/lookup.rb +1 -2
- data/lib/rails_generator/options.rb +6 -3
- data/lib/tasks/databases.rake +46 -20
- data/lib/tasks/documentation.rake +1 -0
- data/lib/tasks/framework.rake +1 -3
- data/lib/tasks/pre_namespace_aliases.rake +34 -27
- data/lib/tasks/rails.rb +2 -2
- data/lib/tasks/statistics.rake +6 -5
- data/lib/tasks/testing.rake +28 -13
- data/lib/tasks/tmp.rake +8 -1
- data/lib/test_help.rb +3 -2
- data/lib/webrick_server.rb +6 -8
- metadata +50 -9
data/Rakefile
CHANGED
@@ -21,16 +21,26 @@ RUBY_FORGE_PROJECT = "rails"
|
|
21
21
|
RUBY_FORGE_USER = "webster132"
|
22
22
|
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
## This is required until the regular test task
|
25
|
+
## below passes. It's not ideal, but at least
|
26
|
+
## we can see the failures
|
27
|
+
task :test do
|
28
|
+
Dir['test/**/*_test.rb'].all? do |file|
|
29
|
+
system("ruby #{file}")
|
30
|
+
end or raise "Failures"
|
31
|
+
end
|
32
|
+
|
33
|
+
Rake::TestTask.new("regular_test") do |t|
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.warning = true
|
37
|
+
t.verbose = true
|
38
|
+
end
|
29
39
|
|
30
40
|
|
31
41
|
BASE_DIRS = %w(
|
32
42
|
app config/environments components db doc log lib lib/tasks public script script/performance script/process test vendor vendor/plugins
|
33
|
-
tmp/sessions tmp/cache tmp/sockets
|
43
|
+
tmp/sessions tmp/cache tmp/sockets tmp/pids
|
34
44
|
)
|
35
45
|
|
36
46
|
APP_DIRS = %w( models controllers helpers views views/layouts )
|
@@ -41,7 +51,7 @@ LOG_FILES = %w( server.log development.log test.log production.log )
|
|
41
51
|
HTML_FILES = %w( 404.html 500.html index.html robots.txt favicon.ico images/rails.png
|
42
52
|
javascripts/prototype.js javascripts/application.js
|
43
53
|
javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js )
|
44
|
-
BIN_FILES = %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner runner server plugin )
|
54
|
+
BIN_FILES = %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/inspector runner server plugin )
|
45
55
|
|
46
56
|
VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport actionwebservice railties )
|
47
57
|
|
@@ -83,7 +93,7 @@ end
|
|
83
93
|
|
84
94
|
# Make directory structure ----------------------------------------------------------------
|
85
95
|
|
86
|
-
def make_dest_dirs(dirs, path =
|
96
|
+
def make_dest_dirs(dirs, path = '.')
|
87
97
|
mkdir_p dirs.map { |dir| File.join(PKG_DESTINATION, path.to_s, dir) }
|
88
98
|
end
|
89
99
|
|
@@ -266,7 +276,7 @@ PKG_FILES = FileList[
|
|
266
276
|
'generators/**/*',
|
267
277
|
'html/**/*',
|
268
278
|
'lib/**/*'
|
269
|
-
]
|
279
|
+
] - [ 'test' ]
|
270
280
|
|
271
281
|
spec = Gem::Specification.new do |s|
|
272
282
|
s.name = 'rails'
|
@@ -278,11 +288,11 @@ spec = Gem::Specification.new do |s|
|
|
278
288
|
EOF
|
279
289
|
|
280
290
|
s.add_dependency('rake', '>= 0.7.1')
|
281
|
-
s.add_dependency('activesupport', '= 1.
|
282
|
-
s.add_dependency('activerecord', '= 1.
|
283
|
-
s.add_dependency('actionpack', '= 1.
|
284
|
-
s.add_dependency('actionmailer', '= 1.
|
285
|
-
s.add_dependency('actionwebservice', '= 1.
|
291
|
+
s.add_dependency('activesupport', '= 1.4.0' + PKG_BUILD)
|
292
|
+
s.add_dependency('activerecord', '= 1.15.0' + PKG_BUILD)
|
293
|
+
s.add_dependency('actionpack', '= 1.13.0' + PKG_BUILD)
|
294
|
+
s.add_dependency('actionmailer', '= 1.3.0' + PKG_BUILD)
|
295
|
+
s.add_dependency('actionwebservice', '= 1.2.0' + PKG_BUILD)
|
286
296
|
|
287
297
|
s.rdoc_options << '--exclude' << '.'
|
288
298
|
s.has_rdoc = false
|
@@ -301,6 +311,7 @@ spec = Gem::Specification.new do |s|
|
|
301
311
|
end
|
302
312
|
|
303
313
|
Rake::GemPackageTask.new(spec) do |pkg|
|
314
|
+
pkg.gem_spec = spec
|
304
315
|
end
|
305
316
|
|
306
317
|
|
@@ -317,4 +328,4 @@ task :release => [ :gem ] do
|
|
317
328
|
release_command = "rubyforge add_release #{PKG_NAME} #{PKG_NAME} 'REL #{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.gem"
|
318
329
|
puts release_command
|
319
330
|
system(release_command)
|
320
|
-
end
|
331
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# FrontBase versions 4.x
|
2
|
+
#
|
3
|
+
# Get the bindings:
|
4
|
+
# gem install ruby-frontbase
|
5
|
+
|
6
|
+
development:
|
7
|
+
adapter: frontbase
|
8
|
+
host: localhost
|
9
|
+
database: <%= app_name %>_development
|
10
|
+
username: <%= app_name %>
|
11
|
+
password: ''
|
12
|
+
|
13
|
+
# Warning: The database defined as 'test' will be erased and
|
14
|
+
# re-generated from your development database when you run 'rake'.
|
15
|
+
# Do not set this db to the same as development or production.
|
16
|
+
test:
|
17
|
+
adapter: frontbase
|
18
|
+
host: localhost
|
19
|
+
database: <%= app_name %>_test
|
20
|
+
username: <%= app_name %>
|
21
|
+
password: ''
|
22
|
+
|
23
|
+
production:
|
24
|
+
adapter: frontbase
|
25
|
+
host: localhost
|
26
|
+
database: <%= app_name %>_production
|
27
|
+
username: <%= app_name %>
|
28
|
+
password: ''
|
data/configs/databases/mysql.yml
CHANGED
@@ -5,8 +5,9 @@
|
|
5
5
|
# On MacOS X:
|
6
6
|
# gem install mysql -- --include=/usr/local/lib
|
7
7
|
# On Windows:
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# gem install mysql
|
9
|
+
# Choose the win32 build.
|
10
|
+
# Install MySQL and put its /bin directory on your path.
|
10
11
|
#
|
11
12
|
# And be sure to use new-style password hashing:
|
12
13
|
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
|
@@ -6,7 +6,16 @@
|
|
6
6
|
# Specify your database using any valid connection syntax, such as a
|
7
7
|
# tnsnames.ora service name, or a sql connect url string of the form:
|
8
8
|
#
|
9
|
-
# //host:[port][/service name]
|
9
|
+
# //host:[port][/service name]
|
10
|
+
#
|
11
|
+
# By default prefetch_rows (OCI_ATTR_PREFETCH_ROWS) is set to 100. And
|
12
|
+
# until true bind variables are supported, cursor_sharing is set by default
|
13
|
+
# to 'similar'. Both can be changed in the configation below; the defaults
|
14
|
+
# are equivalent to specifying:
|
15
|
+
#
|
16
|
+
# prefetch_rows: 100
|
17
|
+
# cursor_sharing: similar
|
18
|
+
#
|
10
19
|
|
11
20
|
development:
|
12
21
|
adapter: oracle
|
@@ -3,6 +3,7 @@
|
|
3
3
|
development:
|
4
4
|
adapter: sqlite3
|
5
5
|
database: db/development.sqlite3
|
6
|
+
timeout: 5000
|
6
7
|
|
7
8
|
# Warning: The database defined as 'test' will be erased and
|
8
9
|
# re-generated from your development database when you run 'rake'.
|
@@ -10,7 +11,9 @@ development:
|
|
10
11
|
test:
|
11
12
|
adapter: sqlite3
|
12
13
|
database: db/test.sqlite3
|
14
|
+
timeout: 5000
|
13
15
|
|
14
16
|
production:
|
15
17
|
adapter: sqlite3
|
16
18
|
database: db/production.sqlite3
|
19
|
+
timeout: 5000
|
data/configs/lighttpd.conf
CHANGED
@@ -7,6 +7,7 @@ server.port = 3000
|
|
7
7
|
server.modules = ( "mod_rewrite", "mod_accesslog", "mod_fastcgi", "mod_compress", "mod_expire" )
|
8
8
|
|
9
9
|
server.error-handler-404 = "/dispatch.fcgi"
|
10
|
+
server.pid-file = CWD + "/tmp/pids/lighttpd.pid"
|
10
11
|
server.document-root = CWD + "/public/"
|
11
12
|
|
12
13
|
server.errorlog = CWD + "/log/lighttpd.error.log"
|
data/configs/routes.rb
CHANGED
data/environments/boot.rb
CHANGED
@@ -22,13 +22,14 @@ unless defined?(Rails::Initializer)
|
|
22
22
|
rails_gem_version = $1
|
23
23
|
|
24
24
|
if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version
|
25
|
-
|
25
|
+
# Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems
|
26
|
+
rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last
|
26
27
|
|
27
28
|
if rails_gem
|
28
|
-
require_gem "rails", "=#{version}"
|
29
|
+
require_gem "rails", "=#{rails_gem.version.version}"
|
29
30
|
require rails_gem.full_gem_path + '/lib/initializer'
|
30
31
|
else
|
31
|
-
STDERR.puts %(Cannot find gem for Rails
|
32
|
+
STDERR.puts %(Cannot find gem for Rails ~>#{version}.0:
|
32
33
|
Install the missing gem with 'gem install -v=#{version} rails', or
|
33
34
|
change environment.rb to define RAILS_GEM_VERSION with your desired version.
|
34
35
|
)
|
data/environments/environment.rb
CHANGED
@@ -5,17 +5,20 @@
|
|
5
5
|
# ENV['RAILS_ENV'] ||= 'production'
|
6
6
|
|
7
7
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
8
|
-
<%= '# ' if freeze %>RAILS_GEM_VERSION = '<%= Rails::VERSION::STRING %>'
|
8
|
+
<%= '# ' if freeze %>RAILS_GEM_VERSION = '<%= Rails::VERSION::STRING %>' unless defined? RAILS_GEM_VERSION
|
9
9
|
|
10
10
|
# Bootstrap the Rails environment, frameworks, and default configuration
|
11
11
|
require File.join(File.dirname(__FILE__), 'boot')
|
12
12
|
|
13
13
|
Rails::Initializer.run do |config|
|
14
|
-
# Settings in config/environments/* take precedence those specified here
|
14
|
+
# Settings in config/environments/* take precedence over those specified here
|
15
15
|
|
16
16
|
# Skip frameworks you're not going to use (only works if using vendor/rails)
|
17
17
|
# config.frameworks -= [ :action_web_service, :action_mailer ]
|
18
18
|
|
19
|
+
# Only load the plugins named here, by default all plugins in vendor/plugins are loaded
|
20
|
+
# config.plugins = %W( exception_notification ssl_requirement )
|
21
|
+
|
19
22
|
# Add additional load paths for your own custom dirs
|
20
23
|
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
21
24
|
|
@@ -50,4 +53,8 @@ end
|
|
50
53
|
# inflect.uncountable %w( fish sheep )
|
51
54
|
# end
|
52
55
|
|
56
|
+
# Add new mime types for use in respond_to blocks:
|
57
|
+
# Mime::Type.register "text/richtext", :rtf
|
58
|
+
# Mime::Type.register "application/x-mobile", :mobile
|
59
|
+
|
53
60
|
# Include your application configuration below
|
data/environments/production.rb
CHANGED
@@ -14,5 +14,5 @@ config.action_controller.perform_caching = true
|
|
14
14
|
# Enable serving of images, stylesheets, and javascripts from an asset server
|
15
15
|
# config.action_controller.asset_host = "http://assets.example.com"
|
16
16
|
|
17
|
-
# Disable delivery errors
|
17
|
+
# Disable delivery errors, bad email addresses will be ignored
|
18
18
|
# config.action_mailer.raise_delivery_errors = false
|
data/helpers/application.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# Filters added to this controller
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
2
|
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
3
4
|
class ApplicationController < ActionController::Base
|
4
|
-
|
5
|
+
# Pick a unique cookie name to distinguish our session data from others'
|
6
|
+
session :session_key => '_<%= app_name %>_session_id'
|
7
|
+
end
|
data/html/404.html
CHANGED
@@ -1,8 +1,30 @@
|
|
1
|
-
<!DOCTYPE
|
2
|
-
|
3
|
-
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
|
6
|
+
<head>
|
7
|
+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
8
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
9
|
+
<style type="text/css">
|
10
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
11
|
+
div.dialog {
|
12
|
+
width: 25em;
|
13
|
+
padding: 0 4em;
|
14
|
+
margin: 4em auto 0 auto;
|
15
|
+
border: 1px solid #ccc;
|
16
|
+
border-right-color: #999;
|
17
|
+
border-bottom-color: #999;
|
18
|
+
}
|
19
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
20
|
+
</style>
|
21
|
+
</head>
|
22
|
+
|
4
23
|
<body>
|
5
|
-
|
6
|
-
<
|
24
|
+
<!-- This file lives in public/404.html -->
|
25
|
+
<div class="dialog">
|
26
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
27
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
28
|
+
</div>
|
7
29
|
</body>
|
8
30
|
</html>
|
data/html/500.html
CHANGED
@@ -1,8 +1,30 @@
|
|
1
|
-
<!DOCTYPE
|
2
|
-
|
3
|
-
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
|
6
|
+
<head>
|
7
|
+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
8
|
+
<title>We're sorry, but something went wrong</title>
|
9
|
+
<style type="text/css">
|
10
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
11
|
+
div.dialog {
|
12
|
+
width: 25em;
|
13
|
+
padding: 0 4em;
|
14
|
+
margin: 4em auto 0 auto;
|
15
|
+
border: 1px solid #ccc;
|
16
|
+
border-right-color: #999;
|
17
|
+
border-bottom-color: #999;
|
18
|
+
}
|
19
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
20
|
+
</style>
|
21
|
+
</head>
|
22
|
+
|
4
23
|
<body>
|
5
|
-
|
6
|
-
<
|
24
|
+
<!-- This file lives in public/500.html -->
|
25
|
+
<div class="dialog">
|
26
|
+
<h1>We're sorry, but something went wrong.</h1>
|
27
|
+
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
28
|
+
</div>
|
7
29
|
</body>
|
8
30
|
</html>
|
@@ -1,12 +1,13 @@
|
|
1
|
-
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
2
|
-
// (c) 2005 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
|
3
|
-
// (c) 2005 Jon Tirsen (http://www.tirsen.com)
|
1
|
+
// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
2
|
+
// (c) 2005, 2006 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
|
3
|
+
// (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com)
|
4
4
|
// Contributors:
|
5
5
|
// Richard Livsey
|
6
6
|
// Rahul Bhargava
|
7
7
|
// Rob Wills
|
8
8
|
//
|
9
|
-
//
|
9
|
+
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
10
|
+
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
10
11
|
|
11
12
|
// Autocompleter.Base handles all the autocompletion functionality
|
12
13
|
// that's independent of the data source for autocompletion. This
|
@@ -33,6 +34,9 @@
|
|
33
34
|
// useful when one of the tokens is \n (a newline), as it
|
34
35
|
// allows smart autocompletion after linebreaks.
|
35
36
|
|
37
|
+
if(typeof Effect == 'undefined')
|
38
|
+
throw("controls.js requires including script.aculo.us' effects.js library");
|
39
|
+
|
36
40
|
var Autocompleter = {}
|
37
41
|
Autocompleter.Base = function() {};
|
38
42
|
Autocompleter.Base.prototype = {
|
@@ -45,7 +49,7 @@ Autocompleter.Base.prototype = {
|
|
45
49
|
this.index = 0;
|
46
50
|
this.entryCount = 0;
|
47
51
|
|
48
|
-
if
|
52
|
+
if(this.setOptions)
|
49
53
|
this.setOptions(options);
|
50
54
|
else
|
51
55
|
this.options = options || {};
|
@@ -55,17 +59,20 @@ Autocompleter.Base.prototype = {
|
|
55
59
|
this.options.frequency = this.options.frequency || 0.4;
|
56
60
|
this.options.minChars = this.options.minChars || 1;
|
57
61
|
this.options.onShow = this.options.onShow ||
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
function(element, update){
|
63
|
+
if(!update.style.position || update.style.position=='absolute') {
|
64
|
+
update.style.position = 'absolute';
|
65
|
+
Position.clone(element, update, {
|
66
|
+
setHeight: false,
|
67
|
+
offsetTop: element.offsetHeight
|
68
|
+
});
|
69
|
+
}
|
70
|
+
Effect.Appear(update,{duration:0.15});
|
71
|
+
};
|
65
72
|
this.options.onHide = this.options.onHide ||
|
66
|
-
|
73
|
+
function(element, update){ new Effect.Fade(update,{duration:0.15}) };
|
67
74
|
|
68
|
-
if
|
75
|
+
if(typeof(this.options.tokens) == 'string')
|
69
76
|
this.options.tokens = new Array(this.options.tokens);
|
70
77
|
|
71
78
|
this.observer = null;
|
@@ -94,7 +101,7 @@ Autocompleter.Base.prototype = {
|
|
94
101
|
},
|
95
102
|
|
96
103
|
fixIEOverlapping: function() {
|
97
|
-
Position.clone(this.update, this.iefix);
|
104
|
+
Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
|
98
105
|
this.iefix.style.zIndex = 1;
|
99
106
|
this.update.style.zIndex = 2;
|
100
107
|
Element.show(this.iefix);
|
@@ -202,11 +209,13 @@ Autocompleter.Base.prototype = {
|
|
202
209
|
markPrevious: function() {
|
203
210
|
if(this.index > 0) this.index--
|
204
211
|
else this.index = this.entryCount-1;
|
212
|
+
this.getEntry(this.index).scrollIntoView(true);
|
205
213
|
},
|
206
214
|
|
207
215
|
markNext: function() {
|
208
216
|
if(this.index < this.entryCount-1) this.index++
|
209
217
|
else this.index = 0;
|
218
|
+
this.getEntry(this.index).scrollIntoView(false);
|
210
219
|
},
|
211
220
|
|
212
221
|
getEntry: function(index) {
|
@@ -254,11 +263,11 @@ Autocompleter.Base.prototype = {
|
|
254
263
|
if(!this.changed && this.hasFocus) {
|
255
264
|
this.update.innerHTML = choices;
|
256
265
|
Element.cleanWhitespace(this.update);
|
257
|
-
Element.cleanWhitespace(this.update.
|
266
|
+
Element.cleanWhitespace(this.update.down());
|
258
267
|
|
259
|
-
if(this.update.firstChild && this.update.
|
268
|
+
if(this.update.firstChild && this.update.down().childNodes) {
|
260
269
|
this.entryCount =
|
261
|
-
this.update.
|
270
|
+
this.update.down().childNodes.length;
|
262
271
|
for (var i = 0; i < this.entryCount; i++) {
|
263
272
|
var entry = this.getEntry(i);
|
264
273
|
entry.autocompleteIndex = i;
|
@@ -269,9 +278,14 @@ Autocompleter.Base.prototype = {
|
|
269
278
|
}
|
270
279
|
|
271
280
|
this.stopIndicator();
|
272
|
-
|
273
281
|
this.index = 0;
|
274
|
-
|
282
|
+
|
283
|
+
if(this.entryCount==1 && this.options.autoSelect) {
|
284
|
+
this.selectEntry();
|
285
|
+
this.hide();
|
286
|
+
} else {
|
287
|
+
this.render();
|
288
|
+
}
|
275
289
|
}
|
276
290
|
},
|
277
291
|
|
@@ -459,6 +473,7 @@ Ajax.InPlaceEditor.prototype = {
|
|
459
473
|
this.element = $(element);
|
460
474
|
|
461
475
|
this.options = Object.extend({
|
476
|
+
paramName: "value",
|
462
477
|
okButton: true,
|
463
478
|
okText: "ok",
|
464
479
|
cancelLink: true,
|
@@ -531,7 +546,7 @@ Ajax.InPlaceEditor.prototype = {
|
|
531
546
|
Element.hide(this.element);
|
532
547
|
this.createForm();
|
533
548
|
this.element.parentNode.insertBefore(this.form, this.element);
|
534
|
-
Field.scrollFreeActivate(this.editField);
|
549
|
+
if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField);
|
535
550
|
// stop the event to avoid a page refresh in Safari
|
536
551
|
if (evt) {
|
537
552
|
Event.stop(evt);
|
@@ -590,7 +605,7 @@ Ajax.InPlaceEditor.prototype = {
|
|
590
605
|
var textField = document.createElement("input");
|
591
606
|
textField.obj = this;
|
592
607
|
textField.type = "text";
|
593
|
-
textField.name =
|
608
|
+
textField.name = this.options.paramName;
|
594
609
|
textField.value = text;
|
595
610
|
textField.style.backgroundColor = this.options.highlightcolor;
|
596
611
|
textField.className = 'editor_field';
|
@@ -603,7 +618,7 @@ Ajax.InPlaceEditor.prototype = {
|
|
603
618
|
this.options.textarea = true;
|
604
619
|
var textArea = document.createElement("textarea");
|
605
620
|
textArea.obj = this;
|
606
|
-
textArea.name =
|
621
|
+
textArea.name = this.options.paramName;
|
607
622
|
textArea.value = this.convertHTMLLineBreaks(text);
|
608
623
|
textArea.rows = this.options.rows;
|
609
624
|
textArea.cols = this.options.cols || 40;
|
@@ -636,6 +651,7 @@ Ajax.InPlaceEditor.prototype = {
|
|
636
651
|
Element.removeClassName(this.form, this.options.loadingClassName);
|
637
652
|
this.editField.disabled = false;
|
638
653
|
this.editField.value = transport.responseText.stripTags();
|
654
|
+
Field.scrollFreeActivate(this.editField);
|
639
655
|
},
|
640
656
|
onclickCancel: function() {
|
641
657
|
this.onComplete();
|
@@ -772,6 +788,8 @@ Object.extend(Ajax.InPlaceCollectionEditor.prototype, {
|
|
772
788
|
collection.each(function(e,i) {
|
773
789
|
optionTag = document.createElement("option");
|
774
790
|
optionTag.value = (e instanceof Array) ? e[0] : e;
|
791
|
+
if((typeof this.options.value == 'undefined') &&
|
792
|
+
((e instanceof Array) ? this.element.innerHTML == e[1] : e == optionTag.value)) optionTag.selected = true;
|
775
793
|
if(this.options.value==optionTag.value) optionTag.selected = true;
|
776
794
|
optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e));
|
777
795
|
selectTag.appendChild(optionTag);
|