').css('width', isGlobal ? 680 : 425).append(this.txtDisplayText).append(addiText).append(imgicon));
this.displayonreportcontrol = $('')
.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 = $('
');
var tr = $('
');
tb.append(tr);
var td = $('
');
tr.append(td);
_this.btncondition = $('');
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($('').append(tb));
!(function createConditionHierarchy() {
var div = $('');
_this.conditionholder.append(div);
div.append($('').text(GetTextByKey('P_IPT_CONDITIONHIERARCHY', 'Condition Hierarchy')));
var root = new ConditionalTree(_this, 'section', _this.pagemodule);
_this.conditionalTree = root;
div.append(root.tree);
})();
}
holder.append($('').append(this.displayonreportcontrol));
holder.append($(''));//ռλ
var funcs = $('');
holder.append(funcs);
//holder.find('.section-name span').click(function () {
// _this.onedit();
//});
//holder.find('.section-display span').click(function () {
// _this.onedit();
//});
if (_this.section.IsLink) {
holder.find('.section-name input').before('');
holder.find('input').prop('disabled', true);
holder.find('.iconmultitext').remove();
holder.find('.iconimage').remove();
}
if (!templatereadonly && editable) {
if (!_this.section.IsLink) {
funcs.append($('').click(function () {
//var aq = new AddQuestion(_this, _this.section.Id);
//if (sectiontype == 0) {
// $('#right_popup').empty().append(aq.createContent());
// showRightPopup(true);
//}
//else {
// aq.onsave = function (question) {
// if (!_this.section.Questions)
// _this.section.Questions = [];
// _this.section.Questions.push(question);
// _this.updateQuestions(_this.section.Questions);
// }
// $('#right_popup1').empty().append(aq.createContent()).show();
//}
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')));
}
if (sectiontype == 1 && !_this.section.IsLink) {
funcs.append($('').click(function () {
if (_this.oncopy)
_this.oncopy(_this.getSectionValue(true, true));
}).attr('title', GetTextByKey("P_IPT_COPYSECTION", 'Copy Section')));
}
//if (!_this.section.IsLink) {
// funcs.append($('').click(function () {
// _this.onedit();
// }).attr('title', 'Edit Section'));
//}
}
if ((sectiontype === 0 && !templatereadonly) || (sectiontype === 1 && !templatereadonly && editable)) {
funcs.append($('').click(function () {
if (sectiontype == 0) {
_this.delete();
}
else {
showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISSECTION", 'Are you sure you want to delete this section?'), GetTextByKey("P_IPT_DELETESECTION", 'Delete Section'), function () {
if (_this.ondelete) {
_this.content.remove();
_this.ondelete(_this);
}
});
}
}).attr('title', GetTextByKey("P_IPT_DELETESECTION", 'Delete Section')));
}
this.holder = holder;
this.updateContent(this.section);
if (sectiontype == 1)
btnsection.click();
//this.holder.find('input').attr('draggable', true).bind('dragstart', function (e) {//½ûÖ¹ÊäÈë¿òÍ϶¯
// e.originalEvent.preventDefault();
//});
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();
}
return content;
};
s.prototype.onedit = function () {
var _this = this;
var s = new AddSection(_this.gsmodule, _this.section);
if (sectiontype == 0) {
$('#right_popup').empty().append(s.createContent());
showRightPopup(true);
}
else {
s.onsave = function (section) {
_this.section.Name = section.Name;
_this.section.DisplayText = section.DisplayText;
_this.section.Notes = section.Notes;
_this.section.LocalNames = section.LocalNames;
_this.section.LocalDisplayTexts = section.LocalDisplayTexts;
_this.updateContent(_this.section);
}
$('#right_popup1').empty().append(s.createContent()).show();
}
}
s.prototype.updateContent = function (section) {
if (section) {
if (sectiontype === 0) {
if (!section.IssueId || section.IssueId == "")
this.holder.find('.section-packages em').hide();
else
this.holder.find('.section-packages em').show();
}
this.txtName.val(section.Name).data("texts", section.LocalNames);
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) {
if (!noalert)
showAlert(GetTextByKey("P_IPT_SETIONNAMENOTBEEMPTY", 'Section Name cannot be empty.'), alerttitle);
return false;
}
if (!section.DisplayText || section.DisplayText.length == 0) {
if (!noalert)
showAlert(GetTextByKey("P_IPT_SECTIONDISPLAYTEXTNOTBEEMPTY", 'Section Display Text cannot be empty.'), alerttitle);
return false;
}
}
var texts = this.txtName.data("texts");
if (texts) {
section.LocalNames = texts;
}
texts = this.txtDisplayText.data("texts");
if (texts) {
section.LocalDisplayTexts = texts;
}
section.Questions = [];
if (this.questionmodules.length > 0) {
for (var i = 0; i < this.questionmodules.length; i++) {
var q = this.questionmodules[i].getQuestionValue(noalert, nocheck);
if (!q) return false;
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) {
if (questions == null) {
return;
}
this.questionmodules = [];
this.content.children('.question-holder').remove();
for (var i = 0; i < questions.length; i++) {
this.addQuestionModule(questions[i], true);
}
this.pagemodule?.refreshIdIndex();
};
s.prototype.addQuestionModule = function (q, init) {
var _this = this;
if (this.section.IsLink)
q.IsLink = true;
var qmodule = new Question(this, q, this.section.Questions.indexOf(q));
qmodule.oncopy = function (question) {
_this.oncopyquestion(question);
}
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._isadd = true;
if (this.pagemodule != null) {
question.Id = $.generateUUID();
}
question.Conditional = null;
//question.IsLink = false;
//question.ReferenceId = "";
if (!this.section.Questions)
this.section.Questions = [];
this.section.Questions.push(question);
this.addQuestionModule(question);
};
s.prototype.getQuestions = function () {
var _this = this;
var p = JSON.stringify([teamintelligence, htmlencode(this.section.Id)]);
inspectionrequest("GetGlobalQuestions", p, function (data) {
if (data) {
_this.section.Questions = data;
_this.content.children('.questionitem').remove();
_this.updateQuestions(data);
}
}, function (err) {
});
};
s.prototype.delete = function () {
var _this = this;
showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISSECTION", 'Are you sure you want to delete this section?'), GetTextByKey("P_IPT_DELETESECTION", 'Delete Section'), function () {
var p = JSON.stringify([teamintelligence, htmlencode(_this.section.Id)]);
inspectionrequest("DeleteGlobalSection", p, function (data) {
if (data !== 'OK')
showAlert(data, GetTextByKey("P_IPT_DELETESECTION", 'Delete Section'));
else if (_this.gsmodule && typeof _this.gsmodule.refresh === "function")
_this.gsmodule.refresh();
}, function (err) {
showAlert(GetTextByKey("P_IPT_FAILEDTODELETESECTION", 'Failed to delete section.'), GetTextByKey("P_IPT_DELETESECTION", 'Delete Section'));
});
});
};
s.prototype.refresh = function () {
var icon = this.content.find('.spanbtn');
if (icon.hasClass('iconangledown')) {
this.getQuestions();
}
};
s.prototype.dragOutQuestion = function (qm) {//called when question dragged end at question
var index = this.section.Questions.indexOf(qm.question)
if (index >= 0) {
this.section.Questions.splice(index, 1);
this.questionmodules.splice(index, 1);
}
};
s.prototype.dragInQuestion = function (target, qm, after) {//called when question dragged end at question
qm.sectionmodule = this;
qm.section = this.section;
if (!this.section.Questions)
this.section.Questions = [];
if (this.section.Questions.length == 0) {
this.section.Questions.push(qm.question);
this.questionmodules.push(qm);
this.pagemodule?.refreshIdIndex();
return;
}
var tindex = 0;
if (target) {
tindex = this.section.Questions.indexOf(target);
if (after)
tindex = tindex + 1;
}
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
this.holder.parent().after(draggingobj.holder.parent());
draggingobj.pagemodule.dragOutSection(draggingobj);
this.pagemodule.dragInSection(this.section, draggingobj, true);
};
s.prototype.onsave = function () {
if (sectiontype == 1) return;
var item = this.getSectionValue(true);
if (!item) return;
var param = JSON.stringify(item);
param = htmlencode(param);
var p = JSON.stringify([teamintelligence, param]);
var _this = this;
inspectionrequest("SaveGlobalSection", p, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_IPT_SAVESECTION", 'Save Section'));
}
else {
if (!_this.section)
_this.section = {};
_this.section.Id = data[0];
}
}, function (err) {
showAlert(GetTextByKey("P_IPT_FAILEDTOSAVESECTION", 'Failed to save Section.'), GetTextByKey("P_IPT_SAVESECTION", 'Save Section'));
});
}
return s;
});