Skip to content

Instantly share code, notes, and snippets.

@ayax79
Created April 12, 2012 17:03
Show Gist options
  • Select an option

  • Save ayax79/2369171 to your computer and use it in GitHub Desktop.

Select an option

Save ayax79/2369171 to your computer and use it in GitHub Desktop.
var Role = Backbone.Model.extend({
urlRoot: '/roles/rest/roles',
validate: function(atts) {
var errors = [];
if (!atts.name || atts.name === '') {
errors.push({field:'name', message: 'Name is required.'});
}
if (!atts.userGroups || atts.userGroups.length < 1) {
errors.push({field:'userGroups', message: 'No Users or Groups have been selected.'});
}
if (!atts.permissions || atts.permissions.length < 1) {
errors.push({field:'permissions', message: 'No Permissions have been selected.'});
}
if (errors.length > 0) {
return errors;
}
}
});
var role = new Role({id: 1});
role.save({
name: 'foo',
userGroups: [{id: 1}]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment