Blame view

sources/core/js/listview.js 1.74 KB
03e52840d   Kload   Init
1
2
3
4
5
6
7
8
9
10
11
12
13
  function ListView(element){
  	this.element=element;
  }
  
  ListView.generateTable=function(collumns){
  	var html='<table>';
  	html+='<thead>';
  	$.each(collumns,function(index,collumn){
  		html+='<th>'+collumn+'</th>';
  	});
  	html+='<thead>';
  	html+='</head>';
  	html+='<tbody>';
31b7f2792   Kload   Upgrade to ownclo...
14
  	html+='<tr class="template">';
03e52840d   Kload   Init
15
16
17
  	$.each(collumns,function(index,collumn){
  		html+='<th class="'+collumn.toLower()+'"</th>';
  	});
31b7f2792   Kload   Upgrade to ownclo...
18
  	html+='</tr>';
03e52840d   Kload   Init
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  	html+='</tbody>';
  	html='</table>';
  	return $(html);
  };
  
  ListView.prototype={
  	rows:{},
  	hoverElements:{},
  	addRow:function(id,data,extraData){
  		var tr=this.element.find('tr.template').clone();
  		tr.removeClass('template');
  		$.each(data,function(name,value){
  			tr.children('td.'+name).text(value);
  			tr.attr('data-'+name,value);
  		});
  		$.each(extraData,function(name,value){
  			tr.attr('data-'+name,value);
  		});
  		this.rows[id]=data;
  		tr.data('id',id);
  		this.element.children('tbody').append(tr);
  	},
  	removeRow:function(id){
  		this.rows[id].remove();
  		delete this.rows[id];
  	},
  	hoverHandeler:function(tr){
  		$.each(this.hoverElement,function(index,collumn){
  			$.each(collumn,function(index,element){
  				var html='<a href="#" title="'+element.title+'" class="hoverElement"/>';
  				var element=$(html);
  				element.append($('<img src="'+element.icon+'"/>'));
  				element.click(element.callback);
  				tr.children('td.'+collumn).append(element);
  			});
  		});
  		if(this.deleteCallback){
  			
  		}
  	},
  	hoverHandelerOut:function(tr){
  		tr.find('*.hoverElement').remove();
  	},
  	addHoverElement:function(collumn,icon,title,callback){
  		if(!this.hoverElements[collumn]){
  			this.hoverElements[collumn]=[];
  		}
  		this.hoverElements[row].push({icon:icon,callback:callback,title:title});
  	},
  	empty:function(){
  		this.element.children('tr:not(.template)').remove();
  	}
  };