forked from shimondoodkin/nodejs-mongodb-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicmodel_setup.js
executable file
·59 lines (51 loc) · 1.76 KB
/
basicmodel_setup.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
this.main=function(app)
{
app.basicmodel.pages=
{
list:require('templates/default/list').page.call(this,app,this),
add:require('templates/default/add').page.call(this,app,this),
edit:require('templates/default/edit').page.call(this,app,this),
del:require('templates/default/del').page.call(this,app,this),
};
app.basicmodel.addpages= function(callback)
{
var p,tempalte_name,template_function;
for(p in this.pages)
{
var page=this.pages[p];
//add .model reference to page
page.model=this;
//if(this.modelname=='t1_organization') console.log(" addpages page "+p);
app.doubletemplate.load_templates(page);
}
if(callback)callback(callback);
};
app.basicmodel.addurls= function(callback)
{
var p;
// adlater calling route before, route after
for(p in this.pages)
{
var pageurl='/'+this.general.urlprefix+this.pages[p].pageurl;
//app.url_routes.push({path:pageurl,code:function(req,res,page,callback){res.writeHead(200, { 'Content-Type': 'text/plain'});res.write('hello world');res.end();}});
app.url_routes.push({path:pageurl,page:this.pages[p]});
}
if(callback)callback(callback);
};
app.basicmodel.setupfirst= function( data )
{
};
app.basicmodel.setup= function( data )
{
};
app.basicmodel.setuplast= function( data )
{
app.prepare_subitems_lists(this);
var self = this;
app._.foreach(this.fields , function(field , field_key){
self.empty_object[field_key] = '';
});
this.addpages();
this.addurls();
};
}