forked from appdevdesigns/appdevjs_hris_old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
def_hris.js
322 lines (231 loc) · 7.5 KB
/
def_hris.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/**
* @class hris
* @parent Installed_Modules
*
* ###hris Module
*
* This module <insert short description>
*
*/
//required to separate comment blocks for documentjs, please do not remove
var __filler;
/**
* @class hris.server
* @parent hris
*
* ##hris server
*
* hris server side
*/
//required to separate comment blocks for documentjs, please do not remove
var __filler;
/**
* @class hris.server.api
* @parent hris.server
*
* ##hris server side apis
*
* hris server side apis
*/
//required to separate comment blocks for documentjs, please do not remove
var __filler;
/**
* @class hris.server.models
* @parent hris.server
*
* ##hris server side models
*
* hris server side models
*/
//required to separate comment blocks for documentjs, please do not remove
var __filler;
/**
* @class hris.server.module_apis
* @parent hris.server
*
* ##hris server side module apis
*
* hris server side module apis
*/
//required to separate comment blocks for documentjs, please do not remove
var __filler;
/**
* @class hris.client
* @parent hris
*
* ##hris client
*
* hris client side
*/
//required to separate comment blocks for documentjs, please do not remove
var __filler;
/**
* @class hris.client.pages
* @parent hris.client
*
* ##hris client side pages
*
* hris client side pages
*/
//required to separate comment blocks for documentjs, please do not remove
var __filler;
/**
* @class hris.titanium
* @parent hris
*
* ##hris titanium
*
* hris titanium
*/
//required to separate comment blocks for documentjs, please do not remove
var __filler;
/**
* @class hris.server.Object
* @parent hris.server
*
* ##HRiS Object operations
*
* The different operations for working with an instance of a defined object
* in HRiS.
*/
//required to separate comment blocks for documentjs, please do not remove
var __filler;
// Replace These Tags:
// hris : <-- the name of this module (lowercase)
// Hris : <-- the name of this module (uppercase)
var log = AD.Util.Log;
var $ = AD.jQuery;
////
//// Hris Module
////
var hrisModule = new AD.App.Module({
nameModule: 'hris',
pathModule: __dirname,
/*
// change the default paths like this:
pathPages: __dirname + '/web/pages',
pathServerModels: __dirname + '/models/node',
pathClientModels: __dirname + '/models/client',
pathModuleScripts: __dirname + '/data/scripts',
pathModuleCSS: __dirname + '/data/css'
*/
/*
// If you want to override the default notification hub settings:
hub: {
wildcard: true, // should the event emitter use wildcards.
delimiter: '.', // the delimiter used to segment namespaces.
maxListeners: 0, // the max number of listeners that can be assigned to an event (defautl:10; 0:unlimited).
}
*/
});
hrisModule.createRoutes();
var mI = hrisModule.initialize(); // mI == Module Initialization Done
$.when(mI).then(function(){
// do any post initialization setup instructions here.
// by the time you get here, all module resources are loaded.
});
module.exports = hrisModule;
exports.version = 1; // v1 of our AD.App.Module Definition
var app = hrisModule.app;
// Don't want this to be Global, but all server side services can access this.
hrisModule.HRiS = require(__dirname + '/server/data/HRiS.js');
var errorLabels = null;
var labelsLoaded = AD.Lang.labelsForPath('/hris/errors');
$.when(labelsLoaded)
.then(function(labels) {
errorLabels = labels;
//console.log('hris error labels!:');
//console.log(errorLabels);
});
var errorMessages = {
'OBJ_NOT_FOUND': { id:1, key:'[hris.error.objNotFound]'},
'ERR_TABLE_ACCESS': { id:2, key:'[hris.error.tableAccess]'},
'ERR_NO_PERMISSION': { id:3, key:'[site.common.noPermission]'},
'ERR_FILTERED_IDS' : { id:4, key:'[hris.error.filteredIDs]'},
'ERR_NON_CACHED_OBJ': { id:5, key:'[hris.error.nonCachedObj]'},
'ERR_PACKAGING_OBJ': { id:6, key:'[hris.error.packagingObj]' },
'ERR_OBJ_CREATE': { id:10, key:'[hris.error.objCreate]' },
'ERR_OBJ_UPDATE': { id:11, key:'[hris.error.objUpdate]' },
'ERR_OBJ_NO_PARAM': { id:12, key:'[hris.error.noParams]' },
'ERR_FIND': { id:20, key:'[hris.error.find]' }, // error finding desired information
'ERR_CREATE': { id:21, key:'[hris.error.create]'}, // error creating object
'ERR_UPDATE': { id:22, key:'[hirs.error.update]' }, // error updating object
'ERR_DESTROY': { id:23, key:'[hris.error.destroy]' } // error destorying object
}
hrisModule.Error = function (req, res, key, param, code) {
if (typeof code == 'undefined') {
if (typeof param == 'number') {
// Error called with no param ... eg:
// Error(req, res, key, code);
code = param;
param = {};
} else {
// hmmmm ... just send a default 400
code = AD.Const.HTTP.ERROR_CLIENT; // default to 400: client fault ... why not?
}
}
if (typeof errorMessages[key] == 'undefined') {
// key not found in our defined error messages:
// assume param is the error data to send
AD.Comm.Service.sendError(req, res, param, code );
} else {
var err = errorMessages[key];
var viewer = AD.Viewer.currentViewer(req);
//console.log(viewer);
var label = errorLabels.label(err.key, viewer.languageKey);
// service response
var errorData = { errorID:err.id, errorMSG:label, errorKey:key, data:param };
AD.Comm.Service.sendError(req, res, errorData, code );
}
}
//add our Error routine to HRiS:
hrisModule.HRiS.errorMsg = hrisModule.Error;
/*
////
//// setup any Hris specific routes here
////
### If you want to override the default Route Handling then
### remove hrisModule.createRoutes(); and uncomment this section.
### Make your changes here:
////
//// On any /hris/* route, we make sure our Client Models are loaded:
////
app.get('/init/hris/*', function(req, res, next) {
log(req,' init/' + hrisModule.nameModule + '/* : adding model dependencies.');
AD.App.Page.addJavascripts( req, hrisModule.moduleScripts );
AD.App.Page.addJavascripts( req, hrisModule.listModelPaths );
next();
});
////
//// Return any Module defined resources
////
app.get('/hris/data/:resourcePath', function(req, res, next) {
log(req,' /' + hrisModule.nameModule + '/data/ being processed.');
var parts = req.url.split('/'+hrisModule.nameModule+'/');
var urlParts = parts[1].split('?');
var path = urlParts[0]; // without any additional params
res.sendfile( hrisModule.pathModule+'/'+path);
});
### If you want to change/prevent any of the automatic directory
### scanning, then remove the hrisModule.initialize() and
### uncomment these lines :
////
//// Scan any sub interfaces to gather their routes
////
hrisModule.loadInterfaces();
////
//// The Model objects
////
//// Load the Server side model objects to handle incoming model actions.
////
hrisModule.loadModels();
exports.listModels=hrisModule.listModels;
////
////
//// Load the shared scripts that need to be used on each interface.
hrisModule.loadModuleScripts();
//// Load the services associated with this Module.
hrisModule.loadServices();
//// Load any shared CSS files defined by this Module.
hrisModule.loadModuleCSS();
*/