Created
March 9, 2011 15:24
-
-
Save janjiss/862380 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In Layouts | |
<head> | |
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title> | |
<%= javascript_include_tag :defaults %> | |
<%= stylesheet_link_tag "style", "theme" %> | |
<%= csrf_meta_tag %> | |
<%= yield(:head) %> | |
<%= javascript_include_tag "admin" %> | |
<% if @cartridge&&@printers %> | |
<script type="text/javascript"> | |
var printerArray = [ | |
<% for printer in @printers %> | |
<%="[" + printer.manufacturer.id.to_s + "," + printer.id.to_s + ",'" + printer.name + "','" + checked_or_not(@printer_ids,printer.id).to_s + "'],"%> | |
<% end %> | |
[]]; | |
</script> | |
<% end %> | |
</head> | |
# In my admin JS | |
// Place your application-specific JavaScript functions and classes here | |
// This file is automatically included by javascript_include_tag :defaults | |
function change_checkboxes () { | |
jQuery("select option:selected").each(function () { | |
//Remove other selected printers | |
jQuery('.printerSelect').remove(); | |
for (i=0; i<printerArray.length-1; i++ ) { | |
// If element of priner array maches selected value | |
if(printerArray[i][0] == jQuery(this).val()) { | |
jQuery('#printerCheckBoxes').append('<span class="printerSelect"><input type="checkbox" name="printer[' + printerArray[i][1] +']" '+ printerArray[i][3] +' " value="1">'+ printerArray[i][2] +'<br></span>'); | |
} | |
} | |
}); | |
} | |
jQuery(document).ready(function() { | |
// When document is ready execute checkboxes to show current manufacturers printer checkboxes | |
change_checkboxes(); | |
// Execute, when #printerSelect is changed. | |
jQuery('#cartridge_manufacturer_id').change(function() { | |
change_checkboxes(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment