Skip to content

Commit

Permalink
Load properties using ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
Willianvdv committed Dec 10, 2013
1 parent 7ca30e3 commit 9cd24d5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions app/assets/javascripts/admin/property_autocomplete.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var property_search_url = "/api/properties.json";

$(document).ready(function () {
'use strict';

if ($('#taxon_property_ids').length > 0) {
$('#taxon_property_ids').select2({
placeholder: Spree.translations.taxon_placeholder,
multiple: true,
initSelection: function (element, callback) {
var url = Spree.url(property_search_url, {
ids: element.val()
});
return $.getJSON(url, null, function (data) {
return callback(data['properties']);
});
},
ajax: {
url: property_search_url,
datatype: 'json',
data: function (term, page) {
return {
per_page: 50,
page: page,
q: {
name_cont: term
}
};
},
results: function (data, page) {
var more = page < data.pages;
return {
results: data['properties'],
more: more
};
}
},
formatResult: function (property) {
return property.name;
},
formatSelection: function (property) {
return property.name;
}
});
}
});
1 change: 1 addition & 0 deletions app/assets/javascripts/admin/spree_hstore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require_tree .

0 comments on commit 9cd24d5

Please sign in to comment.