diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/js/nms-info-box.js | 42 | ||||
-rw-r--r-- | web/js/nms-ui-switch.js | 38 |
2 files changed, 38 insertions, 42 deletions
diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js index 0d18930..d364f8b 100644 --- a/web/js/nms-info-box.js +++ b/web/js/nms-info-box.js @@ -980,48 +980,6 @@ var switchEditPanel = function () { this.refresh = function (reason) { if (this.box) { return; } this.box = new nmsModSwitch(this.sw); - var save = new nmsButton("Save","btn-primary"); - save.panel = this; - save.html.onclick = function(e) { - var diff = this.nmsBox.panel.box.diff() - console.log(diff) - - if (diff != undefined) { - $.ajax({ - type: "POST", - url: "/api/write/switches", - dataType: "text", - data:JSON.stringify([diff]), - success: function (data, textStatus, jqXHR) { - var result = JSON.parse(data); - console.log("hei...") - nmsData.invalidate("switches"); - nmsData.invalidate("smanagement"); - } - }); - } - } - this.box.add(save) - var del = new nmsButton("Delete","btn btn-danger"); - del.panel = this - del.html.onclick = function(e) { - if(confirm("This will delete the switch: " + this.nmsBox.panel.sw)) { - var myData = [{'sysname': this.nmsBox.panel.sw, 'deleted': true}]; - myData = JSON.stringify(myData); - $.ajax({ - type: "POST", - url: "/api/write/switches", - dataType: "text", - data:myData, - success: function (data, textStatus, jqXHR) { - nmsInfoBox.hide(); - nmsData.invalidate("switches"); - nmsData.invalidate("smanagement"); - } - }); - }; - } - this.box.add(del) this.box.attach(this.me) this.box.show() }; diff --git a/web/js/nms-ui-switch.js b/web/js/nms-ui-switch.js index 571f215..326db1c 100644 --- a/web/js/nms-ui-switch.js +++ b/web/js/nms-ui-switch.js @@ -23,6 +23,44 @@ class nmsModSwitch extends nmsBox { //this.nav.add(new nmsString("Adding and editing stuff has immediate effects and blah blah blah, insert sensible help-text here.")); this.generateBaseTemplate() this.populate() + var save = new nmsButton("Save","btn-primary"); + save.panel = this; + save.html.onclick = this.save; + this.add(save) + var del = new nmsButton("Delete","btn btn-danger"); + del.panel = this + del.html.onclick = this.del; + this.add(del) + } + commit(data) { + $.ajax({ + type: "POST", + url: "/api/write/switches", + dataType: "text", + nmsBox:this, + data:JSON.stringify(data), + success: function (data, textStatus, jqXHR) { + var msg = new nmsString("Changed..."); + msg.attach(this.nmsBox._root); + msg.show() + this.nmsBox.destroy() + //nmsInfoBox.hide(); + nmsData.invalidate("switches"); + nmsData.invalidate("smanagement"); + } + }); + } + + del(e) { + if(confirm("This will delete the switch: " + this.nmsBox._sw)) { + this.nmsBox.panel.commit([{'sysname': this.nmsBox.panel.sw, 'deleted': true}]); + }; + } + save(e) { + var diff = this.nmsBox.panel.diff() + if (diff != undefined) { + this.nmsBox.panel.commit([diff]) + } } /* Pretty sure that the type-thing is OK, but what I want is to * generate a nmsTemplate or something that can be used to get/set |