Author: jfthomps
Date: Tue Dec 23 17:49:28 2014
New Revision: 1647627

URL: http://svn.apache.org/r1647627
Log:
VCL-174 - NAT - support for sites that have small IP address ranges

added code to dynamically manage list of computers that can be selected for use 
as a nat host in the add/edit dialog

computer.php: modified addEditDialogHTML: changed select for nathostid to 
specify 'selectonly'

utils.php: modified getComputers: added nathostenabledid to returned data

computer.js: modified saveResourceCB: add/remove computer from nathostid select 
for add/edit dialog if submitted computer has nathostenabled changed

Modified:
    vcl/trunk/web/.ht-inc/computer.php
    vcl/trunk/web/.ht-inc/utils.php
    vcl/trunk/web/js/resources/computer.js

Modified: vcl/trunk/web/.ht-inc/computer.php
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/computer.php?rev=1647627&r1=1647626&r2=1647627&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/computer.php (original)
+++ vcl/trunk/web/.ht-inc/computer.php Tue Dec 23 17:49:28 2014
@@ -694,7 +694,7 @@ class Computer extends Resource {
                $h .= labeledFormItem('natenabled', 'Connect Using NAT', 
'check', '', '', '1', '', '', $extra);
                # which NAT host
                $nathosts = getNAThosts(0, 1);
-               $h .= labeledFormItem('nathostid', 'NAT Host', 'select', 
$nathosts);
+               $h .= labeledFormItem('nathostid', 'NAT Host', 'selectonly', 
$nathosts);
                $h .= "</div>\n"; # NAT
 
                # NAT Host

Modified: vcl/trunk/web/.ht-inc/utils.php
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/utils.php?rev=1647627&r1=1647626&r2=1647627&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/utils.php (original)
+++ vcl/trunk/web/.ht-inc/utils.php Tue Dec 23 17:49:28 2014
@@ -8221,7 +8221,8 @@ function getComputers($sort=0, $included
               .        "c.predictivemoduleid, "
               .        "m.prettyname AS predictivemodule, "
               .        "nh.id AS nathostid, "
-              .        "nh2.publicIPaddress AS natpublicIPaddress, "
+              .        "nh2.id AS nathostenabledid, "
+              .        "COALESCE(nh2.publicIPaddress, '') AS 
natpublicIPaddress, "
               .        "COALESCE(nh2.internalIPaddress, '') AS 
natinternalIPaddress "
               . "FROM state st, "
               .      "platform p, "
@@ -8263,10 +8264,8 @@ function getComputers($sort=0, $included
                        $row['natenabled'] = 1;
                        $row['nathost'] = 
$nathosts[$row['nathostid']]['hostname'];
                }
-               if(is_null($row['natpublicIPaddress'])) {
+               if(is_null($row['nathostenabledid']))
                        $row['nathostenabled'] = 0;
-                       $row['natpublicIPaddress'] = '';
-               }
                else
                        $row['nathostenabled'] = 1;
                $return[$row['id']] = $row;

Modified: vcl/trunk/web/js/resources/computer.js
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/js/resources/computer.js?rev=1647627&r1=1647626&r2=1647627&view=diff
==============================================================================
--- vcl/trunk/web/js/resources/computer.js (original)
+++ vcl/trunk/web/js/resources/computer.js Tue Dec 23 17:49:28 2014
@@ -850,6 +850,8 @@ function saveResourceCB(data, ioArgs) {
                                if(typeof resourcegrid !== 'undefined') {
                                        
resourcegrid.store.newItem(data.items.data);
                                        resourcegrid.sort();
+                                       if(data.items.data.nathostenabled)
+                                               
dijit.byId('nathostid').addOption({label: data.items.data.hostname, value: 
data.items.data.nathostenabledid});
                                }
                                
dojo.forEach(dijit.findWidgets(dojo.byId('groupdlgcontent')), function(w) {
                                        w.destroyRecursive();
@@ -893,6 +895,7 @@ function saveResourceCB(data, ioArgs) {
                        resourcegrid.store.fetch({
                                query: {id: data.items.data.id},
                                onItem: function(item) {
+                                       var washost = 
resourcegrid.store.getValue(item, 'nathostenabled');
                                        resourcegrid.store.setValue(item, 
'name', data.items.data.hostname);
                                        resourcegrid.store.setValue(item, 
'owner', data.items.data.owner);
                                        resourcegrid.store.setValue(item, 
'state', data.items.data.state);
@@ -920,6 +923,18 @@ function saveResourceCB(data, ioArgs) {
                                        resourcegrid.store.setValue(item, 
'nathostenabled', data.items.data.nathostenabled);
                                        resourcegrid.store.setValue(item, 
'natpublicIPaddress', data.items.data.natpublicIPaddress);
                                        resourcegrid.store.setValue(item, 
'natinternalIPaddress', data.items.data.natinternalIPaddress);
+                                       if(data.items.data.nathostenabled) {
+                                               if(washost == 0)
+                                                       
dijit.byId('nathostid').addOption({label: data.items.data.hostname, value: 
data.items.data.nathostenabledid});
+                                       }
+                                       else {
+                                               
dijit.byId('nathostid').options.forEach(
+                                                       function(node, index, 
nodelist) {
+                                                               if(node.label 
== data.items.data.hostname)
+                                                                       
dijit.byId('nathostid').removeOption({value: node.value});
+                                                       }
+                                               );
+                                       }
                                },
                                onComplete: function(items, result) {
                                        // when call resourcegrid.sort 
directly, the table contents disappear; not sure why


Reply via email to