lib/rack/oauth2/admin/js/application.js in rack-oauth2-server-2.0.0.beta3 vs lib/rack/oauth2/admin/js/application.js in rack-oauth2-server-2.0.0.beta4

- old
+ new

@@ -13,64 +13,84 @@ // For all request (except callback), if we don't have an OAuth access token, this.requireOAuth(); this.bind("oauth.denied", function(evt, error) { this.partial("admin/views/no_access.tmpl", { error: error.message }); }); + this.bind("oauth.connected", function() { $("#header .signout").show() }); + this.bind("oauth.disconnected", function() { $("#header .signout").hide() }); var api = document.location.pathname + "/api"; // Takes array of string with scope names (typically request parameters) and // normalizes them into an array of scope names. - function mergeScopes(scopes) { - if ($.isArray(scopes)) - scopes = scopes.join(" "); - scopes = (scopes || "").trim().split(/\s+/); - return scopes.length == 1 && scopes[0] == "" ? [] : _.uniq(scopes).sort(); + function mergeScope(scope) { + if ($.isArray(scope)) + scope = scope.join(" "); + scope = (scope || "").trim().split(/\s+/); + return scope.length == 1 && scope[0] == "" ? [] : _.uniq(scope).sort(); } - var commonScopes; - function withCommonScopes(cb) { - if (commonScopes) - cb(commonScopes) + var commonScope; + function withCommonScope(cb) { + if (commonScope) + cb(commonScope) else - $.getJSON(api + "/clients", function(json) { cb(commonScopes = json.scopes); }) + $.getJSON(api + "/clients", function(json) { cb(commonScope = json.scope); }) } // View all clients this.get("#/", function(context) { context.title("All Clients"); $.getJSON(api + "/clients", function(clients) { - commonScopes = clients.scopes; + commonScope = clients.scope; context.partial("admin/views/clients.tmpl", { clients: clients.list, tokens: clients.tokens }). load(clients.history).then(function(json) { $("#fig").chart(json.data, "granted"); }); }); }); + // View single client + this.get("#/client/:id", function(context) { + $.getJSON(api + "/client/" + context.params.id, function(client) { + context.title(client.displayName); + client.notes = (client.notes || "").split(/\n\n/); + context.partial("admin/views/client.tmpl", client). + load(client.history).then(function(json) { $("#fig").chart(json.data, "granted"); }); + }); + }); + this.get("#/client/:id/page/:page", function(context) { + $.getJSON(api + "/client/" + context.params.id + "?page=" + context.params.page, function(client) { + context.title(client.displayName); + client.notes = client.notes.split(/\n\n/); + context.partial("admin/views/client.tmpl", client). + load(client.history).then(function(json) { $("#fig").chart(json.data, "granted"); }); + }); + }); // Edit client this.get("#/client/:id/edit", function(context) { $.getJSON(api + "/client/" + context.params.id, function(client) { context.title(client.displayName); - withCommonScopes(function(scopes) { - client.common = scopes; + withCommonScope(function(scope) { + client.common = scope; context.partial("admin/views/edit.tmpl", client) }) }) }); this.put("#/client/:id", function(context) { - context.params.scopes = mergeScopes(context.params.scopes); + context.params.scope = mergeScope(context.params.scope); $.ajax({ type: "put", url: api + "/client/" + context.params.id, data: { displayName: context.params.displayName, link: context.params.link, imageUrl: context.params.imageUrl, redirectUri: context.params.redirectUri, - scopes: context.params.scopes + notes: context.params.notes, + scope: context.params.scope }, success: function(client) { context.redirect("#/client/" + context.params.id); app.trigger("notice", "Saved your changes"); }, error: function(xhr) { - withCommonScopes(function(scopes) { - context.params.common = scopes; + withCommonScope(function(scope) { + context.params.common = scope; context.partial("admin/views/edit.tmpl", context.params); }); } }) }); @@ -86,48 +106,35 @@ }); // Revoke token this.post("#/token/:id/revoke", function(context) { $.post(api + "/token/" + context.params.id + "/revoke", function() { app.refresh() }); }); - // View single client - this.get("#/client/:id", function(context) { - $.getJSON(api + "/client/" + context.params.id, function(client) { - context.title(client.displayName); - context.partial("admin/views/client.tmpl", client). - load(client.history).then(function(json) { $("#fig").chart(json.data, "granted"); }); - }); - }); - this.get("#/client/:id/:page", function(context) { - $.getJSON(api + "/client/" + context.params.id + "?page=" + context.params.page, function(client) { - context.title(client.displayName); - context.partial("admin/views/client.tmpl", client) - }); - }); // Create new client this.get("#/new", function(context) { context.title("Add New Client"); - withCommonScopes(function(scopes) { - context.partial("admin/views/edit.tmpl", { common: scopes, scopes: scopes }); + withCommonScope(function(scope) { + context.partial("admin/views/edit.tmpl", { common: scope, scope: scope }); }); }); this.post("#/clients", function(context) { context.title("Add New Client"); - context.params.scopes = mergeScopes(context.params.scopes); + context.params.scope = mergeScope(context.params.scope); $.ajax({ type: "post", url: api + "/clients", data: { displayName: context.params.displayName, link: context.params.link, imageUrl: context.params.imageUrl, redirectUri: context.params.redirectUri, - scopes: context.params.scopes + notes: context.params.notes, + scope: context.params.scope }, success: function(client) { app.trigger("notice", "Added new client application " + client.displayName); context.redirect("#/"); }, error: function(xhr) { - withCommonScopes(function(scopes) { - context.params.common = scopes; + withCommonScope(function(scope) { + context.params.common = scope; context.partial("admin/views/edit.tmpl", context.params); }); } }); });