Hi,
I have issu when returning values in js on creating an new record . Here is my actually code :
From **QuestionnaireAppService **:
`[AbpAuthorize(AppPermissions.Pages_Questionnaires_Create)] protected virtual async Task Create(CreateOrEditQuestionnaireDto input) { var questionnaire = new Survey(); questionnaire.Intitule = input.Intitule; questionnaire.Descriptif = input.Descriptif; questionnaire.DateDebut = input.DateDebut; questionnaire.DateFin = input.DateFin;
if (AbpSession.TenantId != null)
{
questionnaire.TenantId = (int?)AbpSession.TenantId;
}
await _questionnaireRepository.InsertAsync(questionnaire);
await CurrentUnitOfWork.SaveChangesAsync();
for (int i = 0; i < input.Questions.Count; i++)
{
Question question = new Question
{
SurveyId = questionnaire.Id,
Number = i + 1,
Text = input.Questions[i].Text,
Type = input.Questions[i].Type,
};
await _questionRepository.InsertAsync(question);
await CurrentUnitOfWork.SaveChangesAsync();
for (int j = 0; j < input.Questions[i].Answers.Count; j++)
{
Answer answer = new Answer
{
QuestionId = question.Id,
Number = i + 1,
Text = input.Questions[i].Answers[j].Text,
};
await _answerRepository.InsertAsync(answer);
await CurrentUnitOfWork.SaveChangesAsync();
}
}
}`
Js code :
` function save(successCallback) {
debugger
if (!_$questionnaireInformationForm.valid()) {
return;
}
var oldJson = _$questionnaireInformationForm.serializeFormToObject();
console.log(JSON.stringify(oldJson, null, 4));
function convertJsonToArray(oldJson) {
// Nouveau format avec des tableaux
var newJson = {
"Questions": [],
"intitule": oldJson.intitule,
"descriptif": oldJson.descriptif,
"dateDebut": oldJson.dateDebut,
"dateFin": oldJson.dateFin,
"id": oldJson.id
};
$.each(oldJson.Questions, function (index, questionData) {
if (index.includes("Text")) {
var questionIndex = index.split(".")[0];
var question = {
"Text": questionData,
"Type": oldJson.Questions[questionIndex + ".Type"],
"Answers": []
};
debugger
$.each(oldJson.Questions[questionIndex + ".Answers"], function (answerKey, answerValue) {
if (answerKey.includes("Text")) {
question.Answers.push({ "Text": answerValue });
}
});
newJson.Questions.push(question);
}
});
return newJson;
}
var newJson = convertJsonToArray(oldJson);
console.log(JSON.stringify(newJson, null, 4));
abp.ui.setBusy();
_questionnairesService
.createOrEditSurvey(newJson)
.done(function () {
abp.notify.info(app.localize('SavedSuccessfully'));
abp.event.trigger('app.createOrEditQuestionnaireModalSaved');
})
.always(function () {
abp.ui.setBusy();
});
}; ` Create (appservice ) model :
` public class CreateOrEditQuestionnaireDto : EntityDto<int?> {
public string Intitule { get; set; }
public string Descriptif { get; set; }
public DateTime DateDebut { get; set; }
public DateTime DateFin { get; set; }
public CreateOrEditQuestionnaireDto()
{
Questions = new List<QuestionDto>();
}
public List<QuestionDto> Questions { get; set; }
}`
View CreateOrEdit viewmodel :
` public class CreateOrEditQuestionnaireModalViewModel { public CreateOrEditQuestionnaireDto Questionnaire { get; set; }
public bool IsEditMode => Questionnaire.Id.HasValue;
public Survey Survey { get; set; }
public QuestionDto Question { get; set; }
public UserAccount User { get; set; }
public List<QuestionDto> Questions { get; set; }
public List<AnswerDto> Answers { get; set; }
}` The recording is done well but the loader continues to run and the page is blocked.
Thks for help Bernard
2 Answer(s)
-
0
Hi Bernard
To fix this, adjust your usage of
abp.ui.setBusy()
so that it's correctly started and stoppedfunction save(successCallback) { debugger; if (!_$questionnaireInformationForm.valid()) { return; } var oldJson = _$questionnaireInformationForm.serializeFormToObject(); console.log(JSON.stringify(oldJson, null, 4)); function convertJsonToArray(oldJson) { var newJson = { "Questions": [], "intitule": oldJson.intitule, "descriptif": oldJson.descriptif, "dateDebut": oldJson.dateDebut, "dateFin": oldJson.dateFin, "id": oldJson.id }; $.each(oldJson.Questions, function (index, questionData) { if (index.includes("Text")) { var questionIndex = index.split(".")[0]; var question = { "Text": questionData, "Type": oldJson.Questions[questionIndex + ".Type"], "Answers": [] }; debugger; $.each(oldJson.Questions[questionIndex + ".Answers"], function (answerKey, answerValue) { if (answerKey.includes("Text")) { question.Answers.push({ "Text": answerValue }); } }); newJson.Questions.push(question); } }); return newJson; } var newJson = convertJsonToArray(oldJson); console.log(JSON.stringify(newJson, null, 4)); abp.ui.setBusy(); // Start loader _questionnairesService .createOrEditSurvey(newJson) .done(function () { abp.notify.info(app.localize('SavedSuccessfully')); abp.event.trigger('app.createOrEditQuestionnaireModalSaved'); if (typeof successCallback === "function") { successCallback(); // Callback if provided } }) .always(function () { abp.ui.clearBusy(); // Stop loader }); };
- You start the loader with
abp.ui.setBusy()
before the request. - You stop the loader with
abp.ui.clearBusy()
in the .always() method after the request completes, regardless of whether it was successful or not.
- You start the loader with
-
0
Hi,
Thks it's was an abp.ui.clearBusy(); problem i set abp.ui.setBusy(); instead