~ptressel/sahana-eden/stalled

« back to all changes in this revision

Viewing changes to views/gis/location_autocomplete.js

  • Committer: Fran Boon
  • Date: 2010-09-01 00:51:37 UTC
  • Revision ID: fran@aidiq.com-20100901005137-gjw0gqwono7u2bxv
Progress the Location Selector (set the Dropdowns if an Lx is selected in the Name box), add useful jquery.form-extension library

Show diffs side-by-side

added added

removed removed

Lines of Context:
207
207
                // Show the next level of hierarchy
208
208
                S3.gis.locations_l{{=int(level) + 1}}(false);
209
209
            };
210
 
        };      
 
210
        };
 
211
        // @ToDo Test
 
212
        //var sync = true;
 
213
        //$.getJSONS3(url, load_locations, '{{=T("locations")}}', sync);
211
214
        $.getJSONS3(url, load_locations, '{{=T("locations")}}');
212
215
    }
213
216
    // When dropdown is selected
622
625
            if (data.addr_street != 'None') {
623
626
                $('#gis_location_addr_street').val(data.addr_street);
624
627
            }
 
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) {
 
638
                        // Open the dropdown
 
639
                        // @ToDo Check for bad side-effects of reusing these!
 
640
                        // Better to use arguments than flags!
 
641
                        S3.gis.level = 'L1';
 
642
                        old_id = data.id;
 
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)
 
650
                    } else {
 
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('');
 
662
                    }
 
663
                } else if (data.level == 'L2') {
 
664
                    // Check if that dropdown is visible
 
665
                    if ($('#gis_location_l2__row').length == 0) {
 
666
                        // Open the dropdown
 
667
                        S3.gis.level = 'L2';
 
668
                        old_id = data.id;
 
669
                        S3.gis.locations_l2(false);
 
670
                        // Set the right entry
 
671
                        //$('#gis_location_l2').val(data.id);
 
672
                        if (data.parent) {
 
673
                            var exists = $("#gis_location_l1").itemExists(data.parent.toString());
 
674
                            if (exists) {
 
675
                                // Set the L1 to the Parent
 
676
                                $('#gis_location_l1').val(data.parent);
 
677
                            } else {
 
678
                                // Reset the L1 dropdown
 
679
                                $('#gis_location_l1').val('');
 
680
                            }
 
681
                            // @ToDo Check the L0
 
682
                            // (Not needed for PK)
 
683
                        }
 
684
                    } else {
 
685
                        // Check that our location is in this dropdown!
 
686
                        var exists = $("#gis_location_l2").itemExists(data.id.toString());
 
687
                        if (exists) {
 
688
                            // Set the right entry
 
689
                            $('#gis_location_l2').val(data.id);
 
690
                            if (data.parent) {
 
691
                                var exists = $("#gis_location_l1").itemExists(data.parent.toString());
 
692
                                if (exists) {
 
693
                                    // Set the L1 to the Parent
 
694
                                    $('#gis_location_l1').val(data.parent);
 
695
                                } else {
 
696
                                    // Reset the L1 dropdown
 
697
                                    $('#gis_location_l1').val('');
 
698
                                }
 
699
                                // @ToDo Check the L0
 
700
                                // (Not needed for PK)
 
701
                            }
 
702
                            // Refresh L3-L5 dropdowns
 
703
                            $('#gis_location_l3').val('');
 
704
                            $('#gis_location_l4').val('');
 
705
                            $('#gis_location_l5').val('');
 
706
                        } else {
 
707
                            // @ToDo Reload this Dropdown
 
708
                        }
 
709
                    }
 
710
                } else if (data.level == 'L3') {
 
711
                    // Check if that dropdown is visible
 
712
                    if ($('#gis_location_l3__row').length == 0) {
 
713
                        // Open the dropdown
 
714
                        S3.gis.level = 'L3';
 
715
                        old_id = data.id;
 
716
                        S3.gis.locations_l3(false);
 
717
                        // Set the right entry
 
718
                        //$('#gis_location_l3').val(data.id);
 
719
                        if (data.parent) {
 
720
                            var exists = $("#gis_location_l2").itemExists(data.parent.toString());
 
721
                            if (exists) {
 
722
                                // Set the L2 to the Parent
 
723
                                $('#gis_location_l2').val(data.parent);
 
724
                            } else {
 
725
                                // Reset the L2 dropdown
 
726
                                $('#gis_location_l2').val('');
 
727
                            }
 
728
                            // @ToDo Check the L1
 
729
                            // @ToDo Check the L0 (not needed for PK)
 
730
                        }
 
731
                    } else {
 
732
                        // Check that our location is in this dropdown!
 
733
                        var exists = $("#gis_location_l3").itemExists(data.id.toString());
 
734
                        if (exists) {
 
735
                            // Set the right entry
 
736
                            $('#gis_location_l3').val(data.id);
 
737
                            if (data.parent) {
 
738
                                var exists = $("#gis_location_l2").itemExists(data.parent.toString());
 
739
                                if (exists) {
 
740
                                    // Set the L2 to the Parent
 
741
                                    $('#gis_location_l2').val(data.parent);
 
742
                                } else {
 
743
                                    // Reset the L2 dropdown
 
744
                                    $('#gis_location_l2').val('');
 
745
                                }
 
746
                                // @ToDo Check the L1
 
747
                                // @ToDo Check the L0 (not needed for PK)
 
748
                            }
 
749
                            // Refresh L4-L5 dropdowns
 
750
                            $('#gis_location_l4').val('');
 
751
                            $('#gis_location_l5').val('');
 
752
                        } else {
 
753
                            // @ToDo Reload this Dropdown
 
754
                        }
 
755
                    }
 
756
                } else if (data.level == 'L4') {
 
757
                    // Check if that dropdown is visible
 
758
                    if ($('#gis_location_l4__row').length == 0) {
 
759
                        // Open the dropdown
 
760
                        S3.gis.level = 'L4';
 
761
                        old_id = data.id;
 
762
                        S3.gis.locations_l4(false);
 
763
                        // Set the right entry
 
764
                        //$('#gis_location_l4').val(data.id);
 
765
                        if (data.parent) {
 
766
                            var exists = $("#gis_location_l3").itemExists(data.parent.toString());
 
767
                            if (exists) {
 
768
                                // Set the L3 to the Parent
 
769
                                $('#gis_location_l3').val(data.parent);
 
770
                            } else {
 
771
                                // Reset the L3 dropdown
 
772
                                $('#gis_location_l3').val('');
 
773
                            }
 
774
                            // @ToDo Check the L2
 
775
                            // @ToDo Check the L1
 
776
                            // @ToDo Check the L0 (not needed for PK)
 
777
                        }
 
778
                    } else {
 
779
                        // Check that our location is in this dropdown!
 
780
                        var exists = $("#gis_location_l4").itemExists(data.id.toString());
 
781
                        if (exists) {
 
782
                            // Set the right entry
 
783
                            $('#gis_location_l4').val(data.id);
 
784
                            if (data.parent) {
 
785
                                var exists = $("#gis_location_l3").itemExists(data.parent.toString());
 
786
                                if (exists) {
 
787
                                    // Set the L3 to the Parent
 
788
                                    $('#gis_location_l3').val(data.parent);
 
789
                                } else {
 
790
                                    // Reset the L3 dropdown
 
791
                                    $('#gis_location_l3').val('');
 
792
                                }
 
793
                                // @ToDo Check the L2
 
794
                                // @ToDo Check the L1
 
795
                                // @ToDo Check the L0 (not needed for PK)
 
796
                            }
 
797
                            // Refresh L5 dropdown
 
798
                            $('#gis_location_l5').val('');
 
799
                        } else {
 
800
                            // @ToDo Reload this Dropdown
 
801
                        }
 
802
                    }
 
803
                } else if (data.level == 'L5') {
 
804
                    // Check if that dropdown is visible
 
805
                    if ($('#gis_location_l5__row').length == 0) {
 
806
                        // Open the dropdown
 
807
                        S3.gis.level = 'L5';
 
808
                        old_id = data.id;
 
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
 
814
                    } else {
 
815
                        // Check that our location is in this dropdown!
 
816
                        var exists = $("#gis_location_l5").itemExists(data.id.toString());
 
817
                        if (exists) {
 
818
                            // Set the right entry
 
819
                            $('#gis_location_l5').val(data.id);
 
820
                            if (data.parent) {
 
821
                                var exists = $("#gis_location_l4").itemExists(data.parent.toString());
 
822
                                if (exists) {
 
823
                                    // Set the L4 to the Parent
 
824
                                    $('#gis_location_l4').val(data.parent);
 
825
                                } else {
 
826
                                    // Reset the L4 dropdown
 
827
                                    $('#gis_location_l4').val('');
 
828
                                }
 
829
                                // @ToDo Check the L3
 
830
                                // @ToDo Check the L2
 
831
                                // @ToDo Check the L1
 
832
                                // @ToDo Check the L0 (not needed for PK)
 
833
                            }
 
834
                        } else {
 
835
                            // @ToDo Reload this Dropdown
 
836
                        }
 
837
                    }
 
838
                }
 
839
                // Clear the Name box, so that it's free for a future sub-location
 
840
                // @ToDo: Critical!
 
841
            }
625
842
        });
626
843
    });
627
844