This commit is contained in:
2024-03-26 15:56:31 +08:00
parent 634e8b71ab
commit 0855ae42cd
547 changed files with 94818 additions and 60463 deletions

View File

@ -1,4 +1,10 @@
define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'modules/templates/picture'], function (AddQuestion, Option, Common, Picture) {
define(['modules/sections/addquestion', 'modules/sections/option', 'modules/sections/conditional', 'common', 'modules/templates/picture'], function (AddQuestion, Option, ConditionalTree, Common, Picture) {
var allowConditionQuestions = [3, 4, 5, 8, 9, 11, 12, 19];
var dropdownType = 8;
var bannedLookupSources = [2, 3];
var fuelRecordsType = 15;
var allowConditionSubTypes = [8, 9, 10, 11, 12];
var q = function (sm, question, index) {
this.sectionmodule = sm;
this.section = sm.section;
@ -6,6 +12,15 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
this.holder = null;
this.questionholder = null;
this.index = index;
// calc id index
var idIndex = index + 1;
if (sm.pagemodule != null) {
var ss = sm.pagemodule.page.Sections;
for (var i = 0; i < sm.index; i++) {
idIndex += ss[i].Questions.length;
}
}
this.idIndex = idIndex;
this.txtName = null;
this.txtDisplayText = null;
@ -26,8 +41,10 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
this.txtBarCodeValidate = null;
this.optionholder = undefined;
this.conditionholder = undefined;
this.optiondiv = undefined;
this.btnoption = undefined;
this.btncondition = undefined;
this.optiontr = undefined;
this.optiontd = undefined;
this.multipleselectdiv = null;
@ -46,25 +63,22 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
q.prototype.createContent = function () {
var _this = this;
if (sectiontype === 0) {
if (!_this.question.IssueId || _this.question.IssueId == "")
editable = true;
else
editable = false;
}
var holder = $('<div class="questionitem"></div>');
_this.holder = holder;
var qholder = $('<div class="question-holder"></div>');//question holder
holder.append(qholder);
_this.questionholder = qholder;
var cholder = $('<div style="display: none"></div>'); // conditional hierarchy holder
holder.append(cholder);
_this.conditionholder = cholder;
var oholder = $('<div style="display:none;"></div>');//option holder
holder.append(oholder);
_this.optionholder = oholder;
if (this.index % 2 == 1)
qholder.addClass('holder-even');
var drag = $('<div class="question-icon" style="width:30px;" title="' + GetTextByKey("P_IPT_XXX", "Move Question") + '"><em class="spanbtn iconmove rowdrag"></em></div>');
var drag = $('<div class="question-icon" style="width:30px;" title="' + GetTextByKey("P_IPT_MOVEQUESTION", "Move Question") + '"><em class="spanbtn iconmove rowdrag"></em></div>');
qholder.append(drag);
if (!_this.section.IsLink && sectiontype == 1) {
drag.attr('draggable', true);
@ -107,15 +121,30 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
drag.hide();
qholder.append('<div class="question-icon" style="width:30px;"><em class="fa"></em></div>');
// index
qholder.append('<div class="question-cell question-index" style="width: 30px; text-align: right">#' + String(this.idIndex) + '</div>');
_this.txtName = $('<input type="text" class="question-input" maxlength="100" autocomplete="off" style="width:146px;" />');
var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_XXX", "Language Selection") + '"/>');
var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_LANGUAGESELECTION", "Language Selection") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(_this.txtName, _this.question);
});
qholder.append($('<div class="question-cell question-name" style="width: 190px;padding-left:10px;"></div>').append(this.txtName).append(addiText));
qholder.append($('<div class="question-cell question-name" style="width: 190px;padding-left:15px;"></div>').append(this.txtName).append(addiText));
_this.txtDisplayText = $('<input type="text" class="question-input" maxlength="200" autocomplete="off" style="width:236px;" />');
addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_XXX", "Language Selection") + '"/>');
if (_this.sectionmodule.pagemodule != null) {
_this.txtDisplayText.on('change', function () {
if ((
allowConditionQuestions.includes(_this.question.QuestionType) ||
(_this.question.QuestionType === fuelRecordsType && allowConditionSubTypes.includes(_this.question.SubType))
) &&
(q.question.QuestionType != dropdownType || !bannedLookupSources.includes(Number(q.question.LookupSource)))) {
_this.sectionmodule.pagemodule.refreshIdIndex();
}
});
}
addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_LANGUAGESELECTION", "Language Selection") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(_this.txtDisplayText, _this.question);
});
@ -130,7 +159,10 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
//this.selQuestionType<70><65>createQuestionTypeCtrl<72>и<EFBFBD>ֵ
var qt = createQuestionTypeCtrl().css('width', 140);
qholder.append($('<div class="question-cell question-type" style="width: 408px"></div>').append(qt));
qholder.append($('<div class="question-cell question-type" style="width: 450px"></div>').append(qt));
if (_this.sectionmodule.pagemodule != null) {
createConditionHierarchy();
}
createOptions();
_this.chkIsRequired = $('<input type="checkbox" />');
@ -208,13 +240,37 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
tr.append(td);
_this.selQuestionType = createQuestionType().addClass('question-input');
td.append(_this.selQuestionType);
_this.selQuestionType.change(function () {
_this.selQuestionType.on('change', function () {
_this.questionTypeChange(true);
if (_this.sectionmodule.pagemodule != null &&
(allowConditionQuestions.includes(_this.question.QuestionType) ||
(_this.question.QuestionType === fuelRecordsType && allowConditionSubTypes.includes(_this.question.SubType)))) {
_this.sectionmodule.pagemodule.refreshIdIndex();
}
});
if (_this.sectionmodule.pagemodule != null) {
td = $('<td></td>');
tr.append(td);
_this.btncondition = $('<span class="spanbtn iconconditional" style="font-size: 12px" title="' + GetTextByKey("P_IPT_CONDITIONALHIERARCHY", "Conditional Hierarchy") + '"></span>');
td.append(_this.btncondition);
_this.btncondition.click(function () {
var icon = $(this);
if (icon.hasClass('iconbold')) {
icon.removeClass('iconbold');
_this.conditionholder.hide();
}
else {
icon.addClass('iconbold');
_this.conditionalTree.refresh();
_this.conditionholder.show();
}
});
}
td = $('<td></td>');
tr.append(td);
_this.btnoption = $('<span class="spanbtn iconangleleft" style="font-size:18px;" title="' + GetTextByKey("P_IPT_XXX","Display Options") + '"></span>');
_this.btnoption = $('<span class="spanbtn iconangleleft" style="font-size:18px;" title="' + GetTextByKey("P_IPT_DISPLAYOPTIONS", "Display Options") + '"></span>');
td.append(_this.btnoption);
_this.btnoption.click(function () {
var icon = $(this);
@ -257,21 +313,21 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
});
td.append(_this.txtTransactionDate);
_this.selState = createState().addClass('question-input').css({ 'width': 116, 'margin-left': '3px' });
_this.selState = createState().addClass('question-input').css({ 'width': 110, 'margin-left': '3px' });
_this.selState.hide();
_this.selState.change(function () {
_this.stateChange(true);
});
td.append(_this.selState);
_this.selFuelType = createFuelType().addClass('question-input').css({ 'width': 116, 'margin-left': '3px' });
_this.selFuelType = createFuelType().addClass('question-input').css({ 'width': 110, 'margin-left': '3px' });
_this.selFuelType.hide();
_this.selFuelType.change(function () {
_this.fuelTypeChange(true);
});
td.append(_this.selFuelType);
_this.selDistributedBy = createDistributedBy().addClass('question-input').css({ 'width': 116, 'margin-left': '3px' });
_this.selDistributedBy = createDistributedBy().addClass('question-input').css({ 'width': 110, 'margin-left': '3px' });
_this.selDistributedBy.hide();
_this.selDistributedBy.change(function () {
_this.distributedByChange(true);
@ -318,6 +374,23 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
return tb;
}
function createConditionHierarchy() {
var div = $('<div style="width:680px;margin-left:540px;padding-left:5px;padding-bottom:5px; border: 1px solid #a8a8a8;line-height:32px;"></div>');
_this.conditionholder.append(div);
div.append($('<span style="font-weight: bold; margin-right: 5px"></span>').text(GetTextByKey('P_IPT_CONDITIONHIERARCHY', 'Condition Hierarchy')));
var root = new ConditionalTree(_this, 'question', _this.sectionmodule.pagemodule);
root.onchanged = function (id) {
if (id === '-') {
_this.btncondition.removeClass('iconexists');
} else {
_this.btncondition.addClass('iconexists');
}
};
_this.conditionalTree = root;
div.append(root.tree);
}
function createOptions() {
_this.optiondiv = $('<div style="width:680px;margin-left:540px;padding-left:5px;padding-bottom:5px; border: 1px solid #a8a8a8;line-height:32px;"></div>');
_this.optionholder.append(_this.optiondiv);
@ -364,8 +437,8 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
items.push({ 'Key': 16, "Value": GetTextByKey("P_IPT_QT_BARCODE", "Bar Code") });
items.push({ 'Key': 17, "Value": GetTextByKey("P_IPT_QT_BARCODEVALIDATE", "Bar Code Validate") });
items.push({ 'Key': 18, "Value": GetTextByKey("P_IPT_QT_FUELUSED", "Fuel Used") });
items.push({ 'Key': 19, "Value": GetTextByKey("P_IPT_QT_XXX", "Asset Status") });
var sel = $('<select style="width:140px; height:26px;"></select>');
items.push({ 'Key': 19, "Value": GetTextByKey("P_IPT_QT_ASSETSTATUS", "Asset Status") });
var sel = $('<select style="width:110px; height:26px;"></select>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
@ -392,7 +465,7 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
items.push({ 'Key': 14, "Value": GetTextByKey("P_IPT_ST_NOTES", "Notes") });
items.push({ 'Key': 15, "Value": GetTextByKey("P_IPT_ST_PICTURE", "Picture") });
items.push({ 'Key': 16, "Value": GetTextByKey("P_IPT_ST_DISTRIBUTEDBY", "Distributed By") });
var sel = $('<select style="width:125px; height:26px;"></select>');
var sel = $('<select style="width:110px; height:26px;"></select>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
@ -405,7 +478,7 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
items.push({ 'Key': "", "Value": "" });
items.push({ 'Key': "0", "Value": GetTextByKey("P_FR_FUELINGSTATION", "Fueling Station") });
items.push({ 'Key': "1", "Value": GetTextByKey("P_FR_FUELINGASSET", "Fueling Asset") });
var sel = $('<select style="width:125px; height:26px;"></select>');
var sel = $('<select style="width:110px; height:26px;"></select>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
@ -665,6 +738,8 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
_this.optionholder.find('table').remove();
_this.optionmodules = [];
}
else if (type == "5")
_this.additemspan.hide();
else {
_this.additemspan.show();
}
@ -762,6 +837,14 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
this.question = question;
}
if (this.btncondition != null) {
if (question.Conditional != null) {
this.btncondition.addClass('iconexists');
} else {
this.btncondition.removeClass('iconexists');
}
}
this.txtName.val(question.Name).data("texts", question.LocalNames);
this.txtDisplayText.val(question.DisplayText).data("texts", question.LocalDisplayTexts);
this.selQuestionType.val(question.QuestionType);
@ -881,12 +964,18 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
// }
// }
//}
var conditional = this.conditionalTree?.getConditional(nocheck, alerttitle);
if (conditional === false) {
return false;
}
question.Conditional = conditional;
return question;
};
q.prototype.delete = function () {
var _this = this;
showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISQUESTION", 'Are you sure you want to delete this question?'), GetTextByKey("P_IPT_DELETEQUESTION", "Delete Question"), function () {
if (!_this.question.Id) {
if (_this.question._isadd) {
_this.holder.remove();
return;
}
@ -894,8 +983,9 @@ define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'mo
inspectionrequest("DeleteGlobalQuestion", p, function (data) {
if (data !== 'OK')
showAlert(data, GetTextByKey("P_IPT_DELETEQUESTION", "Delete Question"));
else if (_this.sectionmodule && typeof _this.sectionmodule.refresh === "function")
else if (_this.sectionmodule && typeof _this.sectionmodule.refresh === "function") {
_this.sectionmodule.refresh();
}
}, function (err) {
showAlert(GetTextByKey("P_IPT_FAILEDTODELETEQUESTION", 'Failed to delete question.'), GetTextByKey("P_IPT_DELETEQUESTION", "Delete Question"));
});