Sha256: 228c0b00223703286762857b223c83f8209f71bb91a821e326b9b54cb0c76b72

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

angular.module('voxality').controller('AdminUserController', [
    '$scope',
    '$http',
    '$window',
    function(
      $scope,
      $http,
      $window) {
        $scope.displayUser = function(user) {
          return user.detail.first_name + ' ' + user.detail.last_name + '(' + user.email + ')'
        };

        $scope.searchUsers = function(text) {
          var protocol = $window.location.protocol;
          var host = $window.location.host;
          var token = $window.Voxality.API.getToken();
          var url = protocol + '//' + host + '/api/admin/users/search';
          var params = { api_token: token, query: text };

          var onSuccess = function(response) {
            $scope.resultUsers = response.data.data;
          };
          var onFailure = function(response) {
            alert(response.data.type + '\n' + response.data.exception);
          };

          $http.get(url, { params: params }).then(onSuccess, onFailure);
        };

        $scope.addFunds = function(amount) {
          $scope.fundsLoading = true;
          var protocol = $window.location.protocol;
          var host = $window.location.host;
          var token = $window.Voxality.API.getToken();
          var url = protocol + '//' + host + '/api/admin/users/' + $scope.selectedUser.id + '/balance/deposit';
          var params = { api_token: token, amount: amount };

          var onSuccess = function(response) {
            $scope.fundsAmount = null;
            $scope.topupForm.$setPristine();
            $scope.topupForm.$setUntouched();
            $scope.fundsLoading = false;
          };
          var onFailure = function(response) {
            alert(response.data.type + '\n' + response.data.exception);
          };

          $http.post(url, params).then(onSuccess, onFailure);
        };
      }
]);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
voxality_core-0.1.0.1 lib/generators/voxality_core/templates/app/assets/javascripts/controllers/AdminUserController.js