made clients robust against deep links

pull/779/head
Justin Richer 2015-02-27 08:47:39 -05:00
parent d570497b16
commit 45754d3b75
3 changed files with 32 additions and 62 deletions

View File

@ -33,6 +33,7 @@ Backbone.Model.prototype.fetchIfNeeded = function(options) {
return options.success(this, null); return options.success(this, null);
} }
}; };
Backbone.Collection.prototype.fetchIfNeeded = function(options) { Backbone.Collection.prototype.fetchIfNeeded = function(options) {
var _self = this; var _self = this;
if (!options) { if (!options) {
@ -639,22 +640,12 @@ var AppRouter = Backbone.Router.extend({
this.updateSidebar('admin/clients'); this.updateSidebar('admin/clients');
var client = this.clientList.get(id); var client = this.clientList.get(id);
if (!client) {
if (client == null) {
// it wasn't in the list, try loading the client directly
client = new ClientModel({id:id}); client = new ClientModel({id:id});
} }
$('#loadingbox').sheet('show'); var view = new ClientFormView({model:client, systemScopeList: app.systemScopeList});
$('#loading').html( view.load(function() {
'<span class="label" id="loading-scopes">' + $.t('common.scopes') + '</span> '
+ '<span class="label" id="loading-client">' + $.t('common.client') + '</span> ');
// re-sync the client every time
client.fetch({
success: function(client, response, options) {
$('#loading-client').addClass('label-success');
if ($.inArray("refresh_token", client.get("grantTypes")) != -1) { if ($.inArray("refresh_token", client.get("grantTypes")) != -1) {
client.set({ client.set({
allowRefresh: true allowRefresh: true
@ -666,32 +657,10 @@ var AppRouter = Backbone.Router.extend({
displayClientSecret:false displayClientSecret:false
}, { silent: true }); }, { silent: true });
var view = new ClientFormView({model:client, systemScopeList: app.systemScopeList});
view.load(function() {
$('#content').html(view.render().el); $('#content').html(view.render().el);
setPageTitle($.t('client.client-form.edit')); setPageTitle($.t('client.client-form.edit'));
}); });
},
error: function(model, response, options) {
//Pull out the response text.
var responseJson = JSON.parse(response.responseText);
//Display an alert with an error message
$('#modalAlert div.modal-header').html(responseJson.error);
$('#modalAlert div.modal-body').html(responseJson.error_description);
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
"backdrop" : "static",
"keyboard" : true,
"show" : true // ensure the modal is shown immediately
});
}
});
}, },
whiteList:function () { whiteList:function () {

View File

@ -644,19 +644,20 @@ var ClientFormView = Backbone.View.extend({
}, },
load:function(callback) { load:function(callback) {
if (this.options.systemScopeList.isFetched) { if (this.model.isFetched &&
$('#loadingbox').sheet('hide'); this.options.systemScopeList.isFetched) {
callback(); callback();
return; return;
} }
if (this.model.get('id') == null) {
// only show the box if this is a new client, otherwise the box is already showing
$('#loadingbox').sheet('show'); $('#loadingbox').sheet('show');
$('#loading').html('<span class="label" id="loading-scopes">' + $.t("common.scopes") + '</span> '); $('#loading').html(
} '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
'<span class="label" id="loading-scopes">' + $.t("common.scopes") + '</span> '
);
$.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}})) $.when(this.options.systemScopeList.fetchIfNeeded({success:function(e) {$('#loading-scopes').addClass('label-success');}}),
this.model.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}}))
.done(function() { .done(function() {
$('#loadingbox').sheet('hide'); $('#loadingbox').sheet('hide');
callback(); callback();

View File

@ -261,7 +261,7 @@ var WhiteListFormView = Backbone.View.extend({
if (this.options.client) { if (this.options.client) {
// we know what client we're dealing with already // we know what client we're dealing with already
if (this.model.isFetched && if (this.model.isFetched &&
this.options.client.isFetched()) { this.options.client.isFetched) {
callback(); callback();
return; return;
} }