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.html b/app/configuration/controllers/network-controller.html
index e9b819c..1d59b37 100644
--- a/app/configuration/controllers/network-controller.html
+++ b/app/configuration/controllers/network-controller.html
@@ -40,13 +40,14 @@
 			<fieldset>
 				<div class="row column">
 					<label class="control-radio" for="dhcp-address">Obtain an IP address automatically using DHCP
-						<input type="radio" name="ip-address" id="dhcp-address" ng-checked="true" ng-model="interface.DHCPEnabled" ng-value="true">
+						<!-- TODO: openbmc/openbmc#3154 Rest server should return a proper JSON bool instead of "0" or "1"-->
+						<input type="radio" name="ip-address" id="dhcp-address" ng-checked="true" ng-model="interface.DHCPEnabled" ng-value="1">
 						<span class="control__indicator control__indicator-on"></span>
 					</label>
 				</div>
 				<div class="row column">
 					<label class="control-radio" for="static-ip-address">Assign a static IP address
-						<input type="radio" name="ip-address" id="static-ip-address" ng-model="interface.DHCPEnabled" ng-value="false"/>
+						<input type="radio" name="ip-address" id="static-ip-address" ng-model="interface.DHCPEnabled" ng-value="0"/>
 						<span class="control__indicator control__indicator-on"></span>
 					</label>
 				</div>
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