Skip to content

Commit

Permalink
Working on #7: refactoring to distinguish between available months an…
Browse files Browse the repository at this point in the history
…d month names. Work in progress (month selection is empty).
  • Loading branch information
Barbara Post committed Jun 2, 2017
1 parent b36d327 commit 0687f83
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ Since some bug fixes were added that conflicted with my changes, work again on i
Swapped "Set" and "Close" buttons position, from user suggestion.
### 5) v1.6.0
Fixed correct limitation of pickable day with any "from"/"to" dates configuration.
[Issue#7](https://github.com/OSAMES/ionic-datepicker/issues/7)
##License:
Expand Down
2 changes: 1 addition & 1 deletion dist/ionic-datepicker.bundle.min.js

Large diffs are not rendered by default.

22 changes: 8 additions & 14 deletions src/ionic-datepicker.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ angular.module('ionic-datepicker.provider', [])
}

$scope.currentDate = newDate;
$scope.data.currentMonth = $scope.mainObj.monthsList[$scope.currentDate.getMonth()];
$scope.data.currentMonth = $scope.monthsNames[$scope.currentDate.getMonth()];
$scope.data.currentYear = $scope.currentDate.getFullYear();
$scope.adjustSelctedDateEpoch($scope.currentDate, true);
refreshDateList($scope.currentDate);
Expand All @@ -88,7 +88,7 @@ angular.module('ionic-datepicker.provider', [])
}

$scope.currentDate = newDate;
$scope.data.currentMonth = $scope.mainObj.monthsList[$scope.currentDate.getMonth()];
$scope.data.currentMonth = $scope.monthsNames[$scope.currentDate.getMonth()];
$scope.data.currentYear = $scope.currentDate.getFullYear();
$scope.adjustSelctedDateEpoch($scope.currentDate, true);
refreshDateList($scope.currentDate);
Expand Down Expand Up @@ -185,16 +185,10 @@ angular.module('ionic-datepicker.provider', [])
var firstDay = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDate();
var lastDay = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0).getDate();

$scope.monthsList = [];
console.info("config ", $scope.mainObj.monthsList);
if ($scope.mainObj.monthsList && $scope.mainObj.monthsList.length === 12) {
$scope.monthsList = $scope.mainObj.monthsList;
} else {
$scope.monthsList = IonicDatepickerService.getMonthsList($scope.mainObj.from, $scope.mainObj.to);
}

console.info("months list ", $scope.monthsList);

// available months
$scope.monthsList = IonicDatepickerService.getMonthsList($scope.mainObj.from, $scope.mainObj.to);
// all month name
$scope.monthsNames = IonicDatepickerService.getMonthsNames($scope.mainObj.monthsList);
$scope.yearsList = IonicDatepickerService.getYearsList($scope.mainObj.from, $scope.mainObj.to);

$scope.dayList = [];
Expand Down Expand Up @@ -228,7 +222,7 @@ angular.module('ionic-datepicker.provider', [])
$scope.rows = [0, 7, 14, 21, 28, 35];
$scope.cols = [0, 1, 2, 3, 4, 5, 6];

$scope.data.currentMonth = $scope.mainObj.monthsList[currentDate.getMonth()];
$scope.data.currentMonth = $scope.monthsNames[currentDate.getMonth()];
$scope.data.currentYear = currentDate.getFullYear();
$scope.data.currentMonthSelected = angular.copy($scope.data.currentMonth);
$scope.currentYearSelected = angular.copy($scope.data.currentYear);
Expand All @@ -237,7 +231,7 @@ angular.module('ionic-datepicker.provider', [])

//Month changed
$scope.monthChanged = function (month) {
var monthNumber = $scope.monthsList.indexOf(month);
var monthNumber = $scope.monthsNames.indexOf(month);
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
monthNumber,
Expand Down
18 changes: 12 additions & 6 deletions src/ionic-datepicker.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ angular.module('ionic-datepicker.service', [])

.service('IonicDatepickerService', function () {

this.monthsList = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

this.getYearsList = function (from, to) {
var yearsList = [];
var minYear = 1900;
Expand All @@ -19,18 +17,26 @@ angular.module('ionic-datepicker.service', [])
return yearsList;
};

this.getMonthsList = function (from, to) {
// 12 items, not available months are null
this.getMonthsList = function (from, to) {
var monthsList = [];
var minMonth = 0;
var maxMonth = 11;

minMonth = from ? new Date(from).getMonth() : minMonth;
maxMonth = to ? new Date(to).getMonth() : maxMonth;

for (var i = minMonth; i <= maxMonth; i++) {
monthsList.push(i);
for (var i = 0; i <= 11; i++) {
monthsList.push(i < minMonth || i > maxMonth ? null : i);
}

return monthsList;
};
};

this.getMonthsNames = function (configNames) {
if (configNames && configNames.length === 12) {
return configNames;
}
return ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
};
});

0 comments on commit 0687f83

Please sign in to comment.