thin_man 0.19.5 → 0.19.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b584855bc4063c49c203b7757b4df16f9ba6f226
4
- data.tar.gz: f81f2377a8ffdb2bc70e062df83fec105d4bf055
3
+ metadata.gz: 4f0e4ee879650cc8ce1501b4b0b6cfe7eb2a0122
4
+ data.tar.gz: 8557f0bbb4c686bca8ad0b5592ba04a724a819d2
5
5
  SHA512:
6
- metadata.gz: 11d8e67f3d423700e98e9d0c7dcab9a51cb99ae79f672cabf253c91381e658227d9921e35ad94deabd23ba969c33d7c4e702e550882bbd36be84749a77d77af9
7
- data.tar.gz: 642fb8905c8ee5976ec61185df6d511ffc23bb462a53cf66f3689e174d18c68f6d19f3929bb592debbdb7c881f19fe82e32e052c1d01ac8cf52772311a0960a9
6
+ metadata.gz: 784e88c488f0970552f3109320801653b6e290310b6882009f0644f04171e9974ff75af5784c340daca59f8fb2b2815aa885b8f73d8f3adf7c87af81919903c1
7
+ data.tar.gz: f9313528484b9c26654fa634e4e072dab2c722f4b707dcc20e1987c32ce2fa41525725fe6224208975f01472cc15513ab2ac883dc91c9e8c4b2d3c139c95be25
@@ -1,967 +1,973 @@
1
1
  //= require simple_inheritance
2
2
  //= require debug_logger
3
- var initThinMan = function(){
4
- thin_man = {
5
- getSubClass: function(sub_class_name,parent_class){
6
- if((typeof(sub_class_name) == 'string') && (sub_class_name != '') && (sub_class_name != 'true')){
7
- var this_class = sub_class_name;
8
- } else {
9
- var this_class = parent_class;
10
- }
11
- return this_class;
12
- },
13
- getLinkGroup: function(name){
14
- if(thin_man.hasOwnProperty('link_groups') && thin_man.link_groups.hasOwnProperty(name)){
15
- return thin_man.link_groups[name]
16
- } else {
17
- return thin_man.addLinkGroup(name)
18
- }
19
- },
20
- addLinkGroup: function(name){
21
- if(!thin_man.hasOwnProperty('link_groups')){
22
- thin_man.link_groups = {}
23
- }
24
- if(!thin_man.link_groups.hasOwnProperty(name)){
25
- var this_group = new thin_man.LinkGroup(name)
26
- thin_man.link_groups[name] = this_group
27
- return this_group
28
- }
29
- },
30
- addLinkToGroup: function(link, sequence_number, group_name){
31
- var group = thin_man.getLinkGroup(group_name)
32
- group.addLink(link,sequence_number)
33
- },
34
- LinkGroup: Class.extend({
35
- init: function(name){
36
- this.name = name
37
- this.resetLinks()
38
- },
39
- resetLinks: function(){
40
- this.links = {}
41
- this.current_number = 0
42
- },
43
- addLink: function(link_submission, sequence_number){
44
- if(this.links.hasOwnProperty(sequence_number)){
45
- //If there is already a link with this number, we're starting over with a new list
46
- this.resetLinks()
47
- }
48
- this.links[sequence_number] = link_submission
49
- link_submission.addWatcher(this)
50
- if(sequence_number == this.current_number){
51
- this.fire()
52
- }
53
- },
54
- fire: function(){
55
- if(this.links.hasOwnProperty(this.current_number)){
56
- this.links[this.current_number].fire()
57
- }
58
- },
59
- linkCompleted: function(link_submission){
60
- this.current_number += 1
61
- this.fire()
62
- }
63
- }),
64
- AjaxSubmission: Class.extend({
65
- init: function(jq_obj,params){
66
- this.jq_obj = jq_obj
67
- this.params = params
68
- if(!this.params){ this.params = {}}
69
- // Bail out if this is a no-mouse-click ajax element and we were mouse clicked
70
- if(this.wasMouseClicked() && this.noMouseClick()){
71
- return false
72
- }
73
- this.getTrigger()
74
- this.getTarget()
75
- this.getErrorTarget()
76
- this.progress_color = jq_obj.data('progress-color')
77
- this.progress_target = $(jq_obj.data('progress-target'))
78
- this.$mask_target = $(jq_obj.data('mask-target'))
79
- this.$mask_message = jq_obj.data('mask-message')
80
- this.custom_progress = typeof(jq_obj.data('custom-progress')) != 'undefined';
81
- this.scroll_to = jq_obj.data('scroll-to')
82
- this.watchers = []
83
- if(this.progress_target.length == 0 && this.trigger.length > 0){
84
- this.progress_target = this.trigger
85
- this.trigger_is_progress_target = true
86
- }
87
- this.insert_method = this.getInsertMethod()
88
- var ajax_submission = this
89
- this.ajax_options = {
90
- url: ajax_submission.getAjaxUrl(),
91
- type: ajax_submission.getAjaxType(),
92
- datatype: ajax_submission.getAjaxDataType(),
93
- data: ajax_submission.getData(),
94
- beforeSend: function(jqXHr) { return ajax_submission.ajaxBefore(jqXHr) },
95
- success: function(data,textStatus,jqXHR) { ajax_submission.ajaxSuccess(data,textStatus,jqXHR) },
96
- error: function(jqXHr) { ajax_submission.ajaxError(jqXHr) },
97
- complete: function(jqXHr) { ajax_submission.ajaxComplete(jqXHr) },
98
- processData: ajax_submission.getProcessData()
99
- };
100
- if(!this.sendContentType()){
101
- this.ajax_options.contentType = false
102
- };
103
- if(typeof this.customXHR === 'function'){
104
- this.ajax_options.xhr = this.customXHR
105
- this.ajax_options.thin_man_obj = this;
106
- }
107
- this.handleGroup()
108
- if(this.readyToFire()){
109
- this.fire()
110
- }
111
- },
112
- fire: function(){
113
- $.ajax(this.ajax_options);
114
- },
115
- readyToFire: function(){
116
- if(!this.sequence_group){ return true }
117
- },
118
- handleGroup: function(){
119
- this.sequence_group = this.jq_obj.data('sequence-group');
120
- this.sequence_number = this.jq_obj.data('sequence-number');
121
- if(typeof(this.sequence_number) == 'number' && !this.sequence_group){
122
- console.log('Warning! Thin Man Link has sequence number but no sequence group.')
123
- }
124
- if(this.sequence_group && typeof(this.sequence_number) != 'number'){
125
- console.log('Warning! Thin Man Link has sequence group ' + this.sequence_group + ' but no sequence number.')
126
- }
127
- if(this.sequence_group){
128
- thin_man.addLinkToGroup(this, this.sequence_number, this.sequence_group)
129
- }
130
- },
131
- getTarget: function(){
132
- var target_selector = this.jq_obj.data('ajax-target');
133
- if(target_selector){
134
- if($(target_selector).length > 0){
135
- this.target = $(target_selector);
136
- }else{
137
- console.log('Warning! Thin Man selector ' + target_selector + ' not found')
138
- }
139
- }else{
140
- console.log('Warning! Thin Man selector not given')
141
- }
142
- },
143
- getErrorTarget: function(){
144
- if($(this.jq_obj.data('error-target')).length > 0){
145
- this.error_target = $(this.jq_obj.data('error-target'));
146
- }else{
147
- this.error_target = $(this.jq_obj.data('ajax-target'));
148
- }
149
- },
150
- getAjaxDataType: function(){
151
- return this.jq_obj.data('return-type') || 'html';
152
- },
153
- getInsertMethod: function(){
154
- return this.jq_obj.data('insert-method') || 'html';
155
- },
156
- getData: function() {
157
- return null;
158
- },
159
- getProcessData: function() {
160
- return true;
161
- },
162
- sendContentType: function() {
163
- return true;
164
- },
165
- insertHtml: function(data) {
166
- debug_logger.log("thin_man.AjaxSubmission.insertHtml target:")
167
- debug_logger.log(this.target)
168
- debug_logger.log("thin_man.AjaxSubmission.insertHtml insert_method:")
169
- debug_logger.log(this.insert_method)
170
- if(this.target){
171
- this.target[this.insert_method](data);
172
- if(this.refocus()){
173
- this.target.find('input,select,textarea').filter(':visible:enabled:first').each(function(){
174
- if(!$(this).data('date-picker')){
175
- $(this).focus();
176
- }
177
- });
178
- }
179
- if(this.scroll_to){
180
- if(this.target.not(':visible')){
181
- if(this.target.parents('[data-tab-id]').length > 0){
182
- this.target.parents('[data-tab-id]').each(function(){
183
- var tab_key = $(this).data('tab-id')
184
- $('[data-tab-target-id="' + tab_key + '"]').trigger('click')
185
- })
186
- }
3
+ var initThinMan = function() {
4
+ thin_man = {
5
+ getSubClass: function(sub_class_name, parent_class) {
6
+ if ((typeof(sub_class_name) == 'string') && (sub_class_name != '') && (sub_class_name != 'true')) {
7
+ var this_class = sub_class_name;
8
+ } else {
9
+ var this_class = parent_class;
187
10
  }
188
- var extra_offset = 0
189
- if($('[data-thin-man-offset]').length > 0){
190
- extra_offset = $('[data-thin-man-offset]').outerHeight()
11
+ return this_class;
12
+ },
13
+ getLinkGroup: function(name) {
14
+ if (thin_man.hasOwnProperty('link_groups') && thin_man.link_groups.hasOwnProperty(name)) {
15
+ return thin_man.link_groups[name]
16
+ } else {
17
+ return thin_man.addLinkGroup(name)
191
18
  }
192
- $('html, body').animate({
193
- scrollTop: this.target.offset().top - extra_offset
194
- }, 1000);
195
- }
196
- }
197
- },
198
- refocus: function(){
199
- return true;
200
- },
201
- ajaxSuccess: function(data,textStatus,jqXHR){
202
- debug_logger.log("thin_man.AjaxSubmission.ajaxSuccess data:")
203
- debug_logger.log(data)
204
- if(typeof data === 'string'){
205
- this.insertHtml(data);
206
- } else if(typeof data === 'object') {
207
- if(typeof data.html != 'undefined'){
208
- if(typeof data.hooch_modal != 'undefined'){
209
- new hooch.Modal($(data.html))
210
- }else{
211
- this.insertHtml(data.html)
19
+ },
20
+ addLinkGroup: function(name) {
21
+ if (!thin_man.hasOwnProperty('link_groups')) {
22
+ thin_man.link_groups = {}
212
23
  }
213
- } else if(this.target && typeof(this.target.empty) == 'function') {
214
- this.target.empty()
215
- }
216
- if(typeof data.class_triggers != 'undefined'){
217
- $.each(data.class_triggers, function(class_name, params){
218
- try{
219
- klass = eval(class_name);
220
- new klass(params);
221
- } catch(err) {
222
- console.log("Error trying to instantiate class " + class_name + " from ajax response:")
223
- console.log(err)
224
- }
225
- })
226
- }
227
- if(typeof data.function_calls != 'undefined'){
228
- $.each(data.function_calls, function(func_name, params){
229
- try{
230
- func = eval(func_name);
231
- func(params);
232
- } catch(err) {
233
- console.log("Error trying to instantiate function " + func_name + " from ajax response:")
234
- console.log(err)
235
- }
236
- })
237
- }
238
- }
239
- if(this.target){
240
- var ajax_flash = this.target.children().last().data('ajax-flash');
241
- if((jqXHR.status == 200) && ajax_flash){
242
- new thin_man.AjaxFlash('success', ajax_flash.notice,this.target);
243
- }
244
- }
245
- if(this.removeOnSuccess()){
246
- if($(this.removeOnSuccess())){
247
- $(this.removeOnSuccess()).remove();
248
- }
249
- }
250
- if(this.emptyOnSuccess()){
251
- if($(this.emptyOnSuccess())){
252
- $(this.emptyOnSuccess()).empty();
253
- }
254
- }
255
- if ($.contains(document, this.jq_obj[0])) {
256
- this.jq_obj.find('.error').removeClass('error')
257
- this.jq_obj.find('.help-inline').remove()
258
- }
259
- },
260
- addWatcher: function(watcher){
261
- if(!this.hasOwnProperty('watchers')){
262
- this.watchers = []
263
- }
264
- this.watchers.push(watcher)
265
- },
266
- notifyWatchers: function(){
267
- $.each(this.watchers, function(){
268
- this.linkCompleted(this)
269
- })
270
- },
271
- ajaxComplete: function(jqXHR) {
272
- debug_logger.log('thin_man.AjaxSubmission.ajaxComplete jqXHR:')
273
- debug_logger.log(jqXHR)
274
- this.showTrigger();
275
- this.notifyWatchers();
276
- if(this.progress_indicator){
277
- this.progress_indicator.stop();
278
- } else if(!this.trigger_is_progress_target){
279
- this.progress_target.remove();
280
- }
281
- if(typeof this.mask != 'undefined'){
282
- this.mask.remove();
283
- }
284
- try{
285
- var response_data = JSON.parse(jqXHR.responseText)
286
- } catch(err) {
287
- var response_data = {}
288
- // hmmm, the response is not JSON, so there's no flash.
289
- }
290
- if(typeof response_data.flash_message != 'undefined'){
291
- var flash_style = this.httpResponseToFlashStyle(jqXHR.status);
292
- var flash_duration = null;
293
- if(typeof response_data.flash_persist != 'undefined'){
294
- if(response_data.flash_persist){
295
- flash_duration = 'persist'
296
- } else {
297
- flash_duration = 'fade'
24
+ if (!thin_man.link_groups.hasOwnProperty(name)) {
25
+ var this_group = new thin_man.LinkGroup(name)
26
+ thin_man.link_groups[name] = this_group
27
+ return this_group
298
28
  }
299
- }
300
- if(this.target){
301
- this.flash = new thin_man.AjaxFlash(flash_style, response_data.flash_message,this.target, flash_duration);
302
- }else{
303
- this.flash = new thin_man.AjaxFlash(flash_style, response_data.flash_message,this.jq_obj, flash_duration);
304
- }
305
- }
306
- if('function' == typeof this.params.on_complete){
307
- this.params.on_complete()
308
- }
309
- },
310
- ajaxBefore: function(jqXHr) {
311
- this.toggleLoading();
312
- if(!this.custom_progress){
313
- this.progress_indicator = new thin_man.AjaxProgress(this.progress_target,this.target,this.progress_color);
314
- }
315
- if(this.$mask_target){
316
- this.mask = new thin_man.AjaxMask(this.$mask_target,this.$mask_message)
317
- }
318
- },
319
- ajaxError: function( jqXHR ) {
320
- debug_logger.log('thin_man.AjaxSubmission.ajaxError jqXHR:')
321
- debug_logger.log(jqXHR)
322
- if(jqXHR.status == 409){
323
- try{
324
- var data = JSON.parse(jqXHR.responseText);
325
- debug_logger.log("thin_man.AjaxSubmission.ajaxError responseText is valid JSON, parsing to an object:")
326
- }catch(error){
327
- debug_logger.log("thin_man.AjaxSubmission.ajaxError responseText is not JSON, assuming a string:")
328
- debug_logger.log(jqXHR.responseText)
329
- var data = jqXHR.responseText;
330
- debug_logger.log("thin_man.AjaxSubmission.ajaxError data to insert:")
331
- debug_logger.log(data)
332
- }
333
- debug_logger.log("thin_man.AjaxSubmission.ajaxError error target:")
334
- debug_logger.log(this.error_target)
335
- debug_logger.log("thin_man.AjaxSubmission.ajaxError data:")
336
- debug_logger.log(data)
337
- if(typeof data === 'string'){
338
- debug_logger.log("thin_man.AjaxSubmission.ajaxError data is a string, inserting into target.")
339
- this.error_target.html(data);
340
- } else if(typeof data === 'object') {
341
- debug_logger.log("thin_man.AjaxSubmission.ajaxError data is an object.")
342
- if(typeof data.html != 'undefined'){
343
- debug_logger.log("thin_man.AjaxSubmission.ajaxError data.html exists, inserting into target.")
344
- this.error_target.html(data.html);
29
+ },
30
+ addLinkToGroup: function(link, sequence_number, group_name) {
31
+ var group = thin_man.getLinkGroup(group_name)
32
+ group.addLink(link, sequence_number)
33
+ },
34
+ LinkGroup: Class.extend({
35
+ init: function(name) {
36
+ this.name = name
37
+ this.resetLinks()
38
+ },
39
+ resetLinks: function() {
40
+ this.links = {}
41
+ this.current_number = 0
42
+ },
43
+ addLink: function(link_submission, sequence_number) {
44
+ if (this.links.hasOwnProperty(sequence_number)) {
45
+ //If there is already a link with this number, we're starting over with a new list
46
+ this.resetLinks()
47
+ }
48
+ this.links[sequence_number] = link_submission
49
+ link_submission.addWatcher(this)
50
+ if (sequence_number == this.current_number) {
51
+ this.fire()
52
+ }
53
+ },
54
+ fire: function() {
55
+ if (this.links.hasOwnProperty(this.current_number)) {
56
+ this.links[this.current_number].fire()
57
+ }
58
+ },
59
+ linkCompleted: function(link_submission) {
60
+ this.current_number += 1
61
+ this.fire()
345
62
  }
346
- }
347
- }else if(jqXHR.status == 500){
348
- alert('There was an error communicating with the server.')
349
- }
350
- },
351
- getTrigger: function(){},
352
- hideTrigger: function(){},
353
- showTrigger: function(){},
354
- toggleLoading: function() {
355
- if(this.target){
356
- if (this.target.find('[data-loading-visible="false"]').length > 0) {
357
- this.target.find('[data-loading-visible="false"]').hide();
358
- }
359
- if (this.target.find('[data-loading-visible="true"]').length > 0) {
360
- this.target.find('[data-loading-visible="true"]').show();
361
- }
362
- }
363
- },
364
- removeOnSuccess: function(){
365
- return this.jq_obj.data('remove-on-success')
366
- },
367
- emptyOnSuccess: function(){
368
- return this.jq_obj.data('empty-on-success')
369
- },
370
- httpResponseToFlashStyle: function(response_code){
371
- if([403,409,500].indexOf(response_code) > -1){
372
- return 'error'
373
- }
374
- if([200,202].indexOf(response_code) > -1){
375
- return 'success'
376
- }
377
- return 'error'
378
- },
379
- wasMouseClicked: function(){
380
- return this.params.e && this.params.e.type && this.params.e.type == 'click'
381
- },
382
- noMouseClick: function(){
383
- return this.jq_obj.data('no-mouse-click')
384
- }
385
- }),
386
- AjaxBrowserPushConnector: Class.extend({
387
- init: function($connector){
388
- this.trigger = $connector.find('button, input[type="submit"]');
389
- if(this.trigger.length < 1){
390
- this.trigger = $connector;
391
- }
392
- this.browser_push_progress_indicator = new thin_man.AjaxProgress(this.trigger,this.trigger,this.progress_color);
393
- $connector.data('browser-push-progress-indicator-object', this.browser_push_progress_indicator);
394
- }
395
- }),
396
- AjaxBrowserPushFlash: Class.extend({
397
- init: function($flash){
398
- this.message = $flash.data('ajax-browser-push-flash')
399
- this.$target = $($flash.data('ajax-browser-push-flash-target'));
400
- this.$target.data('ajax-browser-push-flash',this.message);
401
- }
402
- }),
403
- AjaxProgress: Class.extend({
404
- init: function(target,alt,progress_color){
405
- if(target.length > 0 && target.is(':visible') && target.css('display') != 'inline' && target.css('display') != 'inline-block'){
406
- this.progress_target = target;
407
- } else if(typeof(alt) != 'undefined' && alt.is(':visible')) {
408
- this.progress_target = alt;
409
- } else {
410
- this.progress_target = $('body');
411
- }
412
- if(typeof(progress_color) == 'undefined'){
413
- var progress_color = 'black';
414
- }
415
- this.progress_container = $('#ajax_progress_container').clone();
416
- var uuid = new UUID;
417
- this.progress_container.prop('id', 'thin_man_ajax_progress_' + uuid.value);
418
- this.progress_target.append(this.progress_container);
419
- var css = {display: 'block', visibility: 'visible','color': progress_color, 'z-index': 1000000}
420
- $.extend(css,
421
- {position: 'absolute', top: '50%', left: '50%',
422
- '-ms-transform': 'translate(-50%, -50%)', /* IE 9 */
423
- '-webkit-transform': 'translate(-50%, -50%)', /* Safari */
424
- 'transform': 'translate(-50%, -50%)'})
425
- this.progress_container.css(css)
426
- },
427
- stop: function(){
428
- this.progress_container.remove();
429
- }
430
- }),
431
- AjaxMask: Class.extend({
432
- init: function($mask_target,mask_message){
433
- var uuid = new UUID;
434
- this.$mask_target = $mask_target
435
- this.$mask = $('#thin_man_mask').clone()
436
- this.$mask.prop('id','thin_man_mask' + uuid.value)
437
- if(typeof mask_message != 'undefined'){
438
- var $message = this.$mask.find('[data-thin-man-mask-message]')
439
- $message.html(mask_message)
440
- }
441
- var height = this.$mask_target.outerHeight()
442
- var width = this.$mask_target.outerWidth()
443
- var radius = this.$mask_target.css('border-radius')
444
- this.$mask.css({'height': height, 'width': width, 'left': 0, 'top':0, 'border-radius':radius})
445
- this.$mask.css({'position': 'absolute', 'z-index': 10000})
63
+ }),
64
+ AjaxSubmission: Class.extend({
65
+ init: function(jq_obj, params) {
66
+ this.jq_obj = jq_obj
67
+ this.params = params
68
+ if (!this.params) { this.params = {} }
69
+ // Bail out if this is a no-mouse-click ajax element and we were mouse clicked
70
+ if (this.wasMouseClicked() && this.noMouseClick()) {
71
+ return false
72
+ }
73
+ this.getTrigger()
74
+ this.getTarget()
75
+ this.getErrorTarget()
76
+ this.progress_color = jq_obj.data('progress-color')
77
+ this.progress_target = $(jq_obj.data('progress-target'))
78
+ this.$mask_target = $(jq_obj.data('mask-target'))
79
+ this.$mask_message = jq_obj.data('mask-message')
80
+ this.custom_progress = typeof(jq_obj.data('custom-progress')) != 'undefined';
81
+ this.scroll_to = jq_obj.data('scroll-to')
82
+ this.watchers = []
83
+ if (this.progress_target.length == 0 && this.trigger.length > 0) {
84
+ this.progress_target = this.trigger
85
+ this.trigger_is_progress_target = true
86
+ }
87
+ this.insert_method = this.getInsertMethod()
88
+ var ajax_submission = this
89
+ this.ajax_options = {
90
+ url: ajax_submission.getAjaxUrl(),
91
+ type: ajax_submission.getAjaxType(),
92
+ datatype: ajax_submission.getAjaxDataType(),
93
+ data: ajax_submission.getData(),
94
+ beforeSend: function(jqXHr) { return ajax_submission.ajaxBefore(jqXHr) },
95
+ success: function(data, textStatus, jqXHR) { ajax_submission.ajaxSuccess(data, textStatus, jqXHR) },
96
+ error: function(jqXHr) { ajax_submission.ajaxError(jqXHr) },
97
+ complete: function(jqXHr) { ajax_submission.ajaxComplete(jqXHr) },
98
+ processData: ajax_submission.getProcessData()
99
+ };
100
+ if (!this.sendContentType()) {
101
+ this.ajax_options.contentType = false
102
+ };
103
+ if (typeof this.customXHR === 'function') {
104
+ this.ajax_options.xhr = this.customXHR
105
+ this.ajax_options.thin_man_obj = this;
106
+ }
107
+ this.handleGroup()
108
+ if (this.readyToFire()) {
109
+ this.fire()
110
+ }
111
+ },
112
+ fire: function() {
113
+ $.ajax(this.ajax_options);
114
+ },
115
+ readyToFire: function() {
116
+ if (!this.sequence_group) { return true }
117
+ },
118
+ handleGroup: function() {
119
+ this.sequence_group = this.jq_obj.data('sequence-group');
120
+ this.sequence_number = this.jq_obj.data('sequence-number');
121
+ if (typeof(this.sequence_number) == 'number' && !this.sequence_group) {
122
+ console.log('Warning! Thin Man Link has sequence number but no sequence group.')
123
+ }
124
+ if (this.sequence_group && typeof(this.sequence_number) != 'number') {
125
+ console.log('Warning! Thin Man Link has sequence group ' + this.sequence_group + ' but no sequence number.')
126
+ }
127
+ if (this.sequence_group) {
128
+ thin_man.addLinkToGroup(this, this.sequence_number, this.sequence_group)
129
+ }
130
+ },
131
+ getTarget: function() {
132
+ var target_selector = this.jq_obj.data('ajax-target');
133
+ if (target_selector) {
134
+ if ($(target_selector).length > 0) {
135
+ this.target = $(target_selector);
136
+ } else {
137
+ console.log('Warning! Thin Man selector ' + target_selector + ' not found')
138
+ }
139
+ } else {
140
+ console.log('Warning! Thin Man selector not given')
141
+ }
142
+ },
143
+ getErrorTarget: function() {
144
+ if ($(this.jq_obj.data('error-target')).length > 0) {
145
+ this.error_target = $(this.jq_obj.data('error-target'));
146
+ } else {
147
+ this.error_target = $(this.jq_obj.data('ajax-target'));
148
+ }
149
+ },
150
+ getAjaxDataType: function() {
151
+ return this.jq_obj.data('return-type') || 'html';
152
+ },
153
+ getInsertMethod: function() {
154
+ return this.jq_obj.data('insert-method') || 'html';
155
+ },
156
+ getData: function() {
157
+ return null;
158
+ },
159
+ getProcessData: function() {
160
+ return true;
161
+ },
162
+ sendContentType: function() {
163
+ return true;
164
+ },
165
+ insertHtml: function(data) {
166
+ debug_logger.log("thin_man.AjaxSubmission.insertHtml target:")
167
+ debug_logger.log(this.target)
168
+ debug_logger.log("thin_man.AjaxSubmission.insertHtml insert_method:")
169
+ debug_logger.log(this.insert_method)
170
+ if (this.target) {
171
+ this.target[this.insert_method](data);
172
+ if (this.refocus()) {
173
+ this.target.find('input,select,textarea').filter(':visible:enabled:first').each(function() {
174
+ if (!$(this).data('date-picker')) {
175
+ $(this).focus();
176
+ }
177
+ });
178
+ }
179
+ if (this.scroll_to) {
180
+ if (this.target.not(':visible')) {
181
+ if (this.target.parents('[data-tab-id]').length > 0) {
182
+ this.target.parents('[data-tab-id]').each(function() {
183
+ var tab_key = $(this).data('tab-id')
184
+ $('[data-tab-target-id="' + tab_key + '"]').trigger('click')
185
+ })
186
+ }
187
+ }
188
+ var extra_offset = 0
189
+ if ($('[data-thin-man-offset]').length > 0) {
190
+ extra_offset = $('[data-thin-man-offset]').outerHeight()
191
+ }
192
+ $('html, body').animate({
193
+ scrollTop: this.target.offset().top - extra_offset
194
+ }, 1000);
195
+ }
196
+ }
197
+ },
198
+ refocus: function() {
199
+ return true;
200
+ },
201
+ ajaxSuccess: function(data, textStatus, jqXHR) {
202
+ debug_logger.log("thin_man.AjaxSubmission.ajaxSuccess data:")
203
+ debug_logger.log(data)
204
+ if (typeof data === 'string') {
205
+ this.insertHtml(data);
206
+ } else if (typeof data === 'object') {
207
+ if (typeof data.html != 'undefined') {
208
+ if (typeof data.hooch_modal != 'undefined') {
209
+ new hooch.Modal($(data.html))
210
+ } else {
211
+ this.insertHtml(data.html)
212
+ }
213
+ } else if (this.target && typeof(this.target.empty) == 'function') {
214
+ this.target.empty()
215
+ }
216
+ if (typeof data.class_triggers != 'undefined') {
217
+ $.each(data.class_triggers, function(class_name, params) {
218
+ try {
219
+ klass = eval(class_name);
220
+ new klass(params);
221
+ } catch (err) {
222
+ console.log("Error trying to instantiate class " + class_name + " from ajax response:")
223
+ console.log(err)
224
+ }
225
+ })
226
+ }
227
+ if (typeof data.function_calls != 'undefined') {
228
+ $.each(data.function_calls, function(func_name, params) {
229
+ try {
230
+ func = eval(func_name);
231
+ func(params);
232
+ } catch (err) {
233
+ console.log("Error trying to instantiate function " + func_name + " from ajax response:")
234
+ console.log(err)
235
+ }
236
+ })
237
+ }
238
+ }
239
+ if (this.target) {
240
+ var ajax_flash = this.target.children().last().data('ajax-flash');
241
+ if ((jqXHR.status == 200) && ajax_flash) {
242
+ new thin_man.AjaxFlash('success', ajax_flash.notice, this.target);
243
+ }
244
+ }
245
+ if (this.removeOnSuccess()) {
246
+ if ($(this.removeOnSuccess())) {
247
+ $(this.removeOnSuccess()).remove();
248
+ }
249
+ }
250
+ if (this.emptyOnSuccess()) {
251
+ if ($(this.emptyOnSuccess())) {
252
+ $(this.emptyOnSuccess()).empty();
253
+ }
254
+ }
255
+ if ($.contains(document, this.jq_obj[0])) {
256
+ this.jq_obj.find('.error').removeClass('error')
257
+ this.jq_obj.find('.help-inline').remove()
258
+ }
259
+ },
260
+ addWatcher: function(watcher) {
261
+ if (!this.hasOwnProperty('watchers')) {
262
+ this.watchers = []
263
+ }
264
+ this.watchers.push(watcher)
265
+ },
266
+ notifyWatchers: function() {
267
+ $.each(this.watchers, function() {
268
+ this.linkCompleted(this)
269
+ })
270
+ },
271
+ ajaxComplete: function(jqXHR) {
272
+ debug_logger.log('thin_man.AjaxSubmission.ajaxComplete jqXHR:')
273
+ debug_logger.log(jqXHR)
274
+ this.showTrigger();
275
+ this.notifyWatchers();
276
+ if (this.progress_indicator) {
277
+ this.progress_indicator.stop();
278
+ } else if (!this.trigger_is_progress_target) {
279
+ this.progress_target.remove();
280
+ }
281
+ if (typeof this.mask != 'undefined') {
282
+ this.mask.remove();
283
+ }
284
+ try {
285
+ var response_data = JSON.parse(jqXHR.responseText)
286
+ } catch (err) {
287
+ var response_data = {}
288
+ // hmmm, the response is not JSON, so there's no flash.
289
+ }
290
+ if (typeof response_data.flash_message != 'undefined') {
291
+ var flash_style = this.httpResponseToFlashStyle(jqXHR.status);
292
+ var flash_duration = null;
293
+ if (typeof response_data.flash_persist != 'undefined') {
294
+ if (response_data.flash_persist) {
295
+ flash_duration = 'persist'
296
+ } else {
297
+ flash_duration = 'fade'
298
+ }
299
+ }
300
+ if (this.target) {
301
+ this.flash = new thin_man.AjaxFlash(flash_style, response_data.flash_message, this.target, flash_duration);
302
+ } else {
303
+ this.flash = new thin_man.AjaxFlash(flash_style, response_data.flash_message, this.jq_obj, flash_duration);
304
+ }
305
+ }
306
+ if ('function' == typeof this.params.on_complete) {
307
+ this.params.on_complete()
308
+ }
309
+ },
310
+ ajaxBefore: function(jqXHr) {
311
+ this.toggleLoading();
312
+ if (!this.custom_progress) {
313
+ this.progress_indicator = new thin_man.AjaxProgress(this.progress_target, this.target, this.progress_color);
314
+ }
315
+ if (this.$mask_target) {
316
+ this.mask = new thin_man.AjaxMask(this.$mask_target, this.$mask_message)
317
+ }
318
+ },
319
+ ajaxError: function(jqXHR) {
320
+ debug_logger.log('thin_man.AjaxSubmission.ajaxError jqXHR:')
321
+ debug_logger.log(jqXHR)
322
+ if (jqXHR.status == 409) {
323
+ try {
324
+ var data = JSON.parse(jqXHR.responseText);
325
+ debug_logger.log("thin_man.AjaxSubmission.ajaxError responseText is valid JSON, parsing to an object:")
326
+ } catch (error) {
327
+ debug_logger.log("thin_man.AjaxSubmission.ajaxError responseText is not JSON, assuming a string:")
328
+ debug_logger.log(jqXHR.responseText)
329
+ var data = jqXHR.responseText;
330
+ debug_logger.log("thin_man.AjaxSubmission.ajaxError data to insert:")
331
+ debug_logger.log(data)
332
+ }
333
+ debug_logger.log("thin_man.AjaxSubmission.ajaxError error target:")
334
+ debug_logger.log(this.error_target)
335
+ debug_logger.log("thin_man.AjaxSubmission.ajaxError data:")
336
+ debug_logger.log(data)
337
+ if (typeof data === 'string') {
338
+ debug_logger.log("thin_man.AjaxSubmission.ajaxError data is a string, inserting into target.")
339
+ this.error_target.html(data);
340
+ } else if (typeof data === 'object') {
341
+ debug_logger.log("thin_man.AjaxSubmission.ajaxError data is an object.")
342
+ if (typeof data.html != 'undefined') {
343
+ debug_logger.log("thin_man.AjaxSubmission.ajaxError data.html exists, inserting into target.")
344
+ this.error_target.html(data.html);
345
+ }
346
+ }
347
+ } else if (jqXHR.status == 500) {
348
+ alert('There was an error communicating with the server.')
349
+ }
350
+ },
351
+ getTrigger: function() {},
352
+ hideTrigger: function() {},
353
+ showTrigger: function() {},
354
+ toggleLoading: function() {
355
+ if (this.target) {
356
+ if (this.target.find('[data-loading-visible="false"]').length > 0) {
357
+ this.target.find('[data-loading-visible="false"]').hide();
358
+ }
359
+ if (this.target.find('[data-loading-visible="true"]').length > 0) {
360
+ this.target.find('[data-loading-visible="true"]').show();
361
+ }
362
+ }
363
+ },
364
+ removeOnSuccess: function() {
365
+ return this.jq_obj.data('remove-on-success')
366
+ },
367
+ emptyOnSuccess: function() {
368
+ return this.jq_obj.data('empty-on-success')
369
+ },
370
+ httpResponseToFlashStyle: function(response_code) {
371
+ if ([403, 409, 500].indexOf(response_code) > -1) {
372
+ return 'error'
373
+ }
374
+ if ([200, 202].indexOf(response_code) > -1) {
375
+ return 'success'
376
+ }
377
+ return 'error'
378
+ },
379
+ wasMouseClicked: function() {
380
+ return this.params.e && this.params.e.type && this.params.e.type == 'click'
381
+ },
382
+ noMouseClick: function() {
383
+ return this.jq_obj.data('no-mouse-click')
384
+ }
385
+ }),
386
+ AjaxBrowserPushConnector: Class.extend({
387
+ init: function($connector) {
388
+ this.trigger = $connector.find('button, input[type="submit"]');
389
+ if (this.trigger.length < 1) {
390
+ this.trigger = $connector;
391
+ }
392
+ this.browser_push_progress_indicator = new thin_man.AjaxProgress(this.trigger, this.trigger, this.progress_color);
393
+ $connector.data('browser-push-progress-indicator-object', this.browser_push_progress_indicator);
394
+ }
395
+ }),
396
+ AjaxBrowserPushFlash: Class.extend({
397
+ init: function($flash) {
398
+ this.message = $flash.data('ajax-browser-push-flash')
399
+ this.$target = $($flash.data('ajax-browser-push-flash-target'));
400
+ this.$target.data('ajax-browser-push-flash', this.message);
401
+ }
402
+ }),
403
+ AjaxProgress: Class.extend({
404
+ init: function(target, alt, progress_color) {
405
+ if (target.length > 0 && target.is(':visible') && target.css('display') != 'inline' && target.css('display') != 'inline-block') {
406
+ this.progress_target = target;
407
+ } else if (typeof(alt) != 'undefined' && alt.is(':visible')) {
408
+ this.progress_target = alt;
409
+ } else {
410
+ this.progress_target = $('body');
411
+ }
412
+ if (typeof(progress_color) == 'undefined') {
413
+ var progress_color = 'black';
414
+ }
415
+ this.progress_container = $('#ajax_progress_container').clone();
416
+ var uuid = new UUID;
417
+ this.progress_container.prop('id', 'thin_man_ajax_progress_' + uuid.value);
418
+ this.progress_target.append(this.progress_container);
419
+ var css = { display: 'block', visibility: 'visible', 'color': progress_color, 'z-index': 1000000 }
420
+ $.extend(css, {
421
+ position: 'absolute',
422
+ top: '50%',
423
+ left: '50%',
424
+ '-ms-transform': 'translate(-50%, -50%)',
425
+ /* IE 9 */
426
+ '-webkit-transform': 'translate(-50%, -50%)',
427
+ /* Safari */
428
+ 'transform': 'translate(-50%, -50%)'
429
+ })
430
+ this.progress_container.css(css)
431
+ },
432
+ stop: function() {
433
+ this.progress_container.remove();
434
+ }
435
+ }),
436
+ AjaxMask: Class.extend({
437
+ init: function($mask_target, mask_message) {
438
+ var uuid = new UUID;
439
+ this.$mask_target = $mask_target
440
+ this.$mask = $('#thin_man_mask').clone()
441
+ this.$mask.prop('id', 'thin_man_mask' + uuid.value)
442
+ if (typeof mask_message != 'undefined') {
443
+ var $message = this.$mask.find('[data-thin-man-mask-message]')
444
+ $message.html(mask_message)
445
+ }
446
+ var height = this.$mask_target.outerHeight()
447
+ var width = this.$mask_target.outerWidth()
448
+ var radius = this.$mask_target.css('border-radius')
449
+ this.$mask.css({ 'height': height, 'width': width, 'left': 0, 'top': 0, 'border-radius': radius })
450
+ this.$mask.css({ 'position': 'absolute', 'z-index': 10000 })
446
451
 
447
- this.$mask_target.append(this.$mask)
448
- this.$mask.on('click', function(e){
449
- e.preventDefault();
450
- return false;
452
+ this.$mask_target.append(this.$mask)
453
+ this.$mask.on('click', function(e) {
454
+ e.preventDefault();
455
+ return false;
456
+ })
457
+ this.$mask.show()
458
+ },
459
+ remove: function() {
460
+ this.$mask.remove()
461
+ }
462
+ }),
463
+ AjaxFlash: Class.extend({
464
+ init: function(type, message, elem, duration) {
465
+ this.flash_container = $('[data-thin-man-flash-template]').clone();
466
+ this.flash_container.removeAttr('data-thin-man-flash-template');
467
+ this.flash_container.attr('data-thin-man-flash-container', true);
468
+ $('body').append(this.flash_container);
469
+ this.flash_container.css({ position: 'absolute', visibility: 'hidden' });
470
+ this.alert_type = type;
471
+ this.elem = elem;
472
+ var alert_class = 'alert-' + type;
473
+ this.flash_container.addClass(alert_class);
474
+ this.flash_content = this.flash_container.find('[data-thin-man-flash-content]');
475
+ this.flash_content.html(message);
476
+ this.flash_container.show();
477
+ this.setFadeBehavior(duration);
478
+ this.reposition(elem);
479
+ },
480
+ setFadeBehavior: function(duration) {
481
+ if (duration) {
482
+ if ('persist' == duration) {
483
+ this.fade = false
484
+ } else {
485
+ this.fade = true
486
+ }
487
+ } else { //default behavior if persist duration is not sent back with message
488
+ if ('error' == this.alert_type || 'warning' == this.alert_type || 'info' == this.alert_type) {
489
+ this.fade = false;
490
+ } else {
491
+ this.fade = true;
492
+ }
493
+ }
494
+ },
495
+ reposition: function(elem) {
496
+ var this_window = {
497
+ top: $(window).scrollTop(),
498
+ left: $(window).scrollLeft(),
499
+ height: $(window).outerHeight(),
500
+ width: $(window).outerWidth()
501
+ };
502
+ var this_flash = {
503
+ height: this.flash_container.outerHeight(),
504
+ width: this.flash_container.outerWidth()
505
+ }
506
+ this_window.vert_middle = (this_window.top + (this_window.height / 2));
507
+ this_window.horiz_middle = (this_window.left + (this_window.width / 2));
508
+ this_flash.half_height = (this_flash.height / 2);
509
+ this_flash.half_width = (this_flash.width / 2);
510
+ var new_top = this_window.vert_middle - this_flash.half_height;
511
+ var new_left = this_window.horiz_middle - this_flash.half_width;
512
+ this.flash_container.css({ left: new_left, top: new_top, visibility: 'visible' });
513
+ var ajax_flash = this;
514
+ if (this.fade) {
515
+ setTimeout(function() { ajax_flash.fadeOut() }, 1618);
516
+ }
517
+ },
518
+ fadeOut: function() {
519
+ this.flash_container.fadeOut('slow');
520
+ }
521
+ }),
522
+ AjaxSorter: Class.extend({
523
+ init: function($sort_container) {
524
+ var base_url = $sort_container.data('url');
525
+ $sort_container.sortable({
526
+ helper: "clone",
527
+ tolerance: 'pointer',
528
+ stop: function(event, ui) {
529
+ new thin_man.AjaxSortSubmission($sort_container);
530
+ }
531
+ });
532
+ $sort_container.disableSelection();
533
+ }
451
534
  })
452
- this.$mask.show()
453
- },
454
- remove: function(){
455
- this.$mask.remove()
456
- }
457
- }),
458
- AjaxFlash: Class.extend({
459
- init: function(type,message,elem,duration){
460
- this.flash_container = $('[data-thin-man-flash-template]').clone();
461
- this.flash_container.removeAttr('data-thin-man-flash-template');
462
- this.flash_container.attr('data-thin-man-flash-container',true);
463
- $('body').append(this.flash_container);
464
- this.flash_container.css({position:'absolute',visibility: 'hidden'});
465
- this.alert_type = type;
466
- this.elem = elem;
467
- var alert_class = 'alert-' + type;
468
- this.flash_container.addClass(alert_class);
469
- this.flash_content = this.flash_container.find('[data-thin-man-flash-content]');
470
- this.flash_content.html(message);
471
- this.flash_container.show();
472
- this.setFadeBehavior(duration);
473
- this.reposition(elem);
474
- },
475
- setFadeBehavior: function(duration){
476
- if(duration){
477
- if('persist' == duration){
478
- this.fade = false
479
- } else {
480
- this.fade = true
481
- }
482
- }else{ //default behavior if persist duration is not sent back with message
483
- if('error' == this.alert_type || 'warning' == this.alert_type || 'info' == this.alert_type){
484
- this.fade = false;
485
- } else {
486
- this.fade = true;
487
- }
488
- }
489
- },
490
- reposition: function(elem){
491
- var this_window = {
492
- top: $(window).scrollTop(),
493
- left: $(window).scrollLeft(),
494
- height: $(window).outerHeight(),
495
- width: $(window).outerWidth()
496
- };
497
- var this_flash = {
498
- height: this.flash_container.outerHeight(),
499
- width: this.flash_container.outerWidth()
500
- }
501
- this_window.vert_middle = (this_window.top + (this_window.height / 2));
502
- this_window.horiz_middle = (this_window.left + (this_window.width / 2));
503
- this_flash.half_height = (this_flash.height / 2);
504
- this_flash.half_width = (this_flash.width / 2);
505
- var new_top = this_window.vert_middle - this_flash.half_height;
506
- var new_left = this_window.horiz_middle - this_flash.half_width;
507
- this.flash_container.css({left: new_left, top: new_top, visibility: 'visible'});
508
- var ajax_flash = this;
509
- if (this.fade) {
510
- setTimeout(function(){ajax_flash.fadeOut()},1618);
511
- }
512
- },
513
- fadeOut: function(){
514
- this.flash_container.fadeOut('slow');
515
- }
516
- }),
517
- AjaxSorter: Class.extend({
518
- init: function($sort_container){
519
- var base_url = $sort_container.data('url');
520
- $sort_container.sortable({
521
- helper: "clone",
522
- tolerance: 'pointer',
523
- stop: function( event, ui) {
524
- new thin_man.AjaxSortSubmission($sort_container);
525
- }
526
- });
527
- $sort_container.disableSelection();
528
- }
529
- })
530
- };
531
- thin_man.AjaxFormSubmission = thin_man.AjaxSubmission.extend({
532
- getAjaxUrl: function(){
533
- return this.jq_obj.attr('action');
534
- },
535
- getAjaxType: function(){
536
- return this.jq_obj.attr('method') || 'POST'
537
- },
538
- getData: function(){
539
- var $clicked = $(document.activeElement);
535
+ };
536
+ thin_man.AjaxFormSubmission = thin_man.AjaxSubmission.extend({
537
+ getAjaxUrl: function() {
538
+ return this.jq_obj.attr('action');
539
+ },
540
+ getAjaxType: function() {
541
+ return this.jq_obj.attr('method') || 'POST'
542
+ },
543
+ getData: function() {
544
+ var $clicked = $(document.activeElement);
540
545
 
541
- if ($clicked.length && $clicked.is('button[type="submit"], input[type="submit"], input[type="image"]') && $clicked.is('[name]')) {
542
- var button_name = $clicked.attr('name')
543
- var button_value = $clicked.attr('value')
544
- }
545
- var event_data = this.params
546
- if(!event_data.hasOwnProperty('e')){
547
- var thin_man_submitter = 'link_now'
548
- }else{
549
- var thin_man_submitter = this.params['e'].type
550
- }
551
- if((this.getAjaxType().toLowerCase() == 'get') || (typeof FormData == 'undefined')){
552
- var data_array = this.jq_obj.serializeArray();
553
- if(button_name && button_value){
554
- data_array.push({name: button_name, value: button_value})
555
- }
556
- data_array.push({name: 'thin_man_submitter', value: thin_man_submitter})
557
- return data_array;
558
- }else{
559
- // need to implement a data-attribute for multiple file fields so we can allow selecting mutliple files at once. example here:
560
- // http://stackoverflow.com/questions/12989442/uploading-multiple-files-using-formdata
561
- var fd = new FormData(this.jq_obj[0]);
562
- if(button_name && button_value){
563
- if(typeof fd.set != 'undefined'){
564
- fd.set(button_name, button_value)
565
- } else if(typeof fd.append != 'undefined'){
566
- fd.append(button_name, button_value)
567
- }
568
- }
569
- if(typeof fd.set != 'undefined'){
570
- fd.set('thin_man_submitter', thin_man_submitter)
571
- } else if(typeof fd.append != 'undefined'){
572
- fd.append('thin_man_submitter', thin_man_submitter)
573
- }
574
- return fd
575
- }
576
- },
577
- ajaxSuccess: function(data,textStatus,jqXHR){
578
- debug_logger.log('thin_man.AjaxFormSubmission.ajaxSuccess')
579
- this._super(data,textStatus,jqXHR)
580
- if(this.resetOnSuccess()){
581
- this.jq_obj[0].reset();
582
- $(this.jq_obj).find('input[type=text],textarea,select').filter(':visible:first').focus();
583
- }
584
- },
585
- resetOnSuccess: function(){
586
- return this.jq_obj.data('reset-on-success')
587
- },
588
- getProcessData: function() {
589
- if(this.getAjaxType().toLowerCase() == 'get'){
590
- return true;
591
- }else{
592
- return false;
593
- }
594
- },
595
- sendContentType: function() {
596
- if(this.getAjaxType().toLowerCase() == 'get'){
597
- return true;
598
- }else{
599
- return false;
600
- }
601
- },
602
- getTrigger: function(){
603
- this.trigger = this.jq_obj.find('button, input[type="submit"]');
604
- if(this.trigger.length != 1){
605
- var $active_element = $(document.activeElement)
606
- if($active_element[0].nodeName.toLowerCase() != 'body'){
607
- this.trigger = $active_element
608
- }
609
- }
610
- },
611
- hideTrigger: function(){
612
- this.trigger.css('visibility','hidden');
613
- },
614
- showTrigger: function(){
615
- this.trigger.css('visibility','visible');
616
- }
617
- }),
618
- thin_man.AjaxLinkSubmission = thin_man.AjaxSubmission.extend({
619
- getAjaxUrl: function(){
620
- return this.jq_obj.attr('href');
621
- },
622
- getData: function(){
623
- var this_data = {authenticity_token: $('[name="csrf-token"]').attr('content')};
624
- if(this.jq_obj.data('form-data')){
625
- $.extend(this_data,this.jq_obj.data('form-data'))
626
- }
627
- return this_data
628
- },
629
- getProcessData: function() {
630
- return true;
631
- },
632
- getAjaxType: function(){
633
- return this.jq_obj.data('ajax-method') || 'GET'
634
- },
635
- getTrigger: function(){
636
- this.trigger = this.jq_obj;
637
- },
638
- hideTrigger: function(){
639
- this.trigger.css('visibility','hidden');
640
- },
641
- showTrigger: function(){
642
- this.trigger.css('visibility','visible');
643
- },
644
- refocus: function(){
645
- if(this.jq_obj.data('ajax-link-now')){
646
- return false
647
- }
648
- return true
649
- },
546
+ if ($clicked.length && $clicked.is('button[type="submit"], input[type="submit"], input[type="image"]') && $clicked.is('[name]')) {
547
+ var button_name = $clicked.attr('name')
548
+ var button_value = $clicked.attr('value')
549
+ }
550
+ var event_data = this.params
551
+ if (!event_data.hasOwnProperty('e')) {
552
+ var thin_man_submitter = 'link_now'
553
+ } else {
554
+ var thin_man_submitter = this.params['e'].type
555
+ }
556
+ if ((this.getAjaxType().toLowerCase() == 'get') || (typeof FormData == 'undefined')) {
557
+ var data_array = this.jq_obj.serializeArray();
558
+ if (button_name && button_value) {
559
+ data_array.push({ name: button_name, value: button_value })
560
+ }
561
+ data_array.push({ name: 'thin_man_submitter', value: thin_man_submitter })
562
+ return data_array;
563
+ } else {
564
+ // need to implement a data-attribute for multiple file fields so we can allow selecting mutliple files at once. example here:
565
+ // http://stackoverflow.com/questions/12989442/uploading-multiple-files-using-formdata
566
+ var fd = new FormData(this.jq_obj[0]);
567
+ if (button_name && button_value) {
568
+ if (typeof fd.set != 'undefined') {
569
+ fd.set(button_name, button_value)
570
+ } else if (typeof fd.append != 'undefined') {
571
+ fd.append(button_name, button_value)
572
+ }
573
+ }
574
+ if (typeof fd.set != 'undefined') {
575
+ fd.set('thin_man_submitter', thin_man_submitter)
576
+ } else if (typeof fd.append != 'undefined') {
577
+ fd.append('thin_man_submitter', thin_man_submitter)
578
+ }
579
+ return fd
580
+ }
581
+ },
582
+ ajaxSuccess: function(data, textStatus, jqXHR) {
583
+ debug_logger.log('thin_man.AjaxFormSubmission.ajaxSuccess')
584
+ this._super(data, textStatus, jqXHR)
585
+ if (this.resetOnSuccess()) {
586
+ this.jq_obj[0].reset();
587
+ $(this.jq_obj).find('input[type=text],textarea,select').filter(':visible:first').focus();
588
+ }
589
+ },
590
+ resetOnSuccess: function() {
591
+ return this.jq_obj.data('reset-on-success')
592
+ },
593
+ getProcessData: function() {
594
+ if (this.getAjaxType().toLowerCase() == 'get') {
595
+ return true;
596
+ } else {
597
+ return false;
598
+ }
599
+ },
600
+ sendContentType: function() {
601
+ if (this.getAjaxType().toLowerCase() == 'get') {
602
+ return true;
603
+ } else {
604
+ return false;
605
+ }
606
+ },
607
+ getTrigger: function() {
608
+ this.trigger = this.jq_obj.find('button, input[type="submit"]');
609
+ if (this.trigger.length != 1) {
610
+ var $active_element = $(document.activeElement)
611
+ if ($active_element[0].nodeName.toLowerCase() != 'body') {
612
+ this.trigger = $active_element
613
+ }
614
+ }
615
+ },
616
+ hideTrigger: function() {
617
+ this.trigger.css('visibility', 'hidden');
618
+ },
619
+ showTrigger: function() {
620
+ this.trigger.css('visibility', 'visible');
621
+ }
622
+ }),
623
+ thin_man.AjaxLinkSubmission = thin_man.AjaxSubmission.extend({
624
+ getAjaxUrl: function() {
625
+ return this.jq_obj.attr('href');
626
+ },
627
+ getData: function() {
628
+ var this_data = { authenticity_token: $('[name="csrf-token"]').attr('content') };
629
+ if (this.jq_obj.data('form-data')) {
630
+ $.extend(this_data, this.jq_obj.data('form-data'))
631
+ }
632
+ return this_data
633
+ },
634
+ getProcessData: function() {
635
+ return true;
636
+ },
637
+ getAjaxType: function() {
638
+ return this.jq_obj.data('ajax-method') || 'GET'
639
+ },
640
+ getTrigger: function() {
641
+ this.trigger = this.jq_obj;
642
+ },
643
+ hideTrigger: function() {
644
+ this.trigger.css('visibility', 'hidden');
645
+ },
646
+ showTrigger: function() {
647
+ this.trigger.css('visibility', 'visible');
648
+ },
649
+ refocus: function() {
650
+ if (this.jq_obj.data('ajax-link-now')) {
651
+ return false
652
+ }
653
+ return true
654
+ },
650
655
 
651
- }),
652
- thin_man.AjaxModalOpener = thin_man.AjaxLinkSubmission.extend({
653
- ajaxSuccess: function(data,textStatus,jqXHR) {
654
- this._super(data,textStatus,jqXHR);
655
- $(this.jq_obj.data('ajax-modal')).modal();
656
- }
657
- }),
658
- thin_man.AddALineForm = thin_man.AjaxFormSubmission.extend({
659
- ajaxSuccess: function(data,textStatus,jqXHR) {
660
- this._super(data,textStatus,jqXHR);
661
- $(this.jq_obj.data('container')).empty();
662
- },
663
- ajaxError: function(jqXHR){
664
- this.insert_method = 'html';
665
- this._super(jqXHR);
666
- }
667
- }),
668
- thin_man.EmptyForm = thin_man.AjaxFormSubmission.extend({
669
- ajaxSuccess: function(data,textStatus,jqXHR) {
670
- var clicked_button = $("input[type=submit][clicked=true]")[0];
671
- this._super(data,textStatus,jqXHR);
672
- if ($(clicked_button).data('clone') != true) {
673
- $(this.jq_obj)[0].reset();
674
- };
675
- $(this.jq_obj).find('input[type=text],textarea,select').filter(':visible:first').focus();
676
- $("[data-autocomplete]").trigger("chosen:updated");
677
- },
678
- ajaxError: function(jqXHR){
679
- this.insert_method = 'html';
680
- this._super(jqXHR);
681
- }
682
- }),
683
- thin_man.ModalCloserForm = thin_man.AjaxFormSubmission.extend({
684
- ajaxSuccess: function(data,textStatus,jqXHR) {
685
- this._super(data,textStatus,jqXHR);
686
- $modal = $(this.jq_obj.data('modal-container'));
687
- $modal.modal('hide');
688
- $modal.remove();
689
- },
690
- ajaxError: function(jqXHR){
691
- this._super(jqXHR);
692
- $modal = $(this.jq_obj.data('modal-container'));
693
- $modal.modal();
694
- }
695
- }),
696
- thin_man.ResetOnSubmitForm = thin_man.AjaxFormSubmission.extend({
697
- ajaxSuccess: function(data, textStatus, jqXHR) {
698
- this._super(data, textStatus, jqXHR);
699
- $(this.jq_obj).each(function() {
700
- this.reset();
701
- });
702
- }
703
- }),
704
- thin_man.DeleteLink = thin_man.AjaxSubmission.extend({
705
- ajaxSuccess: function(data,textStatus,jqXHR){
706
- this._super(data,textStatus,jqXHR);
707
- if(this.jq_obj.data('replace-response')){
708
- this.insertHtml(data);
709
- } else {
710
- if(this.target){
711
- this.target.remove();
712
- }
713
- }
714
- },
715
- getTrigger: function(){
716
- this.trigger = this.jq_obj;
717
- },
718
- getAjaxType: function(){
719
- return 'DELETE';
720
- },
721
- getAjaxUrl: function(){
722
- return this.jq_obj.attr('href');
723
- },
724
- getData: function(){
725
- return {authenticity_token: $('[name="csrf-token"]').attr('content')};
726
- },
727
- getProcessData: function() {
728
- return true;
729
- },
730
- ajaxBefore: function(jqXHR){
731
- if(!this.jq_obj.data('no-confirm')){
732
- return confirm("Are you sure you want to delete this?");
733
- }
734
- }
735
- }),
736
- thin_man.ReplaceDelete = thin_man.DeleteLink.extend({
737
- ajaxSuccess: function(data,textStatus,jqXHR){
738
- this.target[this.insert_method](data);
739
- },
740
- ajaxBefore: function(jqXHR){
741
- //noop
742
- }
743
- }),
744
- thin_man.AjaxSortSubmission = thin_man.AjaxLinkSubmission.extend({
745
- init: function($form){
746
- this.sort_field = $form.data('sort-field');
747
- this._super($form);
748
- },
749
- getAjaxUrl: function(){
750
- return this._super() + '?' + 'sort_field=' + this.sort_field + '&' + this.jq_obj.sortable("serialize");
751
- },
752
- getAjaxType: function(){
753
- return 'PUT';
754
- },
755
- ajaxSuccess: function(){
656
+ }),
657
+ thin_man.AjaxModalOpener = thin_man.AjaxLinkSubmission.extend({
658
+ ajaxSuccess: function(data, textStatus, jqXHR) {
659
+ this._super(data, textStatus, jqXHR);
660
+ $(this.jq_obj.data('ajax-modal')).modal();
661
+ }
662
+ }),
663
+ thin_man.AddALineForm = thin_man.AjaxFormSubmission.extend({
664
+ ajaxSuccess: function(data, textStatus, jqXHR) {
665
+ this._super(data, textStatus, jqXHR);
666
+ $(this.jq_obj.data('container')).empty();
667
+ },
668
+ ajaxError: function(jqXHR) {
669
+ this.insert_method = 'html';
670
+ this._super(jqXHR);
671
+ }
672
+ }),
673
+ thin_man.EmptyForm = thin_man.AjaxFormSubmission.extend({
674
+ ajaxSuccess: function(data, textStatus, jqXHR) {
675
+ var clicked_button = $("input[type=submit][clicked=true]")[0];
676
+ this._super(data, textStatus, jqXHR);
677
+ if ($(clicked_button).data('clone') != true) {
678
+ $(this.jq_obj)[0].reset();
679
+ };
680
+ $(this.jq_obj).find('input[type=text],textarea,select').filter(':visible:first').focus();
681
+ $("[data-autocomplete]").trigger("chosen:updated");
682
+ },
683
+ ajaxError: function(jqXHR) {
684
+ this.insert_method = 'html';
685
+ this._super(jqXHR);
686
+ }
687
+ }),
688
+ thin_man.ModalCloserForm = thin_man.AjaxFormSubmission.extend({
689
+ ajaxSuccess: function(data, textStatus, jqXHR) {
690
+ this._super(data, textStatus, jqXHR);
691
+ $modal = $(this.jq_obj.data('modal-container'));
692
+ $modal.modal('hide');
693
+ $modal.remove();
694
+ },
695
+ ajaxError: function(jqXHR) {
696
+ this._super(jqXHR);
697
+ $modal = $(this.jq_obj.data('modal-container'));
698
+ $modal.modal();
699
+ }
700
+ }),
701
+ thin_man.ResetOnSubmitForm = thin_man.AjaxFormSubmission.extend({
702
+ ajaxSuccess: function(data, textStatus, jqXHR) {
703
+ this._super(data, textStatus, jqXHR);
704
+ $(this.jq_obj).each(function() {
705
+ this.reset();
706
+ });
707
+ }
708
+ }),
709
+ thin_man.DeleteLink = thin_man.AjaxSubmission.extend({
710
+ ajaxSuccess: function(data, textStatus, jqXHR) {
711
+ this._super(data, textStatus, jqXHR);
712
+ if (data.length === 0) {
713
+ if (this.target) {
714
+ // $(this.target.selector).remove();
715
+ this.target.remove();
716
+ }
717
+ }
718
+ },
719
+ getTrigger: function() {
720
+ this.trigger = this.jq_obj;
721
+ },
722
+ getAjaxType: function() {
723
+ return 'DELETE';
724
+ },
725
+ getAjaxUrl: function() {
726
+ return this.jq_obj.attr('href');
727
+ },
728
+ getData: function() {
729
+ return { authenticity_token: $('[name="csrf-token"]').attr('content') };
730
+ },
731
+ getProcessData: function() {
732
+ return true;
733
+ },
734
+ ajaxBefore: function(jqXHR) {
735
+ if (!this.jq_obj.data('no-confirm')) {
736
+ return confirm("Are you sure you want to delete this?");
737
+ }
738
+ }
739
+ }),
740
+ thin_man.ReplaceDelete = thin_man.DeleteLink.extend({
741
+ ajaxSuccess: function(data, textStatus, jqXHR) {
742
+ this.target[this.insert_method](data);
743
+ },
744
+ ajaxBefore: function(jqXHR) {
745
+ //noop
746
+ }
747
+ }),
748
+ thin_man.AjaxSortSubmission = thin_man.AjaxLinkSubmission.extend({
749
+ init: function($form) {
750
+ this.sort_field = $form.data('sort-field');
751
+ this._super($form);
752
+ },
753
+ getAjaxUrl: function() {
754
+ return this._super() + '?' + 'sort_field=' + this.sort_field + '&' + this.jq_obj.sortable("serialize");
755
+ },
756
+ getAjaxType: function() {
757
+ return 'PUT';
758
+ },
759
+ ajaxSuccess: function() {
756
760
 
757
- }
758
- });
761
+ }
762
+ });
759
763
 
760
- window.any_time_manager.registerListWithClasses({'sortable' : 'AjaxSorter', 'ajax-link-now' : 'AjaxLinkSubmission', 'ajax-form-now' : 'AjaxFormSubmission'},'thin_man');
764
+ window.any_time_manager.registerListWithClasses({ 'sortable': 'AjaxSorter', 'ajax-link-now': 'AjaxLinkSubmission', 'ajax-form-now': 'AjaxFormSubmission' }, 'thin_man');
761
765
 
762
- $(document).ready(function(){
763
- $(document).on('click apiclick','[data-ajax-link],[data-ajax-link-now]',function(e){
764
- e.preventDefault();
765
- var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'),'AjaxLinkSubmission'));
766
- var submission = new this_class($(this),{e: e});
767
- return false;
768
- });
766
+ $(document).ready(function() {
767
+ $(document).on('click apiclick', '[data-ajax-link],[data-ajax-link-now]', function(e) {
768
+ e.preventDefault();
769
+ var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'), 'AjaxLinkSubmission'));
770
+ var submission = new this_class($(this), { e: e });
771
+ return false;
772
+ });
769
773
 
770
- $(document).on('submit apisubmit','[data-ajax-form]',function(e){
771
- e.preventDefault();
772
- var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'),'AjaxFormSubmission'));
773
- var submission = new this_class($(this),{e: e});
774
- return false;
775
- });
774
+ $(document).on('submit apisubmit', '[data-ajax-form]', function(e) {
775
+ e.preventDefault();
776
+ var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'), 'AjaxFormSubmission'));
777
+ var submission = new this_class($(this), { e: e });
778
+ return false;
779
+ });
776
780
 
777
- $(document).on('click apiclick','[data-ajax-delete]',function(e){
778
- e.preventDefault();
779
- var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'),'DeleteLink'));
780
- var deletion = new this_class($(this),{e: e});
781
- });
782
- $(document).on('click', '[data-change-url]',function(e){
783
- e.preventDefault();
784
- new thin_man.AjaxPushState($(this))
785
- });
781
+ $(document).on('click apiclick', '[data-ajax-delete]', function(e) {
782
+ e.preventDefault();
783
+ var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'), 'DeleteLink'));
784
+ var deletion = new this_class($(this), { e: e });
785
+ });
786
+ $(document).on('click', '[data-change-url]', function(e) {
787
+ e.preventDefault();
788
+ new thin_man.AjaxPushState($(this))
789
+ });
786
790
 
787
- $('[data-sortable]').each(function(){
788
- new thin_man.AjaxSorter($(this));
789
- });
791
+ $('[data-sortable]').each(function() {
792
+ new thin_man.AjaxSorter($(this));
793
+ });
790
794
 
791
795
 
792
- });
796
+ });
793
797
 
794
798
  };
795
799
 
796
- if(typeof Class === "undefined"){
797
- /* Simple JavaScript Inheritance
798
- * By John Resig http://ejohn.org/
799
- * MIT Licensed.
800
- */
801
- // Inspired by base2 and Prototype
802
- (function(){
803
- var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
804
- // The base Class implementation (does nothing)
805
- this.Class = function(){};
800
+ if (typeof Class === "undefined") {
801
+ /* Simple JavaScript Inheritance
802
+ * By John Resig http://ejohn.org/
803
+ * MIT Licensed.
804
+ */
805
+ // Inspired by base2 and Prototype
806
+ (function() {
807
+ var initializing = false,
808
+ fnTest = /xyz/.test(function() { xyz; }) ? /\b_super\b/ : /.*/;
809
+ // The base Class implementation (does nothing)
810
+ this.Class = function() {};
806
811
 
807
- // Create a new Class that inherits from this class
808
- Class.extend = function(prop) {
809
- var _super = this.prototype;
812
+ // Create a new Class that inherits from this class
813
+ Class.extend = function(prop) {
814
+ var _super = this.prototype;
810
815
 
811
- // Instantiate a base class (but only create the instance,
812
- // don't run the init constructor)
813
- initializing = true;
814
- var prototype = new this();
815
- initializing = false;
816
+ // Instantiate a base class (but only create the instance,
817
+ // don't run the init constructor)
818
+ initializing = true;
819
+ var prototype = new this();
820
+ initializing = false;
816
821
 
817
- // Copy the properties over onto the new prototype
818
- for (var name in prop) {
819
- // Check if we're overwriting an existing function
820
- prototype[name] = typeof prop[name] == "function" &&
821
- typeof _super[name] == "function" && fnTest.test(prop[name]) ?
822
- (function(name, fn){
823
- return function() {
824
- var tmp = this._super;
822
+ // Copy the properties over onto the new prototype
823
+ for (var name in prop) {
824
+ // Check if we're overwriting an existing function
825
+ prototype[name] = typeof prop[name] == "function" &&
826
+ typeof _super[name] == "function" && fnTest.test(prop[name]) ?
827
+ (function(name, fn) {
828
+ return function() {
829
+ var tmp = this._super;
825
830
 
826
- // Add a new ._super() method that is the same method
827
- // but on the super-class
828
- this._super = _super[name];
831
+ // Add a new ._super() method that is the same method
832
+ // but on the super-class
833
+ this._super = _super[name];
829
834
 
830
- // The method only need to be bound temporarily, so we
831
- // remove it when we're done executing
832
- var ret = fn.apply(this, arguments);
833
- this._super = tmp;
835
+ // The method only need to be bound temporarily, so we
836
+ // remove it when we're done executing
837
+ var ret = fn.apply(this, arguments);
838
+ this._super = tmp;
834
839
 
835
- return ret;
836
- };
837
- })(name, prop[name]) :
838
- prop[name];
839
- }
840
+ return ret;
841
+ };
842
+ })(name, prop[name]) :
843
+ prop[name];
844
+ }
840
845
 
841
- // The dummy class constructor
842
- function Class() {
843
- // All construction is actually done in the init method
844
- if ( !initializing && this.init )
845
- this.init.apply(this, arguments);
846
- }
846
+ // The dummy class constructor
847
+ function Class() {
848
+ // All construction is actually done in the init method
849
+ if (!initializing && this.init)
850
+ this.init.apply(this, arguments);
851
+ }
847
852
 
848
- // Populate our constructed prototype object
849
- Class.prototype = prototype;
853
+ // Populate our constructed prototype object
854
+ Class.prototype = prototype;
850
855
 
851
- // Enforce the constructor to be what we expect
852
- Class.prototype.constructor = Class;
856
+ // Enforce the constructor to be what we expect
857
+ Class.prototype.constructor = Class;
853
858
 
854
- // And make this class extendable
855
- Class.extend = arguments.callee;
859
+ // And make this class extendable
860
+ Class.extend = arguments.callee;
856
861
 
857
- return Class;
858
- };
859
- })();
862
+ return Class;
863
+ };
864
+ })();
860
865
  }
861
866
 
862
- if(typeof UUID == 'undefined'){
863
- var UUID = Class.extend({
864
- init: function(){
865
- this.value = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
866
- var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
867
- return v.toString(16);
868
- });
869
- }
870
- })
867
+ if (typeof UUID == 'undefined') {
868
+ var UUID = Class.extend({
869
+ init: function() {
870
+ this.value = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
871
+ var r = Math.random() * 16 | 0,
872
+ v = c == 'x' ? r : (r & 0x3 | 0x8);
873
+ return v.toString(16);
874
+ });
875
+ }
876
+ })
871
877
  }
872
878
 
873
- if(typeof window.any_time_manager === "undefined" && typeof window.loading_any_time_manager === "undefined"){
874
- //Anytime loader, simulates load events for ajax requests
875
- function getSubClass(sub_class_name,parent_class){
876
- if((typeof(sub_class_name) == 'string') && (sub_class_name != '') && (sub_class_name != 'true')){
877
- var this_class = sub_class_name;
878
- } else {
879
- var this_class = parent_class;
880
- }
881
- return this_class;
882
- };
879
+ if (typeof window.any_time_manager === "undefined" && typeof window.loading_any_time_manager === "undefined") {
880
+ //Anytime loader, simulates load events for ajax requests
881
+ function getSubClass(sub_class_name, parent_class) {
882
+ if ((typeof(sub_class_name) == 'string') && (sub_class_name != '') && (sub_class_name != 'true')) {
883
+ var this_class = sub_class_name;
884
+ } else {
885
+ var this_class = parent_class;
886
+ }
887
+ return this_class;
888
+ };
889
+
890
+ String.prototype.toCapCamel = function() {
891
+ camel = this.replace(/[-_]([a-z])/g, function(g) { return g.replace(/[-_]/, '').charAt(0).toUpperCase(); });
892
+ return camel.charAt(0).toUpperCase() + camel.slice(1);
893
+ };
883
894
 
884
- String.prototype.toCapCamel = function(){
885
- camel = this.replace(/[-_]([a-z])/g, function (g) { return g.replace(/[-_]/,'').charAt(0).toUpperCase(); });
886
- return camel.charAt(0).toUpperCase() + camel.slice(1);
887
- };
895
+ var AnyTimeManager = Class.extend({
896
+ init: function() {
897
+ this.loader_array = []
898
+ },
899
+ register: function(data_attribute, load_method, base_class, namespace) {
900
+ if (!namespace) { namespace = '' } else { namespace = namespace + '.' }
901
+ this.loader_array.push({ data_attribute: data_attribute, base_class: base_class, load_method: load_method, namespace: namespace });
902
+ },
903
+ registerList: function(list, namespace) {
904
+ var anytime_manager = this;
905
+ $.each(list, function() {
906
+ anytime_manager.register(this + '', 'instantiate', null, namespace)
907
+ })
908
+ },
909
+ registerListWithClasses: function(list, namespace) {
910
+ var anytime_manager = this;
911
+ $.each(list, function(attr, klass) {
912
+ anytime_manager.register(attr, 'instantiate', klass, namespace)
913
+ })
914
+ },
915
+ registerRunList: function(list) {
916
+ var anytime_manager = this;
917
+ $.each(list, function(attr, method) {
918
+ anytime_manager.register(attr, method, null)
919
+ })
920
+ },
921
+ instantiate: function(jq_obj, class_name) {
922
+ if (!jq_obj.data('anytime_loaded')) {
923
+ jq_obj.data('anytime_loaded', true);
924
+ var this_class = eval(class_name);
925
+ new this_class(jq_obj);
926
+ }
927
+ },
928
+ run: function(jq_obj, resource, method_name) {
929
+ if (!jq_obj.data('anytime_run')) {
930
+ jq_obj.data('anytime_run', true);
931
+ resource[method_name](jq_obj);
932
+ }
933
+ },
934
+ load: function() {
935
+ var atm = this;
936
+ $.each(atm.loader_array, function() {
937
+ var data_attribute = this['data_attribute'];
938
+ var base_class = this['base_class'];
939
+ if (!base_class) {
940
+ base_class = data_attribute.toCapCamel();
941
+ }
942
+ var this_method = this['load_method'];
943
+ var namespace = this['namespace'];
944
+ $('[data-' + data_attribute + ']').each(function() {
945
+ if ('instantiate' == this_method) {
946
+ var declared_class = $(this).data('sub-type');
947
+ var this_class = getSubClass(declared_class, base_class);
948
+ this_class = namespace + this_class;
949
+ atm.instantiate($(this), this_class);
950
+ } else {
951
+ atm.run($(this), base_class, this_method);
952
+ }
888
953
 
889
- var AnyTimeManager = Class.extend({
890
- init: function(){
891
- this.loader_array = []
892
- },
893
- register: function(data_attribute,load_method,base_class,namespace){
894
- if(!namespace){namespace = ''}else{namespace= namespace + '.'}
895
- this.loader_array.push({data_attribute: data_attribute, base_class: base_class, load_method: load_method, namespace: namespace});
896
- },
897
- registerList: function(list,namespace){
898
- var anytime_manager = this;
899
- $.each(list,function(){
900
- anytime_manager.register(this + '','instantiate',null,namespace)
901
- })
902
- },
903
- registerListWithClasses: function(list,namespace){
904
- var anytime_manager = this;
905
- $.each(list,function(attr,klass){
906
- anytime_manager.register(attr,'instantiate',klass,namespace)
907
- })
908
- },
909
- registerRunList: function(list){
910
- var anytime_manager = this;
911
- $.each(list,function(attr,method){
912
- anytime_manager.register(attr,method,null)
913
- })
914
- },
915
- instantiate: function(jq_obj, class_name){
916
- if(!jq_obj.data('anytime_loaded')){
917
- jq_obj.data('anytime_loaded',true);
918
- var this_class = eval(class_name);
919
- new this_class(jq_obj);
920
- }
921
- },
922
- run: function (jq_obj, resource, method_name){
923
- if(!jq_obj.data('anytime_run')){
924
- jq_obj.data('anytime_run',true);
925
- resource[method_name](jq_obj);
926
- }
927
- },
928
- load: function(){
929
- var atm = this;
930
- $.each(atm.loader_array,function(){
931
- var data_attribute = this['data_attribute'];
932
- var base_class = this['base_class'];
933
- if(!base_class){
934
- base_class = data_attribute.toCapCamel();
954
+ });
955
+ });
935
956
  }
936
- var this_method = this['load_method'];
937
- var namespace = this['namespace'];
938
- $('[data-' + data_attribute + ']').each(function(){
939
- if('instantiate' == this_method){
940
- var declared_class = $(this).data('sub-type');
941
- var this_class = getSubClass(declared_class,base_class);
942
- this_class = namespace + this_class;
943
- atm.instantiate($(this),this_class);
944
- }else{
945
- atm.run($(this),base_class,this_method);
946
- }
947
-
948
- });
949
- });
950
- }
951
- });
952
- window.any_time_manager = new AnyTimeManager();
953
- $(document).ajaxComplete(function(){
954
- window.any_time_manager.load();
955
- });
956
- $(document).ready(function(){
957
- if(typeof window.any_time_load_functions != 'undefined'){
958
- $.each(window.any_time_load_functions, function(i,func){
959
- func();
960
- });
961
- }
962
- window.any_time_manager.load();
963
- })
964
- // End AnyTime library
957
+ });
958
+ window.any_time_manager = new AnyTimeManager();
959
+ $(document).ajaxComplete(function() {
960
+ window.any_time_manager.load();
961
+ });
962
+ $(document).ready(function() {
963
+ if (typeof window.any_time_load_functions != 'undefined') {
964
+ $.each(window.any_time_load_functions, function(i, func) {
965
+ func();
966
+ });
967
+ }
968
+ window.any_time_manager.load();
969
+ })
970
+ // End AnyTime library
965
971
  }
966
972
 
967
- initThinMan();
973
+ initThinMan();