Refactoring of routing. Client updates

pull/105/merge
Michael Jett 2012-05-17 16:33:22 -04:00
parent 6f43040587
commit 2d980a4d8f
5 changed files with 60 additions and 52 deletions

View File

@ -25,18 +25,18 @@ import org.springframework.web.bind.annotation.RequestMapping;
@Controller @Controller
@RequestMapping("/") @RequestMapping("/")
@PreAuthorize("hasRole('ROLE_USER')")
public class ManagerController { public class ManagerController {
@PreAuthorize("hasRole('ROLE_USER')")
@RequestMapping({"", "/home", "/index"}) @RequestMapping({"", "/home", "/index"})
public String showHomePage() { public String showHomePage() {
return "home"; return "home";
} }
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping("/admin/manage/")
@RequestMapping("/admin/manage/clients")
public String showClientManager() { public String showClientManager() {
return "admin/manage/clients"; return "admin/manage";
} }
} }

View File

@ -5,7 +5,7 @@
<ul class="nav nav-list"> <ul class="nav nav-list">
<security:authorize ifAnyGranted="ROLE_ADMIN"> <security:authorize ifAnyGranted="ROLE_ADMIN">
<li class="nav-header">Administrative</li> <li class="nav-header">Administrative</li>
<li><a href="admin/manage/clients">Manage Clients</a></li> <li><a href="admin/manage/#clients">Manage Clients</a></li>
<li><a href="#">White Lists</a></li> <li><a href="#">White Lists</a></li>
<li><a href="#">Black Lists</a></li> <li><a href="#">Black Lists</a></li>
</security:authorize> </security:authorize>

View File

@ -6,31 +6,28 @@
initialize: function () { initialize: function () {
this.bind('error:clientName', function(model, errs) { // bind validation errors to dom elements
$('#clientName').addClass('error'); // this will display form elements in red if they are not valid
this.bind('error', function(model, errs) {
_.map(errs, function (val, elID) {
$('#' + elID).addClass('error');
});
}); });
this.bind('error:clientDescription', function(model, errs) {
$('#clientDescription').addClass('error');
});
this.bind('error:registeredRedirectUri', function(model, errs) {
$('#registeredRedirectUri').addClass('error');
});
}, },
validate:{ validate:{
clientName:{ clientName:{
required:true, required:true,
pattern:/^[a-zA-Z ]+$/, pattern:/^[\w ]+$/,
minlength:3, minlength:3,
maxlength:100 maxlength:100
}, },
clientDescription:{ clientDescription:{
required:true, required:true,
pattern:/^[a-zA-Z ]+$/, pattern:/^[\w ]+$/,
minlength:3, minlength:3,
maxlength:100 maxlength:200
}, },
registeredRedirectUri: { registeredRedirectUri: {
custom: 'validateURI' custom: 'validateURI'
@ -42,17 +39,19 @@
var expression = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi; var expression = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
var regex = new RegExp(expression); var regex = new RegExp(expression);
return attributeValue.every(function (url) { if (!attributeValue.every(function (url) {
if (!url.match(regex)) { if (url.match(regex)) {
return false; return true;
} }
}); })) return "Invalid URI";
}, },
// We can pass it default values. // We can pass it default values.
defaults:{ defaults:{
clientName:"", clientName:"",
registeredRedirectUri:[], registeredRedirectUri:[""],
authorizedGrantTypes:[], authorizedGrantTypes:[],
scope:[], scope:[],
authorities:[], authorities:[],
@ -61,13 +60,18 @@
allowRefresh:false allowRefresh:false
}, },
urlRoot:"/api/clients" urlRoot:"api/clients"
}); });
var ClientCollection = Backbone.Collection.extend({ var ClientCollection = Backbone.Collection.extend({
initialize: function() {
this.fetch();
},
model:ClientModel, model:ClientModel,
url:"/api/clients" url:"api/clients"
}); });
@ -82,7 +86,6 @@
} }
this.model.bind('change', this.render, this); this.model.bind('change', this.render, this);
//this.model.on('change', this.render)
}, },
render:function (eventName) { render:function (eventName) {
@ -96,7 +99,7 @@
}, },
editClient:function () { editClient:function () {
document.location.hash = 'client/' + this.model.id; app.navigate('client/' + this.model.id, {trigger: true});
}, },
deleteClient:function () { deleteClient:function () {
@ -105,8 +108,8 @@
this.model.destroy({ this.model.destroy({
success:function () { success:function () {
self.$el.fadeTo("slow", 0.00, function(){ //fade self.$el.fadeTo("fast", 0.00, function(){ //fade
$(this).slideUp("slow", function() { //slide up $(this).slideUp("fast", function() { //slide up
$(this).remove(); //then remove from the DOM $(this).remove(); //then remove from the DOM
}); });
}); });
@ -135,7 +138,7 @@
newClient:function () { newClient:function () {
this.remove(); this.remove();
document.location.hash = 'client/new'; app.navigate('client/new', {trigger: true});
}, },
render:function (eventName) { render:function (eventName) {
@ -144,7 +147,7 @@
$(this.el).html($('#tmpl-client-table').html()); $(this.el).html($('#tmpl-client-table').html());
_.each(this.model.models, function (client) { _.each(this.model.models, function (client) {
$("#client-table").append(new ClientView({model:client}).render().el); $("#client-table",this.el).append(new ClientView({model:client}).render().el);
}, this); }, this);
return this; return this;
@ -168,7 +171,7 @@
saveClient:function (event) { saveClient:function (event) {
event.preventDefault(); $('.control-group').removeClass('error');
this.model.set({ this.model.set({
clientName:$('#clientName input').val(), clientName:$('#clientName input').val(),
@ -176,26 +179,21 @@
clientDescription:$('#clientDescription textarea').val(), clientDescription:$('#clientDescription textarea').val(),
allowRefresh:$('#allowRefresh').is(':checked') allowRefresh:$('#allowRefresh').is(':checked')
}); });
if (this.model.isNew()) {
this.model.save(this.model, {
success:function () {
app.navigate('clients', {trigger: true});
}
});
if (this.model.isNew() && this.model.isValid()) {
var self = this; var self = this;
app.clientList.create(this.model, { app.clientList.create(this.model, {
success:function () { success:function () {
document.location.hash = ''; app.navigate('clients', {trigger: true});
},
error: function () {
//alert('boo!');
} }
}); });
} else {
this.model.save(this.model, {
success:function () {
document.location.hash = '';
},
error: function () {
//alert('boo!');
}
});
} }
return false; return false;
@ -212,21 +210,32 @@
var AppRouter = Backbone.Router.extend({ var AppRouter = Backbone.Router.extend({
routes:{ routes:{
"":"list", "clients":"list",
"client/new":"newClient", "client/new":"newClient",
"client/:id":"editClient" "client/:id":"editClient"
}, },
initialize:function () { initialize:function () {
this.clientList = new ClientCollection();
this.clientListView = new ClientListView({model:this.clientList});
this.startAfter([this.clientList]);
},
startAfter:function (collections) {
// Start history when required collections are loaded
var start = _.after(collections.length, _.once(function () {
Backbone.history.start()
}));
_.each(collections, function (collection) {
collection.bind('reset', start, Backbone.history)
});
}, },
list:function () { list:function () {
this.clientList = new ClientCollection();
this.clientListView = new ClientListView({model:this.clientList});
this.clientList.fetch();
$('#content').html(this.clientListView.render().el); $('#content').html(this.clientListView.render().el);
}, },
@ -255,7 +264,6 @@
$('body').append(templates); $('body').append(templates);
app = new AppRouter(); app = new AppRouter();
Backbone.history.start();
}); });

View File

@ -92,7 +92,7 @@
</span> </span>
<span class="control-group" id="registeredRedirectUri"> <span class="control-group" id="registeredRedirectUri">
<label>Redirect URL</label> <label>Redirect URL</label>
<input type="text" class="" placeholder="http://"><span class="help-inline">Associated help text!</span> <input type="text" class="" value="<%=registeredRedirectUri[0]%>" placeholder="http://"><span class="help-inline">Associated help text!</span>
</span> </span>
</div> </div>
<div class="span6"> <div class="span6">