{"size": 1648, "ext": "js", "max_stars_repo_path": "app/yitao/scripts/ProductsController.js", "max_stars_repo_name": "xxn520/yitao-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/yitao/scripts/ProductsController.js", "max_issues_repo_name": "xxn520/yitao-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/yitao/scripts/ProductsController.js", "max_forks_repo_name": "xxn520/yitao-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.9322033898, "max_line_length": 80, "alphanum_fraction": 0.4563106796}
/**
 * Created by m2mbob on 16/5/16.
 */
angular.module("yitao").controller(
    "ProductsController", function($scope, supersonic, Restangular, BaseUrl) {

        var nowPage = 0, id = 0;
        $scope.categories = [];
        $scope.BaseUrl = BaseUrl;

        var resetList = function() {
            $scope.items = [];
            $scope.total = 0;
            $scope.loading = true;
            nowPage = 0;
        };

        resetList();

        var showCategory = function(cateid) {
            Restangular.one("category", cateid).get().then(function(category){
                $scope.category = category;
            }, function(err){
                supersonic.logger.log(err);
            });
        };

        var stop = supersonic.ui.views.current.params.onValue(function(params) {
            id = params.id;
            showCategory(id);
        });

        stop();

        $scope.getItems = function(inview) {
            if (!inview) {
                return;
            }
            Restangular.all("product").getList({
                cid: id,
                page: nowPage++,
                "page-size": 6
            }).then(
                function(data) {
                    $scope.items = data.meta.first ? data
                        : $scope.items.concat(data);
                    $scope.loading = !data.meta.last;
                    $scope.total = data.meta.total_elements;
                }, function(response) {
                    //TODO 这里是加载不成功
                });
        };

        $scope.toDetail = function(id) {
            supersonic.ui.layers.push("yitao#detail?id="+ id);
        }

    });
