(function() {
    var app = angular.module("moviequotes", [ "ui.bootstrap", "modal-controllers", "firebase" ]);

    app.controller("MoviequotesCtrl", function($modal, $firebaseArray) {
        this.navbarCollapsed = true;
        var _this = this;
        //Done: Bind data to Firebase
        var moviequotesRef = new Firebase("https://fisherds-auth-movie-quotes.firebaseio.com/quotes");
        this.items = $firebaseArray(moviequotesRef);

        var compare = function(a, b) {
            return a.$id < b.$id;
        }
        this.items.$watch(function() { _this.items.sort(compare); });

        this.showAddQuoteDialog = function(movieQuoteFromRow) {
            this.navbarCollapsed = true;
            var modalInstance = $modal.open({
                templateUrl : "/partials/addQuoteModal.html",
                controller : "AddQuoteModalCtrl",
                controllerAs : "insertModal"
            });
            modalInstance.result.then(function(movieQuoteFromModal) {
                //Done: Add movieQuote to Firebase
                _this.items.$add(movieQuoteFromModal);
                _this.isEditing = false;
            });
        };

        this.showUpdateQuoteDialog = function(movieQuoteFromRow) {
            this.navbarCollapsed = true;
            var modalInstance = $modal.open({
                templateUrl : "/partials/updateQuoteModal.html",
                controller : "UpdateQuoteModalCtrl",
                controllerAs : "insertModal",
                resolve : {
                    movieQuote : function() {
                        return {
                            get :
                            function() {
                                return movieQuoteFromRow;
                            },
                            save :
                            function(movieQuoteFromModal) {
                                //Done: save movieQuote to Firebase
                                _this.items.$save(movieQuoteFromModal);
                            }
                        };
                    }
                }
            });

            modalInstance.result.then(function() {
                _this.isEditing = false;
            });
        };

        this.showDeleteQuoteDialog = function(movieQuoteFromRow) {
            var modalInstance = $modal.open({
                templateUrl : "/partials/deleteQuoteModal.html",
                controller : "DeleteQuoteModalCtrl",
                controllerAs : "deleteModal",
                resolve : {
                    movieQuoteInModal : function() {
                        return movieQuoteFromRow;
                    }
                }
            });
            modalInstance.result.then(function(movieQuoteFromModal) {
                //Done: Delete the moviequote from Firebase
                _this.items.$remove(movieQuoteFromModal);
                _this.isEditing = false;
            });
        };
    });
})();

@@ -383,16 +383,17 @@
 otes%22);%0A
+%0A
         
@@ -609,58 +609,876 @@
 his.
-showAddQuoteDialog = function(movieQuoteFromRow) %7B
+authDataCallback = function(authData) %7B%0A            if (authData) %7B%0A                console.log(%22User %22 + authData.uid + %22 is logged in with %22 + authData.provider);%0A                this.uid = authData.uid;%0A            %7D else %7B%0A                console.log(%22User is logged out%22);%0A            %7D%0A        %7D;%0A        moviequotesRef.onAuth(this.authDataCallback);%0A%0A        this.authHandler = function(error, authData) %7B%0A          if (error) %7B%0A            console.log(%22Login Failed!%22, error);%0A          %7D else %7B%0A            console.log(%22Authenticated successfully with payload:%22, authData);%0A          %7D%0A      %7D;%0A%0A        this.showAddQuoteDialog = function(movieQuoteFromRow) %7B%0A%0A            console.log(%22Fake login%22);%0A            moviequotesRef.authWithPassword(%7B%0A              email    : 'matt@boutell.com',%0A              password : 'boutell'%0A          %7D, this.authHandler);%0A%0A
 %0A   
@@ -1847,32 +1847,131 @@
 ote to Firebase%0A
+                console.log(%22Adding the uid%22);%0A                movieQuoteFromModal.uid = this.uid;%0A
                 

add a quote from the web client in a hacky way