Showing
1 changed file
with
32 additions
and
8 deletions
... | @@ -16,6 +16,7 @@ router.get('/', function (req, res) { | ... | @@ -16,6 +16,7 @@ router.get('/', function (req, res) { |
16 | 16 | ||
17 | router.get('/products', function (req, res) { | 17 | router.get('/products', function (req, res) { |
18 | CategoriModel.find(function (err, products) { | 18 | CategoriModel.find(function (err, products) { |
19 | + console.log(products); | ||
19 | res.render( | 20 | res.render( |
20 | 'category/products', | 21 | 'category/products', |
21 | { categories: products } | 22 | { categories: products } |
... | @@ -33,7 +34,7 @@ router.post('/categories/write', loginRequired, function (req, res) { | ... | @@ -33,7 +34,7 @@ router.post('/categories/write', loginRequired, function (req, res) { |
33 | var category = new CategoriModel({ | 34 | var category = new CategoriModel({ |
34 | title: req.body.title, | 35 | title: req.body.title, |
35 | description: req.body.description, | 36 | description: req.body.description, |
36 | - username: req.user.username, | 37 | + username: req.user.displayname, |
37 | }); | 38 | }); |
38 | // | 39 | // |
39 | var validationError = category.validateSync(); | 40 | var validationError = category.validateSync(); |
... | @@ -133,14 +134,19 @@ router.get('/products/detail/:id', function (req, res) { | ... | @@ -133,14 +134,19 @@ router.get('/products/detail/:id', function (req, res) { |
133 | router.post('/products/detail/:id', loginRequired, function (req, res) { | 134 | router.post('/products/detail/:id', loginRequired, function (req, res) { |
134 | var item = []; | 135 | var item = []; |
135 | var count = 1; | 136 | var count = 1; |
136 | - for (var i in req.body.videoNum) { | 137 | + var temp = ''; |
137 | - item.push(req.body.videoNum[i].split('///')); | 138 | + console.log(req.body.videoNum.length); |
139 | + if (req.body.videoNum.length > 30) { | ||
140 | + for (var i in req.body.videoNum) { | ||
141 | + temp += req.body.videoNum[i]; | ||
142 | + } | ||
143 | + item.push(temp.split('///')); | ||
138 | var video = new VideoModel({ | 144 | var video = new VideoModel({ |
139 | - categori: item[i][2], | 145 | + categori: item[0][2], |
140 | id: count, | 146 | id: count, |
141 | - title: item[i][1], | 147 | + title: item[0][1], |
142 | - video_id: item[i][3], | 148 | + video_id: item[0][3], |
143 | - urls: item[i][4], | 149 | + urls: item[0][4], |
144 | }); | 150 | }); |
145 | var validationError = video.validateSync(); | 151 | var validationError = video.validateSync(); |
146 | if (validationError) { | 152 | if (validationError) { |
... | @@ -149,6 +155,24 @@ router.post('/products/detail/:id', loginRequired, function (req, res) { | ... | @@ -149,6 +155,24 @@ router.post('/products/detail/:id', loginRequired, function (req, res) { |
149 | video.save(function (err) {}); | 155 | video.save(function (err) {}); |
150 | } | 156 | } |
151 | count++; | 157 | count++; |
158 | + } else { | ||
159 | + for (var i in req.body.videoNum) { | ||
160 | + item.push(req.body.videoNum[i].split('///')); | ||
161 | + var video = new VideoModel({ | ||
162 | + categori: item[i][2], | ||
163 | + id: count, | ||
164 | + title: item[i][1], | ||
165 | + video_id: item[i][3], | ||
166 | + urls: item[i][4], | ||
167 | + }); | ||
168 | + var validationError = video.validateSync(); | ||
169 | + if (validationError) { | ||
170 | + res.send(validationError); | ||
171 | + } else { | ||
172 | + video.save(function (err) {}); | ||
173 | + } | ||
174 | + count++; | ||
175 | + } | ||
152 | } | 176 | } |
153 | res.redirect('/categori/products/detail/' + req.params.id); | 177 | res.redirect('/categori/products/detail/' + req.params.id); |
154 | }); | 178 | }); |
... | @@ -201,7 +225,7 @@ router.get('/products/delete/:id', function (req, res) { | ... | @@ -201,7 +225,7 @@ router.get('/products/delete/:id', function (req, res) { |
201 | router.get('/products/detail/delete/:id', function (req, res) { | 225 | router.get('/products/detail/delete/:id', function (req, res) { |
202 | VideoModel.findOne({ _id: req.params.id }, function (err, products) { | 226 | VideoModel.findOne({ _id: req.params.id }, function (err, products) { |
203 | VideoModel.deleteMany({ _id: products }, function (err) { | 227 | VideoModel.deleteMany({ _id: products }, function (err) { |
204 | - res.redirect('/categori/products/detail/'+ redirectUrls); | 228 | + res.redirect('/categori/products/detail/' + redirectUrls); |
205 | }); | 229 | }); |
206 | }); | 230 | }); |
207 | }); | 231 | }); | ... | ... |
-
Please register or login to post a comment