'use strict';

var nevernoteBasePath = 'https://nevernote-1150.herokuapp.com/api/v1/',
    apiKey = '$2a$10$3UAODMts8D3bK8uqwe2mF.F39vZD3/CypYXLUk1yvhpedfbMiBaFW';

var noteApp = angular.module('notely.notes', ['ngRoute']);

noteApp.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/notes', {
    templateUrl: 'notes/notes.html'
  });
}]);

noteApp.controller('NotesController', ['$scope', 'NotesBackend', function($scope, NotesBackend) {
  var self = this;
  $scope.note = {};
  $scope.notes = [];

  self.assignNotes = function(notes) {
    $scope.notes = notes;
  };

  $scope.commit = function() {
    NotesBackend.postNote($scope.note, self.assignNotes);
  };

  $scope.hasNotes = function() {
    return $scope.notes.length > 0;
  };

  $scope.loadNote = function(note) {
    $scope.note = self.cloneNote(note);
  };

  NotesBackend.fetchNotes(self.assignNotes);
}]);

@@ -583,32 +583,307 @@
  = notes;%0A  %7D;%0A%0A
+  self.findNoteById = function(noteId) %7B%0A    for (var i = 0; i %3C $scope.notes.length; i++) %7B%0A      if ($scope.notes%5Bi%5D.id === noteId) %7B%0A        return $scope.notes%5Bi%5D;%0A      %7D%0A    %7D%0A  %7D;%0A%0A  self.cloneNote = function(note) %7B%0A    return JSON.parse(JSON.stringify(note));%0A  %7D;%0A%0A
   $scope.commit 

Load existing notes into the form.