Your IP : 216.73.216.164


Current Path : /var/www/html/anwc/wp-content/plugins/eea-pricing/scripts/
Upload File :
Current File : /var/www/html/anwc/wp-content/plugins/eea-pricing/scripts/admin-js.js

jQuery(document).ready(function(){
	
	price = ssa_price_ds.price;
	type  = ssa_price_ds.type;
	//console.log(price);
	//console.log(type);
	append = '';
	input ='';
	if(price !== null && typeof price != 'undefined' && price!='' ) 
	{
		for(i=0;i<price.length;i++)
		{
			desc = price[i].OPT_DESC;
			pr = price[i].OPT_PRICE;
			qid = price[i].id;
			input += "<div class='option_div' >";
			input += "<input type='hidden' class='que-opt' value='"+qid+"'>";
			input += "<input type='text' class='question_desc' name='question_text[]' value='"+desc+"' placeholder='Option Description'>";
			input += "<input type='text' class='question_price' name='question_price[]' value='"+pr+"' placeholder='Option Value'> ";
			if(i==0)
			{
				input += "<input type='button' class='add_option'  value='+'> ";
			}
			else
			{
				input += "<input type='button' class='remove_option'  value='-'> ";
			}
			input += "</div>";
		}
	}
	else
	{
		input = "<div class='option_div'>";
		input += "<input type='hidden' class='que-opt' value=''>";
		input += "<input type='text' class='question_desc' name='question_text[]' value='' placeholder='Option Description'>";
		input += "<input type='text' class='question_price' name='question_price[]' value='"+price+"' placeholder='Option Value'> ";
		input += "<input type='button' class='add_option'  value='+'> </div>";
	}

	second = "<div class='option_div'>";
	second += "<input type='text' class='question_desc' name='question_text[]' value='' placeholder='Option Description'>";
	second += "<input type='text' class='question_price' name='question_price[]' value='' placeholder='Option Value'> ";
	//second += "<input type='button' class='add_option'  value='+'>";
	second += "<input type='button' class='remove_option'  value='-'> </div>";
	str ="<tr class='ssa_price' style='display:none'><th>Price Options</th>";
	str +="<td>"+input;
	str += "<input type='hidden' class='ssa_removed_input' name='removed_opts'>";
	str += "<input type='hidden' class='ssa_pricing_input' name='pricing_opts'>";
	str += "</td></tr>";

	str1 ="<tr class='ssa_price_type' style='display:none'><th>Display As </th>";
	str1 +="<td><span> <input type='radio' name='pricing_type' value='radio'> Radio Buttons</span>";
	str1 +=" <br><br><span> <input type='radio' name='pricing_type' value='checkbox'> Checkboxes</span>";
	str1 +=" </tr>";
	var chk ='';
	if(ssa_price_ds.tax == 1)
		chk='checked';
	str2 ="<tr class='ssa_price_type' style='display:none'><th>This question is taxable </th>";
	str2 +="<td><span> <input type='checkbox' name='pricing_taxable' value='1' "+chk+"></span>";
	str2 +=" </tr>";
	
	if(jQuery('#update_question_event_form').length > 0 || jQuery('#insert_question_event_form').length > 0 )
    {

		ele = jQuery('table:first');
		ele.append(str1);
		ele.append(str);
		ele.append(str2);
		jQuery('#QST_type').change(function(){
			selected_val = jQuery(this).val();
			
			if(selected_val == 'pricing')
			{
				jQuery('.ssa_price_type').show();
				jQuery('.ssa_price').show();
				jQuery("input[type='radio'][value='"+type+"']").attr('checked','checked');
			}
			else
			{
				jQuery('.ssa_price_type').hide();
				jQuery('.ssa_price').hide();
			}
		});
		if(price != '' && jQuery('#QST_type').val() =='pricing')
		{
			jQuery('.ssa_price_type').show();
			jQuery('.ssa_price').show();
			jQuery("input[type='radio'][value='"+type+"']").attr('checked','checked');
		}
	}
	jQuery('.form-table').on('click','.add_option',function(){
		console.log('here');
		jQuery('.ssa_price td').append(second);
	});
	jQuery('.form-table').on('click','.remove_option',function(){
		r = confirm('Do you really want to remove this option?');
		ele = jQuery(this);
		if(r == true)
		{
			id = jQuery(this).siblings('.que-opt').val();
			input = jQuery('.ssa_removed_input').val();
			ins = new Array();
			if(input != '')
				ins = input.split();
			ins.push(id);
			data = ins.join();
			jQuery('.ssa_removed_input').val(data);
			ele.parent('.option_div').remove();	
				
		}
		
	});
	jQuery('#update_question_event_form,#insert_question_event_form').submit(function()
	{
		
		if(jQuery('#QST_type').val() == 'pricing')
		{
			error_flag = '';
			var optArray = {}; 
			i = 50001;
			jQuery('.option_div').each(function()
			{
				qid = jQuery(this).find('.que-opt').val();
				desc = jQuery(this).find('.question_desc').val();
				pr = jQuery(this).find('.question_price').val();
				if(pr == '' || desc == '')
					error_flag = 1;
				console.log(qid+ '|'+desc +'|'+pr);
				if(qid == '' || typeof qid == 'undefined')
					{
						qid = i;
						i++;
					}
				optArray[qid] = desc + '|' + pr;
			});
			len = jQuery('input[name="pricing_type"]:checked').length;
			if(len <1)
			{
				alert("Please choose one of the option from Radio button and Checkboxes");
				return false;
			}
			else if(error_flag == 1)
			{
				alert("Please enter price and description for all price options");
				return false;	
			}
			else
			{	

				str = JSON.stringify(optArray);
				console.log(str);
				jQuery('.ssa_pricing_input').val(str);
			}

		
		//return false;
	}

	});

});