Skip to content

Commit c7c6d23

Browse files
author
Jessica Wang
committed
cloudstack UI - advanced search - add a new shared function listViewDataProvider() to deal with data parameter passed to API call in listView.
1 parent 71355c1 commit c7c6d23

2 files changed

Lines changed: 52 additions & 53 deletions

File tree

‎ui/scripts/sharedFunctions.js‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,48 @@ cloudStack.converters = {
408408
}
409409
}
410410

411+
//data parameter passed to API call in listView
412+
function listViewDataProvider(args, data) {
413+
//search
414+
if(args.filterBy != null) {
415+
if(args.filterBy.advSearch != null && typeof(args.filterBy.advSearch) == "object") { //advanced search
416+
for(var key in args.filterBy.advSearch) {
417+
if(key == 'tagKey' && args.filterBy.advSearch[key].length > 0) {
418+
$.extend(data, {
419+
'tags[0].key': args.filterBy.advSearch[key]
420+
});
421+
}
422+
else if(key == 'tagValue' && args.filterBy.advSearch[key].length > 0) {
423+
$.extend(data, {
424+
'tags[0].value': args.filterBy.advSearch[key]
425+
});
426+
}
427+
else if(args.filterBy.advSearch[key] != null && args.filterBy.advSearch[key].length > 0) {
428+
data[key] = args.filterBy.advSearch[key]; //do NOT use $.extend(data, { key: args.filterBy.advSearch[key] }); which will treat key variable as "key" string
429+
}
430+
}
431+
}
432+
else if(args.filterBy.search != null && args.filterBy.search.by != null && args.filterBy.search.value != null) { //basic search
433+
switch(args.filterBy.search.by) {
434+
case "name":
435+
if(args.filterBy.search.value.length > 0) {
436+
$.extend(data, {
437+
keyword: args.filterBy.search.value
438+
});
439+
}
440+
break;
441+
}
442+
}
443+
}
444+
445+
//pagination
446+
$.extend(data, {
447+
listAll: true,
448+
page: args.page,
449+
pagesize: pageSize
450+
});
451+
}
452+
411453
//find service object in network object
412454
function ipFindNetworkServiceByName(pName, networkObj) {
413455
if(networkObj == null)

‎ui/scripts/storage.js‎

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
}
5050
*/
5151
},
52+
5253
advSearchFields: {
5354
name: { label: 'Name' },
5455
zoneid: {
@@ -73,32 +74,7 @@
7374
}
7475
});
7576
}
76-
},
77-
78-
domainid: {
79-
label: 'Domain',
80-
select: function(args) {
81-
$.ajax({
82-
url: createURL('listDomains'),
83-
data: {
84-
listAll: true,
85-
details: 'min'
86-
},
87-
success: function(json) {
88-
args.response.success({
89-
data: $.map(json.listdomainsresponse.domain, function(domain) {
90-
return {
91-
id: domain.id,
92-
description: domain.path
93-
};
94-
})
95-
});
96-
}
97-
});
98-
}
99-
},
100-
account: { label: 'Account' },
101-
77+
},
10278
tagKey: { label: 'Tag Key' },
10379
tagValue: { label: 'Tag Value' }
10480
},
@@ -323,39 +299,20 @@
323299
},
324300

325301
dataProvider: function(args) {
326-
var array1 = [];
327-
if(args.filterBy != null) {
328-
if(args.filterBy.advSearch != null && typeof(args.filterBy.advSearch) == "object") {
329-
for(var key in args.filterBy.advSearch) {
330-
if(key == 'tagKey' && args.filterBy.advSearch[key].length > 0)
331-
array1.push("&tags[0].key=" + args.filterBy.advSearch[key]);
332-
else if(key == 'tagValue' && args.filterBy.advSearch[key].length > 0)
333-
array1.push("&tags[0].value=" + args.filterBy.advSearch[key]);
334-
else if(args.filterBy.advSearch[key] != null && args.filterBy.advSearch[key].length > 0)
335-
array1.push("&" + key + "=" + args.filterBy.advSearch[key]);
336-
}
337-
}
338-
else if(args.filterBy.search != null && args.filterBy.search.by != null && args.filterBy.search.value != null) {
339-
switch(args.filterBy.search.by) {
340-
case "name":
341-
if(args.filterBy.search.value.length > 0)
342-
array1.push("&keyword=" + args.filterBy.search.value);
343-
break;
344-
}
345-
}
346-
}
347-
348-
var apiCmd = "listVolumes&listAll=true&page=" + args.page + "&pagesize=" + pageSize+ array1.join("");
302+
var data = {};
303+
listViewDataProvider(args, data);
304+
349305
if(args.context != null) {
350306
if("instances" in args.context) {
351-
apiCmd += "&virtualMachineId=" + args.context.instances[0].id;
307+
$.extend(data, {
308+
virtualMachineId: args.context.instances[0].id
309+
});
352310
}
353311
}
354312

355313
$.ajax({
356-
url: createURL(apiCmd),
357-
dataType: "json",
358-
async: true,
314+
url: createURL('listVolumes'),
315+
data: data,
359316
success: function(json) {
360317
var items = json.listvolumesresponse.volume;
361318
args.response.success({

0 commit comments

Comments
 (0)