/
service.js
97 lines (88 loc) · 2.62 KB
/
service.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
/*
* action.js、batch.jsのビジネスロジックの
* 定義
*/
var {Response} = require('ringo/webapp/response');
var email = require('ringo/mail');
var config = require('./config.js');
var strings = require('ringo/utils/strings');
var simpleFormat = java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
exports.Service = {
email: "",
keyword: "",
/**
* トリミング(全角、半角のスペース削除)
*/
trim : function(key) {
return key.replace(/^\s+|\s+$/g, '');
},
/**
* カンマ(,)でreplace
*/
commaReplace: function(key) {
return key.replace(/\s+/g, ',');
},
/**
* 確認メールを入力されたメールアドレスに送信する
*/
sendMail: function(to, text) {
email.send({from: config.email.from, to: to,
subject: config.email.subject, text: text});
},
/**
* ユニークIDの作成
*/
createUniqId: function() {
return strings.digest(new Date().toString());
},
/**
* GData calendarのSummary的な値を読みやすい形に加工する
*/
modifySummary : function(content) {
var CR = "\r\n";
return content.replace(' JST ', CR)
.replace('予定のステータス: 確定', '')
.replace('予定の説明", "詳細内容') + CR;
}
};
/**
* 検索対象期間のDateTimeを取得する
*/
exports.Service.searchTerm = {
sd: simpleFormat,
start: function() {
return this.sd.format(new Date());
},
end: function() {
var duration = config.durationDays * 24 * 60 * 60 * 1000;
var now = new Date().getTime();
return this.sd.format(new Date(now + duration));
}
};
/**
* メールフォーマットの作成
*/
exports.Service.textFormat = {
confirm: function(uid) {
var sv = exports.Service;
return Response.skin(module.resolve
('skins/email/confirm.tpl'),
{ keyword: sv.commaReplace(sv.trim(sv.keyword)),
completeUrl: config.fqdn
+ "/complete?uid=" + uid}).body;
},
batch : function(uid, keyword, text) {
return Response.skin(module.resolve
('skins/email/batch.tpl'),
{ keyword: keyword,
withdrawUrl: config.fqdn
+ "/withdraw?uid=" + uid,
textBody: text}).body;
},
batchPart : function(studyTitle, plainText) {
return Response.skin(module.resolve
('skins/email/batchPart.tpl'),
{ studyTitle: studyTitle,
plainText: plainText}).body;
}
};