You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2012/07/24 00:18:41 UTC

[2/5] git commit: UI: Add tag API call generator

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'
})


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/64605e77
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/64605e77
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/64605e77

Branch: refs/heads/master
Commit: 64605e7703c1cb0802a02481907abf40529492f1
Parents: 1c2780f
Author: bfederle <bf...@gmail.com>
Authored: Mon Jul 23 15:04:43 2012 -0700
Committer: Brian Federle <br...@citrix.com>
Committed: Mon Jul 23 15:18:36 2012 -0700

----------------------------------------------------------------------
 ui/scripts/sharedFunctions.js |   78 ++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/64605e77/ui/scripts/sharedFunctions.js
----------------------------------------------------------------------
diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js
index cf437af..55d014b 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));
+          }
+        });
+      }
+    };
   }
 };