o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1366207004.388164:@value"{I"
class:ETI"ProcessedAsset; FI"logical_path; TI""blacklight/checkbox_submit.js; FI"
pathname; TI"~/Users/jfriesen/.rvm/gems/ruby-2.0.0-p0@curate/gems/blacklight-4.0.1/app/assets/javascripts/blacklight/checkbox_submit.js; FI"content_type; TI"application/javascript; TI"
mtime; TI"2013-04-08T11:16:57-04:00; TI"length; TiøI"digest; TI"%14cd102f67dce3d40823b0ca7dc57f0a; FI"source; TI"ø/* A JQuery plugin (should this be implemented as a widget instead? not sure)
that will convert a "toggle" form, with single submit button to add/remove
something, like used for Bookmarks, into an AJAXy checkbox instead.
Apply to a form. Does require certain assumption about the form:
1) The same form 'action' href must be used for both ADD and REMOVE
actions, with the different being the hidden input name="_method"
being set to "put" or "delete" -- that's the Rails method to pretend
to be doing a certain HTTP verb. So same URL, PUT to add, DELETE
to remove. This plugin assumes that.
Plus, the form this is applied to should provide a data-doc-id
attribute (HTML5-style doc-*) that contains the id/primary key
of the object in question -- used by plugin for a unique value for
DOM id's.
Pass in options for your class name and labels:
$("form.something").bl_checkbox_submit({
checked_label: "Selected",
unchecked_label: "Select",
progress_label: "Saving...",
//css_class is added to elements added, plus used for id base
css_class: "toggle_my_kinda_form",
success: function(after_success_check_state) {
#optional callback
}
});
*/
(function($) {
$.fn.bl_checkbox_submit = function(arg_opts) {
this.each(function() {
var options = $.extend({}, $.fn.bl_checkbox_submit.defaults, arg_opts);
var form = $(this);
form.children().hide();
//We're going to use the existing form to actually send our add/removes
//This works conveneintly because the exact same action href is used
//for both bookmarks/$doc_id. But let's take out the irrelevant parts
//of the form to avoid any future confusion.
form.find("input[type=submit]").remove();
form.addClass('form-inline');
//View needs to set data-doc-id so we know a unique value
//for making DOM id
var unique_id = form.attr("data-doc-id") || Math.random();
// if form is currently using method delete to change state,
// then checkbox is currently checked
var checked = (form.find("input[name=_method][value=delete]").size() != 0);
var checkbox = $('')
.addClass( options.css_class )
.attr("id", options.css_class + "_" + unique_id);
var label = $('