forked from fjamon/cellcube-ussd-page-builder-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
123 lines (104 loc) · 4.62 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var generateRedirectPage = function(options){
if (!options)
return this.getEmptyPage()
//Encoder l'url pour l'ussd
var urlencode = require('urlencode')
if (options.encodeUrl){
if (options.encodeUrl == true)
options.erl = urlencode.encode(options.erl)
}
else{
if (options.encodeUrl == true)
options.erl = urlencode.encode(options.erl)
}
var page = require('./templates/redirect.xml')
.replace("{descr}",options.descr? options.descr : process.pid)
.replace("{nav}",options.nav? options.nav : 'default')
.replace("{ismenu}",options.ismenu? options.ismenu : true)
.replace("{volatile}",options.descr? options.volatile : false)
.replace("{erl}",options.erl)
return page
}
var generateContentPage = function(options){
if (!options)
return this.getEmptyPage()
//Ajout des liens
var links = ""
if (options.links){
var ussdLink
for (var i = 0; i<options.links.length; i++){
if (options.links[i]){
ussdLink = "<a key = '{key}' href = '{href}'>{text}</a>"
if (options.links[i].href)
ussdLink = ussdLink.replace("{href}",options.links[i].href)
else
ussdLink = ussdLink.replace("{href}","")
if (options.links[i].text)
ussdLink = ussdLink.replace("{text}",options.links[i].text)
else
ussdLink = ussdLink.replace("{text}","")
if (!options.autoIncrementKeys){
if (options.links[i].key)
ussdLink = ussdLink.replace("{key}",options.links[i].key)
else
ussdLink = ussdLink.replace("{key}",i+1)
}
else{
ussdLink = ussdLink.replace("{key}",i+1)
}
links += ussdLink + "<br/>"
}
}
}
var page = require('./templates/page.xml')
.replace("{descr}",options.descr? options.descr : process.pid)
.replace("{nav}",options.nav? options.nav : 'default')
.replace("{volatile}",options.volatile? options.volatile : false)
.replace("{ismenu}",options.ismenu? options.ismenu : true)
.replace("{content}",options.content? options.content + "<br/>" : "")
.replace("{links}",links)
return page
}
var generateForm = function(options){
//console.log("jjj")
if (!options)
return this.getEmptyPage()
if (options.req){
options.action = options.action? options.action.split('?')[0] : ""
var i = 0
for(var param in options.req.query){
if (i == 0){
if (options.action.indexOf(options.req.query[param]) == -1)
options.action += "?" + param + "=" + options.req.query[param]
}
else{
if (options.action.indexOf(options.req.query[param]) == -1)
options.action += "&" + param + "=" + options.req.query[param]
}
i++
}
}
var page = require('./templates/form.xml')
.replace("{descr}", options.descr? options.descr : process.pid )
.replace("{nav}",options.nav? options.nav : 'default')
.replace("{volatile}",options.volatile? options.volatile : false)
.replace("{ismenu}",options.ismenu? options.ismenu : false)
.replace("{action}", options.action? options.action : "")
.replace("{var}", options.var? options.var : "")
.replace("{kind}",options.kind? options.kind : "alphanum")
.replace("{prompt}",options.prompt? options.prompt + "<br/>" : "")
return page
}
var generateEmptyPage = function(options){
return require('./templates/page.xml')
.replace("{descr}", options.descr? options.descr : process.pid)
.replace("{nav}", options.nav? options.nav : 'default')
.replace("{volatile}",false)
.replace("{ismenu}",true)
.replace("{content}","")
.replace("{links}","")
}
module.exports.generateRedirectPage = generateRedirectPage
module.exports.generateContentPage = generateContentPage
module.exports.generateForm = generateForm
module.exports.generateEmptyPage = generateEmptyPage