From 7b7570bb4719376b4fbb97642e168ef8b7d295ad Mon Sep 17 00:00:00 2001 From: kayvan noureddin moosa Date: Tue, 10 May 2016 13:58:50 +0430 Subject: [PATCH 1/5] 1.days of everymonth will change dynamically now,(example : february). 2.fixing demo.html --- .gitignore | 3 +- demo/index.htm | 2 +- directive.js | 79 ++++++++++++++++++++++++++++++-------------------- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index ea546a7..6fa6656 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules bower_components -npm-debug.log \ No newline at end of file +npm-debug.log +.idea \ No newline at end of file diff --git a/demo/index.htm b/demo/index.htm index 9b0743d..7af9af9 100644 --- a/demo/index.htm +++ b/demo/index.htm @@ -1,7 +1,7 @@ - + diff --git a/directive.js b/directive.js index 8dff3f4..24dc2f2 100644 --- a/directive.js +++ b/directive.js @@ -4,22 +4,23 @@ var dd = angular.module('rorymadden.date-dropdowns', []); dd.factory('rsmdateutils', function () { - var that = this, - dayRange = [1, 31], - months = [ - 'January', - 'February', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'November', - 'December' - ]; + function RsmDate() { + this.dayRange = [1, 31]; + this.months = [ + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December' + ]; + } function changeDate (date) { if(date.day > 28) { @@ -30,9 +31,9 @@ date.month--; return date; } - }; + } - return { + RsmDate.prototype = { checkDate: function (date) { var d; if (!date.day || date.month === null || date.month === undefined || !date.year) return false; @@ -45,26 +46,36 @@ return this.checkDate(changeDate(date)); }, - days: (function () { - var days = []; - while (dayRange[0] <= dayRange[1]) { - days.push(dayRange[0]++); + checkMonth: function (date) { + if (!angular.isNumber(date.month)) { + return false; + } + + this.dayRange[1] = (new Date(date.year || (new Date()).getYear(), date.month + 1, 0)).getDate(); + }, + getDays: function () { + var days = [], + start = this.dayRange[0]; + while (start <= this.dayRange[1]) { + days.push(start++); } return days; - }()), - months: (function () { + }, + getMonths: function () { var lst = [], - mLen = months.length; + mLen = this.months.length; for (var i = 0; i < mLen; i++) { lst.push({ value: i, - name: months[i] + name: this.months[i] }); } return lst; - }()) + } }; + + return new RsmDate(); }) dd.directive('rsmdatedropdowns', ['rsmdateutils', function (rsmdateutils) { @@ -76,8 +87,9 @@ model: '=ngModel' }, controller: ['$scope', 'rsmdateutils', function ($scope, rsmDateUtils) { - $scope.days = rsmDateUtils.days; - $scope.months = rsmDateUtils.months; + console.log(rsmDateUtils); + $scope.days = rsmDateUtils.getDays(); + $scope.months = rsmDateUtils.getMonths(); $scope.dateFields = {}; @@ -100,6 +112,11 @@ $scope.model = date; } }; + + $scope.checkMonth = function () { + rsmDateUtils.checkMonth($scope.dateFields); + $scope.days = rsmDateUtils.getDays(); + }; }], template: '
' + @@ -107,10 +124,10 @@ ' ' + '
' + '
' + - ' ' + + ' ' + '
' + '
' + - ' ' + + ' ' + ' ' + '
' + '', From 0b4522245cb6195c0f66ca042553103a8d98f6b5 Mon Sep 17 00:00:00 2001 From: kayvan noureddin moosa Date: Sat, 28 May 2016 15:23:53 +0430 Subject: [PATCH 2/5] fixing positioning of divisions. --- directive.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/directive.js b/directive.js index 24dc2f2..4869b2b 100644 --- a/directive.js +++ b/directive.js @@ -39,7 +39,7 @@ if (!date.day || date.month === null || date.month === undefined || !date.year) return false; d = new Date(Date.UTC(date.year, date.month, date.day)); - + if (d && (d.getMonth() === date.month && d.getDate() === Number(date.day))) { return d; } @@ -119,15 +119,21 @@ }; }], template: - '
' + - '
' + - ' ' + + '
' + + '
' + + ' ' + '
' + - '
' + - ' ' + + '
' + + ' ' + '
' + - '
' + - ' ' + + '
' + + ' ' + ' ' + '
' + '
', @@ -191,4 +197,4 @@ } }; }]); -}()); \ No newline at end of file +}()); From 396b3d827aea2286ff9ef6040512346537a97542 Mon Sep 17 00:00:00 2001 From: kayvannm Date: Mon, 29 Aug 2016 16:26:46 +0430 Subject: [PATCH 3/5] Adding ngChange and using for validation now can be used by ng-change and the answer by any change of these three fields is true/false --- directive.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/directive.js b/directive.js index 4869b2b..e013261 100644 --- a/directive.js +++ b/directive.js @@ -84,10 +84,11 @@ replace: true, require: 'ngModel', scope: { - model: '=ngModel' + model: '=ngModel', + change: '&ngChange' }, controller: ['$scope', 'rsmdateutils', function ($scope, rsmDateUtils) { - console.log(rsmDateUtils); + $scope.days = rsmDateUtils.getDays(); $scope.months = rsmDateUtils.getMonths(); @@ -111,6 +112,7 @@ if (date) { $scope.model = date; } + $scope.change({value : date}); }; $scope.checkMonth = function () { @@ -119,24 +121,24 @@ }; }], template: - '
' + - '
' + - ' ' + - '
' + - '
' + - ' ' + - '
' + - '
' + - ' ' + - ' ' + - '
' + - '
', + '
' + + '
' + + ' ' + + '
' + + '
' + + ' ' + + '
' + + '
' + + ' ' + + ' ' + + '
' + + '
', link: function (scope, element, attrs, ctrl) { var currentYear = parseInt(attrs.startingYear, 10) || new Date().getFullYear(), numYears = parseInt(attrs.numYears,10) || 100, From bc94e6271eab0b74756bfcbb7d57f83684fdf158 Mon Sep 17 00:00:00 2001 From: kayvannm Date: Mon, 29 Aug 2016 17:05:21 +0430 Subject: [PATCH 4/5] Update bower.json --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index e566451..7b87b0d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-date-dropdowns", - "version": "0.2.0", + "version": "0.5.0", "main": "directive.js", "ignore": [ "**/.*", From 8dcf981ac2c64e907bca3e0bf5f4f558115198cd Mon Sep 17 00:00:00 2001 From: kayvannm Date: Mon, 29 Aug 2016 17:08:09 +0430 Subject: [PATCH 5/5] Update bower.json --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 7b87b0d..e566451 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-date-dropdowns", - "version": "0.5.0", + "version": "0.2.0", "main": "directive.js", "ignore": [ "**/.*",