%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/home/bitrix/www/local/components/UB/adbase.offer.edit/templates/offer/
Upload File :
Create Path :
Current File : //proc/self/root/home/bitrix/www/local/components/UB/adbase.offer.edit/templates/offer/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>');
}

$(document).ready(function(){
	
	var new_image = '';
	var idCType = 218;
		


	$('#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[name="CASTING[NAME]"]').val().length<3)
			errorMsg += LA_MESS["AD_TITLE_IS_NOT_SPECIFIED"];
		if (!$('select[name="CASTING_PROPS[CITY]"]').val())
			errorMsg += LA_MESS["THE_CITY_IS_NOT_SPECIFIED"];
		if ($('textarea[name="CASTING_PROPS[CASTING_TEXT]"]').val().length<10)
			errorMsg += LA_MESS["AD_TEXT_IS_NOT_SPECIFIED"];
		if ($('select#sel_comp_type option:selected').val()==idCType && $('input[name="CASTING_PROPS[COMPENSATION]"]').val().length==0)
			errorMsg += LA_MESS["COMPENSATION_SUM_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();
		  // console.log($(this).parent().attr('name')+" : "+value);
		  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()
		);

		if ($('select#sel_comp_type option:selected').val()==idCType) {
			$('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION]"]').show();
			$('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION_CURRENCY]"]').show();
			$('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION_TYPE]"]').hide();
		} else {
			$('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION]"]').hide();
			$('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION_CURRENCY]"]').hide();
			$('div#confirm-submit-body ul > li > span[data-id="CASTING_PROPS[COMPENSATION_TYPE]"]').show();
		}

	  $('#confirm-submit').modal('show');
	  
	});

	$('#post-offer-btn').click(function(){
		$('#casting-form').submit();
	});

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

	$('select#sel_comp_type').chosen().change(function() {
		if ($('select#sel_comp_type option:selected').val()==idCType) {
			$('input[name="CASTING_PROPS[COMPENSATION]"]').prop('disabled',false);
			$('#label_curency').prop('disabled',false);
		}
		else {
			$('input[name="CASTING_PROPS[COMPENSATION]"]').val(0);
			$('input[name="CASTING_PROPS[COMPENSATION]"]').prop('disabled',true);
			$('#label_curency').prop('disabled',true);
		}		
	});
	
	$('#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;
		}
	);

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

	$('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();
		  }
		});
	}
	
	initCityList();
		
});

Zerion Mini Shell 1.0