append.js 2.59 KB
$(function(){
	region.start();
	
	function actions(){
		function _show(obj){
			obj.next().show();
		}
		function _append(obj){
			obj.parent().find(".show-more").append(
				'<div class="more-cell">'+ 
				obj.parent().find(".title div").html() +
				'<span></span></div>'
			);
			obj.parent().find(".title div").html("");
			
		}
		function _remove(obj){
			if (obj.parent().parent().find(".more-cell").length<=1){
				obj.parent().parent().parent().hide();
			}
			obj.parent().remove();
		}
		this.run =  function(){
			$(".more-cell").live("mouseover",function(){
				$(this).find("span").css("visibility","visible");
			}).live("mouseout",function(){
				$(this).find("span").css("visibility","hidden");
			})
			$(".add-more").live("click",function(){
				if (!$(this).prev().find(".title div").html()){return false};
				if (!$(this).parent().find(".title div").html()){return false};
				_show($(this));
				_append($(this))
				return false;
			});
			$(".more-cell span").live("click",function(){
				_remove($(this));
			})
		}
	}
	var action = new actions();
	action.run();
	
		var varieties = new OperationList({
			add : 'add-category',
			view : 'category-list',
			del : 'category-list span',
			fun : function(data){
				var ids = '';
				var texts = '';
				var view = '';
				for (var i=0; i < data.length; i++) {
					var txt = '';
				    for (var k=0; k < data[i].length; k++) {
					   if(k === (data[i].length - 1)){
				   	   	  ids   += data[i][k].cid+',';
				   	   	  texts += data[i][k].cname+',';
				   	   }else{
				   	   	  texts += data[i][k].cname+'-->';
				   	   };
				   	   txt += data[i][k].cname+' ';
					};
					view += '<div  page="'+i+'" class="more-cell">'+txt+'<span style="visibility: hidden;"></span></div>';
				};
				$('.category-list').html('');
				$('.category-list').append(view);
				$('#categoryId').val(ids);
				$('#varietiesId').val(texts);
			}
		});
		
		var areaData = new OperationList({
			add : 'add-area',
			view : 'area-list',
			del : 'area-list span',
			pid : 'regionId',
			txt : 'regionName',
			fun : function(data){
				var adata = '';
				var view = '';
				for (var i=0; i < data.length; i++) {
				  var txt = '';
				  for (var k=0; k < data[i].length; k++) {
				  	 if(k == (data[i].length - 1)){
				  	 	adata += data[i][k].regionId+'/'+data[i][k].regionName+',';
				  	 };
				  	 txt += data[i][k].regionName+' ';
				   };
				  view += '<div  page="'+i+'" class="more-cell">'+txt+'<span style="visibility: hidden;"></span></div>';
				};
				$('.area-list').html('');
				$('.area-list').append(view);
				$('#specialiseAreaId').val(adata);
			}
		});
})