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

@ -83,7 +83,7 @@ define(['common'], function (Common) {
tb.append(tr);
tr.append('<td class="label">' + GetTextByKey("P_IPT_NAME_COLON", "Name:") + '<span class="redasterisk">*</span></td>');
namecontrol = $('<input type="text" maxlength="100"/>');
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(namecontrol, _this.question);
});
@ -93,7 +93,7 @@ define(['common'], function (Common) {
tb.append(tr);
tr.append('<td class="label">' + GetTextByKey("P_IPT_DISPLAYTEXT_COLON", "Display Text:") + '<span class="redasterisk">*</span></td>');
displaytextcontrol = $('<input type="text" maxlength="1000" />');
addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_XXX", "Language Selection") + '"/>');
addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_LANGUAGESELECTION", "Language Selection") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(displaytextcontrol, _this.question);
});
@ -187,7 +187,7 @@ define(['common'], function (Common) {
tb.append(tr);
var optext = $('<input type="text" style="width:240px;margin-left:5px;"/>');
this.dialog_text = optext;
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(optext, _this.question);
});

View File

@ -12,6 +12,7 @@ define(['common'], function (Common) {
var namecontrol = undefined;
var displaytextcontrol = undefined;
var notescontrol = undefined;
var displayonreportcontrol = undefined;
s.prototype.createContent = function () {
var _this = this;
editable = true;
@ -22,7 +23,7 @@ define(['common'], function (Common) {
var func = $('<div class="function_title"></div>');
if (sectiontype == 0) {
var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE","Save") + '</span>').click(function () {
var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE", "Save") + '</span>').click(function () {
saveData(0);
});
func.append(btn);
@ -82,12 +83,18 @@ define(['common'], function (Common) {
tb.append(tr);
tr.append('<td class="label" style="vertical-align:middle;">' + GetTextByKey("P_IPT_DISPLAYTEXT_COLON", "Display Text:") + '<span class="redasterisk">*</span></td>');
displaytextcontrol = $('<input type="text" maxlength="200" autocomplete="off"/>');
addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_XXX", "Language Selection") + '"/>');
addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_LANGUAGESELECTION", "Language Selection") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(displaytextcontrol, _this.section);
});
tr.append($('<td></td>').append(displaytextcontrol).append(addiText));
tr = $('<tr></tr>');
tb.append(tr);
tr.append('<td class="label">' + GetTextByKey("P_IPT_DISPLAYONREPORT_COLON", "Display on Report:") + '</td>');
displayonreportcontrol = $('<input type="checkbox" />');
tr.append($('<td></td>').append(displayonreportcontrol));
tr = $('<tr></tr>');
tb.append(tr);
tr.append('<td class="label">' + GetTextByKey("P_IPT_NOTES_COLON", "Notes:") + '</td>');
@ -103,6 +110,10 @@ define(['common'], function (Common) {
namecontrol.val(section.Name).data("texts", section.LocalNames);
displaytextcontrol.val(section.DisplayText).data("texts", section.LocalDisplayTexts);
notescontrol.val(section.Notes);
displayonreportcontrol.attr('checked', section.DisplayOnReport);
}
else {
displayonreportcontrol.attr('checked', true);
}
}
@ -110,13 +121,15 @@ define(['common'], function (Common) {
namecontrol.prop('disabled', true);
displaytextcontrol.prop('disabled', true);
notescontrol.prop('disabled', true);
displayonreportcontrol.prop('disabled', true);
}
function getData() {
var item = {
'Name': namecontrol.val(),
'DisplayText': displaytextcontrol.val(),
'Notes': notescontrol.val()
'Notes': notescontrol.val(),
'DisplayOnReport': displayonreportcontrol.prop('checked')
};
var texts = namecontrol.data("texts");
if (texts) {
@ -129,17 +142,17 @@ define(['common'], function (Common) {
var alerttitle;
if (_this.section) {
item.Id = _this.section.Id;
alerttitle = GetTextByKey("P_IPT_EDITSECTION","Edit Section");
alerttitle = GetTextByKey("P_IPT_EDITSECTION", "Edit Section");
} else {
alerttitle = GetTextByKey("P_IPT_ADDSECTION","Add Section");
alerttitle = GetTextByKey("P_IPT_ADDSECTION", "Add Section");
}
if (!item.Name || item.Name.length == 0) {
showAlert(GetTextByKey("P_IPT_NAMENOTBEEMPTY",'Name cannot be empty.'), alerttitle);
showAlert(GetTextByKey("P_IPT_NAMENOTBEEMPTY", 'Name cannot be empty.'), alerttitle);
return false;
}
if (!item.DisplayText || item.DisplayText.length == 0) {
showAlert(GetTextByKey("P_IPT_DISPLAYTEXTNOTBEEMPTY",'Display Text cannot be empty.'), alerttitle);
showAlert(GetTextByKey("P_IPT_DISPLAYTEXTNOTBEEMPTY", 'Display Text cannot be empty.'), alerttitle);
return false;
}
@ -162,7 +175,7 @@ define(['common'], function (Common) {
_this.section = { 'Id': data[0] };
}
if (exit == 0) {
showAlert(GetTextByKey("P_IPT_SAVSUCCESSFULLY",'Saved successfully.'), alerttitle);
showAlert(GetTextByKey("P_IPT_SAVSUCCESSFULLY", 'Saved successfully.'), alerttitle);
_this.datasaved = true;
}
if (exit == 1) {
@ -171,7 +184,7 @@ define(['common'], function (Common) {
}
}
}, function (err) {
showAlert(GetTextByKey("P_IPT_FAILEDTOSAVESECTION",'Failed to save Section.'), alerttitle);
showAlert(GetTextByKey("P_IPT_FAILEDTOSAVESECTION", 'Failed to save Section.'), alerttitle);
});
}

View File

@ -0,0 +1,451 @@
define([], function () {
var allowConditionQuestions = [3, 4, 5, 8, 9, 11, 12, 19];
var dropdownType = 8;
var bannedLookupSources = [2, 3];
var fuelRecordsType = 15;
var numberQuestionTypes = [3, 4, 11, 12];
var integerQuestionTypes = [4];
var dropQuestionTypes = [5, 8, 9, 19];
var numberSubTypes = [8, 10, 11, 12];
var integerSubTypes = [10];
var dropSubTypes = [9];
var selectorChanged = function (id) {
var c = this.conditional;
c.QuestionId = id;
if (['-', 'or', 'and'].includes(id)) {
this.addbutton.show();
this.span.hide();
this.selector.css('width', 80);
} else {
c.SubItems = [];
this.addbutton.hide();
this.span.show();
this.selector.css('width', 150);
var pagemodule = this.wrapper.pagemodule;
var question;
for (var i = 0; i < pagemodule.sectionmodules.length; i++) {
var section = pagemodule.sectionmodules[i];
for (var j = 0; j < section.questionmodules.length; j++) {
var q = section.questionmodules[j].question;
if (q.Id == id) {
question = q;
}
}
}
if (question == null) {
return;
}
this.question = question;
var qtype = Number(question.QuestionType);
var stype = Number(question.SubType);
var isnumber = numberQuestionTypes.includes(qtype);
var isdrop = dropQuestionTypes.includes(qtype);
isnumber |= qtype == fuelRecordsType && numberSubTypes.includes(stype);
isdrop |= qtype == fuelRecordsType && dropSubTypes.includes(stype);
var operator = this.operator;
if (isnumber) {
operator.empty().attr('data-vtype', '0').append(
'<option value="eq">&#x3d;</option>',
'<option value="noteq">&lt;&gt;</option>',
'<option value="gt">&gt;</option>',
'<option value="gteq">&gt;&#x3d;</option>',
'<option value="lt">&lt;</option>',
'<option value="lteq">&lt;&#x3d;</option>',
$('<option value="between"></option>').text(GetTextByKey('P_CDH_BETWEEN', 'Between'))
);
if (c.Operator?.length > 0 && c.Operator !== 'in') {
operator.val(c.Operator).trigger('change');
} else {
operator.val(c.Operator = 'gt').trigger('change');
}
}
if (isdrop) {
operator.empty().attr('data-vtype', '1').append(
'<option value="eq">&#x3d;</option>',
'<option value="noteq">&lt;&gt;</option>',
$('<option value="in"></option>').text(GetTextByKey('P_CDH_IN', 'In'))
);
var op = c.Operator;
if (['eq', 'noteq', 'in'].includes(op)) {
operator.val(op).trigger('change');
} else {
operator.val(c.Operator = op = 'eq').trigger('change');
}
if (['eq', 'noteq'].includes(op) && (question.SelectItems?.length > 0 || question.QuestionType == 19)) {
var valueDrop = this.valueDrop;
if (question.QuestionType == 19) {
valueDrop.empty().append(
$('<option value="In Use"></option>').text(GetTextByKey('P_MA_INUSE', 'In Use')),
$('<option value="Available"></option>').text(GetTextByKey('P_MA_AVAILABLE', 'Available')),
$('<option value="Standby"></option>').text(GetTextByKey('P_MA_STANDBY', 'Standby')),
$('<option value="Down"></option>').text(GetTextByKey('P_MA_DOWN', 'Down'))
);
var r = String(c.Value);
if (['In Use', 'Available', 'Standby', 'Down'].includes(r)) {
valueDrop.val(r);
} else {
c.Value = 'In Use';
}
} else {
valueDrop.empty().append(
...question.SelectItems.map(function (it) {
return $('<option></option>').val(it.Text).text(it.Text);
})
);
var r = String(c.Value);
if (question.SelectItems.map(function (it) { return it.Text }).includes(r)) {
valueDrop.val(r);
} else {
var i0 = question.SelectItems[0];
c.Value = i0.Text;
}
}
}
}
}
if (typeof this.wrapper.onchanged === 'function') {
this.wrapper.onchanged(id);
}
};
var onAdded = function () {
var conditional = this.conditional;
if (this.selector.val() == '-') {
this.selector.val('or');
conditional.QuestionId = 'or';
}
var c = { SubItems: [] };
conditional.SubItems.push(c);
var item = new conditionalTree(this.wrapper, c);
var items = this.children;
items.push(item);
item.ondelete = function () {
var i = items.indexOf(this);
if (i >= 0) {
items.splice(i, 1);
}
i = conditional.SubItems.indexOf(this.conditional);
if (i >= 0) {
conditional.SubItems.splice(i, 1);
}
this.tree.remove();
};
this.container.append(item.tree);
item.refresh(true);
};
var onOperatorChanged = function (op, type) {
this.conditional.Operator = op;
if (type == '1') {
this.value2.hide();
// drop
if (['eq', 'noteq'].includes(op) && (this.question.SelectItems?.length > 0 || this.question.QuestionType == 19)) {
this.value1.hide();
this.valueDrop.show();
} else {
this.value1.show();
this.valueDrop.hide();
}
} else {
this.valueDrop.hide();
this.value1.show();
if (op == 'between') {
this.value2.show();
} else {
this.value2.hide();
}
}
};
var conditionalTree = function (obj, c, root) {
this.wrapper = obj;
this.conditional = c;
this.children = [];
this.isroot = root;
var This = this;
var tree = $('<div></div>').addClass(root ? 'conditional-item-root' : 'conditional-item');
var selector = $('<select style="width: 80px; height: 26px; border: 1px solid #a9a9a9; margin-left: 6px" class="question-input"></select>')
.on('change', function () { selectorChanged.call(This, this.value) });
if (root) {
selector.append('<option selected value="-">--</option>');
}
selector.append(
$('<option selected value="or"></option>').text(GetTextByKey('P_CDH_OR', 'OR')),
$('<option value="and"></option>').text(GetTextByKey('P_CDH_AND', 'AND'))
);
tree.append(selector);
this.tree = tree;
this.selector = selector;
var addbutton = $('<span class="spanbtn iconadd" style="font-size: 14px"></span>');
addbutton.on('click', onAdded.bind(this));
tree.append(addbutton);
this.addbutton = addbutton;
var span = $('<span style="display: none"></span>');
var operator = $('<select style="width: 80px; height: 26px; border: 1px solid #a9a9a9; margin-left: 4px" class="question-input"></select>')
.on('change', function () { onOperatorChanged.call(This, this.value, $(this).attr('data-vtype')) });
var value1 = $('<input type="text" class="question-input" maxlength="200" autocomplete="off" style="width: 130px; box-sizing: border-box; height: 26px"></input>')
.on('change', function () { c.Value = this.value });
var value2 = $('<input type="text" class="question-input" maxlength="200" autocomplete="off" style="display: none; width: 130px; margin-left: 4px; box-sizing: border-box; height: 26px"></input>')
.on('change', function () { c.Value1 = this.value });
var valueDrop = $('<select class="question-input" style="display: none; height: 26px; width: 130px; border: 1px solid #a9a9a9"></select>')
.on('change', function () { c.Value = this.value });
span.append(operator, $('<span style="margin-left: 4px"></span>').append(value1, value2, valueDrop));
tree.append(span);
this.span = span;
this.operator = operator;
this.value1 = value1;
this.value2 = value2;
this.valueDrop = valueDrop;
if (!root) {
var removebutton = $('<span class="spanbtn icondelete" style="font-size: 14px"></span>');
removebutton.on('click', function () {
if (typeof This.ondelete === 'function') {
This.ondelete();
}
});
tree.append(removebutton);
}
var container = $('<div style="padding-left: 20px; overflow-y: hidden"></div>');
tree.append(container);
this.container = container;
};
conditionalTree.prototype.fill = function () {
var conditional = this.conditional;
this.selector.val(conditional.QuestionId).trigger('change');
this.operator.val(conditional.Operator).trigger('change');
this.value1.val(conditional.Value);
this.value2.val(conditional.Value1);
this.valueDrop.val(conditional.Value);
var container = this.container;
container.empty();
var items = [];
this.children = items;
if (conditional.SubItems?.length > 0) {
for (var i = 0; i < conditional.SubItems.length; i++) {
var c = conditional.SubItems[i];
var item = new conditionalTree(this.wrapper, c);
items.push(item);
item.ondelete = function () {
var i = items.indexOf(this);
if (i >= 0) {
items.splice(i, 1);
}
i = conditional.SubItems.indexOf(this.conditional);
if (i >= 0) {
conditional.SubItems.splice(i, 1);
}
this.tree.remove();
};
container.append(item.tree);
item.refresh(true);
}
}
};
conditionalTree.prototype.refresh = function (force) {
if (!force && this.wrapper.initialized) {
return;
}
this.wrapper.initialized = true;
var idIndex = this.wrapper.module.idIndex;
var secs = this.wrapper.pagemodule.sectionmodules.map(function (s) {
var qs = s.questionmodules.filter(function (q) {
return (
allowConditionQuestions.includes(Number(q.question.QuestionType)) ||
(q.question.QuestionType == fuelRecordsType && numberSubTypes.concat(dropSubTypes).includes(Number(q.question.SubType)))
) &&
idIndex > q.idIndex &&
(q.question.QuestionType != dropdownType || !bannedLookupSources.includes(Number(q.question.LookupSource)))
});
return qs.length > 0 && $('<optgroup></optgroup>').attr('label', s.section.DisplayText || s.section.Name).append(
...qs.map(function (q) {
return $('<option></option>').val(q.question.Id).text(`#${q.idIndex} - ${q.txtDisplayText?.val() || q.question.DisplayText || q.question.Name}`);
})
);
}).filter(function (s) { return s });
this.selector.children('optgroup').remove();
this.selector.append(...secs);
// fill selected
if (this.conditional.QuestionId == null) {
if (this.isroot) {
this.conditional.QuestionId = '-';
} else if (secs.length > 0) {
var f = secs[0].children('option')?.[0];
if (f != null) {
this.conditional.QuestionId = f.value;
}
}
if (this.conditional.QuestionId == null) {
this.conditional.QuestionId = 'or';
}
this.selector.val(this.conditional.QuestionId).trigger('change');
} else if (this.conditional.QuestionId?.length > 0) {
setTimeout(this.fill.bind(this), 10);
}
};
var conditionalWrapper = function (module, key, pagemodule) {
this.module = module;
this.key = key;
this.pagemodule = pagemodule;
var conditional = module.conditional;
if (conditional == null) {
conditional = module[key].Conditional;
}
if (conditional == null) {
conditional = { SubItems: [] };
}
module.conditional = conditional;
var root = new conditionalTree(this, conditional, true);
this.root = root;
};
conditionalWrapper.prototype.refresh = function () {
this.root.refresh();
};
Object.defineProperty(conditionalWrapper.prototype, 'tree', {
get: function () {
return this.root.tree;
}
});
conditionalWrapper.prototype.init = function () {
var idIndex = this.module.idIndex;
var array = this.pagemodule.sectionmodules.reduce(function (array, s) {
return array.concat(s.questionmodules.filter(function (q) {
return (
allowConditionQuestions.includes(Number(q.question.QuestionType)) ||
(q.question.QuestionType == fuelRecordsType && numberSubTypes.concat(dropSubTypes).includes(Number(q.question.SubType)))
) &&
idIndex > q.idIndex &&
(q.question.QuestionType != dropdownType || !bannedLookupSources.includes(Number(q.question.LookupSource)))
}));
}, []);
return array.length > 0;
};
conditionalWrapper.prototype.getConditional = function (nocheck, alerttitle) {
var module = this.module;
var conditional = module.conditional;
if (conditional != null) {
var questionTitle = '#' + module.idIndex + ' - ' + module[this.key].DisplayText + '\n\n';
var questions = this.pagemodule.sectionmodules.reduce(function (array, s) {
return array.concat(s.questionmodules.map(function (q) { return q }));
}, []);
var checkConditional = function (c) {
if (c.QuestionId == null || c.QuestionId == '-') {
if (c.SubItems?.length > 0) {
showAlert(questionTitle + GetTextByKey('P_CDH_MUSTBEORAND', 'If there are child nodes, the root must be "OR" or "AND".'), alerttitle);
return false;
}
return 'null';
} else if (c.QuestionId == 'or' || c.QuestionId == 'and') {
if (c.SubItems == null || c.SubItems.length == 0) {
showAlert(questionTitle + GetTextByKey('P_CDH_NOSUBITEMS', 'When the parent node is "OR" or "AND", the child node cannot be empty.'), alerttitle);
return false;
}
for (var i = c.SubItems.length - 1; i >= 0; i--) {
var sub = c.SubItems[i];
var result = checkConditional(sub);
if (result === false) {
return false;
} else if (result === 'null') {
c.SubItems.splice(i, 1);
}
}
if (c.SubItems.length === 0) {
return 'null';
}
} else {
var qmodule = questions.find(function (q) { return q.question.Id == c.QuestionId });
var q = qmodule?.question;
if (q == null) {
showAlert(questionTitle + GetTextByKey('P_CDH_NOTFOUNDQUESTION', 'Could not find the specified question: {name}.').replace('{name}', c.QuestionId), alerttitle);
return false;
}
var qname = q.DisplayText || q.Name;
if (c.Operator == null || c.Operator.length == 0) {
showAlert(questionTitle + GetTextByKey('P_CDH_INVALIDOPERATOR', 'Invalid operator of question: {name}.').replace('{name}', qname), alerttitle);
return false;
}
if (c.Value == null || c.Value.length == 0) {
showAlert(questionTitle + GetTextByKey('P_CDH_VALUEREQUIRED', 'The conditional value is required of question: {name}.').replace('{name}', qname), alerttitle);
return false;
}
if (c.Operator == 'between' && (c.Value1 == null || c.Value1.length == 0)) {
showAlert(questionTitle + GetTextByKey('P_CDH_VALUE2REQUIRED', 'If the operator is "Between", both of the values are required of question: {name}.').replace('{name}', qname), alerttitle);
return false;
}
// validate question index
if (qmodule.idIndex > module.idIndex) {
showAlert(questionTitle + GetTextByKey('P_CDH_INVALIDQUESTION', 'You can only set a previous question to be a conditional one: {name}.').replace('{name}', qname), alerttitle);
return false;
return 'null';
}
// validate question value
var qtype = Number(q.QuestionType);
var stype = Number(q.SubType);
var isnumber = numberQuestionTypes.includes(qtype);
var isdrop = dropQuestionTypes.includes(qtype);
isnumber |= qtype == fuelRecordsType && numberSubTypes.includes(stype);
isdrop |= qtype == fuelRecordsType && dropSubTypes.includes(stype);
if (isnumber) {
var nvalue = Number(c.Value);
var n2value = Number(c.Value1);
if (isNaN(nvalue)) {
showAlert(questionTitle + GetTextByKey('P_CDH_ISVALUENAN', 'Invalid number of question: {name}.').replace('{name}', qname), alerttitle);
return false;
}
if (c.Operator == 'between' && isNaN(n2value)) {
showAlert(questionTitle + GetTextByKey('P_CDH_ISVALUE2NAN', 'Invalid end number of question: {name}.').replace('{name}', qname), alerttitle);
return false;
}
if (integerQuestionTypes.includes(qtype) || (qtype == fuelRecordsType && integerSubTypes.includes(stype))) {
// integer
if (Math.floor(nvalue) != nvalue) {
showAlert(questionTitle + GetTextByKey('P_CDH_ISVALUENOTINTEGER', 'Invalid integer of question: {name}.').replace('{name}', q.DisplayText || q.Name), alerttitle);
return false;
}
if (c.Operator == 'between' && Math.floor(n2value) != n2value) {
showAlert(questionTitle + GetTextByKey('P_CDH_ISVALUE2NOTINTEGER', 'Invalid end integer of question: {name}.').replace('{name}', q.DisplayText || q.Name), alerttitle);
return false;
}
}
if (c.Operator == 'between' && n2value < nvalue) {
showAlert(questionTitle + GetTextByKey('P_CDH_INVALIDVALUERANGE', 'The end number must be greater than or equal to the start number of question: {name}.').replace('{name}', qname), alerttitle);
return false;
}
} else if (!isdrop) {
//showAlert(questionTitle + 'The question type is not supported: ' + qname + '.', alerttitle);
//return false;
return 'null';
}
}
};
if (nocheck) {
if (conditional != null && conditional.QuestionId == null && conditional.SubItems?.length == 0) {
return null;
}
return conditional;
} else {
var result = checkConditional(conditional);
if (result === false) {
return false;
}
return result === 'null' ? null : conditional;
}
}
return null;
};
return conditionalWrapper;
})

View File

@ -48,7 +48,7 @@
tb.append(tr);
var optext = $('<input type="text" class="form-control" style="width:226px;margin-left:5px;"/>');
this.dialog_text = optext;
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(optext);
});

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"));
});

View File

@ -1,14 +1,32 @@
define(['modules/sections/question', 'modules/sections/addsection', 'modules/sections/addquestion', 'common', 'modules/templates/picture']
, function (Question, AddSection, AddQuestion, Common, Picture) {
var s = function (section, gsm, pm) {
define(['modules/sections/question', 'modules/sections/addsection', 'modules/sections/addquestion', 'modules/sections/conditional', 'common', 'modules/templates/picture']
, function (Question, AddSection, AddQuestion, ConditionalTree, Common, Picture) {
var s = function (section, gsm, pm, index) {
this.section = section;
this.content = null;
this.holder = null;
this.gsmodule = gsm;
this.pagemodule = pm;
if (pm != null) {
if (isNaN(index)) {
index = pm.page.Sections.length - 1;
}
this.index = index;
// calc id index
var idIndex = 1;
var ss = pm.page.Sections;
for (var i = 0; i < index; i++) {
idIndex += ss[i].Questions.length;
}
this.idIndex = idIndex;
} else {
this.index = index;
}
this.txtName = null;
this.txtDisplayText = null;
this.displayonreportcontrol = null;
this.conditionholder = null;
this.btncondition = null;
if (!this.section.Questions)
this.section.Questions = [];
@ -22,23 +40,25 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
s.prototype.createContent = function () {
var content = $('<div></div>');
this.content = content;
var div = $('<div class="sectionitem"></div>');
var holder = $('<div class="section-holder"></div>');
content.append(holder);
var _this = this;
if (sectiontype === 0) {
if (!_this.section.IssueId || _this.section.IssueId == "")
editable = true;
else
editable = false;
div.append(holder);
var isGlobal = this.pagemodule == null;
if (!isGlobal) {
var cholder = $('<div style="display: none"></div>'); // conditional hierarchy holder
div.append(cholder);
this.conditionholder = cholder;
}
content.append(div);
var _this = this;
if (sectiontype === 0) {
var package = $('<div class="question-icon section-packages" style="width:30px;padding-left:10px;"><em class="fa icon-menu icon-packages"></em></div>');
var package = $('<div class="question-icon section-packages" style="width:30px;"><em class="spanbtn icon-packages" style="font-size:16px;"></em></div>');
holder.append(package);
}
if (sectiontype == 1) {
var drag = $('<div class="question-icon" style="width:30px;" title="' + GetTextByKey("P_IPT_XXX","Move Section") + '"><em class="spanbtn iconmove rowdrag"></em></div>');
var drag = $('<div class="question-icon" style="width:30px;" title="' + GetTextByKey("P_IPT_MOVESECTION", "Move Section") + '"><em class="spanbtn iconmove rowdrag"></em></div>');
holder.append(drag);
if (sectiontype == 1) {
drag.attr('draggable', true);
@ -102,21 +122,21 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
}
});
holder.append(btnsection);
this.txtName = $('<input type="text" class="section-input" maxlength="100" autocomplete="off" style="width:156px;" />');
this.txtName = $('<input type="text" class="section-input" maxlength="100" autocomplete="off" style="width:191px;" />');
this.txtName.change(function () {
_this.onsave();
});
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.section);
});
holder.append($('<div class="section-cell section-name" style="width:200px;flex-grow:0;"></div>').append(this.txtName).append(addiText));
holder.append($('<div class="section-cell section-name" style="width:235px;flex-grow:0;"></div>').append(this.txtName).append(addiText));
this.txtDisplayText = $('<input type="text" class="section-input" maxlength="200" autocomplete="off" style="width:236px;" />');
this.txtDisplayText.change(function () {
_this.onsave();
});
addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_XXX", "Language Selection") + '"/>');
addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_LANGUAGESELECTION", "Language Selection") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(_this.txtDisplayText, _this.section);
});
@ -125,11 +145,55 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
var picturemodule = new Picture(false, _this.section, function () { _this.onsave() });
picturemodule.createContent();
});
holder.append($('<div class="section-cell section-display" style="width:230px;flex-grow: 1;"><span></span></div>').append(this.txtDisplayText).append(addiText).append(imgicon));
if (sectiontype === 0)
holder.append($('<div class="section-cell section-createdby" style="text-align:center;"><span></span></div>'));
var funcs = $('<div class="section-cell section-func" style="width: 120px;text-align:right;padding-right:20px;"></div>');
holder.append($('<div class="section-cell section-display" style="flex-grow: 0;"><span></span></div>').css('width', isGlobal ? 680 : 425).append(this.txtDisplayText).append(addiText).append(imgicon));
this.displayonreportcontrol = $('<input type="checkbox" />')
.attr('title', GetTextByKey("P_IPT_SECITONDISPLAYONREPORTTIPS", 'Checked indicates that the section breakout \n will appear on the final report.\n\n Unchecked indicates that the section is only \n visible during inspection completion.'));
this.displayonreportcontrol.change(function () {
_this.onsave();
});
if (!isGlobal) {
var tb = (function () {
var tb = $('<table style="line-height:unset;"></table>');
var tr = $('<tr></tr>');
tb.append(tr);
var 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();
}
});
return tb;
})();
holder.append($('<div class="section-cell" style="width: 255px; flex-grow: 0"></div>').append(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, 'section', _this.pagemodule);
_this.conditionalTree = root;
div.append(root.tree);
})();
}
holder.append($('<div class="section-cell section-displayonreport" style="width:80px;text-align:center;flex-grow:0;"></div>').append(this.displayonreportcontrol));
holder.append($('<div style="min-width:265px;flex-grow:1;"></div>'));//ռλ
var funcs = $('<div class="section-cell section-func" style="width: 160px;text-align:right;padding-right:20px;"></div>');
holder.append(funcs);
//holder.find('.section-name span').click(function () {
@ -163,7 +227,19 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
// }
// $('#right_popup1').empty().append(aq.createContent()).show();
//}
var question = { QuestionType: '0', IsRequired: false, CanComment: false, IsImportant: false, SeverityLevel: 0, LookupSource: 0, SelectItems: [] };
var question = {
_isadd: true,
QuestionType: '0',
IsRequired: false,
CanComment: false,
IsImportant: false,
SeverityLevel: 0,
LookupSource: 0,
SelectItems: []
};
if (!isGlobal) {
question.Id = $.generateUUID();
}
_this.section.Questions.push(question);
_this.addQuestionModule(question);
}).attr('title', GetTextByKey("P_IPT_ADDQUESTION", 'Add Question')));
@ -207,6 +283,7 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
if (templatereadonly || !editable) {
this.txtName.prop('disabled', true);
this.txtDisplayText.prop('disabled', true);
this.displayonreportcontrol.prop('disabled', true);
this.holder.find(".iconmultitext").hide();
this.holder.find(".iconimage").hide();
@ -236,23 +313,29 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
s.prototype.updateContent = function (section) {
if (section) {
if (sectiontype === 0) {
if (!section.IssueId || section.IssueId == "") {
if (!section.IssueId || section.IssueId == "")
this.holder.find('.section-packages em').hide();
this.holder.find('.section-createdby span').text('');
}
else {
else
this.holder.find('.section-packages em').show();
this.holder.find('.section-createdby span').text(section.IssueName);
}
}
this.txtName.val(section.Name).data("texts", section.LocalNames);
this.txtDisplayText.val(section.DisplayText).data("texts", section.LocalDisplayTexts);;
this.txtDisplayText.val(section.DisplayText).data("texts", section.LocalDisplayTexts);
if (this.btncondition != null) {
if (section.Conditional != null) {
this.btncondition.addClass('iconexists');
} else {
this.btncondition.removeClass('iconexists');
}
}
this.displayonreportcontrol.attr('checked', section.DisplayOnReport);
}
};
s.prototype.getSectionValue = function (noalert, nocheck) {
var section = this.section;
section.Name = this.txtName.val();
section.DisplayText = this.txtDisplayText.val();
section.DisplayOnReport = this.displayonreportcontrol.prop('checked');
var alerttitle = GetTextByKey("P_IPT_SECTION", "Section");
if (!nocheck) {
if (!section.Name || section.Name.length == 0) {
@ -282,6 +365,11 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
section.Questions.push(q);
}
}
var conditional = this.conditionalTree?.getConditional(nocheck, alerttitle);
if (conditional === false) {
return false;
}
section.Conditional = conditional;
return section;
};
s.prototype.updateQuestions = function (questions) {
@ -291,10 +379,11 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
this.questionmodules = [];
this.content.children('.question-holder').remove();
for (var i = 0; i < questions.length; i++) {
this.addQuestionModule(questions[i]);
this.addQuestionModule(questions[i], true);
}
this.pagemodule?.refreshIdIndex();
};
s.prototype.addQuestionModule = function (q) {
s.prototype.addQuestionModule = function (q, init) {
var _this = this;
if (this.section.IsLink)
q.IsLink = true;
@ -305,13 +394,21 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
qmodule.ondelete = function (qm) {//qm:question module
_this.section.Questions.splice(_this.section.Questions.indexOf(qm.question), 1);
_this.questionmodules.splice(_this.questionmodules.indexOf(qm), 1);
_this.pagemodule?.refreshIdIndex();
}
this.questionmodules.push(qmodule);
this.content.append(qmodule.createContent());
if (!init) {
this.pagemodule?.refreshIdIndex();
}
};
s.prototype.oncopyquestion = function (question) {
question = JSON.parse(JSON.stringify(question));
question.Id = "";
question._isadd = true;
if (this.pagemodule != null) {
question.Id = $.generateUUID();
}
question.Conditional = null;
//question.IsLink = false;
//question.ReferenceId = "";
if (!this.section.Questions)
@ -366,6 +463,7 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
if (this.section.Questions.length == 0) {
this.section.Questions.push(qm.question);
this.questionmodules.push(qm);
this.pagemodule?.refreshIdIndex();
return;
}
var tindex = 0;
@ -377,6 +475,7 @@ define(['modules/sections/question', 'modules/sections/addsection', 'modules/sec
if (tindex >= 0) {
this.section.Questions.splice(tindex, 0, qm.question);
this.questionmodules.splice(tindex, 0, qm);
this.pagemodule?.refreshIdIndex();
}
};
s.prototype.dragInSection = function () {//called when section dragged end at question