-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
154 lines (134 loc) · 3.87 KB
/
Copy pathindex.js
File metadata and controls
154 lines (134 loc) · 3.87 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
'use strict';
var Pagelet = require('pagelet')
, async = require('async')
, path = require('path');
Pagelet.extend({
view: 'view.ejs',
css: 'css.styl',
js: 'client.js',
//
// Allow FORM submits to be streaming.
//
streaming: true,
//
// Force a name.
//
name: 'service-select',
//
// What data needs to be synced with the front-end.
//
query: ['services'],
pagelets: {
target: Pagelet.extend({
view: 'target.ejs',
streaming: true
}).on(module)
},
//
// External dependencies that should be included on the page using a regular
// script tag. This dependency is needed for the `package.js` client file.
//
dependencies: [
path.join(__dirname, '/selectize.default.css'),
'//code.jquery.com/jquery-2.1.0.min.js',
path.join(__dirname, '/selectize.js')
],
/**
* Respond to POST requests.
*
* @param {Object} fields The input fields.
* @param {Object} files Optional uploaded files.
* @param {Function} next Completion callback.
* @api public
*/
post: function post(fields, files, next) {
if ('delete' in fields) {
this.remove(fields, next);
} else if ('add' in fields) {
this.add(fields, next);
} else {
next(new Error('Invalid form data'));
}
},
/**
* Called when a new service has to be added.
*
* @param {Object} data The data to add.
* @param {FUnction} next Continuation function.
* @api public
*/
add: function add(data, next) {
throw new Error([
'You, as a developer need to implement the `.add` method of the service',
'select pagelet. If you dont know how to do this, see the documenation',
'about Pagelet.extend({});'
].join(' '));
},
/**
* A service has been removed from the UI.
*
* @param {Object} data The data containing the info about the service
*/
remove: function remove(data, next) {
throw new Error([
'You, as a developer need to implement the `.remove` method of the service',
'select pagelet. If you dont know how to do this, see the documenation',
'about Pagelet.extend({});'
].join(' '));
},
/**
* The available services that should be listed in the UI.
*
* @param {Function} next Continuation callback
* @api public
*/
services: function services(next) {
throw new Error([
'You, as a developer need to implement the `.services` method of the service',
'select pagelet. If you dont know how to do this, see the documenation',
'about Pagelet.extend({});'
].join(' '));
},
/**
* List of added services that should be displayed in the UI.
*
* @param {Fucntion} next Continuation callback.
* @api public
*/
added: function added(next) {
throw new Error([
'You, as a developer need to implement the `.added` method of the service',
'select pagelet. If you dont know how to do this, see the documenation',
'about Pagelet.extend({});'
].join(' '));
},
/**
* Render the HTML things.
*
* @param {Function} done Continuation callback.
* @api public
*/
get: function get(done) {
var pagelet = this;
async.parallel({
services: this.services.bind(this),
added: this.added.bind(this)
}, function completed(err, data) {
if (err) return done(err);
data.services = data.services || [];
data.added = data.added || [];
['services', 'added'].forEach(function transform(key) {
if (Array.isArray(data[key])) return;
data[key] = Object.keys(data[key]).map(function map(name) {
var thing = data[key][name];
thing.name = thing.name || name;
return thing;
});
});
data.description = pagelet.description;
data.name = pagelet.name.replace('-', ' ');
data.name = data.name.slice(0, 1).toUpperCase() + data.name.slice(1);
done(err, data);
});
}
}).on(module);