thin_man 0.19.6 → 0.19.7

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.
@@ -1,973 +1,979 @@
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
- }
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 })
451
-
452
- this.$mask_target.append(this.$mask)
453
- this.$mask.on('click', function(e) {
454
- e.preventDefault();
455
- return false;
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.not(':visible')){
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')
456
187
  })
457
- this.$mask.show()
458
- },
459
- remove: function() {
460
- this.$mask.remove()
188
+ }
461
189
  }
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');
190
+ var extra_offset = 0
191
+ if($('[data-thin-man-offset]').length > 0){
192
+ extra_offset = $('[data-thin-man-offset]').outerHeight()
520
193
  }
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();
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)
533
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)
534
271
  })
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);
545
-
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
- },
655
-
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
- }
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'
738
300
  }
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
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);
746
347
  }
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() {
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.not(':visible')){
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})
760
450
 
761
- }
451
+ this.$mask_target.append(this.$mask)
452
+ this.$mask.on('click', function(e){
453
+ e.preventDefault();
454
+ return false;
455
+ })
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
+ }
762
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);
763
544
 
764
- window.any_time_manager.registerListWithClasses({ 'sortable': 'AjaxSorter', 'ajax-link-now': 'AjaxLinkSubmission', 'ajax-form-now': 'AjaxFormSubmission' }, 'thin_man');
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
+ },
765
662
 
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
- });
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(){
773
768
 
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
- });
769
+ }
770
+ });
780
771
 
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
- });
772
+ window.any_time_manager.registerListWithClasses({'sortable' : 'AjaxSorter', 'ajax-link-now' : 'AjaxLinkSubmission', 'ajax-form-now' : 'AjaxFormSubmission'},'thin_man');
790
773
 
791
- $('[data-sortable]').each(function() {
792
- new thin_man.AjaxSorter($(this));
793
- });
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
+ });
781
+
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
+ });
794
788
 
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
+ });
795
798
 
799
+ $('[data-sortable]').each(function(){
800
+ new thin_man.AjaxSorter($(this));
796
801
  });
797
802
 
803
+
804
+ });
805
+
798
806
  };
799
807
 
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() {};
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(){};
811
818
 
812
- // Create a new Class that inherits from this class
813
- Class.extend = function(prop) {
814
- var _super = this.prototype;
819
+ // Create a new Class that inherits from this class
820
+ Class.extend = function(prop) {
821
+ var _super = this.prototype;
815
822
 
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;
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;
821
828
 
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;
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;
830
837
 
831
- // Add a new ._super() method that is the same method
832
- // but on the super-class
833
- this._super = _super[name];
838
+ // Add a new ._super() method that is the same method
839
+ // but on the super-class
840
+ this._super = _super[name];
834
841
 
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;
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;
839
846
 
840
- return ret;
841
- };
842
- })(name, prop[name]) :
843
- prop[name];
844
- }
847
+ return ret;
848
+ };
849
+ })(name, prop[name]) :
850
+ prop[name];
851
+ }
845
852
 
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
- }
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
+ }
852
859
 
853
- // Populate our constructed prototype object
854
- Class.prototype = prototype;
860
+ // Populate our constructed prototype object
861
+ Class.prototype = prototype;
855
862
 
856
- // Enforce the constructor to be what we expect
857
- Class.prototype.constructor = Class;
863
+ // Enforce the constructor to be what we expect
864
+ Class.prototype.constructor = Class;
858
865
 
859
- // And make this class extendable
860
- Class.extend = arguments.callee;
866
+ // And make this class extendable
867
+ Class.extend = arguments.callee;
861
868
 
862
- return Class;
863
- };
864
- })();
869
+ return Class;
870
+ };
871
+ })();
865
872
  }
866
873
 
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
- })
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
+ })
877
883
  }
878
884
 
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
- };
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
+ };
894
895
 
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
- }
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
+ };
953
900
 
954
- });
955
- });
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();
956
947
  }
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
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
971
977
  }
972
978
 
973
- initThinMan();
979
+ initThinMan();