Commit 9feac3f1c0680aa0a086053b4166a0bd7e5f4474

Authored by Adhidarma Hadiwinoto
1 parent a1da8a567a
Exists in master

tambah product pair

Showing 4 changed files with 48 additions and 4 deletions Side-by-side Diff

... ... @@ -45,13 +45,21 @@ function renderConfigIndex(req, res) {
45 45 function renderConfigEdit(req, res) {
46 46 res.render('config.edit.html', {
47 47 gateway_name: config.globals.gateway_name,
48   - title: 'Edit Config',
  48 + title: 'Edit Konfigurasi',
49 49 scope: req.scope,
50 50 keyword: req.keyword,
51 51 old_value: config[req.scope][req.keyword]
52 52 });
53 53 }
54 54  
  55 +function renderConfigAdd(req, res){
  56 + res.render('config.add.html', {
  57 + gateway_name: config.globals.gateway_name,
  58 + title: 'Tambah Item Konfigurasi',
  59 + scope: req.scope
  60 + });
  61 +}
  62 +
55 63 function submitConfigEdit(req, res) {
56 64  
57 65 if (config[req.body.scope][req.body.keyword] != req.body.newValue.trim()) {
... ... @@ -62,6 +70,14 @@ function submitConfigEdit(req, res) {
62 70 res.redirect('/config');
63 71 }
64 72  
  73 +function submitConfigAdd(req, res) {
  74 +
  75 + config[req.body.scope][req.body.newKeyword] = req.body.newValue.trim();
  76 + matrix.config_dirty = 1;
  77 +
  78 + res.redirect('/config');
  79 +}
  80 +
65 81 function submitConfigDelete(req, res) {
66 82  
67 83 matrix.config_dirty = 1;
... ... @@ -70,7 +86,6 @@ function submitConfigDelete(req, res) {
70 86 res.redirect('/config');
71 87 }
72 88  
73   -
74 89 function submitConfigSave(req, res) {
75 90 fsextra.copy('config.ini', 'config.ini.backup_' + strftime('%F_%H%M%S', new Date()), function(err) {
76 91 fs.writeFileSync('./config.ini', ini.stringify(config));
... ... @@ -164,6 +179,9 @@ function createServer() {
164 179 app.get('/config/ask-delete/:scope/:keyword', loggedIn, renderConfigAskDelete);
165 180 app.get('/config/delete/:scope/:keyword', loggedIn, submitConfigDelete);
166 181  
  182 + app.get('/config/add/:scope', loggedIn, renderConfigAdd);
  183 + app.post('/config/add/:scope', loggedIn, submitConfigAdd);
  184 +
167 185 app.get('/config/save', loggedIn, submitConfigSave);
168 186  
169 187 var server = app.listen(config.expresso.listen_port, function () {
views/config.add.html
... ... @@ -0,0 +1,22 @@
  1 +{% extends "layout-with-topbar.html" %}
  2 +
  3 +{% block content %}
  4 +<form method="POST">
  5 +
  6 + <input type="hidden" name="scope" value="{{ scope }}">
  7 +
  8 + <div class="form-group">
  9 + <label for="newKeyword">Kata kunci</label>
  10 + <input name="newKeyword" type="text" class="form-control" id="newKeyword" placeholder="Kata kunci">
  11 + </div>
  12 +
  13 + <div class="form-group">
  14 + <label for="newValue">Nilai</label>
  15 + <input name="newValue" type="text" class="form-control" id="newValue" placeholder="Nilai">
  16 + </div>
  17 +
  18 +
  19 + <button type="submit" class="btn btn-primary">Tambah</button>
  20 + <a class="btn btn-default" href="/config" role="button">Batal</a>
  21 +</form>
  22 +{% endblock %}
views/config.edit.html
... ... @@ -11,7 +11,7 @@
11 11 <input name="newValue" type="text" class="form-control" id="{{ scope }}.{{ keyword }}.newValue" placeholder="New value" value="{{ old_value }}">
12 12 </div>
13 13  
14   - <button type="submit" class="btn btn-primary">Submit</button>
15   - <a class="btn btn-default" href="/config" role="button">Cancel</a>
  14 + <button type="submit" class="btn btn-primary">Simpan</button>
  15 + <a class="btn btn-default" href="/config" role="button">Batal</a>
16 16 </form>
17 17 {% endblock %}
views/config.index.html
... ... @@ -41,6 +41,10 @@
41 41  
42 42 </table>
43 43  
  44 +<a href="/config/add/products">
  45 + Tambah Pasangan Kode Produk (config.products)
  46 +</a>
  47 +
44 48 {% include "block.config.save.html" %}
45 49  
46 50 {% endblock %}