add site
This commit is contained in:
313
Site/Inspection/js/modules/templates/page.js
Normal file
313
Site/Inspection/js/modules/templates/page.js
Normal file
@ -0,0 +1,313 @@
|
||||
define(['modules/sections/section', 'modules/sections/addsection', 'common', 'modules/templates/linksection'], function (Section, AddSection, Common, LinkSection) {
|
||||
var p = function (page, pagesmodule) {
|
||||
this.page = page || {};
|
||||
this.pagesmodule = pagesmodule;
|
||||
this.namecontrol = undefined;
|
||||
this.displaytextcontrol = undefined;
|
||||
this.notescontrol = undefined;
|
||||
this.onNameChanged = undefined;
|
||||
this.datacontent = null;
|
||||
|
||||
this.sectionmodules = [];
|
||||
};
|
||||
p.prototype.description = "Page";
|
||||
p.prototype.version = "1.0.0.0";
|
||||
|
||||
p.prototype.createContent = function () {
|
||||
var _this = this;
|
||||
var content = $('<div></div>');
|
||||
|
||||
function createPageContent() {
|
||||
var div_main = $('<div class="content_main"></div>');
|
||||
var div_content = $('<div class="edit-content"></div>');
|
||||
div_main.append(div_content);
|
||||
var tb = $('<table></table>');
|
||||
div_content.append(tb);
|
||||
|
||||
var tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:154px;">' + GetTextByKey("P_IPT_NAME_COLON", "Name:") + '<span class="redasterisk">*</span></td>');
|
||||
_this.namecontrol = $('<input type="text" class="form-control" maxlength="100" autocomplete="off"/>');
|
||||
var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>');
|
||||
addiText.click(function () {
|
||||
Common.createMultiTextDialog(_this.namecontrol);
|
||||
});
|
||||
tr.append($('<td style="white-space:nowrap;"></td>').append(_this.namecontrol).append(addiText));
|
||||
_this.namecontrol.change(function () {
|
||||
if (_this.onNameChanged)
|
||||
_this.onNameChanged($.trim(_this.namecontrol.val()))
|
||||
})
|
||||
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:154px;">' + GetTextByKey("P_IPT_NOTES_COLON", "Notes:") + '</td>');
|
||||
_this.notescontrol = $('<textarea id="dialog_notes" class="inputbox form-control" maxlength="500" autocomplete="off" style="width: 540px; margin-top:6px;height:55px;"></textarea>');
|
||||
tr.append($('<td rowspan="2"></td>').append(_this.notescontrol));
|
||||
|
||||
tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:154px;">' + GetTextByKey("P_IPT_DISPLAYTEXT_COLON", "Display Text:") + '<span class="redasterisk">*</span></td>');
|
||||
_this.displaytextcontrol = $('<input type="text" class="form-control" maxlength="200" autocomplete="off"/>');
|
||||
addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>');
|
||||
addiText.click(function () {
|
||||
Common.createMultiTextDialog(_this.displaytextcontrol);
|
||||
});
|
||||
tr.append($('<td style="white-space:nowrap;"></td>').append(_this.displaytextcontrol).append(addiText));
|
||||
|
||||
var sectioncontent = createSectionContent();
|
||||
div_main.append(sectioncontent);
|
||||
return div_main;
|
||||
}
|
||||
|
||||
function createSectionContent() {
|
||||
var content = $('<div style="min-width:1820px;"></div>');
|
||||
|
||||
function createSectionHeader() {
|
||||
var header = $('<div></div>');
|
||||
//header.append($('<div class="page_title"></div>').text(gs.title));
|
||||
var func = $('<div class="function_title"></div>');
|
||||
var iconAdd = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADD", "Add") + '</span>').click(function () {
|
||||
//var s = new AddSection();
|
||||
//s.onsave = function (section) {
|
||||
// _this.page.Sections.push(section);
|
||||
// updateContent(true);
|
||||
//}
|
||||
//$('#right_popup1').empty().append(s.createContent()).show();
|
||||
var section = {};
|
||||
_this.page.Sections.push(section);
|
||||
addSectionModule(section);
|
||||
});
|
||||
func.append(iconAdd);
|
||||
var iconRefresh = $('<span class="sbutton iconlink">' + GetTextByKey("P_ADDGLOBALSECTION", "Add Global Section") + '</span>').click(function () {
|
||||
addGlobalSection();
|
||||
});
|
||||
func.append(iconRefresh);
|
||||
header.append(func)
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
if (!templatereadonly && editable)
|
||||
content.append(createSectionHeader());
|
||||
|
||||
var dataheader = $('<div class="question-holder no-hover" style="font-weight: bold;font-size:14px;"></div>');
|
||||
dataheader.append('<div style="width: 60px; flex-shrink: 0"></div>');
|
||||
dataheader.append('<div class="question-cell" style="width: 200px">' + GetTextByKey("P_IPT_NAME", "Name") + '</div>');
|
||||
dataheader.append('<div class="question-cell" style="width: 310px">' + GetTextByKey("P_IPT_DISPLAYTEXT", "Display Text") + '</div>');
|
||||
dataheader.append('<div class="question-cell" style="width: 400px">' + GetTextByKey("P_IPT_TYPE", "Type") + '</div>');
|
||||
dataheader.append('<div class="question-cell" style="width: 80px; text-align: center">' + GetTextByKey("P_IPT_REQUIRED", "Required") + '</div>');
|
||||
dataheader.append('<div class="question-cell" style="width: 100px; text-align: center">' + GetTextByKey("P_IPT_CANCOMMENT", "Can Comment") + '</div>');
|
||||
dataheader.append('<div class="question-cell" style="width: 100px; text-align: center">' + GetTextByKey("P_IPT_ISIMPORTANT", "Is Important") + '</div>');
|
||||
dataheader.append('<div class="question-cell" style="width: 140px">' + GetTextByKey("P_IPT_CUSTOMERVISIBLE", "Customer Visible") + '</div>');
|
||||
dataheader.append('<div class="question-cell" style="width: 140px">' + GetTextByKey("P_IPT_SEVERITYLEVEL", "Severity Level") + '</div>');
|
||||
dataheader.append('<div style="flex-grow: 1" style="width: 160px">' + GetTextByKey("P_IPT_ST_NOTES", "Notes") + '</div>');
|
||||
dataheader.append('<div class="question-cell" style="width: 90px;padding-right:20px;"></div>');
|
||||
content.append(dataheader);
|
||||
|
||||
_this.datacontent = $('<div></div>');
|
||||
content.append(_this.datacontent);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
function updateContent(sectiononly) {
|
||||
if (!sectiononly) {
|
||||
_this.namecontrol.val(_this.page.Name).data("texts", _this.page.LocalNames);
|
||||
_this.displaytextcontrol.val(_this.page.DisplayText).data("texts", _this.page.LocalDisplayTexts);
|
||||
_this.notescontrol.val(_this.page.Notes);
|
||||
}
|
||||
|
||||
if (_this.page.Sections) {
|
||||
_this.sectionmodules = [];
|
||||
_this.datacontent.empty();
|
||||
for (var i = 0; i < _this.page.Sections.length; i++) {
|
||||
//var s = new Section(_this.page.Sections[i], null, _this);
|
||||
addSectionModule(_this.page.Sections[i]);
|
||||
}
|
||||
} else
|
||||
_this.page.Sections = [];
|
||||
}
|
||||
|
||||
function addSectionModule(s) {
|
||||
var sectionmodule = new Section(s, null, _this);
|
||||
sectionmodule.oncopy = function (section) {
|
||||
section = JSON.parse(JSON.stringify(section));
|
||||
section.Id = "";
|
||||
if (!section.IsLink && section.Questions) {
|
||||
for (var j = 0; j < section.Questions.length; j++) {
|
||||
section.Questions[j].Id = "";
|
||||
}
|
||||
}
|
||||
_this.page.Sections.push(section);
|
||||
addSectionModule(section);
|
||||
};
|
||||
sectionmodule.ondelete = function (sm) {
|
||||
_this.page.Sections.splice(_this.page.Sections.indexOf(sm.section), 1);
|
||||
_this.sectionmodules.splice(_this.sectionmodules.indexOf(sm), 1);
|
||||
}
|
||||
_this.sectionmodules.push(sectionmodule);
|
||||
_this.datacontent.append(sectionmodule.createContent());
|
||||
}
|
||||
|
||||
function setDisabled() {
|
||||
_this.namecontrol.prop('disabled', true);
|
||||
_this.displaytextcontrol.prop('disabled', true);
|
||||
_this.notescontrol.prop('disabled', true);
|
||||
|
||||
content.find(".iconmultitext").hide();
|
||||
content.find(".iconimage").hide();
|
||||
}
|
||||
|
||||
function addGlobalSection() {//<2F><><EFBFBD><EFBFBD>Global Section
|
||||
var dialogSection = new LinkSection().getDialogSection();
|
||||
|
||||
dialogSection.onDialogClosed = function () {
|
||||
}
|
||||
dialogSection.onOK = function (sections, iscopy) {
|
||||
if (!iscopy) {
|
||||
var linkedSectionIds = [];
|
||||
if (_this.pagesmodule && _this.pagesmodule.pages) {
|
||||
for (var i = 0; i < _this.pagesmodule.pages.length; i++) {
|
||||
var page = _this.pagesmodule.pages[i];
|
||||
if (page.Sections) {
|
||||
for (var j = 0; j < page.Sections.length; j++) {
|
||||
var s = page.Sections[j];
|
||||
if (s.IsLink)
|
||||
linkedSectionIds.push(s.ReferenceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sections && sections.length > 0) {
|
||||
for (var i = 0; i < sections.length; i++) {
|
||||
var it = sections[i].Values;
|
||||
if (it.Selected && linkedSectionIds.indexOf(it.Id) >= 0) {
|
||||
showAlert(GetTextByKey("P_IPT_ALREADYLINKED", '{0} has already been linked to current template.').replace("{0}", it.Name), GetTextByKey("P_ADDGLOBALSECTION", "Add Global Section"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onAddGlobalSection(sections, iscopy);
|
||||
}
|
||||
|
||||
//var sections = [];
|
||||
//for (var i = 0; i < _this.page.Sections.length; i++) {
|
||||
// if (_this.page.Sections[i].IsLink)
|
||||
// sections.push(_this.page.Sections[i].ReferenceId);
|
||||
//}
|
||||
|
||||
//dialogSection.exceptSource = sections;
|
||||
dialogSection.showSelector();
|
||||
}
|
||||
|
||||
function onAddGlobalSection(sections, iscopy) {
|
||||
if (sections && sections.length > 0) {
|
||||
var sids = [];
|
||||
for (var i = 0; i < sections.length; i++) {
|
||||
var it = sections[i].Values;
|
||||
if (it.Selected)
|
||||
sids.push(it.Id);
|
||||
}
|
||||
var p = JSON.stringify([teamintelligence, JSON.stringify(sids)]);
|
||||
inspectionrequest("GetGlobalSectionsByID", p, function (data) {
|
||||
if (typeof data === 'string')
|
||||
return;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var section = data[i];
|
||||
if (iscopy) {//copy secton<6F><6E>reference its questions
|
||||
if (section.Questions) {
|
||||
for (var j = 0; j < section.Questions.length; j++) {
|
||||
var q = section.Questions[j];
|
||||
q.Id = '';
|
||||
//q.ReferenceId = q.Id;
|
||||
//q.IsLink = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {//reference section
|
||||
section.ReferenceId = section.Id;
|
||||
section.IsLink = true;
|
||||
}
|
||||
section.Id = '';
|
||||
_this.page.Sections.push(section);
|
||||
addSectionModule(section);
|
||||
|
||||
}
|
||||
//updateContent(true);
|
||||
}, function (err) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
content.append(createPageContent());
|
||||
updateContent();
|
||||
if (templatereadonly || !editable)
|
||||
setDisabled();
|
||||
return content;
|
||||
}
|
||||
|
||||
p.prototype.getPageValue = function (noalert, nocheck) {
|
||||
var page = this.page;
|
||||
page.Name = this.namecontrol.val();
|
||||
page.DisplayText = this.displaytextcontrol.val();
|
||||
page.Notes = this.notescontrol.val();
|
||||
|
||||
var texts = this.namecontrol.data("texts");
|
||||
if (texts) {
|
||||
page.LocalNames = texts;
|
||||
}
|
||||
texts = this.displaytextcontrol.data("texts");
|
||||
if (texts) {
|
||||
page.LocalDisplayTexts = texts;
|
||||
}
|
||||
if (!nocheck) {
|
||||
var alerttitle = GetTextByKey("P_IPT_PAGE", 'Page');
|
||||
if (!noalert && (!page.Name || page.Name.length == 0)) {
|
||||
showAlert(GetTextByKey("P_IPT_PAGENAMENOTBEEMPTY", 'Page Name cannot be empty.'), alerttitle);
|
||||
return false;
|
||||
}
|
||||
if (!noalert && (!page.DisplayText || page.DisplayText.length == 0)) {
|
||||
showAlert(GetTextByKey("P_IPT_DISPLAYTEXTNOTBEEMPTY", 'Display Text cannot be empty.'), alerttitle);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
page.Sections = [];
|
||||
if (this.sectionmodules.length > 0) {
|
||||
for (var i = 0; i < this.sectionmodules.length; i++) {
|
||||
var s = this.sectionmodules[i].getSectionValue(noalert, nocheck);
|
||||
if (!s) return false;
|
||||
page.Sections.push(s);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
p.prototype.dragOutSection = function (sm) {//called when end drag
|
||||
var index = this.page.Sections.indexOf(sm.section)
|
||||
if (index >= 0) {
|
||||
this.page.Sections.splice(index, 1);
|
||||
this.sectionmodules.splice(index, 1);
|
||||
}
|
||||
};
|
||||
p.prototype.dragInSection = function (target, sm, after) {//called when end drag
|
||||
if (!this.page.Sections)
|
||||
this.page.Sections = [];
|
||||
if (this.page.Sections.length == 0) {
|
||||
this.page.Sections.push(sm.section);
|
||||
this.sectionmodules.push(sm);
|
||||
return;
|
||||
}
|
||||
var tindex = 0;
|
||||
if (target) {
|
||||
tindex = this.page.Sections.indexOf(target);
|
||||
if (after)
|
||||
tindex = tindex + 1;
|
||||
}
|
||||
if (tindex >= 0) {
|
||||
this.page.Sections.splice(tindex, 0, sm.section);
|
||||
this.sectionmodules.splice(tindex, 0, sm);
|
||||
}
|
||||
};
|
||||
return p;
|
||||
});
|
||||
|
Reference in New Issue
Block a user