Updating the add city button.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 8 Aug 2017 18:32:27 +0000 (14:32 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 8 Aug 2017 18:34:02 +0000 (14:34 -0400)
Now when adding the city it sorts the state list.
Also done with mailing address.
commenting out a call that was giving an error.
Think the geocode thing is done on the map button anyways.

views/admin/member/memberInfo.html

index 9c8808d..8429b32 100644 (file)
                 $("#newCityDialog").dialog("open");
             });
 
+            function sortSelectOptions(selector, skip_first) {
+                var options = (skip_first) ? $(selector + ' option:not(:first)') : $(selector + ' option');
+                var arr = options.map(function(_, o) { return { t: $(o).text().trim(), v: o.value, s: $(o).prop('selected') }; }).get();
+                arr.sort(function(o1, o2) {
+                  var t1 = o1.t.toLowerCase(), t2 = o2.t.toLowerCase();
+                  return t1 > t2 ? 1 : t1 < t2 ? -1 : 0;
+                });
+                options.each(function(i, o) {
+                    o.value = arr[i].v;
+                    $(o).text(arr[i].t);
+                    if (arr[i].s) {
+                        $(o).attr('selected', 'selected').prop('selected', true);
+                    } else {
+                        $(o).removeAttr('selected');
+                        $(o).prop('selected', false);
+                    }
+                });
+            }
+
             // Submit new city
             var newCityAdded = false;
             $('#newCitySubmit').click( function() {
                     // Add the new city name to the city picklist
                     $('#city').append('<option value="-1">' + newCityName + '</option>');
                     $('#city').val(-1);
+                    sortSelectOptions( '#city', true );
                     $('#newCityNameTD').append('<input type="hidden" name="newCity" value="' + newCityName + '">');
                     newCityAdded = true;
 
 
                 $("#newCityDialog").dialog("close");
 
-                glmGeocode();
+                // This was giving an error.
+                //glmGeocode();
 
             });
 
+
             /*
              * New Mailing City Dialog
              */
                     // Add the new city name to the city picklist
                     $('#mailing_city').append('<option value="-1">' + newMailingCityName + '</option>');
                     $('#mailing_city').val(-1);
+                    sortSelectOptions( '#mailing_city', true );
                     $('#newMailingCityNameTD').append('<input type="hidden" name="newMailingCity" value="' + newMailingCityName + '">');
                     newMailingCityAdded = true;
 
 
                 $("#newMailingCityDialog").dialog("close");
 
-                glmGeocode();
-
             });
 
             /*