form.html 5.17 KB

	<link rel="stylesheet" href="${MAIN_SOURCE_URL}/tmpl/css/admin.css" type="text/css"/>
	<link rel="stylesheet" href="${MAIN_SOURCE_URL}/tmpl/css/default.css" type="text/css"/>
	<link rel="stylesheet" type="text/css" href="${MAIN_SOURCE_URL}/ext/fc_cropresizer/fc-cropresizer.css" />
	<script src="${MAIN_SOURCE_URL}/tmpl/default/js/default.js"></script>
	<script src="${MAIN_SOURCE_URL}/ext/ajax/JsHttpRequest.js"></script>
	<script src='${MAIN_SOURCE_URL}/tmpl/default/js/upload.js'></script>
	<script type="text/javascript" src="${MAIN_SOURCE_URL}/ext/fc_cropresizer/fc-cropresizer.js"></script>

<div style="padding:10px">
	<div style="color:red;font-size:12px;text-align:center;" id="ua_error" ></div>
	
	<form id="form1"  enctype="multipart/form-data"  onsubmit="return false" method="post" >
	<input type="file"  name="ua_file"  id="ua_file" style="margin:0px;padding:0px;height:20px;" />
	<input type="hidden"  name="path" value="${path}"/>
	<input type="hidden"  name="max_size" value="${max_size}"/>
	<input type="hidden"  name="max_width" value="${max_width}"/>
	<input type="hidden"  name="max_height" value="${max_height}"/>
	<div style="text-align:left;color:#808080;font-size:10px;">
		Нажав на кнопку "<b>Обзор</b>", выберите на своём компьютере изображение  размером не более 
		<b>${max_size_str}</b> в формате <b>JPG</b>,<b>GIF</b> или <b>PNG</b> для загрузки его на сайт.
	</div>
	<br/>
	<div style="color:#808080;font-size:10px;text-align:center;display:none" id="ua_status" >
		<b>Подождите, идёт загрузка изображения на сайт...</b>
		<div><img src="/source/tmpl/default/img/ajax-loader.gif" style="margin:5px;" /></div>
	</div>

	<div style="text-align:right"><input type="button" id="ua_button" onclick="upload_ajax.send()" value="Загрузить" class="button_rp"  /></div>
	
	</form>
</div>


<div style="display:none;padding:30px;" id="crop_form">
	
	
		<img  src="?resize=2&width=300&height=300" id="photo1"  
			style="
			
			
				border:1px solid black;
				
			" /> 
	<br/>
	
	
	<form  class="reg_profile" method="POST" action="${MAIN_URL}/?p_name=ajax_upload_img&act=crop" target="_self" enctype="multipart/form-data">
		<input type="hidden" name="act" value="crop" />
		<input type="hidden" name="image_width" id="image_width" />
		<input type="hidden" name="image_height" id="image_height" />
		<input type="hidden" name="image_top" id="image_top" />
		<input type="hidden" name="image_left" id="image_left" />
	
	
		<div style="float:left;">
		<input type="button" value="Сохранить" onclick="upload_ajax.crop()"  />
		</div>
		<div style="text-align:right">
		<input type="button" value="Удалить" onclick="upload_ajax.del()"  />
		</div>
	
	</form>
</div>
	
<script>/*<![CDATA[*/



	//	передаем из адресной строки в js скрипт
upload_ajax = {};
upload_ajax.crop_x = ${crop_image_width};
upload_ajax.crop_y = ${crop_image_height};
upload_ajax.path = '${path}';
upload_ajax.max_size = ${max_size};
upload_ajax.server = '${MAIN_URL}/?p_name=admin_images';



	//	загрузка изображения на сервер
upload_ajax.send = function(){
	r = new request(  upload_ajax.server+'&act=ajax_upload' );
		//	возвращаем результат
	r.onload = function(rst){
		if ( !upload_ajax.crop_x && !upload_ajax.crop_y ){
			opener.upload_img_class.set_file(rst.img_name)	
			opener.upload_img_class.show();
			window.close();
			return false;
		}
		upload_ajax.img_name = rst.img_name;
		upload_ajax.img_id = rst.img_id;
	
		o.$('crop_form').style.display='block'
		o.$('photo1').src='/media/'+upload_ajax.path+'/'+rst.img_name+'?resize=2&width=800&height=600';
	
		
		o.$('photo1').onload = function(){
		
			cropresizer.getObject("photo1").init({
					cropWidth : upload_ajax.crop_x ,
					cropHeight : upload_ajax.crop_y,
					onUpdate : function() {
						this.stopSelection = false;
						document.getElementById("image_width").value= this.iWidth;
						document.getElementById("image_height").value= this.iHeight
						document.getElementById("image_top").value= this.cropTop - this.iTop;
						document.getElementById("image_left").value= this.cropLeft - this.iLeft
					}
			},1);
		}
	
	}
	r.error = function(e){
		o.$('ua_error').innerHTML =e; 
	}
	r.form( o.$('form1') );
	
}


upload_ajax.crop = function(){
	r = new request(  upload_ajax.server+'&act=ajax_crop' );
	r.onload = function(rst){ 
			opener.upload_img_class.set_file(rst.img_src)	
			opener.upload_img_class.show();
			window.close();
			return false;
	};
	
	r.send( 
			{
				'img_id': upload_ajax.img_id ,
				'w' : document.getElementById("image_width").value,
				'h' : document.getElementById("image_height").value,
				't' : document.getElementById("image_top").value,
				'l' : document.getElementById("image_left").value,
				'crop_w':upload_ajax.crop_x,
				'crop_h':upload_ajax.crop_y,
			} 
	)
	
}


upload_ajax.del = function(){
	r = new request(  upload_ajax.server+'&act=ajax_delete' );
	r.onload = function(rst){ 
			window.close();
			//alert('файл удалён')
			//return false;
	};
	
	r.send( {'id': upload_ajax.img_id } )
	
}



/*]]>*/</script>