Created
October 28, 2010 15:34
-
-
Save gudata/651604 to your computer and use it in GitHub Desktop.
In the view
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
<%= sell_search_form.input :city_id, | |
:label => t("Град", :scope => [:admin, :buy_search]), | |
:as => :select, | |
:collection => [] | |
%> | |
<% content_for :head do %> | |
<script type="text/javascript"> | |
function fill_from_storage(target_select, storage_name, data_url, value) { | |
// localStorage.removeItem("cities_storage" + "_options") | |
// localStorage.removeItem("cities_storage") | |
var json_stored_data = localStorage.getItem(storage_name); | |
if (json_stored_data == null) { | |
$.getJSON(data_url, function(data) { | |
var select_options = ''; | |
// use http://code.google.com/p/jquery-json/ | |
var encoded = $.toJSON(data); | |
localStorage.setItem(storage_name, encoded); // store the raw data | |
// Store parsed options tags | |
$(data).each(function(index, object) { | |
select_options += '<option value="' + object.id + '">' + object.name + '</option>'; | |
}); | |
localStorage.setItem(storage_name + "_options", select_options); // store the raw data | |
$(target_select).html(localStorage.getItem(storage_name + "_options")); | |
$(target_select).val(value); | |
}); | |
} else { | |
// we don't need the raw data' | |
// data = localStorage.getItem(storage_name); | |
// items = jQuery.parseJSON(data); | |
$(target_select).html(localStorage.getItem(storage_name + "_options")); | |
$(target_select).val(value); | |
} | |
} | |
$(document).ready(function(){ | |
fill_from_storage("#sell_search_city_id", "cities_storage", "<%= cities_navigations_path %>", <%= sell_search_form.object.city_id %>); | |
}); | |
</script> | |
<% end%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment