rails-ajax 0.3.3.20140307 → 1.0.0.20140320
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AUTHORS.rdoc +1 -0
- data/ChangeLog +16 -0
- data/Gemfile +0 -19
- data/Gemfile.lock +10 -82
- data/ReleaseInfo +1 -1
- data/assets/javascripts/jquery.rails-ajax.js.erb +78 -51
- data/gen/app/assets/javascripts/RailsAjax-Config.js.erb +1 -1
- data/gen/config/initializers/rails-ajax-config.rb +1 -1
- data/lib/rails-ajax.rb +0 -5
- data/lib/rails-ajax/action_controller/base.rb +0 -6
- data/lib/rails-ajax/action_view/base.rb +0 -5
- data/lib/rails-ajax/configuration.rb +34 -37
- data/lib/rails-ajax/controller.rb +51 -74
- data/lib/rails-ajax/form_tag_helper.rb +2 -21
- data/lib/rails-ajax/rails-ajax.rb +10 -15
- data/lib/rails-ajax/railtie.rb +2 -7
- data/lib/rails-ajax/url_helper.rb +14 -11
- data/tasks/rails-ajax_tasks.rake +8 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d174e764d5f6b7b2c49ade21b0b53419a38656fb
|
4
|
+
data.tar.gz: eace139aa4e7b220466a5cc8fb7f6fde0e6461bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24f0d39e6f272df7336e5803cc413c52d4a8ee3308c4517f2274e3b33f9d1707bc6e696bf9b18163c4fe1f9cbd1bcdf4eb0dd4e60ff108a51dfb6d5397621d22
|
7
|
+
data.tar.gz: fc12a427b0b6ce796085125a1f7fe84277a1637ce14f921c0eac80c24305edbd3ffd411f246cb7196f17a1c2ea44a7e8cf040a2c5ece289a1987f791840d11fc
|
data/AUTHORS.rdoc
CHANGED
data/ChangeLog
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
= Rails-Ajax Release History
|
2
2
|
|
3
|
+
== 1.0.0.20140320 (Beta)
|
4
|
+
|
5
|
+
! Compatibility break !
|
6
|
+
The way to test if RailsAjax is enabled changes from:
|
7
|
+
RailsAjax.config.Enabled
|
8
|
+
to:
|
9
|
+
RailsAjax.config.enabled?
|
10
|
+
Unless you specifically used this method, this only impacts the generated config file app/assets/javascripts/RailsAjax-Config.js.erb.
|
11
|
+
|
12
|
+
* Added support for Rails button_to helper.
|
13
|
+
* Handled the case when servers return an empty content.
|
14
|
+
* Update page when a 4xx status gets to rails-ajax.
|
15
|
+
* Now compatible with Devise.
|
16
|
+
* Complete code review.
|
17
|
+
* Adapted Travis configuration to take database into account.
|
18
|
+
|
3
19
|
== 0.3.3.20140307 (Beta)
|
4
20
|
|
5
21
|
* Adapted tests environment to Travis
|
data/Gemfile
CHANGED
@@ -15,22 +15,3 @@ gem "jquery-rails"
|
|
15
15
|
|
16
16
|
# To use debugger
|
17
17
|
# gem 'debugger'
|
18
|
-
|
19
|
-
group :test do
|
20
|
-
|
21
|
-
# Rails itself
|
22
|
-
gem 'rails'
|
23
|
-
|
24
|
-
# RSpec
|
25
|
-
gem 'rspec'
|
26
|
-
gem 'rspec-rails'
|
27
|
-
|
28
|
-
# Cucumber
|
29
|
-
gem 'cucumber-rails', :require => false
|
30
|
-
gem 'sqlite3'
|
31
|
-
gem 'database_cleaner'
|
32
|
-
|
33
|
-
# Capybara-webkit
|
34
|
-
gem 'capybara-webkit'
|
35
|
-
|
36
|
-
end
|
data/Gemfile.lock
CHANGED
@@ -6,116 +6,44 @@ PATH
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
actionpack (4.0.3)
|
12
|
-
activesupport (= 4.0.3)
|
9
|
+
actionpack (4.0.4)
|
10
|
+
activesupport (= 4.0.4)
|
13
11
|
builder (~> 3.1.0)
|
14
12
|
erubis (~> 2.7.0)
|
15
13
|
rack (~> 1.5.2)
|
16
14
|
rack-test (~> 0.6.2)
|
17
|
-
|
18
|
-
|
19
|
-
builder (~> 3.1.0)
|
20
|
-
activerecord (4.0.3)
|
21
|
-
activemodel (= 4.0.3)
|
22
|
-
activerecord-deprecated_finders (~> 1.0.2)
|
23
|
-
activesupport (= 4.0.3)
|
24
|
-
arel (~> 4.0.0)
|
25
|
-
activerecord-deprecated_finders (1.0.3)
|
26
|
-
activesupport (4.0.3)
|
27
|
-
i18n (~> 0.6, >= 0.6.4)
|
15
|
+
activesupport (4.0.4)
|
16
|
+
i18n (~> 0.6, >= 0.6.9)
|
28
17
|
minitest (~> 4.2)
|
29
18
|
multi_json (~> 1.3)
|
30
19
|
thread_safe (~> 0.1)
|
31
20
|
tzinfo (~> 0.3.37)
|
32
|
-
|
33
|
-
atomic (1.1.15)
|
21
|
+
atomic (1.1.16)
|
34
22
|
builder (3.1.4)
|
35
|
-
capybara (2.2.1)
|
36
|
-
mime-types (>= 1.16)
|
37
|
-
nokogiri (>= 1.3.3)
|
38
|
-
rack (>= 1.0.0)
|
39
|
-
rack-test (>= 0.5.4)
|
40
|
-
xpath (~> 2.0)
|
41
|
-
capybara-webkit (1.1.0)
|
42
|
-
capybara (~> 2.0, >= 2.0.2)
|
43
|
-
json
|
44
|
-
cucumber (1.3.11)
|
45
|
-
builder (>= 2.1.2)
|
46
|
-
diff-lcs (>= 1.1.3)
|
47
|
-
gherkin (~> 2.12)
|
48
|
-
multi_json (>= 1.7.5, < 2.0)
|
49
|
-
multi_test (>= 0.0.2)
|
50
|
-
cucumber-rails (1.3.0)
|
51
|
-
capybara (>= 1.1.2)
|
52
|
-
cucumber (>= 1.1.8)
|
53
|
-
nokogiri (>= 1.5.0)
|
54
|
-
database_cleaner (1.2.0)
|
55
|
-
diff-lcs (1.2.5)
|
56
23
|
erubis (2.7.0)
|
57
|
-
gherkin (2.12.2)
|
58
|
-
multi_json (~> 1.3)
|
59
24
|
i18n (0.6.9)
|
60
25
|
jquery-rails (3.1.0)
|
61
26
|
railties (>= 3.0, < 5.0)
|
62
27
|
thor (>= 0.14, < 2.0)
|
63
|
-
json (1.8.1)
|
64
|
-
mime-types (2.1)
|
65
|
-
mini_portile (0.5.2)
|
66
28
|
minitest (4.7.5)
|
67
29
|
multi_json (1.9.0)
|
68
|
-
multi_test (0.0.3)
|
69
|
-
nokogiri (1.6.1)
|
70
|
-
mini_portile (~> 0.5.0)
|
71
30
|
rack (1.5.2)
|
72
31
|
rack-test (0.6.2)
|
73
32
|
rack (>= 1.0)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
activerecord (>= 1.6.0)
|
78
|
-
rake (>= 0.4.15)
|
79
|
-
railties (4.0.3)
|
80
|
-
actionpack (= 4.0.3)
|
81
|
-
activesupport (= 4.0.3)
|
33
|
+
railties (4.0.4)
|
34
|
+
actionpack (= 4.0.4)
|
35
|
+
activesupport (= 4.0.4)
|
82
36
|
rake (>= 0.8.7)
|
83
37
|
thor (>= 0.18.1, < 2.0)
|
84
38
|
rake (10.1.1)
|
85
|
-
rspec (2.14.1)
|
86
|
-
rspec-core (~> 2.14.0)
|
87
|
-
rspec-expectations (~> 2.14.0)
|
88
|
-
rspec-mocks (~> 2.14.0)
|
89
|
-
rspec-core (2.14.8)
|
90
|
-
rspec-expectations (2.14.5)
|
91
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
92
|
-
rspec-mocks (2.14.6)
|
93
|
-
rspec-rails (2.14.1)
|
94
|
-
actionpack (>= 3.0)
|
95
|
-
activemodel (>= 3.0)
|
96
|
-
activesupport (>= 3.0)
|
97
|
-
railties (>= 3.0)
|
98
|
-
rspec-core (~> 2.14.0)
|
99
|
-
rspec-expectations (~> 2.14.0)
|
100
|
-
rspec-mocks (~> 2.14.0)
|
101
|
-
sqlite3 (1.3.9)
|
102
39
|
thor (0.18.1)
|
103
|
-
thread_safe (0.
|
40
|
+
thread_safe (0.3.0)
|
104
41
|
atomic (>= 1.1.7, < 2)
|
105
|
-
tzinfo (0.3.
|
106
|
-
xpath (2.0.0)
|
107
|
-
nokogiri (~> 1.3)
|
42
|
+
tzinfo (0.3.39)
|
108
43
|
|
109
44
|
PLATFORMS
|
110
45
|
ruby
|
111
46
|
|
112
47
|
DEPENDENCIES
|
113
|
-
capybara-webkit
|
114
|
-
cucumber-rails
|
115
|
-
database_cleaner
|
116
48
|
jquery-rails
|
117
|
-
rails
|
118
49
|
rails-ajax!
|
119
|
-
rspec
|
120
|
-
rspec-rails
|
121
|
-
sqlite3
|
data/ReleaseInfo
CHANGED
@@ -1,9 +1,4 @@
|
|
1
|
-
|
2
|
-
// Copyright (c) 2012 Muriel Salvan (muriel@x-aeon.com)
|
3
|
-
// Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
-
//++
|
5
|
-
|
6
|
-
<% if (RailsAjax.config.Enabled) %>
|
1
|
+
<% if (RailsAjax.config.enabled?) %>
|
7
2
|
|
8
3
|
//=========================================
|
9
4
|
// Browser detection code (removed from jQuery >=1.9):
|
@@ -47,8 +42,6 @@ if ( browser.chrome ) {
|
|
47
42
|
jQuery.browser = browser;
|
48
43
|
//===========================================
|
49
44
|
|
50
|
-
|
51
|
-
|
52
45
|
// Encapsulate everything in a nice namespace
|
53
46
|
var railsAjax = {
|
54
47
|
|
@@ -61,7 +54,8 @@ var railsAjax = {
|
|
61
54
|
jQuery(window).bind('statechange', function() {
|
62
55
|
try {
|
63
56
|
var lState = History.getState();
|
64
|
-
<%= 'alert(\'[RailsAjax] History statechange triggered #\' + lState.data.id + \' via \' + lState.data.type + \' to \' + lState.url.replace(lRootURL, \'/\') + \' (anchor: \' + lState.data.anchor + \')\');' if (RailsAjax.config.
|
57
|
+
<%= 'alert(\'[RailsAjax] History statechange triggered #\' + lState.data.id + \' via \' + lState.data.type + \' to \' + lState.url.replace(lRootURL, \'/\') + \' (anchor: \' + lState.data.anchor + \', dataType: \' + lState.data.dataType + \')\');' if (RailsAjax.config.debug_alerts?) %>
|
58
|
+
// console.log('[RailsAjax] History statechange triggered ' + lState.data.type + ' to ' + lState.url.replace(lRootURL, '/') + ' (anchor: ' + lState.data.anchor + ', dataType: ' + lState.data.dataType + ')');
|
65
59
|
jQuery.ajax({
|
66
60
|
// TODO (History.js): Remove the anchor attribute when History.js handles anchors correctly.
|
67
61
|
anchor: lState.data.anchor,
|
@@ -75,21 +69,26 @@ var railsAjax = {
|
|
75
69
|
// And the callbacks
|
76
70
|
// TODO (History.js): Remove the beforeSend callback when anchors will be handled correctly by History.js
|
77
71
|
beforeSend: function(ioXHR, iSettings) {
|
72
|
+
// console.log('[RailsAjax] Before sending request');
|
78
73
|
// Remember the anchor used
|
79
74
|
ioXHR.anchor = iSettings.anchor;
|
80
75
|
},
|
81
76
|
success: function(iData, iStatus, iXHR) {
|
77
|
+
// console.log('[RailsAjax] Response returned success');
|
82
78
|
railsAjax.ajaxSuccess(iXHR, iData);
|
83
79
|
},
|
84
80
|
error: function(iXHR, iStatus, iError) {
|
81
|
+
// console.log('[RailsAjax] Response returned error');
|
85
82
|
railsAjax.ajaxError(iXHR, iError);
|
86
83
|
}
|
87
84
|
});
|
88
85
|
} catch (iError) {
|
86
|
+
// console.log('[RailsAjax] Exception in statechange callback: ' + iError.name + ' - ' + iError.message);
|
89
87
|
alert('[RailsAjax] Exception in statechange callback: ' + iError.name + ' - ' + iError.message);
|
90
88
|
}
|
91
89
|
});
|
92
90
|
} catch (iError) {
|
91
|
+
// console.log('[RailsAjax] Exception during railsAjax initialization: ' + iError.name + ' - ' + iError.message);
|
93
92
|
alert('[RailsAjax] Exception during railsAjax initialization: ' + iError.name + ' - ' + iError.message);
|
94
93
|
}
|
95
94
|
},
|
@@ -100,13 +99,13 @@ var railsAjax = {
|
|
100
99
|
// * *iCSSSelector* (_String_): CSS selector of elements needing attachment
|
101
100
|
attachAjaxToElements: function(iCSSSelector) {
|
102
101
|
try {
|
103
|
-
<%= 'alert(\'[RailsAjax] Attach Ajax bindings to elements \' + iCSSSelector + \' (\' + jQuery(iCSSSelector).length + \' elements)\');' if (RailsAjax.config.
|
102
|
+
<%= 'alert(\'[RailsAjax] Attach Ajax bindings to elements \' + iCSSSelector + \' (\' + jQuery(iCSSSelector).length + \' elements)\');' if (RailsAjax.config.debug_alerts?) %>
|
104
103
|
jQuery(document)
|
105
104
|
.delegate(iCSSSelector, 'ajax:beforeSend', function(iEvent, ioXHR, iSettings) {
|
106
105
|
try {
|
107
106
|
var lThis = jQuery(this);
|
108
107
|
var lURL = ((lThis.is('a')) ? lThis.attr('href') : lThis.attr('action'));
|
109
|
-
<%= 'alert(\'[RailsAjax] Ajax before send. URL=\' + lURL + \' Method=\' + iSettings.type + \' Data=\' + iSettings.data);' if (RailsAjax.config.
|
108
|
+
<%= 'alert(\'[RailsAjax] Ajax before send. URL=\' + lURL + \' Method=\' + iSettings.type + \' Data=\' + iSettings.data);' if (RailsAjax.config.debug_alerts?) %>
|
110
109
|
var lContinue = true;
|
111
110
|
if (railsAjax.beforeSend != undefined) {
|
112
111
|
try {
|
@@ -115,7 +114,7 @@ var railsAjax = {
|
|
115
114
|
alert('[RailsAjax] Exception in user callback railsAjax.beforeSend: ' + iUserError.name + ' - ' + iUserError.message);
|
116
115
|
}
|
117
116
|
}
|
118
|
-
<%= 'alert(\'[RailsAjax] Continue on the Ajax load ? \' + lContinue);' if (RailsAjax.config.
|
117
|
+
<%= 'alert(\'[RailsAjax] Continue on the Ajax load ? \' + lContinue);' if (RailsAjax.config.debug_alerts?) %>
|
119
118
|
if (lContinue) {
|
120
119
|
railsAjax.pushNewState(lURL,
|
121
120
|
{
|
@@ -144,45 +143,16 @@ var railsAjax = {
|
|
144
143
|
//
|
145
144
|
// Parameters::
|
146
145
|
// * *iXHR* (_Object_): The XHR object responsible for the Ajax call
|
147
|
-
// * *iData* (_String_): The received data
|
146
|
+
// * *iData* (_String_): The received data (can be undefined for empty contents)
|
148
147
|
ajaxSuccess: function(iXHR, iData) {
|
149
148
|
try {
|
150
|
-
<%= 'alert(\'[RailsAjax] Ajax success. Loading data: \' + iData);' if (RailsAjax.config.
|
151
|
-
|
152
|
-
// 1. Change the window's title if needed
|
153
|
-
if ('page_title' in iData) {
|
154
|
-
document.title = iData.page_title;
|
155
|
-
}
|
156
|
-
|
157
|
-
// 2. Replace HTML data, and execute scripts in the same time
|
158
|
-
jQuery.each(iData.div_contents, function(iCSSSelector, iContent) {
|
159
|
-
// This replaces HTML content and also executes scripts (even document.ready ones)
|
160
|
-
jQuery(iCSSSelector).html(iContent);
|
161
|
-
});
|
162
|
-
|
163
|
-
// 3. Scroll to anchor if needed
|
164
|
-
if (iXHR.anchor) {
|
165
|
-
railsAjax.scrollToAnchor(iXHR.anchor);
|
166
|
-
}
|
149
|
+
<%= 'alert(\'[RailsAjax] Ajax success. Loading data: \' + iData);' if (RailsAjax.config.debug_alerts?) %>
|
167
150
|
|
168
|
-
|
169
|
-
|
170
|
-
railsAjax.setFavicon();
|
171
|
-
}
|
172
|
-
|
173
|
-
// 5. Execute scripts that were added
|
174
|
-
if ('js_to_execute' in iData) {
|
175
|
-
jQuery.each(iData.js_to_execute, function(iIdx, iJS) {
|
176
|
-
<%= 'alert(\'[RailsAjax] Execute script #\' + iIdx + \':\\n\' + iJS);' if (RailsAjax.config.DebugAlerts) %>
|
177
|
-
try {
|
178
|
-
eval(iJS);
|
179
|
-
} catch (iError) {
|
180
|
-
alert('[RailsAjax] Exception while executing Ajax script: ' + iError.name + ' - ' + iError.message + '\nScript:\n' + iJS);
|
181
|
-
}
|
182
|
-
});
|
151
|
+
if (iData != undefined) {
|
152
|
+
railsAjax.updatePage(iXHR, iData);
|
183
153
|
}
|
184
154
|
|
185
|
-
//
|
155
|
+
// Call user callbacks
|
186
156
|
if (railsAjax.success != undefined) {
|
187
157
|
try {
|
188
158
|
railsAjax.success(iXHR, iData);
|
@@ -198,8 +168,9 @@ var railsAjax = {
|
|
198
168
|
}
|
199
169
|
}
|
200
170
|
|
201
|
-
//
|
202
|
-
if (
|
171
|
+
// Handle redirects
|
172
|
+
if ((iData != undefined) &&
|
173
|
+
('redirect_to' in iData)) {
|
203
174
|
railsAjax.pushNewState(iData.redirect_to, {}, true);
|
204
175
|
}
|
205
176
|
|
@@ -214,6 +185,15 @@ var railsAjax = {
|
|
214
185
|
// * *iXHR* (_Object_): The xhr object
|
215
186
|
// * *iError* (_Object_): The error
|
216
187
|
ajaxError: function(iXHR, iError) {
|
188
|
+
|
189
|
+
// If the error is a 4xx one, and handled by rails-ajax (using a JSON object), still update the page.
|
190
|
+
if ((iXHR.status >= 400) &&
|
191
|
+
(iXHR.status < 500) &&
|
192
|
+
(iXHR.responseJSON != undefined)) {
|
193
|
+
railsAjax.updatePage(iXHR, iXHR.responseJSON);
|
194
|
+
}
|
195
|
+
|
196
|
+
// Call user callbacks
|
217
197
|
if (railsAjax.error != undefined) {
|
218
198
|
try {
|
219
199
|
railsAjax.error(iXHR, iError);
|
@@ -228,10 +208,57 @@ var railsAjax = {
|
|
228
208
|
alert('[RailsAjax] Exception in user callback railsAjax.complete: ' + iUserError.name + ' - ' + iUserError.message);
|
229
209
|
}
|
230
210
|
}
|
211
|
+
|
212
|
+
},
|
213
|
+
|
214
|
+
// Update the page with a given data returned by rails-ajax
|
215
|
+
//
|
216
|
+
// Parameters::
|
217
|
+
// * *iXHR* (_Object_): The XHR object responsible for the Ajax call
|
218
|
+
// * *iData* (_String_): The received data
|
219
|
+
updatePage: function(iXHR, iData) {
|
220
|
+
try {
|
221
|
+
|
222
|
+
// 1. Change the window's title if needed
|
223
|
+
if ('page_title' in iData) {
|
224
|
+
document.title = iData.page_title;
|
225
|
+
}
|
226
|
+
|
227
|
+
// 2. Replace HTML data, and execute scripts in the same time
|
228
|
+
jQuery.each(iData.div_contents, function(iCSSSelector, iContent) {
|
229
|
+
// This replaces HTML content and also executes scripts (even document.ready ones)
|
230
|
+
jQuery(iCSSSelector).html(iContent);
|
231
|
+
});
|
232
|
+
|
233
|
+
// 3. Scroll to anchor if needed
|
234
|
+
if (iXHR.anchor) {
|
235
|
+
railsAjax.scrollToAnchor(iXHR.anchor);
|
236
|
+
}
|
237
|
+
|
238
|
+
// 4. For Firefox only, workaround a bug by setting the Favicon
|
239
|
+
if (jQuery.browser.mozilla) {
|
240
|
+
railsAjax.setFavicon();
|
241
|
+
}
|
242
|
+
|
243
|
+
// 5. Execute scripts that were added
|
244
|
+
if ('js_to_execute' in iData) {
|
245
|
+
jQuery.each(iData.js_to_execute, function(iIdx, iJS) {
|
246
|
+
<%= 'alert(\'[RailsAjax] Execute script #\' + iIdx + \':\\n\' + iJS);' if (RailsAjax.config.debug_alerts?) %>
|
247
|
+
try {
|
248
|
+
eval(iJS);
|
249
|
+
} catch (iError) {
|
250
|
+
alert('[RailsAjax] Exception while executing Ajax script: ' + iError.name + ' - ' + iError.message + '\nScript:\n' + iJS);
|
251
|
+
}
|
252
|
+
});
|
253
|
+
}
|
254
|
+
|
255
|
+
} catch (iError) {
|
256
|
+
alert('[RailsAjax] Exception while updating page: ' + iError.name + ' - ' + iError.message);
|
257
|
+
}
|
231
258
|
},
|
232
259
|
|
233
260
|
// Used to identify states in debugging logs
|
234
|
-
<%= 'gStateID: 0,' if (RailsAjax.config.
|
261
|
+
<%= 'gStateID: 0,' if (RailsAjax.config.debug_alerts?) %>
|
235
262
|
|
236
263
|
// Push a new History state
|
237
264
|
//
|
@@ -248,7 +275,7 @@ var railsAjax = {
|
|
248
275
|
var lState = jQuery.extend(
|
249
276
|
{
|
250
277
|
// Used to identify states in debugging logs
|
251
|
-
<%= 'id: railsAjax.gStateID,' if (RailsAjax.config.
|
278
|
+
<%= 'id: railsAjax.gStateID,' if (RailsAjax.config.debug_alerts?) %>
|
252
279
|
anchor: lSplittedURL[1]
|
253
280
|
},
|
254
281
|
iData
|
@@ -258,7 +285,7 @@ var railsAjax = {
|
|
258
285
|
} else {
|
259
286
|
History.pushState(lState, null, lSplittedURL[0]);
|
260
287
|
}
|
261
|
-
<%= 'railsAjax.gStateID = railsAjax.gStateID + 1;' if (RailsAjax.config.
|
288
|
+
<%= 'railsAjax.gStateID = railsAjax.gStateID + 1;' if (RailsAjax.config.debug_alerts?) %>
|
262
289
|
} catch (iError) {
|
263
290
|
alert('[RailsAjax] Exception in pushNewState: ' + iError.name + ' - ' + iError.message);
|
264
291
|
}
|
data/lib/rails-ajax.rb
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2012 Muriel Salvan (Muriel@X-Aeon.com)
|
3
|
-
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
-
#++
|
5
|
-
|
6
1
|
module RailsAjax
|
7
2
|
|
8
3
|
# Class used to configure and store the configuration of RailsAjax
|
@@ -10,63 +5,65 @@ module RailsAjax
|
|
10
5
|
|
11
6
|
# Indicate if RailsAjax is enabled
|
12
7
|
#
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# _String_
|
19
|
-
attr_reader :MainContainer
|
20
|
-
|
21
|
-
# The flash containers
|
22
|
-
#
|
23
|
-
# <em>map< Symbol, String ></em>
|
24
|
-
attr_reader :FlashContainers
|
8
|
+
# Return::
|
9
|
+
# * _Boolean_: Is rails-ajax enabled?
|
10
|
+
def enabled?
|
11
|
+
return @enabled
|
12
|
+
end
|
25
13
|
|
26
14
|
# Debug alerts ?
|
27
15
|
#
|
28
|
-
#
|
29
|
-
|
16
|
+
# Return::
|
17
|
+
# * _Boolean_: Do we switch on debug alerts?
|
18
|
+
def debug_alerts?
|
19
|
+
return @debug_alerts
|
20
|
+
end
|
30
21
|
|
31
22
|
# Constructor
|
32
23
|
def initialize
|
33
24
|
# Set default values here
|
34
|
-
@
|
35
|
-
@
|
36
|
-
@
|
37
|
-
@
|
25
|
+
@enabled = true
|
26
|
+
@main_container = 'body'
|
27
|
+
@flash_containers = {}
|
28
|
+
@debug_alerts = false
|
38
29
|
end
|
39
30
|
|
40
31
|
# Do we activate RailsAjax ?
|
41
32
|
#
|
42
33
|
# Parameters::
|
43
|
-
# * *
|
44
|
-
def enable(
|
45
|
-
@
|
34
|
+
# * *switch* (_Boolean_): Do we activate RailsAjax ?
|
35
|
+
def enable(switch)
|
36
|
+
@enabled = switch
|
46
37
|
end
|
47
38
|
|
48
|
-
# Define the main container
|
39
|
+
# Define the main container if provided, and return it
|
49
40
|
#
|
50
41
|
# Parameters::
|
51
|
-
# * *
|
52
|
-
|
53
|
-
|
42
|
+
# * *selector* (_String_): Selector used to identify the container [optional = nil]
|
43
|
+
# Return::
|
44
|
+
# * _String_: The CSS selector of the main container
|
45
|
+
def main_container(selector = nil)
|
46
|
+
@main_container = selector if (selector != nil)
|
47
|
+
return @main_container
|
54
48
|
end
|
55
49
|
|
56
|
-
# Define the flash containers
|
50
|
+
# Define the flash containers (add them to already present ones) if provided, and return them
|
57
51
|
#
|
58
52
|
# Parameters::
|
59
|
-
# * *
|
60
|
-
|
61
|
-
|
53
|
+
# * *selectors_map* (<em>map<Symbol,String></em>): The map of selectors, per flash message type (:alert, :notice...)
|
54
|
+
# Return::
|
55
|
+
# * <em>map<Symbol,String></em>: The map of selectors [optional = nil]
|
56
|
+
def flash_containers(selectors_map = nil)
|
57
|
+
@flash_containers.merge!(selectors_map) if (selectors_map != nil)
|
58
|
+
return @flash_containers
|
62
59
|
end
|
63
60
|
|
64
61
|
# Do we activate debugging alerts ?
|
65
62
|
#
|
66
63
|
# Parameters::
|
67
|
-
# * *
|
68
|
-
def debug_alerts(
|
69
|
-
@
|
64
|
+
# * *switch* (_Boolean_): Do we activate debugging alerts ?
|
65
|
+
def debug_alerts(switch)
|
66
|
+
@debug_alerts = switch
|
70
67
|
end
|
71
68
|
|
72
69
|
end
|
@@ -1,8 +1,3 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2012 Muriel Salvan (Muriel@X-Aeon.com)
|
3
|
-
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
-
#++
|
5
|
-
|
6
1
|
module RailsAjax
|
7
2
|
|
8
3
|
# Module defining new methods that will be part of every controller
|
@@ -10,75 +5,60 @@ module RailsAjax
|
|
10
5
|
|
11
6
|
# Render
|
12
7
|
# Adapt to AJAX calls, by returning the following JSON object that will be interpreted by client side JavaScript.
|
13
|
-
def render(*
|
14
|
-
if (RailsAjax.config.
|
15
|
-
|
8
|
+
def render(*options, &block)
|
9
|
+
if (RailsAjax.config.enabled?)
|
10
|
+
args = _normalize_args(*options, &block)
|
16
11
|
if ((request.xhr?) and
|
17
|
-
(!
|
18
|
-
(!
|
19
|
-
(!
|
12
|
+
(!args.has_key?(:partial)) and
|
13
|
+
(!args.has_key?(:layout)) and
|
14
|
+
(!args.has_key?(:json)) and
|
20
15
|
(params['format'] != 'json') and
|
21
16
|
(self.content_type != 'application/json'))
|
22
|
-
logger.debug "[RailsAjax] render:
|
17
|
+
logger.debug "[RailsAjax] render: options=#{options.inspect} block?#{block != nil} flash=#{flash.inspect} | Normalized arguments: #{args.inspect}"
|
23
18
|
|
24
19
|
# If we have a redirection, use redirect_to
|
25
|
-
if (
|
20
|
+
if (args[:location] == nil)
|
26
21
|
# Complete arguments if needed
|
27
22
|
# We don't want a special layout for Ajax requests: this was asked using AJAX for a page to be displayed in the main content
|
28
|
-
|
23
|
+
args[:layout] = false
|
29
24
|
# Render
|
30
|
-
|
31
|
-
if (iBlock == nil)
|
32
|
-
lMainPage = render_to_string(lArgs)
|
33
|
-
else
|
34
|
-
lMainPage = render_to_string(lArgs) do
|
35
|
-
iBlock.call
|
36
|
-
end
|
37
|
-
end
|
25
|
+
main_content = render_to_string(args, &block)
|
38
26
|
|
39
27
|
# Send JSON result
|
40
28
|
# Use 'application/json'
|
41
29
|
self.content_type = 'application/json'
|
42
30
|
self.response_body = get_json_response(
|
43
|
-
:
|
44
|
-
RailsAjax
|
31
|
+
:elements_to_refresh => {
|
32
|
+
RailsAjax.config.main_container => main_content
|
45
33
|
}
|
46
34
|
).to_json
|
47
|
-
elsif (
|
48
|
-
redirect_to
|
35
|
+
elsif (args[:status] == nil)
|
36
|
+
redirect_to args[:location]
|
49
37
|
else
|
50
|
-
redirect_to
|
38
|
+
redirect_to args[:location], args[:status]
|
51
39
|
end
|
52
40
|
|
53
|
-
elsif (iBlock == nil)
|
54
|
-
super(*iArgs)
|
55
41
|
else
|
56
|
-
super(*
|
57
|
-
iBlock.call
|
58
|
-
end
|
42
|
+
super(*options, &block)
|
59
43
|
end
|
60
|
-
elsif (iBlock == nil)
|
61
|
-
super(*iArgs)
|
62
44
|
else
|
63
|
-
super(*
|
64
|
-
iBlock.call
|
65
|
-
end
|
45
|
+
super(*options, &block)
|
66
46
|
end
|
67
47
|
|
68
48
|
end
|
69
49
|
|
70
50
|
# Render a redirection
|
71
51
|
# Adapt to AJAX calls
|
72
|
-
def redirect_to(
|
73
|
-
if (RailsAjax.config.
|
74
|
-
logger.debug "[RailsAjax] redirect_to:
|
52
|
+
def redirect_to(options = {}, response_status = {})
|
53
|
+
if (RailsAjax.config.enabled? and request.xhr?)
|
54
|
+
logger.debug "[RailsAjax] redirect_to: options=#{options.inspect} response_status=#{response_status.inspect}"
|
75
55
|
# Use 'application/json'
|
76
56
|
self.content_type = 'application/json'
|
77
57
|
self.response_body = get_json_response(
|
78
|
-
:redirect_to => url_for(
|
58
|
+
:redirect_to => url_for(options)
|
79
59
|
).to_json
|
80
60
|
else
|
81
|
-
super(
|
61
|
+
super(options, response_status)
|
82
62
|
end
|
83
63
|
end
|
84
64
|
|
@@ -87,15 +67,13 @@ module RailsAjax
|
|
87
67
|
# Mark given DOM elements (selected using a CSS selector) to be refreshed with a partial's content
|
88
68
|
#
|
89
69
|
# Parameters::
|
90
|
-
# * *
|
91
|
-
# * *
|
92
|
-
def refresh_dom_with_partial(
|
93
|
-
if RailsAjax.config.
|
94
|
-
logger.debug "[RailsAjax] Mark partial #{
|
95
|
-
if (defined?(@
|
96
|
-
|
97
|
-
end
|
98
|
-
@PartialsToRefresh[iCSSSelector] = iPartialName
|
70
|
+
# * *css_selector* (_String_): The CSS selector to be used to refresh elements
|
71
|
+
# * *partial_name* (_String_): Name of the partial to be used to refresh these elements
|
72
|
+
def refresh_dom_with_partial(css_selector, partial_name)
|
73
|
+
if RailsAjax.config.enabled?
|
74
|
+
logger.debug "[RailsAjax] Mark partial #{partial_name} to be refreshed in #{css_selector}"
|
75
|
+
@partials_to_refresh = {} if (defined?(@partials_to_refresh) == nil)
|
76
|
+
@partials_to_refresh[css_selector] = partial_name
|
99
77
|
end
|
100
78
|
end
|
101
79
|
|
@@ -103,14 +81,12 @@ module RailsAjax
|
|
103
81
|
# This is used to execute special Ajax handling that is not needed in case the same request is made without Ajax
|
104
82
|
#
|
105
83
|
# Parameters::
|
106
|
-
# * *
|
107
|
-
def execute_javascript(
|
108
|
-
if RailsAjax.config.
|
109
|
-
logger.debug "[RailsAjax] Add javascript to be executed: #{
|
110
|
-
if (defined?(@
|
111
|
-
|
112
|
-
end
|
113
|
-
@JSToExecute << iJS
|
84
|
+
# * *js_code* (_String_): Javascript to be executed
|
85
|
+
def execute_javascript(js_code)
|
86
|
+
if RailsAjax.config.enabled?
|
87
|
+
logger.debug "[RailsAjax] Add javascript to be executed: #{js_code[0..255]}"
|
88
|
+
@js_to_execute = [] if (defined?(@js_to_execute) == nil)
|
89
|
+
@js_to_execute << js_code
|
114
90
|
end
|
115
91
|
end
|
116
92
|
|
@@ -118,7 +94,8 @@ module RailsAjax
|
|
118
94
|
|
119
95
|
# Get the JSON object that will be sent to an Ajax request.
|
120
96
|
# Include the partials marked to be refreshed.
|
121
|
-
# Include Javascripts to be executed
|
97
|
+
# Include Javascripts to be executed.
|
98
|
+
# Include Flash messages.
|
122
99
|
# Structure of the JSON object:
|
123
100
|
# * *:div_contents* (<em>map<String,String></em>): The content of DOM elements to be replaced, indexed by CSS selector.
|
124
101
|
# * *:page_title* (_String_): The new page title
|
@@ -126,28 +103,28 @@ module RailsAjax
|
|
126
103
|
# * *:js_to_execute* (<em>list<String></em>): Javascripts to be executed
|
127
104
|
#
|
128
105
|
# Parameters::
|
129
|
-
# * *
|
130
|
-
# * *:
|
106
|
+
# * *options* (<em>map<Symbol,Object></em>): Options [optional = {}]
|
107
|
+
# * *:elements_to_refresh* (<em>map<String,String></em>): List of elements to be refreshed (HTML code), indexed by their CSS selector [optional = {}]
|
131
108
|
# * *:redirect_to* (_String_): URL to redirect to [optional = nil]
|
132
109
|
# Return::
|
133
110
|
# * <em>map<Object,Object></em>: The corresponding JSON data
|
134
|
-
def get_json_response(
|
135
|
-
|
111
|
+
def get_json_response(options = {})
|
112
|
+
json_result = {}
|
136
113
|
|
137
|
-
|
138
|
-
if (defined?(@
|
139
|
-
@
|
140
|
-
|
114
|
+
elements_contents = options[:elements_to_refresh] || {}
|
115
|
+
if (defined?(@partials_to_refresh) != nil)
|
116
|
+
@partials_to_refresh.each do |css_selector, partial_name|
|
117
|
+
elements_contents[css_selector] = render_to_string(:partial => partial_name)
|
141
118
|
end
|
142
119
|
end
|
143
|
-
RailsAjax
|
144
|
-
|
120
|
+
RailsAjax.config.flash_containers.each do |flash_type, css_selector|
|
121
|
+
elements_contents[css_selector] = flash[flash_type]
|
145
122
|
end
|
146
|
-
|
147
|
-
|
148
|
-
|
123
|
+
json_result[:js_to_execute] = @js_to_execute if (defined?(@js_to_execute) != nil)
|
124
|
+
json_result[:div_contents] = elements_contents
|
125
|
+
json_result[:redirect_to] = options[:redirect_to] if (options[:redirect_to] != nil)
|
149
126
|
|
150
|
-
return
|
127
|
+
return json_result
|
151
128
|
end
|
152
129
|
|
153
130
|
end
|
@@ -1,8 +1,3 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2012 Muriel Salvan (Muriel@X-Aeon.com)
|
3
|
-
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
-
#++
|
5
|
-
|
6
1
|
module RailsAjax
|
7
2
|
|
8
3
|
# Module defining methods to include in ActionView::Helpers::FormTagHelper
|
@@ -10,22 +5,8 @@ module RailsAjax
|
|
10
5
|
|
11
6
|
# Replaces form_tag with an Ajax updated version
|
12
7
|
def form_tag(url_for_options = {}, options = {}, &block)
|
13
|
-
if (RailsAjax.config.
|
14
|
-
|
15
|
-
if block_given?
|
16
|
-
return super(url_for_options, options.merge({ :remote => true, :'data-rails-ajax-remote' => true })) do
|
17
|
-
block.call
|
18
|
-
end
|
19
|
-
else
|
20
|
-
return super(url_for_options, options.merge({ :remote => true, :'data-rails-ajax-remote' => true }))
|
21
|
-
end
|
22
|
-
elsif block_given?
|
23
|
-
return super(url_for_options, options) do
|
24
|
-
block.call
|
25
|
-
end
|
26
|
-
else
|
27
|
-
return super(url_for_options, options)
|
28
|
-
end
|
8
|
+
options.merge!({ :remote => true, :'data-rails-ajax-remote' => true }) if (RailsAjax.config.enabled? and RailsAjax.rails_ajaxifiable?(options))
|
9
|
+
return super(url_for_options, options, &block)
|
29
10
|
end
|
30
11
|
|
31
12
|
end
|
@@ -1,40 +1,35 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2012 Muriel Salvan (Muriel@X-Aeon.com)
|
3
|
-
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
-
#++
|
5
|
-
|
6
1
|
module RailsAjax
|
7
2
|
|
8
3
|
# The configuration
|
9
4
|
# <em>RailsAjax::Configuration</em>
|
10
|
-
|
5
|
+
@configuration = RailsAjax::Configuration.new
|
11
6
|
|
12
7
|
# Give access to the configuration
|
13
8
|
#
|
14
9
|
# Return::
|
15
10
|
# * <em>RailsAjax::Configuration</em>: The RailsAjax configuration
|
16
11
|
def self.config
|
17
|
-
return
|
12
|
+
return @configuration
|
18
13
|
end
|
19
14
|
|
20
15
|
# Configure RailsAjax
|
21
16
|
#
|
22
17
|
# Parameters::
|
23
|
-
# * *
|
24
|
-
def self.configure(&
|
25
|
-
|
18
|
+
# * *config_block* (_CodeBlock_): Block called that will contain all configuration directives
|
19
|
+
def self.configure(&config_block)
|
20
|
+
@configuration.instance_eval(&config_block)
|
26
21
|
end
|
27
22
|
|
28
23
|
# Find if we use rails-ajax for a given set of options applicable to a link
|
29
24
|
#
|
30
25
|
# Parameters::
|
31
|
-
# * *
|
26
|
+
# * *options* (<em>map<Symbol,Object></em>): The options provided to a link (used in link_to or form_tag)
|
32
27
|
# Result::
|
33
28
|
# * _Boolean_: Would this link be handled by rails-ajax?
|
34
|
-
def self.rails_ajaxifiable?(
|
35
|
-
return ((
|
36
|
-
(
|
37
|
-
(!
|
29
|
+
def self.rails_ajaxifiable?(options)
|
30
|
+
return ((options[:use_rails_ajax] != false) and # User has not removed rails-ajax voluntarily
|
31
|
+
(options[:target] == nil) and # Open in the same window and
|
32
|
+
(!options.has_key?(:remote))) # User has not specified Ajax call itself
|
38
33
|
end
|
39
34
|
|
40
35
|
end
|
data/lib/rails-ajax/railtie.rb
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2012 Muriel Salvan (Muriel@X-Aeon.com)
|
3
|
-
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
-
#++
|
5
|
-
|
6
1
|
module RailsAjax
|
7
2
|
|
8
3
|
# Class defining how Rails-Ajax is plugged into Rails
|
@@ -13,7 +8,7 @@ module RailsAjax
|
|
13
8
|
load "#{RailsAjax.root}/tasks/rails-ajax_tasks.rake"
|
14
9
|
end
|
15
10
|
|
16
|
-
initializer :'rails-ajax.initialize' do |
|
11
|
+
initializer :'rails-ajax.initialize' do |app|
|
17
12
|
# Require all files
|
18
13
|
require 'rails-ajax/configuration'
|
19
14
|
require 'rails-ajax/rails-ajax'
|
@@ -23,7 +18,7 @@ module RailsAjax
|
|
23
18
|
require 'rails-ajax/action_controller/base'
|
24
19
|
require 'rails-ajax/action_view/base'
|
25
20
|
# Add a new assets path for javascript
|
26
|
-
|
21
|
+
app.config.assets.paths << "#{RailsAjax.root}/assets/javascripts"
|
27
22
|
end
|
28
23
|
|
29
24
|
end
|
@@ -1,8 +1,3 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2012 Muriel Salvan (Muriel@X-Aeon.com)
|
3
|
-
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
-
#++
|
5
|
-
|
6
1
|
module RailsAjax
|
7
2
|
|
8
3
|
# Module defining methods to include in ActionView::Helpers::FormHelper
|
@@ -12,19 +7,27 @@ module RailsAjax
|
|
12
7
|
def link_to(name = nil, options = nil, html_options = nil, &block)
|
13
8
|
options, html_options = name, options if block_given?
|
14
9
|
html_options ||= {}
|
15
|
-
if (RailsAjax.config.
|
16
|
-
|
17
|
-
|
10
|
+
html_options.merge!({ :remote => true, :'data-rails-ajax-remote' => true }) if (RailsAjax.config.enabled? and RailsAjax.rails_ajaxifiable?(html_options))
|
11
|
+
if block_given?
|
12
|
+
return super(options, html_options, &block)
|
13
|
+
else
|
14
|
+
return super(name, options, html_options)
|
18
15
|
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Adapt button_to method to handle Ajax queries automatically
|
19
|
+
def button_to(name = nil, options = nil, html_options = nil, &block)
|
20
|
+
html_options, options = options, name if block_given?
|
21
|
+
html_options ||= {}
|
22
|
+
html_options.merge!({ :remote => true, :form => {:'data-rails-ajax-remote' => true} }) if (RailsAjax.config.enabled? and RailsAjax.rails_ajaxifiable?(html_options))
|
19
23
|
if block_given?
|
20
|
-
return super(options, html_options)
|
21
|
-
block.call
|
22
|
-
end
|
24
|
+
return super(options, html_options, &block)
|
23
25
|
else
|
24
26
|
return super(name, options, html_options)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
30
|
+
|
28
31
|
end
|
29
32
|
|
30
33
|
end
|
data/tasks/rails-ajax_tasks.rake
CHANGED
@@ -1,22 +1,17 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2012 Muriel Salvan (Muriel@X-Aeon.com)
|
3
|
-
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
-
#++
|
5
|
-
|
6
1
|
namespace :'rails-ajax' do
|
7
2
|
|
8
3
|
# Copy a file if it does not exist from RailsAjax root path /gen to Rails root path
|
9
4
|
#
|
10
5
|
# Parameters::
|
11
|
-
# * *
|
12
|
-
def copy_file_unless_exists(
|
13
|
-
|
14
|
-
if (File.exist?(
|
15
|
-
puts "File #{
|
6
|
+
# * *file_name* (_String_): The file name
|
7
|
+
def copy_file_unless_exists(file_name)
|
8
|
+
dest_file_name = File.join(Rails.root, file_name)
|
9
|
+
if (File.exist?(dest_file_name))
|
10
|
+
puts "File #{dest_file_name} already exists. Will not overwrite."
|
16
11
|
else
|
17
|
-
puts "Creating file #{
|
18
|
-
FileUtils.mkdir_p(File.dirname(
|
19
|
-
FileUtils.cp(
|
12
|
+
puts "Creating file #{dest_file_name}."
|
13
|
+
FileUtils.mkdir_p(File.dirname(dest_file_name))
|
14
|
+
FileUtils.cp("#{RailsAjax.root}/gen/#{file_name}", dest_file_name)
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-ajax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.20140320
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Muriel Salvan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|