2011-08-12 20:18:38 +00:00
|
|
|
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>';
|
2013-07-31 19:21:02 +00:00
|
|
|
html+='<tr class="template">';
|
2011-08-12 20:18:38 +00:00
|
|
|
$.each(collumns,function(index,collumn){
|
|
|
|
html+='<th class="'+collumn.toLower()+'"</th>';
|
|
|
|
});
|
2013-07-31 19:21:02 +00:00
|
|
|
html+='</tr>';
|
2011-08-12 20:18:38 +00:00
|
|
|
html+='</tbody>';
|
|
|
|
html='</table>';
|
|
|
|
return $(html);
|
2012-09-05 20:17:33 +00:00
|
|
|
};
|
2011-08-12 20:18:38 +00:00
|
|
|
|
|
|
|
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"/>';
|
2014-03-03 16:11:23 +00:00
|
|
|
element = $(html);
|
2011-08-12 20:18:38 +00:00
|
|
|
element.append($('<img src="'+element.icon+'"/>'));
|
|
|
|
element.click(element.callback);
|
2012-09-05 20:17:33 +00:00
|
|
|
tr.children('td.'+collumn).append(element);
|
2011-08-12 20:18:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
if(this.deleteCallback){
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hoverHandelerOut:function(tr){
|
|
|
|
tr.find('*.hoverElement').remove();
|
|
|
|
},
|
2014-03-01 01:46:27 +00:00
|
|
|
addHoverElement:function(column,icon,title,callback){
|
|
|
|
if(!this.hoverElements[column]){
|
2014-03-03 16:11:23 +00:00
|
|
|
this.hoverElements[column] = [];
|
2011-08-12 20:18:38 +00:00
|
|
|
}
|
|
|
|
this.hoverElements[row].push({icon:icon,callback:callback,title:title});
|
|
|
|
},
|
|
|
|
empty:function(){
|
|
|
|
this.element.children('tr:not(.template)').remove();
|
|
|
|
}
|
2012-09-05 20:17:33 +00:00
|
|
|
};
|