Skip to content

Commit

Permalink
Fixed #6, almost ready for publication.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbara Post committed May 5, 2017
1 parent 0dd5bf6 commit 3cdd58a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 48 deletions.
20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

##Introduction:

This is an `ionic-datepicker` bower component, which can be used in any Ionic framework's application. No additional plugins required for this component.
This is an Ionic date picker, but also week and month picker, as a bower component, which can be used in any Ionic framework's application. No additional plugins required for this component.
This plugin is completely open source.

OSAMES' fork intends to add some features, supporting ionic v1 for now.
Indeed, the original author wasn't interested by our addition of week and month picking.
Hence the bower package name `ionic-datepicker-fork-ionic1`.
OSAMES forked from version 1.2.1, starting with first release as version 1.3.0.


## For ionic v2, this component is under development by the original author.
You can check it [here](https://github.com/rajeshwarpatlolla/ionic2-datepicker)

[View original author's Demo](http://rajeshwarpatlolla.github.io/DatePickerForIonicFramework/demo/ "Demo")

##Prerequisites.

* node.js, npm
Expand Down Expand Up @@ -188,6 +187,9 @@ The first screen shot shows the popup and the second shows the modal of this plu
<img src="https://lh3.googleusercontent.com/iMB88WThVW9om9EwFTaXprMWCXjbm9dm5A9aGjC497seWtX37rjzxynRrnVRYgXN9ORy5gjzhKilgdlt-eB53cXIAovFgqicuJ4UXn-HkLNZflkenUM6_k-sbK-GkNCzCfB1rd3wD5m0zgJ5dhJ3CniDUNKygQbo5f4W7JldSz93nVzdOb3OLqgcmZFeSY-FeWdovQi6zYttUPOaem5_47vF2ikt-ZW6H5UL0FI4WGcJSeAdu7wNsdoE5KY_oQfBTpsbl24eUrTxYPXhoNpcUNxRXjGnF31tDWD-jTEOJZZ9lqTnEK3OZ0g4Rci5jeq_wDmOfT0A11HXICbyL9asAPvB6TNrcOWj_qGUIrJtPeiaRDDgk8GYM2gVBY23xiOW3K5lERIfn6HTSNsZCbQciV0oFBROL3wHNuNGA-3mot_jP9ZJgyHz7f0VrWg5fytot3nDB2Gp4bMWsjXk-VOWoCP3lHc75vOvhOZb1ybemB95JI0RiYCdJMaytjzFWPsS5i3J1yEk0FS4PMyH1HEhYPPB48Et9ullJodL9nxDLvpTxJYzf8yqwC_V-pic-WHNgm9f=w382-h678-no" width="360" height="640" />
<img src="https://lh3.googleusercontent.com/GzTwRh3IHzF9UieGIJTbQwTIosA101q32OSXEcgDFj7GdG7vHvs9Vj5DpWLj0HOny-zqM6zNRdqAkWlgZv_CnpqLEZNX9EP86xFkknkdtFczd6_63XmlsPgbCiArWAqtVpzjZuhfxPujbm_b52hfyAEBBvNOTrd7VcHmVsZYiwoqVggRYyaOxvEobVxTOF7eB0iXiNIBSnOIFcwla8y9nDFJp2ilgBiMCuI7gEuVW95axHlouFOhyOBILG1u-tO28oLXvqxBnWbZDjjciaKJtB8xBZLH5TsIxyH477dMjTr6SYaykZA1tBHHFlgM9AwrWsnCmaPyP1hNIanCEeuemy9Stt5_2Y5u3el7AwUqGQ7C2ZSYs9nJ0ezHhfTJnF7bpONNWVhHE3G6XpuwKOStUdTli70_mWV8Hx_Ennwdh5FrnjLTnltUve4VCtv3sWNxBxN9_rcwymLneeWIB8X1y8E_ulzxQcMG6YJ3Cf-1WrMRTOR-3SQBgm4R0MQjSau1hgYie6u35dIb0h2FirT540xs4EvUWzT8w4Pv6r9Cze5EsgSHAK54F1In8SG8VtBUCQj4=w382-h678-no" width="360" height="640" />

### Week and month selection :

TODO ADD MY SCREENSHOTS

##CSS Classes:

Expand Down Expand Up @@ -236,7 +238,7 @@ First releases of fork: added ability to select a week or month in addition to s
[Issue#4](https://github.com/OSAMES/ionic-datepicker/issues/4)
[Issue#5](https://github.com/OSAMES/ionic-datepicker/issues/5)

### 2) v1.5.0
### 3) v1.5.0
Synchronization with original project's master as of 27-03-2017.
Since some bug fixes were added that conflicted with my changes, work again on issues #4 and #5 as
[Issue#6](https://github.com/OSAMES/ionic-datepicker/issues/6)
Expand All @@ -248,14 +250,4 @@ Since some bug fixes were added that conflicted with my changes, work again on i
https://github.com/OSAMES/ionic-datepicker
##Contact (original author):
Gmail : rajeshwar.patlolla@gmail.com
Github : https://github.com/rajeshwarpatlolla
Twitter : https://twitter.com/rajeshwar_9032
Facebook : https://www.facebook.com/rajeshwarpatlolla
Paypal : rajeshwar.patlolla@gmail.com
Comment or Rate it : http://market.ionic.io/plugins/ionicdatepicker
2 changes: 1 addition & 1 deletion dist/ionic-datepicker.bundle.min.js

Large diffs are not rendered by default.

Binary file added screenshots/month_selection_modal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/month_selection_popup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/week_selection_modal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/week_selection_popup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 47 additions & 31 deletions src/ionic-datepicker.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,44 @@ angular.module('ionic-datepicker.provider', [])

//Previous month
$scope.prevMonth = function () {
if ($scope.currentDate.getMonth() === 1) {
$scope.currentDate.setFullYear($scope.currentDate.getFullYear());
}
$scope.currentDate.setMonth($scope.currentDate.getMonth() - 1);
var fromDateTmp = new Date($scope.fromDate);
if ($scope.currentDate.getFullYear() <= fromDateTmp.getFullYear() &&
$scope.currentDate.getMonth() <= fromDateTmp.getMonth()) return;
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
selectedDate.getMonth() - 1,
selectedDate.getFullYear() - (selectedDate.getMonth() == 0 ? 1 : 0));
$scope.currentDate = resetHMSM(new Date($scope.currentDate.getFullYear(), $scope.currentDate.getMonth() - 1, newDay));
$scope.data.currentMonth = $scope.mainObj.monthsList[$scope.currentDate.getMonth()];
$scope.data.currentYear = $scope.currentDate.getFullYear();
$scope.adjustSelctedDateEpoch($scope.currentDate, true);
refreshDateList($scope.currentDate);
changeDaySelected();
};

//Next month
$scope.nextMonth = function () {
if ($scope.currentDate.getMonth() === 11) {
$scope.currentDate.setFullYear($scope.currentDate.getFullYear());
}
$scope.currentDate.setMonth($scope.currentDate.getMonth() + 1);
var toDateTmp = new Date($scope.toDate);
if ($scope.currentDate.getFullYear() >= toDateTmp.getFullYear() &&
$scope.currentDate.getMonth() >= toDateTmp.getMonth()) return;
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
selectedDate.getMonth() + 1,
selectedDate.getFullYear() + (selectedDate.getMonth() == 11 ? 1 : 0));
$scope.currentDate = resetHMSM(new Date($scope.currentDate.getFullYear(), $scope.currentDate.getMonth() + 1, newDay));
$scope.data.currentMonth = $scope.mainObj.monthsList[$scope.currentDate.getMonth()];
$scope.data.currentYear = $scope.currentDate.getFullYear();
$scope.adjustSelctedDateEpoch($scope.currentDate, true);
refreshDateList($scope.currentDate);
changeDaySelected();
};

var changeDaySelected = function() {
var newSelectedDate = new Date($scope.selctedDateEpoch);
newSelectedDate.setMonth($scope.currentDate.getMonth());
newSelectedDate.setYear($scope.currentDate.getFullYear());
$scope.selctedDateEpoch = newSelectedDate.getTime();
$scope.adjustSelctedDateEpoch(newSelectedDate, true);
};
//Get the acceptable day
var getAcceptableDay = function(currentDay, newMonth, newYear) {
var nbDaysInMonth = new Date(newYear, newMonth+1, 0).getDate();
if(currentDay > nbDaysInMonth) {
currentDay = nbDaysInMonth;
}
return currentDay;
};

//Date selected
$scope.dateSelected = function (selectedDate) {
Expand All @@ -91,9 +100,9 @@ angular.module('ionic-datepicker.provider', [])

//Set today as date for the modal
$scope.setIonicDatePickerTodayDate = function () {
var today = new Date();
refreshDateList(new Date());
$scope.selctedDateEpoch = resetHMSM(today).getTime();
var today = resetHMSM(new Date());
$scope.adjustSelctedDateEpoch(today, true);
refreshDateList(today);
};

//Set date for the modal
Expand All @@ -111,8 +120,9 @@ angular.module('ionic-datepicker.provider', [])
// When false, event call and item of $scope.dayList passed.
$scope.adjustSelctedDateEpoch = function(selectedDate, initialSelRawDate) {
var selectedTime = initialSelRawDate ? selectedDate.getTime() : selectedDate.epoch;
var d;
if($scope.mainObj.selectMode == 'week') {
var d = new Date(selectedTime);
d = new Date(selectedTime);
if($scope.mainObj.mondayFirst) {
d.setDate(d.getDate() - new Date(selectedTime).getDay() + 1);
} else {
Expand All @@ -122,7 +132,7 @@ angular.module('ionic-datepicker.provider', [])
d.setDate(d.getDate() + 6);
$scope.selctedDateEpochEndWeek = d.getTime();
} else if($scope.mainObj.selectMode == 'month') {
var d = new Date(selectedTime);
d = new Date(selectedTime);
d.setDate(1);
selectedTime = d.getTime();
var nbDaysInMonth = new Date(d.getYear(), d.getMonth()+1, 0).getDate();
Expand Down Expand Up @@ -203,18 +213,24 @@ angular.module('ionic-datepicker.provider', [])
//Month changed
$scope.monthChanged = function (month) {
var monthNumber = $scope.monthsList.indexOf(month);
$scope.currentDate.setMonth(monthNumber);
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
monthNumber,
selectedDate.getFullYear());
$scope.currentDate = resetHMSM(new Date($scope.currentDate.getFullYear(), monthNumber, newDay));
$scope.adjustSelctedDateEpoch($scope.currentDate, true);
refreshDateList($scope.currentDate);

changeDaySelected();
};

//Year changed
$scope.yearChanged = function (year) {
$scope.currentDate.setFullYear(year);
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
selectedDate.getMonth(),
year);
$scope.currentDate = resetHMSM(new Date(year, $scope.currentDate.getMonth(), newDay));
$scope.adjustSelctedDateEpoch($scope.currentDate, true);
refreshDateList($scope.currentDate);

changeDaySelected();
};

//Setting up the initial object
Expand Down Expand Up @@ -296,9 +312,9 @@ angular.module('ionic-datepicker.provider', [])
text: $scope.mainObj.todayLabel,
type: 'button_today',
onTap: function (e) {
var today = new Date();
refreshDateList(new Date());
$scope.selctedDateEpoch = resetHMSM(today).getTime();
var today = resetHMSM(new Date());
$scope.adjustSelctedDateEpoch(today, true);
refreshDateList(today);
e.preventDefault();
}
});
Expand Down
4 changes: 4 additions & 0 deletions test/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ <h1 class="title">Test of ionic date picker</h1>
<ion-content ng-controller="mainController">

<div id="options">
<div class="row">
<div class="col100">Dates: From 2012-01-01 to 2018-12-31.
</div>
</div>
<div class="row">
<div class="col25">OPTIONS
</div>
Expand Down
4 changes: 3 additions & 1 deletion test/www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ angular.module('starter.controllers', [])
closeOnSelect: $scope.options.close == "close", //Optional
templateType: $scope.options.style, //Optional
selectMode: $scope.options.range, //Optional
showTodayButton: $scope.options.today == "today" //Optional
showTodayButton: $scope.options.today == "today", //Optional
from: new Date(2012, 0, 1), //Optional
to: new Date(2018, 11, 31) //Optional
};

ionicDatePicker.openDatePicker(ipObj1);
Expand Down
4 changes: 4 additions & 0 deletions test_original_datepicker/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ <h1 class="title">Test of original project's ionic date picker</h1>
<ion-content ng-controller="mainController">

<div id="options">
<div class="row">
<div class="col100">Dates: From 2012-01-01 to 2018-12-31.
</div>
</div>
<div class="row">
<div class="col25">OPTIONS
</div>
Expand Down
4 changes: 3 additions & 1 deletion test_original_datepicker/www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ angular.module('starter.controllers', [])
closeOnSelect: $scope.options.close == "close", //Optional
templateType: $scope.options.style, //Optional
selectMode: $scope.options.range, //Optional
showTodayButton: $scope.options.today == "today" //Optional
showTodayButton: $scope.options.today == "today", //Optional
from: new Date(2012, 0, 1), //Optional
to: new Date(2018, 11, 31) //Optional
};

ionicDatePicker.openDatePicker(ipObj1);
Expand Down

0 comments on commit 3cdd58a

Please sign in to comment.