thin_man 0.0.1
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +32 -0
- data/app/assets/javascripts/ajax_bindings.js +503 -0
- data/lib/tasks/thin_man_tasks.rake +4 -0
- data/lib/thin_man.rb +10 -0
- data/lib/thin_man/ajax_helper.rb +24 -0
- data/lib/thin_man/railtie.rb +8 -0
- data/lib/thin_man/version.rb +3 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/test_helper.rb +16 -0
- data/test/thin_man_test.rb +7 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9330e34fea5d4a337e32a6873f0745455de96981
|
4
|
+
data.tar.gz: b0ce857997952fbfc05049d0454e9f1ec197f7ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35fc8023dcb75972e3cd363a6275d4b0a0c4867419a9b95799d3f01a3ff16c276752f902d4953f3309f6d5eb264a69daf8c4103b84860e353741e461e63fccaf
|
7
|
+
data.tar.gz: d36eeced14cc004864cef85c36b983b16749f3b6e416c4ca139e25403544aa072d79252d3a63b7b7aeea01aa1eecf1a46b85be0f30e153ec477c9e0b7a4532cb
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'ThinMan'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,503 @@
|
|
1
|
+
//ThinMan javascript
|
2
|
+
function getSubClass(sub_class_name,parent_class){
|
3
|
+
if((typeof(sub_class_name) == 'string') && (sub_class_name != '') && (sub_class_name != 'true')){
|
4
|
+
var this_class = sub_class_name;
|
5
|
+
} else {
|
6
|
+
var this_class = parent_class;
|
7
|
+
}
|
8
|
+
return this_class;
|
9
|
+
};
|
10
|
+
|
11
|
+
// This is a utility to convert a javascript object to a query string and append it to a url.
|
12
|
+
function toUrlParams(params){
|
13
|
+
var params_array = [];
|
14
|
+
$.each(params, function(key,value){
|
15
|
+
params_array.push([key,value].join('='));
|
16
|
+
});
|
17
|
+
return params_array.join('&');
|
18
|
+
};
|
19
|
+
|
20
|
+
function addUrlParams(url,params){
|
21
|
+
if(url.match(/\?/)){
|
22
|
+
url = url + '&' + toUrlParams(params);
|
23
|
+
} else {
|
24
|
+
url = url + '?' + toUrlParams(params);
|
25
|
+
}
|
26
|
+
return url;
|
27
|
+
};
|
28
|
+
|
29
|
+
var AjaxSubmission = Class.extend({
|
30
|
+
init: function(jq_obj){
|
31
|
+
this.jq_obj = jq_obj;
|
32
|
+
this.getTrigger();
|
33
|
+
this.getTarget();
|
34
|
+
this.getErrorTarget();
|
35
|
+
this.insert_method = this.getInsertMethod();
|
36
|
+
var ajax_submission = this;
|
37
|
+
this.ajax_options = {
|
38
|
+
url: ajax_submission.getAjaxUrl(),
|
39
|
+
type: ajax_submission.getAjaxType(),
|
40
|
+
datatype: ajax_submission.getAjaxDataType(),
|
41
|
+
data: ajax_submission.getData(),
|
42
|
+
beforeSend: function(jqXHr) { return ajax_submission.ajaxBefore(jqXHr) },
|
43
|
+
success: function(data,textStatus,jqXHR) { ajax_submission.ajaxSuccess(data,textStatus,jqXHR) },
|
44
|
+
error: function(jqXHr) { ajax_submission.ajaxError(jqXHr) },
|
45
|
+
complete: function(jqXHr) { ajax_submission.ajaxComplete(jqXHr) }
|
46
|
+
};
|
47
|
+
$.ajax(ajax_submission.ajax_options);
|
48
|
+
},
|
49
|
+
getTarget: function(){
|
50
|
+
var target_selector = this.jq_obj.data('ajax-target');
|
51
|
+
if(target_selector){
|
52
|
+
this.target = $(target_selector);
|
53
|
+
}
|
54
|
+
},
|
55
|
+
getErrorTarget: function(){
|
56
|
+
if($(this.jq_obj.data('error_target')).length > 0){
|
57
|
+
this.error_target = $(this.jq_obj.data('error-target'));
|
58
|
+
}else{
|
59
|
+
this.error_target = $(this.jq_obj.data('ajax-target'));
|
60
|
+
}
|
61
|
+
},
|
62
|
+
getAjaxDataType: function(){
|
63
|
+
return this.jq_obj.data('return-type') || 'html';
|
64
|
+
},
|
65
|
+
getInsertMethod: function(){
|
66
|
+
return this.jq_obj.data('insert-method') || 'html';
|
67
|
+
},
|
68
|
+
getData: function() {
|
69
|
+
return null;
|
70
|
+
},
|
71
|
+
insertHtml: function(data) {
|
72
|
+
if(this.target){
|
73
|
+
this.target[this.insert_method](data);
|
74
|
+
}
|
75
|
+
},
|
76
|
+
ajaxSuccess: function(data,textStatus,jqXHR){
|
77
|
+
if(typeof data === 'string'){
|
78
|
+
this.insertHtml(data);
|
79
|
+
}
|
80
|
+
else if(typeof data === 'object'){
|
81
|
+
if(typeof data.html != 'undefined'){
|
82
|
+
this.insertHtml(data.html)
|
83
|
+
}
|
84
|
+
if(typeof data.class_triggers != 'undefined'){
|
85
|
+
$.each(data.class_triggers, function(class_name, params){
|
86
|
+
try{
|
87
|
+
klass = eval(class_name);
|
88
|
+
new klass(params);
|
89
|
+
} catch(err) {
|
90
|
+
console.log("Error trying to instantiate class " + class_name + " from ajax response:")
|
91
|
+
console.log(err)
|
92
|
+
}
|
93
|
+
})
|
94
|
+
}
|
95
|
+
if(typeof data.function_calls != 'undefined'){
|
96
|
+
$.each(data.function_calls, function(func_name, params){
|
97
|
+
try{
|
98
|
+
func = eval(func_name);
|
99
|
+
func(params);
|
100
|
+
} catch(err) {
|
101
|
+
console.log("Error trying to instantiate function " + func_name + " from ajax response:")
|
102
|
+
console.log(err)
|
103
|
+
}
|
104
|
+
})
|
105
|
+
}
|
106
|
+
}
|
107
|
+
var ajax_flash = this.target.children().last().data('ajax-flash');
|
108
|
+
if((jqXHR.status == 200) && ajax_flash){
|
109
|
+
new AjaxFlash('success', ajax_flash.notice,this.target);
|
110
|
+
}
|
111
|
+
if ((jqXHR.status == 200) && !(typeof step === 'undefined')) {
|
112
|
+
$(form_map[step]).ScrollTo();
|
113
|
+
}
|
114
|
+
},
|
115
|
+
ajaxComplete: function(jqXHr) {
|
116
|
+
this.showTrigger();
|
117
|
+
if(this.progress_indicator){
|
118
|
+
this.progress_indicator.stop();
|
119
|
+
}
|
120
|
+
},
|
121
|
+
ajaxBefore: function(jqXHr) {
|
122
|
+
this.toggleLoading();
|
123
|
+
this.progress_indicator = new AjaxProgress(this.trigger);
|
124
|
+
},
|
125
|
+
ajaxError: function(jqXHR) {
|
126
|
+
if(jqXHR.status == 409){
|
127
|
+
this.error_target.html(jqXHR.responseText);
|
128
|
+
}else{
|
129
|
+
alert('There was an error communicating with the server.')
|
130
|
+
}
|
131
|
+
},
|
132
|
+
getTrigger: function(){},
|
133
|
+
hideTrigger: function(){},
|
134
|
+
showTrigger: function(){},
|
135
|
+
toggleLoading: function() {
|
136
|
+
if(this.target){
|
137
|
+
if (this.target.find('[data-loading-visible="false"]').length > 0) {
|
138
|
+
this.target.find('[data-loading-visible="false"]').addClass('hidden');
|
139
|
+
}
|
140
|
+
if (this.target.find('[data-loading-visible="true"]').length > 0) {
|
141
|
+
this.target.find('[data-loading-visible="true"]').removeClass('hidden');
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}
|
145
|
+
});
|
146
|
+
|
147
|
+
var AjaxBrowserPushConnector = Class.extend({
|
148
|
+
init: function($connector){
|
149
|
+
this.trigger = $connector.find('button, input[type="submit"]');
|
150
|
+
if(this.trigger.length < 1){
|
151
|
+
this.trigger = $connector;
|
152
|
+
}
|
153
|
+
this.browser_push_progress_indicator = new AjaxProgress(this.trigger);
|
154
|
+
$connector.data('browser-push-progress-indicator-object', this.browser_push_progress_indicator);
|
155
|
+
}
|
156
|
+
});
|
157
|
+
var AjaxBrowserPushFlash = Class.extend({
|
158
|
+
init: function($flash){
|
159
|
+
this.message = $flash.data('ajax-browser-push-flash')
|
160
|
+
this.$target = $($flash.data('ajax-browser-push-flash-target'));
|
161
|
+
this.$target.data('ajax-browser-push-flash',this.message);
|
162
|
+
console.log("AjaxBrowserPushFlash: ")
|
163
|
+
console.log(this.message)
|
164
|
+
console.log(this.$target.data());
|
165
|
+
}
|
166
|
+
});
|
167
|
+
var AjaxProgress = Class.extend({
|
168
|
+
init: function(target){
|
169
|
+
if(target.not(':visible')){
|
170
|
+
var targetOffset = target.parent().offset();
|
171
|
+
} else {
|
172
|
+
var targetOffset = target.offset();
|
173
|
+
}
|
174
|
+
if(targetOffset){
|
175
|
+
var targetLeft = targetOffset.left;
|
176
|
+
var targetTop = targetOffset.top;
|
177
|
+
this.progress_container = $('#ajax_progress_container').clone();
|
178
|
+
uuid = new UUID;
|
179
|
+
this.progress_container.prop('id', uuid.value);
|
180
|
+
$('body').append(this.progress_container);
|
181
|
+
this.progress_container.css({position:'absolute',left: targetLeft, top: targetTop});
|
182
|
+
this.progress_container.show();
|
183
|
+
}
|
184
|
+
},
|
185
|
+
stop: function(){
|
186
|
+
if(this.progress_container){
|
187
|
+
this.progress_container.remove();
|
188
|
+
// This is a hack to force finding the element. For some ridiculous reason in certain cases
|
189
|
+
// the progress_container is present, can be logged in console, yet cannot be removed.
|
190
|
+
// Finding it again by its unique id allows us to remove it. baffled me, but it works now in all known cases.
|
191
|
+
$actual_progress_container = $('#' + this.progress_container.attr('id'))
|
192
|
+
$actual_progress_container.remove();
|
193
|
+
}
|
194
|
+
}
|
195
|
+
});
|
196
|
+
var AjaxFlash = Class.extend({
|
197
|
+
init: function(type,message,elem){
|
198
|
+
this.flash_container = $('#ajax_flash_container').clone();
|
199
|
+
$('body').append(this.flash_container);
|
200
|
+
this.flash_container.css({position:'absolute',visibility: 'hidden'});
|
201
|
+
var alert_class = 'alert-' + type;
|
202
|
+
this.flash_container.addClass(alert_class);
|
203
|
+
$('#ajax_flash_content', this.flash_container).html(message);
|
204
|
+
this.flash_container.show();
|
205
|
+
this.reposition(elem);
|
206
|
+
},
|
207
|
+
reposition: function(elem){
|
208
|
+
var this_window = {
|
209
|
+
top: $(window).scrollTop(),
|
210
|
+
left: $(window).scrollLeft(),
|
211
|
+
height: $(window).outerHeight(),
|
212
|
+
width: $(window).outerWidth()
|
213
|
+
};
|
214
|
+
var this_flash = {
|
215
|
+
height: this.flash_container.outerHeight(),
|
216
|
+
width: this.flash_container.outerWidth()
|
217
|
+
}
|
218
|
+
this_window.vert_middle = (this_window.top + (this_window.height / 2));
|
219
|
+
this_window.horiz_middle = (this_window.left + (this_window.width / 2));
|
220
|
+
this_flash.half_height = (this_flash.height / 2);
|
221
|
+
this_flash.half_width = (this_flash.width / 2);
|
222
|
+
var new_top = this_window.vert_middle - this_flash.half_height;
|
223
|
+
var new_left = this_window.horiz_middle - this_flash.half_width;
|
224
|
+
this.flash_container.css({left: new_left, top: new_top, visibility: 'visible'});
|
225
|
+
var ajax_flash = this;
|
226
|
+
if (! $('form', elem).data('ajax-flash-persist')) {
|
227
|
+
setTimeout(function(){ajax_flash.fadeOut()},1000);
|
228
|
+
}
|
229
|
+
},
|
230
|
+
fadeOut: function(){
|
231
|
+
this.flash_container.fadeOut('slow');
|
232
|
+
}
|
233
|
+
});
|
234
|
+
|
235
|
+
var AjaxFormSubmission = AjaxSubmission.extend({
|
236
|
+
getAjaxUrl: function(){
|
237
|
+
return this.jq_obj.attr('action');
|
238
|
+
},
|
239
|
+
getAjaxType: function(){
|
240
|
+
return this.jq_obj.attr('method') || 'POST'
|
241
|
+
},
|
242
|
+
getData: function(){
|
243
|
+
var data_array = this.jq_obj.serializeArray();
|
244
|
+
return data_array;
|
245
|
+
},
|
246
|
+
getTrigger: function(){
|
247
|
+
this.trigger = this.jq_obj.find('button, input[type="submit"]');
|
248
|
+
},
|
249
|
+
hideTrigger: function(){
|
250
|
+
this.trigger.css('visibility','hidden');
|
251
|
+
},
|
252
|
+
showTrigger: function(){
|
253
|
+
this.trigger.css('visibility','visible');
|
254
|
+
}
|
255
|
+
});
|
256
|
+
|
257
|
+
var AjaxLinkSubmission = AjaxSubmission.extend({
|
258
|
+
getAjaxUrl: function(){
|
259
|
+
return this.jq_obj.attr('href');
|
260
|
+
},
|
261
|
+
getData: function(){
|
262
|
+
var this_data = {authenticity_token: $('[name="csrf-token"]').attr('content')};
|
263
|
+
if(this.jq_obj.data('form-data')){
|
264
|
+
$.extend(this_data,this.jq_obj.data('form-data'))
|
265
|
+
}
|
266
|
+
return this_data
|
267
|
+
},
|
268
|
+
getAjaxType: function(){
|
269
|
+
return this.jq_obj.data('method') || 'GET'
|
270
|
+
},
|
271
|
+
getTrigger: function(){
|
272
|
+
this.trigger = this.jq_obj;
|
273
|
+
},
|
274
|
+
hideTrigger: function(){
|
275
|
+
this.trigger.css('visibility','hidden');
|
276
|
+
},
|
277
|
+
showTrigger: function(){
|
278
|
+
this.trigger.css('visibility','visible');
|
279
|
+
}
|
280
|
+
});
|
281
|
+
|
282
|
+
var AjaxModalOpener = AjaxLinkSubmission.extend({
|
283
|
+
ajaxSuccess: function(data,textStatus,jqXHR) {
|
284
|
+
this._super(data,textStatus,jqXHR);
|
285
|
+
$(this.jq_obj.data('ajax-modal')).modal();
|
286
|
+
}
|
287
|
+
});
|
288
|
+
|
289
|
+
var AddALineForm = AjaxFormSubmission.extend({
|
290
|
+
ajaxSuccess: function(data,textStatus,jqXHR) {
|
291
|
+
this._super(data,textStatus,jqXHR);
|
292
|
+
$(this.jq_obj.data('container')).empty();
|
293
|
+
},
|
294
|
+
ajaxError: function(jqXHR){
|
295
|
+
this.insert_method = 'html';
|
296
|
+
this._super(jqXHR);
|
297
|
+
}
|
298
|
+
});
|
299
|
+
|
300
|
+
var EmptyForm = AjaxFormSubmission.extend({
|
301
|
+
ajaxSuccess: function(data,textStatus,jqXHR) {
|
302
|
+
var clicked_button = $("input[type=submit][clicked=true]")[0];
|
303
|
+
this._super(data,textStatus,jqXHR);
|
304
|
+
if ($(clicked_button).data('clone') != true) {
|
305
|
+
$(this.jq_obj)[0].reset();
|
306
|
+
};
|
307
|
+
$(this.jq_obj).find('input[type=text],textarea,select').filter(':visible:first').focus();
|
308
|
+
$("[data-autocomplete]").trigger("chosen:updated");
|
309
|
+
},
|
310
|
+
ajaxError: function(jqXHR){
|
311
|
+
this.insert_method = 'html';
|
312
|
+
this._super(jqXHR);
|
313
|
+
}
|
314
|
+
});
|
315
|
+
|
316
|
+
var ModalCloserForm = AjaxFormSubmission.extend({
|
317
|
+
ajaxSuccess: function(data,textStatus,jqXHR) {
|
318
|
+
this._super(data,textStatus,jqXHR);
|
319
|
+
$modal = $(this.jq_obj.data('modal-container'));
|
320
|
+
$modal.modal('hide');
|
321
|
+
$modal.remove();
|
322
|
+
},
|
323
|
+
ajaxError: function(jqXHR){
|
324
|
+
this._super(jqXHR);
|
325
|
+
$modal = $(this.jq_obj.data('modal-container'));
|
326
|
+
$modal.modal();
|
327
|
+
}
|
328
|
+
});
|
329
|
+
|
330
|
+
var ResetOnSubmitForm = AjaxFormSubmission.extend({
|
331
|
+
ajaxSuccess: function(data, textStatus, jqXHR) {
|
332
|
+
this._super(data, textStatus, jqXHR);
|
333
|
+
$(this.jq_obj).each(function() {
|
334
|
+
this.reset();
|
335
|
+
});
|
336
|
+
}
|
337
|
+
});
|
338
|
+
|
339
|
+
var DeleteLink = AjaxSubmission.extend({
|
340
|
+
ajaxSuccess: function(data,textStatus,jqXHR){
|
341
|
+
this._super(data,textStatus,jqXHR);
|
342
|
+
this.target.remove();
|
343
|
+
},
|
344
|
+
getAjaxType: function(){
|
345
|
+
return 'DELETE';
|
346
|
+
},
|
347
|
+
getAjaxUrl: function(){
|
348
|
+
return this.jq_obj.attr('href');
|
349
|
+
},
|
350
|
+
getData: function(){
|
351
|
+
return {authenticity_token: $('[name="csrf-token"]').attr('content')};
|
352
|
+
},
|
353
|
+
ajaxBefore: function(jqXHR){
|
354
|
+
return confirm("Are you sure you want to delete this?");
|
355
|
+
}
|
356
|
+
});
|
357
|
+
|
358
|
+
var AjaxSortSubmission = AjaxLinkSubmission.extend({
|
359
|
+
getAjaxUrl: function(){
|
360
|
+
return this._super() + '?' + this.jq_obj.sortable("serialize");
|
361
|
+
},
|
362
|
+
getAjaxType: function(){
|
363
|
+
return 'PUT';
|
364
|
+
},
|
365
|
+
ajaxSuccess: function(){
|
366
|
+
|
367
|
+
}
|
368
|
+
});
|
369
|
+
|
370
|
+
var AjaxSorter = Class.extend({
|
371
|
+
init: function(jq_obj){
|
372
|
+
var sort_container = jq_obj;
|
373
|
+
var base_url = sort_container.data('url');
|
374
|
+
sort_container.sortable({
|
375
|
+
helper: "clone",
|
376
|
+
tolerance: 'pointer',
|
377
|
+
stop: function( event, ui) {
|
378
|
+
new AjaxSortSubmission(sort_container);
|
379
|
+
}
|
380
|
+
});
|
381
|
+
jq_obj.disableSelection();
|
382
|
+
}
|
383
|
+
});
|
384
|
+
|
385
|
+
|
386
|
+
var AjaxPushState = Class.extend({
|
387
|
+
init: function(obj) {
|
388
|
+
if (obj.data('push-state') != null && obj.data('push-state') != "") {
|
389
|
+
history.pushState(null, null, obj.data('push-state'));
|
390
|
+
}
|
391
|
+
}
|
392
|
+
});
|
393
|
+
|
394
|
+
var RadioFormGroup = Class.extend({
|
395
|
+
init: function($form_group){
|
396
|
+
this.$form_group = $form_group;
|
397
|
+
$form_group.data('form-group', this);
|
398
|
+
},
|
399
|
+
closeForm: function(){
|
400
|
+
this.cancel_button.cancel();
|
401
|
+
},
|
402
|
+
removeOpenForm: function(){
|
403
|
+
delete this.cancel_button;
|
404
|
+
}
|
405
|
+
});
|
406
|
+
|
407
|
+
var RadioEdit = Class.extend({
|
408
|
+
init: function($radio_edit){
|
409
|
+
$radio_edit.data('radio-edit-loaded',true);
|
410
|
+
this.$radio_edit = $radio_edit;
|
411
|
+
this.$go_link = $($radio_edit.data('radio-edit'));
|
412
|
+
var radio_edit = this;
|
413
|
+
$radio_edit.bind('click',function(e){
|
414
|
+
e.preventDefault();
|
415
|
+
radio_edit.tryEdit();
|
416
|
+
return false;
|
417
|
+
})
|
418
|
+
},
|
419
|
+
tryEdit: function(){
|
420
|
+
if(confirm("Any incomplete changes on other forms will be lost, are you sure you want to open this form?")){
|
421
|
+
this.form_group.closeForm();
|
422
|
+
step = this.$go_link.data('step-link') - 1;
|
423
|
+
this.$go_link.click();
|
424
|
+
}
|
425
|
+
},
|
426
|
+
findGroup: function(){
|
427
|
+
$form_group = this.$radio_edit.parents('[data-radio-form-group]')
|
428
|
+
this.form_group = $form_group.data('form-group');
|
429
|
+
}
|
430
|
+
});
|
431
|
+
|
432
|
+
var RadioCancel = Class.extend({
|
433
|
+
init: function($radio_cancel){
|
434
|
+
this.$radio_cancel = $radio_cancel;
|
435
|
+
},
|
436
|
+
findGroup: function(){
|
437
|
+
$form_group = this.$radio_cancel.parents('[data-radio-form-group]')
|
438
|
+
this.form_group = $form_group.data('form-group');
|
439
|
+
this.form_group.cancel_button = this;
|
440
|
+
},
|
441
|
+
cancel: function(){
|
442
|
+
this.$radio_cancel.click();
|
443
|
+
}
|
444
|
+
});
|
445
|
+
|
446
|
+
$(document).ready(function(){
|
447
|
+
$(document).on('click','[data-ajax-link]',function(e){
|
448
|
+
e.preventDefault();
|
449
|
+
var this_class = eval(getSubClass($(this).data('sub-type'),'AjaxLinkSubmission'));
|
450
|
+
var submission = new this_class($(this));
|
451
|
+
return false;
|
452
|
+
});
|
453
|
+
|
454
|
+
$(document).on('submit','[data-ajax-form]',function(e){
|
455
|
+
e.preventDefault();
|
456
|
+
var this_class = eval(getSubClass($(this).data('sub-type'),'AjaxFormSubmission'));
|
457
|
+
var submission = new this_class($(this));
|
458
|
+
return false;
|
459
|
+
});
|
460
|
+
|
461
|
+
$(document).on('click','[data-ajax-delete]',function(e){
|
462
|
+
e.preventDefault();
|
463
|
+
var this_class = eval(getSubClass($(this).data('sub-type'),'DeleteLink'));
|
464
|
+
var deletion = new this_class($(this));
|
465
|
+
});
|
466
|
+
|
467
|
+
$(document).on('click','form input[type=submit]',function(e){
|
468
|
+
$("input[type=submit]", $(this).parents("form")).removeAttr("clicked");
|
469
|
+
$(this).attr("clicked", "true");
|
470
|
+
});
|
471
|
+
|
472
|
+
$('[data-sortable]').each(function(){
|
473
|
+
new AjaxSorter($(this));
|
474
|
+
});
|
475
|
+
|
476
|
+
$('[data-radio-form-group]').each(function(){
|
477
|
+
new RadioFormGroup($(this));
|
478
|
+
})
|
479
|
+
});
|
480
|
+
$(document).ready(function(){
|
481
|
+
$('[data-radio-edit]').each(function(){
|
482
|
+
if(!($(this).data('radio-edit-loaded'))){
|
483
|
+
var radio_edit = new RadioEdit($(this))
|
484
|
+
radio_edit.findGroup();
|
485
|
+
}
|
486
|
+
});
|
487
|
+
$('[data-radio-cancel]').each(function(){
|
488
|
+
var radio_cancel = new RadioCancel($(this))
|
489
|
+
radio_cancel.findGroup();
|
490
|
+
});
|
491
|
+
});
|
492
|
+
$(document).ajaxComplete(function(){
|
493
|
+
$('[data-radio-edit]').each(function(){
|
494
|
+
if(!($(this).data('radio-edit-loaded'))){
|
495
|
+
var radio_edit = new RadioEdit($(this))
|
496
|
+
radio_edit.findGroup();
|
497
|
+
}
|
498
|
+
});
|
499
|
+
$('[data-radio-cancel]').each(function(){
|
500
|
+
var radio_cancel = new RadioCancel($(this))
|
501
|
+
radio_cancel.findGroup();
|
502
|
+
});
|
503
|
+
});
|