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,58 +640,26 @@ 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) { client = new ClientModel({id:id});
// it wasn't in the list, try loading the client directly
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> ' if ($.inArray("refresh_token", client.get("grantTypes")) != -1) {
+ '<span class="label" id="loading-client">' + $.t('common.client') + '</span> '); client.set({
allowRefresh: true
}, { silent: true });
}
// re-sync the client every time client.set({
client.fetch({ generateClientSecret:false,
success: function(client, response, options) { displayClientSecret:false
$('#loading-client').addClass('label-success'); }, { silent: true });
if ($.inArray("refresh_token", client.get("grantTypes")) != -1) { $('#content').html(view.render().el);
client.set({ setPageTitle($.t('client.client-form.edit'));
allowRefresh: true });
}, { silent: true });
}
client.set({
generateClientSecret:false,
displayClientSecret:false
}, { silent: true });
var view = new ClientFormView({model:client, systemScopeList: app.systemScopeList});
view.load(function() {
$('#content').html(view.render().el);
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
});
}
});
}, },

View File

@ -644,20 +644,21 @@ 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) { $('#loadingbox').sheet('show');
// only show the box if this is a new client, otherwise the box is already showing $('#loading').html(
$('#loadingbox').sheet('show'); '<span class="label" id="loading-clients">' + $.t('common.clients') + '</span> ' +
$('#loading').html('<span class="label" id="loading-scopes">' + $.t("common.scopes") + '</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');}}),
.done(function() { this.model.fetchIfNeeded({success:function(e) {$('#loading-clients').addClass('label-success');}}))
.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;
} }