Permalink
Browse files

Merge branch 'master' of github.com:jcreamer898/BackboneCoffeeWebApi

  • Loading branch information...
jcreamer898 committed Apr 2, 2012
2 parents cd59c67 + 0024e0c commit c1271376b61db4580bf8a230f709a84c5a2e6e56
Showing with 40 additions and 16 deletions.
  1. +18 −9 CustomerManager/Scripts/app.coffee
  2. +21 −6 CustomerManager/Scripts/app.js
  3. +1 −1 CustomerManager/Views/Home/Index.cshtml
@@ -55,7 +55,8 @@ class CustomerEdit extends Backbone.View
html = @template data
@$el.html(html).show()
.find('#first').focus()
-
+
+ @model.on 'error', @showError
return this;
save: (event) =>
@model.set
@@ -65,23 +66,31 @@ class CustomerEdit extends Backbone.View
'Phone': @$el.find('#phone').val()
'Birthday': @$el.find('#birthday').val()
'Description': @$el.find('#description').val()
-
- window.customers.add @model unless !@model.isNew()
- $('.alert').fadeIn()
-
- @model.save
- wait: true
- @$el.hide()
+ if @model.isValid()
+ $('.alert').fadeOut()
+ window.customers.add @model unless !@model.isNew()
+ @model.save
+ wait: true
+ @$el.hide()
cancel: =>
@$el.hide()
-
+ showError: (model, error) =>
+ $('.alert').html(error).fadeIn('fast');
+
class Vent extends Backbone.Events
window.Vent = Vent
class Customer extends Backbone.Model
urlRoot: '/api/customers/'
idAttribute: 'Id'
+ validate: (attr) =>
+ if !attr.FirstName
+ return "First Name is required"
+ if !attr.LastName
+ return "Last Name is required"
+ if !attr.Email
+ return "Email Address is required"
class Customers extends Backbone.Collection
url: '/api/customers/'

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -51,5 +51,5 @@
<td colspan="2">
<a href="#edit" class="edit" data-id="{{Id}}"><i class="icon-pencil"></i></a>
<a href="#remove" class="remove" data-id="{{Id}}"><i class="icon-remove"></i></a>
- </td>0101
+ </td>
</script>

0 comments on commit c127137

Please sign in to comment.