This repository has been archived by the owner on Nov 25, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-weekly.js
89 lines (85 loc) · 2.73 KB
/
angular-weekly.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(function() {
angular.module('weekly', [])
.directive('weekly', ['$parse', function($parse) {
return {
restrict: 'EA',
require: 'ngModel',
scope: {
model: '=ngModel',
selectableDates: '=weeklySelectableDates',
options: '&weekly',
weekChangeEventFn: '&weeklyChange',
addEventFn: '&weeklyAdd',
removeEventFn: '&weeklyRemove',
clickEventFn: '&weeklyClick',
timezone: '=weeklyTimezone',
readOnly: '=weeklyReadOnly'
},
link: function(scope, el, args) {
var isUpdating = false;
var options = scope.options() || {};
var fnName = 'weekly';
if (typeof args.weeklyMobile !== 'undefined') {
fnName = 'weeklyMobile';
options.daysToDisplay = 1;
}
el
.addClass('weekly')
.on('weekChange', function(e, data) {
scope.weekChangeEventFn({ data: data });
})
.on('addEvent', function(e, evnt) {
if (!isUpdating) {
scope.$apply(function() {
scope.model.push(evnt);
scope.addEventFn({ event: evnt });
});
}
})
.on('removeEvent', function(e, evnt) {
if (!isUpdating) {
var index = evnt._index;
scope.$apply(function() {
scope.model.splice(index, 1);
scope.removeEventFn({ event: evnt });
});
}
})
.on('eventClick', function(e, evnt, el) {
scope.$apply(function() {
scope.clickEventFn({ event: scope.model[evnt._index], el: el });
});
})
[fnName](options);
if (args.ngModel) {
scope.$watch('model', function(val) {
isUpdating = true;
el
[fnName]('clearEvents')
[fnName]('addEvent', val);
isUpdating = false;
}, true);
}
if (args.weeklyTimezone) {
scope.$watch('timezone', function(val) {
if (val !== null) {
el[fnName]('setTimezoneOffset', val);
}
});
}
if (args.weeklyReadOnly) {
scope.$watch('readOnly', function(val) {
if (typeof val !== 'undefined') {
el[fnName]('setReadOnly', val);
}
});
}
if (args.weeklySelectableDates) {
scope.$watch('selectableDates', function(val) {
el[fnName]('setSelectableDates', val);
});
}
}
};
}]);
})();