Added pretty country flags to geoselector

This commit is contained in:
Rick Falkvinge
2015-02-22 20:11:23 +01:00
parent f983173c54
commit bb28464ebf
5 changed files with 29 additions and 16 deletions
+11 -12
View File
@@ -19,12 +19,7 @@ namespace Swarmops.Frontend.Automation
int parentGeographyId = 0;
bool initialExpand = true;
if (Request.QueryString["InitialExpand"] == "false")
{
initialExpand = false;
}
bool initialExpand = (Request.QueryString["InitialExpand"] != "false");
string parentIdString = Request.QueryString["ParentGeographyId"];
if (!string.IsNullOrEmpty (parentIdString))
@@ -37,7 +32,7 @@ namespace Swarmops.Frontend.Automation
string cacheKey = "Geographies-Json-" + parentGeographyId.ToString (CultureInfo.InvariantCulture) + "-" +
Thread.CurrentThread.CurrentCulture.Name;
string accountsJson = (string) Cache[cacheKey];
string accountsJson = null; // (string) Cache[cacheKey];
if (accountsJson != null)
{
@@ -92,6 +87,7 @@ namespace Swarmops.Frontend.Automation
foreach (TreeNode<Geography> geographyNode in geoBranch)
{
Geography geography = geographyNode.Data;
Country country = null;
string geoName = TestLocalization (geography.Name);
@@ -99,7 +95,8 @@ namespace Swarmops.Frontend.Automation
{
// Special case for country nodes: "[NativeName] ([LocalizedName])", e.g. "Deutschland (Tyskland)" for Germany when in Swedish
string localizedCountryName = GeographyNames.ResourceManager.GetString("Country_" + _countryLookup[geography.Identity].Code);
country = _countryLookup[geography.Identity];
string localizedCountryName = GeographyNames.ResourceManager.GetString("Country_" + country.Code);
string nativeCountryName = geography.Name.Split ('(')[0].Trim();
if (localizedCountryName != nativeCountryName)
@@ -115,13 +112,15 @@ namespace Swarmops.Frontend.Automation
string element = string.Format ("\"id\":{0},\"text\":\"{1}\"", geography.Identity,
JsonSanitize (TestLocalization (geoName)));
if (_countryLookup.ContainsKey (geography.Identity))
if (country != null)
{
// this is a country node. Populate with stuff to enable lazy-load of the tree.
Country country = _countryLookup[geography.Identity];
// this is a country node. Populate with stuff to enable lazy-load of the tree at this point.
element += ",\"children1\":\"\",\"state\":\"closed\"," +
string.Format ("\"countryId\":\"{0}\",\"countryNode\":\"{1}\"", country.Code, geography.Identity);
string.Format ("\"countryId\":\"{0}\",\"countryNode\":\"{1}\"", country.Code.ToLowerInvariant(), geography.Identity);
// Suppress icon to reaplce with flag
element += ",\"iconCls\":\"countryNode\"";
}
else if (geographyNode.Children.Count > 0)
{
+14 -4
View File
@@ -19,15 +19,25 @@
} else {
$.getJSON("/Automation/Json-GeographiesTree.aspx?InitialExpand=false&ParentGeographyId=" + param.id, null, success);
}
}
<%
},
onSelect: function (row) {
<%
if (!String.IsNullOrEmpty(this.OnClientSelect))
{
Response.Write(", onSelect: function(row) { " + this.OnClientSelect + "(row.id); }");
Response.Write(this.OnClientSelect + "(row.id);");
}
%>
});
},
formatter: function (row) {
// If we're at a country node, add that country's flag ahead of the country name. Replaces the folder icon (that part is done in CSS).
if (row.countryId != null) {
return "<img src='/Images/Flags/" + row.countryId + "-24px.png' style='width:16px;height:18px;vertical-align:bottom' /> " + row.text;
}
else return row.text;
}
});
$('#<%=this.ClientID %>_SpanGeographies span.combo input.combo-text').click(function () {
$('#<%=this.ClientID %>_SpanGeographies span.combo span span.combo-arrow').click();
Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

+4
View File
@@ -127,6 +127,10 @@ div.combobox-item {
}
.tree-icon.tree-folder.countryNode {
display: none; /* suppress display of node, when country flag is displayed */
}
/* TABS */