{"size": 2888, "ext": "js", "max_stars_repo_path": "resources/assets/js/components/want/want.component.js", "max_stars_repo_name": "LucasMessiasPG/poketrade", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "resources/assets/js/components/want/want.component.js", "max_issues_repo_name": "LucasMessiasPG/poketrade", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "resources/assets/js/components/want/want.component.js", "max_forks_repo_name": "LucasMessiasPG/poketrade", "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.5047619048, "max_line_length": 74, "alphanum_fraction": 0.4331717452}
(function(){
	"use strict";

	module.exports = angular.module("pokecard.want.module",[
		require('../../services/search.service'),
		require('../../services/user.service'),
        require('../../common/list/list.component'),
        require('../../directives/materialize'),

	])
		.component("pokeWant",{
		  template: /*@ngInject*/ function($templateCache){
		      return $templateCache.get("want/want.html");
		  },
		  controller: controller,
		  controllerAs: "want"
	   })
        .name;

	/*@ngInject*/
	function controller(SearchService,UserService,$scope, $location, $route){
		var want = this;
        want.send = send;
        want.have = have;
        want.opemHave = opemHave;
        want.addHave = addHave;


        init();

        //////////////

        function init(){
            want.user = UserService.user;
            want.url = '/api/card/wants';
            // SearchService.wants()
                // .then(function(response){
                    // want.list = response.data;
                // });
        }

        function send(item){
            UserService.sendWant(item.id_want)
                .then(function(response){
                    if(response.status == 'success') {
                        if(!want.filter)
                            want.filter = {};
                        want.filter.refresh = true;
                    }
                });
        }

        function have(status) {
            if(status)
                want.filter = {
                    have: 1
                };
            else
                want.filter = {};
        }


        function opemHave(card) {
            want.card_modal = card;
            $('#have').modal("open");
        }

        function addHave(card){
            var new_card = {
                id_card:card.card.id_card,
                amount:(card.amount)?card.amount:1,
                foil:(card.foil)?card.foil:false,
                reverse_foil:(card.reverse_foil)?card.reverse_foil:false,
                full_art:(card.full_art)?card.full_art:false
            };

            if(card.full_art) {
                new_card.foil = true;
                new_card.reverse_foil = true;
            }

            if(card.reverse_foil){
                new_card.foil = true;
            }

            UserService.addCard(new_card)
                .then(function(response){
                    if(response.status == 'success'){
                        $('#have').modal("close");
                        $route.reload();
                    }
                })
                .catch(function(response){
                    $('#have').modal("close");
                    if(response.status == 403){
                        $location.path("/login");
                    }else{
                        alert("ops !!!");
                    }
                });
        }

	}

})();