HEX
Server: Apache
System: Linux v38079.2is.nl 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: democfellows (10015)
PHP: 8.1.34
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/creativefellows.nl/bestelscan.creativefellows.nl/public/js/app.js
$(document).foundation().ready(function(){

	$(".duplicate-rows").duplicateSupplierRow();
	
	$("[data-bestelscan]").bestelScan();
});


$.fn.bestelScan = function(){
	
	//<input type="text" class="form-text" id="supplier1_name" name="supplier1_name" autocomplete="off" placeholder="Naam leverancier 1" value="" required="" data-copy="&quot;supplier1&quot;">
	return this.each(function(){

		let plugin 	= $(this);
		let $copy 	= plugin.find("[data-copy]");
		
		let $toggle = plugin.find(".toggle-groups");
		let $select = plugin.find(".select-supplier-goods select");
		let $other 	= plugin.find(".cell__goods-other");
		
		let $types = plugin.find("#customer_suppliers select");
		
		plugin.init = function()
		{	
			$copy.keyup(plugin.copy);
			$toggle.click(plugin.toggle);
			$select.change(plugin.isDifferent)
			
		
			$types.change(function(){
				
				let selected = [];
				
				$types.each(function(){
					selected.push( parseInt($(this).val()) );
				});

				let unique = selected.filter(plugin.onlyUnique);
				
				
				$("#supplier-check").addClass("hide").find("span").html("");
				
				let count = 0;
				
				if(!unique.includes(2)){
					$("#supplier-check").removeClass("hide").find("span").append("<strong>facilitair</strong>");
					count++;
				}

				if(!unique.includes(3)){
					if(count >= 1) $("#supplier-check").removeClass("hide").find("span").append(", ");
					$("#supplier-check").removeClass("hide").find("span").append("<strong>bedrijfsgoederen</strong>");
					count++;
				}
				
				if(!unique.includes(4)){
					if(count >= 1) $("#supplier-check").removeClass("hide").find("span").append(", ");
					$("#supplier-check").removeClass("hide").find("span").append("<strong>afval</strong>");
					count++;
				} 

			});
			
			
		}
		plugin.onlyUnique = function(value, index, array){
		  return array.indexOf(value) === index;
		}
		
		plugin.isDifferent = function(){
			let val = $(this).val();
			let next = $(this).closest(".cell").next()
			
			if(val == 6) next.removeClass("cell__hidden");
			else next.addClass("cell__hidden").val("");
		}

		plugin.copy = function()
		{	
			let val = $(this).val();
			$("#"+ $(this).data("copy")+" [data-group-label]").text(val);
		}	
		
		plugin.toggle = function()
		{	
			
			$( $(this).data("show") ).removeClass("form-group__hidden");
			$( $(this).data("hide") ).addClass("form-group__hidden");

		}		
		
	
	    plugin.init();	
		
	});
	
}



$.fn.duplicateSupplierRow = function(){
	
	return this.each(function(){

		var plugin 	= $(this);
		var $group	= plugin.closest(".form-group");
		var $row 	= plugin.closest(".form-group-row");
		
		var $fields = $(this).closest(".form").find(".form-group__supplier-fields");
		
	//	var count 	= plugin.data("counter");

		//var $button = $row.find("button");
		//var $form 	= $("#page-main-form");
		
		var $clone;
		
		
		plugin.init = function()
		{	
			plugin.click(plugin.duplicate);
		}	
		
		
		plugin.duplicate = function()
		{		
			// clone
			$clone = $row.clone();
			$clone.find(".duplicate-rows").duplicateSupplierRow();				
			$clone.find("input").val();
							
			$group.append( $clone );
			// change button into 'minus'
			$row.find(".duplicate-rows").text("-");

			// click off
			plugin.off("click");
			plugin.click("click",plugin.delete);
			
			$supplier_fields = $fields.clone();
			$supplier_fields.insertAfter($fields);

			
		}	
		
		plugin.delete = function()
		{
			$row.remove();
		}
			
	    plugin.init();	
		
	});
	
}