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); | ||||
|  | ||||
|   | ||||
| @@ -58,7 +58,7 @@ | ||||
|         // items | ||||
|         this.data = {}; | ||||
|     }; | ||||
|     question.prototype.createContent = function (answer, medias, change) { | ||||
|     question.prototype.createContent = function (answer, answerchange, inputchange, medias) { | ||||
|         this.answer = answer; | ||||
|         var content = $('<div class="question-item" style="line-height: 26px; margin: 0 0 22px 22px"></div>'); | ||||
|         var q = this.question; | ||||
| @@ -72,7 +72,7 @@ | ||||
|             var div_pic = $('<div></div>'); | ||||
|             for (var i = 0; i < q.StaticPictures.length; i++) { | ||||
|                 var pic = q.StaticPictures[i]; | ||||
|                 var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name); | ||||
|                 var img = $('<img loading="lazy" 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") | ||||
|                 }); | ||||
| @@ -83,7 +83,7 @@ | ||||
|  | ||||
|         var cnt = $('<div style="margin: 6px 0 0 22px"></div>'); | ||||
|         if (typeof this.createQuestion === 'function') { | ||||
|             this.ui.content = this.createQuestion(answer, medias, change); | ||||
|             this.ui.content = this.createQuestion(answer, answerchange, inputchange, medias); | ||||
|             cnt.append(this.ui.content); | ||||
|         } else { | ||||
|             cnt.append('<div style="font-style: italic; color: #ccc"><Not implemented yet.></div>'); | ||||
| @@ -128,7 +128,7 @@ | ||||
|     }; | ||||
|     inputQuestion.prototype = Object.create(question.prototype); | ||||
|     inputQuestion.prototype.constructor = inputQuestion; | ||||
|     inputQuestion.prototype.createQuestion = function (answer, _medias, change) { | ||||
|     inputQuestion.prototype.createQuestion = function (answer, answerchange, inputchange, _medias) { | ||||
|         var content = $('<div></div>'); | ||||
|         var input; | ||||
|         if (this.question.QuestionType === QTypes.MultipleLineText | ||||
| @@ -145,11 +145,19 @@ | ||||
|                 input.prop('readonly', true).css('background', '#eee'); | ||||
|             } else if (this.question.SubType === FuelRecordTypes.Quantity | ||||
|                 || this.question.SubType === FuelRecordTypes.UnitCost) { | ||||
|                 if (typeof change === 'function') { | ||||
|                     input.on('input propertychange', this, change); | ||||
|                 if (typeof inputchange === 'function') { | ||||
|                     input.on('input propertychange', this, inputchange); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         if (typeof answerchange === 'function') { | ||||
|             if (this.question.QuestionType === QTypes.Number | ||||
|                 || this.question.QuestionType === QTypes.Integer | ||||
|                 || this.question.QuestionType === QTypes.EngingHours | ||||
|                 || this.question.SubType === FuelRecordTypes.UnitCost) { | ||||
|                 input.on('change', this, answerchange); | ||||
|             } | ||||
|         } | ||||
|         if (answer && answer.Result) { | ||||
|             input.val(answer.Result); | ||||
|         } | ||||
| @@ -169,7 +177,7 @@ | ||||
|                 var div_pic = $('<div></div>'); | ||||
|                 for (var i = 0; i < _medias.length; i++) { | ||||
|                     var pic = _medias[i]; | ||||
|                     var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name); | ||||
|                     var img = $('<img loading="lazy" 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") | ||||
|                     }); | ||||
| @@ -186,6 +194,7 @@ | ||||
|         //if (this.question.QuestionType !== QTypes.FuelRecords || | ||||
|         //    this.question.SubType !== FuelRecordTypes.TotalCost) { | ||||
|         answer.Result = this.ui.input.val(); | ||||
|         answer.AsDouble = Number(answer.Result); | ||||
|         //} | ||||
|         return answer; | ||||
|     }; | ||||
| @@ -258,7 +267,7 @@ | ||||
|     }; | ||||
|     listQuestion.prototype = Object.create(question.prototype); | ||||
|     listQuestion.prototype.constructor = listQuestion; | ||||
|     listQuestion.prototype.createQuestion = function (answer) { | ||||
|     listQuestion.prototype.createQuestion = function (answer, answerchange) { | ||||
|         var content = $('<div></div>'); | ||||
|         var q = this.question; | ||||
|         for (var i = 0; i < q.SelectItems.length; i++) { | ||||
| @@ -275,6 +284,9 @@ | ||||
|                 check = $('<input type="radio"></input>').attr({ 'id': id, 'name': name }).val(val); | ||||
|             } | ||||
|             check.data('item', item); | ||||
|             if (typeof answerchange === 'function') { | ||||
|                 check.on('change', this, answerchange); | ||||
|             } | ||||
|             if (answer && answer.SelectedItems) { | ||||
|                 var s = answer.SelectedItems.filter(function (a) { return (a.Value || a.Text) === val }); | ||||
|                 if (s.length > 0) { | ||||
| @@ -353,6 +365,9 @@ | ||||
|             //onSelectDate: function (v, inp) { | ||||
|  | ||||
|             //} | ||||
|             onChangeDateTime: function (v, inp) { | ||||
|                 var date = new DateFormatter().formatDate(v, 'm/d/Y'); | ||||
|             } | ||||
|         }); | ||||
|         if (q.QuestionType === QTypes.DateAndTime | ||||
|             || (q.QuestionType === QTypes.FuelRecords && | ||||
| @@ -406,9 +421,9 @@ | ||||
|     }; | ||||
|     dropQuestion.prototype = Object.create(question.prototype); | ||||
|     dropQuestion.prototype.constructor = dropQuestion; | ||||
|     dropQuestion.prototype.createQuestion = function (answer) { | ||||
|     dropQuestion.prototype.createQuestion = function (answer, answerchange) { | ||||
|         var _this = this; | ||||
|         var content = $('<div></div>').click(function () { _this.openDrop(content.offset()) }); | ||||
|         var content = $('<div></div>').click(function () { _this.openDrop(content.offset(), answerchange) }); | ||||
|         var result = $('<div class="drop-result" style="float: left; cursor: pointer"></div>'); | ||||
|         this.fillResult(result, answer && answer.SelectedItems); | ||||
|         content.append(result); | ||||
| @@ -469,7 +484,7 @@ | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
|     dropQuestion.prototype.openDrop = function (pos) { | ||||
|     dropQuestion.prototype.openDrop = function (pos, answerchange) { | ||||
|         var _this = this; | ||||
|         var q = this.question; | ||||
|         var mask = this.ui.mask; | ||||
| @@ -559,6 +574,7 @@ | ||||
|                 refreshList(panelContent, items); | ||||
|             } | ||||
|         }); | ||||
|         search.attr("placeholder", GetTextByKey("P_AM_SEARCH", "Search")); | ||||
|         var funcs = $('<div style="margin-right: 45px"></div>'); | ||||
|         funcs.append(search); | ||||
|         panel.append($('<div class="sbutton iconcheck"></div>').css({ | ||||
| @@ -585,6 +601,10 @@ | ||||
|             answer.SelectedItems = items; | ||||
|             _this.fillResult(_this.ui.content.find('.drop-result'), items); | ||||
|             _this.closeDrop(); | ||||
|  | ||||
|             if (typeof answerchange === 'function') { | ||||
|                 answerchange(_this); | ||||
|             } | ||||
|         })); | ||||
|         panel.append(funcs); | ||||
|         // scroller | ||||
| @@ -728,7 +748,7 @@ | ||||
|     }; | ||||
|     pictureQuestion.prototype = Object.create(question.prototype); | ||||
|     pictureQuestion.prototype.constructor = pictureQuestion; | ||||
|     pictureQuestion.prototype.createQuestion = function (_answer, medias) { | ||||
|     pictureQuestion.prototype.createQuestion = function (_answer, answerchange, inputchange, medias) { | ||||
|         var content = $('<div></div>'); | ||||
|         if (medias && medias.length > 0) { | ||||
|             for (var i = 0; i < medias.length; i++) { | ||||
| @@ -750,7 +770,7 @@ | ||||
|                         'color': '#000' | ||||
|                     })); | ||||
|                 } else { | ||||
|                     ele = $('<img></img>').css({ | ||||
|                     ele = $('<img loading="lazy"></img>').css({ | ||||
|                         'float': 'left', | ||||
|                         'border': '1px solid #ccc', | ||||
|                         'padding': '4px', | ||||
| @@ -774,7 +794,7 @@ | ||||
|     }; | ||||
|     assetStatusQuestion.prototype = Object.create(question.prototype); | ||||
|     assetStatusQuestion.prototype.constructor = assetStatusQuestion; | ||||
|     assetStatusQuestion.prototype.createQuestion = function (answer, medias) { | ||||
|     assetStatusQuestion.prototype.createQuestion = function (answer, answerchange, inputchange, medias) { | ||||
|         var content = $('<div></div>'); | ||||
|         var q = this.question; | ||||
|         q.SelectItems = [ | ||||
| @@ -792,6 +812,9 @@ | ||||
|             var val = item.Value || item.Text; | ||||
|             var check = $('<input type="radio"></input>').attr({ 'id': id, 'name': name }).val(val); | ||||
|             check.data('item', item); | ||||
|             if (typeof answerchange === 'function') { | ||||
|                 check.on('change', this, answerchange); | ||||
|             } | ||||
|             if (answer && answer.SelectedItems) { | ||||
|                 var s = answer.SelectedItems.filter(function (a) { return (a.Value || a.Text) === val }); | ||||
|                 if (s.length > 0) { | ||||
| @@ -837,7 +860,7 @@ | ||||
|                         'color': '#000' | ||||
|                     })); | ||||
|                 } else { | ||||
|                     ele = $('<img></img>').css({ | ||||
|                     ele = $('<img loading="lazy"></img>').css({ | ||||
|                         'float': 'left', | ||||
|                         'border': '1px solid #ccc', | ||||
|                         'padding': '4px', | ||||
|   | ||||
| @@ -5,8 +5,8 @@ | ||||
|     }; | ||||
|  | ||||
|     var __proto = ctor.prototype; | ||||
|     __proto.createContent = function (change) { | ||||
|         var content = $('<div style="margin-bottom: 20px"></div>'); | ||||
|     __proto.createContent = function (change, answerchange) { | ||||
|         var content = $('<div class="section-item" 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>'); | ||||
| @@ -47,15 +47,9 @@ | ||||
|                 || 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); | ||||
|             } | ||||
|             var qContent = q.createContent(answer, answerchange, change, medias); | ||||
|             qContent.data('question', q); | ||||
|             qContent.data('section', this.section); | ||||
|             content.append(qContent); | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user