/*global angular*/
/* =========================================
--------------------------------------------

	Biage Public views
	"Keep watch over your Bitcoins"
	
   	(Leon Gaban @leongaban | Paulo Rocha @paulinhorocha)

--------------------------------------------
============================================ */

(function() { "use strict";

	var app = angular.module('bitAge',
		['ui.router',
		 'matchmedia-ng',
		 'app-about',
		 'app-login',
		 'app-register'])

	.config(['matchmediaProvider', function (matchmediaProvider) {
		matchmediaProvider.rules.desktop = "(max-width: 800px)";
	}])

	.config(['$stateProvider', '$urlRouterProvider',
		function($stateProvider, $urlRouterProvider) {

			$stateProvider
				.state('home', { url: '/home' })

				.state('about', {
					url: '/about',
					templateUrl: '_views/about.html',
					controller: 'AboutCtrl'
				})

				.state('login', {
					url: '/login',
					templateUrl: '_views/login.html',
					controller: 'LoginCtrl'
				})

				.state('register', {
					url: '/register',
					templateUrl: '_views/register.html',
					controller: 'RegisterCtrl'
				});

			$urlRouterProvider.otherwise('/home');
	}])

	.controller('MainCtrl', ['$scope', '$state', 'matchmedia',
		function($scope, $state, matchmedia) {

		var vm = $scope;

		vm.showHome = function() {
	    	return $state.is('home');
	   	}

	   	vm.showTicker = function() {
	    	return $state.is('home');
	   	}

		// Mobile nav
		vm.isMobileNavOpen = false;
		var unregister = matchmedia.onDesktop( function(mediaQueryList) {
			vm.isDesktop = mediaQueryList.matches;
			vm.isMobileNavOpen = false;
		});

		var postSignUpForm = function() {
            console.log(vm.formData);
            
            // process the form
            vm.processForm = function() {
                $http({
                    method  : 'POST',
                    url     : 'process.php',
                    data    : $.param(vm.formData),
                    headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
                })
                .success(function(data) {
                    console.log(data);

                    if (!data.success) {
                        console.log('display error on page');
                        alert('There was an error in getting response');
                      // if not successful, bind errors to error variables
                    } else {
                        console.log('success! time to login...');
                    }

                });
            };
		};

	   	// Quick form submit          
        vm.submitForm = function(isValid) {
            if (isValid) {
                // alert('our form is amazing');
                postSignUpForm();
            } else {
            	alert('Please correct the form');
            }
        };

	}]);

})();
@@ -1199,16 +1199,29 @@
 $scope',
+ '$location',
  '$state
@@ -1255,16 +1255,27 @@
 ($scope,
+ $location,
  $state,
@@ -1800,32 +1800,33 @@
  = function() %7B%0A
+%0A
                 
@@ -1825,35 +1825,148 @@
     
-    $http(%7B%0A               
+%09// make an API call%0A%09%09%09%09$http.post('$location/signup').then(function($.param(vm.formData)) %7B%0A%0A                // $http(%7B%0A                //
     
@@ -2000,20 +2000,23 @@
         
+//
     
+ 
 url     
@@ -2043,24 +2043,27 @@
             
+ //
      data   
@@ -2098,24 +2098,27 @@
             
+ //
      headers

update public