Skip to content

Commit

Permalink
fix month range bug
Browse files Browse the repository at this point in the history
  • Loading branch information
timkeane committed Jan 15, 2016
1 parent 4160681 commit 4777d31
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 116 deletions.
63 changes: 25 additions & 38 deletions src/main/js/nyc/collapsible-month-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ nyc.MonthRangePicker = function(options){
var labelMin = $('<label>The beginning of</label>'),
labelMax = $('<label>through the end of</label>');

this.minYear = options.minYear;
this.minMonth = options.minMonth;
this.maxYear = options.maxYear;
this.maxMonth = options.maxMonth;
this.minDate = this.firstOfMonth(options.minMonth, options.minYear);
this.maxDate = this.lastOfMonth(options.maxMonth, options.maxYear);

this.minDates = [];
this.maxDates = [];
Expand All @@ -34,8 +32,8 @@ nyc.MonthRangePicker = function(options){

this.populate(options);

this.min[0].selectedIndex = this.minDates.length - 1;
this.max[0].selectedIndex = this.maxDates.length - 1;
this.min.get(0).selectedIndex = this.min.children().length - 1;
this.max.get(0).selectedIndex = this.max.children().length - 1;
this.min.selectmenu().selectmenu('refresh', true);
this.max.selectmenu().selectmenu('refresh', true);

Expand All @@ -46,29 +44,27 @@ nyc.MonthRangePicker = function(options){

nyc.MonthRangePicker.prototype = {
/**
* @desc The minimum zero-indexed month
* @desc The minimum date
* @public
* @member {number}
* @member {Date}
*/
minMonth: null,
minDate: null,
/**
* @desc The minimum year
* @desc The maximum date
* @public
* @member {number}
* @member {Date}
*/
minYear: null,
maxDate: null,
/**
* @desc The maximum zero-indexed month
* @public
* @member {number}
* @private
* @member {Array<Date>}
*/
maxMonth: null,
minDates: null,
/**
* @desc The maximum year
* @public
* @member {number}
* @private
* @member {Array<Date>}
*/
maxYear: null,
maxDates: null,
/**
* @private
* @member {JQuery}
Expand Down Expand Up @@ -96,24 +92,15 @@ nyc.MonthRangePicker.prototype = {
*/
populate: function(options){
for (var year = options.minYear; year <= options.maxYear; year++){
for (var month = 0; month < 12; month++){
if (
(year == options.minYear && month >= options.minMonth) ||
(year == options.maxYear && month <= options.maxMonth) ||
(year > options.minYear && year < options.maxYear)
){
var min = this.firstOfMonth(month, year), max = this.lastOfMonth(month, year);
if (
(year >- options.minYear && month >= options.minMonth) &&
(year <= options.maxYear && month <= options.maxMonth)
){
this.minDates.push(min);
this.appendOpt(this.min, min);
}
if ((year == options.maxYear && month <= options.maxMonth) || year < options.maxYear){
this.maxDates.push(max);
this.appendOpt(this.max, max);
}
for (var month = 0; month < 12; month++){
var min = this.firstOfMonth(month, year), max = this.lastOfMonth(month, year);
if (min >= this.minDate && min <= this.maxDate){
this.minDates.push(min);
this.appendOpt(this.min, min);
}
if (max >= this.minDate && max <= this.maxDate){
this.maxDates.push(max);
this.appendOpt(this.max, max);
}
}
}
Expand Down
70 changes: 35 additions & 35 deletions src/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,46 +81,46 @@
<!-- tests -->
<script src="js/setup-teardown.js"></script>

<!-- <script src="js/nyc/nyc.js"></script> -->
<!-- <script src="js/nyc/util.js"></script> -->
<!-- <script src="js/nyc/content.js"></script> -->
<!-- <script src="js/nyc/dialog.js"></script> -->
<!-- <script src="js/nyc/lang.js"></script> -->
<!-- <script src="js/nyc/collapsible.js"></script> -->
<script src="js/nyc/nyc.js"></script>
<script src="js/nyc/util.js"></script>
<script src="js/nyc/content.js"></script>
<script src="js/nyc/dialog.js"></script>
<script src="js/nyc/lang.js"></script>
<script src="js/nyc/collapsible.js"></script>
<script src="js/nyc/collapsible-month-range.js"></script>
<!-- <script src="js/nyc/collapsible-radio.js"></script> -->
<!-- <script src="js/nyc/geocoder.js"></script> -->
<!-- <script src="js/nyc/legend.js"></script> -->
<!-- <script src="js/nyc/locationmgr.js"></script> -->
<!-- <script src="js/nyc/share.js"></script> -->
<!-- <script src="js/nyc/zoomsearch.js"></script> -->
<script src="js/nyc/collapsible-radio.js"></script>
<script src="js/nyc/geocoder.js"></script>
<script src="js/nyc/legend.js"></script>
<script src="js/nyc/locationmgr.js"></script>
<script src="js/nyc/share.js"></script>
<script src="js/nyc/zoomsearch.js"></script>

<!-- <script src="js/nyc/leaf/zoomsearch.js"></script> -->
<!-- <script src="js/nyc/leaf/locate.js"></script> -->
<!-- <script src="js/nyc/leaf/locator.js"></script> -->
<script src="js/nyc/leaf/zoomsearch.js"></script>
<script src="js/nyc/leaf/locate.js"></script>
<script src="js/nyc/leaf/locator.js"></script>

<!-- <script src="js/nyc/carto/carto.js"></script> -->
<!-- <script src="js/nyc/carto/heatsymbolizer.js"></script> -->
<!-- <script src="js/nyc/carto/jenkssymbolizer.js"></script> -->
<!-- <script src="js/nyc/carto/view.js"></script> -->
<!-- <script src="js/nyc/carto/sqlview.js"></script> -->
<!-- <script src="js/nyc/carto/chart.js"></script> -->
<!-- <script src="js/nyc/carto/popup.js"></script> -->
<script src="js/nyc/carto/carto.js"></script>
<script src="js/nyc/carto/heatsymbolizer.js"></script>
<script src="js/nyc/carto/jenkssymbolizer.js"></script>
<script src="js/nyc/carto/view.js"></script>
<script src="js/nyc/carto/sqlview.js"></script>
<script src="js/nyc/carto/chart.js"></script>
<script src="js/nyc/carto/popup.js"></script>

<!-- <script src="js/nyc/ol/draw.js"></script> -->
<!-- <script src="js/nyc/ol/featuretip.js"></script> -->
<!-- <script src="js/nyc/ol/geoserver/getfeature.js"></script> -->
<!-- <script src="js/nyc/ol/source/arcgiscache.js"></script> -->
<!-- <script src="js/nyc/ol/source/decorating.js"></script> -->
<!-- <script src="js/nyc/ol/source/filteringandsorting.js"></script> -->
<!-- <script src="js/nyc/ol/layer/baselayer.js"></script> -->
<!-- <script src="js/nyc/ol/layer/grayscale.js"></script> -->
<script src="js/nyc/ol/draw.js"></script>
<script src="js/nyc/ol/featuretip.js"></script>
<script src="js/nyc/ol/geoserver/getfeature.js"></script>
<script src="js/nyc/ol/source/arcgiscache.js"></script>
<script src="js/nyc/ol/source/decorating.js"></script>
<script src="js/nyc/ol/source/filteringandsorting.js"></script>
<script src="js/nyc/ol/layer/baselayer.js"></script>
<script src="js/nyc/ol/layer/grayscale.js"></script>

<!-- <script src="js/nyc/directions.js"></script> -->
<!-- <script src="js/nyc/ol/locate.js"></script> -->
<!-- <script src="js/nyc/ol/locator.js"></script> -->
<!-- <script src="js/nyc/ol/popup.js"></script> -->
<!-- <script src="js/nyc/ol/featuretip.js"></script> -->
<script src="js/nyc/directions.js"></script>
<script src="js/nyc/ol/locate.js"></script>
<script src="js/nyc/ol/locator.js"></script>
<script src="js/nyc/ol/popup.js"></script>
<script src="js/nyc/ol/featuretip.js"></script>

</body>
</html>
Loading

0 comments on commit 4777d31

Please sign in to comment.