Sha256: 8ae9d52648721934876dee5ccd04343b749e145a412cafe0bc149ebed694fcfa

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

'use strict';

function ApiController($scope, $http, $location) {
  $scope.goTo = function(path) {
    $location.path(path)
  }

  $scope.post = function() {
    var formData = {};
    $scope.collection.template.data.forEach(function(f){ formData[f.name] = f.value })
    $http.post($scope.collection.href, formData).success(successHandler)
  }

  $scope.$watch(function() {
    return $location.path()
  }, function(path, oldPath) {
    if(path !== oldPath) get(path)
  });

  get('/api')

  // helpers

  function get(path) {
    $http.get(path).success(successHandler)
  }

  function successHandler(data, status) {
    $scope.collection = data.collection;
    $scope.raw = JSON.stringify(data, undefined, 2)
    $scope.status = status

    $location.path($scope.collection.href)
  }
}


ApiController.$inject = ['$scope', '$http', '$location'];

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
collection-json-browser-0.0.2 app/assets/javascripts/collection_json_browser/angular/controllers/api_controller.js
collection-json-browser-0.0.1 app/assets/javascripts/collection_json_browser/angular/controllers/api_controller.js