-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
102 lines (90 loc) · 2.69 KB
/
index.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
// Generated by CoffeeScript 1.8.0
var Model, racer,
__hasProp = {}.hasOwnProperty;
racer = require('racer');
Model = racer.Model;
module.exports = function(app, options) {
var Flash;
if (options == null) {
options = {};
}
return Flash = (function() {
var middleware, originalRouter;
function Flash() {}
Flash.prototype.view = __dirname;
app.on('render', function(app) {
var data, flashq, model, obj, type, _i, _len;
model = app.model;
flashq = model.get('_flash.flashq') || {};
if (flashq) {
for (type in flashq) {
data = flashq[type];
if (data instanceof Array) {
for (_i = 0, _len = data.length; _i < _len; _i++) {
obj = data[_i];
if (typeof obj.msg === 'string' && model.toast && (options.useToast || obj.toast)) {
model.toast(type, obj.msg);
} else {
model.root.push("_page.flash." + type, obj.msg);
}
}
} else {
model.root.set("_page.flash." + type, data);
}
}
}
return model.del('_flash.flashq');
});
Model.prototype.flash = function(type, msg, useToast) {
var key, t, val, _ref, _ref1, _ref2;
if (typeof type === 'object') {
useToast = msg;
for (key in type) {
if (!__hasProp.call(type, key)) continue;
val = type[key];
t = key;
msg = val;
}
type = t;
}
if (type && msg) {
if ((_ref = this.data) != null ? (_ref1 = _ref.$controller) != null ? (_ref2 = _ref1.req) != null ? _ref2.flash : void 0 : void 0 : void 0) {
return this.data.$controller.req.flash(type, msg);
} else {
return this.root.push("_flash.flashq." + type, {
msg: msg,
toast: useToast
});
}
}
};
originalRouter = app.router;
middleware = function(req, res, next) {
var model, msg, msgs, obj, type, _i, _len, _ref;
if (req.flash) {
model = req.getModel();
msgs = req.flash();
for (type in msgs) {
_ref = msgs[type];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
msg = _ref[_i];
if (typeof msg === 'string') {
model.push("_flash.flashq." + type, {
msg: msg
});
} else {
for (obj in msg) {
model.set("_flash.flashq." + type + "." + obj, msg[obj]);
}
}
}
}
}
return (originalRouter())(req, res, next);
};
app.router = function() {
return middleware;
};
return Flash;
})();
};