Add files via upload
This commit is contained in:
		
							
								
								
									
										58
									
								
								z_daisy/hook/post_js.htm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								z_daisy/hook/post_js.htm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
<script>
 | 
			
		||||
//上传view图片到附件表
 | 
			
		||||
$('#addattachs').on('change', function(e) {
 | 
			
		||||
	var files = xn.get_files_from_event(e);
 | 
			
		||||
	if (!files) return;
 | 
			
		||||
	// 并发下会 服务端 session 写入会有问题,由客户端控制改为串行
 | 
			
		||||
	var jprogress = $('.attachlist_parents').find('progress');
 | 
			
		||||
	if (!$('.attachlist_parents').find('.attachlist').length) {
 | 
			
		||||
		$('.attachlist_parents').append('<ul class="attachlist"><ul>');
 | 
			
		||||
	}
 | 
			
		||||
	if(!jprogress.length) {
 | 
			
		||||
		jprogress = $('<progress class="progress progress-success" value="0" max="100">0%</progress>').appendTo('.attachlist_parent > ul');
 | 
			
		||||
		//jprogress = $('.attachlist_parents').append('<div class="progress"><div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">25%</div></div>');
 | 
			
		||||
	}
 | 
			
		||||
	$.each_sync(files, function(i, callback) {
 | 
			
		||||
		var file = files[i];
 | 
			
		||||
		xn.upload_file(file, xn.url('attach-create'), {
 | 
			
		||||
			is_image: 2
 | 
			
		||||
		}, function(code, message) {
 | 
			
		||||
			if (code != 0) return $.alert(message);
 | 
			
		||||
			// 把文件 append 到附件列表 替换到wivebg
 | 
			
		||||
			var url = message.url;
 | 
			
		||||
			var filetype = message.filetype;
 | 
			
		||||
			var aid = message.aid;
 | 
			
		||||
			
 | 
			
		||||
			$('.attachlist').append('<li aid="' + aid + '"><a href="' + message.url + '" target="_blank"><i class="icon filetype ' + filetype + '"></i> ' + message.orgfilename + '</a> <a href="javascript:void(0);" class="delete m-l-1"><i class="icon-remove"></i> <?php echo lang('delete');?></a></li>');
 | 
			
		||||
			callback();
 | 
			
		||||
			jprogress.hide();
 | 
			
		||||
			jprogress.val(0);
 | 
			
		||||
			jprogress.text('0%');
 | 
			
		||||
		}, function(percent) {
 | 
			
		||||
			/*
 | 
			
		||||
			var jprogress = $('.attachlist_parents').find('.progress');
 | 
			
		||||
			jprogressbar = jprogress.find('.progress-bar');
 | 
			
		||||
			jprogressbar.css('width', percent+'%');
 | 
			
		||||
			jprogressbar.text(percent+'%');
 | 
			
		||||
			*/
 | 
			
		||||
			jprogress.show();
 | 
			
		||||
			jprogress.val(percent);
 | 
			
		||||
			jprogress.text(percent+'%');
 | 
			
		||||
			console.log('progress:'+ percent); 
 | 
			
		||||
		});
 | 
			
		||||
	});
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// 删除附件 这里的删除hhh
 | 
			
		||||
$('.attachlist_parents').on('click', 'a.delete', function() {
 | 
			
		||||
	var jlink = $(this);
 | 
			
		||||
	var jli = jlink.parents('li');
 | 
			
		||||
	var aid = jli.attr('aid');
 | 
			
		||||
	if(!window.confirm(lang.confirm_delete)) return false;
 | 
			
		||||
	$.xpost(xn.url('attach-delete-'+aid), function(code, message) {
 | 
			
		||||
		if(code != 0) return $.alert(message);
 | 
			
		||||
		jlink.parent().remove();
 | 
			
		||||
	});
 | 
			
		||||
	return false;
 | 
			
		||||
})
 | 
			
		||||
</script>
 | 
			
		||||
		Reference in New Issue
	
	Block a user