blacklight 3.4.2 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight/blacklight.js +15 -474
- data/app/assets/javascripts/blacklight/bookmark_toggle.js +21 -0
- data/app/assets/javascripts/blacklight/checkbox_submit.js +126 -0
- data/app/assets/javascripts/blacklight/core.js +2 -0
- data/app/assets/javascripts/blacklight/facet_expand_contract.js +40 -0
- data/app/assets/javascripts/blacklight/folder_toggle.js +24 -0
- data/app/assets/javascripts/blacklight/lightbox_dialog.js +15 -0
- data/app/assets/javascripts/blacklight/more_facets.js +15 -0
- data/app/assets/javascripts/blacklight/search_context.js +26 -0
- data/app/assets/javascripts/blacklight/select_submit.js +18 -0
- data/app/assets/javascripts/blacklight/zebra_stripe.js +13 -0
- data/app/assets/javascripts/jquery.uiExt.ajaxyDialog.js +180 -0
- data/app/controllers/bookmarks_controller.rb +9 -9
- data/app/controllers/feedback_controller.rb +3 -3
- data/app/controllers/folder_controller.rb +3 -3
- data/app/controllers/saved_searches_controller.rb +7 -7
- data/app/controllers/search_history_controller.rb +2 -2
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +6 -10
- data/app/helpers/blacklight/catalog_helper_behavior.rb +8 -11
- data/app/helpers/blacklight/facets_helper_behavior.rb +2 -2
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +2 -2
- data/app/models/bookmark.rb +5 -0
- data/app/models/record_mailer.rb +5 -11
- data/app/views/_user_util_links.html.erb +6 -6
- data/app/views/bookmarks/index.html.erb +8 -8
- data/app/views/catalog/_bookmark_control.html.erb +2 -2
- data/app/views/catalog/_bookmark_form.html.erb +3 -3
- data/app/views/catalog/_citation.html.erb +3 -3
- data/app/views/catalog/_constraints.html.erb +1 -1
- data/app/views/catalog/_constraints_element.html.erb +2 -2
- data/app/views/catalog/_did_you_mean.html.erb +2 -7
- data/app/views/catalog/_document.html.erb +1 -1
- data/app/views/catalog/_email_form.html.erb +4 -4
- data/app/views/catalog/_facet_limit.html.erb +1 -1
- data/app/views/catalog/_facet_pagination.html.erb +7 -7
- data/app/views/catalog/_facets.html.erb +1 -1
- data/app/views/catalog/_folder_control.html.erb +1 -1
- data/app/views/catalog/_home_text.html.erb +1 -1
- data/app/views/catalog/_marc_view.html.erb +2 -2
- data/app/views/catalog/_refworks_form.html.erb +2 -2
- data/app/views/catalog/_results_pagination.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +5 -5
- data/app/views/catalog/_show_tools.html.erb +6 -6
- data/app/views/catalog/_sms_form.html.erb +5 -5
- data/app/views/catalog/_sort_and_per_page.html.erb +6 -9
- data/app/views/catalog/index.atom.builder +3 -3
- data/app/views/catalog/index.html.erb +2 -2
- data/app/views/catalog/index.rss.builder +3 -3
- data/app/views/catalog/show.html.erb +2 -2
- data/app/views/feedback/complete.html.erb +2 -2
- data/app/views/feedback/show.html.erb +5 -5
- data/app/views/folder/_tools.html.erb +4 -4
- data/app/views/folder/index.html.erb +1 -1
- data/app/views/layouts/blacklight.html.erb +1 -1
- data/app/views/record_mailer/email_record.text.erb +2 -2
- data/app/views/record_mailer/sms_record.text.erb +1 -1
- data/app/views/saved_searches/index.html.erb +6 -6
- data/app/views/search_history/index.html.erb +6 -6
- data/config/locales/blacklight.en.yml +227 -0
- data/lib/blacklight.rb +0 -2
- data/lib/blacklight/catalog.rb +11 -13
- data/lib/blacklight/configurable.rb +0 -3
- data/lib/blacklight/configuration.rb +0 -42
- data/lib/blacklight/configuration/fields.rb +2 -0
- data/lib/blacklight/routes.rb +14 -2
- data/lib/blacklight/search_fields.rb +1 -1
- data/lib/blacklight/solr/document/email.rb +6 -6
- data/lib/blacklight/solr/document/sms.rb +4 -4
- data/lib/blacklight/solr_helper.rb +1 -3
- data/lib/generators/blacklight/blacklight_generator.rb +3 -0
- data/lib/railties/blacklight_cucumber.rake +12 -3
- data/lib/railties/blacklight_rspec.rake +9 -2
- data/test_support/alternate_controller.rb +4 -0
- data/test_support/bin/test.sh +13 -1
- data/test_support/features/bookmarks.feature +1 -1
- data/test_support/features/librarian_view.feature +2 -1
- data/test_support/features/record_view.feature +1 -0
- data/test_support/features/search.feature +1 -0
- data/test_support/features/step_definitions/general_steps.rb +4 -0
- data/test_support/features/support/env.rb +12 -1
- data/test_support/features/support/paths.rb +2 -1
- data/test_support/spec/helpers/blacklight_helper_spec.rb +8 -2
- data/test_support/spec/helpers/search_history_constraints_helper_spec.rb +6 -18
- data/test_support/spec/lib/search_fields_spec.rb +18 -25
- data/test_support/spec/models/record_mailer_spec.rb +5 -4
- data/test_support/spec/requests/alternate_controller_spec.rb +15 -0
- data/test_support/spec/spec_helper.rb +12 -0
- data/test_support/spec/views/catalog/_index_default.erb_spec.rb +6 -17
- data/test_support/spec/views/catalog/_show_default.erb_spec.rb +7 -17
- metadata +19 -8
- data/config/locales/kaminari.yml +0 -10
- data/lib/blacklight/global_configurable.rb +0 -46
- data/test_support/spec/lib/global_configurable_spec.rb +0 -98
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.5.0
|
@@ -1,7 +1,18 @@
|
|
1
|
-
|
2
|
-
this file directly, or you'll have to manually merge your changes if later
|
3
|
-
versions of Blacklight change this file. Instead, use your own JS file
|
4
|
-
which over-rides things in this JS file, as described below
|
1
|
+
// This file is generated by Blacklight. You probably don't want to edit
|
2
|
+
// this file directly, or you'll have to manually merge your changes if later
|
3
|
+
// versions of Blacklight change this file. Instead, use your own JS file
|
4
|
+
// which over-rides things in this JS file, as described below.
|
5
|
+
//
|
6
|
+
// These javascript files are compiled in via the Rails asset pipeline:
|
7
|
+
//= require blacklight/core
|
8
|
+
//= require blacklight/bookmark_toggle
|
9
|
+
//= require blacklight/facet_expand_contract
|
10
|
+
//= require blacklight/folder_toggle
|
11
|
+
//= require blacklight/lightbox_dialog
|
12
|
+
//= require blacklight/more_facets
|
13
|
+
//= require blacklight/search_context
|
14
|
+
//= require blacklight/select_submit
|
15
|
+
//= require blacklight/zebra_stripe
|
5
16
|
|
6
17
|
/* Blacklight has a Javascript setup meant to support local disabling,
|
7
18
|
modification, and use of Blacklight behaviors.
|
@@ -41,473 +52,3 @@
|
|
41
52
|
});
|
42
53
|
};
|
43
54
|
*/
|
44
|
-
|
45
|
-
Blacklight = {};
|
46
|
-
|
47
|
-
|
48
|
-
$(document).ready(function() {
|
49
|
-
Blacklight.do_zebra_stripe();
|
50
|
-
|
51
|
-
Blacklight.do_select_submit();
|
52
|
-
|
53
|
-
Blacklight.do_more_facets_behavior();
|
54
|
-
|
55
|
-
Blacklight.do_lightbox_dialog();
|
56
|
-
|
57
|
-
Blacklight.do_bookmark_toggle_behavior();
|
58
|
-
|
59
|
-
Blacklight.do_folder_toggle_behavior();
|
60
|
-
|
61
|
-
Blacklight.do_facet_expand_contract_behavior();
|
62
|
-
|
63
|
-
Blacklight.do_search_context_behavior();
|
64
|
-
});
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
//Note all of these definitions are NOT in document ready, they get defined on
|
69
|
-
//page load, and later called on document ready.
|
70
|
-
(function($) {
|
71
|
-
Blacklight.do_search_context_behavior = function() {
|
72
|
-
$('a[data-counter]').click(function(event) {
|
73
|
-
var f = document.createElement('form'); f.style.display = 'none';
|
74
|
-
this.parentNode.appendChild(f);
|
75
|
-
f.method = 'POST';
|
76
|
-
f.action = $(this).attr('href');
|
77
|
-
if(event.metaKey || event.ctrlKey){f.target = '_blank';};
|
78
|
-
var d = document.createElement('input'); d.setAttribute('type', 'hidden');
|
79
|
-
d.setAttribute('name', 'counter'); d.setAttribute('value', $(this).data('counter')); f.appendChild(d);
|
80
|
-
var m = document.createElement('input'); m.setAttribute('type', 'hidden');
|
81
|
-
m.setAttribute('name', '_method'); m.setAttribute('value', 'put'); f.appendChild(m);
|
82
|
-
var m = document.createElement('input'); m.setAttribute('type', 'hidden');
|
83
|
-
m.setAttribute('name', $('meta[name="csrf-param"]').attr('content')); m.setAttribute('value', $('meta[name="csrf-token"]').attr('content')); f.appendChild(m);
|
84
|
-
|
85
|
-
f.submit();
|
86
|
-
|
87
|
-
return false;
|
88
|
-
});
|
89
|
-
|
90
|
-
};
|
91
|
-
|
92
|
-
// adds classes for zebra striping table rows
|
93
|
-
Blacklight.do_zebra_stripe = function() {
|
94
|
-
$(Blacklight.do_zebra_stripe.selector).addClass('zebra_stripe');
|
95
|
-
};
|
96
|
-
Blacklight.do_zebra_stripe.selector = "table.zebra tr:even, ul.zebra li:even";
|
97
|
-
|
98
|
-
//add ajaxy dialogs to certain links, using the ajaxyDialog widget.
|
99
|
-
Blacklight.do_more_facets_behavior = function () {
|
100
|
-
$( Blacklight.do_more_facets_behavior.selector ).ajaxyDialog({
|
101
|
-
width: $(window).width() / 2,
|
102
|
-
chainAjaxySelector: "a.next_page, a.prev_page, a.sort_change"
|
103
|
-
});
|
104
|
-
};
|
105
|
-
Blacklight.do_more_facets_behavior.selector = "a.more_facets_link";
|
106
|
-
|
107
|
-
// Used for sort-by and per-page controls, hide the submit button
|
108
|
-
// and make the select auto-submit
|
109
|
-
Blacklight.do_select_submit = function() {
|
110
|
-
$(Blacklight.do_select_submit.selector).each(function() {
|
111
|
-
var select = $(this);
|
112
|
-
select.closest("form").find("input[type=submit]").hide();
|
113
|
-
select.bind("change", function() {
|
114
|
-
this.form.submit();
|
115
|
-
});
|
116
|
-
});
|
117
|
-
};
|
118
|
-
Blacklight.do_select_submit.selector = "form.sort select, form.per_page select";
|
119
|
-
|
120
|
-
|
121
|
-
Blacklight.do_lightbox_dialog = function() {
|
122
|
-
$("a.lightboxLink").ajaxyDialog({
|
123
|
-
chainAjaxySelector: false
|
124
|
-
});
|
125
|
-
//But make the librarian link wider than 300px default.
|
126
|
-
$('a.lightboxLink#librarianLink').ajaxyDialog("option", "width", 650);
|
127
|
-
//And the email one too needs to be wider to fit the textarea
|
128
|
-
$("a.lightboxLink#emailLink").ajaxyDialog("option", "width", 500);
|
129
|
-
};
|
130
|
-
|
131
|
-
//change form submit toggle to checkbox
|
132
|
-
Blacklight.do_bookmark_toggle_behavior = function() {
|
133
|
-
$(Blacklight.do_bookmark_toggle_behavior.selector).bl_checkbox_submit({
|
134
|
-
checked_label: "In Bookmarks",
|
135
|
-
unchecked_label: "Bookmark",
|
136
|
-
progress_label: "Saving...",
|
137
|
-
//css_class is added to elements added, plus used for id base
|
138
|
-
css_class: "toggle_bookmark"
|
139
|
-
});
|
140
|
-
};
|
141
|
-
Blacklight.do_bookmark_toggle_behavior.selector = "form.bookmark_toggle";
|
142
|
-
|
143
|
-
Blacklight.do_folder_toggle_behavior = function() {
|
144
|
-
$( Blacklight.do_folder_toggle_behavior.selector ).bl_checkbox_submit({
|
145
|
-
checked_label: "Selected",
|
146
|
-
unchecked_label: "Select",
|
147
|
-
css_class: "toggle_folder",
|
148
|
-
success: function(new_state) {
|
149
|
-
|
150
|
-
if (new_state) {
|
151
|
-
$("#folder_number").text(parseInt($("#folder_number").text()) + 1);
|
152
|
-
}
|
153
|
-
else {
|
154
|
-
$("#folder_number").text(parseInt($("#folder_number").text()) - 1);
|
155
|
-
}
|
156
|
-
}
|
157
|
-
});
|
158
|
-
};
|
159
|
-
Blacklight.do_folder_toggle_behavior.selector = "form.folder_toggle";
|
160
|
-
|
161
|
-
Blacklight.do_facet_expand_contract_behavior = function() {
|
162
|
-
$( Blacklight.do_facet_expand_contract_behavior.selector ).each (
|
163
|
-
Blacklight.facet_expand_contract
|
164
|
-
);
|
165
|
-
}
|
166
|
-
Blacklight.do_facet_expand_contract_behavior.selector = '#facets h3';
|
167
|
-
|
168
|
-
/* Behavior that makes facet limit headings in sidebar expand/contract
|
169
|
-
their contents. This is kind of fragile code targeted specifically
|
170
|
-
at how we currently render facet HTML, which is why I put it in a function
|
171
|
-
on Blacklight instead of in a jquery plugin. Perhaps in the future this
|
172
|
-
could/should be expanded to a general purpose jquery plugin -- or
|
173
|
-
we should just use one of the existing ones for expand/contract? */
|
174
|
-
Blacklight.facet_expand_contract = function() {
|
175
|
-
$(this).next("ul, div").each(function(){
|
176
|
-
var f_content = $(this);
|
177
|
-
$(f_content).prev('h3').addClass('twiddle');
|
178
|
-
// find all f_content's that don't have any span descendants with a class of "selected"
|
179
|
-
if($('span.selected', f_content).length == 0){
|
180
|
-
// hide it
|
181
|
-
f_content.hide();
|
182
|
-
} else {
|
183
|
-
$(this).prev('h3').addClass('twiddle-open');
|
184
|
-
}
|
185
|
-
|
186
|
-
// attach the toggle behavior to the h3 tag
|
187
|
-
$('h3', f_content.parent()).click(function(){
|
188
|
-
// toggle the content
|
189
|
-
$(this).toggleClass('twiddle-open');
|
190
|
-
$(f_content).slideToggle();
|
191
|
-
});
|
192
|
-
});
|
193
|
-
};
|
194
|
-
|
195
|
-
})(jQuery);
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
/* A JQuery plugin (should this be implemented as a widget instead? not sure)
|
203
|
-
that will convert a "toggle" form, with single submit button to add/remove
|
204
|
-
something, like used for Bookmarks/Folder, into an AJAXy checkbox instead.
|
205
|
-
|
206
|
-
Apply to a form. Does require certain assumption about the form:
|
207
|
-
1) The same form 'action' href must be used for both ADD and REMOVE
|
208
|
-
actions, with the different being the hidden input name="_method"
|
209
|
-
being set to "put" or "delete" -- that's the Rails method to pretend
|
210
|
-
to be doing a certain HTTP verb. So same URL, PUT to add, DELETE
|
211
|
-
to remove. This plugin assumes that.
|
212
|
-
|
213
|
-
Plus, the form this is applied to should provide a data-doc-id
|
214
|
-
attribute (HTML5-style doc-*) that contains the id/primary key
|
215
|
-
of the object in question -- used by plugin for a unique value for
|
216
|
-
DOM id's.
|
217
|
-
|
218
|
-
Pass in options for your class name and labels:
|
219
|
-
$("form.something").bl_checkbox_submit({
|
220
|
-
checked_label: "Selected",
|
221
|
-
unchecked_label: "Select",
|
222
|
-
progress_label: "Saving...",
|
223
|
-
//css_class is added to elements added, plus used for id base
|
224
|
-
css_class: "toggle_my_kinda_form",
|
225
|
-
success: function(after_success_check_state) {
|
226
|
-
#optional callback
|
227
|
-
}
|
228
|
-
});
|
229
|
-
*/
|
230
|
-
(function($) {
|
231
|
-
$.fn.bl_checkbox_submit = function(arg_opts) {
|
232
|
-
|
233
|
-
this.each(function() {
|
234
|
-
var options = $.extend({}, $.fn.bl_checkbox_submit.defaults, arg_opts);
|
235
|
-
|
236
|
-
|
237
|
-
var form = $(this);
|
238
|
-
form.children().hide();
|
239
|
-
//We're going to use the existing form to actually send our add/removes
|
240
|
-
//This works conveneintly because the exact same action href is used
|
241
|
-
//for both bookmarks/$doc_id. But let's take out the irrelevant parts
|
242
|
-
//of the form to avoid any future confusion.
|
243
|
-
form.find("input[type=submit]").remove();
|
244
|
-
|
245
|
-
//View needs to set data-doc-id so we know a unique value
|
246
|
-
//for making DOM id
|
247
|
-
var unique_id = form.attr("data-doc-id") || Math.random();
|
248
|
-
// if form is currently using method delete to change state,
|
249
|
-
// then checkbox is currently checked
|
250
|
-
var checked = (form.find("input[name=_method][value=delete]").size() != 0);
|
251
|
-
|
252
|
-
var checkbox = $('<input type="checkbox">')
|
253
|
-
.addClass( options.css_class )
|
254
|
-
.attr("id", options.css_class + "_" + unique_id);
|
255
|
-
var label = $('<label>')
|
256
|
-
.addClass( options.css_class )
|
257
|
-
.attr("for", options.css_class + '_' + unique_id)
|
258
|
-
.attr("title", form.attr("title") || "");
|
259
|
-
|
260
|
-
|
261
|
-
function update_state_for(state) {
|
262
|
-
checkbox.attr("checked", state);
|
263
|
-
label.toggleClass("checked", state);
|
264
|
-
if (state) {
|
265
|
-
//Set the Rails hidden field that fakes an HTTP verb
|
266
|
-
//properly for current state action.
|
267
|
-
form.find("input[name=_method]").val("delete");
|
268
|
-
label.text(options.checked_label);
|
269
|
-
} else {
|
270
|
-
form.find("input[name=_method]").val("put");
|
271
|
-
label.text(options.unchecked_label);
|
272
|
-
}
|
273
|
-
}
|
274
|
-
|
275
|
-
form.append(checkbox).append(" ").append(label);
|
276
|
-
update_state_for(checked);
|
277
|
-
|
278
|
-
checkbox.click(function() {
|
279
|
-
label.text(options.progress_label).attr("disabled", "disabled");
|
280
|
-
checkbox.attr("disabled", "disabled");
|
281
|
-
|
282
|
-
$.ajax({
|
283
|
-
url: form.attr("action"),
|
284
|
-
dataType: 'json',
|
285
|
-
type: form.attr("method").toUpperCase(),
|
286
|
-
data: form.serialize(),
|
287
|
-
error: function() {
|
288
|
-
alert("Error");
|
289
|
-
update_state_for(checked);
|
290
|
-
label.removeAttr("disabled");
|
291
|
-
checkbox.removeAttr("disabled");
|
292
|
-
},
|
293
|
-
success: function(data, status, xhr) {
|
294
|
-
//if app isn't running at all, xhr annoyingly
|
295
|
-
//reports success with status 0.
|
296
|
-
if (xhr.status != 0) {
|
297
|
-
checked = ! checked;
|
298
|
-
update_state_for(checked);
|
299
|
-
label.removeAttr("disabled");
|
300
|
-
checkbox.removeAttr("disabled");
|
301
|
-
options.success.call(form, checked);
|
302
|
-
} else {
|
303
|
-
alert("Error");
|
304
|
-
update_state_for(checked);
|
305
|
-
label.removeAttr("disabled");
|
306
|
-
checkbox.removeAttr("disabled");
|
307
|
-
}
|
308
|
-
}
|
309
|
-
});
|
310
|
-
|
311
|
-
return false;
|
312
|
-
}); //checkbox.click
|
313
|
-
|
314
|
-
|
315
|
-
}); //this.each
|
316
|
-
return this;
|
317
|
-
};
|
318
|
-
|
319
|
-
$.fn.bl_checkbox_submit.defaults = {
|
320
|
-
checked_label: "",
|
321
|
-
unchecked_label: "",
|
322
|
-
progress_label: "Saving...",
|
323
|
-
//css_class is added to elements added, plus used for id base
|
324
|
-
css_class: "bl_checkbox_submit",
|
325
|
-
success: function() {} //callback
|
326
|
-
};
|
327
|
-
|
328
|
-
})(jQuery);
|
329
|
-
|
330
|
-
|
331
|
-
/* A widget written by jrochkind to make a link or form result in
|
332
|
-
an in-window ajaxy dialog, instead of page load, using JQuery UI
|
333
|
-
Dialog widget.
|
334
|
-
|
335
|
-
This widget is actually hosted at: https://github.com/jrochkind/jquery.uiExt.ajaxyDialog
|
336
|
-
|
337
|
-
|
338
|
-
Included in this main file because I just couldn't bare to add yet
|
339
|
-
another JS file to our app, until we figure out a good fix those too
|
340
|
-
many JS files are serious page load speed problem. */
|
341
|
-
|
342
|
-
(function($) {
|
343
|
-
var widgetNamespace = "uiExt";
|
344
|
-
var widgetName = "ajaxyDialog";
|
345
|
-
|
346
|
-
$.widget(widgetNamespace + "." + widgetName, {
|
347
|
-
options: {
|
348
|
-
extractTitleSelector: "h1, h2, h3, h4, h5",
|
349
|
-
chainAjaxySelector: "a:not([target]), form:not([target])",
|
350
|
-
closeDialogSelector: "a.dialog-close"
|
351
|
-
},
|
352
|
-
|
353
|
-
_create: function() {
|
354
|
-
var self = this;
|
355
|
-
var element = self.element[0];
|
356
|
-
if (element.tagName.toUpperCase() == "A") {
|
357
|
-
$(element).bind("click."+self.widgetName, function(event, ui) {
|
358
|
-
self._handleClick();
|
359
|
-
return false;
|
360
|
-
});
|
361
|
-
}
|
362
|
-
else if (element.tagName.toUpperCase() == "FORM") {
|
363
|
-
$(element).bind("submit."+self.widgetName, function(event, ui) {
|
364
|
-
self._handleSubmit();
|
365
|
-
return false;
|
366
|
-
});
|
367
|
-
}
|
368
|
-
},
|
369
|
-
|
370
|
-
open: function() {
|
371
|
-
var self = this;
|
372
|
-
var element = self.element[0];
|
373
|
-
|
374
|
-
if ( element.tagName.toUpperCase() == "A") {
|
375
|
-
self._handleClick();
|
376
|
-
} else if (element.tagName.toUpperCase() == "FORM") {
|
377
|
-
self._handleSubmit();
|
378
|
-
}
|
379
|
-
},
|
380
|
-
|
381
|
-
close: function() {
|
382
|
-
this.dialogContainer().dialog("close");
|
383
|
-
},
|
384
|
-
|
385
|
-
_handleClick: function() {
|
386
|
-
var self = this;
|
387
|
-
var url = this.element.attr("href");
|
388
|
-
var requestDialog = self.dialogContainer();
|
389
|
-
|
390
|
-
$("body").css("cursor", "progress");
|
391
|
-
|
392
|
-
$.ajax({
|
393
|
-
url: url,
|
394
|
-
dataType: "html",
|
395
|
-
success: function(resp, status, xhr) {
|
396
|
-
if (xhr.status != 0) {
|
397
|
-
self._loadToDialog(resp);
|
398
|
-
} else {
|
399
|
-
//stupid jquery calling this 'success', it's
|
400
|
-
//network unavailable.
|
401
|
-
self._displayFailure(url, xhr, status);
|
402
|
-
}
|
403
|
-
},
|
404
|
-
error: function(xhr, msg) {
|
405
|
-
self._displayFailure(url, xhr, msg);
|
406
|
-
}
|
407
|
-
});
|
408
|
-
},
|
409
|
-
|
410
|
-
_handleSubmit: function() {
|
411
|
-
var self = this;
|
412
|
-
var form = self.element;
|
413
|
-
var actionUri = form.attr("action");
|
414
|
-
var serialized = form.serialize();
|
415
|
-
|
416
|
-
$("body").css("cursor", "progress");
|
417
|
-
|
418
|
-
$.ajax({
|
419
|
-
url: actionUri,
|
420
|
-
data: serialized,
|
421
|
-
type: form.attr("method").toUpperCase(),
|
422
|
-
dataType: "html",
|
423
|
-
success: function(resp, status, xhr) {
|
424
|
-
if (xhr.status != 0) {
|
425
|
-
self._loadToDialog(resp);
|
426
|
-
} else {
|
427
|
-
//stupid jquery calling this 'success', it's
|
428
|
-
//network unavailable.
|
429
|
-
self._displayFailure(url, xhr, status);
|
430
|
-
}
|
431
|
-
},
|
432
|
-
error: function(xhr, msg) {
|
433
|
-
self._displayFailure(actionUri, xhr, msg);
|
434
|
-
}
|
435
|
-
});
|
436
|
-
},
|
437
|
-
|
438
|
-
_loadToDialog: function(html_content) {
|
439
|
-
var self = this;
|
440
|
-
var dialog = self.dialogContainer();
|
441
|
-
//Cheesy way to restore it to it's default options, plus
|
442
|
-
//our own local options, since its' a reuseable dialog.
|
443
|
-
//for now we insist on modal:true.
|
444
|
-
dialog.dialog($.extend({},
|
445
|
-
$.ui.dialog.prototype.options,
|
446
|
-
self.options,
|
447
|
-
{autoOpen:false, modal:true}
|
448
|
-
));
|
449
|
-
|
450
|
-
if (self._trigger('beforeDisplay', 0, html_content) !== false) {
|
451
|
-
dialog.html( html_content );
|
452
|
-
|
453
|
-
//extract and set title
|
454
|
-
var title;
|
455
|
-
self.options.extractTitleSelector &&
|
456
|
-
(title = dialog.find(self.options.extractTitleSelector).first().remove().text());
|
457
|
-
title = title ||
|
458
|
-
self.element.attr("title")
|
459
|
-
title && dialog.dialog("option", "title", title);
|
460
|
-
|
461
|
-
//Make any hyperlinks or forms ajaxified, by applying
|
462
|
-
//this very same plugin to em, and passing on our options.
|
463
|
-
if (self.options.chainAjaxySelector) {
|
464
|
-
dialog.find(self.options.chainAjaxySelector).ajaxyDialog(self.options);
|
465
|
-
}
|
466
|
-
|
467
|
-
//Make any links marked dialog-close do so
|
468
|
-
if ( self.options.closeDialogSelector ) {
|
469
|
-
dialog.find(self.options.closeDialogSelector).unbind("click." + widgetName);
|
470
|
-
dialog.find(self.options.closeDialogSelector).bind("click." + widgetName, function() {
|
471
|
-
dialog.dialog("close");
|
472
|
-
return false;
|
473
|
-
});
|
474
|
-
}
|
475
|
-
|
476
|
-
dialog.dialog("open");
|
477
|
-
}
|
478
|
-
$("body").css("cursor", "auto");
|
479
|
-
},
|
480
|
-
|
481
|
-
_displayFailure: function(uri, xhr, serverMsg) {
|
482
|
-
if ( this._trigger("error", 0, {uri:uri, xhr: xhr, serverMsg: serverMsg}) !== false) {
|
483
|
-
var dialog = this.dialogContainer();
|
484
|
-
|
485
|
-
dialog.html("<div class='ui-state-error' style='padding: 1em;'><p><span style='float: left; margin-right: 0.3em;' class='ui-icon ui-icon-alert'></span>Sorry, a software error has occured.</p><p>" + uri + ": " + xhr.status + " " + serverMsg+"</p></div>");
|
486
|
-
dialog.dialog("option", "title", "Sorry, an error has occured.");
|
487
|
-
dialog.dialog("option", "buttons", {"OK": function() { dialog.dialog("close"); }});
|
488
|
-
dialog.dialog("open");
|
489
|
-
}
|
490
|
-
$("body").css("cursor", "auto");
|
491
|
-
},
|
492
|
-
|
493
|
-
// The DOM element which has a ui dialog() called on it.
|
494
|
-
// Right now we insist upon modal dialogs, and re-use the same
|
495
|
-
// <div>.dialog() for all of them. It's lazily created here.
|
496
|
-
// If client calls dialog("destroy") on it, no problem, it'll
|
497
|
-
// be lazily created if it's needed again.
|
498
|
-
dialogContainer: function() {
|
499
|
-
var existing = $("#reusableModalDialog");
|
500
|
-
if ( existing.size() > 0) {
|
501
|
-
return existing.first();
|
502
|
-
}
|
503
|
-
else {
|
504
|
-
//single shared element for modal dialogs
|
505
|
-
var requestDialog = $('<div id="reusableModalDialog" style="display:none"></div>').appendTo('body').
|
506
|
-
dialog({autoOpen: false});
|
507
|
-
return requestDialog;
|
508
|
-
}
|
509
|
-
}
|
510
|
-
|
511
|
-
});
|
512
|
-
}(jQuery));
|
513
|
-
|