%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/bitrix/www/local/components/p4/p.castings.edit/templates/job/
Upload File :
Create Path :
Current File : //home/bitrix/www/local/components/p4/p.castings.edit/templates/job/script.js

function setCurrency(s) {
	$('input[name="CASTING_PROPS[COMPENSATION_CURRENCY]"]').attr('value',s.attr('data-currency'));
	$('#label_curency').html(s.html()+'&nbsp;<span class="caret"></span>');
}

BX.ready(function(){
	
	var new_image = '';
	modelID = 7; // Модели



	$('#DATE_FROM').datetimepicker(datetimepickerParams);
	$('#JOB_DATE').datetimepicker(datetimepickerParams);
	$('#DATE_FROM').val("");
	$('#JOB_DATE').val("");

	$('#image-cropper').cropit({ imageBackground: true, width:650, height:450 });

	$('#select-image-btn').click(function() {
	  $('.cropit-image-input').click();
	});

	$('#save-image-btn').click(function() { // Сохранение изображения в поле формы
		// закрываем окно
		$('#imageloader').modal('hide'); 
		// загружаем картинку в форму
		new_image = $('#image-cropper').cropit('export',{type:'image/jpeg',quality:.9,originalSize:false}); 
		$('#new_image_preview > div').html('<img src="'+new_image+'" width="140" height="97" />');
		$('#confirm-submit-body .portfolio-item > div').html('<img src="'+new_image+'" width="140" height="97" />');
		$('#new_image_content').attr('value',new_image);
	});

	function showErrorAlert(s) {
		$('#alert-danger > span').html(s);
		$('#alert-danger').show();
	}
	$('input[name="CASTING_PROPS[COMPENSATION]"]').bind("change keyup input click", function() {
		if (this.value.match(/[^0-9]/g)) {
			this.value = this.value.replace(/[^0-9]/g, '');
		}
	});
	// Отображение превью и ошибок (если есть)
	$('#confirm-buttom-submit').click(function(){

		// Проверка обязательных полей
		errorMsg = '';
		if (!$('input#new_image_content').val())
			errorMsg += LA_MESS["IMAGE_IS_NOT_SPECIFIED"];
		if (!$('select[name="CASTING_PROPS[CITY]"]').val())
			errorMsg += LA_MESS["THE_CITY_IS_NOT_SPECIFIED"];
		if ($('input[name="CASTING_PROPS[JOB_DATE]"]').val()=="" | $('input[name="CASTING_PROPS[JOB_DATE]"]').val()=="__.__.____" | $('input[name="CASTING_PROPS[JOB_DATE]"]').val()=="__/__/____")
			errorMsg += LA_MESS["JOB_DATE_IS_NOT_SPECIFIED"];	
		if (!$('select#sel_section').val())
			errorMsg += LA_MESS["AD_CATEGORY_IS_NOT_SELECTED"];
		if ($('#sel_public_date_chosen .chosen-single span').hasClass("discolor"))
			errorMsg += LA_MESS["PUBL_TIME_IS_NOT_SPECIFIED"];
		if ($('input#cb_tfp:checked').val()!='Y' && $('input[name="CASTING_PROPS[COMPENSATION]"]').val().length==0)
			errorMsg += LA_MESS["COMPENSATION_SUM_IS_NOT_SPECIFIED"];
		if ($('input[name="CASTING[NAME]"]').val().length<3)
			errorMsg += LA_MESS["AD_TITLE_IS_NOT_SPECIFIED"];
		if ($('textarea[name="CASTING_PROPS[CASTING_TEXT]"]').val().length<10)
			errorMsg += LA_MESS["AD_TEXT_IS_NOT_SPECIFIED"];
		if ($('input[name="CASTING_PROPS[CONTACT_NAME]"]').val().length<3)
			errorMsg += LA_MESS["CONTACT_NAME_IS_NOT_SPECIFIED"];
		if ($('input[name="CASTING_PROPS[CONTACT_EMAIL]"]').val().length<3)
			errorMsg += LA_MESS["CONTACT_EMAIL_IS_NOT_SPECIFIED"];
		
		if (!$('input[name="CASTING_PROPS[SEX][]"]').is(':checked'))
			errorMsg += LA_MESS["SEX_IS_NOT_SPECIFIED"];

		if (errorMsg.length>0) {
			showErrorAlert(errorMsg);
			return false;
		}
		
		$('#alert-danger').hide();

		// Формирование превью
		$('div#confirm-submit-body ul > li > span').html('');
				
	  $('form#casting-form').find('input[type="text"],textarea').each(function() {
		  value = $(this).val().length>0?$(this).val():'-';
		  $('div#confirm-submit-body ul > li > span[data-id="'+$(this).attr('name')+'"]').html(value.replace(/([^])\n/g,'$1<br/>'));
	  });
	  
	  $('form#casting-form').find('select > option:selected').each(function() {		  
		  value = $(this).text().length>0?$(this).text():'-';
		  old_value = $('div#confirm-submit-body ul > li > span[data-id="'+$(this).parent().attr('name')+'"]').html();
		  if (old_value.length>0) value = old_value+', '+value;
		  $('div#confirm-submit-body ul > li > span[data-id="'+$(this).parent().attr('name')+'"]').html(value);
	  });
	  
	  $('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[CITY]"]').html(
			$('#CASTING_CITY_chosen .chosen-single span').text()
	  );

		$('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION_CURRENCY]"]').html(
		  $('a.sel_curency[data-currency="'+$('input[name="CASTING_PROPS[COMPENSATION_CURRENCY]"]').val()+'"]').html()
		);
	  
		  var lengcheck = $("input.sel_sex:checked").length;
		 var sex = $("input.sel_sex:checked:eq(0)").data('value');
		  if (lengcheck > 1){			
				  sex += " " + $("input.sel_sex:checked:eq(1)").data('value');
		  };  
				  $('#model-more').html(
						(sex===undefined?'':LA_MESS["SEX_JS"]+sex)+
					($("input#sel_nudity").prop('checked')?LA_MESS["NUDE_JS"]:'')
			  );

	  $('input#cb_tfp:checked').each(function(){
		  $('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION]"]').html('TFP');
		  $('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION_CURRENCY]"]').html('');
		  $('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION_TYPE]"]').html('');
	  });

	  $('#confirm-submit').modal('show');
	  
	});
		$("#sex_div a").click(function(){
			var checkbox_sex = $(this).parents("#sex_div").find(".sel_sex[value='"+$(this).attr("data-id")+"']");
			$(this).toggleClass("sel_cast_btn");
			if (checkbox_sex.prop("checked")){
				checkbox_sex.prop("checked", false);			
			}
			else {
				checkbox_sex.prop("checked", true);
			}
			
		}		
		);
		$("#nudity199").click(function(){
			$(this).toggleClass("sel_cast_btn");
			if ($("#sel_nudity").prop("checked")){
				$("#sel_nudity").prop("checked", false);			
			}
			else {
				$("#sel_nudity").prop("checked", true);
			}
			
		}		
		);
		$("#tfp1").click(function(){
			if (!$('#cb_tfp').prop('disabled')){
			$(this).toggleClass("sel_cast_btn");
			if ($("#cb_tfp").prop("checked")){
				$("#cb_tfp").prop("checked", false);			
			}
			else {
				$("#cb_tfp").prop("checked", true);
			}
			$('#cb_tfp').change();
			};
		}		
		);
	$('input.sel_sex').change(function(){
		state = $(this).prop('checked');
		$('input.sel_sex').each(function(){
			/*$(this).prop('checked',false);*/
		});
		$(this).prop('checked',state);
	});

	$('#cb_tfp').change(function(){
		if ($('#cb_tfp').prop('checked')) {
			$('input[name="CASTING_PROPS[COMPENSATION]"]').attr('value',0);
			$('input[name="CASTING_PROPS[COMPENSATION]"]').prop('disabled',true);
			$('#label_curency').prop('disabled',true);
			$('select#sel_comp_type').prop('disabled',true);
			$('select#sel_comp_type').trigger('chosen:updated');
		}
		else {
			$('input[name="CASTING_PROPS[COMPENSATION]"]').prop('disabled',false);
			$('#label_curency').prop('disabled',false);
			$('select#sel_comp_type').prop('disabled',false);
			$('select#sel_comp_type').trigger('chosen:updated');
		}
	});
	$('#sel_comp_type').change(function(){
		if ($('select#sel_comp_type').val() == 392 || $('select#sel_comp_type').val() == 452) {
			$('input[name="CASTING_PROPS[COMPENSATION]"]').attr('value',0);
			$('input[name="CASTING_PROPS[COMPENSATION]"]').prop('disabled',true);
			$('#label_curency').prop('disabled',true);
			$('#cb_tfp').prop('disabled',true);
			$('#tfp1').attr('disabled',true);
			$('select#sel_comp_type').trigger('chosen:updated');
		}
		else {
			$('input[name="CASTING_PROPS[COMPENSATION]"]').prop('disabled',false);
			$('#label_curency').prop('disabled',false);
			$('#cb_tfp').prop('disabled',false);
			$('#tfp1').attr('disabled',false);
			$('select#sel_comp_type').trigger('chosen:updated');
		}
	});
	$('#cb_tfp').trigger('change');


	$('#post-offer-btn').click(function(){
		$(this).prop("disabled", true);
		$('#casting-form').submit();
	});

	$('form.register-page').find('select').each(function() {
		$(this).chosen({disable_search_threshold: ($(this).attr('id')=='CASTING_CITY')?0:10, max_selected_options: 3});
	});

	/*$('select#sel_section').chosen().change(function (){
		if ($('select#sel_section > option:selected').attr('value')==modelID)
			$('div.casting-model').show();
		else
			$('div.casting-model').hide();
	});*/

	
	$('#START_DATE').datetimepicker(datetimepickerParams);

	$('a.sel_curency').click(function(){		
		setCurrency($(this));
	});

	if ($('input[name="CASTING_PROPS[COMPENSATION_CURRENCY]"]').val().length==0) {
		$("a.sel_curency:first").each(function(){
			setCurrency($(this));
		});
	}
	else {
		$('a.sel_curency[data-currency="'+$('input[name="CASTING_PROPS[COMPENSATION_CURRENCY]"]').attr('value')+'"]').click();	
	}
			
	$('select#CASTING_CITY').ajaxChosen(
		{
	    type: 'GET',
	    url: 'load_ref.php',
	    dataType: 'json'
		},
		function (data) {
			return data;
		}
	);
	
	//$("select#sel_section").trigger('change');

	addRegionToCity = function() {
		$('#CASTING_CITY_chosen .chosen-single span').text(
			$('select#CASTING_CITY option:selected').parent()[0].label+', '+
			$('#CASTING_CITY_chosen .chosen-single span').text()
		);		
	}
	addSpanCity = function() {
		$('#CASTING_CITY_chosen .chosen-single span').text(
			""+$("#CASTING_CITY").attr("data-placeholder")+""
		);		
	}

	$('select#CASTING_CITY').chosen().change(function(){
		addRegionToCity();
	});
	
	initCityList = function() {
		sid = $('input#CASTING_CITY_PRE').val();
    $.ajax({
	    url: 'load_ref.php',
			type: "GET",			
			data: {REF: 'CITY', SID: sid },
			dataType: "html",
			success: function(html){
				$('select#CASTING_CITY').html(html);
				if ($('input#CASTING_CITY_PRE').attr('value')>0){
					$('select#CASTING_CITY option[value="'+$('input#CASTING_CITY_PRE').attr('value')+'"]').prop("selected", true);
					
				$("select#CASTING_CITY").trigger('chosen:updated');
				addRegionToCity();
				} else {
					$("select#CASTING_CITY").trigger('chosen:updated');
					addSpanCity();
	
				};
				
		  }
		});
	}
	$("#CASTING_CITY_chosen .chosen-single div").html('');
	$("#sel_section_chosen .chosen-single div").html('');
	$("#sel_public_date_chosen .chosen-single div").html('');
	$("#sel_comp_type_chosen .chosen-single div").html('');
	initCityList();
	$("#sel_public_date_chosen .chosen-single span").addClass("discolor");
	$("#sel_comp_type_chosen .chosen-single span").addClass("discolor");
		$("#casting-form .chosen-container-single .chosen-drop").click(function(){ 
		if ($(this).find("result-selected").hasClass("disabled-result")){	
			$(this).parents(".chosen-container-single").find("span").addClass("discolor");			
		}
		else
		{
			$(this).parents(".chosen-container-single").find("span").removeClass("discolor");
		};
		
	});
	$("#new_image_preview").click(function(){
		$("#btn_load_pic").click();
		
	});
});

Zerion Mini Shell 1.0