소스 검색

Adding controllers and services for getting Django RESTful endpoint, handling URL dispatch and passing data to templates

David Leonard 10 년 전
부모
커밋
bf4ffe180e
2개의 변경된 파일47개의 추가작업 그리고 0개의 파일을 삭제
  1. 42 0
      ionic/www/js/controllers.js
  2. 5 0
      ionic/www/js/services.js

+ 42 - 0
ionic/www/js/controllers.js

@@ -0,0 +1,42 @@
+angular.module('starter.controllers', ['starter.services'])
+
+.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
+  // Form data for the login modal
+  $scope.loginData = {};
+
+  // Create the login modal that we will use later
+  $ionicModal.fromTemplateUrl('templates/login.html', {
+    scope: $scope
+  }).then(function(modal) {
+    $scope.modal = modal;
+  });
+
+  // Triggered in the login modal to close it
+  $scope.closeLogin = function() {
+    $scope.modal.hide();
+  };
+
+  // Open the login modal
+  $scope.login = function() {
+    $scope.modal.show();
+  };
+
+  // Perform the login action when the user submits the login form
+  $scope.doLogin = function() {
+    console.log('Doing login', $scope.loginData);
+
+    // Simulate a login delay. Remove this and replace with your login
+    // code if using a login system
+    $timeout(function() {
+      $scope.closeLogin();
+    }, 1000);
+  };
+})
+
+.controller('SessionsCtrl', function($scope, Session) {
+    $scope.sessions = Session.query();
+})
+
+.controller('SessionCtrl', function($scope, $stateParams, Session) {
+    $scope.session = Session.get({sessionId: $stateParams.sessionId});
+});

+ 5 - 0
ionic/www/js/services.js

@@ -0,0 +1,5 @@
+angular.module('starter.services', ['ngResource'])
+
+.factory('Session', function ($resource) {
+    return $resource('http://127.0.0.1:8000/hackathon/snippets/');
+});