[Patchew-devel] [PATCH 10/17] mods: do not allow creating duplicate map items

Paolo Bonzini posted 17 patches 2 years, 6 months ago

[Patchew-devel] [PATCH 10/17] mods: do not allow creating duplicate map items

Posted by Paolo Bonzini 2 years, 6 months ago
The code for that was there but more or less stubbed out, fix it.
---
 static/js/config-editor.js | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/static/js/config-editor.js b/static/js/config-editor.js
index f15211f..c0f326f 100644
--- a/static/js/config-editor.js
+++ b/static/js/config-editor.js
@@ -70,9 +70,10 @@ function properties_save(btn) {
         });
 }
 
-function collect_items(btn) {
-    $(btn).parent().parent().find(".map-item");
-    return {};
+function collect_items(container) {
+    return container.find("> .items > .item > .item-heading > .item-name").map(function() {
+        return $(this).text();
+    }).get();
 }
 
 function map_add_item(btn) {
@@ -81,8 +82,8 @@ function map_add_item(btn) {
         return;
     }
     container = $(btn).parent().parent();
-    if (name in collect_items(btn)) {
-        alert(test_name + " already exists.");
+    if (collect_items(container).includes(name)) {
+        alert(name + " already exists.");
         return;
     }
     if (name.indexOf(".") >= 0) {
-- 
2.21.0


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel