thin_man 0.20.2 → 0.20.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/thin_man.js +997 -965
- data/lib/thin_man/ajax_helper.rb +39 -7
- data/lib/thin_man/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f3a3149a78c919863fc40928cbed440b12e8adbf944532241fd460c5ff8c77a
|
4
|
+
data.tar.gz: a328ba03fef1ea832ff05f9e1fefd7338234b6df4818a53bf3f87858605a30c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 297ff75de6284081cd2f5bde87ce29c30435a4f516df7f8c7d92a55d4b7c81a4bd4bb9577b5a8d1fdd0550160442a6f3132bc7b7e8e14c6393790b1dd01937b6
|
7
|
+
data.tar.gz: 5353f964208f3ad3aaeedf891aab222d4f735c9baf95a59579811252564ab2e52e908c5abdfd97081f779bf44c5676943c7b6c6e31eca762f93f6d88bd028de5
|
@@ -1,1047 +1,1079 @@
|
|
1
1
|
//= require simple_inheritance
|
2
2
|
//= require debug_logger
|
3
3
|
var initThinMan = function() {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
+
}
|
23
189
|
}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
return this_group
|
190
|
+
var extra_offset = 0
|
191
|
+
if ($('[data-thin-man-offset]').length > 0) {
|
192
|
+
extra_offset = $('[data-thin-man-offset]').outerHeight()
|
28
193
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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()
|
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)
|
62
214
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
}
|
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
|
-
if(this.shouldReplaceHistory()){
|
260
|
-
var new_url = [location.protocol, '//', location.host, '/', this.replacement_path].join('')
|
261
|
-
history['pushState']({}, null, new_url);
|
262
|
-
}
|
263
|
-
},
|
264
|
-
shouldReplaceHistory: function(){
|
265
|
-
this.replacement_path = this.jq_obj.data('replacement-path')
|
266
|
-
if(this.replacement_path){
|
267
|
-
if('/' === this.replacement_path[0]){
|
268
|
-
this.replacement_path = this.replacement_path.slice(1)
|
269
|
-
}
|
270
|
-
return true
|
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)
|
271
224
|
}
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
debug_logger.log("thin_man.AjaxSubmission.ajaxError responseText is not JSON, assuming a string:", 1, 'thin-man')
|
342
|
-
debug_logger.log(jqXHR.responseText, 1, 'thin-man')
|
343
|
-
var data = jqXHR.responseText;
|
344
|
-
debug_logger.log("thin_man.AjaxSubmission.ajaxError data to insert:", 1, 'thin-man')
|
345
|
-
debug_logger.log(data, 1, 'thin-man')
|
346
|
-
}
|
347
|
-
debug_logger.log("thin_man.AjaxSubmission.ajaxError error target:", 1, 'thin-man')
|
348
|
-
debug_logger.log(this.error_target, 1, 'thin-man')
|
349
|
-
debug_logger.log("thin_man.AjaxSubmission.ajaxError data:", 1, 'thin-man')
|
350
|
-
debug_logger.log(data, 1, 'thin-man')
|
351
|
-
if (typeof data === 'string') {
|
352
|
-
debug_logger.log("thin_man.AjaxSubmission.ajaxError data is a string, inserting into target.", 1, 'thin-man')
|
353
|
-
this.error_target.html(data);
|
354
|
-
} else if (typeof data === 'object') {
|
355
|
-
debug_logger.log("thin_man.AjaxSubmission.ajaxError data is an object.", 1, 'thin-man')
|
356
|
-
if (typeof data.html != 'undefined') {
|
357
|
-
debug_logger.log("thin_man.AjaxSubmission.ajaxError data.html exists, inserting into target.", 1, 'thin-man')
|
358
|
-
this.error_target.html(data.html);
|
359
|
-
}
|
360
|
-
}
|
361
|
-
} else if (jqXHR.status == 500) {
|
362
|
-
if (this.sendHelpLink()) {
|
363
|
-
if (window.confirm('There was an error communicating with the server. Please click "ok" to submit a bug report. If a new tab does not open, please disable pop up blocking and try again. Clicking "Cancel" will return you to the current page.')) { this.updateAndSubmitForm() };
|
364
|
-
} else {
|
365
|
-
window.alert('There was an error communicating with the server.')
|
366
|
-
}
|
367
|
-
}
|
368
|
-
},
|
369
|
-
sendHelpLink: function() {
|
370
|
-
var sendHelpLink = $("meta[name='sendHelpLink']").attr("content")
|
371
|
-
return (undefined !== sendHelpLink && "true" === sendHelpLink)
|
372
|
-
},
|
373
|
-
updateAndSubmitForm: function() {
|
374
|
-
var $form = $('#ajax-500-help')
|
375
|
-
var user = this.getCurrentUser()
|
376
|
-
var token = $("meta[name='helpToken']").attr("content")
|
377
|
-
|
378
|
-
$form.children('input[name="http_request_details[requested_path]"]').val(this.ajax_options.url)
|
379
|
-
$form.children('input[name="http_request_details[referred_from]"]').val(window.location.href)
|
380
|
-
$form.children('input[name="http_request_details[request_method]"]').val(this.ajax_options.type)
|
381
|
-
$form.children('input[name="http_request_details[data]"]').val(this.ajax_options.data)
|
382
|
-
$form.children('input[name="submission[occured_at]"]').val(new Date())
|
383
|
-
$form.children('input[name="submission[url]"]').val(window.location.href)
|
384
|
-
$form.children('input[name="submission[url]"]').val(window.location.href)
|
385
|
-
$form.children('input[name="user[name]"]').val(user.name)
|
386
|
-
$form.children('input[name="user[email]"]').val(user.email)
|
387
|
-
$form.children('input[name="user[time_zone]"]').val(user.time_zone)
|
388
|
-
$form.children('input[name="token"]').val(token)
|
389
|
-
$form.submit()
|
390
|
-
},
|
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
|
+
if (typeof data.replacement_path != 'undefined') {
|
239
|
+
this.replacement_path = data.replacement_path
|
240
|
+
}
|
241
|
+
if (typeof data.push_path != 'undefined') {
|
242
|
+
this.push_path = data.push_path
|
243
|
+
}
|
244
|
+
}
|
245
|
+
if (this.target) {
|
246
|
+
var ajax_flash = this.target.children().last().data('ajax-flash');
|
247
|
+
if ((jqXHR.status == 200) && ajax_flash) {
|
248
|
+
new thin_man.AjaxFlash('success', ajax_flash.notice, this.target);
|
249
|
+
}
|
250
|
+
}
|
251
|
+
if (this.removeOnSuccess()) {
|
252
|
+
if ($(this.removeOnSuccess())) {
|
253
|
+
$(this.removeOnSuccess()).remove();
|
254
|
+
}
|
255
|
+
}
|
256
|
+
if (this.emptyOnSuccess()) {
|
257
|
+
if ($(this.emptyOnSuccess())) {
|
258
|
+
$(this.emptyOnSuccess()).empty();
|
259
|
+
}
|
260
|
+
}
|
261
|
+
if ($.contains(document, this.jq_obj[0])) {
|
262
|
+
this.jq_obj.find('.error').removeClass('error')
|
263
|
+
this.jq_obj.find('.help-inline').remove()
|
264
|
+
}
|
265
|
+
this.handleHistory()
|
266
|
+
},
|
267
|
+
handleHistory: function(){
|
268
|
+
if(!this.replacement_path){ //if it wasn't passed in the response, look for it on the trigger object
|
269
|
+
this.replacement_path = this.jq_obj.data('replacement-path')
|
270
|
+
}
|
271
|
+
if(this.replacement_path){
|
272
|
+
this.handleReplaceState()
|
273
|
+
}
|
274
|
+
if(!this.push_path){ //if it wasn't passed in the response, look for it on the trigger object
|
275
|
+
this.push_path = this.jq_obj.data('push-path')
|
276
|
+
}
|
277
|
+
if(this.push_path){
|
278
|
+
this.handlePushState()
|
279
|
+
}
|
280
|
+
},
|
281
|
+
handleReplaceState: function(){
|
282
|
+
if('/' === this.replacement_path[0]){
|
283
|
+
this.replacement_path = this.replacement_path.slice(1)
|
284
|
+
}
|
285
|
+
var new_url = [location.protocol, '//', location.host, '/', this.replacement_path].join('')
|
286
|
+
history['replaceState']({}, null, new_url);
|
287
|
+
},
|
288
|
+
handlePushState: function(){
|
289
|
+
if('/' === this.push_path[0]){
|
290
|
+
this.push_path = this.push_path.slice(1)
|
291
|
+
}
|
292
|
+
var new_url = [location.protocol, '//', location.host, '/', this.push_path].join('')
|
293
|
+
history['pushState']({path: ('/' + this.push_path), target: this.target}, null, new_url);
|
391
294
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
noMouseClick: function() {
|
432
|
-
return this.jq_obj.data('no-mouse-click')
|
433
|
-
}
|
434
|
-
}),
|
435
|
-
AjaxBrowserPushConnector: Class.extend({
|
436
|
-
init: function($connector) {
|
437
|
-
this.trigger = $connector.find('button, input[type="submit"]');
|
438
|
-
if (this.trigger.length < 1) {
|
439
|
-
this.trigger = $connector;
|
440
|
-
}
|
441
|
-
this.browser_push_progress_indicator = new thin_man.AjaxProgress(this.trigger, this.trigger, this.progress_color);
|
442
|
-
$connector.data('browser-push-progress-indicator-object', this.browser_push_progress_indicator);
|
443
|
-
}
|
444
|
-
}),
|
445
|
-
AjaxBrowserPushFlash: Class.extend({
|
446
|
-
init: function($flash) {
|
447
|
-
this.message = $flash.data('ajax-browser-push-flash')
|
448
|
-
this.$target = $($flash.data('ajax-browser-push-flash-target'));
|
449
|
-
this.$target.data('ajax-browser-push-flash', this.message);
|
295
|
+
},
|
296
|
+
addWatcher: function(watcher) {
|
297
|
+
if (!this.hasOwnProperty('watchers')) {
|
298
|
+
this.watchers = []
|
299
|
+
}
|
300
|
+
this.watchers.push(watcher)
|
301
|
+
},
|
302
|
+
notifyWatchers: function() {
|
303
|
+
$.each(this.watchers, function() {
|
304
|
+
this.linkCompleted(this)
|
305
|
+
})
|
306
|
+
},
|
307
|
+
ajaxComplete: function(jqXHR) {
|
308
|
+
debug_logger.log('thin_man.AjaxSubmission.ajaxComplete jqXHR:', 1, 'thin-man')
|
309
|
+
debug_logger.log(jqXHR, 1, 'thin-man')
|
310
|
+
this.showTrigger();
|
311
|
+
this.notifyWatchers();
|
312
|
+
if (this.progress_indicator) {
|
313
|
+
this.progress_indicator.stop();
|
314
|
+
} else if (!this.trigger_is_progress_target) {
|
315
|
+
this.progress_target.remove();
|
316
|
+
}
|
317
|
+
if (typeof this.mask != 'undefined') {
|
318
|
+
this.mask.remove();
|
319
|
+
}
|
320
|
+
try {
|
321
|
+
var response_data = JSON.parse(jqXHR.responseText)
|
322
|
+
} catch (err) {
|
323
|
+
var response_data = {}
|
324
|
+
// hmmm, the response is not JSON, so there's no flash.
|
325
|
+
}
|
326
|
+
if (typeof response_data.flash_message != 'undefined') {
|
327
|
+
var flash_style = this.httpResponseToFlashStyle(jqXHR.status);
|
328
|
+
var flash_duration = null;
|
329
|
+
if (typeof response_data.flash_persist != 'undefined') {
|
330
|
+
if (response_data.flash_persist) {
|
331
|
+
flash_duration = 'persist'
|
332
|
+
} else {
|
333
|
+
flash_duration = 'fade'
|
450
334
|
}
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
335
|
+
}
|
336
|
+
if (this.target) {
|
337
|
+
this.flash = new thin_man.AjaxFlash(flash_style, response_data.flash_message, this.target, flash_duration);
|
338
|
+
} else {
|
339
|
+
this.flash = new thin_man.AjaxFlash(flash_style, response_data.flash_message, this.jq_obj, flash_duration);
|
340
|
+
}
|
341
|
+
}
|
342
|
+
if ('function' == typeof this.params.on_complete) {
|
343
|
+
this.params.on_complete()
|
344
|
+
}
|
345
|
+
},
|
346
|
+
ajaxBefore: function(jqXHr) {
|
347
|
+
this.toggleLoading();
|
348
|
+
if (!this.custom_progress) {
|
349
|
+
this.progress_indicator = new thin_man.AjaxProgress(this.progress_target, this.target, this.progress_color);
|
350
|
+
}
|
351
|
+
if (this.$mask_target) {
|
352
|
+
this.mask = new thin_man.AjaxMask(this.$mask_target, this.$mask_message)
|
353
|
+
}
|
354
|
+
},
|
355
|
+
ajaxError: function(jqXHR) {
|
356
|
+
debug_logger.log('thin_man.AjaxSubmission.ajaxError jqXHR:', 1, 'thin-man')
|
357
|
+
debug_logger.log(jqXHR, 1, 'thin-man')
|
358
|
+
if ([409,422,424,428].indexOf(jqXHR.status) >= 0) {
|
359
|
+
try {
|
360
|
+
var data = JSON.parse(jqXHR.responseText);
|
361
|
+
debug_logger.log("thin_man.AjaxSubmission.ajaxError responseText is valid JSON, parsing to an object:", 1, 'thin-man')
|
362
|
+
} catch (error) {
|
363
|
+
debug_logger.log("thin_man.AjaxSubmission.ajaxError responseText is not JSON, assuming a string:", 1, 'thin-man')
|
364
|
+
debug_logger.log(jqXHR.responseText, 1, 'thin-man')
|
365
|
+
var data = jqXHR.responseText;
|
366
|
+
debug_logger.log("thin_man.AjaxSubmission.ajaxError data to insert:", 1, 'thin-man')
|
367
|
+
debug_logger.log(data, 1, 'thin-man')
|
368
|
+
}
|
369
|
+
debug_logger.log("thin_man.AjaxSubmission.ajaxError error target:", 1, 'thin-man')
|
370
|
+
debug_logger.log(this.error_target, 1, 'thin-man')
|
371
|
+
debug_logger.log("thin_man.AjaxSubmission.ajaxError data:", 1, 'thin-man')
|
372
|
+
debug_logger.log(data, 1, 'thin-man')
|
373
|
+
if (typeof data === 'string') {
|
374
|
+
debug_logger.log("thin_man.AjaxSubmission.ajaxError data is a string, inserting into target.", 1, 'thin-man')
|
375
|
+
this.error_target.html(data);
|
376
|
+
} else if (typeof data === 'object') {
|
377
|
+
debug_logger.log("thin_man.AjaxSubmission.ajaxError data is an object.", 1, 'thin-man')
|
378
|
+
if (typeof data.html != 'undefined') {
|
379
|
+
debug_logger.log("thin_man.AjaxSubmission.ajaxError data.html exists, inserting into target.", 1, 'thin-man')
|
380
|
+
this.error_target.html(data.html);
|
485
381
|
}
|
486
|
-
|
487
|
-
|
382
|
+
}
|
383
|
+
} else if (jqXHR.status == 500) {
|
384
|
+
if (this.sendHelpLink()) {
|
385
|
+
if (window.confirm('There was an error communicating with the server. Please click "ok" to submit a bug report. If a new tab does not open, please disable pop up blocking and try again. Clicking "Cancel" will return you to the current page.')) { this.updateAndSubmitForm() };
|
386
|
+
} else {
|
387
|
+
window.alert('There was an error communicating with the server.')
|
388
|
+
}
|
389
|
+
}
|
390
|
+
},
|
391
|
+
sendHelpLink: function() {
|
392
|
+
var sendHelpLink = $("meta[name='sendHelpLink']").attr("content")
|
393
|
+
return (undefined !== sendHelpLink && "true" === sendHelpLink)
|
394
|
+
},
|
395
|
+
updateAndSubmitForm: function() {
|
396
|
+
var $form = $('#ajax-500-help')
|
397
|
+
var user = this.getCurrentUser()
|
398
|
+
var token = $("meta[name='helpToken']").attr("content")
|
399
|
+
|
400
|
+
$form.children('input[name="http_request_details[requested_path]"]').val(this.ajax_options.url)
|
401
|
+
$form.children('input[name="http_request_details[referred_from]"]').val(window.location.href)
|
402
|
+
$form.children('input[name="http_request_details[request_method]"]').val(this.ajax_options.type)
|
403
|
+
$form.children('input[name="http_request_details[data]"]').val(this.ajax_options.data)
|
404
|
+
$form.children('input[name="submission[occured_at]"]').val(new Date())
|
405
|
+
$form.children('input[name="submission[url]"]').val(window.location.href)
|
406
|
+
$form.children('input[name="submission[url]"]').val(window.location.href)
|
407
|
+
$form.children('input[name="user[name]"]').val(user.name)
|
408
|
+
$form.children('input[name="user[email]"]').val(user.email)
|
409
|
+
$form.children('input[name="user[time_zone]"]').val(user.time_zone)
|
410
|
+
$form.children('input[name="token"]').val(token)
|
411
|
+
$form.submit()
|
412
|
+
},
|
413
|
+
|
414
|
+
getCurrentUser: function() {
|
415
|
+
user = {
|
416
|
+
name: $("meta[name='userName']").attr("content"),
|
417
|
+
email: $("meta[name='userEmail']").attr("content"),
|
418
|
+
time_zone: $("meta[name='userTimeZone']").attr("content")
|
419
|
+
}
|
420
|
+
return user
|
421
|
+
},
|
422
|
+
getTrigger: function() {},
|
423
|
+
hideTrigger: function() {},
|
424
|
+
showTrigger: function() {},
|
425
|
+
toggleLoading: function() {
|
426
|
+
if (this.target) {
|
427
|
+
if (this.target.find('[data-loading-visible="false"]').length > 0) {
|
428
|
+
this.target.find('[data-loading-visible="false"]').hide();
|
429
|
+
}
|
430
|
+
if (this.target.find('[data-loading-visible="true"]').length > 0) {
|
431
|
+
this.target.find('[data-loading-visible="true"]').show();
|
432
|
+
}
|
433
|
+
}
|
434
|
+
},
|
435
|
+
removeOnSuccess: function() {
|
436
|
+
return this.jq_obj.data('remove-on-success')
|
437
|
+
},
|
438
|
+
emptyOnSuccess: function() {
|
439
|
+
return this.jq_obj.data('empty-on-success')
|
440
|
+
},
|
441
|
+
httpResponseToFlashStyle: function(response_code) {
|
442
|
+
if ([403, 409, 500].indexOf(response_code) > -1) {
|
443
|
+
return 'error'
|
444
|
+
}
|
445
|
+
if ([200, 202].indexOf(response_code) > -1) {
|
446
|
+
return 'success'
|
447
|
+
}
|
448
|
+
return 'error'
|
449
|
+
},
|
450
|
+
wasMouseClicked: function() {
|
451
|
+
return this.params.e && this.params.e.type && this.params.e.type == 'click'
|
452
|
+
},
|
453
|
+
noMouseClick: function() {
|
454
|
+
return this.jq_obj.data('no-mouse-click')
|
455
|
+
}
|
456
|
+
}),
|
457
|
+
AjaxBrowserPushConnector: Class.extend({
|
458
|
+
init: function($connector) {
|
459
|
+
this.trigger = $connector.find('button, input[type="submit"]');
|
460
|
+
if (this.trigger.length < 1) {
|
461
|
+
this.trigger = $connector;
|
462
|
+
}
|
463
|
+
this.browser_push_progress_indicator = new thin_man.AjaxProgress(this.trigger, this.trigger, this.progress_color);
|
464
|
+
$connector.data('browser-push-progress-indicator-object', this.browser_push_progress_indicator);
|
465
|
+
}
|
466
|
+
}),
|
467
|
+
AjaxBrowserPushFlash: Class.extend({
|
468
|
+
init: function($flash) {
|
469
|
+
this.message = $flash.data('ajax-browser-push-flash')
|
470
|
+
this.$target = $($flash.data('ajax-browser-push-flash-target'));
|
471
|
+
this.$target.data('ajax-browser-push-flash', this.message);
|
472
|
+
}
|
473
|
+
}),
|
474
|
+
AjaxProgress: Class.extend({
|
475
|
+
init: function(target, alt, progress_color) {
|
476
|
+
if (target.length > 0 && target.is(':visible') && target.css('display') != 'inline' && target.css('display') != 'inline-block') {
|
477
|
+
this.progress_target = target;
|
478
|
+
} else if (typeof(alt) != 'undefined' && alt.is(':visible')) {
|
479
|
+
this.progress_target = alt;
|
480
|
+
} else if (target.length > 0 && target.is(':hidden')) {
|
481
|
+
this.progress_target = $('')
|
482
|
+
} else {
|
483
|
+
this.progress_target = $('body');
|
484
|
+
}
|
485
|
+
if (typeof(progress_color) == 'undefined') {
|
486
|
+
var progress_color = 'black';
|
487
|
+
}
|
488
|
+
this.progress_container = $('#ajax_progress_container').clone();
|
489
|
+
var uuid = new UUID;
|
490
|
+
this.progress_container.prop('id', 'thin_man_ajax_progress_' + uuid.value);
|
491
|
+
this.progress_target.append(this.progress_container);
|
492
|
+
var css = { display: 'block', visibility: 'visible', 'color': progress_color, 'z-index': 1000000 }
|
493
|
+
$.extend(css, {
|
494
|
+
position: 'absolute',
|
495
|
+
top: '50%',
|
496
|
+
left: '50%',
|
497
|
+
'-ms-transform': 'translate(-50%, -50%)',
|
498
|
+
/* IE 9 */
|
499
|
+
'-webkit-transform': 'translate(-50%, -50%)',
|
500
|
+
/* Safari */
|
501
|
+
'transform': 'translate(-50%, -50%)'
|
502
|
+
})
|
503
|
+
this.progress_container.css(css)
|
504
|
+
},
|
505
|
+
stop: function() {
|
506
|
+
this.progress_container.remove();
|
507
|
+
}
|
508
|
+
}),
|
509
|
+
AjaxMask: Class.extend({
|
488
510
|
init: function($mask_target, mask_message) {
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
511
|
+
var uuid = new UUID;
|
512
|
+
this.$mask_target = $mask_target
|
513
|
+
this.$mask = $('#thin_man_mask').clone()
|
514
|
+
this.$mask.prop('id', 'thin_man_mask' + uuid.value)
|
515
|
+
if (typeof mask_message != 'undefined') {
|
516
|
+
var $message = this.$mask.find('[data-thin-man-mask-message]')
|
517
|
+
$message.html(mask_message)
|
518
|
+
}
|
519
|
+
var height = this.$mask_target.outerHeight()
|
520
|
+
var width = this.$mask_target.outerWidth()
|
521
|
+
var radius = this.$mask_target.css('border-radius')
|
522
|
+
this.$mask.css({ 'height': height, 'width': width, 'left': 0, 'top': 0, 'border-radius': radius })
|
523
|
+
this.$mask.css({ 'position': 'absolute', 'z-index': 10000 })
|
502
524
|
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
525
|
+
this.$mask_target.append(this.$mask)
|
526
|
+
this.$mask.on('click mousedown mousemove', function(e) {
|
527
|
+
e.preventDefault();
|
528
|
+
return false;
|
529
|
+
})
|
530
|
+
this.$mask.show()
|
509
531
|
},
|
510
532
|
remove: function() {
|
511
|
-
|
533
|
+
this.$mask.remove()
|
512
534
|
}
|
513
|
-
|
514
|
-
|
535
|
+
}),
|
536
|
+
AjaxFlash: Class.extend({
|
515
537
|
init: function(type, message, elem, duration) {
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
538
|
+
this.flash_container = $('[data-thin-man-flash-template]').clone();
|
539
|
+
this.flash_container.removeAttr('data-thin-man-flash-template');
|
540
|
+
this.flash_container.attr('data-thin-man-flash-container', true);
|
541
|
+
$('body').append(this.flash_container);
|
542
|
+
this.flash_container.css({ position: 'absolute', visibility: 'hidden' });
|
543
|
+
this.alert_type = type;
|
544
|
+
this.elem = elem;
|
545
|
+
var alert_class = 'alert-' + type;
|
546
|
+
this.flash_container.addClass(alert_class);
|
547
|
+
this.flash_content = this.flash_container.find('[data-thin-man-flash-content]');
|
548
|
+
this.flash_content.html(message);
|
549
|
+
this.flash_container.show();
|
550
|
+
this.setFadeBehavior(duration);
|
551
|
+
this.reposition(elem);
|
552
|
+
this.bindDismisser();
|
531
553
|
},
|
532
554
|
setFadeBehavior: function(duration) {
|
533
|
-
|
555
|
+
if (duration) {
|
534
556
|
if ('persist' == duration) {
|
535
|
-
|
557
|
+
this.fade = false
|
536
558
|
} else {
|
537
|
-
|
559
|
+
this.fade = true
|
538
560
|
}
|
539
|
-
|
561
|
+
} else { //default behavior if persist duration is not sent back with message
|
540
562
|
if ('error' == this.alert_type || 'warning' == this.alert_type || 'info' == this.alert_type) {
|
541
|
-
|
563
|
+
this.fade = false;
|
542
564
|
} else {
|
543
|
-
|
565
|
+
this.fade = true;
|
544
566
|
}
|
545
|
-
|
567
|
+
}
|
546
568
|
},
|
547
569
|
reposition: function(elem) {
|
548
|
-
|
570
|
+
var this_window = {
|
549
571
|
top: $(window).scrollTop(),
|
550
572
|
left: $(window).scrollLeft(),
|
551
573
|
height: $(window).outerHeight(),
|
552
574
|
width: $(window).outerWidth()
|
553
|
-
|
554
|
-
|
575
|
+
};
|
576
|
+
var this_flash = {
|
555
577
|
height: this.flash_container.outerHeight(),
|
556
578
|
width: this.flash_container.outerWidth()
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
579
|
+
}
|
580
|
+
this_window.vert_middle = (this_window.top + (this_window.height / 2));
|
581
|
+
this_window.horiz_middle = (this_window.left + (this_window.width / 2));
|
582
|
+
this_flash.half_height = (this_flash.height / 2);
|
583
|
+
this_flash.half_width = (this_flash.width / 2);
|
584
|
+
var new_top = this_window.vert_middle - this_flash.half_height;
|
585
|
+
var new_left = this_window.horiz_middle - this_flash.half_width;
|
586
|
+
this.flash_container.css({ left: new_left, top: new_top, visibility: 'visible' });
|
587
|
+
var ajax_flash = this;
|
588
|
+
if (this.fade) {
|
567
589
|
setTimeout(function() { ajax_flash.fadeOut() }, 1618);
|
568
|
-
|
590
|
+
}
|
569
591
|
},
|
570
592
|
fadeOut: function() {
|
571
|
-
|
593
|
+
this.flash_container.fadeOut('slow');
|
572
594
|
},
|
573
595
|
bindDismisser: function() {
|
574
|
-
|
575
|
-
|
576
|
-
|
596
|
+
this.$dismisser = this.flash_container.find('[data-dismiss]')
|
597
|
+
var ajax_flash = this
|
598
|
+
this.$dismisser.on('click', function(){
|
577
599
|
ajax_flash.flash_container.remove()
|
578
|
-
|
600
|
+
})
|
579
601
|
}
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
602
|
+
}),
|
603
|
+
AjaxSorter: Class.extend({
|
604
|
+
init: function($sort_container) {
|
605
|
+
var base_url = $sort_container.data('url');
|
606
|
+
$sort_container.sortable({
|
607
|
+
helper: "clone",
|
608
|
+
tolerance: 'pointer',
|
609
|
+
stop: function(event, ui) {
|
610
|
+
new thin_man.AjaxSortSubmission($sort_container);
|
611
|
+
}
|
612
|
+
});
|
613
|
+
$sort_container.disableSelection();
|
614
|
+
}
|
615
|
+
})
|
616
|
+
};
|
617
|
+
thin_man.AjaxFormSubmission = thin_man.AjaxSubmission.extend({
|
618
|
+
getAjaxUrl: function() {
|
619
|
+
return this.jq_obj.attr('action');
|
620
|
+
},
|
621
|
+
getAjaxType: function() {
|
622
|
+
return this.jq_obj.attr('method') || 'POST'
|
623
|
+
},
|
624
|
+
getData: function() {
|
625
|
+
var $clicked = $(document.activeElement);
|
626
|
+
var browserTabId = $("meta[name='browser_tab_id']").attr("content");
|
605
627
|
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
628
|
+
if ($clicked.length && $clicked.is('button[type="submit"], input[type="submit"], input[type="image"]') && $clicked.is('[name]')) {
|
629
|
+
var button_name = $clicked.attr('name')
|
630
|
+
var button_value = $clicked.attr('value')
|
631
|
+
}
|
632
|
+
var event_data = this.params
|
633
|
+
if (!event_data.hasOwnProperty('e')) {
|
634
|
+
var thin_man_submitter = 'link_now'
|
635
|
+
} else {
|
636
|
+
var thin_man_submitter = this.params['e'].type
|
637
|
+
}
|
638
|
+
if ((this.getAjaxType().toLowerCase() == 'get') || (typeof FormData == 'undefined')) {
|
639
|
+
var data_array = this.jq_obj.serializeArray();
|
640
|
+
if (button_name && button_value) {
|
641
|
+
data_array.push({ name: button_name, value: button_value })
|
642
|
+
}
|
643
|
+
data_array.push(
|
622
644
|
{ name: 'thin_man_submitter', value: thin_man_submitter },
|
623
645
|
{ name: 'browser_tab_id', value: browserTabId }
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
}
|
636
|
-
}
|
637
|
-
if (typeof fd.set != 'undefined') {
|
638
|
-
fd.set('thin_man_submitter', thin_man_submitter)
|
639
|
-
fd.set('browser_tab_id', browserTabId)
|
640
|
-
} else if (typeof fd.append != 'undefined') {
|
641
|
-
fd.append('thin_man_submitter', thin_man_submitter)
|
642
|
-
fd.append('browser_tab_id', browserTabId)
|
643
|
-
}
|
644
|
-
return fd
|
645
|
-
}
|
646
|
-
},
|
647
|
-
ajaxSuccess: function(data, textStatus, jqXHR) {
|
648
|
-
debug_logger.log('thin_man.AjaxFormSubmission.ajaxSuccess', 1, 'thin-man')
|
649
|
-
this._super(data, textStatus, jqXHR)
|
650
|
-
if (this.resetOnSuccess()) {
|
651
|
-
this.jq_obj[0].reset();
|
652
|
-
$(this.jq_obj).find('input[type=text],textarea,select').filter(':visible:first').focus();
|
653
|
-
}
|
654
|
-
},
|
655
|
-
resetOnSuccess: function() {
|
656
|
-
return this.jq_obj.data('reset-on-success')
|
657
|
-
},
|
658
|
-
getProcessData: function() {
|
659
|
-
if (this.getAjaxType().toLowerCase() == 'get') {
|
660
|
-
return true;
|
661
|
-
} else {
|
662
|
-
return false;
|
663
|
-
}
|
664
|
-
},
|
665
|
-
sendContentType: function() {
|
666
|
-
if (this.getAjaxType().toLowerCase() == 'get') {
|
667
|
-
return true;
|
668
|
-
} else {
|
669
|
-
return false;
|
670
|
-
}
|
671
|
-
},
|
672
|
-
getTrigger: function() {
|
673
|
-
this.trigger = this.jq_obj.find('button, input[type="submit"]');
|
674
|
-
if (this.trigger.length != 1) {
|
675
|
-
var $active_element = $(document.activeElement)
|
676
|
-
if ($active_element[0].nodeName.toLowerCase() != 'body') {
|
677
|
-
this.trigger = $active_element
|
678
|
-
}
|
679
|
-
}
|
680
|
-
},
|
681
|
-
hideTrigger: function() {
|
682
|
-
this.trigger.css('visibility', 'hidden');
|
683
|
-
},
|
684
|
-
showTrigger: function() {
|
685
|
-
this.trigger.css('visibility', 'visible');
|
686
|
-
}
|
687
|
-
}),
|
688
|
-
thin_man.AjaxLinkSubmission = thin_man.AjaxSubmission.extend({
|
689
|
-
getAjaxUrl: function() {
|
690
|
-
if (this.search_path) {
|
691
|
-
if (this.search_params) {
|
692
|
-
return this.search_path + '?' + this.search_params
|
693
|
-
} else {
|
694
|
-
return this.search_path
|
695
|
-
}
|
696
|
-
} else {
|
697
|
-
return this.jq_obj.attr('href');
|
698
|
-
}
|
699
|
-
},
|
700
|
-
getData: function() {
|
701
|
-
var this_data = { authenticity_token: $('[name="csrf-token"]').attr('content'), browser_tab_id: $("meta[name='browser_tab_id']").attr("content") };
|
702
|
-
if (this.jq_obj.data('form-data')) {
|
703
|
-
$.extend(this_data, this.jq_obj.data('form-data'))
|
704
|
-
}
|
705
|
-
return this_data
|
706
|
-
},
|
707
|
-
getProcessData: function() {
|
708
|
-
return true;
|
709
|
-
},
|
710
|
-
getAjaxType: function() {
|
711
|
-
return this.jq_obj.data('ajax-method') || 'GET'
|
712
|
-
},
|
713
|
-
getTrigger: function() {
|
714
|
-
this.trigger = this.jq_obj;
|
715
|
-
},
|
716
|
-
hideTrigger: function() {
|
717
|
-
this.trigger.css('visibility', 'hidden');
|
718
|
-
},
|
719
|
-
showTrigger: function() {
|
720
|
-
this.trigger.css('visibility', 'visible');
|
721
|
-
},
|
722
|
-
refocus: function() {
|
723
|
-
if (this.jq_obj.data('ajax-link-now')) {
|
724
|
-
return false
|
725
|
-
}
|
726
|
-
return true
|
727
|
-
},
|
728
|
-
|
729
|
-
}),
|
730
|
-
thin_man.AjaxModalOpener = thin_man.AjaxLinkSubmission.extend({
|
731
|
-
ajaxSuccess: function(data, textStatus, jqXHR) {
|
732
|
-
this._super(data, textStatus, jqXHR);
|
733
|
-
$(this.jq_obj.data('ajax-modal')).modal();
|
734
|
-
}
|
735
|
-
}),
|
736
|
-
thin_man.AddALineForm = thin_man.AjaxFormSubmission.extend({
|
737
|
-
ajaxSuccess: function(data, textStatus, jqXHR) {
|
738
|
-
this._super(data, textStatus, jqXHR);
|
739
|
-
$(this.jq_obj.data('container')).empty();
|
740
|
-
},
|
741
|
-
ajaxError: function(jqXHR) {
|
742
|
-
this.insert_method = 'html';
|
743
|
-
this._super(jqXHR);
|
744
|
-
}
|
745
|
-
}),
|
746
|
-
thin_man.EmptyForm = thin_man.AjaxFormSubmission.extend({
|
747
|
-
ajaxSuccess: function(data, textStatus, jqXHR) {
|
748
|
-
var clicked_button = $("input[type=submit][clicked=true]")[0];
|
749
|
-
this._super(data, textStatus, jqXHR);
|
750
|
-
if ($(clicked_button).data('clone') != true) {
|
751
|
-
$(this.jq_obj)[0].reset();
|
752
|
-
};
|
753
|
-
$(this.jq_obj).find('input[type=text],textarea,select').filter(':visible:first').focus();
|
754
|
-
$("[data-autocomplete]").trigger("chosen:updated");
|
755
|
-
},
|
756
|
-
ajaxError: function(jqXHR) {
|
757
|
-
this.insert_method = 'html';
|
758
|
-
this._super(jqXHR);
|
759
|
-
}
|
760
|
-
}),
|
761
|
-
thin_man.ModalCloserForm = thin_man.AjaxFormSubmission.extend({
|
762
|
-
ajaxSuccess: function(data, textStatus, jqXHR) {
|
763
|
-
this._super(data, textStatus, jqXHR);
|
764
|
-
$modal = $(this.jq_obj.data('modal-container'));
|
765
|
-
$modal.modal('hide');
|
766
|
-
$modal.remove();
|
767
|
-
},
|
768
|
-
ajaxError: function(jqXHR) {
|
769
|
-
this._super(jqXHR);
|
770
|
-
$modal = $(this.jq_obj.data('modal-container'));
|
771
|
-
$modal.modal();
|
772
|
-
}
|
773
|
-
}),
|
774
|
-
thin_man.ResetOnSubmitForm = thin_man.AjaxFormSubmission.extend({
|
775
|
-
ajaxSuccess: function(data, textStatus, jqXHR) {
|
776
|
-
this._super(data, textStatus, jqXHR);
|
777
|
-
$(this.jq_obj).each(function() {
|
778
|
-
this.reset();
|
779
|
-
});
|
780
|
-
}
|
781
|
-
}),
|
782
|
-
thin_man.DeleteLink = thin_man.AjaxSubmission.extend({
|
783
|
-
ajaxSuccess: function(data, textStatus, jqXHR) {
|
784
|
-
this._super(data, textStatus, jqXHR);
|
785
|
-
if (this.jq_obj.data('replace-response')) {
|
786
|
-
this.insertHtml(data);
|
787
|
-
} else {
|
788
|
-
if (this.target) {
|
789
|
-
this.target.remove();
|
790
|
-
}
|
791
|
-
}
|
792
|
-
},
|
793
|
-
getTrigger: function() {
|
794
|
-
this.trigger = this.jq_obj;
|
795
|
-
},
|
796
|
-
getAjaxType: function() {
|
797
|
-
return 'DELETE';
|
798
|
-
},
|
799
|
-
getAjaxUrl: function() {
|
800
|
-
return this.jq_obj.attr('href');
|
801
|
-
},
|
802
|
-
getData: function() {
|
803
|
-
return { authenticity_token: $('[name="csrf-token"]').attr('content'), browser_tab_id: $("meta[name='browser_tab_id']").attr("content") };
|
804
|
-
},
|
805
|
-
getProcessData: function() {
|
806
|
-
return true;
|
807
|
-
},
|
808
|
-
ajaxBefore: function(jqXHR) {
|
809
|
-
if (!this.jq_obj.data('no-confirm')) {
|
810
|
-
return confirm("Are you sure you want to delete this?");
|
811
|
-
}
|
812
|
-
}
|
813
|
-
}),
|
814
|
-
thin_man.ReplaceDelete = thin_man.DeleteLink.extend({
|
815
|
-
ajaxSuccess: function(data, textStatus, jqXHR) {
|
816
|
-
this.target[this.insert_method](data);
|
817
|
-
},
|
818
|
-
ajaxBefore: function(jqXHR) {
|
819
|
-
//noop
|
646
|
+
)
|
647
|
+
return data_array;
|
648
|
+
} else {
|
649
|
+
// need to implement a data-attribute for multiple file fields so we can allow selecting mutliple files at once. example here:
|
650
|
+
// http://stackoverflow.com/questions/12989442/uploading-multiple-files-using-formdata
|
651
|
+
var fd = new FormData(this.jq_obj[0]);
|
652
|
+
if (button_name && button_value) {
|
653
|
+
if (typeof fd.set != 'undefined') {
|
654
|
+
fd.set(button_name, button_value)
|
655
|
+
} else if (typeof fd.append != 'undefined') {
|
656
|
+
fd.append(button_name, button_value)
|
820
657
|
}
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
658
|
+
}
|
659
|
+
if (typeof fd.set != 'undefined') {
|
660
|
+
fd.set('thin_man_submitter', thin_man_submitter)
|
661
|
+
fd.set('browser_tab_id', browserTabId)
|
662
|
+
} else if (typeof fd.append != 'undefined') {
|
663
|
+
fd.append('thin_man_submitter', thin_man_submitter)
|
664
|
+
fd.append('browser_tab_id', browserTabId)
|
665
|
+
}
|
666
|
+
return fd
|
667
|
+
}
|
668
|
+
},
|
669
|
+
ajaxSuccess: function(data, textStatus, jqXHR) {
|
670
|
+
debug_logger.log('thin_man.AjaxFormSubmission.ajaxSuccess', 1, 'thin-man')
|
671
|
+
this._super(data, textStatus, jqXHR)
|
672
|
+
if (this.resetOnSuccess()) {
|
673
|
+
this.jq_obj[0].reset();
|
674
|
+
$(this.jq_obj).find('input[type=text],textarea,select').filter(':visible:first').focus();
|
675
|
+
}
|
676
|
+
},
|
677
|
+
resetOnSuccess: function() {
|
678
|
+
return this.jq_obj.data('reset-on-success')
|
679
|
+
},
|
680
|
+
getProcessData: function() {
|
681
|
+
if (this.getAjaxType().toLowerCase() == 'get') {
|
682
|
+
return true;
|
683
|
+
} else {
|
684
|
+
return false;
|
685
|
+
}
|
686
|
+
},
|
687
|
+
sendContentType: function() {
|
688
|
+
if (this.getAjaxType().toLowerCase() == 'get') {
|
689
|
+
return true;
|
690
|
+
} else {
|
691
|
+
return false;
|
692
|
+
}
|
693
|
+
},
|
694
|
+
getTrigger: function() {
|
695
|
+
this.trigger = this.jq_obj.find('button, input[type="submit"]');
|
696
|
+
if (this.trigger.length != 1) {
|
697
|
+
var $active_element = $(document.activeElement)
|
698
|
+
if ($active_element[0].nodeName.toLowerCase() != 'body') {
|
699
|
+
this.trigger = $active_element
|
700
|
+
}
|
701
|
+
}
|
702
|
+
},
|
703
|
+
hideTrigger: function() {
|
704
|
+
this.trigger.css('visibility', 'hidden');
|
705
|
+
},
|
706
|
+
showTrigger: function() {
|
707
|
+
this.trigger.css('visibility', 'visible');
|
708
|
+
}
|
709
|
+
}),
|
710
|
+
thin_man.AjaxLinkSubmission = thin_man.AjaxSubmission.extend({
|
711
|
+
getAjaxUrl: function() {
|
712
|
+
if (this.search_path) {
|
713
|
+
if (this.search_params) {
|
714
|
+
return this.search_path + '?' + this.search_params
|
715
|
+
} else {
|
716
|
+
return this.search_path
|
717
|
+
}
|
718
|
+
} else {
|
719
|
+
return this.jq_obj.attr('href');
|
720
|
+
}
|
721
|
+
},
|
722
|
+
getData: function() {
|
723
|
+
var this_data = { authenticity_token: $('[name="csrf-token"]').attr('content'), browser_tab_id: $("meta[name='browser_tab_id']").attr("content") };
|
724
|
+
if (this.jq_obj.data('form-data')) {
|
725
|
+
$.extend(this_data, this.jq_obj.data('form-data'))
|
726
|
+
}
|
727
|
+
return this_data
|
728
|
+
},
|
729
|
+
getProcessData: function() {
|
730
|
+
return true;
|
731
|
+
},
|
732
|
+
getAjaxType: function() {
|
733
|
+
return this.jq_obj.data('ajax-method') || 'GET'
|
734
|
+
},
|
735
|
+
getTrigger: function() {
|
736
|
+
this.trigger = this.jq_obj;
|
737
|
+
},
|
738
|
+
hideTrigger: function() {
|
739
|
+
this.trigger.css('visibility', 'hidden');
|
740
|
+
},
|
741
|
+
showTrigger: function() {
|
742
|
+
this.trigger.css('visibility', 'visible');
|
743
|
+
},
|
744
|
+
refocus: function() {
|
745
|
+
if (this.jq_obj.data('ajax-link-now')) {
|
746
|
+
return false
|
747
|
+
}
|
748
|
+
return true
|
749
|
+
},
|
834
750
|
|
835
|
-
|
751
|
+
}),
|
752
|
+
thin_man.AjaxModalOpener = thin_man.AjaxLinkSubmission.extend({
|
753
|
+
ajaxSuccess: function(data, textStatus, jqXHR) {
|
754
|
+
this._super(data, textStatus, jqXHR);
|
755
|
+
$(this.jq_obj.data('ajax-modal')).modal();
|
756
|
+
}
|
757
|
+
}),
|
758
|
+
thin_man.AddALineForm = thin_man.AjaxFormSubmission.extend({
|
759
|
+
ajaxSuccess: function(data, textStatus, jqXHR) {
|
760
|
+
this._super(data, textStatus, jqXHR);
|
761
|
+
$(this.jq_obj.data('container')).empty();
|
762
|
+
},
|
763
|
+
ajaxError: function(jqXHR) {
|
764
|
+
this.insert_method = 'html';
|
765
|
+
this._super(jqXHR);
|
766
|
+
}
|
767
|
+
}),
|
768
|
+
thin_man.EmptyForm = thin_man.AjaxFormSubmission.extend({
|
769
|
+
ajaxSuccess: function(data, textStatus, jqXHR) {
|
770
|
+
var clicked_button = $("input[type=submit][clicked=true]")[0];
|
771
|
+
this._super(data, textStatus, jqXHR);
|
772
|
+
if ($(clicked_button).data('clone') != true) {
|
773
|
+
$(this.jq_obj)[0].reset();
|
774
|
+
};
|
775
|
+
$(this.jq_obj).find('input[type=text],textarea,select').filter(':visible:first').focus();
|
776
|
+
$("[data-autocomplete]").trigger("chosen:updated");
|
777
|
+
},
|
778
|
+
ajaxError: function(jqXHR) {
|
779
|
+
this.insert_method = 'html';
|
780
|
+
this._super(jqXHR);
|
781
|
+
}
|
782
|
+
}),
|
783
|
+
thin_man.ModalCloserForm = thin_man.AjaxFormSubmission.extend({
|
784
|
+
ajaxSuccess: function(data, textStatus, jqXHR) {
|
785
|
+
this._super(data, textStatus, jqXHR);
|
786
|
+
$modal = $(this.jq_obj.data('modal-container'));
|
787
|
+
$modal.modal('hide');
|
788
|
+
$modal.remove();
|
789
|
+
},
|
790
|
+
ajaxError: function(jqXHR) {
|
791
|
+
this._super(jqXHR);
|
792
|
+
$modal = $(this.jq_obj.data('modal-container'));
|
793
|
+
$modal.modal();
|
794
|
+
}
|
795
|
+
}),
|
796
|
+
thin_man.ResetOnSubmitForm = thin_man.AjaxFormSubmission.extend({
|
797
|
+
ajaxSuccess: function(data, textStatus, jqXHR) {
|
798
|
+
this._super(data, textStatus, jqXHR);
|
799
|
+
$(this.jq_obj).each(function() {
|
800
|
+
this.reset();
|
836
801
|
});
|
802
|
+
}
|
803
|
+
}),
|
804
|
+
thin_man.DeleteLink = thin_man.AjaxSubmission.extend({
|
805
|
+
ajaxSuccess: function(data, textStatus, jqXHR) {
|
806
|
+
this._super(data, textStatus, jqXHR);
|
807
|
+
if (this.jq_obj.data('replace-response')) {
|
808
|
+
this.insertHtml(data);
|
809
|
+
} else {
|
810
|
+
if (this.target) {
|
811
|
+
this.target.remove();
|
812
|
+
}
|
813
|
+
}
|
814
|
+
},
|
815
|
+
getTrigger: function() {
|
816
|
+
this.trigger = this.jq_obj;
|
817
|
+
},
|
818
|
+
getAjaxType: function() {
|
819
|
+
return 'DELETE';
|
820
|
+
},
|
821
|
+
getAjaxUrl: function() {
|
822
|
+
return this.jq_obj.attr('href');
|
823
|
+
},
|
824
|
+
getData: function() {
|
825
|
+
return { authenticity_token: $('[name="csrf-token"]').attr('content'), browser_tab_id: $("meta[name='browser_tab_id']").attr("content") };
|
826
|
+
},
|
827
|
+
getProcessData: function() {
|
828
|
+
return true;
|
829
|
+
},
|
830
|
+
ajaxBefore: function(jqXHR) {
|
831
|
+
if (!this.jq_obj.data('no-confirm')) {
|
832
|
+
return confirm("Are you sure you want to delete this?");
|
833
|
+
}
|
834
|
+
}
|
835
|
+
}),
|
836
|
+
thin_man.ReplaceDelete = thin_man.DeleteLink.extend({
|
837
|
+
ajaxSuccess: function(data, textStatus, jqXHR) {
|
838
|
+
this.target[this.insert_method](data);
|
839
|
+
},
|
840
|
+
ajaxBefore: function(jqXHR) {
|
841
|
+
//noop
|
842
|
+
}
|
843
|
+
}),
|
844
|
+
thin_man.AjaxSortSubmission = thin_man.AjaxLinkSubmission.extend({
|
845
|
+
init: function($form) {
|
846
|
+
this.sort_field = $form.data('sort-field');
|
847
|
+
this._super($form);
|
848
|
+
},
|
849
|
+
getAjaxUrl: function() {
|
850
|
+
return this._super() + '?' + 'sort_field=' + this.sort_field + '&' + this.jq_obj.sortable("serialize");
|
851
|
+
},
|
852
|
+
getAjaxType: function() {
|
853
|
+
return 'PUT';
|
854
|
+
},
|
855
|
+
ajaxSuccess: function() {
|
837
856
|
|
838
|
-
|
839
|
-
|
840
|
-
$(document).ready(function() {
|
841
|
-
$(document).on('click apiclick', '[data-ajax-link],[data-ajax-link-now]', function(e) {
|
842
|
-
e.preventDefault();
|
843
|
-
var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'), 'AjaxLinkSubmission'));
|
844
|
-
var submission = new this_class($(this), { e: e });
|
845
|
-
return false;
|
846
|
-
});
|
857
|
+
}
|
858
|
+
});
|
847
859
|
|
848
|
-
|
849
|
-
e.preventDefault();
|
850
|
-
var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'), 'AjaxFormSubmission'));
|
851
|
-
var submission = new this_class($(this), { e: e });
|
852
|
-
return false;
|
853
|
-
});
|
860
|
+
window.any_time_manager.registerListWithClasses({ 'sortable': 'AjaxSorter', 'ajax-link-now': 'AjaxLinkSubmission', 'ajax-form-now': 'AjaxFormSubmission' }, 'thin_man');
|
854
861
|
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
new thin_man.AjaxPushState($(this))
|
863
|
-
});
|
862
|
+
$(document).ready(function() {
|
863
|
+
$(document).on('click apiclick', '[data-ajax-link],[data-ajax-link-now]', function(e) {
|
864
|
+
e.preventDefault();
|
865
|
+
var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'), 'AjaxLinkSubmission'));
|
866
|
+
var submission = new this_class($(this), { e: e });
|
867
|
+
return false;
|
868
|
+
});
|
864
869
|
|
865
|
-
|
866
|
-
|
867
|
-
|
870
|
+
$(document).on('submit apisubmit', '[data-ajax-form]', function(e) {
|
871
|
+
e.preventDefault();
|
872
|
+
var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'), 'AjaxFormSubmission'));
|
873
|
+
var submission = new this_class($(this), { e: e });
|
874
|
+
return false;
|
875
|
+
});
|
868
876
|
|
877
|
+
$(document).on('click apiclick', '[data-ajax-delete]', function(e) {
|
878
|
+
e.preventDefault();
|
879
|
+
var this_class = eval('thin_man.' + thin_man.getSubClass($(this).data('sub-type'), 'DeleteLink'));
|
880
|
+
var deletion = new this_class($(this), { e: e });
|
881
|
+
});
|
882
|
+
$(document).on('click', '[data-change-url]', function(e) {
|
883
|
+
e.preventDefault();
|
884
|
+
new thin_man.AjaxPushState($(this))
|
885
|
+
});
|
869
886
|
|
887
|
+
$('[data-sortable]').each(function() {
|
888
|
+
new thin_man.AjaxSorter($(this));
|
870
889
|
});
|
871
890
|
|
891
|
+
$(window).bind("popstate", function(e){
|
892
|
+
$('[data-thin-man-back-link]').remove()
|
893
|
+
var previous_state = e.originalEvent.state
|
894
|
+
var $back_link = $('<div>').
|
895
|
+
css({display: 'none'}).
|
896
|
+
attr('data-ajax-target',previous_state.target).
|
897
|
+
attr('href',previous_state.path).
|
898
|
+
attr('data-thin-man-back-link',true)
|
899
|
+
new AjaxLinkSubmission($back_link)
|
900
|
+
})
|
901
|
+
|
902
|
+
});
|
903
|
+
|
872
904
|
};
|
873
905
|
|
874
906
|
if (typeof Class === "undefined") {
|
875
|
-
|
907
|
+
/* Simple JavaScript Inheritance
|
876
908
|
* By John Resig http://ejohn.org/
|
877
909
|
* MIT Licensed.
|
878
910
|
*/
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
911
|
+
// Inspired by base2 and Prototype
|
912
|
+
(function() {
|
913
|
+
var initializing = false,
|
914
|
+
fnTest = /xyz/.test(function() { xyz; }) ? /\b_super\b/ : /.*/;
|
915
|
+
// The base Class implementation (does nothing)
|
916
|
+
this.Class = function() {};
|
885
917
|
|
886
|
-
|
887
|
-
|
888
|
-
|
918
|
+
// Create a new Class that inherits from this class
|
919
|
+
Class.extend = function(prop) {
|
920
|
+
var _super = this.prototype;
|
889
921
|
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
922
|
+
// Instantiate a base class (but only create the instance,
|
923
|
+
// don't run the init constructor)
|
924
|
+
initializing = true;
|
925
|
+
var prototype = new this();
|
926
|
+
initializing = false;
|
895
927
|
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
928
|
+
// Copy the properties over onto the new prototype
|
929
|
+
for (var name in prop) {
|
930
|
+
// Check if we're overwriting an existing function
|
931
|
+
prototype[name] = typeof prop[name] == "function" &&
|
932
|
+
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
933
|
+
(function(name, fn) {
|
934
|
+
return function() {
|
935
|
+
var tmp = this._super;
|
904
936
|
|
905
|
-
|
906
|
-
|
907
|
-
|
937
|
+
// Add a new ._super() method that is the same method
|
938
|
+
// but on the super-class
|
939
|
+
this._super = _super[name];
|
908
940
|
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
941
|
+
// The method only need to be bound temporarily, so we
|
942
|
+
// remove it when we're done executing
|
943
|
+
var ret = fn.apply(this, arguments);
|
944
|
+
this._super = tmp;
|
913
945
|
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
946
|
+
return ret;
|
947
|
+
};
|
948
|
+
})(name, prop[name]) :
|
949
|
+
prop[name];
|
950
|
+
}
|
919
951
|
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
952
|
+
// The dummy class constructor
|
953
|
+
function Class() {
|
954
|
+
// All construction is actually done in the init method
|
955
|
+
if (!initializing && this.init)
|
956
|
+
this.init.apply(this, arguments);
|
957
|
+
}
|
926
958
|
|
927
|
-
|
928
|
-
|
959
|
+
// Populate our constructed prototype object
|
960
|
+
Class.prototype = prototype;
|
929
961
|
|
930
|
-
|
931
|
-
|
962
|
+
// Enforce the constructor to be what we expect
|
963
|
+
Class.prototype.constructor = Class;
|
932
964
|
|
933
|
-
|
934
|
-
|
965
|
+
// And make this class extendable
|
966
|
+
Class.extend = arguments.callee;
|
935
967
|
|
936
|
-
|
937
|
-
|
938
|
-
|
968
|
+
return Class;
|
969
|
+
};
|
970
|
+
})();
|
939
971
|
}
|
940
972
|
|
941
973
|
if (typeof UUID == 'undefined') {
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
974
|
+
var UUID = Class.extend({
|
975
|
+
init: function() {
|
976
|
+
this.value = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
977
|
+
var r = Math.random() * 16 | 0,
|
978
|
+
v = c == 'x' ? r : (r & 0x3 | 0x8);
|
979
|
+
return v.toString(16);
|
980
|
+
});
|
981
|
+
}
|
982
|
+
})
|
951
983
|
}
|
952
984
|
|
953
985
|
if (typeof window.any_time_manager === "undefined" && typeof window.loading_any_time_manager === "undefined") {
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
986
|
+
//Anytime loader, simulates load events for ajax requests
|
987
|
+
function getSubClass(sub_class_name, parent_class) {
|
988
|
+
if ((typeof(sub_class_name) == 'string') && (sub_class_name != '') && (sub_class_name != 'true')) {
|
989
|
+
var this_class = sub_class_name;
|
990
|
+
} else {
|
991
|
+
var this_class = parent_class;
|
992
|
+
}
|
993
|
+
return this_class;
|
994
|
+
};
|
963
995
|
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
996
|
+
String.prototype.toCapCamel = function() {
|
997
|
+
camel = this.replace(/[-_]([a-z])/g, function(g) { return g.replace(/[-_]/, '').charAt(0).toUpperCase(); });
|
998
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
999
|
+
};
|
968
1000
|
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
}
|
1016
|
-
var this_method = this['load_method'];
|
1017
|
-
var namespace = this['namespace'];
|
1018
|
-
$('[data-' + data_attribute + ']').each(function() {
|
1019
|
-
if ('instantiate' == this_method) {
|
1020
|
-
var declared_class = $(this).data('sub-type');
|
1021
|
-
var this_class = getSubClass(declared_class, base_class);
|
1022
|
-
this_class = namespace + this_class;
|
1023
|
-
atm.instantiate($(this), this_class);
|
1024
|
-
} else {
|
1025
|
-
atm.run($(this), base_class, this_method);
|
1026
|
-
}
|
1027
|
-
|
1028
|
-
});
|
1029
|
-
});
|
1001
|
+
var AnyTimeManager = Class.extend({
|
1002
|
+
init: function() {
|
1003
|
+
this.loader_array = []
|
1004
|
+
},
|
1005
|
+
register: function(data_attribute, load_method, base_class, namespace) {
|
1006
|
+
if (!namespace) { namespace = '' } else { namespace = namespace + '.' }
|
1007
|
+
this.loader_array.push({ data_attribute: data_attribute, base_class: base_class, load_method: load_method, namespace: namespace });
|
1008
|
+
},
|
1009
|
+
registerList: function(list, namespace) {
|
1010
|
+
var anytime_manager = this;
|
1011
|
+
$.each(list, function() {
|
1012
|
+
anytime_manager.register(this + '', 'instantiate', null, namespace)
|
1013
|
+
})
|
1014
|
+
},
|
1015
|
+
registerListWithClasses: function(list, namespace) {
|
1016
|
+
var anytime_manager = this;
|
1017
|
+
$.each(list, function(attr, klass) {
|
1018
|
+
anytime_manager.register(attr, 'instantiate', klass, namespace)
|
1019
|
+
})
|
1020
|
+
},
|
1021
|
+
registerRunList: function(list) {
|
1022
|
+
var anytime_manager = this;
|
1023
|
+
$.each(list, function(attr, method) {
|
1024
|
+
anytime_manager.register(attr, method, null)
|
1025
|
+
})
|
1026
|
+
},
|
1027
|
+
instantiate: function(jq_obj, class_name) {
|
1028
|
+
if (!jq_obj.data('anytime_loaded')) {
|
1029
|
+
jq_obj.data('anytime_loaded', true);
|
1030
|
+
var this_class = eval(class_name);
|
1031
|
+
new this_class(jq_obj);
|
1032
|
+
}
|
1033
|
+
},
|
1034
|
+
run: function(jq_obj, resource, method_name) {
|
1035
|
+
if (!jq_obj.data('anytime_run')) {
|
1036
|
+
jq_obj.data('anytime_run', true);
|
1037
|
+
resource[method_name](jq_obj);
|
1038
|
+
}
|
1039
|
+
},
|
1040
|
+
load: function() {
|
1041
|
+
var atm = this;
|
1042
|
+
$.each(atm.loader_array, function() {
|
1043
|
+
var data_attribute = this['data_attribute'];
|
1044
|
+
var base_class = this['base_class'];
|
1045
|
+
if (!base_class) {
|
1046
|
+
base_class = data_attribute.toCapCamel();
|
1030
1047
|
}
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
})
|
1044
|
-
|
1048
|
+
var this_method = this['load_method'];
|
1049
|
+
var namespace = this['namespace'];
|
1050
|
+
$('[data-' + data_attribute + ']').each(function() {
|
1051
|
+
if ('instantiate' == this_method) {
|
1052
|
+
var declared_class = $(this).data('sub-type');
|
1053
|
+
var this_class = getSubClass(declared_class, base_class);
|
1054
|
+
this_class = namespace + this_class;
|
1055
|
+
atm.instantiate($(this), this_class);
|
1056
|
+
} else {
|
1057
|
+
atm.run($(this), base_class, this_method);
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
});
|
1061
|
+
});
|
1062
|
+
}
|
1063
|
+
});
|
1064
|
+
window.any_time_manager = new AnyTimeManager();
|
1065
|
+
$(document).ajaxComplete(function() {
|
1066
|
+
window.any_time_manager.load();
|
1067
|
+
});
|
1068
|
+
$(document).ready(function() {
|
1069
|
+
if (typeof window.any_time_load_functions != 'undefined') {
|
1070
|
+
$.each(window.any_time_load_functions, function(i, func) {
|
1071
|
+
func();
|
1072
|
+
});
|
1073
|
+
}
|
1074
|
+
window.any_time_manager.load();
|
1075
|
+
})
|
1076
|
+
// End AnyTime library
|
1045
1077
|
}
|
1046
1078
|
|
1047
1079
|
initThinMan();
|