Set DHCP on "Save settings"

Set the DHCP enabled field when the user selects "Save settings"
and accepts the popup. Added a TODO for issue #3154, Rest server
should return a proper JSON bool.

Resolves openbmc/openbmc#3165

Tested: Set "Obtain an IP address automatically using DHCP"
on a Witherspoon.
Change-Id: I45c817e3ddd8bf9c4f582460b1f9230e38548ff8
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/app/configuration/controllers/network-controller.js b/app/configuration/controllers/network-controller.js
index 5a6912f..3f7cebe 100644
--- a/app/configuration/controllers/network-controller.js
+++ b/app/configuration/controllers/network-controller.js
@@ -49,6 +49,9 @@
         if ($scope.hostname != dataService.hostname) {
           promises.push(setHostname());
         }
+        if ($scope.interface.DHCPEnabled != $scope.old_interface.DHCPEnabled) {
+          promises.push(setDHCPEnabled());
+        }
 
         // Set IPV4 IP Addresses, Netmask Prefix Lengths, and Gateways
         if (!$scope.interface.DHCPEnabled) {
@@ -106,6 +109,18 @@
                 });
       }
 
+      function setDHCPEnabled() {
+        return APIUtils
+            .setDHCPEnabled(
+                $scope.selectedInterface, $scope.interface.DHCPEnabled)
+            .then(
+                function(data) {},
+                function(error) {
+                  console.log(JSON.stringify(error));
+                  $scope.set_network_error = 'DHCP';
+                });
+      }
+
       function setIPV4(index) {
         // The correct way to edit an IPV4 interface is to remove it and then
         // add a new one