Skip to content

Commit e3886d9

Browse files
author
Anurag Awasthi
committed
Fixes to UI code
- Check before repopulating fields not meant for users. - Fixed localization and removed unnecessary IDs in index.html - Hide fields for pod, cluster and host if user is logged in
1 parent 930043f commit e3886d9

3 files changed

Lines changed: 98 additions & 146 deletions

File tree

ui/index.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@
102102
<h3><translate key="label.select.deployment.infrastructure"/></h3>
103103
<p><translate key="message.select.a.zone"/></p>
104104
<div class="select-area lower-area">
105-
<select id="zoneid" name="zoneid" class="zoneid required" required></select>
106-
<label for="zoneid" class="">Zone</label>
105+
<select name="zoneid" class="zoneid required" required></select>
106+
<label for="zoneid" class="description"><translate key="label.zone"/></label>
107107
</div>
108108
<div class="select-area lower-area">
109-
<select id="podid" name="podid" class="podid"></select>
110-
<label for="podid">Pod</label>
109+
<select name="podid" class="podid"></select>
110+
<label for="podid" class="description"><translate key="label.pod"/></label>
111111
</div>
112112
<div class="select-area lower-area">
113-
<select id="clusterid" name="clusterid" class="clusterid"></select>
114-
<label for="clusterid">Cluster</label>
113+
<select name="clusterid" class="clusterid"></select>
114+
<label for="clusterid" class="description"><translate key="label.cluster"/></label>
115115
</div>
116116
<div class="select-area lower-area">
117-
<select id="hostid" name="hostid" class="hostid"></select>
118-
<label for="hostid">Host</label>
117+
<select name="hostid" class="hostid"></select>
118+
<label for="hostid" class="description"><translate key="label.host"/></label>
119119
</div>
120120
</div>
121121
<!-- Select template -->

ui/scripts/instanceWizard.js

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,31 @@
196196
}
197197
//in all other cases (as well as from instance page) all zones are populated to dropdown
198198
else {
199-
if (isAdmin()) {
200-
zones = [{
201-
id: -1,
202-
name: 'Default'
203-
}];
204-
$.ajax({
205-
url: createURL("listZones&available=true"),
206-
dataType: "json",
207-
async: false,
208-
success: function(json) {
209-
zoneObjs = json.listzonesresponse.zone;
210-
$(zoneObjs).each(function() {
211-
zones.push({
212-
id: this.id,
213-
name: this.name
214-
});
199+
var postData = {};
200+
var zones = [{
201+
id: -1,
202+
name: 'Default'
203+
}];
204+
$.ajax({
205+
url: createURL("listZones&available=true"),
206+
dataType: "json",
207+
async: false,
208+
success: function(json) {
209+
zoneObjs = json.listzonesresponse.zone;
210+
$(zoneObjs).each(function() {
211+
zones.push({
212+
id: this.id,
213+
name: this.name
215214
});
216-
}
217-
});
215+
});
216+
}
217+
});
218+
219+
$.extend(postData, {
220+
"zones": zones
221+
});
222+
223+
if (isAdmin()) {
218224
pods = [{
219225
id: -1,
220226
description: 'Default',
@@ -281,40 +287,16 @@
281287
}
282288
}
283289
});
284-
args.response.success({
285-
data: {
286-
zones: zones,
287-
pods: pods,
288-
clusters: clusters,
289-
hosts: hosts
290-
}
290+
$.extend(postData, {
291+
"pods": pods,
292+
"clusters": clusters,
293+
"hosts": hosts
291294
});
292295

293-
} else{
294-
zones = [{
295-
id: -1,
296-
name: 'Default'
297-
}];
298-
$.ajax({
299-
url: createURL("listZones&available=true"),
300-
dataType: "json",
301-
async: false,
302-
success: function(json) {
303-
zoneObjs = json.listzonesresponse.zone;
304-
$(zoneObjs).each(function() {
305-
zones.push({
306-
id: this.id,
307-
name: this.name
308-
});
309-
});
310-
}
311-
});
312-
args.response.success({
313-
data: {
314-
zones: zones
315-
}
316-
});
317-
}
296+
}
297+
args.response.success({
298+
data: postData
299+
});
318300
}
319301
},
320302

ui/scripts/ui-custom/instanceWizard.js

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -277,95 +277,65 @@
277277
}).click();
278278
};
279279

280-
var filterPodList = function(zoneId) {
281-
var podcallback = function(data) {
282-
var podSelect = $step.find('.select-deployment .podid');
283-
podSelect.find('option').remove().end();
284-
$(data).each(function() {
285-
podSelect.append(
286-
$('<option>')
287-
.attr({
288-
value: this.id,
289-
'wizard-field': 'pod',
290-
'parentId': this.parentId
291-
})
292-
.html(this.description)
293-
.data('json-obj', this)
294-
);
295-
});
296-
};
297-
args.fetchPodList(podcallback, zoneId);
298-
};
299-
300-
var filterClusterList = function(podId, zoneId) {
301-
var clustercallback = function(data) {
302-
var clusterSelect = $step.find('.select-deployment .clusterid');
303-
clusterSelect.find('option').remove().end();
304-
$(data).each(function() {
305-
clusterSelect.append(
306-
$('<option>')
307-
.attr({
308-
value: this.id,
309-
'wizard-field': 'cluster',
310-
'parentId': this.parentId
311-
})
312-
.html(this.description)
313-
.data('json-obj', this)
314-
);
315-
});
316-
};
317-
args.fetchClusterList(clustercallback, podId, zoneId);
318-
};
319-
320-
var filterHostList = function(clusterId, podId, zoneId) {
321-
var hostcallback = function(data) {
322-
var hostSelect = $step.find('.select-deployment .hostid');
323-
hostSelect.find('option').remove().end();
324-
$(data).each(function() {
325-
hostSelect.append(
326-
$('<option>')
327-
.attr({
328-
value: this.id,
329-
'wizard-field': 'host',
330-
'parentId': this.parentId
331-
})
332-
.html(this.description)
333-
.data('json-obj', this)
334-
);
335-
});
336-
};
337-
args.fetchHostList(hostcallback, clusterId, podId, zoneId);
338-
};
339-
340-
var $zoneSelect = $step.find('.select-deployment .zoneid');
341-
$zoneSelect.unbind('change');
342-
$zoneSelect.change(function() {
343-
zoneId = $zoneSelect.val();
344-
if (zoneId != null) {
345-
filterPodList(zoneId);
346-
filterClusterList(-1, zoneId);
347-
filterHostList(-1, -1, zoneId);
348-
}
349-
});
350-
351-
var $podSelect = $step.find('.select-deployment .podid');
352-
$podSelect.unbind('change');
353-
$podSelect.change(function() {
354-
podId = $podSelect.val();
355-
if (podId != null) {
356-
filterClusterList(podId, -1);
357-
filterHostList(-1, podId, -1);
358-
}
359-
});
280+
if (isAdmin()) {
281+
$step.find('.select-deployment .podid').parent().show();
282+
$step.find('.select-deployment .clusterid').parent().show();
283+
$step.find('.select-deployment .hostid').parent().show();
284+
285+
286+
var updateFieldOptions = function(fieldClass, wizardField) {
287+
return function(data) {
288+
var fieldSelect = $step.find('.select-deployment .' + fieldClass);
289+
fieldSelect.find('option').remove().end();
290+
$(data).each(function() {
291+
fieldSelect.append(
292+
$('<option>')
293+
.attr({
294+
value: this.id,
295+
'wizard-field': wizardField,
296+
'parentId': this.parentId
297+
})
298+
.html(this.description)
299+
.data('json-obj', this)
300+
);
301+
});
302+
}
303+
};
304+
305+
var $zoneSelect = $step.find('.select-deployment .zoneid');
306+
$zoneSelect.unbind('change');
307+
$zoneSelect.change(function() {
308+
zoneId = $zoneSelect.val();
309+
if (zoneId != null && isAdmin()) {
310+
args.fetchPodList(updateFieldOptions('podid', 'pod'), zoneId);
311+
args.fetchClusterList(updateFieldOptions('clusterid', 'cluster'), -1, zoneId);
312+
args.fetchHostList(updateFieldOptions('hostid', 'host'), -1, -1, zoneId);
313+
}
314+
});
315+
316+
var $podSelect = $step.find('.select-deployment .podid');
317+
$podSelect.unbind('change');
318+
$podSelect.change(function() {
319+
podId = $podSelect.val();
320+
if (podId != null) {
321+
args.fetchClusterList(updateFieldOptions('clusterid', 'cluster'), podId, -1);
322+
args.fetchHostList(updateFieldOptions('hostid', 'host'), -1, podId, -1);
323+
}
324+
});
360325

361-
var $clusterSelect = $step.find('.select-deployment .clusterid');
362-
$clusterSelect.unbind('change');
363-
$clusterSelect.change(function() {
364-
clusterId = $clusterSelect.val();
365-
if (clusterId != null) {
366-
filterHostList(clusterId, -1, -1);
367-
}
368-
});
326+
var $clusterSelect = $step.find('.select-deployment .clusterid');
327+
$clusterSelect.unbind('change');
328+
$clusterSelect.change(function() {
329+
clusterId = $clusterSelect.val();
330+
if (clusterId != null) {
331+
args.fetchHostList(updateFieldOptions('hostid', 'host'), clusterId, -1, -1);
332+
}
333+
});
334+
} else {
335+
$step.find('.select-deployment .podid').parent().hide();
336+
$step.find('.select-deployment .clusterid').parent().hide();
337+
$step.find('.select-deployment .hostid').parent().hide();
338+
}
369339

370340
return {
371341
response: {

0 commit comments

Comments
 (0)