/
app.js
executable file
·117 lines (89 loc) · 2.74 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
// Generated by CoffeeScript 1.6.3
(function() {
var Home, Post, Posts, PostsShow, Show, app, _ref,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
_this = this;
app = require('zygote').config({
port: 4444,
dbname: 'omb2',
dbuser: 'brian',
dbpass: '',
dbhost: 'localhost',
dbport: 5432
});
Post = (function(_super) {
__extends(Post, _super);
function Post() {
_ref = Post.__super__.constructor.apply(this, arguments);
return _ref;
}
return Post;
})(app.Model);
Home = (function(_super) {
__extends(Home, _super);
function Home() {
Home.__super__.constructor.apply(this, arguments);
this.controller = new Posts(this.model, this);
}
return Home;
})(app.View);
Show = (function(_super) {
__extends(Show, _super);
function Show(model, req, res, id) {
Show.__super__.constructor.apply(this, arguments);
this.controller = new PostsShow(this.model, this, id);
}
return Show;
})(app.View);
PostsShow = (function(_super) {
__extends(PostsShow, _super);
function PostsShow(Post, View, id) {
PostsShow.__super__.constructor.apply(this, arguments);
Post.find(id);
}
PostsShow.prototype.render = function() {
return this.view.render();
};
return PostsShow;
})(app.Controller);
Posts = (function(_super) {
__extends(Posts, _super);
function Posts(Post) {
Posts.__super__.constructor.apply(this, arguments);
Post.find();
}
Posts.prototype.render = function() {
return this.view.render();
};
return Posts;
})(app.Controller);
app.get('/', function(req, res) {
this.model = new Post;
return this.view = new Home(this.model, req, res);
});
app.get('/:id', function(req, res, id) {
this.model = new Post;
return this.view = new Show(this.model, req, res, id);
});
app.post('/post/new', function(req, res) {
var _this = this;
this.fullBody = '';
req.on('data', function(chunk) {
return _this.fullBody += chunk.toString();
});
return req.on('end', function() {
_this.data = JSON.parse(_this.fullBody);
_this.model = new Post;
_this.post = _this.model.create(_this.data);
return res.end('ok');
});
});
$('#post-save').click(function() {
_this.model = new Post;
_this.model.save();
$('#post-title').val('');
$('.modal').removeClass('active');
return $('.modal-bg').remove();
});
}).call(this);