From 64605e7703c1cb0802a02481907abf40529492f1 Mon Sep 17 00:00:00 2001 From: bfederle Date: Mon, 23 Jul 2012 15:04:43 -0700 Subject: [PATCH] UI: Add tag API call generator Adds a helper to return an object to pass to the 'tagger' widget, including all required data and action functions. Syntax is as follows, just include anywhere were the tags widget is supported: tags: cloudStack.api.tags({ resourceType: 'Project', contextId: 'projects' }) --- ui/scripts/sharedFunctions.js | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js index cf437afed52..55d014ba429 100644 --- a/ui/scripts/sharedFunctions.js +++ b/ui/scripts/sharedFunctions.js @@ -617,5 +617,83 @@ cloudStack.api = { } } } + }, + + tags: function(args) { + var resourceType = args.resourceType; + var contextId = args.contextId; + + return { + actions: { + add: function(args) { + var data = args.data; + var resourceId = args.context[contextId][0].id; + + $.ajax({ + url: createURL( + 'createTags&tags[0].key=' + data.key + '&tags[0].value=' + data.value + ), + data: { + resourceIds: resourceId, + resourceType: resourceType + }, + success: function(json) { + args.response.success({ + _custom: { jobId: json.createtagsresponse.jobid }, + notification: { + desc: 'Add tag for instance', + poll: pollAsyncJobResult + } + }); + } + }); + }, + + remove: function(args) { + var data = args.context.tagItems[0]; + var resourceId = args.context[contextId][0].id; + + $.ajax({ + url: createURL( + 'deleteTags&tags[0].key=' + data.key + '&tags[0].value=' + data.value + ), + data: { + resourceIds: resourceId, + resourceType: resourceType + }, + success: function(json) { + args.response.success({ + _custom: { jobId: json.deletetagsresponse.jobid }, + notification: { + desc: 'Remove tag for instance', + poll: pollAsyncJobResult + } + }); + } + }); + } + }, + dataProvider: function(args) { + var resourceId = args.context[contextId][0].id; + + $.ajax({ + url: createURL('listTags'), + data: { + listAll: true, + resourceId: resourceId, + resourceType: resourceType + }, + success: function(json) { + args.response.success({ + data: json.listtagsresponse ? + json.listtagsresponse.tag : [] + }); + }, + error: function(json) { + args.response.error(parseXMLHttpResponse(json)); + } + }); + } + }; } };