/
app.js
132 lines (110 loc) · 3.82 KB
/
app.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
(function (_, App, EntityLayoutView, EntityListItemView, EntityFormView, ModalMixin, UtilitiesMixin, $, cherrytree, Backbone) {
var $config = $('#config');
if ($config.length > 0) {
var config = JSON.parse(decodeURIComponent($config.val()));
_.extend(App, config);
}
App.isMobile = function () {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
return ((/iPhone|iPod|iPad|Android|BlackBerry|Opera Mini|IEMobile/).test(userAgent));
};
App.keyStrokes = {
backspace: 8,
tab: 9,
enter: 13,
esc: 27,
space: 32,
pageup: 33,
pagedown: 34,
end: 35,
home: 36,
left: 37,
up: 38,
right: 39,
down: 40,
insert: 45,
del: 46
};
Backbone.Radio.DEBUG = App.DEBUG_MODE;
//turn on/off logging based on environment
if (!App.DEBUG_MODE) {
console.log = function () {
};
}
//set up simple caching
var cache = {};
App.getCache = function (key, store) {
if (cache[key]) {
return cache[key];
}
if (!store) {
return undefined;
}
var result;
if (typeof (store) === "function") {
result = store();
} else {
result = store;
}
cache[key] = result;
return result;
};
App.setCache = function (key, value) {
if (_.isUndefined(cache[key]) || _.isNull(cache[key])) {
cache[key] = value;
}
};
if (_.isUndefined(App.pageSize)) {
App.pageSize = 10;
}
$('#file-manager').on('click', function (e) {
e.preventDefault();
BrowseServer();
});
App.router = cherrytree();
App.entityViewMiddleware = function render(transition) {
transition.routes.forEach(function (route, i) {
if (App.router.isActive(route.name, route.params, route.query)) {
return;
}
let routeSegments = route.name.split('.'),
count = routeSegments.length - 1,
channelName = '',
method = routeSegments[count];
for (let i = 0; i < count; i++) {
channelName += routeSegments[i];
if (i + 1 < count) {
channelName += '.';
}
}
switch (method) {
case 'getType':
Backbone.Radio.channel(channelName).trigger(method, route.params.page);
break;
case 'edit':
Backbone.Radio.channel(channelName).trigger(method, route.params[route.name.replace('.', '') + 'id']);
break;
case 'create':
Backbone.Radio.channel(channelName).trigger(method);
break;
}
});
};
App.on('destroy', function(){
this.router.destroy();
});
_.extend(EntityLayoutView.prototype, ModalMixin);
_.extend(EntityListItemView.prototype, ModalMixin);
_.extend(EntityFormView.prototype, ModalMixin);
_.extend(EntityLayoutView.prototype, UtilitiesMixin);
_.extend(EntityListItemView.prototype, UtilitiesMixin);
_.extend(EntityFormView.prototype, UtilitiesMixin);
_.extend(EntityModel.prototype, UtilitiesMixin);
_.extend(FilterFormView.prototype, UtilitiesMixin);
_.extend(EntityLayoutView.prototype, DataMixin);
_.extend(EntityListItemView.prototype, DataMixin);
_.extend(EntityFormView.prototype, DataMixin);
_.extend(FilterFormView.prototype, DataMixin);
_.extend(EntityService.prototype, DataMixin);
_.extend(Marionette.FormView.prototype, FieldsMixin);
})(_, App, EntityLayoutView, EntityListItemView, EntityFormView, ModalMixin, UtilitiesMixin, jQuery, cherrytree, Backbone);