public/js/models/record.js in conjur-asset-ui-api-1.1.1 vs public/js/models/record.js in conjur-asset-ui-api-1.2.0

- old
+ new

@@ -1,26 +1,39 @@ if (typeof $ === "undefined") { throw new Error("jQuery is required") } -var RecordModel = function(kind, id){ - var Record = function() { - this.object = null; - } - - Record.prototype.fetch = function(callback, errback) { - errback || (errback = function(status, text, xhr){ - alert("Error fetching " + kind + ":" + id + " " + status + " " + text); - }); - var self = this; - $.ajax({ - url: "/api/" + kind + "/" + encodeURIComponent(id), - success: function(data) { - self.object = data; - callback(self); - }, - error: function(xhr, textStatus, errorThrown){ - errback(xhr.status, errorThrown, xhr); - } - }); - } - - return new Record(); +Record = {}; + +Record.Generic = function(kind, id) { + this.kind = kind; + this.id = id; +} + +Record.Generic.prototype.attributes = function(callback) { + var id = this.id; + $.ajax({ + url: "/api/" + kind + "/" + encodeURIComponent(id), + success: function(data) { + callback(null, data); + }, + error: callback + }); +} + +Record.Generic.prototype.ownedResources = function(callback) { + var id = this.id; + var roleid = [ this.kind, this.id ].join(':') + $.ajax({ + url: "/api/authz/" + conjurConfiguration.account + "/resources?owner=" + roleid, + success: function(result) { + callback(null, result); + }, + error: callback + }); +} + +Record.Generic.prototype.fetch = function(callback) { + this.attributes(function(err, data) { + if ( err ) + return errback(err); + callback(data); + }); }