186 lines
7.9 KiB
JavaScript
186 lines
7.9 KiB
JavaScript
define(['common'], function (Common) {
|
|
var s = function (gs, section) {
|
|
this.section = section;
|
|
this.dialog = null;
|
|
this.gsmodule = gs;
|
|
this.datasaved = false;
|
|
};
|
|
s.prototype.description = "Add or edit section";
|
|
s.prototype.version = "1.0.0.0";
|
|
s.prototype.onsave = null;
|
|
|
|
var namecontrol = undefined;
|
|
var displaytextcontrol = undefined;
|
|
var notescontrol = undefined;
|
|
s.prototype.createContent = function () {
|
|
var _this = this;
|
|
editable = true;
|
|
var content = $('<div></div>');
|
|
|
|
function createHeader() {
|
|
var header = $('<div></div>');
|
|
|
|
var func = $('<div class="function_title"></div>');
|
|
if (sectiontype == 0) {
|
|
var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE","Save") + '</span>').click(function () {
|
|
saveData(0);
|
|
});
|
|
func.append(btn);
|
|
btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE1", "Save and Exit") + '</span>').click(function () {
|
|
saveData(1);
|
|
});
|
|
func.append(btn);
|
|
btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_SAVE2", "Exit Without Saving") + '</span>').click(function () {
|
|
showRightPopup(false);
|
|
if (_this.datasaved)
|
|
_this.gsmodule.refresh();
|
|
});
|
|
func.append(btn);
|
|
}
|
|
else {
|
|
header.append($('<div class="function_title" style="background-color:#ddd;font-size:16px;"></div>').text(_this.section ? 'Edit Section' : 'Add Section'));
|
|
if (!templatereadonly && (!_this.section || (_this.section && !_this.section.IsLink))) {
|
|
//if (!_this.section || (_this.section && !_this.section.IsLink)) {
|
|
var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_OK", "OK") + '</span>').click(function () {
|
|
var item = getData();
|
|
if (!item)
|
|
return;
|
|
if (_this.onsave)
|
|
_this.onsave(item);
|
|
$('#right_popup1').empty().hide();
|
|
});
|
|
func.append(btn);
|
|
}
|
|
btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_CANCEL", "Cancel") + '</span>').click(function () {
|
|
$('#right_popup1').empty().hide();
|
|
});
|
|
func.append(btn);
|
|
}
|
|
header.append(func)
|
|
|
|
return header;
|
|
}
|
|
|
|
function createSectionContent() {
|
|
var div_main = $('<div class="content_main" style="overflow: auto;"></div>');
|
|
var div_content = $('<div class="edit-content"></div>');
|
|
div_main.append(div_content);
|
|
var tb = $('<table style="line-height:40px;"></table>');
|
|
div_content.append(tb);
|
|
|
|
var tr = $('<tr></tr>');
|
|
tb.append(tr);
|
|
tr.append('<td class="label" style="vertical-align:middle;">' + GetTextByKey("P_IPT_NAME_COLON", "Name:") + '<span class="redasterisk">*</span></td>');
|
|
namecontrol = $('<input type="text" maxlength="100" autocomplete="off"/>');
|
|
var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title=""/>');
|
|
addiText.click(function () {
|
|
Common.createMultiTextDialog(namecontrol, _this.section);
|
|
});
|
|
tr.append($('<td></td>').append(namecontrol).append(addiText));
|
|
|
|
tr = $('<tr></tr>');
|
|
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.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_NOTES_COLON", "Notes:") + '</td>');
|
|
notescontrol = $('<textarea id="dialog_notes" maxlength="500" autocomplete="off" style="width: 400px; margin-top: 6px;"></textarea>');
|
|
tr.append($('<td></td>').append(notescontrol));
|
|
|
|
return div_main;
|
|
}
|
|
|
|
function updateContent() {
|
|
var section = _this.section;
|
|
if (section) {
|
|
namecontrol.val(section.Name).data("texts", section.LocalNames);
|
|
displaytextcontrol.val(section.DisplayText).data("texts", section.LocalDisplayTexts);
|
|
notescontrol.val(section.Notes);
|
|
}
|
|
}
|
|
|
|
function setDisabled() {
|
|
namecontrol.prop('disabled', true);
|
|
displaytextcontrol.prop('disabled', true);
|
|
notescontrol.prop('disabled', true);
|
|
}
|
|
|
|
function getData() {
|
|
var item = {
|
|
'Name': namecontrol.val(),
|
|
'DisplayText': displaytextcontrol.val(),
|
|
'Notes': notescontrol.val()
|
|
};
|
|
var texts = namecontrol.data("texts");
|
|
if (texts) {
|
|
item.LocalNames = texts;
|
|
}
|
|
texts = displaytextcontrol.data("texts");
|
|
if (texts) {
|
|
item.LocalDisplayTexts = texts;
|
|
}
|
|
var alerttitle;
|
|
if (_this.section) {
|
|
item.Id = _this.section.Id;
|
|
alerttitle = GetTextByKey("P_IPT_EDITSECTION","Edit Section");
|
|
} else {
|
|
alerttitle = GetTextByKey("P_IPT_ADDSECTION","Add Section");
|
|
}
|
|
|
|
if (!item.Name || item.Name.length == 0) {
|
|
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);
|
|
return false;
|
|
}
|
|
|
|
return item;
|
|
}
|
|
|
|
function saveData(exit) {
|
|
var item = getData();
|
|
if (!item) return;
|
|
|
|
var param = JSON.stringify(item);
|
|
param = htmlencode(param);
|
|
var p = JSON.stringify([teamintelligence, param]);
|
|
var alerttitle = GetTextByKey("P_IPT_SAVESECTION", 'Save Section');
|
|
inspectionrequest("SaveGlobalSection", p, function (data) {
|
|
if (typeof (data) === "string") {
|
|
showAlert(data, alerttitle);
|
|
} else {
|
|
if (!_this.section) {
|
|
_this.section = { 'Id': data[0] };
|
|
}
|
|
if (exit == 0) {
|
|
showAlert(GetTextByKey("P_IPT_SAVSUCCESSFULLY",'Saved successfully.'), alerttitle);
|
|
_this.datasaved = true;
|
|
}
|
|
if (exit == 1) {
|
|
_this.gsmodule.refresh();
|
|
showRightPopup(false);
|
|
}
|
|
}
|
|
}, function (err) {
|
|
showAlert(GetTextByKey("P_IPT_FAILEDTOSAVESECTION",'Failed to save Section.'), alerttitle);
|
|
});
|
|
}
|
|
|
|
content.append(createHeader());
|
|
content.append(createSectionContent());
|
|
updateContent();
|
|
if (templatereadonly)
|
|
setDisabled();
|
|
return content;
|
|
}
|
|
return s;
|
|
}); |