You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by je...@apache.org on 2012/10/03 00:40:48 UTC
git commit: cloudstack UI - advanced search - add a new shared
function listViewDataProvider() to deal with data parameter passed to API
call in listView.
Updated Branches:
refs/heads/master 71355c194 -> c7c6d2376
cloudstack UI - advanced search - add a new shared function listViewDataProvider() to deal with data parameter passed to API call in listView.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/c7c6d237
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/c7c6d237
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/c7c6d237
Branch: refs/heads/master
Commit: c7c6d23762c0ba2908fb89bebf418e207a71b272
Parents: 71355c1
Author: Jessica Wang <je...@citrix.com>
Authored: Tue Oct 2 15:29:36 2012 -0700
Committer: Jessica Wang <je...@citrix.com>
Committed: Tue Oct 2 15:40:34 2012 -0700
----------------------------------------------------------------------
ui/scripts/sharedFunctions.js | 42 ++++++++++++++++++++++++
ui/scripts/storage.js | 63 ++++++------------------------------
2 files changed, 52 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c7c6d237/ui/scripts/sharedFunctions.js
----------------------------------------------------------------------
diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js
index dfabef8..3b5d151 100644
--- a/ui/scripts/sharedFunctions.js
+++ b/ui/scripts/sharedFunctions.js
@@ -408,6 +408,48 @@ cloudStack.converters = {
}
}
+//data parameter passed to API call in listView
+function listViewDataProvider(args, data) {
+ //search
+ if(args.filterBy != null) {
+ if(args.filterBy.advSearch != null && typeof(args.filterBy.advSearch) == "object") { //advanced search
+ for(var key in args.filterBy.advSearch) {
+ if(key == 'tagKey' && args.filterBy.advSearch[key].length > 0) {
+ $.extend(data, {
+ 'tags[0].key': args.filterBy.advSearch[key]
+ });
+ }
+ else if(key == 'tagValue' && args.filterBy.advSearch[key].length > 0) {
+ $.extend(data, {
+ 'tags[0].value': args.filterBy.advSearch[key]
+ });
+ }
+ else if(args.filterBy.advSearch[key] != null && args.filterBy.advSearch[key].length > 0) {
+ data[key] = args.filterBy.advSearch[key]; //do NOT use $.extend(data, { key: args.filterBy.advSearch[key] }); which will treat key variable as "key" string
+ }
+ }
+ }
+ else if(args.filterBy.search != null && args.filterBy.search.by != null && args.filterBy.search.value != null) { //basic search
+ switch(args.filterBy.search.by) {
+ case "name":
+ if(args.filterBy.search.value.length > 0) {
+ $.extend(data, {
+ keyword: args.filterBy.search.value
+ });
+ }
+ break;
+ }
+ }
+ }
+
+ //pagination
+ $.extend(data, {
+ listAll: true,
+ page: args.page,
+ pagesize: pageSize
+ });
+}
+
//find service object in network object
function ipFindNetworkServiceByName(pName, networkObj) {
if(networkObj == null)
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c7c6d237/ui/scripts/storage.js
----------------------------------------------------------------------
diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js
index 6d2b734..9b207c5 100644
--- a/ui/scripts/storage.js
+++ b/ui/scripts/storage.js
@@ -49,6 +49,7 @@
}
*/
},
+
advSearchFields: {
name: { label: 'Name' },
zoneid: {
@@ -73,32 +74,7 @@
}
});
}
- },
-
- domainid: {
- label: 'Domain',
- select: function(args) {
- $.ajax({
- url: createURL('listDomains'),
- data: {
- listAll: true,
- details: 'min'
- },
- success: function(json) {
- args.response.success({
- data: $.map(json.listdomainsresponse.domain, function(domain) {
- return {
- id: domain.id,
- description: domain.path
- };
- })
- });
- }
- });
- }
- },
- account: { label: 'Account' },
-
+ },
tagKey: { label: 'Tag Key' },
tagValue: { label: 'Tag Value' }
},
@@ -323,39 +299,20 @@
},
dataProvider: function(args) {
- var array1 = [];
- if(args.filterBy != null) {
- if(args.filterBy.advSearch != null && typeof(args.filterBy.advSearch) == "object") {
- for(var key in args.filterBy.advSearch) {
- if(key == 'tagKey' && args.filterBy.advSearch[key].length > 0)
- array1.push("&tags[0].key=" + args.filterBy.advSearch[key]);
- else if(key == 'tagValue' && args.filterBy.advSearch[key].length > 0)
- array1.push("&tags[0].value=" + args.filterBy.advSearch[key]);
- else if(args.filterBy.advSearch[key] != null && args.filterBy.advSearch[key].length > 0)
- array1.push("&" + key + "=" + args.filterBy.advSearch[key]);
- }
- }
- else if(args.filterBy.search != null && args.filterBy.search.by != null && args.filterBy.search.value != null) {
- switch(args.filterBy.search.by) {
- case "name":
- if(args.filterBy.search.value.length > 0)
- array1.push("&keyword=" + args.filterBy.search.value);
- break;
- }
- }
- }
-
- var apiCmd = "listVolumes&listAll=true&page=" + args.page + "&pagesize=" + pageSize+ array1.join("");
+ var data = {};
+ listViewDataProvider(args, data);
+
if(args.context != null) {
if("instances" in args.context) {
- apiCmd += "&virtualMachineId=" + args.context.instances[0].id;
+ $.extend(data, {
+ virtualMachineId: args.context.instances[0].id
+ });
}
}
$.ajax({
- url: createURL(apiCmd),
- dataType: "json",
- async: true,
+ url: createURL('listVolumes'),
+ data: data,
success: function(json) {
var items = json.listvolumesresponse.volume;
args.response.success({