-
Notifications
You must be signed in to change notification settings - Fork 0
/
BTM.GeoNames.js
67 lines (52 loc) · 1.73 KB
/
BTM.GeoNames.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Drupal.behaviors.bindCountryProvinceSelect = function(context) {
if($("#edit-country-province-wrapper", context).length) {
BTM.GeoNames.bindCountryProvinceSelectSet(context);
}
}
var BTM = BTM || {}
BTM.GeoNames = {
get_provinces_path: 'btm_geonames/get_states_provinces',
showProvincesSelect: function(selector, context, states_provinces, default_selected){
var default_selected = default_selected || '';
var select = $(selector, context);
var options = select.attr('options');
$('option', select).remove();
// var names = new Array();
//
// $.each(states_provinces, function(val, text) {
// names.push(text);
// });
//
// names.sort();
//
// PRC.console.log(names);
$.each(states_provinces, function(val, text) {
options[options.length] = new Option(val, text);
});
$(select).val(default_selected);
},
bindCountryProvinceSelectSet: function(context, country_select, province_select, default_province) {
//console.log(country_select, context);
if(!country_select) {
country_select = '#edit-country-province-country';
}
if(!province_select) {
province_select = '#edit-country-province-state-province';
}
$(country_select, context).change(
function(){
var country_id = $(this).val();
var url = Drupal.settings.basePath + BTM.GeoNames.get_provinces_path + '/' + country_id + '/0/TRUE';
$.ajax({
'url': url,
'dataType': 'json',
'type':'GET',
'success': function(response){
BTM.GeoNames.showProvincesSelect(province_select, context, response.states_provinces, default_province);
},
'error': function(response){
}
});
});
}
}