/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
//PAGE Devices
one.f = {};
// specify dashlets and layouts
one.f.dashlet = {
nodesLearnt : {
id : 'nodesLearnt',
name : 'Nodes Learned'
},
staticRouteConfig : {
id : 'staticRouteConfig',
name : 'Static Route Configuration'
},
subnetGatewayConfig : {
id : 'subnetGatewayConfig',
name : 'Subnet Gateway Configuration'
},
spanPortConfig : {
id : 'spanPortConfig',
name : 'SPAN Port Configuration'
}
};
one.f.menu = {
left : {
top : [
one.f.dashlet.nodesLearnt
],
bottom : [
one.f.dashlet.staticRouteConfig
]
},
right : {
top : [],
bottom : [
one.f.dashlet.subnetGatewayConfig,
one.f.dashlet.spanPortConfig
]
}
};
/**Devices Modules */
one.f.switchmanager = {
rootUrl: "controller/web/devices",
createTable: function(columnNames, body) {
var tableAttributes = ["table-striped", "table-bordered", "table-condensed"];
var $table = one.lib.dashlet.table.table(tableAttributes);
var tableHeaders = columnNames;
var $thead = one.lib.dashlet.table.header(tableHeaders);
var $tbody = one.lib.dashlet.table.body(body, tableHeaders);
$table.append($thead)
.append($tbody);
return $table;
},
validateName: function(name) {
return (name.length < 256);
}
};
one.f.switchmanager.nodesLearnt = {
id: {
dashlet: {
popout: "one_f_switchmanager_nodesLearnt_id_dashlet_popout",
datagrid: "one_f_switchmanager_nodesLearnt_id_dashlet_datagrid"
},
modal: {
modal: "one_f_switchmanager_nodesLearnt_id_modal_modal",
configure: "one_f_switchmanager_nodesLearnt_id_modal_configure",
ports: "one_f_switchmanager_nodesLearnt_id_modal_ports",
save: "one_f_switchmanager_nodesLearnt_id_modal_save",
datagrid: "one_f_switchmanager_nodesLearnt_id_modal_datagrid",
portsDatagrid: "one_f_switchmanager_nodesLearnt_id_modal_portsDatagrid",
form: {
nodeId: "one_f_switchmanager_nodesLearnt_id_modal_form_nodeid",
nodeName : "one_f_switchmanager_nodesLearnt_id_modal_form_nodename",
portStatus : "one_f_switchmanager_nodesLearnt_id_modal_form_portstatus",
tier: "one_f_switchmanager_nodesLearnt_id_modal_form_tier",
operationMode: "one_f_switchmanager_nodesLearnt_id_modal_form_opmode"
}
}
},
dashlet: function($dashlet) {
var url = one.f.switchmanager.rootUrl + "/nodesLearnt";
one.lib.dashlet.empty($dashlet);
$dashlet.append(one.lib.dashlet.header(one.f.dashlet.nodesLearnt.name));
one.f.switchmanager.nodesLearnt.ajax.main(url, function(content) {
var $gridHTML = one.lib.dashlet.datagrid.init(one.f.switchmanager.nodesLearnt.id.dashlet.datagrid, {
searchable: true,
filterable: false,
pagination: true,
flexibleRowsPerPage: true
}, "table-striped table-condensed");
$dashlet.append($gridHTML);
var dataSource = one.f.switchmanager.nodesLearnt.data.gridDataSource.abridged(content);
$("#" + one.f.switchmanager.nodesLearnt.id.dashlet.datagrid).datagrid({dataSource: dataSource}).on("loaded", function() {
$(this).find("tbody a").click(one.f.switchmanager.nodesLearnt.modal.initialize.updateNode);
});
$("#" + one.f.switchmanager.nodesLearnt.id.dashlet.datagrid).datagrid({dataSource: dataSource}).on("loaded", function() {
$(this).find("tbody span").click(function(){
one.f.switchmanager.nodesLearnt.modal.initialize.displayPorts($(this));
});
});
});
},
ajax : {
main : function(url, callback) {
$.getJSON(url, function(data) {
callback(data);
});
}
},
modal : {
initialize: {
updateNode: function(evt) {
one.f.switchmanager.nodesLearnt.ajax.main(one.f.switchmanager.rootUrl + "/tiers", function(tiers) {
var nodeId = decodeURIComponent(evt.target.id);
var h3;
var footer = [];
var $body = one.f.switchmanager.nodesLearnt.modal.body.updateNode(nodeId, JSON.parse(decodeURIComponent(evt.target.getAttribute("switchDetails"))), tiers);
if (evt.target.getAttribute("privilege") == 'WRITE'){
h3 = "Update Node Information";
footer = one.f.switchmanager.nodesLearnt.modal.footer.updateNode();
} else { //disable node edit
$body.find('*').attr('disabled', 'disabled');
h3 = 'Node Information';
}
var $modal = one.lib.modal.spawn(one.f.switchmanager.nodesLearnt.id.modal.configure, h3, "", footer);
// bind save button
$('#' + one.f.switchmanager.nodesLearnt.id.modal.save, $modal).click(function() {
one.f.switchmanager.nodesLearnt.modal.save($modal);
});
// inject body (nodePorts)
one.lib.modal.inject.body($modal, $body);
$modal.modal();
});
},
popout: function() {
var h3 = "Nodes Learned";
var footer = one.f.switchmanager.nodesLearnt.modal.footer.popout();
var $modal = one.lib.modal.spawn(one.f.switchmanager.nodesLearnt.id.modal.modal, h3, "", footer);
var $body = one.f.switchmanager.nodesLearnt.modal.body.popout($modal);
return $modal;
},
displayPorts: function(ports) {
var content = JSON.parse(decodeURIComponent(ports.attr("ports")));
var h3 = ((ports.attr("nodeName") == "None")? ports.attr("nodeId") : ports.attr("nodeName"))
var footer = [];
var $modal = one.lib.modal.spawn(one.f.switchmanager.nodesLearnt.id.modal.ports, h3, "", footer);
var $gridHTML = one.lib.dashlet.datagrid.init(one.f.switchmanager.nodesLearnt.id.modal.portsDatagrid, {
searchable: true,
filterable: false,
pagination: true,
flexibleRowsPerPage: true,
popout: true
}, "table-striped table-condensed");
one.lib.modal.inject.body($modal, $gridHTML);
$modal.on("shown", function() {
var dataSource = one.f.switchmanager.nodesLearnt.data.gridDataSource.displayPorts(content);
$("#" + one.f.switchmanager.nodesLearnt.id.modal.portsDatagrid).datagrid({
dataSource: dataSource,
stretchHeight: false
});
});
$modal.modal();
}
},
body: {
updateNode: function(nodeId, switchDetails, tiers) {
var $form = $(document.createElement('form'));
var $fieldset = $(document.createElement('fieldset'));
// node ID. not editable.
var $label = one.lib.form.label("Node ID");
var $input = one.lib.form.input("node id");
$input.attr('id', one.f.switchmanager.nodesLearnt.id.modal.form.nodeId);
$input.attr("disabled", true);
$input.attr("value", nodeId);
$fieldset.append($label).append($input);
// node name
var $label = one.lib.form.label("Node Name");
var $input = one.lib.form.input("Node Name");
$input.attr('id', one.f.switchmanager.nodesLearnt.id.modal.form.nodeName);
if(switchDetails["nodeName"] != null) {
$input.attr('value', switchDetails["nodeName"]);
}
$fieldset.append($label).append($input);
// node tier
var $label = one.lib.form.label("Tier");
var $select = one.lib.form.select.create(tiers);
$select.attr('id', one.f.switchmanager.nodesLearnt.id.modal.form.tier);
$select.val(switchDetails["tier"]);
$fieldset.append($label).append($select);
// operation mode
var $label = one.lib.form.label("Operation Mode");
var $select = one.lib.form.select.create(
["Allow reactive forwarding", "Proactive forwarding only"]);
$select.attr('id', one.f.switchmanager.nodesLearnt.id.modal.form.operationMode);
if ((one.main.registry != undefined) && (one.main.registry.container != 'default')) {
$select.attr("disabled", true);
}
$select.val(switchDetails["mode"]);
$fieldset.append($label).append($select);
$form.append($fieldset);
return $form;
},
popout: function($modal) {
var $gridHTML = one.lib.dashlet.datagrid.init(one.f.switchmanager.nodesLearnt.id.modal.datagrid, {
searchable: true,
filterable: false,
pagination: true,
flexibleRowsPerPage: true,
popout: true
}, "table-striped table-condensed");
one.lib.modal.inject.body($modal, $gridHTML);
// attach to shown event of modal
$modal.on("shown", function() {
var url = one.f.switchmanager.rootUrl + "/nodesLearnt";
one.f.switchmanager.nodesLearnt.ajax.main(url, function(content) {
var dataSource = one.f.switchmanager.nodesLearnt.data.gridDataSource.popout(content);
$("#" + one.f.switchmanager.nodesLearnt.id.modal.datagrid).datagrid({
dataSource: dataSource,
stretchHeight: false
})
.on("loaded", function() {
$("#" + one.f.switchmanager.nodesLearnt.id.modal.datagrid).find("tbody span").click(function(){
one.f.switchmanager.nodesLearnt.modal.initialize.displayPorts($(this));
});
});
});
});
}
},
save: function($modal) {
var result = {};
result['nodeName'] = $('#' + one.f.switchmanager.nodesLearnt.id.modal.form.nodeName, $modal).val();
if(!one.f.switchmanager.validateName(result['nodeName'])) {
alert("Node name can contain upto 255 characters");
return;
}
result['nodeId'] = $('#' + one.f.switchmanager.nodesLearnt.id.modal.form.nodeId, $modal).val();
result['tier'] = $('#' + one.f.switchmanager.nodesLearnt.id.modal.form.tier, $modal).val();
result['operationMode'] = $('#' + one.f.switchmanager.nodesLearnt.id.modal.form.operationMode, $modal).val();
one.f.switchmanager.nodesLearnt.modal.ajax(result,
function(response) {
if(response.status == true) {
$modal.modal('hide');
one.topology.update(); // refresh visual topology with new name
// TODO: Identify dashlet by inserting a nodesLearnt div
// in the dashlet() instead
one.f.switchmanager.nodesLearnt.dashlet($("#left-top .dashlet"));
} else {
alert(response.message);
}
});
},
ajax: function(requestData, callback) {
$.getJSON(one.f.switchmanager.rootUrl + "/nodesLearnt/update", requestData, function(response) {
callback(response);
});
},
footer: {
updateNode: function() {
var footer = [];
var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.nodesLearnt.id.modal.save, "btn-primary", "");
var $saveButton = one.lib.dashlet.button.button(saveButton);
footer.push($saveButton);
return footer;
},
popout: function() {
// TODO: Maybe put a close button in the footer?
return [];
}
}
},
// data functions
data : {
gridDataSource: {
abridged: function(data) {
var source = new StaticDataSource({
columns: [
{
property: 'nodeName',
label: 'Node Name',
sortable: true
},
{
property: 'nodeId',
label: 'Node ID',
sortable: true
},
{
property: 'ports',
label: 'Ports',
sortable: true
}
],
data: data.nodeData,
formatter: function(items) {
$.each(items, function (index, item) {
var nodeName = item.nodeName;
var nodeNameEntry = item.nodeName ? item.nodeName : "Click to update";
item.nodeName = '' + nodeNameEntry + '';
var ports = item.ports;
var portsMatch = ports.match(/<\/span>/g);
var portsLength = 0;
if (portsMatch != null) {
portsLength = portsMatch.length;
}
item.ports = '' + portsLength +'';
});
},
delay: 0
});
return source;
},
popout: function(data) {
var source = new StaticDataSource({
columns: [
{
property: 'nodeName',
label: 'Node Name',
sortable: true
},
{
property: 'nodeId',
label: 'Node ID',
sortable: true
},
{
property: 'tierName',
label: 'Tier Name',
sortable: true
},
{
property: 'mac',
label: 'MAC Address',
sortable: true
},
{
property: 'ports',
label: 'Ports',
sortable: true
}
],
data: data.nodeData,
formatter: function(items) {
$.each(items, function (index, item) {
var ports = item.ports;
var portsMatch = ports.match(/<\/span>/g);
var portsLength = 0;
if (portsMatch != null) {
portsLength = portsMatch.length;
}
item.ports = '' + portsLength +'';
});
},
delay: 0
});
return source;
},
displayPorts: function(content){
var data=[];
var start=0;;
var finish=content.indexOf("
",start);
while(finish != -1){
data.push({"ports":content.substring(start,finish)});
start=finish+4
finish=content.indexOf("
",start);
}
var source = new StaticDataSource({
columns: [
{
property: 'ports',
label: 'Ports',
sortable: true
}
],
data:data,
delay: 0
});
return source;
}
},
abridged : function(data) {
var result = [];
$.each(data.nodeData, function(key, value) {
var tr = {};
var entry = [];
var nodeNameEntry = value["nodeName"] ? value["nodeName"] : "Click to update";
// TODO: Move anchor tag creation to one.lib.form.
var aTag;
aTag = document.createElement("a");
aTag.privilege = data.privilege;
aTag.addEventListener("click", one.f.switchmanager.nodesLearnt.modal.initialize.updateNode);
aTag.addEventListener("mouseover", function(evt) {
evt.target.style.cursor = "pointer";
}, false);
aTag.setAttribute("id", encodeURIComponent(value["nodeId"]));
aTag.switchDetails = value;
aTag.innerHTML = nodeNameEntry;
entry.push(aTag);
entry.push(value["nodeId"]);
entry.push(value["ports"]);
tr.entry = entry;
result.push(tr);
});
return result;
},
popout : function(data) {
var result = [];
$.each(data.nodeData, function(key, value) {
var tr = {};
// fill up all the td's
var entry = [];
var nodenameentry = value["nodeName"] ? value["nodeName"] : "No name provided";
entry.push(nodenameentry);
entry.push(value["nodeId"]);
entry.push(value["tierName"]);
entry.push(value["mac"]);
entry.push(value["ports"]);
tr.entry = entry;
result.push(tr);
});
return result;
}
}
};
one.f.switchmanager.subnetGatewayConfig = {
id: {
dashlet: {
addIPAddress: "one_f_switchmanager_subnetGatewayConfig_id_dashlet_addIP",
addPorts: "one_f_switchmanager_subnetGatewayConfig_id_dashlet_addPorts",
removeIPAddress: "one_f_switchmanager_subnetGatewayConfig_id_dashlet_removeIP",
datagrid: "one_f_switchmanager_subnetGatewayConfig_id_dashlet_datagrid",
selectAll: "one_f_switchmanager_subnetGatewayConfig_id_dashlet_selectAll"
},
modal: {
modal: "one_f_switchmanager_subnetGatewayConfig_id_modal_modal",
ports : "one_f_switchmanager_subnetGatewayConfig_id_modal_ports",
save: "one_f_switchmanager_subnetGatewayConfig_id_modal_save",
remove: "one_f_switchmanager_subnetGatewayConfig_id_modal_remove",
cancel: "one_f_switchmanager_subnetGatewayConfig_id_modal_cancel",
form: {
name : "one_f_switchmanager_subnetGatewayConfig_id_modal_form_gatewayname",
gatewayIPAddress : "one_f_switchmanager_subnetGatewayConfig_id_modal_form_gatewayipaddress",
nodeId: "one_f_switchmanager_subnetGatewayConfig_id_modal_form_nodeid",
ports: "one_f_switchmanager_subnetGatewayConfig_id_modal_form_ports"
}
}
},
// device ajax calls
dashlet: function($dashlet) {
one.lib.dashlet.empty($dashlet);
$dashlet.append(one.lib.dashlet.header(one.f.dashlet.subnetGatewayConfig.name));
// Add gateway IP Address button
var url = one.f.switchmanager.rootUrl + "/subnets";
one.f.switchmanager.subnetGatewayConfig.ajax.main(url, {}, function(content) {
if (content.privilege === 'WRITE') {
var button = one.lib.dashlet.button.single("Add Gateway IP Address",
one.f.switchmanager.subnetGatewayConfig.id.dashlet.addIPAddress, "btn-primary", "btn-mini");
var $button = one.lib.dashlet.button.button(button);
$button.click(function() {
var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.gateway();
$modal.modal();
});
$dashlet.append($button);
// Delete gateway ip address button
var button = one.lib.dashlet.button.single("Remove Gateway IP Address",
one.f.switchmanager.subnetGatewayConfig.id.dashlet.removeIPAddress, "btn-danger", "btn-mini");
var $button = one.lib.dashlet.button.button(button);
$button.click(function() {
var gatewaysToDelete = [];
var checkedCheckBoxes = $("#" + one.f.switchmanager.subnetGatewayConfig.id.dashlet.datagrid).find("tbody input:checked")
checkedCheckBoxes.each(function(index, value) {
gatewaysToDelete.push(checkedCheckBoxes[index].id);
});
if (checkedCheckBoxes.size() === 0) {
return false;
}
one.f.switchmanager.subnetGatewayConfig.modal.removeMultiple.dialog(gatewaysToDelete)
});
$dashlet.append($button);
// Add Ports button
var button = one.lib.dashlet.button.single("Add Ports",
one.f.switchmanager.subnetGatewayConfig.id.dashlet.addPorts, "btn-primary", "btn-mini");
var $button = one.lib.dashlet.button.button(button);
$button.click(function() {
if (one.f.switchmanager.subnetGatewayConfig.registry.gateways.length === 0) {
alert('No Gateways Exist');
return false;
}
var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.ports();
$modal.modal();
});
$dashlet.append($button);
}
var $gridHTML = one.lib.dashlet.datagrid.init(one.f.switchmanager.subnetGatewayConfig.id.dashlet.datagrid, {
searchable: true,
filterable: false,
pagination: true,
flexibleRowsPerPage: true
}, "table-striped table-condensed");
$dashlet.append($gridHTML);
var dataSource = one.f.switchmanager.subnetGatewayConfig.data.devicesgrid(content);
$("#" + one.f.switchmanager.subnetGatewayConfig.id.dashlet.datagrid).datagrid({dataSource: dataSource})
.on("loaded", function() {
$("#"+one.f.switchmanager.subnetGatewayConfig.id.dashlet.selectAll).click(function() {
$("#" + one.f.switchmanager.subnetGatewayConfig.id.dashlet.datagrid).find(':checkbox').prop('checked',
$("#"+one.f.switchmanager.subnetGatewayConfig.id.dashlet.selectAll).is(':checked'));
});
$(".subnetGatewayConfig").click(function(e){
if (!$('.subnetGatewayConfig[type=checkbox]:not(:checked)').length) {
$("#"+one.f.switchmanager.subnetGatewayConfig.id.dashlet.selectAll)
.prop("checked",
true);
} else {
$("#"+one.f.switchmanager.subnetGatewayConfig.id.dashlet.selectAll)
.prop("checked",
false);
}
e.stopPropagation();
});
});
});
},
ajax : {
main : function(url, requestData, callback) {
$.getJSON(url, requestData, function(data) {
callback(data);
});
}
},
registry: {},
modal : {
initialize: {
gateway: function() {
var h3 = "Add Gateway IP Address";
var footer = one.f.switchmanager.subnetGatewayConfig.modal.footer();
var $modal = one.lib.modal.spawn(one.f.switchmanager.subnetGatewayConfig.id.modal.modal, h3, "", footer);
// bind save button
$('#' + one.f.switchmanager.subnetGatewayConfig.id.modal.save, $modal).click(function() {
one.f.switchmanager.subnetGatewayConfig.modal.save.gateway($modal);
});
var $body = one.f.switchmanager.subnetGatewayConfig.modal.body.gateway();
one.lib.modal.inject.body($modal, $body);
return $modal;
},
ports: function() {
var h3 = "Add Ports";
var footer = one.f.switchmanager.subnetGatewayConfig.modal.footer();
var $modal = one.lib.modal.spawn(one.f.switchmanager.subnetGatewayConfig.id.modal.ports, h3, "", footer);
// bind save button
$('#' + one.f.switchmanager.subnetGatewayConfig.id.modal.save, $modal).click(function() {
one.f.switchmanager.subnetGatewayConfig.modal.save.ports($modal);
});
// TODO: Change to subnetGateway instead.
one.f.switchmanager.spanPortConfig.modal.ajax.nodes(function(nodes, nodeports) {
var $body = one.f.switchmanager.subnetGatewayConfig.modal.body.ports(nodes, nodeports);
one.lib.modal.inject.body($modal, $body);
});
return $modal;
}
},
save: {
gateway: function($modal) {
var result = {};
result['gatewayName'] = $('#' + one.f.switchmanager.subnetGatewayConfig.id.modal.form.name, $modal).val();
if(!one.f.switchmanager.validateName(result['gatewayName'])) {
alert("Gateway name can contain upto 255 characters");
return;
}
result['gatewayIPAddress'] = $('#' + one.f.switchmanager.subnetGatewayConfig.id.modal.form.gatewayIPAddress, $modal).val();
one.f.switchmanager.subnetGatewayConfig.modal.ajax.gateway(result,
function(response) {
if(response.status == true) {
$modal.modal('hide');
one.f.switchmanager.subnetGatewayConfig.dashlet($("#right-bottom .dashlet"));
} else {
alert(response.message);
}
});
},
ports: function($modal) {
var result = {};
var gatewayRegistryIndex = $('#' + one.f.switchmanager.subnetGatewayConfig.id.modal.form.name, $modal).val();
result['portsName'] = one.f.switchmanager.subnetGatewayConfig.registry.gateways[gatewayRegistryIndex];
result['nodeId'] = $('#' + one.f.switchmanager.subnetGatewayConfig.id.modal.form.nodeId, $modal).val();
result['ports'] = $('#' + one.f.switchmanager.subnetGatewayConfig.id.modal.form.ports, $modal).val();
if(!result['portsName'] || result['portsName'] == "") {
alert("No gateway chosen. Cannot add port");
return;
}
if(!result['nodeId'] || result['nodeId'] == "") {
alert("Please select a node.");
return;
}
if(!result['ports'] || result['ports'] == "") {
alert("Please choose a port.");
return;
}
one.f.switchmanager.subnetGatewayConfig.modal.ajax.ports(result,
function(response) {
if(response.status == true) {
$modal.modal('hide');
one.f.switchmanager.subnetGatewayConfig.dashlet($("#right-bottom .dashlet"));
} else {
alert(response.message);
}
});
}
},
body: {
gateway: function() {
var $form = $(document.createElement('form'));
var $fieldset = $(document.createElement('fieldset'));
// gateway name
var $label = one.lib.form.label("Name");
var $input = one.lib.form.input("Name");
$input.attr('id', one.f.switchmanager.subnetGatewayConfig.id.modal.form.name);
$fieldset.append($label).append($input);
// gateway IP Mask
var $label = one.lib.form.label("Gateway IP Address/Mask");
var $input = one.lib.form.input("Gateway IP Address/Mask");
var $help = one.lib.form.help('Example: 192.168.10.254/16');
$input.attr('id', one.f.switchmanager.subnetGatewayConfig.id.modal.form.gatewayIPAddress);
$fieldset.append($label).append($input).append($help);
$form.append($fieldset);
return $form;
},
ports: function(nodes, nodeports) {
var $form = $(document.createElement('form'));
var $fieldset = $(document.createElement('fieldset'));
// gateways drop down
var $label = one.lib.form.label("Gateway Name");
var $select = one.lib.form.select.create(one.f.switchmanager.subnetGatewayConfig.registry.gateways);
$select.attr('id', one.f.switchmanager.subnetGatewayConfig.id.modal.form.name);
one.lib.form.select.prepend($select, { '' : 'Please Select a Gateway' });
$select.val($select.find("option:first").val());
$fieldset.append($label).append($select);
// node ID
var $label = one.lib.form.label("Node ID");
var $select = one.lib.form.select.create(nodes);
$select.attr('id', one.f.switchmanager.subnetGatewayConfig.id.modal.form.nodeId);
one.lib.form.select.prepend($select, { '' : 'Please Select a Node' });
$select.val($select.find("option:first").val());
$fieldset.append($label).append($select);
// bind onchange
$select.change(function() {
// retrieve port value
var node = $(this).find('option:selected').attr('value');
one.f.switchmanager.subnetGatewayConfig.registry['currentNode'] = node;
var $ports = $('#' + one.f.switchmanager.subnetGatewayConfig.id.modal.form.ports);
var ports = nodeports[node];
var options = {};
$(ports).each(function(idx, val) {
options[val.internalPortName] = val.portName+' ('+val.portId+')';
});
one.lib.form.select.inject($ports, options);
one.lib.form.select.prepend($ports, { '' : 'Please Select a Port' });
$ports.val($ports.find("option:first").val());
});
// ports
var $label = one.lib.form.label("Select Port");
var $select = one.lib.form.select.create();
one.lib.form.select.prepend($select, { '' : 'Please Select a Port' });
$select.attr('id', one.f.switchmanager.subnetGatewayConfig.id.modal.form.ports);
$fieldset.append($label).append($select);
$form.append($fieldset);
return $form;
}
},
ajax: {
gateway: function(requestData, callback) {
$.getJSON(one.f.switchmanager.rootUrl + "/subnetGateway/add", requestData, function(data) {
callback(data);
});
},
ports: function(requestData, callback) {
$.getJSON(one.f.switchmanager.rootUrl + "/subnetGateway/ports/add", requestData, function(data) {
callback(data);
});
}
},
footer : function() {
var footer = [];
var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.subnetGatewayConfig.id.modal.save, "btn-primary", "");
var $saveButton = one.lib.dashlet.button.button(saveButton);
footer.push($saveButton);
return footer;
},
removeMultiple: {
dialog: function(gatewaysToDelete) {
var h3 = 'Remove Gateway IP Address';
var footer = one.f.switchmanager.subnetGatewayConfig.modal.removeMultiple.footer();
var $body = one.f.switchmanager.subnetGatewayConfig.modal.removeMultiple.body(gatewaysToDelete);
var $modal = one.lib.modal.spawn(one.f.switchmanager.subnetGatewayConfig.id.modal.modal, h3, $body, footer);
// bind close button
$('#'+one.f.switchmanager.subnetGatewayConfig.id.modal.cancel, $modal).click(function() {
$modal.modal('hide');
});
// bind remove rule button
$('#'+one.f.switchmanager.subnetGatewayConfig.id.modal.remove, $modal).click(this, function(e) {
var requestData = {};
if (gatewaysToDelete.length > 0) {
requestData["gatewaysToDelete"] = gatewaysToDelete.toString();
var url = one.f.switchmanager.rootUrl + "/subnetGateway/delete";
one.f.switchmanager.subnetGatewayConfig.ajax.main(url, requestData, function(response) {
$modal.modal('hide');
if (response.status == true) {
// refresh dashlet by passing dashlet div as param
one.lib.alert("Gateway IP Address(es) successfully removed");
} else {
alert(response.message);
}
one.f.switchmanager.subnetGatewayConfig.dashlet($("#right-bottom .dashlet"));
});
}
});
$modal.modal();
},
footer : function() {
var footer = [];
var remove = one.lib.dashlet.button.single('Remove Gateway IP Address',one.f.switchmanager.subnetGatewayConfig.id.modal.remove, 'btn-danger', '');
var $remove = one.lib.dashlet.button.button(remove);
footer.push($remove);
var cancel = one.lib.dashlet.button.single('Cancel', one.f.switchmanager.subnetGatewayConfig.id.modal.cancel, '', '');
var $cancel = one.lib.dashlet.button.button(cancel);
footer.push($cancel);
return footer;
},
body : function (gatewayList) {
var $p = $(document.createElement('p'));
var p = 'Remove the following Gateway IP Address(es)?';
//creata a BS label for each rule and append to list
$(gatewayList).each(function(){
var $span = $(document.createElement('span'));
$span.append(this);
p += '
' + $span[0].outerHTML;
});
$p.append(p);
return $p;
}
}
},
// data functions
data : {
devicesgrid: function(data) {
one.f.switchmanager.subnetGatewayConfig.registry.gateways = [];
var source = new StaticDataSource({
columns: [
{
property: 'selector',
label: "",
sortable: false
},
{
property: 'name',
label: 'Name',
sortable: true
},
{
property: 'subnet',
label: 'Gateway IP Address/Mask',
sortable: true
},
{
property: 'nodePorts',
label: 'Ports',
sortable: false
}
],
data: data.nodeData,
formatter: function(items) {
$.each(items, function(index, tableRow) {
tableRow["selector"] = '';
var json = tableRow["nodePorts"];
var nodePorts = JSON.parse(json);
var nodePortHtml = "