thin_man 0.19.10 → 0.19.11

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