Add adapter selection on server page

Change-Id: I27c7256376ff32fe416ca5f63fc92f1f56b18c20
This commit is contained in:
jiahuay 2014-05-06 18:15:39 -07:00
parent 902f491305
commit 36779c99aa
5 changed files with 65 additions and 4 deletions

View File

@ -485,4 +485,21 @@ steal("jquery/dom/fixture", "jquery/lang/json", function(){
return res;
});
$.fixture('GET /api/adapters', function(original, settings, headers) {
console.log("original: ", original);
console.log("settings: ", settings);
var res = {
"status": "OK",
"adapters": [{
"id": 1,
"name": "Centos_openstack"
}, {
"id": 2,
"name": "Centos"
}
]
};
return res;
});
})

View File

@ -113,6 +113,14 @@ steal("jquery/model", "jquery/lang/json",
success: success,
error: error
});
},
get: function(success, error) {
$.ajax({
url: '/api/adapters',
type: 'get',
success: success,
error: error
});
}
}, {});

View File

@ -19,7 +19,8 @@ steal(
machines: [],
switches: [],
snmp: true,
adapter_id: null
adapter_id: null,
adapters: []
};
var state = new $.Observe(odsState);

View File

@ -36,6 +36,11 @@ steal(
this.dataTable.fnClearTable();
this.dataTable.fnAddData(oldAllServersData);
for (var i = 0; i < this.options.odsState.adapters.length; i++) {
$("#adapter").append("<option value=\"" + this.options.odsState.adapters[i].id + "\">" + this.options.odsState.adapters[i].name + "</option>");
}
$('#adapter').val(String(this.options.odsState.adapter_id));
var oldSelectedServersData = this.options.odsState.servers;
for (var i = 0; i < oldSelectedServersData.length; i++) {
@ -47,6 +52,10 @@ steal(
});
}
this.countCheckedServers();
} else {
// get adapters
this.adapters = [];
Ods.Adapter.get(this.proxy('onGetAdapters'), this.proxy('onGetAdaptersErr'));
}
@ -79,7 +88,6 @@ steal(
"serverControl": this
});
}
},
dataTableIpAddrSort: function() {
@ -203,14 +211,14 @@ steal(
this.options.odsState.machines = this.dataTable.fnGetData();
if (this.initServerStep) {
this.options.odsState.adapter_id = parseInt($("#adapter").val());
// create cluster
Ods.Cluster.create({
"cluster": {
"name": "",
"adapter_id": 1
"adapter_id": this.options.odsState.adapter_id
}
}, this.proxy('onClusterCreated'), this.proxy('onClusterCreatedErr'));
this.options.odsState.adapter_id = 1;
} else {
// replace all hosts in current cluster
var cluster_id = this.options.odsState.cluster_id;
@ -222,6 +230,30 @@ steal(
}
},
/************************************/
// get adapters success callback
/************************************/
'onGetAdapters': function(data, textStatus, xhr) {
if (xhr.status == 200) {
this.adapters = data.adapters;
this.options.odsState.adapters = data.adapters;
if (this.adapters.length > 0) {
for (var i = 0; i < this.adapters.length; i++) {
$("#adapter").append("<option value=\"" + this.adapters[i].id + "\">" + this.adapters[i].name + "</option>");
}
} else {
$("#adapter").append("<option value='-1'>Not Available</option>");
}
}
},
/************************************/
// get adapters error callback
/************************************/
'onGetAdaptersErr': function(xhr, status, statusText) {
$("#adapter").append("<option value='-1'>Not Available</option>");
},
/************************************/
// create cluster success callback
/************************************/

View File

@ -54,6 +54,9 @@
</tbody>
</table>
<br>
<div class='float_left rounded server-selection-num'>
Adapter: <select id="adapter"></select>
</div>
<div class='float_right rounded server-selection-num'>
<span id="selected_num">0</span> items selected
</div>