function initGoodTable(tag, data) {
	if( data.length <= 0 ) return;
	let keys = Object.keys(data[0]);
	let header = "";
	for( let i = 0; i < keys.length; i++ ) {
		header += "<th>" + keys[i] + "</th>";
	}
	$($(tag).children("thead")[0]).html("<tr>"+header+"</tr>");
	for( let i = 0; i < data.length; i++ ) {
		header = "";
		let row_id = data[i]["id"];
		for( let u = 0; u < keys.length; u++ ) {
			if( keys[u] == "url" ) {
			    header += "<td><img class=\"good-img\" src=\"/"+data[i][keys[u]]+"\"></td>";
			} else {
			    header += "<td>" + data[i][keys[u]] + "</td>";
			}
		}
		let tabName = tag.substring(1);
		$($(tag).children("tbody")[0]).append("<tr data-rownum=\""+row_id+"\" data-table=\""+tabName[0].toUpperCase()+tabName.substring(1)+"\">"+header+"</tr>");
	}
}

function getUserGoods() {
	$.get( "/api/get_goods", function( data ) {
		initGoodTable("#goods", data);
		set_loading("#goods", false);
	});
}

function set_loading(obj, state) {
	$(obj).attr("aria-busy", state);
}

getUserGoods();