sync
This commit is contained in:
@ -18,7 +18,9 @@
|
||||
for (var i = 0; i < pages.length; i++) {
|
||||
var qs = $(pages[i]).find('.question-item');
|
||||
for (var j = 0; j < qs.length; j++) {
|
||||
var question = $(qs[j]).data('question');
|
||||
var qso = $(qs[j]);
|
||||
var question = qso.data('question');
|
||||
var section = qso.data('section');
|
||||
var q = question.question;
|
||||
var a = question.getAnswer();
|
||||
var flag;
|
||||
@ -32,7 +34,7 @@
|
||||
(q.QuestionType === Question.types.FuelRecords
|
||||
&& (q.SubType === Question.fueltypes.State ||
|
||||
q.SubType === Question.fueltypes.FuelType));
|
||||
if (q.IsRequired) {
|
||||
if (q.IsRequired && checkConditional(_this.report.Template, q.Conditional, answers) && checkConditional(_this.report.Template, section.Conditional, answers)) {
|
||||
if (isChoice) {
|
||||
flag = a.SelectedItems == null || a.SelectedItems.length == 0;
|
||||
} else if (a.Result == null || a.Result.length == 0) {
|
||||
@ -52,7 +54,7 @@
|
||||
continue;
|
||||
}
|
||||
} else if (a.Result == null || a.Result.length == 0) {
|
||||
if (q.QuestionType !== Question.types.Picture) {
|
||||
if (q.QuestionType !== Question.types.Picture && (q.QuestionType !== Question.types.FuelRecords || q.SubType !== Question.fueltypes.Picture)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -157,6 +159,104 @@
|
||||
});
|
||||
}
|
||||
|
||||
function checkConditional(template, cond, answers) {
|
||||
if (!cond) return true;
|
||||
|
||||
var qid = cond.QuestionId.toLowerCase();
|
||||
if (qid == "and") {
|
||||
for (let scond of cond.SubItems) {
|
||||
var r = checkConditional(template, scond, answers);
|
||||
if (!r) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (qid == "or") {
|
||||
for (let scond of cond.SubItems) {
|
||||
var r = checkConditional(template, scond, answers);
|
||||
if (r) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
var condquestion = getQuestionAndSection(template, cond.QuestionId);
|
||||
if (!condquestion) return false;
|
||||
if (!condquestion.Question || !checkConditional(template, condquestion.Question.Conditional, answers)) return false;
|
||||
if (!condquestion.Section || !checkConditional(template, condquestion.Section.Conditional, answers)) return false;
|
||||
|
||||
if (!cond.Value) return cond.Operator == "noteq" ? true : false;
|
||||
var ans = answers.find(c => c.QuestionId.toLowerCase() == cond.QuestionId.toLowerCase());
|
||||
if (ans == null) return false;
|
||||
var condValue = Number(cond.Value);
|
||||
switch (cond.Operator) {
|
||||
case "gt"://>
|
||||
return ans.AsDouble > condValue;
|
||||
case "gteq"://>=
|
||||
return ans.AsDouble >= condValue;
|
||||
case "lt"://<
|
||||
return ans.AsDouble < condValue;
|
||||
case "lteq"://<=
|
||||
return ans.AsDouble <= condValue;
|
||||
case "between"://between
|
||||
var condValue1 = Number(cond.Value1);
|
||||
return ans.AsDouble >= condValue && ans.AsDouble <= condValue1;
|
||||
case "in"://in
|
||||
if (!ans.SelectedItems || ans.SelectedItems.Count == 0) return false;
|
||||
var condvs = cond.Value.toLowerCase().split(';');
|
||||
for (let item of ans.SelectedItems) {
|
||||
var sv = item.Value;
|
||||
if (condquestion.Question.QuestionType == Question.types.AssetStatus || condquestion.Question.QuestionType == Question.types.YesOrNo)
|
||||
sv = item.Text || ans.SelectedText;
|
||||
if (!sv || condquestion.Question.LookupSource != 0)
|
||||
sv = item.Text;
|
||||
if (condvs.indexOf(sv.toLowerCase()) >= 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case "noteq":
|
||||
var v = "";
|
||||
if (condquestion.Question.QuestionType == 5// QuestionTypes.YesOrNo
|
||||
|| condquestion.Question.QuestionType == 8//QuestionTypes.DropDown
|
||||
|| condquestion.Question.QuestionType == 9//QuestionTypes.List
|
||||
|| condquestion.Question.QuestionType == 19) {//QuestionTypes.AssetStatus)
|
||||
if (!ans.SelectedItems || ans.SelectedItems.length == 0) return false;
|
||||
if (ans.SelectedItems.length > 1) return true;
|
||||
v = ans.SelectedItems[0].Value;
|
||||
if (!v || condquestion.Question.QuestionType == 19 || condquestion.Question.QuestionType == 5 || condquestion.Question.LookupSource != 0)
|
||||
v = ans.SelectedItems[0].Text;
|
||||
}
|
||||
else
|
||||
v = ans.Result;
|
||||
return cond.Value.toLowerCase() != v.toLowerCase() && ans.AsDouble != condValue;
|
||||
default: //=
|
||||
var v1 = "";
|
||||
if (condquestion.Question.QuestionType == 5// QuestionTypes.YesOrNo
|
||||
|| condquestion.Question.QuestionType == 8//QuestionTypes.DropDown
|
||||
|| condquestion.Question.QuestionType == 9//QuestionTypes.List
|
||||
|| condquestion.Question.QuestionType == 19) {//QuestionTypes.AssetStatus)
|
||||
if (!ans.SelectedItems || ans.SelectedItems.length != 1) return false;
|
||||
v1 = ans.SelectedItems[0].Value;
|
||||
if (!v1 || condquestion.Question.QuestionType == 19 || condquestion.Question.QuestionType == 5 || condquestion.Question.LookupSource != 0)
|
||||
v1 = ans.SelectedItems[0].Text;
|
||||
}
|
||||
else
|
||||
v1 = ans.Result;
|
||||
|
||||
return cond.Value.toLowerCase() == v1.toLowerCase() || ans.AsDouble == condValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
function getQuestionAndSection(template, questionid) {
|
||||
for (var p of template.Pages) {
|
||||
for (var s of p.Sections) {
|
||||
for (var q of s.Questions) {
|
||||
if (q.Id.toLowerCase() == questionid.toLowerCase())
|
||||
return { Question: q, Section: s };
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
__proto.createContent = function () {
|
||||
var _this = this;
|
||||
var content = $('<div></div>');
|
||||
@ -247,7 +347,7 @@
|
||||
tr.append(td);
|
||||
tb.append(tr);
|
||||
|
||||
if (data.ForWorkOrder) {
|
||||
if (data.Template.ForWorkOrder) {
|
||||
tr = $('<tr></tr>');
|
||||
td = $('<td style="width: 25%"><b style="display: inline-block; width: 85px">' + GetTextByKey("P_IPT_WORKORDER_COLON", "Work Order:") + '</b></td>');
|
||||
var selwo = $('<select style="margin-left: 6px;width: 160px"></select>');
|
||||
@ -304,6 +404,41 @@
|
||||
|
||||
// content
|
||||
var p = $('<div></div>').attr('data-page', name);
|
||||
|
||||
var answerchange = (function (panel) {
|
||||
return function (e, answers) {
|
||||
var qs = panel.find('.question-item');
|
||||
if (!answers) {
|
||||
answers = [];
|
||||
for (var j = 0; j < qs.length; j++) {
|
||||
var question = $(qs[j]).data('question');
|
||||
var q = question.question;
|
||||
var a = question.getAnswer();
|
||||
answers.push(a);
|
||||
}
|
||||
}
|
||||
|
||||
for (var j = 0; j < qs.length; j++) {
|
||||
var temp = $(qs[j]);
|
||||
var question = temp.data('question');
|
||||
if (checkConditional(data.Template, question.question.Conditional, answers))
|
||||
temp.show();
|
||||
else
|
||||
temp.hide();
|
||||
}
|
||||
|
||||
var ss = panel.find('.section-item');
|
||||
for (var j = 0; j < ss.length; j++) {
|
||||
var temp = $(ss[j]);
|
||||
var section = temp.data('section');
|
||||
if (checkConditional(data.Template, section.section.Conditional, answers))
|
||||
temp.show();
|
||||
else
|
||||
temp.hide();
|
||||
}
|
||||
}
|
||||
})(p);
|
||||
|
||||
var change = (function (panel) {
|
||||
return function (e) {
|
||||
var v = e.data.getAnswer();
|
||||
@ -373,7 +508,13 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
p.append(section.createContent(change));
|
||||
|
||||
var sContent = section.createContent(change, answerchange);
|
||||
sContent.data('section', section);
|
||||
p.append(sContent);
|
||||
setTimeout(function () {
|
||||
answerchange(null, data.Answers);
|
||||
})
|
||||
}
|
||||
content.append(p);
|
||||
|
||||
|
Reference in New Issue
Block a user