This repository was archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseController.js
More file actions
77 lines (63 loc) · 1.75 KB
/
BaseController.js
File metadata and controls
77 lines (63 loc) · 1.75 KB
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
/**
* Base controller for all controllers.
* Use this as a template for all future controllers
*
* Use of Class.js
*
* @author tommy[followed by the usual sign]julo.ca
*/
var BaseController = Class.extend({
$scope: null,
_WatchListeners: null,
_Log: null,
/**
* Initialize Notes Controller
* @param $scope, current controller scope
*/
init: function (scope, moduleName) {
this.$scope = scope;
this._WatchListeners = [];
// Initialize logger
if (!moduleName) {
this._Log = Logger.get(scope.$id);
}
else {
this._Log = Logger.get(moduleName);
}
this.defineListeners();
this.defineScope();
},
addWatch: function (name, fn, isArray) {
this._WatchListeners.push(this.$scope.$watch(name, fn, isArray));
},
/**
* Initialize listeners needs to be overrided by the subclass.
* Don't forget to call _super() to activate
*/
defineListeners: function () {
this.$scope.$on('$destroy', this.destroy.bind(this));
this.$scope.$on('$destroy', this.removeWatchListeners.bind(this));
},
/**
* Use this function to define all scope objects.
* Give a way to instantaly view whats available
* publicly on the scope.
*/
defineScope: function () {
//OVERRIDE
},
/**
* Triggered when controller is about
* to be destroyed, clear all remaining values.
*/
destroy: function (event) {
//OVERRIDE
},
removeWatchListeners: function () {
// Remove watch listeners
for (var i = 0; i < this._WatchListeners.length; i++) {
this._WatchListeners[i]();
}
}
})
BaseController.$inject = ['$scope'];