From fd3801089a3b46dbe00448a9c49576d14ed0481b Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Fri, 25 May 2018 13:15:05 +0200
Subject: [PATCH] Set the IOC tag by default based on device type

JIRA INFRA-302
---
 app/static/js/hosts.js | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/app/static/js/hosts.js b/app/static/js/hosts.js
index 01e17b5..9bfc6c6 100644
--- a/app/static/js/hosts.js
+++ b/app/static/js/hosts.js
@@ -12,7 +12,17 @@ $(document).ready(function() {
     );
   }
 
+  // Select the IOC tag by default depending on the device type
+  function update_default_tags(device_type) {
+    var ioc_device_types = ["PhysicalMachine", "VirtualMachine", "MicroTCA", "VME"];
+    var is_ioc_selected = $.inArray(device_type, ioc_device_types) > -1;
+    $("#tags option").filter(function() {
+      return this.text == "IOC";
+    }).prop("selected", is_ioc_selected).change();
+  }
+
   // And check / uncheck random_mac checkbox
+  // and update default tags
   function update_device_type_attributes() {
     var device_type = $("#device_type_id option:selected").text();
     if( device_type.startsWith("Virtual") ) {
@@ -20,6 +30,7 @@ $(document).ready(function() {
     } else {
       $("#random_mac").prop("checked", false).change();
     }
+    update_default_tags(device_type);
   }
 
   // If random_mac is checked, generate a random address
@@ -55,8 +66,8 @@ $(document).ready(function() {
     set_default_ip();
   });
 
-  // On register and edit host first page load
-  if( $("#hostForm").length || $("#editHostForm").length ) {
+  // On register host first page load
+  if( $("#hostForm").length ) {
     update_device_type_attributes();
   }
 
-- 
GitLab