Explorar el Código

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

David Leonard hace 10 años
padre
commit
bf4ffe180e
Se han modificado 2 ficheros con 47 adiciones y 0 borrados
  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/');
+});