mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 15:07:13 +08:00
re-imagined toderp, first commit.
This commit is contained in:
69
example/toderp2/controllers.js
Normal file
69
example/toderp2/controllers.js
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
angular.module('ionic.todo.controllers', ['ionic.todo', 'firebase'])
|
||||||
|
|
||||||
|
// The main controller for the application
|
||||||
|
.controller('TodoCtrl', function($scope, $rootScope, AuthService) {
|
||||||
|
$rootScope.$on('angularFireAuth:login', function(evt, user) {
|
||||||
|
$scope.display.screen = 'tasks';
|
||||||
|
});
|
||||||
|
$rootScope.$on('angularFireAuth:logout', function(evt, user) {
|
||||||
|
console.log('Logged out!', evt, user);
|
||||||
|
$scope.display.screen = 'login';
|
||||||
|
});
|
||||||
|
$rootScope.$on('angularFireAuth:error', function(evt, err) {
|
||||||
|
console.log('Login Error!', evt, err);
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.setScreen = function(screen) {
|
||||||
|
$scope.display.screen = screen;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
// The login form controller
|
||||||
|
.controller('LoginCtrl', function($scope, AuthService) {
|
||||||
|
console.log('Created login Ctrl');
|
||||||
|
|
||||||
|
$scope.loginForm = {
|
||||||
|
email: 'max@drifty.com',
|
||||||
|
password: 'test'
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.tryLogin = function(data) {
|
||||||
|
$scope.loginError = false;
|
||||||
|
AuthService.login(data.email, data.password)
|
||||||
|
.then(function(e) {
|
||||||
|
$scope.loginError = false;
|
||||||
|
}, function(e) {
|
||||||
|
$scope.loginError = true;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.showSignup = function() {
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
// The signup form controller
|
||||||
|
.controller('SignupCtrl', function($scope, AuthService) {
|
||||||
|
$scope.signupForm = {};
|
||||||
|
|
||||||
|
$scope.trySignup = function(data) {
|
||||||
|
AuthService.signup(data.email, data.password);
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
// The tasks controller (main app controller)
|
||||||
|
.controller('TasksCtrl', function($scope, angularFire, FIREBASE_URL) {
|
||||||
|
var taskRef = new Firebase(FIREBASE_URL + '/todos');
|
||||||
|
$scope.todos = [];
|
||||||
|
angularFire(taskRef, $scope, 'todos');
|
||||||
|
$scope.addTask = function(task) {
|
||||||
|
var t = {};
|
||||||
|
t = angular.extend({
|
||||||
|
id: $scope.user.id
|
||||||
|
}, task);
|
||||||
|
|
||||||
|
console.log("Adding task:", t);
|
||||||
|
$scope.todos.push(t);
|
||||||
|
|
||||||
|
$scope.task = {};
|
||||||
|
};
|
||||||
|
});
|
||||||
75
example/toderp2/index.html
Normal file
75
example/toderp2/index.html
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<html ng-app="ionic.todo">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>ToDerp</title>
|
||||||
|
|
||||||
|
<!-- Sets initial viewport load and disables zooming -->
|
||||||
|
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||||
|
<link href="/vendor/font-awesome/css/font-awesome.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="../../dist/ionic.css">
|
||||||
|
<link rel="stylesheet" href="app.css">
|
||||||
|
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js"></script>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-mocks.js"></script>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-touch.js"></script>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-route.js"></script>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-animate.js"></script>
|
||||||
|
|
||||||
|
<script src='https://cdn.firebase.com/v0/firebase.js'></script>
|
||||||
|
<script src="https://cdn.firebase.com/v0/firebase-simple-login.js"></script>
|
||||||
|
<script src='https://cdn.firebase.com/libs/angularfire/0.3.0/angularfire.min.js'></script>
|
||||||
|
|
||||||
|
<script src="../../dist/ionic.js"></script>
|
||||||
|
<script src="../../dist/ionic-angular.js"></script>
|
||||||
|
|
||||||
|
<script src="js/app.js"></script>
|
||||||
|
<script src="js/services.js"></script>
|
||||||
|
<script src="js/controllers.js"></script>
|
||||||
|
<style>
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body ng-controller="TodoCtrl">
|
||||||
|
|
||||||
|
<!-- The root view controller -->
|
||||||
|
<nav-ctrl>
|
||||||
|
</nav-ctrl>
|
||||||
|
|
||||||
|
<!-- Splash -->
|
||||||
|
<script id="/splash.html" type="text/ng-template">
|
||||||
|
<div class="vc">
|
||||||
|
<h1>Toderp</h1>
|
||||||
|
</div>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Login -->
|
||||||
|
<script id="/login.html" type="text/ng-template">
|
||||||
|
<div></div>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Signup -->
|
||||||
|
<script id="/signup.html" type="text/ng-template">
|
||||||
|
<div></div>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Tasks -->
|
||||||
|
<script id="/tasks.html" type="text/ng-template">
|
||||||
|
<side-menu-ctrl>
|
||||||
|
<menu side="left">
|
||||||
|
<header>
|
||||||
|
<div class="toderp-logo"></div>
|
||||||
|
</header>
|
||||||
|
<content ng-controller="ProjectsCtrl">
|
||||||
|
<input type="text" ng-model="newProject.name">
|
||||||
|
<list>
|
||||||
|
<li class="list-item" ng-repeat="project in projects">
|
||||||
|
{{project.title}}
|
||||||
|
</li>
|
||||||
|
</list>
|
||||||
|
</content>
|
||||||
|
</menu>
|
||||||
|
<view>
|
||||||
|
</view>
|
||||||
|
</side-menu-ctrl>
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
4
example/toderp2/js/app.js
Normal file
4
example/toderp2/js/app.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
angular.module('ionic.todo', ['ionic.todo.services', 'ionic.todo.controllers', 'firebase', 'ngRoute', 'ngAnimate'])
|
||||||
|
|
||||||
|
// Our Firebase URL
|
||||||
|
.constant('FIREBASE_URL', 'https://ionic-todo-demo.firebaseio.com/');
|
||||||
73
example/toderp2/js/controllers.js
Normal file
73
example/toderp2/js/controllers.js
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
angular.module('ionic.todo.controllers', ['ionic.todo', 'firebase'])
|
||||||
|
|
||||||
|
// The main controller for the application
|
||||||
|
.controller('TodoCtrl', function($scope, $rootScope, AuthService) {
|
||||||
|
$scope.display = {
|
||||||
|
screen: 'splash'
|
||||||
|
};
|
||||||
|
$rootScope.$on('angularFireAuth:login', function(evt, user) {
|
||||||
|
$scope.display.screen = 'tasks';
|
||||||
|
});
|
||||||
|
$rootScope.$on('angularFireAuth:logout', function(evt, user) {
|
||||||
|
console.log('Logged out!', evt, user);
|
||||||
|
$scope.display.screen = 'login';
|
||||||
|
});
|
||||||
|
$rootScope.$on('angularFireAuth:error', function(evt, err) {
|
||||||
|
console.log('Login Error!', evt, err);
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.setScreen = function(screen) {
|
||||||
|
$scope.display.screen = screen;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
// The login form controller
|
||||||
|
.controller('LoginCtrl', function($scope, AuthService) {
|
||||||
|
console.log('Created login Ctrl');
|
||||||
|
|
||||||
|
$scope.loginForm = {
|
||||||
|
email: 'max@drifty.com',
|
||||||
|
password: 'test'
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.tryLogin = function(data) {
|
||||||
|
$scope.loginError = false;
|
||||||
|
AuthService.login(data.email, data.password)
|
||||||
|
.then(function(e) {
|
||||||
|
$scope.loginError = false;
|
||||||
|
}, function(e) {
|
||||||
|
$scope.loginError = true;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.showSignup = function() {
|
||||||
|
$scope.setScreen('signup');
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
// The signup form controller
|
||||||
|
.controller('SignupCtrl', function($scope, AuthService) {
|
||||||
|
$scope.signupForm = {};
|
||||||
|
|
||||||
|
$scope.trySignup = function(data) {
|
||||||
|
AuthService.signup(data.email, data.password);
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
// The tasks controller (main app controller)
|
||||||
|
.controller('TasksCtrl', function($scope, angularFire, FIREBASE_URL) {
|
||||||
|
var taskRef = new Firebase(FIREBASE_URL + '/todos');
|
||||||
|
$scope.todos = [];
|
||||||
|
angularFire(taskRef, $scope, 'todos');
|
||||||
|
$scope.addTask = function(task) {
|
||||||
|
var t = {};
|
||||||
|
t = angular.extend({
|
||||||
|
id: $scope.user.id
|
||||||
|
}, task);
|
||||||
|
|
||||||
|
console.log("Adding task:", t);
|
||||||
|
$scope.todos.push(t);
|
||||||
|
|
||||||
|
$scope.task = {};
|
||||||
|
};
|
||||||
|
});
|
||||||
46
example/toderp2/js/services.js
Normal file
46
example/toderp2/js/services.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
angular.module('ionic.todo.services', ['ionic.todo', 'firebase'])
|
||||||
|
|
||||||
|
// The AuthService handles user authentication with Firebase.
|
||||||
|
.factory('AuthService', function(angularFireAuth, $rootScope, FIREBASE_URL) {
|
||||||
|
|
||||||
|
// Initialize the angularFireAuth service.
|
||||||
|
var ref = new Firebase(FIREBASE_URL);
|
||||||
|
angularFireAuth.initialize(ref, {
|
||||||
|
scope: $rootScope,
|
||||||
|
callback: function(user, err) {
|
||||||
|
console.log('AUTH CHANGED', err, user);
|
||||||
|
},
|
||||||
|
name: 'user'
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
// Try to log in with the given email and pass
|
||||||
|
login: function(email, password) {
|
||||||
|
if(!email || !password) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('Logging in', email, password);
|
||||||
|
|
||||||
|
return angularFireAuth.login('password', {
|
||||||
|
email: email,
|
||||||
|
password: password
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// Try to sign up with the given email and pass
|
||||||
|
signup: function(email, password) {
|
||||||
|
if(!email || !password) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('Signing up', name, email, password);
|
||||||
|
|
||||||
|
angularFireAuth.createUser(email, password, function(err, user) {
|
||||||
|
if(err && err.code == "EMAIL_TAKEN") {
|
||||||
|
alert('That email is already taken');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
2
js/ext/angular/src/directive/ionicNav.js
vendored
2
js/ext/angular/src/directive/ionicNav.js
vendored
@ -32,7 +32,7 @@ angular.module('ionic.ui.nav', [])
|
|||||||
$scope.navController = this;
|
$scope.navController = this;
|
||||||
})
|
})
|
||||||
|
|
||||||
.directive('navController', function() {
|
.directive('navCtrl', function() {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
replace: true,
|
replace: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user