622
625
if (data.addr_street != 'None') {
623
626
$('#gis_location_addr_street').val(data.addr_street);
628
// If a location in the admin hierarchy has been selected
629
if ((data.level != 'None') && (data.level != '')){
630
if (data.level == 'L0') {
631
// Set the location (whether visible or not)
632
$('#gis_location_l0').val(data.id);
633
// @ToDo Refresh other dropdowns
634
// (Not needed for PK)
635
} else if (data.level == 'L1') {
636
// Check if that dropdown is visible
637
if ($('#gis_location_l1__row').length == 0) {
639
// @ToDo Check for bad side-effects of reusing these!
640
// Better to use arguments than flags!
643
S3.gis.locations_l1(false);
644
// Set the right entry
645
//s3_debug('opened dropdown', data.id)
646
// Not working - async issue?
647
//$('#gis_location_l1').val(data.id);
648
// @ToDo If we know country has changed, then reset that dropdown too
649
// (Not needed for PK)
651
// @ToDo Check that our location is in this dropdown!
652
// (Not needed for PK)
653
// Set the right entry
654
$('#gis_location_l1').val(data.id);
655
// @ToDo If we know country has changed, then reset that dropdown too
656
// (Not needed for PK)
657
// Refresh L2-L5 dropdowns
658
$('#gis_location_l2').val('');
659
$('#gis_location_l3').val('');
660
$('#gis_location_l4').val('');
661
$('#gis_location_l5').val('');
663
} else if (data.level == 'L2') {
664
// Check if that dropdown is visible
665
if ($('#gis_location_l2__row').length == 0) {
669
S3.gis.locations_l2(false);
670
// Set the right entry
671
//$('#gis_location_l2').val(data.id);
673
var exists = $("#gis_location_l1").itemExists(data.parent.toString());
675
// Set the L1 to the Parent
676
$('#gis_location_l1').val(data.parent);
678
// Reset the L1 dropdown
679
$('#gis_location_l1').val('');
681
// @ToDo Check the L0
682
// (Not needed for PK)
685
// Check that our location is in this dropdown!
686
var exists = $("#gis_location_l2").itemExists(data.id.toString());
688
// Set the right entry
689
$('#gis_location_l2').val(data.id);
691
var exists = $("#gis_location_l1").itemExists(data.parent.toString());
693
// Set the L1 to the Parent
694
$('#gis_location_l1').val(data.parent);
696
// Reset the L1 dropdown
697
$('#gis_location_l1').val('');
699
// @ToDo Check the L0
700
// (Not needed for PK)
702
// Refresh L3-L5 dropdowns
703
$('#gis_location_l3').val('');
704
$('#gis_location_l4').val('');
705
$('#gis_location_l5').val('');
707
// @ToDo Reload this Dropdown
710
} else if (data.level == 'L3') {
711
// Check if that dropdown is visible
712
if ($('#gis_location_l3__row').length == 0) {
716
S3.gis.locations_l3(false);
717
// Set the right entry
718
//$('#gis_location_l3').val(data.id);
720
var exists = $("#gis_location_l2").itemExists(data.parent.toString());
722
// Set the L2 to the Parent
723
$('#gis_location_l2').val(data.parent);
725
// Reset the L2 dropdown
726
$('#gis_location_l2').val('');
728
// @ToDo Check the L1
729
// @ToDo Check the L0 (not needed for PK)
732
// Check that our location is in this dropdown!
733
var exists = $("#gis_location_l3").itemExists(data.id.toString());
735
// Set the right entry
736
$('#gis_location_l3').val(data.id);
738
var exists = $("#gis_location_l2").itemExists(data.parent.toString());
740
// Set the L2 to the Parent
741
$('#gis_location_l2').val(data.parent);
743
// Reset the L2 dropdown
744
$('#gis_location_l2').val('');
746
// @ToDo Check the L1
747
// @ToDo Check the L0 (not needed for PK)
749
// Refresh L4-L5 dropdowns
750
$('#gis_location_l4').val('');
751
$('#gis_location_l5').val('');
753
// @ToDo Reload this Dropdown
756
} else if (data.level == 'L4') {
757
// Check if that dropdown is visible
758
if ($('#gis_location_l4__row').length == 0) {
762
S3.gis.locations_l4(false);
763
// Set the right entry
764
//$('#gis_location_l4').val(data.id);
766
var exists = $("#gis_location_l3").itemExists(data.parent.toString());
768
// Set the L3 to the Parent
769
$('#gis_location_l3').val(data.parent);
771
// Reset the L3 dropdown
772
$('#gis_location_l3').val('');
774
// @ToDo Check the L2
775
// @ToDo Check the L1
776
// @ToDo Check the L0 (not needed for PK)
779
// Check that our location is in this dropdown!
780
var exists = $("#gis_location_l4").itemExists(data.id.toString());
782
// Set the right entry
783
$('#gis_location_l4').val(data.id);
785
var exists = $("#gis_location_l3").itemExists(data.parent.toString());
787
// Set the L3 to the Parent
788
$('#gis_location_l3').val(data.parent);
790
// Reset the L3 dropdown
791
$('#gis_location_l3').val('');
793
// @ToDo Check the L2
794
// @ToDo Check the L1
795
// @ToDo Check the L0 (not needed for PK)
797
// Refresh L5 dropdown
798
$('#gis_location_l5').val('');
800
// @ToDo Reload this Dropdown
803
} else if (data.level == 'L5') {
804
// Check if that dropdown is visible
805
if ($('#gis_location_l5__row').length == 0) {
809
S3.gis.locations_l5(false);
810
// Set the right entry
811
//$('#gis_location_l5').val(data.id);
812
// @ToDo Ensure that all dropdowns above it are now visible
813
// @ToDo If we have parent data, set those too
815
// Check that our location is in this dropdown!
816
var exists = $("#gis_location_l5").itemExists(data.id.toString());
818
// Set the right entry
819
$('#gis_location_l5').val(data.id);
821
var exists = $("#gis_location_l4").itemExists(data.parent.toString());
823
// Set the L4 to the Parent
824
$('#gis_location_l4').val(data.parent);
826
// Reset the L4 dropdown
827
$('#gis_location_l4').val('');
829
// @ToDo Check the L3
830
// @ToDo Check the L2
831
// @ToDo Check the L1
832
// @ToDo Check the L0 (not needed for PK)
835
// @ToDo Reload this Dropdown
839
// Clear the Name box, so that it's free for a future sub-location