2023-04-28 12:22:26 +08:00

67 lines
2.9 KiB
JavaScript

define(['modules/inspects/editquestion'], function (Question) {
var ctor = function (section, report) {
this.section = section;
this.report = report;
};
var __proto = ctor.prototype;
__proto.createContent = function (change) {
var content = $('<div style="margin-bottom: 20px"></div>');
if (this.section.StaticPictures && this.section.StaticPictures.length > 0) {
var div_pic = $('<div style="background: #eee; padding: 2px 2px;"></div>');
for (var i = 0; i < this.section.StaticPictures.length; i++) {
var pic = this.section.StaticPictures[i];
var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name);
img.click(pic.Url, function (e) {
window.open(e.data, "_blank")
});
div_pic.append(img);
}
content.append(div_pic);
}
var div_title = $('<div style="background: #eee; padding: 5px 3px; margin: 5px 0; font-size: 1.4em"></div>').text(this.section.DisplayText);
content.append(div_title);
for (var i = 0; i < this.section.Questions.length; i++) {
var question = this.section.Questions[i];
if (question.QuestionType === Question.types.YesOrNo ||
question.QuestionType === Question.types.DropDown ||
question.QuestionType === Question.types.List) {
if (!question.SelectItems || question.SelectItems.length <= 0) {
if (question.QuestionType !== Question.types.DropDown ||
question.LookupSource === 0) {
continue;
}
}
}
var q = Question.factory(question);
// get answer and media
var answer = this.report.Answers.filter(function (a) { return Question.equals(a.QuestionId, question.Id) })[0];
var isPicture = question.QuestionType === Question.types.Picture
|| (question.QuestionType === Question.types.FuelRecords &&
question.SubType === Question.fueltypes.Picture)
|| question.QuestionType === Question.types.AssetStatus;
var medias = isPicture && answer && this.report.Medias.filter(function (m) { return Question.equals(m.AnswerId, answer.Id) });
var qContent;
if (question.QuestionType === Question.types.FuelRecords
&& (question.SubType === Question.fueltypes.Quantity ||
question.SubType === Question.fueltypes.UnitCost)) {
qContent = q.createContent(answer, medias, change);
} else {
qContent = q.createContent(answer, medias);
}
qContent.data('question', q);
content.append(qContent);
}
return content;
};
return ctor;
});