vanilla.namespace('campagnepublique.panier');

campagnepublique.panier.deamon =
{
    init : function(properties)
    {
	this.properties = properties;
	this.view = $("#view-" + properties.viewId);
    },

    manageVisuel : function(visuelId, action, success, error, complete)
    {
	var self = this;

	$.ajax
	(
	    {
		type	    : "post", 
		url	    : this.properties.libraryURL + "campagnepublique/plugin/panier/ajax_visuel.php",
		data	    : {action:action, id:visuelId},

		success : function(json)
		{
		    var div = self.view.find("div.button");
		    div.find("span.nb").text(json.nbLignes);

		    success(json, div);
		},

		error : error,
		complete : complete
	    }
	);
    },

    removeLigne : function(ligneId, success, error, complete)
    {
	var self = this;

	$.ajax
	(
	    {
		type	    : "post", 
		url	    : this.properties.libraryURL + "campagnepublique/plugin/panier/ajax_ligne.php",
		data	    : {id:ligneId},

		success : function(json)
		{
		    var div = self.view.find("div.button");
		    div.find("span.nb").text(json.nbLignes);

		    success(json, div);
		},

		error : error,
		complete : complete
	    }
	);
    }
}

