Skip to content

Commit 56c0119

Browse files
committed
Merge pull request #62 from sendilkumarn/disableSelection
Disable Selection
2 parents 273d972 + a69bb6c commit 56c0119

File tree

5 files changed

+83
-23
lines changed

5 files changed

+83
-23
lines changed

angular-material-calendar.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ angular.module("materialCalendar").service("MaterialCalendarData", [function ()
166166

167167
angular.module("materialCalendar").directive("calendarMd", ["$compile", "$parse", "$templateRequest", "$q", "materialCalendar.Calendar", "MaterialCalendarData", function ($compile, $parse, $templateRequest, $q, Calendar, CalendarData) {
168168

169-
var defaultTemplate = "<md-content layout='column' layout-fill md-swipe-left='next()' md-swipe-right='prev()'><md-toolbar><div class='md-toolbar-tools' layout='row'><md-button class='md-icon-button' ng-click='prev()' aria-label='Previous month'><md-tooltip ng-if='::tooltips()'>Previous month</md-tooltip>&laquo;</md-button><div flex></div><h2 class='calendar-md-title'><span>{{ calendar.start | date:titleFormat:timezone }}</span></h2><div flex></div><md-button class='md-icon-button' ng-click='next()' aria-label='Next month'><md-tooltip ng-if='::tooltips()'>Next month</md-tooltip>&raquo;</md-button></div></md-toolbar><!-- agenda view --><md-content ng-if='weekLayout === columnWeekLayout' class='agenda'><div ng-repeat='week in calendar.weeks track by $index'><div ng-if='sameMonth(day)' ng-class='{&quot;disabled&quot; : isDisabled(day,startDateOfMonth,noOfDays), active: active === day, currentDayHighlight : isCurrentDay(day) }' ng-click='handleDayClick(day)' ng-repeat='day in week' layout><md-tooltip ng-if='::tooltips()'>{{ day | date:dayTooltipFormat:timezone }}</md-tooltip><div>{{ day | date:dayFormat:timezone }}</div><div flex ng-bind-html='dataService.data[dayKey(day)]'></div></div></div></md-content><!-- calendar view --><md-content ng-if='weekLayout !== columnWeekLayout' flex layout='column' class='calendar'><div layout='row' class='subheader'><div layout-padding class='subheader-day' flex ng-repeat='day in calendar.weeks[0]'><md-tooltip ng-if='::tooltips()'>{{ day | date:dayLabelTooltipFormat }}</md-tooltip>{{ day | date:dayLabelFormat }}</div></div><div ng-if='week.length' ng-repeat='week in calendar.weeks track by $index' flex layout='row'><div tabindex='{{ sameMonth(day) ? (day | date:dayFormat:timezone) : 0 }}' ng-repeat='day in week track by $index' ng-click='handleDayClick(day)' flex layout layout-padding ng-class='{&quot;disabled&quot; : isDisabled(day,startDateOfMonth,noOfDays), &quot;active&quot;: isActive(day), &quot;md-whiteframe-12dp&quot;: hover || focus }' ng-focus='focus = true;' ng-blur='focus = false;' ng-mouseleave='hover = false' ng-mouseenter='hover = true'><md-tooltip ng-if='::tooltips()'>{{ day | date:dayTooltipFormat }}</md-tooltip><div>{{ day | date:dayFormat }}</div><div flex ng-bind-html='dataService.data[dayKey(day)]'></div></div></div></md-content></md-content>";
169+
var defaultTemplate = "<md-content layout='column' layout-fill md-swipe-left='next()' md-swipe-right='prev()'><md-toolbar><div class='md-toolbar-tools' layout='row'><md-button class='md-icon-button' ng-click='prev()' aria-label='Previous month'><md-tooltip ng-if='::tooltips()'>Previous month</md-tooltip>&laquo;</md-button><div flex></div><h2 class='calendar-md-title'><span>{{ calendar.start | date:titleFormat:timezone }}</span></h2><div flex></div><md-button class='md-icon-button' ng-click='next()' aria-label='Next month'><md-tooltip ng-if='::tooltips()'>Next month</md-tooltip>&raquo;</md-button></div></md-toolbar><!-- agenda view --><md-content ng-if='weekLayout === columnWeekLayout' class='agenda'><div ng-repeat='week in calendar.weeks track by $index'><div ng-if='sameMonth(day)' ng-class='{&quot;disabled&quot; : isDisabled(day), active: active === day }' ng-click='handleDayClick(day)' ng-repeat='day in week' layout><md-tooltip ng-if='::tooltips()'>{{ day | date:dayTooltipFormat:timezone }}</md-tooltip><div>{{ day | date:dayFormat:timezone }}</div><div flex ng-bind-html='dataService.data[dayKey(day)]'></div></div></div></md-content><!-- calendar view --><md-content ng-if='weekLayout !== columnWeekLayout' flex layout='column' class='calendar'><div layout='row' class='subheader'><div layout-padding class='subheader-day' flex ng-repeat='day in calendar.weeks[0]'><md-tooltip ng-if='::tooltips()'>{{ day | date:dayLabelTooltipFormat }}</md-tooltip>{{ day | date:dayLabelFormat }}</div></div><div ng-if='week.length' ng-repeat='week in calendar.weeks track by $index' flex layout='row'><div tabindex='{{ sameMonth(day) ? (day | date:dayFormat:timezone) : 0 }}' ng-repeat='day in week track by $index' ng-click='handleDayClick(day)' flex layout layout-padding ng-class='{&quot;disabled&quot; : isDisabled(day), &quot;active&quot;: isActive(day), &quot;md-whiteframe-12dp&quot;: hover || focus }' ng-focus='focus = true;' ng-blur='focus = false;' ng-mouseleave='hover = false' ng-mouseenter='hover = true'><md-tooltip ng-if='::tooltips()'>{{ day | date:dayTooltipFormat }}</md-tooltip><div>{{ day | date:dayFormat }}</div><div flex ng-bind-html='dataService.data[dayKey(day)]'></div></div></div></md-content></md-content>";
170170

171171
var injectCss = function () {
172172
var styleId = "calendarMdCss";
@@ -202,7 +202,8 @@ angular.module("materialCalendar").directive("calendarMd", ["$compile", "$parse"
202202
startDateOfMonth: "=?",
203203
noOfDays: "=?",
204204
clearDataCacheOnLoad: "=?",
205-
disableFutureSelection: "=?"
205+
disableFutureSelection: "=?",
206+
disableSelection: "=?"
206207
},
207208
link: function ($scope, $element, $attrs) {
208209

@@ -239,7 +240,8 @@ angular.module("materialCalendar").directive("calendarMd", ["$compile", "$parse"
239240
$scope.dayFormat = $scope.dayFormat || "d";
240241
$scope.dayTooltipFormat = $scope.dayTooltipFormat || "fullDate";
241242
$scope.disableFutureSelection = $scope.disableFutureSelection || false;
242-
243+
$scope.disableSelection = $scope.disableSelection || false;
244+
243245
$scope.sameMonth = function (date) {
244246
var d = angular.copy(date);
245247
return d.getFullYear() === $scope.calendar.year &&
@@ -252,11 +254,6 @@ angular.module("materialCalendar").directive("calendarMd", ["$compile", "$parse"
252254
return !$scope.sameMonth(date);
253255
};
254256

255-
$scope.isCurrentDay = function(date) {
256-
var currentDate = new Date();
257-
return angular.equals(date.getDate(), currentDate.getDate()) && angular.equals(date.getMonth(), currentDate.getMonth()) && angular.equals(date.getFullYear(), currentDate.getFullYear());
258-
};
259-
260257
$scope.calendarDirection = $scope.calendarDirection || "horizontal";
261258

262259
$scope.$watch("calendarDirection", function (val) {
@@ -323,7 +320,11 @@ angular.module("materialCalendar").directive("calendarMd", ["$compile", "$parse"
323320
if($scope.disableFutureSelection && date > new Date()) {
324321
return;
325322
}
326-
323+
324+
if($scope.disableSelection) {
325+
return;
326+
}
327+
327328
var active = angular.copy($scope.active);
328329
if (angular.isArray(active)) {
329330
var idx = dateFind(active, date);

0 commit comments

Comments
 (0)