PuppetsController.js 996 Bytes
angular.module('footyroom')

    .controller('PuppetsController', ['$http', function ($http) {
        const ctrl = this;
        var offset = 0;

        ctrl.loadMore = loadMore;
        ctrl.searchAccounts = searchAccounts;
        ctrl.getAccounts = getAccounts;

        getAccounts();

        function getAccounts() {
            $http.get('/puppets.json', {
                params: {
                    offset: offset,
                    username: ctrl.username,
                },
            })
                .success(function (response) {
                    if (offset > 0) {
                        ctrl.accounts = ctrl.accounts.concat(response);
                    } else {
                        ctrl.accounts = response;
                    }
                });
        }

        function loadMore() {
            offset += 20;
            getAccounts();
        }

        function searchAccounts() {
            offset = 0;
            getAccounts();
        }
    }]);