I may be approaching this all wrong so feedback or suggestions would be very appreciated.
I am building a tool using javascript and jQuery that allows a user to create their own dashboard. The user can select modules that they want to add to the dashboard and re-arrange it as they see fit.
A module could be anything such as a html table or an input that allows them to perform a search.
My goal was to make each module its own JS file so that its easy to keep the logic separate and debug it when needed.
This is what I was working towards, specifically the getScript
// Loop over our modules and create our output
for ( var i = 0; i < moduleData.modules.length; i++){
output += '<li data-sizey="'+moduleData.modules[i].sizeY+'" data-sizex="'+moduleData.modules[i].sizeX+'" data-col="'+moduleData.modules[i].col+'" data-row="'+moduleData.modules[i].row+'" data-min-sizey="'+moduleData.modules[i].minYsize+'" data-min-sizex="'+moduleData.modules[i].minXsize+'">';
output += '<div class="portlet" >';
output += '<div class="portlet-title">';
output += '<div class="caption">';
output += '<i class="'+moduleData.modules[i].moduleIcon+'"></i>';
output += '<span class="caption-subject text-uppercase"> '+moduleData.modules[i].moduleName+'</span>';
output += '<span class="caption-helper"> '+moduleData.modules[i].moduleDescription+'</span>';
output += '</div>';
output += '<div class="actions">';
output += '<a class="btn" name="editModule" data-moduleid="'+moduleData.modules[i].moduleID+'"><i class="fa fa-pencil"></i>Edit</a>';
output += '</div>';
output += '</div>';
output += '<div class="portlet-body">';
$.getScript( "includes/js/modules/"+moduleData.modules[i].moduleID+".js", function(data){
output += data;
});
output += '</div>';
output += '</div>';
output += '</li>';
}
// Append our output
$('#moduleData').empty().append(output);
The code above fetches the modules that the user selected. It sets up the module block/div where the actual logic will be rendered.
My goal now is to fill those modules with the output of the individual JS files I was trying to fetch.
Any suggestions on a better way to handle this while trying to some how keep the modules all as separate files (assumed this would be the best).