I'm not sure what's the right question, but I'll try to explain in my current working code:
var container, loader
switch(section){
case 'A':
container = $('#list .container')
loader = $('#surveylist')
var r = postToServer(data, loader)
if(r.cstatus === true){
container.html(r.content)
}
break
case 'B':
container = $('#control .container')
loader = container
var r = postToServer(data, loader)
if(r.cstatus === true){
container.html(r.content.panelB)
}
break
case 'C':
container = $('#content .container')
loader = container
var r = postToServer(data, loader)
if(r.cstatus === true){
$('#surveyElements').sortable();
$('textarea').autosize();
container.html(r.content.panelC)
}
break
}
As you can see, I'm repeating the same code and would like to simplify the method, but not sure what the right term to search in Google. Basically what I'm trying to achieve is this structure:
var container, loader, test
switch(section){
case 'A':,
container = $('#list .container')
loader = $('#surveylist')
test = container.html(r.content)
break
case 'B':
container = $('#control .container')
loader = container
test = container.html(r.content.panelB)
break
case 'C':
container = $('#content .container')
loader = container
test = container.html(r.content.panelC)
break
}
var r = postToServer(data, loader)
if(r.cstatus === true){
// what is the right method to put 'test' here?
}
Or maybe if you guys have any suggestion on refactoring this code?