Advertisement
Guest User

Untitled

a guest
Mar 13th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. var NotesApp = (function() {
  2. var App = {
  3. stores: {}, views: {}
  4. }
  5.  
  6. App.stores.notes = new Store('notes');
  7. // Note Model
  8. var Note = Backbone.Model.extend({
  9. //Local Storage
  10. localStorage: App.stores.notes,
  11.  
  12. initialize: function(){
  13. if(!this.get('title')){
  14. this.set({title: "Note at " + Date() })
  15. };
  16.  
  17. if(!this.get('body')){
  18. this.set({body: "No Body"})
  19. };
  20. }
  21.  
  22. })
  23.  
  24. //Views
  25. var NewFormView = Backbone.View.extend({
  26. events: {
  27. "submit form": "createNote"
  28. },
  29.  
  30. createNote: function(e){
  31. var attrs = this.getAttributes(),
  32. note = new Note();
  33.  
  34. note.set(attrs);
  35. note.save();
  36. },
  37.  
  38. getAttributes: function(){
  39. return {
  40. title: this.$('form [name=title]').val(),
  41. body: this.$('form [name=body]').val()
  42. }
  43. }
  44.  
  45. });
  46.  
  47. window.Note = Note;
  48.  
  49. $(document).ready(function(){
  50.  
  51. App.views.new_form = new NewFormView({
  52. el: $('#new')
  53. });
  54.  
  55. })
  56.  
  57.  
  58.  
  59.  
  60. return App
  61. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement