typus 3.0.10 → 3.0.11.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/Gemfile +9 -5
- data/README.md +17 -53
- data/app/assets/vendor/typus/javascripts/application.js +2 -0
- data/app/assets/vendor/typus/javascripts/jquery.application.js +29 -0
- data/app/assets/vendor/typus/javascripts/jquery.rails.autocomplete.js +32 -0
- data/app/assets/vendor/typus/javascripts/jquery.rails.js +158 -0
- data/app/assets/vendor/typus/javascripts/jquery.searchField.js +91 -0
- data/app/assets/vendor/typus/stylesheets/application.css +11 -0
- data/app/assets/vendor/typus/stylesheets/reset.css +48 -0
- data/app/assets/vendor/typus/stylesheets/screen.css +361 -0
- data/app/assets/vendor/typus/vendor/jquery-tokeninput/css/token-input-facebook.css +122 -0
- data/app/assets/vendor/typus/vendor/jquery-tokeninput/css/token-input-mac.css +204 -0
- data/app/assets/vendor/typus/vendor/jquery-tokeninput/css/token-input.css +120 -0
- data/app/assets/vendor/typus/vendor/jquery-tokeninput/js/jquery.tokeninput.js +736 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/jquery-ui-1.8.12.custom.css +578 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/index.html +367 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/js/jquery-1.5.1.min.js +16 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/js/jquery-ui-1.8.12.custom.min.js +783 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/blank.gif +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_close.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_loading.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_nav_left.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_nav_right.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_e.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_n.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_ne.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_nw.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_s.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_se.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_sw.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_w.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_left.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_main.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_over.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_right.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancybox-x.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancybox-y.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancybox.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.easing-1.3.pack.js +72 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css +359 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.js +1156 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js +46 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.mousewheel-3.0.4.pack.js +14 -0
- data/app/controllers/admin/account_controller.rb +2 -2
- data/app/controllers/admin/base_controller.rb +4 -0
- data/app/controllers/admin/resources_controller.rb +8 -83
- data/app/controllers/admin/session_controller.rb +10 -2
- data/app/helpers/admin/file_preview_helper.rb +15 -1
- data/app/helpers/admin/filters_helper.rb +4 -4
- data/app/helpers/admin/relationships_helper.rb +11 -6
- data/app/helpers/admin/resources_helper.rb +4 -1
- data/app/helpers/admin/table_helper.rb +6 -3
- data/app/views/admin/dashboard/_sidebar.html.erb +1 -3
- data/app/views/admin/helpers/table/_table.html.erb +0 -8
- data/app/views/admin/resources/index.html.erb +3 -1
- data/app/views/admin/shared/_head.html.erb +30 -0
- data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +23 -4
- data/app/views/admin/templates/_relate_form.html.erb +1 -1
- data/app/views/admin/templates/_selector.html.erb +5 -1
- data/app/views/layouts/admin/base.html.erb +1 -30
- data/app/views/layouts/admin/headless.html.erb +1 -30
- data/app/views/layouts/admin/session.html.erb +1 -19
- data/doc/mongo_db.md +10 -0
- data/lib/generators/typus/typus_generator.rb +0 -5
- data/lib/support/active_record.rb +8 -0
- data/lib/typus.rb +2 -1
- data/lib/typus/controller/actions.rb +7 -0
- data/lib/typus/controller/acts_as.rb +22 -0
- data/lib/typus/controller/associations.rb +66 -0
- data/lib/typus/controller/autocomplete.rb +1 -1
- data/lib/typus/controller/format.rb +1 -1
- data/lib/typus/engine.rb +7 -2
- data/lib/typus/orm/active_record/class_methods.rb +1 -1
- data/lib/typus/version.rb +1 -1
- data/test/app/controllers/admin/assets_controller_test.rb +8 -5
- data/test/app/controllers/admin/pages_controller_test.rb +2 -2
- data/test/app/controllers/admin/posts_controller_test.rb +27 -2
- data/test/app/controllers/admin/views_controller_test.rb +36 -0
- data/test/app/helpers/admin/file_preview_helper_test.rb +9 -1
- data/test/app/helpers/admin/filters_helper_test.rb +5 -0
- data/test/app/helpers/admin/resources_helper_test.rb +2 -2
- data/test/app/helpers/admin/table_helper_test.rb +26 -0
- data/test/factories.rb +11 -0
- data/test/fixtures/rails_app/app/controllers/admin/hits_controller.rb +0 -3
- data/test/fixtures/rails_app/app/controllers/admin/views_controller.rb +6 -0
- data/test/fixtures/rails_app/app/models/asset.rb +16 -4
- data/test/fixtures/rails_app/app/models/site.rb +16 -0
- data/test/fixtures/rails_app/app/models/view.rb +2 -0
- data/test/fixtures/rails_app/config/typus/crud_extended.yml +2 -2
- data/test/fixtures/rails_app/db/schema.rb +15 -0
- data/test/lib/support/active_record_test.rb +24 -0
- data/test/lib/typus/orm/active_record/class_methods_test.rb +4 -4
- data/test/lib/typus_test.rb +1 -1
- metadata +68 -190
- data/.gemtest +0 -0
- data/doc/hudson_setup.md +0 -19
- data/lib/generators/typus/assets_generator.rb +0 -19
- data/test/fixtures/rails_app/app/views/layouts/admin/headless.html.erb +0 -38
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -8,7 +8,7 @@ gemspec
|
|
8
8
|
|
9
9
|
gem 'acts_as_list'
|
10
10
|
gem 'acts_as_tree'
|
11
|
-
gem 'dragonfly', '~>0.
|
11
|
+
gem 'dragonfly', '~> 0.9'
|
12
12
|
gem 'factory_girl'
|
13
13
|
gem 'paperclip'
|
14
14
|
gem 'rack-cache', :require => 'rack/cache'
|
@@ -32,7 +32,7 @@ group :development, :test do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
platforms :ruby do
|
35
|
-
gem 'mysql2'
|
35
|
+
gem 'mysql2', '0.2.7'
|
36
36
|
gem 'pg'
|
37
37
|
gem 'sqlite3'
|
38
38
|
end
|
@@ -41,9 +41,13 @@ end
|
|
41
41
|
|
42
42
|
# MongoDB support is still in "beta" mode, so I'm not testing it for the moment.
|
43
43
|
group :production do
|
44
|
-
|
45
|
-
gem 'mongoid'
|
46
|
-
|
44
|
+
|
45
|
+
gem 'mongoid'
|
46
|
+
|
47
|
+
platforms :ruby do
|
48
|
+
gem 'bson_ext'
|
49
|
+
end
|
50
|
+
|
47
51
|
end
|
48
52
|
|
49
53
|
group :production do
|
data/README.md
CHANGED
@@ -1,83 +1,47 @@
|
|
1
1
|
# Typus: Admin Panel for Ruby on Rails applications
|
2
2
|
|
3
|
-
**Typus**
|
4
|
-
|
5
|
-
Trusted users editing structured content.
|
6
|
-
|
7
|
-
**Typus** doesn't try to be all the things to all the people but it's
|
8
|
-
extensible enough to match lots of use cases.
|
3
|
+
**Typus** allows trusted users to edit structured content.
|
9
4
|
|
10
5
|
## Key Features
|
11
6
|
|
12
|
-
- Built-in Authentication.
|
13
|
-
- User Permissions by using Access Control Lists. (stored in yaml files)
|
7
|
+
- Built-in Authentication and Access Control Lists.
|
14
8
|
- CRUD and custom actions for your models on a clean interface.
|
15
|
-
- Internationalized interface (
|
16
|
-
Français, Magyar, Italiano, Portuguese, Russian, 中文)
|
9
|
+
- Internationalized interface ([See available translations][locales])
|
17
10
|
- Customizable and extensible templates.
|
18
|
-
- Integrated [paperclip][
|
19
|
-
-
|
20
|
-
-
|
21
|
-
- Tested with `ruby-1.8.7-p334`, `ree-1.8.7-2011.03` and `ruby-1.9.2-p180` and `jruby-1.5.6`.
|
11
|
+
- Integrated [paperclip][paperclip] and [dragonfly][dragonfly] attachments viewer.
|
12
|
+
- Works with `Rails 3.0.X`.
|
13
|
+
- Tested with latest versions of `1.8.7`, `ree`, `1.9.2` and `jruby`.
|
22
14
|
- Tested with `SQLite`, `MySQL` and `PostgreSQL`.
|
23
|
-
- MIT License, the same as Rails.
|
24
15
|
|
25
16
|
## Links
|
26
17
|
|
27
|
-
- [Documentation](
|
28
|
-
- [
|
18
|
+
- [Documentation](https://github.com/fesplugas/typus/wiki)
|
19
|
+
- [Issues](https://github.com/fesplugas/typus/issues)
|
20
|
+
- [Demo](http://demo.typuscms.com/) ([Code][code])
|
29
21
|
- [Source Code](http://github.com/fesplugas/typus)
|
30
22
|
- [Mailing List](http://groups.google.com/group/typus)
|
31
23
|
- [Gems](http://rubygems.org/gems/typus)
|
32
24
|
- [Contributors List](http://github.com/fesplugas/typus/contributors)
|
33
|
-
- [Continous Integration](http://ci.typuscms.com/)
|
34
25
|
|
35
26
|
## Installing
|
36
27
|
|
37
28
|
Add **Typus** to your `Gemfile`
|
38
29
|
|
39
|
-
gem 'typus', :git => '
|
40
|
-
|
41
|
-
# If you have problems with "Smart HTTP" use the "Git Transfer Protocol".
|
42
|
-
# gem 'typus', :git => 'git://github.com/fesplugas/typus.git'
|
30
|
+
gem 'typus', :git => 'git://github.com/fesplugas/typus.git'
|
43
31
|
|
44
|
-
Update your bundle
|
32
|
+
Update your bundle, run the generator and start the application server:
|
45
33
|
|
46
34
|
$ bundle install
|
47
|
-
|
48
|
-
Run the generator
|
49
|
-
|
50
35
|
$ rails generate typus
|
51
|
-
|
52
|
-
Start the application server
|
53
|
-
|
54
36
|
$ rails server
|
55
37
|
|
56
38
|
and go to <http://0.0.0.0:3000/admin>.
|
57
39
|
|
58
|
-
##
|
59
|
-
|
60
|
-
Copyright (c) 2007-2011 Francesc Esplugas Marti
|
61
|
-
|
62
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
63
|
-
a copy of this software and associated documentation files (the
|
64
|
-
"Software"), to deal in the Software without restriction, including
|
65
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
66
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
67
|
-
permit persons to whom the Software is furnished to do so, subject to
|
68
|
-
the following conditions:
|
69
|
-
|
70
|
-
The above copyright notice and this permission notice shall be
|
71
|
-
included in all copies or substantial portions of the Software.
|
40
|
+
## License
|
72
41
|
|
73
|
-
|
74
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
75
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
76
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
77
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
78
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
79
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
42
|
+
Typus is released under the MIT license.
|
80
43
|
|
81
|
-
[
|
82
|
-
[
|
83
|
-
[
|
44
|
+
[paperclip]: http://rubygems.org/gems/paperclip
|
45
|
+
[dragonfly]: http://rubygems.org/gems/dragonfly
|
46
|
+
[code]: https://github.com/fesplugas/typus/tree/master/test/fixtures/rails_app
|
47
|
+
[locales]: https://github.com/fesplugas/typus/tree/master/config/locales
|
@@ -0,0 +1,29 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
$("#quicksearch").searchField();
|
4
|
+
|
5
|
+
$('.resource :input', document.myForm).bind("change", function() { setConfirmUnload(true); });
|
6
|
+
|
7
|
+
$("a.fancybox").fancybox({
|
8
|
+
'titlePosition': 'over',
|
9
|
+
'type': 'image'
|
10
|
+
});
|
11
|
+
|
12
|
+
$(".iframe").fancybox({
|
13
|
+
'width': '75%',
|
14
|
+
'height': '100%',
|
15
|
+
'autoScale': false,
|
16
|
+
'transitionIn': 'none',
|
17
|
+
'transitionOut': 'none',
|
18
|
+
'type': 'iframe'
|
19
|
+
});
|
20
|
+
|
21
|
+
});
|
22
|
+
|
23
|
+
function setConfirmUnload(on) {
|
24
|
+
window.onbeforeunload = (on) ? unloadMessage : null;
|
25
|
+
}
|
26
|
+
|
27
|
+
function unloadMessage() {
|
28
|
+
return "You have entered new data on this page. If you navigate away from this page without first saving your data, the changes will be lost.";
|
29
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*
|
2
|
+
* Unobtrusive autocomplete
|
3
|
+
*
|
4
|
+
* To use it, you just have to include the HTML attribute autocomplete
|
5
|
+
* with the autocomplete URL as the value
|
6
|
+
*
|
7
|
+
* Example:
|
8
|
+
* <input type="text" autocomplete="/url/to/autocomplete">
|
9
|
+
*
|
10
|
+
* Optionally, you can use a jQuery selector to specify a field that can
|
11
|
+
* be updated with the element id whenever you find a matching value
|
12
|
+
*
|
13
|
+
* Example:
|
14
|
+
* <input type="text" autocomplete="/url/to/autocomplete" id_element="#id_field">
|
15
|
+
*/
|
16
|
+
|
17
|
+
$(document).ready(function(){
|
18
|
+
$('input[data-autocomplete]').each(function(i){
|
19
|
+
$(this).autocomplete({
|
20
|
+
minLength: 3,
|
21
|
+
source: $(this).attr('data-autocomplete'),
|
22
|
+
|
23
|
+
select: function(event, ui) {
|
24
|
+
$(this).val(ui.item.value);
|
25
|
+
if ($(this).attr('id_element')) {
|
26
|
+
$($(this).attr('id_element')).val(ui.item.id);
|
27
|
+
}
|
28
|
+
return false;
|
29
|
+
}
|
30
|
+
});
|
31
|
+
});
|
32
|
+
});
|
@@ -0,0 +1,158 @@
|
|
1
|
+
/**
|
2
|
+
* Unobtrusive scripting adapter for jQuery
|
3
|
+
*
|
4
|
+
* Requires jQuery 1.4.3 or later.
|
5
|
+
* https://github.com/rails/jquery-ujs
|
6
|
+
*/
|
7
|
+
|
8
|
+
(function($) {
|
9
|
+
// Make sure that every Ajax request sends the CSRF token
|
10
|
+
function CSRFProtection(xhr) {
|
11
|
+
var token = $('meta[name="csrf-token"]').attr('content');
|
12
|
+
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
13
|
+
}
|
14
|
+
if ('ajaxPrefilter' in $) $.ajaxPrefilter(function(options, originalOptions, xhr){ CSRFProtection(xhr) });
|
15
|
+
else $(document).ajaxSend(function(e, xhr){ CSRFProtection(xhr) });
|
16
|
+
|
17
|
+
// Triggers an event on an element and returns the event result
|
18
|
+
function fire(obj, name, data) {
|
19
|
+
var event = $.Event(name);
|
20
|
+
obj.trigger(event, data);
|
21
|
+
return event.result !== false;
|
22
|
+
}
|
23
|
+
|
24
|
+
// Submits "remote" forms and links with ajax
|
25
|
+
function handleRemote(element) {
|
26
|
+
var method, url, data,
|
27
|
+
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
|
28
|
+
|
29
|
+
if (fire(element, 'ajax:before')) {
|
30
|
+
if (element.is('form')) {
|
31
|
+
method = element.attr('method');
|
32
|
+
url = element.attr('action');
|
33
|
+
data = element.serializeArray();
|
34
|
+
// memoized value from clicked submit button
|
35
|
+
var button = element.data('ujs:submit-button');
|
36
|
+
if (button) {
|
37
|
+
data.push(button);
|
38
|
+
element.data('ujs:submit-button', null);
|
39
|
+
}
|
40
|
+
} else {
|
41
|
+
method = element.data('method');
|
42
|
+
url = element.attr('href');
|
43
|
+
data = null;
|
44
|
+
}
|
45
|
+
$.ajax({
|
46
|
+
url: url, type: method || 'GET', data: data, dataType: dataType,
|
47
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
48
|
+
beforeSend: function(xhr, settings) {
|
49
|
+
if (settings.dataType === undefined) {
|
50
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
51
|
+
}
|
52
|
+
return fire(element, 'ajax:beforeSend', [xhr, settings]);
|
53
|
+
},
|
54
|
+
success: function(data, status, xhr) {
|
55
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
56
|
+
},
|
57
|
+
complete: function(xhr, status) {
|
58
|
+
element.trigger('ajax:complete', [xhr, status]);
|
59
|
+
},
|
60
|
+
error: function(xhr, status, error) {
|
61
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
62
|
+
}
|
63
|
+
});
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
// Handles "data-method" on links such as:
|
68
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
69
|
+
function handleMethod(link) {
|
70
|
+
var href = link.attr('href'),
|
71
|
+
method = link.data('method'),
|
72
|
+
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
73
|
+
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
74
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
75
|
+
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
76
|
+
|
77
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
78
|
+
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
79
|
+
}
|
80
|
+
|
81
|
+
form.hide().append(metadata_input).appendTo('body');
|
82
|
+
form.submit();
|
83
|
+
}
|
84
|
+
|
85
|
+
function disableFormElements(form) {
|
86
|
+
form.find('input[data-disable-with]').each(function() {
|
87
|
+
var input = $(this);
|
88
|
+
input.data('ujs:enable-with', input.val())
|
89
|
+
.val(input.data('disable-with'))
|
90
|
+
.attr('disabled', 'disabled');
|
91
|
+
});
|
92
|
+
}
|
93
|
+
|
94
|
+
function enableFormElements(form) {
|
95
|
+
form.find('input[data-disable-with]').each(function() {
|
96
|
+
var input = $(this);
|
97
|
+
input.val(input.data('ujs:enable-with')).removeAttr('disabled');
|
98
|
+
});
|
99
|
+
}
|
100
|
+
|
101
|
+
function allowAction(element) {
|
102
|
+
var message = element.data('confirm');
|
103
|
+
return !message || (fire(element, 'confirm') && confirm(message));
|
104
|
+
}
|
105
|
+
|
106
|
+
function requiredValuesMissing(form) {
|
107
|
+
var missing = false;
|
108
|
+
form.find('input[name][required]').each(function() {
|
109
|
+
if (!$(this).val()) missing = true;
|
110
|
+
});
|
111
|
+
return missing;
|
112
|
+
}
|
113
|
+
|
114
|
+
$('a[data-confirm], a[data-method], a[data-remote]').live('click.rails', function(e) {
|
115
|
+
var link = $(this);
|
116
|
+
if (!allowAction(link)) return false;
|
117
|
+
|
118
|
+
if (link.data('remote') != undefined) {
|
119
|
+
handleRemote(link);
|
120
|
+
return false;
|
121
|
+
} else if (link.data('method')) {
|
122
|
+
handleMethod(link);
|
123
|
+
return false;
|
124
|
+
}
|
125
|
+
});
|
126
|
+
|
127
|
+
$('form').live('submit.rails', function(e) {
|
128
|
+
var form = $(this), remote = form.data('remote') != undefined;
|
129
|
+
if (!allowAction(form)) return false;
|
130
|
+
|
131
|
+
// skip other logic when required values are missing
|
132
|
+
if (requiredValuesMissing(form)) return !remote;
|
133
|
+
|
134
|
+
if (remote) {
|
135
|
+
handleRemote(form);
|
136
|
+
return false;
|
137
|
+
} else {
|
138
|
+
// slight timeout so that the submit button gets properly serialized
|
139
|
+
setTimeout(function(){ disableFormElements(form) }, 13);
|
140
|
+
}
|
141
|
+
});
|
142
|
+
|
143
|
+
$('form input[type=submit], form button[type=submit], form button:not([type])').live('click.rails', function() {
|
144
|
+
var button = $(this);
|
145
|
+
if (!allowAction(button)) return false;
|
146
|
+
// register the pressed submit button
|
147
|
+
var name = button.attr('name'), data = name ? {name:name, value:button.val()} : null;
|
148
|
+
button.closest('form').data('ujs:submit-button', data);
|
149
|
+
});
|
150
|
+
|
151
|
+
$('form').live('ajax:beforeSend.rails', function(event) {
|
152
|
+
if (this == event.target) disableFormElements($(this));
|
153
|
+
});
|
154
|
+
|
155
|
+
$('form').live('ajax:complete.rails', function(event) {
|
156
|
+
if (this == event.target) enableFormElements($(this));
|
157
|
+
});
|
158
|
+
})( jQuery );
|
@@ -0,0 +1,91 @@
|
|
1
|
+
/*
|
2
|
+
* searchField - jQuery plugin to display and remove
|
3
|
+
* a default value in a searchvalue on blur/focus
|
4
|
+
*
|
5
|
+
* Copyright (c) 2008 J�örn Zaefferer
|
6
|
+
*
|
7
|
+
* $Id$
|
8
|
+
*
|
9
|
+
* Dual licensed under the MIT and GPL licenses:
|
10
|
+
* http://www.opensource.org/licenses/mit-license.php
|
11
|
+
* http://www.gnu.org/licenses/gpl.html
|
12
|
+
*
|
13
|
+
*/
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Clear the help text in a search field (either in the value or title attribute)
|
17
|
+
* when focused, and restore it on blur if nothing was entered. If the value is
|
18
|
+
* blank but there is a title attribute, the title will be moved to the initial value.
|
19
|
+
*
|
20
|
+
* @example $('#quicksearch').searchField();
|
21
|
+
* @before <input id="quicksearch" title="Enter search here" name="quicksearch" />
|
22
|
+
* @result <input id="quicksearch" value="Enter search here" name="quicksearch" />
|
23
|
+
*
|
24
|
+
* @name searchField
|
25
|
+
* @type jQuery
|
26
|
+
* @cat Plugins/SearchField
|
27
|
+
*/
|
28
|
+
jQuery.fn.searchField = function(mark){
|
29
|
+
return this.each(function() {
|
30
|
+
var mark = mark || this.title;
|
31
|
+
|
32
|
+
if (!mark)
|
33
|
+
return;
|
34
|
+
|
35
|
+
var target = this;
|
36
|
+
var original = $(this);
|
37
|
+
if (this.type == "password") {
|
38
|
+
target = $("<input />")
|
39
|
+
.insertBefore(this)
|
40
|
+
.css("display", $(this).css("display"))
|
41
|
+
.attr("size", this.size)
|
42
|
+
.attr("title", this.title)
|
43
|
+
.attr("class", this.className)
|
44
|
+
.addClass("watermark")[0];
|
45
|
+
if (!this.value) {
|
46
|
+
$(this).hide();
|
47
|
+
} else {
|
48
|
+
$(target).hide();
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
if(!target.value || mark == this.value) {
|
53
|
+
$(target).addClass("watermark");
|
54
|
+
}
|
55
|
+
|
56
|
+
// setup initial value
|
57
|
+
if (!this.value || target != this) {
|
58
|
+
target.value = mark;
|
59
|
+
}
|
60
|
+
|
61
|
+
$(target).focus(function() {
|
62
|
+
if (target != original[0]) {
|
63
|
+
$(this).hide();
|
64
|
+
original.show().focus();
|
65
|
+
} else if (this.value == mark) {
|
66
|
+
this.value = '';
|
67
|
+
$(this).removeClass("watermark");
|
68
|
+
}
|
69
|
+
});
|
70
|
+
$(this).blur(function() {
|
71
|
+
if (!this.value.length) {
|
72
|
+
if (target != original[0]) {
|
73
|
+
$(target).show();
|
74
|
+
original.hide();
|
75
|
+
} else {
|
76
|
+
this.value = mark;
|
77
|
+
$(this).addClass("watermark")
|
78
|
+
}
|
79
|
+
}
|
80
|
+
});
|
81
|
+
|
82
|
+
// make sure that when the form is submitted, the watermark is
|
83
|
+
// replaced with the empty string, which is usually the expected behavior.
|
84
|
+
$(this).parents("form:first").submit(function(){
|
85
|
+
if ($(target).hasClass("watermark")) {
|
86
|
+
$(target).attr("value", "");
|
87
|
+
$(target).removeClass("watermark");
|
88
|
+
}
|
89
|
+
});
|
90
|
+
});
|
91
|
+
};
|