jqr-helpers 1.0.9 → 1.0.10
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.
- data/app/assets/javascripts/jqr-helpers.js +52 -14
- data/jqr-helpers.gemspec +1 -1
- data/lib/jqr-helpers/helpers.rb +12 -6
- data/lib/jqr-helpers/version.rb +1 -1
- metadata +1 -1
@@ -108,30 +108,65 @@
|
|
108
108
|
return false;
|
109
109
|
}
|
110
110
|
|
111
|
+
function ujsButtonClick(event) {
|
112
|
+
var element = $(this);
|
113
|
+
element.uniqueId(); // to store for later
|
114
|
+
if ($.rails.allowAction(element)) {
|
115
|
+
// largely copied from rails_jquery.js
|
116
|
+
var href = element.data('url');
|
117
|
+
var method = element.data('method');
|
118
|
+
var csrf_token = $('meta[name=csrf-token]').attr('content');
|
119
|
+
var csrf_param = $('meta[name=csrf-param]').attr('content');
|
120
|
+
var form = $('<form method="post" action="' + href + '"></form>');
|
121
|
+
var metadata_input =
|
122
|
+
'<input name="_method" value="' + method + '" type="hidden" />';
|
123
|
+
|
124
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
125
|
+
metadata_input += '<input name="' + csrf_param + '" value="' +
|
126
|
+
csrf_token + '" type="hidden" />';
|
127
|
+
}
|
128
|
+
|
129
|
+
form.hide().append(metadata_input).appendTo('body');
|
130
|
+
$(form).data(element.data()); // copy to form
|
131
|
+
$(form).data('remote', true);
|
132
|
+
$(form).addClass('ujs-ajax');
|
133
|
+
$(form).data('real-element', element.attr('id'));
|
134
|
+
form.submit();
|
135
|
+
}
|
136
|
+
event.preventDefault();
|
137
|
+
return false;
|
138
|
+
}
|
139
|
+
|
111
140
|
function ujsAjaxBeforeSend() {
|
112
|
-
|
113
|
-
|
141
|
+
var element = $(this);
|
142
|
+
if (element.data('real-element')) {
|
143
|
+
element = $('#' + element.data('real-element'));
|
144
|
+
}
|
145
|
+
if (element.is('form')) {
|
146
|
+
var submit = $('input[type=submit]', element);
|
114
147
|
if (submit.length)
|
115
148
|
showThrobber(submit);
|
116
149
|
else
|
117
|
-
showThrobber(
|
150
|
+
showThrobber(element);
|
118
151
|
}
|
119
152
|
else {
|
120
|
-
showThrobber(
|
153
|
+
showThrobber(element);
|
121
154
|
}
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
disableElement.attr('disabled', 'disabled');
|
155
|
+
if (element.is('form'))
|
156
|
+
element = $('button, input[type=submit]', element).first();
|
157
|
+
element.attr('disabled', 'disabled');
|
126
158
|
}
|
127
159
|
|
128
160
|
function ujsAjaxSuccess(evt, data, status, xhr) {
|
129
|
-
hideThrobber(this);
|
130
|
-
var disableElement = $(this);
|
131
|
-
if ($(this).is('form'))
|
132
|
-
disableElement = $('button, input[type=submit]', this).first();
|
133
|
-
disableElement.attr('disabled', false);
|
134
161
|
var element = $(this);
|
162
|
+
if (element.data('real-element')) {
|
163
|
+
element = $('#' + element.data('real-element'));
|
164
|
+
}
|
165
|
+
hideThrobber(element);
|
166
|
+
var disableElement = element;
|
167
|
+
if (element.is('form'))
|
168
|
+
disableElement = $('button, input[type=submit]', element).first();
|
169
|
+
disableElement.attr('disabled', false);
|
135
170
|
var targetElement = element;
|
136
171
|
// if this was sent from a dialog, close the dialog and look at the
|
137
172
|
// element that opened it for update/append/delete callbacks.
|
@@ -164,7 +199,7 @@
|
|
164
199
|
target.trigger('jqr.load');
|
165
200
|
break;
|
166
201
|
case 'delete':
|
167
|
-
target.remove();
|
202
|
+
target.fadeOut(500, function() {$(this).remove()});
|
168
203
|
break;
|
169
204
|
}
|
170
205
|
target.effect('highlight');
|
@@ -207,6 +242,7 @@
|
|
207
242
|
var options = $(this).data('date-options');
|
208
243
|
$(this).datepicker(options);
|
209
244
|
});
|
245
|
+
|
210
246
|
$('.ujs-button-set', event.target).each(function() {
|
211
247
|
$(this).buttonset();
|
212
248
|
});
|
@@ -237,6 +273,7 @@
|
|
237
273
|
$(document).on('click', '.ujs-dialog', ujsDialogClick);
|
238
274
|
$(document).on('click', '.ujs-dialog-close, .ujs-dialog-x',
|
239
275
|
ujsDialogCloseClick);
|
276
|
+
$(document).on('click', '.ujs-ajax-button', ujsButtonClick);
|
240
277
|
$(document).on('ajax:beforeSend', '.ujs-ajax', ujsAjaxBeforeSend);
|
241
278
|
$(document).on('ajax:success', '.ujs-ajax', ujsAjaxSuccess);
|
242
279
|
$(document).on('ajax:error', '.ujs-ajax', ujsAjaxError);
|
@@ -246,6 +283,7 @@
|
|
246
283
|
$('body').live('jqr.load', ujsLoadPlugins);
|
247
284
|
$('.ujs-dialog').live('click', ujsDialogClick);
|
248
285
|
$('.ujs-dialog-close, .ujs-dialog-x').live('click', ujsDialogCloseClick);
|
286
|
+
$('.ujs-ajax-button').live('click', ujsButtonClick);
|
249
287
|
$('.ujs-ajax').live('ajax:beforeSend', ujsAjaxBeforeSend);
|
250
288
|
$('.ujs-ajax').live('ajax:success', ujsAjaxSuccess);
|
251
289
|
$('.ujs-ajax').live('ajax:error', ujsAjaxError);
|
data/jqr-helpers.gemspec
CHANGED
data/lib/jqr-helpers/helpers.rb
CHANGED
@@ -176,19 +176,25 @@ module JqrHelpers
|
|
176
176
|
link_to body, url, options
|
177
177
|
end
|
178
178
|
|
179
|
-
# Create a button that fires off a jQuery Ajax request. This
|
180
|
-
#
|
179
|
+
# Create a button that fires off a jQuery Ajax request. This does not use
|
180
|
+
# button_to, so it can be used inside forms.
|
181
181
|
# @param body [String] the text/content that goes inside the tag.
|
182
182
|
# @param url [String] the URL to connect to.
|
183
183
|
# @param options [Hash] Ajax options - see above.
|
184
184
|
# @return [String]
|
185
185
|
def button_to_ajax(body, url, options={})
|
186
186
|
|
187
|
-
|
188
|
-
options[:
|
189
|
-
options[:
|
187
|
+
# Specifically do not add data-remote
|
188
|
+
options[:'data-method'] = options.delete(:method)
|
189
|
+
options[:'class'] ||= ''
|
190
|
+
options[:'class'] << ' ujs-ajax-button'
|
191
|
+
options[:'data-url'] = url
|
192
|
+
if options.key?(:confirm)
|
193
|
+
options[:'data-confirm'] = options.delete(:confirm)
|
194
|
+
end
|
195
|
+
options.merge!(_process_ajax_options(options))
|
190
196
|
|
191
|
-
|
197
|
+
content_tag :button, body, options
|
192
198
|
end
|
193
199
|
|
194
200
|
# Create a form tag that submits to an Ajax request. Basically a wrapper for
|
data/lib/jqr-helpers/version.rb
CHANGED