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 = $('
'); function createPageContent() { var div_main = $('
'); var div_content = $('
'); div_main.append(div_content); var tb = $('
'); div_content.append(tb); var tr = $(''); tb.append(tr); tr.append('' + GetTextByKey("P_IPT_NAME_COLON", "Name:") + '*'); _this.namecontrol = $(''); var addiText = $(''); addiText.click(function () { Common.createMultiTextDialog(_this.namecontrol); }); tr.append($('').append(_this.namecontrol).append(addiText)); _this.namecontrol.change(function () { if (_this.onNameChanged) _this.onNameChanged($.trim(_this.namecontrol.val())) }) tb.append(tr); tr.append('' + GetTextByKey("P_IPT_NOTES_COLON", "Notes:") + ''); _this.notescontrol = $(''); tr.append($('').append(_this.notescontrol)); tr = $(''); tb.append(tr); tr.append('' + GetTextByKey("P_IPT_DISPLAYTEXT_COLON", "Display Text:") + '*'); _this.displaytextcontrol = $(''); addiText = $(''); addiText.click(function () { Common.createMultiTextDialog(_this.displaytextcontrol); }); tr.append($('').append(_this.displaytextcontrol).append(addiText)); var sectioncontent = createSectionContent(); div_main.append(sectioncontent); return div_main; } function createSectionContent() { var content = $('
'); function createSectionHeader() { var header = $('
'); //header.append($('
').text(gs.title)); var func = $('
'); var iconAdd = $('' + GetTextByKey("P_IPT_ADDSECTION", "Add Section") + '').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 = $('' + GetTextByKey("P_ADDGLOBALSECTION", "Add Global Section") + '').click(function () { addGlobalSection(); }); func.append(iconRefresh); header.append(func) return header; } if (!templatereadonly && editable) content.append(createSectionHeader()); var dataheader = $('
'); dataheader.append('
'); dataheader.append('
' + GetTextByKey("P_IPT_NAME", "Name") + '
'); dataheader.append('
' + GetTextByKey("P_IPT_DISPLAYTEXT", "Display Text") + '
'); dataheader.append('
' + GetTextByKey("P_IPT_TYPE", "Type") + '
'); dataheader.append('
' + GetTextByKey("P_IPT_REQUIRED", "Required") + '
'); dataheader.append('
' + GetTextByKey("P_IPT_XXX", "Include Comment") + '
'); dataheader.append('
' + GetTextByKey("P_IPT_ISIMPORTANT", "Is Important") + '
'); dataheader.append('
' + GetTextByKey("P_IPT_CUSTOMERVISIBLE", "Customer Visible") + '
'); dataheader.append('
' + GetTextByKey("P_IPT_SEVERITYLEVEL", "Severity Level") + '
'); dataheader.append('
' + GetTextByKey("P_IPT_ST_NOTES", "Notes") + '
'); dataheader.append('
'); content.append(dataheader); _this.datacontent = $('
'); 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() {//ÒýÓÃ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£¬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; });