Skip to content

Commit 377da75

Browse files
committed
Completed task AtlasOfLivingAustralia#28 -> Display number of occurrences when user select a group
1 parent 0e3a36e commit 377da75

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

grails-app/views/regions/region.gsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</section>
5050
</g:if>
5151

52-
<h2 id="occurrenceRecords">Occurrence records</h2>
52+
<h2 id="occurrenceRecords">Occurrence records <span id="totalRecords"></span></h2>
5353
</div>
5454
</div>
5555

web-app/js/region.js

+29
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,33 @@ var region = {
6161
else {
6262
return regionFid + ':"' + regionName + '"';
6363
}
64+
},
65+
66+
/**
67+
* Formats numbers as human readable. Handles numbers in the millions.
68+
* @param count the number
69+
*/
70+
format: function(count) {
71+
if (count >= 1000000) {
72+
return count.numberFormat("#,#0,,.00 million");
73+
}
74+
return region.addCommas(count);
75+
},
76+
77+
/**
78+
* Inserts commas into a number for display.
79+
* @param nStr
80+
*/
81+
addCommas: function(nStr) {
82+
nStr += '';
83+
x = nStr.split('.');
84+
x1 = x[0];
85+
x2 = x.length > 1 ? '.' + x[1] : '';
86+
var rgx = /(\d+)(\d{3})/;
87+
while (rgx.test(x1)) {
88+
x1 = x1.replace(rgx, '$1' + ',' + '$2');
89+
}
90+
return x1 + x2;
6491
}
6592
};
6693

@@ -366,6 +393,8 @@ var RegionWidget = function (config) {
366393

367394
speciesLoaded: function() {
368395
$('#species').effect('highlight', 2000);
396+
$('#totalRecords').text('(' + region.format(parseInt($('#moreSpeciesZone').attr('totalRecords'))) + ')');
397+
$('#occurrenceRecords').effect('highlight', 2000);
369398
},
370399

371400
showMoreSpecies: function() {

0 commit comments

Comments
 (0)