This commit is contained in:
2023-04-28 12:22:26 +08:00
parent 88e0a25ecd
commit c9723008af
1047 changed files with 443540 additions and 1 deletions

View File

@ -0,0 +1,508 @@
define(['common'], function (Common) {
var aq = function (p, sectionid, question) {
this.sectionid = sectionid;
this.question = question;
this.holder = null;
this.sectionmodule = p;
this.datasaved = false;
};
aq.prototype.description = "Add or edit question";
aq.prototype.version = "1.0.0.0";
aq.prototype.onsave = null;
var namecontrol = undefined;
var questiontypecontrol = undefined;
var isrequiredcontrol = undefined;
var cancommentcontrol = undefined;
var severitylevelcontrol = undefined;
var isimportantcontrol = undefined;
var displaytextcontrol = undefined;
var notescontrol = undefined;
var optiontr = undefined;
var optiontd = undefined;
var options = [];
var questiontype = undefined;
aq.prototype.createContent = function () {
options = [];
var _this = this;
var content = $('<div></div>');
function createHeader() {
var header = $('<div></div>');
var funcs = $('<div class="function_title"></div>');
if (sectiontype == 0) {
var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE", "Save") + '</span>').click(function () {
saveData(0);
});
funcs.append(btn);
btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE1", "Save and Exit") + '</span>').click(function () {
saveData(1);
});
funcs.append(btn);
btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_SAVE2", "Exit Without Saving") + '</span>').click(function () {
showRightPopup(false);
if (_this.datasaved)
_this.sectionmodule.refresh();
});
funcs.append(btn);
}
else {
header.append($('<div class="function_title" style="background-color:#ddd;font-size:16px;"></div>').text(_this.question ? GetTextByKey("P_IPT_EDITQUESTION", 'Edit Question') : GetTextByKey("P_IPT_ADDQUESTION", 'Add Question')));
if (!templatereadonly && (!_this.question || (_this.question && !_this.question.IsLink))) {
//if (!_this.question || (_this.question && !_this.question.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();
});
funcs.append(btn);
}
btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_CANCEL", "Cancel") + '</span>').click(function () {
$('#right_popup1').empty().hide();
});
funcs.append(btn);
}
header.append(funcs)
return header;
}
function createQuestionContent() {
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: 35px;"></table>');
div_content.append(tb);
var tr = $('<tr></tr>');
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_ADDITIONALTEXTS", "Additional Texts") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(namecontrol, _this.question);
});
tr.append($('<td></td>').append(namecontrol).append(addiText));
tr = $('<tr></tr>');
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_ADDITIONALTEXTS", "Additional Texts") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(displaytextcontrol, _this.question);
});
tr.append($('<td></td>').append(displaytextcontrol).append(addiText));
tr = $('<tr></tr>');
tb.append(tr);
tr.append('<td class="label">Type:</td>');
questiontypecontrol = createQuestionType();
questiontypecontrol.change(function () {
questionTypeChange();
});
tr.append($('<td></td>').append(questiontypecontrol));
optiontr = $('<tr style="display:none;"></tr>');
tb.append(optiontr);
optiontr.append('<td class="label"></td>');
var btn_additem = $('<span class="sbutton iconadd">Add</span>').click(function () {
addOption();
});
optiontd = $('<td></td>').append(btn_additem);
optiontr.append(optiontd);
tr = $('<tr></tr>');
tb.append(tr);
tr.append('<td class="label" style="vertical-align:inherit;">Is Required:</td>');
var table = $('<table></table>');
tr.append($('<td></td>').append(table));
tr = $('<tr></tr>');
table.append(tr);
isrequiredcontrol = $('<input type="checkbox"/>');
tr.append($('<td style="width:75px;"></td>').append(isrequiredcontrol));
cancommentcontrol = $('<input type="checkbox" style="margin-left:10px;" />');
tr.append($('<td style="width:155px;"><label style="">Can Comment:</label></td>').append(cancommentcontrol));
isimportantcontrol = $('<input type="checkbox" style="margin-left:10px;" />');
tr.append($('<td><label>Is Important:</label></td>').append(isimportantcontrol));
tr = $('<tr></tr>');
tb.append(tr);
tr.append('<td class="label">Severity Level:</td>')
severitylevelcontrol = createSeverityLevel();
tr.append($('<td></td>').append(severitylevelcontrol));
tr = $('<tr></tr>');
tb.append(tr);
tr.append('<td class="label">Notes:</td>');
notescontrol = $('<textarea id="dialog_notes" class="inputbox" maxlength="1000" style="width: 400px; margin-top: 6px;"></textarea>');
tr.append($('<td></td>').append(notescontrol));
return div_main;
}
var option = function (op) {
this.option = op;
this.dialog_text = null;
this.dialog_bgcolor = null;
this.dialog_severitylevel = null;
this.holder = null;
this.removable = true;
if (op) {
if (op.removable == false)
this.removable = false;
else
this.removable = true;
}
};
option.prototype.getContentValue = function () {
var option = this.option || {};
option.Text = this.dialog_text.val();
var texts = this.dialog_text.data("texts");
if (texts) {
option.LocalTexts = texts;
}
option.BackgroundColor = this.dialog_bgcolor.val();
option.SeverityLevel = this.dialog_severitylevel.val();
return option;
}
option.prototype.removeOption = function () {
this.holder.remove();
options.splice(options.indexOf(this), 1);
}
option.prototype.createContent = function () {
var _thisop = this;
var tb = $('<table style="border: 1px solid #a8a8a8; width:700px;margin-top:2px;"></table>');
this.holder = tb;
var tr = $('<tr></tr>');
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_ADDITIONALTEXTS", "Additional Texts") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(optext, _this.question);
});
tr.append($('<td style="width:295px;"><span class="redasterisk">*</span></td>').append(this.dialog_text).append(addiText));
td = $('<td style="width:76px;"></td>');
tr.append(td);
td.append($('<label>' + GetTextByKey("P_IPT_SEVERITYLEVEL", "Severity Level") + '</label>'));
this.dialog_severitylevel = createSeverityLevel();
this.dialog_severitylevel.css('width', 100);
tr.append($('<td></td>').append(this.dialog_severitylevel));
var bg_label = $('<label>' + GetTextByKey("P_IPT_BACKGROUNDCOLOR", "Background Color") + '</label>');
td = $('<td style="width:100px;"></td>').append(bg_label);
tr.append(td);
this.dialog_bgcolor = $('<input style="width:100px;"/>');
var bgcolor = $('<div></div>')
bgcolor.append(this.dialog_bgcolor);
td = $('<td></td>').append(bgcolor);
tr.append(td);
initColorCtrl(this.dialog_bgcolor);
td = $('<td></td>');
tr.append(td);
if (_thisop.removable) {
var deleteoptionbtn = $('<em class="spanbtn icondelete"></em>');
td.append(deleteoptionbtn.click(function () {
_thisop.removeOption();
}));
}
if (questiontype === "5") {
this.dialog_text.attr('disabled', 'disabled');
}
//else if (questiontype === "8") {
// bg_label.hide();
// bgcolor.hide();
// tb.css('width', 324);
//}
function updateOptionContent() {
var op = _thisop.option;
if (op) {
_thisop.dialog_text.val(op.Text).data("texts", op.LocalTexts);
_thisop.dialog_bgcolor.spectrum("set", op.BackgroundColor);
_thisop.dialog_severitylevel.val(op.SeverityLevel);
}
}
updateOptionContent();
return tb;
}
function updateContent() {
var question = _this.question;
if (question) {
namecontrol.val(question.Name).data("texts", question.LocalNames);
displaytextcontrol.val(question.DisplayText).data("texts", question.LocalDisplayTexts);
questiontypecontrol.val(question.QuestionType);
questionTypeChange();
isrequiredcontrol.attr('checked', question.IsRequired);
cancommentcontrol.attr('checked', question.CanComment);
isimportantcontrol.attr('checked', question.IsImportant);
severitylevelcontrol.val(question.SeverityLevel);
notescontrol.val(question.Notes);
}
}
function setDisabled() {
namecontrol.prop('disabled', true);
displaytextcontrol.prop('disabled', true);
questiontypecontrol.prop('disabled', true);
isrequiredcontrol.prop('disabled', true);
cancommentcontrol.prop('disabled', true);
isimportantcontrol.prop('disabled', true);
severitylevelcontrol.prop('disabled', true);
notescontrol.prop('disabled', true);
}
function questionTypeChange() {
options = [];
optiontd.find('table').remove();
var type = questiontypecontrol.val();
questiontype = type;
if (['5', '8', '9'].indexOf(type) >= 0) {
optiontr.show();
if (type === "5") {
var ynops = [{ 'Text': GetTextByKey("P_IPT_YES", 'Yes'), 'BackgroundColor': '#0F0', 'Value': 'Yes', 'SeverityLevel': 0 }, { 'Text': GetTextByKey("P_IPT_NO", 'No'), 'BackgroundColor': '#F00', 'Value': 'No', 'SeverityLevel': 0 }];
for (var i = 0; i < ynops.length; i++) {
var op = ynops[i]; if (_this.question) {
if (i < _this.question.SelectItems.length) {
op.BackgroundColor = _this.question.SelectItems[i].BackgroundColor;
op.SeverityLevel = _this.question.SelectItems[i].SeverityLevel;
op.LocalTexts = _this.question.SelectItems[i].LocalTexts;
}
}
op.removable = false;
addOption(op);
}
optiontr.find('.sbutton').hide();
}
else {
optiontr.find('.sbutton').show();
if (_this.question) {
for (var i = 0; i < _this.question.SelectItems.length; i++) {
addOption(_this.question.SelectItems[i]);
}
}
else
addOption();
}
}
else {
optiontr.hide();
}
}
function addOption(item) {
var op = new option(item);
var tb = op.createContent();
options.push(op);
optiontd.append(tb);
}
function getData() {
var item = {
'Name': namecontrol.val(),
'QuestionType': questiontypecontrol.val(),
'IsRequired': isrequiredcontrol.prop('checked'),
'CanComment': cancommentcontrol.prop('checked'),
'IsImportant': isimportantcontrol.prop('checked'),
'SeverityLevel': severitylevelcontrol.val(),
'DisplayText': displaytextcontrol.val(),
'Notes': notescontrol.val()
};
var alerttitle;
if (_this.question) {
item.Id = _this.question.Id;
alerttitle = GetTextByKey("P_IPT_EDITQUESTION", "Edit Question");
} else {
alerttitle = GetTextByKey("P_IPT_ADDQUESTION", "Add Question");
}
var texts = namecontrol.data("texts");
if (texts) {
item.LocalNames = texts;
}
texts = displaytextcontrol.data("texts");
if (texts) {
item.LocalDisplayTexts = texts;
}
item.SelectItems = [];
if (options.length > 0) {
for (var i = 0; i < options.length; i++) {
var selectitem = options[i].getContentValue();
if (!selectitem.Text || selectitem.Text.length == 0) {
showAlert(GetTextByKey("P_IPT_OPTIONNAMECANNOTBEEMPTY", 'Option name cannot be empty.'), alerttitle);
return false;
}
item.SelectItems.push(selectitem)
}
}
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;
}
if ((item.QuestionType === "8" || item.QuestionType === "9") && item.SelectItems.length == 0) {
showAlert(GetTextByKey("P_IPT_THEREMUSTBEATLEASTONECHOICE", 'There must be at least one choice.'), alerttitle);
return false;
}
return item;
}
saveData = function (exit) {
var item = getData();
if (!item) return;
var param = htmlencode(JSON.stringify(item));
param = JSON.stringify([teamintelligence, _this.sectionid, param]);
inspectionrequest("SaveGlobalQuestion", param, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question'));
} else {
if (!_this.question) {
_this.question = { 'Id': data[0] };
}
if (exit == 0) {
_this.datasaved = true;
showAlert(GetTextByKey("P_IPT_SAVSUCCESSFULLY", 'Saved successfully.'), GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question'));
}
if (exit == 1) {
_this.sectionmodule.refresh();
showRightPopup(false);
}
}
}, function (err) {
showAlert(GetTextByKey("P_IPT_FAILEDTOSAVEQUESTION", 'Failed to save question.'), GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question'));
});
}
content.append(createHeader());
content.append(createQuestionContent());
updateContent();
if (templatereadonly)
setDisabled();
return content;
}
function initColorCtrl(ipt_color) {
ipt_color.spectrum({
allowEmpty: true,
color: "#FFF",
showInput: true,
containerClassName: "full-spectrum",
showInitial: true,
showPalette: true,
showSelectionPalette: true,
showAlpha: true,
maxPaletteSize: 10,
preferredFormat: "hex",
localStorageKey: "spectrum.demo",
chooseText: GetTextByKey("P_IPT_OK", "OK"),
cancelText: GetTextByKey("P_IPT_CANCEL", "Cancel"),
clearText: GetTextByKey("P_SPECTRUM_CLEARCOLORSELECTION", "Clear Color Selection"),
noColorSelectedText: GetTextByKey("P_SPECTRUM_NOCOLORSELECTED", "No Color Selected"),
move: function (color) {
if (color)
ipt_color.val(color.toHexString().toUpperCase()); // #ff0000
},
show: function () {
},
beforeShow: function () {
},
hide: function (color) {
if (color) {
ipt_color.val(color.toHexString().toUpperCase()); // #ff0000
}
},
palette: [
["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)", /*"rgb(153, 153, 153)","rgb(183, 183, 183)",*/
"rgb(204, 204, 204)", "rgb(217, 217, 217)", /*"rgb(239, 239, 239)", "rgb(243, 243, 243)",*/ "rgb(255, 255, 255)"],
["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)",
"rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"],
["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)",
"rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)",
"rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)",
"rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)",
"rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)",
"rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)",
"rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)",
"rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)",
/*"rgb(133, 32, 12)", "rgb(153, 0, 0)", "rgb(180, 95, 6)", "rgb(191, 144, 0)", "rgb(56, 118, 29)",
"rgb(19, 79, 92)", "rgb(17, 85, 204)", "rgb(11, 83, 148)", "rgb(53, 28, 117)", "rgb(116, 27, 71)",*/
"rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)",
"rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"]
]
});
}
function createQuestionType() {
var items = [];
items.push({ 'Key': 0, "Value": "Single Line Text" });
items.push({ 'Key': 1, "Value": "Multiple Line Text" });
items.push({ 'Key': 2, "Value": "Email (Manual)" });
items.push({ 'Key': 14, "Value": "Email (Drop Down)" });
items.push({ 'Key': 3, "Value": "Number" });
items.push({ 'Key': 4, "Value": "Integer" });
items.push({ 'Key': 5, "Value": "Yes Or No" });
items.push({ 'Key': 6, "Value": "Date" });
items.push({ 'Key': 7, "Value": "Date And Time" });
items.push({ 'Key': 8, "Value": "Drop Down" });
items.push({ 'Key': 9, "Value": "List" });
items.push({ 'Key': 10, "Value": "Picture" });
if (!teamintelligence) {
items.push({ 'Key': 11, "Value": "Odometer" });
items.push({ 'Key': 12, "Value": "Engine Hours" });
items.push({ 'Key': 13, "Value": "Fuel Remaining" });
}
var sel = $('<select style="width:324px; height:22px;"></select>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
return sel;
}
function createSeverityLevel() {
var items = [];
items.push({ 'Key': 0, "Value": "None" });
items.push({ 'Key': 1, "Value": "Low" });
items.push({ 'Key': 2, "Value": "Medium" });
items.push({ 'Key': 3, "Value": "High" });
var sel = $('<select style="width:324px;height:22px;"></select>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
return sel;
}
return aq;
});

View File

@ -0,0 +1,186 @@
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_ADDITIONALTEXTS", "Additional Texts") + '"/>');
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" class="inputbox" 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;
});

View File

@ -0,0 +1,200 @@
define(['common'], function (Common) {
var option = function (q, op) {
this.questionmodule = q;
this.option = op;
this.dialog_text = null;
this.dialog_bgcolor = null;
this.dialog_severitylevel = null;
this.holder = null;
this.texteditable = true;
this.removable = true;
if (op) {
if (op.removable == false)
this.removable = false;
else
this.removable = true;
}
this.onremove = null;
};
option.prototype.getOptionValue = function () {
var option = this.option || {};
option.Text = this.dialog_text.val();
var texts = this.dialog_text.data("texts");
if (texts) {
option.LocalTexts = texts;
}
option.BackgroundColor = this.dialog_bgcolor.val();
option.SeverityLevel = this.dialog_severitylevel.val();
return option;
}
option.prototype.removeOption = function () {
this.holder.remove();
if (this.onremove)
this.onremove(this);
this.onsave();
}
option.prototype.onsave = function () {
this.questionmodule.onsave();
}
option.prototype.createContent = function () {
var _this = this;
var tb = $('<table style="border: 1px solid #a8a8a8; margin-top:2px;line-height:32px;"></table>');
this.holder = tb;
var tr = $('<tr></tr>');
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_ADDITIONALTEXTS", "Additional Texts") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(optext);
});
var td = $('<td colspan="2"><span class="redasterisk">*</span></td>');
td.append(this.dialog_text).append(addiText)
tr.append(td);
//tr = $('<tr></tr>');
//tb.append(tr);
td = $('<td style="width:76px;"></td>');
tr.append(td);
td.append($('<label>' + GetTextByKey("P_IPT_SEVERITYLEVEL", "Severity Level") + '</label>'));
this.dialog_severitylevel = createSeverityLevel().addClass('form-control');
this.dialog_severitylevel.css('width', 100);
tr.append($('<td></td>').append(this.dialog_severitylevel));
//tr = $('<tr></tr>');
//tb.append(tr);
var bg_label = $('<label>' + GetTextByKey("P_IPT_BACKGROUNDCOLOR", "Background Color") + '</label>');
td = $('<td style="width:100px;"></td>').append(bg_label);
tr.append(td);
this.dialog_bgcolor = $('<input style="width:100px;"/>');
var bgcolor = $('<div></div>')
bgcolor.append(this.dialog_bgcolor);
td = $('<td></td>').append(bgcolor);
tr.append(td);
initColorCtrl(this.dialog_bgcolor);
if (!this.texteditable) {
this.dialog_text.attr('disabled', 'disabled');
}
if (this.removable) {
td = $('<td style="width:30px;"></td>');
tr.append(td);
var deleteoptionbtn = $('<em class="spanbtn icondelete"></em>');
td.append(deleteoptionbtn.click(function () {
_this.removeOption();
}));
if (templatereadonly || !editable)
deleteoptionbtn.hide();
}
function updateOptionContent() {
var op = _this.option;
if (op) {
_this.dialog_text.val(op.Text).data("texts", op.LocalTexts);
if (op.BackgroundColor && op.BackgroundColor != '')
_this.dialog_bgcolor.spectrum("set", op.BackgroundColor);
_this.dialog_severitylevel.val(op.SeverityLevel);
}
}
function controlSaveEvent() {
_this.dialog_text.change(function () {
_this.onsave();
});
_this.dialog_severitylevel.change(function () {
_this.onsave();
});
_this.dialog_bgcolor.change(function () {
_this.onsave();
});
}
function setDisabled() {
_this.dialog_text.prop('disabled', true);
_this.dialog_bgcolor.prop('disabled', true);
_this.dialog_severitylevel.prop('disabled', true);
}
updateOptionContent();
if (templatereadonly || !editable)
setDisabled();
controlSaveEvent();
return tb;
}
function initColorCtrl(ipt_color) {
ipt_color.spectrum({
allowEmpty: true,
color: "#FFF",
showInput: true,
containerClassName: "full-spectrum",
showInitial: true,
showPalette: true,
showSelectionPalette: true,
showAlpha: true,
maxPaletteSize: 10,
preferredFormat: "hex",
localStorageKey: "spectrum.demo",
chooseText: GetTextByKey("P_IPT_OK", "OK"),
cancelText: GetTextByKey("P_IPT_CANCEL", "Cancel"),
clearText: GetTextByKey("P_SPECTRUM_CLEARCOLORSELECTION", "Clear Color Selection"),
noColorSelectedText: GetTextByKey("P_SPECTRUM_NOCOLORSELECTED", "No Color Selected"),
disabled: (templatereadonly && !editable),
move: function (color) {
if (color)
ipt_color.val(color.toHexString().toUpperCase()); // #ff0000
},
show: function () {
},
beforeShow: function () {
},
hide: function (color) {
if (color) {
ipt_color.val(color.toHexString().toUpperCase()); // #ff0000
}
},
palette: [
["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)", /*"rgb(153, 153, 153)","rgb(183, 183, 183)",*/
"rgb(204, 204, 204)", "rgb(217, 217, 217)", /*"rgb(239, 239, 239)", "rgb(243, 243, 243)",*/ "rgb(255, 255, 255)"],
["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)",
"rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"],
["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)",
"rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)",
"rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)",
"rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)",
"rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)",
"rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)",
"rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)",
"rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)",
/*"rgb(133, 32, 12)", "rgb(153, 0, 0)", "rgb(180, 95, 6)", "rgb(191, 144, 0)", "rgb(56, 118, 29)",
"rgb(19, 79, 92)", "rgb(17, 85, 204)", "rgb(11, 83, 148)", "rgb(53, 28, 117)", "rgb(116, 27, 71)",*/
"rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)",
"rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"]
]
});
}
function createSeverityLevel() {
var items = [];
items.push({ 'Key': 0, "Value": GetTextByKey("P_IPT_SL_NONE", "None") });
items.push({ 'Key': 1, "Value": GetTextByKey("P_IPT_SL_LOW", "Low") });
items.push({ 'Key': 2, "Value": GetTextByKey("P_IPT_SL_MEDIUM", "Medium") });
items.push({ 'Key': 3, "Value": GetTextByKey("P_IPT_SL_HIGH", "High") });
var sel = $('<select style="width:324px;height:22px;"></select>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
return sel;
}
return option;
});

View File

@ -0,0 +1,940 @@
define(['modules/sections/addquestion', 'modules/sections/option', 'common', 'modules/templates/picture'], function (AddQuestion, Option, Common, Picture) {
var q = function (sm, question, index) {
this.sectionmodule = sm;
this.section = sm.section;
this.question = question;
this.holder = null;
this.questionholder = null;
this.index = index;
this.txtName = null;
this.txtDisplayText = null;
this.selQuestionType = null;
this.chkIsRequired = null;
this.chkCanComment = null;
this.chkIsImportant = null;
this.chkCustomerVisible = null;
this.selSeverityLevel = null;
this.txtNotes = null;
this.chkMultipleSelect = null;
this.selLookupSource = null;
this.selSubType = null;
this.txtTransactionDate = null;
this.selState = null;
this.selFuelType = null;
this.selDistributedBy = null;
this.txtBarCodeValidate = null;
this.optionholder = undefined;
this.optiondiv = undefined;
this.btnoption = undefined;
this.optiontr = undefined;
this.optiontd = undefined;
this.multipleselectdiv = null;
this.lookupsourcespan = null;
this.additemspan = null;
this.optionmodules = [];
this.saving = false;
this.datachanged = false;
};
q.prototype.moduletype = "question";
q.prototype.description = "Question Module";
q.prototype.version = "1.0.0.0";
q.prototype.ondelete = null;
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 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;"><em class="spanbtn iconmove rowdrag"></em></div>');
qholder.append(drag);
if (!_this.section.IsLink && sectiontype == 1) {
drag.attr('draggable', true);
holder.bind('dragstart', function (e) {
//var data = e.originalEvent.dataTransfer;
draggingobj = _this;
});
holder.bind('dragend', function (e) {
draggingobj = null;
});
holder.bind('dragover', function (e) {
e.originalEvent.preventDefault()
});
holder.bind('drop', function (e) {
if (!draggingobj || _this === draggingobj)
return;
if (draggingobj.moduletype == "question") {
var t = $(this);
var after = e.originalEvent.clientY > t.offset().top + t.height() / 2;
if (after)
t.after(draggingobj.holder);
else
t.before(draggingobj.holder);
draggingobj.sectionmodule.dragOutQuestion(draggingobj);
_this.sectionmodule.dragInQuestion(_this.question, draggingobj, after);
}
else {//section dragging
if (_this.sectionmodule === draggingobj)
return;
else
_this.sectionmodule.dragInSection();
}
});
}
else
drag.children().remove();
if (templatereadonly || !editable)
drag.hide();
qholder.append('<div class="question-icon" style="width:30px;"><em class="fa"></em></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_ADDITIONALTEXTS", "Additional Texts") + '"/>');
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));
_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_ADDITIONALTEXTS", "Additional Texts") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(_this.txtDisplayText, _this.question);
});
var imgicon = $('<span class="spanbtn iconimage" style="font-size:14px;" title="' + GetTextByKey("P_IPT_PICTURES", "Pictures") + '"/>');
imgicon.click(function (e) {
var picturemodule = new Picture(false, _this.question, function () { _this.onsave() });
picturemodule.createContent();
//Common.createImageDialog(_this.txtDisplayText, _this.question);
});
qholder.append($('<div class="question-cell question-display" style="width: 310px;"></div>').append(this.txtDisplayText).append(addiText).append(imgicon));
//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));
createOptions();
_this.chkIsRequired = $('<input type="checkbox" />');
qholder.append($('<div class="question-cell question-required" style="width: 80px; text-align: center"></div>').append(this.chkIsRequired));
_this.chkCanComment = $('<input type="checkbox" />');
qholder.append($('<div class="question-cell question-comment" style="width: 100px; text-align: center"></div>').append(this.chkCanComment));
_this.chkIsImportant = $('<input type="checkbox" />');
qholder.append($('<div class="question-cell question-important" style="width: 100px; text-align: center"></div>').append(this.chkIsImportant));
_this.chkCustomerVisible = $('<input type="checkbox" />');
qholder.append($('<div class="question-cell question-important" style="width: 140px; text-align: center"></div>').append(this.chkCustomerVisible));
_this.selSeverityLevel = createSeverityLevel().addClass('question-input').css('width', 130);
qholder.append($('<div class="question-cell question-security" style="width: 140px"></div>').append(this.selSeverityLevel));
_this.txtNotes = $('<textarea class="question-input" maxlength="500" autocomplete="off" style="width:95%;margin-top:5px;"></textarea>');
qholder.append($('<div class="question-cell question-notes" style="width: 160px;white-space:normal;"></div>').append(this.txtNotes));
var funcs = $('<div class="question-cell question-func" style="width: 90px;text-align:right;padding-right:20px;"></div>');
qholder.append(funcs);
//qholder.find('.question-name span').click(function () {
// _this.onedit();
//});
//qholder.find('.question-display span').click(function () {
// _this.onedit();
//});
if (_this.question.IsLink) {
qholder.find('.question-name input').before('<em class="spanbtn iconlink" style="cursor:default;margin:0;padding-left:0;padding-right:2px;font-size:10px;"></em>');
qholder.find('input').prop('disabled', true);
qholder.find('select').prop('disabled', true);
qholder.find('textarea').prop('disabled', true);
qholder.find('.iconmultitext').remove();
qholder.find('.iconimage').remove();
}
if (!templatereadonly && editable) {
if (!_this.section.IsLink && sectiontype == 1 /*&& !_this.question.IsLink*/) {
funcs.append($('<em class="spanbtn iconcopy"></em>').click(function () {
if (_this.oncopy)
_this.oncopy(_this.getQuestionValue(true, true));
}).attr('title', GetTextByKey("P_IPT_COPYQUESTION", 'Copy Question')));
}
//if (!_this.question.IsLink) {
// funcs.append($('<em class="spanbtn iconedit"></em>').click(function () {
// _this.onedit();
// }).attr('title', 'Edit Question'));
//}
if (!_this.section.IsLink) {
funcs.append($('<em class="spanbtn icondelete"></em>').click(function () {
if (sectiontype == 0) {
_this.delete();
}
else {
showConfirm(GetTextByKey("P_IPT_AREYOUSUREYOUWANTTODELETETHISQUESTION", 'Are you sure you want to delete this question?'), GetTextByKey("P_IPT_DELETEQUESTION", 'Delete Question'), function () {
if (_this.ondelete) {
_this.holder.remove();
_this.ondelete(_this);
}
});
}
}).attr('title', GetTextByKey("P_IPT_DELETEQUESTION", 'Delete Question')));
}
}
if (_this.question != null) {
_this.updateContent(_this.question);
}
if (templatereadonly || !editable)
setDisabled();
function createQuestionTypeCtrl() {
var tb = $('<table style="line-height:unset;"></table>');
var tr = $('<tr></tr>');
tb.append(tr);
var td = $('<td></td>');
tr.append(td);
_this.selQuestionType = createQuestionType().addClass('question-input');
td.append(_this.selQuestionType);
_this.selQuestionType.change(function () {
_this.questionTypeChange(true);
});
td = $('<td></td>');
tr.append(td);
_this.btnoption = $('<span class="spanbtn iconangleleft" style="font-size:18px;"></span>');
td.append(_this.btnoption);
_this.btnoption.click(function () {
var icon = $(this);
var type = _this.selQuestionType.val();
if (icon.hasClass('iconangleleft')) {
icon.removeClass('iconangleleft').addClass('iconangledown');
_this.optionholder.show();
if (type === "8" || type === "9")
_this.multipleselectdiv.show();
else
_this.multipleselectdiv.hide();
}
else {
icon.removeClass('iconangledown').addClass('iconangleleft');
_this.optionholder.hide();
}
});
td = $('<td></td>');
tr.append(td);
_this.selSubType = createSubType().addClass('question-input').css({ 'width': 128, 'margin-left': '3px' });
_this.selSubType.change(function () {
_this.subTypeChange(true);
});
td.append(_this.selSubType);
td = $('<td></td>');
tr.append(td);
_this.txtTransactionDate = $('<input type="text" class="question-input" maxlength="20" autocomplete="off" />').css({ 'width': 100, 'margin-left': '3px' });
_this.txtTransactionDate.hide();
_this.txtTransactionDate.datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false
});
_this.txtTransactionDate.change(function () {
_this.transactionDateChange(true);
});
td.append(_this.txtTransactionDate);
_this.selState = createState().addClass('question-input').css({ 'width': 116, '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.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.hide();
_this.selDistributedBy.change(function () {
_this.distributedByChange(true);
});
td.append(_this.selDistributedBy);
td = $('<td></td>');
tr.append(td);
_this.txtBarCodeValidate = $('<input type="text" class="question-input" maxlength="200" autocomplete="off" isValue="0" promptText="' + GetTextByKey("P_IPT_TEXTTOCOMPARE", "Text to compare") + '" style="width:112px;margin-left:3px;" />');
_this.txtBarCodeValidate.focus(function () {
if (_this.txtBarCodeValidate.attr("isValue") === "0") {
_this.txtBarCodeValidate.val("");
_this.txtBarCodeValidate.removeClass("prompttext");
}
});
_this.txtBarCodeValidate.blur(function () {
if (_this.txtBarCodeValidate.val() == "") {
_this.txtBarCodeValidate.attr("isValue", "0");
_this.txtBarCodeValidate.val(_this.txtBarCodeValidate.attr("promptText"));
_this.txtBarCodeValidate.addClass("prompttext");
}
});
td.append(_this.txtBarCodeValidate);
if (_this.question.IsLink)
_this.btnoption.remove();
//tb = $('<table style="line-height:unset;"></table>');
//_this.multipleselectdiv = $('<span style="margin-left:50px;"><label>Multiple Select:</label></span>');
//_this.chkMultipleSelect = $('<input type="checkbox" style="margin-left:10px;" />');
//_this.multipleselectdiv.append(_this.chkMultipleSelect);
//_this.optiontr = $('<tr style="display:none;"></tr>');
//tb.append(_this.optiontr);
//var btn_additem = $('<span class="sbutton iconadd">Add Item</span>').click(function () {
// _this.addOption();
//});
//_this.optiontd = $('<td colspan="2"></td>');
//_this.optiontd.append('<span style="font-weight:bold;margin-right:5px;">Options</span>');
//_this.optiontd.append(btn_additem);
//_this.optiontd.append(_this.multipleselectdiv);
//_this.optiontr.append(_this.optiontd);
return tb;
}
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);
_this.multipleselectdiv = $('<span style="margin-left:50px;"><label>' + GetTextByKey("P_IPT_MULTIPLESELECT_COLON", "Multiple Select:") + '</label></span>');
_this.chkMultipleSelect = $('<input type="checkbox" style="margin-left:10px;" />');
_this.multipleselectdiv.append(_this.chkMultipleSelect);
_this.additemspan = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADDITEM", "Add Item") + '</span>').click(function () {
_this.addOption();
});
_this.lookupsourcespan = $('<span style="margin-left:50px;"><label>' + GetTextByKey("P_IPT_LOOKUPSOURCE_COLON", "Lookup Source:") + '</label></span>');
_this.selLookupSource = createLookupSource().addClass('question-input').css({ 'width': 150, 'margin-left': '5px' });
_this.selLookupSource.change(function () {
_this.lookupSourcesChange(true);
});
_this.lookupsourcespan.append(_this.selLookupSource);
_this.optiondiv.append('<span style="font-weight:bold;margin-right:5px;">' + GetTextByKey("P_IPT_OPTIONS", "Options") + '</span>');
_this.optiondiv.append(_this.additemspan);
_this.optiondiv.append(_this.multipleselectdiv);
_this.optiondiv.append(_this.lookupsourcespan);
}
function createQuestionType() {
var items = [];
items.push({ 'Key': 0, "Value": GetTextByKey("P_IPT_QT_SINGLELINETEXT", "Single Line Text") });
items.push({ 'Key': 1, "Value": GetTextByKey("P_IPT_QT_MULTIPLELINETEXT", "Multiple Line Text") });
items.push({ 'Key': 2, "Value": GetTextByKey("P_IPT_QT_EMAILMANUAL", "Email (Manual)") });
items.push({ 'Key': 14, "Value": GetTextByKey("P_IPT_QT_EMAILDROPDOWN", "Email (Drop Down)") });
items.push({ 'Key': 3, "Value": GetTextByKey("P_IPT_QT_NUMBER", "Number") });
items.push({ 'Key': 4, "Value": GetTextByKey("P_IPT_QT_INTEGER", "Integer") });
items.push({ 'Key': 5, "Value": GetTextByKey("P_IPT_QT_YESORNO", "Yes Or No") });
items.push({ 'Key': 6, "Value": GetTextByKey("P_IPT_QT_DATE", "Date") });
items.push({ 'Key': 7, "Value": GetTextByKey("P_IPT_QT_DATEANDTIME", "Date And Time") });
items.push({ 'Key': 8, "Value": GetTextByKey("P_IPT_QT_DROPDOWN", "Drop Down") });
items.push({ 'Key': 9, "Value": GetTextByKey("P_IPT_QT_LIST", "List") });
items.push({ 'Key': 10, "Value": GetTextByKey("P_IPT_QT_PICTURE", "Picture") });
if (!teamintelligence) {
items.push({ 'Key': 11, "Value": GetTextByKey("P_IPT_QT_ODOMETER", "Odometer") });
items.push({ 'Key': 12, "Value": GetTextByKey("P_IPT_QT_ENGINEHOURS", "Engine Hours") });
items.push({ 'Key': 13, "Value": GetTextByKey("P_IPT_QT_FUELREMAINING", "Fuel Remaining") });
items.push({ 'Key': 15, "Value": GetTextByKey("P_IPT_QT_FUELRECORDS", "Fuel Records") });
}
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>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
return sel;
}
function createSubType() {
var items = [];
items.push({ 'Key': 0, "Value": GetTextByKey("P_IPT_ST_TRANSACTIONDATE", "Transaction Date") });
items.push({ 'Key': 1, "Value": GetTextByKey("P_IPT_ST_TICKETRECEIPTNUMBER", "Ticket/Receipt Number") });
items.push({ 'Key': 2, "Value": GetTextByKey("P_IPT_ST_DRIVERNAME", "Driver Name") });
items.push({ 'Key': 3, "Value": GetTextByKey("P_IPT_ST_RETAILERNAME", "Retailer Name") });
items.push({ 'Key': 4, "Value": GetTextByKey("P_IPT_ST_RETAILERADDRESS", "Retailer Address") });
items.push({ 'Key': 5, "Value": GetTextByKey("P_IPT_ST_CITY", "City") });
items.push({ 'Key': 6, "Value": GetTextByKey("P_IPT_ST_STATE", "State") });
items.push({ 'Key': 7, "Value": GetTextByKey("P_IPT_ST_ZIP", "Zip") });
items.push({ 'Key': 8, "Value": GetTextByKey("P_IPT_ST_ODOMETER", "Odometer") });
items.push({ 'Key': 9, "Value": GetTextByKey("P_IPT_ST_FUELTYPE", "Fuel Type") });
items.push({ 'Key': 10, "Value": GetTextByKey("P_IPT_ST_QUANTITY", "Quantity") });
items.push({ 'Key': 11, "Value": GetTextByKey("P_IPT_ST_UOMCOST", "Unit Cost") });
items.push({ 'Key': 12, "Value": GetTextByKey("P_IPT_ST_TOTALCOST", "Total Cost") });
items.push({ 'Key': 13, "Value": GetTextByKey("P_IPT_ST_BRANDNAME", "Brand Name") });
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>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
return sel;
}
function createDistributedBy() {
var items = [];
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>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
return sel;
}
function createState() {
var items = [];
items.push("", "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ",
"NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY");
var sel = $('<select style="width:125px; height:26px;"></select>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item + '">' + item + '</option>');
}
return sel;
}
function createFuelType() {
var sel = $('<select style="width:125px; height:26px;"></select>');
sel.append('<option value=""></option>');
if (typeof fuelTypes !== 'undefined') {
if (fuelTypes && fuelTypes.length > 0) {
for (var i = 0; i < fuelTypes.length; i++) {
var item = fuelTypes[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
}
if (_this.question && _this.question.QuestionType === 15 && _this.question.SubType === 9)
sel.val(_this.question.DefaultValue);
return sel;
}
inspectionrequest("GetFuelTypes", '', function (data) {
if (typeof (data) === "string")
return sel;
if (data && data.length > 0) {
for (var i = 0; i < data.length; i++) {
var item = data[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
}
if (_this.question && _this.question.QuestionType === 15 && _this.question.SubType === 9)
sel.val(_this.question.DefaultValue);
}, function (err) {
});
return sel;
}
function createSeverityLevel() {
var items = [];
items.push({ 'Key': 0, "Value": GetTextByKey("P_IPT_SL_NONE", "None") });
items.push({ 'Key': 1, "Value": GetTextByKey("P_IPT_SL_LOW", "Low") });
items.push({ 'Key': 2, "Value": GetTextByKey("P_IPT_SL_MEDIUM", "Medium") });
items.push({ 'Key': 3, "Value": GetTextByKey("P_IPT_SL_HIGH", "High") });
var sel = $('<select style="width:324px;height:26px;"></select>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
return sel;
}
function createLookupSource() {
var items = [];
items.push({ 'Key': 0, "Value": GetTextByKey("P_IPT_LS_MANUALINPUT", "Manual Input") });
items.push({ 'Key': 1, "Value": GetTextByKey("P_IPT_LS_JOBSITES", "Jobsites") });
items.push({ 'Key': 2, "Value": GetTextByKey("P_IPT_LS_ASSETS", "Assets") });
items.push({ 'Key': 4, "Value": GetTextByKey("P_IPT_LS_ASSETNAMECUSTOM", "Asset Name Custom") });
items.push({ 'Key': 3, "Value": GetTextByKey("P_IPT_LS_EMPLOYEES", "Employees") });
var sel = $('<select style="width:324px;height:26px;"></select>');
for (var i = 0; i < items.length; i++) {
var item = items[i];
sel.append('<option value="' + item.Key + '">' + item.Value + '</option>');
}
return sel;
}
function controlSaveEvent() {
_this.txtName.change(function () {
_this.onsave();
});
_this.txtDisplayText.change(function () {
_this.onsave();
});
_this.chkIsRequired.click(function () {
_this.onsave();
});
_this.chkCanComment.click(function () {
_this.onsave();
});
_this.chkIsImportant.click(function () {
_this.onsave();
});
_this.chkCustomerVisible.click(function () {
_this.onsave();
});
_this.selSeverityLevel.change(function () {
_this.onsave();
});
_this.txtNotes.blur(function () {
_this.onsave();
});
_this.chkMultipleSelect.click(function () {
_this.onsave();
});
_this.txtBarCodeValidate.change(function () {
if (_this.txtBarCodeValidate.val() == "") {
_this.txtBarCodeValidate.attr("isValue", "0");
_this.txtBarCodeValidate.val(_this.txtBarCodeValidate.attr("promptText"));
_this.txtBarCodeValidate.addClass("prompttext");
}
else {
_this.txtBarCodeValidate.attr("isValue", "1");
}
_this.onsave();
});
}
function setDisabled() {
_this.txtName.prop('disabled', true);
_this.txtDisplayText.prop('disabled', true);
_this.chkIsRequired.prop('disabled', true);
_this.chkCanComment.prop('disabled', true);
_this.chkIsImportant.prop('disabled', true);
_this.chkCustomerVisible.prop('disabled', true);
_this.selSeverityLevel.prop('disabled', true);
_this.txtNotes.prop('disabled', true);
_this.chkMultipleSelect.prop('disabled', true);
_this.selQuestionType.prop('disabled', true);
_this.selLookupSource.prop('disabled', true);
_this.selSubType.prop('disabled', true);
_this.selDistributedBy.prop('disabled', true);
_this.selFuelType.prop('disabled', true);
_this.txtTransactionDate.prop('disabled', true);
_this.selState.prop('disabled', true);
_this.txtBarCodeValidate.prop('disabled', true);
_this.additemspan.hide();
_this.holder.find(".iconmultitext").hide();
_this.holder.find(".iconimage").hide();
_this.holder.find(".iconangleleft").hide();
}
controlSaveEvent();
return holder;
};
q.prototype.questionTypeChange = function (needsave) {
var _this = this;
_this.optionmodules = [];
//_this.optiontd.find('table').remove();
_this.optionholder.find('table').remove();
var type = _this.selQuestionType.val();
questiontype = type;
if (['5', '8', '9'].indexOf(type) >= 0) {
_this.btnoption.show();
if (_this.btnoption.hasClass('iconangledown')) {
if (type === "8" || type === "9")
_this.multipleselectdiv.show();
else
_this.multipleselectdiv.hide();
//_this.optiontr.show();
_this.optionholder.show();
}
if (type === "5") {
var ynops = [{ 'Text': GetTextByKey("P_IPT_YES", 'Yes'), 'BackgroundColor': '#0F0', 'Value': 'Yes', 'SeverityLevel': 0 }, { 'Text': GetTextByKey("P_IPT_NO", 'No'), 'BackgroundColor': '#F00', 'Value': 'No', 'SeverityLevel': 0 }];
for (var i = 0; i < ynops.length; i++) {
var op = ynops[i]; if (_this.question) {
if (i < _this.question.SelectItems.length) {
op.BackgroundColor = _this.question.SelectItems[i].BackgroundColor;
op.SeverityLevel = _this.question.SelectItems[i].SeverityLevel;
op.LocalTexts = _this.question.SelectItems[i].LocalTexts;
}
}
op.removable = false;
_this.addOption(op, false);
}
//_this.optiontr.find('.sbutton').hide();
_this.optionholder.find('.sbutton').hide();
}
else {
//_this.optiontr.find('.sbutton').show();
_this.optionholder.find('.sbutton').show();
if (_this.question) {
for (var i = 0; i < _this.question.SelectItems.length; i++) {
_this.addOption(_this.question.SelectItems[i]);
}
}
else
_this.addOption();
}
if (type === "8") {
_this.lookupsourcespan.show();
}
else {
_this.lookupsourcespan.hide();
}
}
else {
_this.btnoption.hide();
//_this.optiontr.hide();
_this.optionholder.hide()
//_this.multipleselectdiv.hide();
}
_this.txtTransactionDate.hide();
_this.selState.hide();
_this.selFuelType.hide();
_this.selDistributedBy.hide();
if (type === "15" || type === "17") {
if (type === "15") {
_this.selSubType.show();
_this.questionholder.attr('title', GetTextByKey("P_IPT_THESEQUESTIONSCREATEFUELRECORDSINASSETHEALTH", 'These questions create Fuel Records in Asset Health'));
_this.txtBarCodeValidate.hide();
var subtype = _this.selSubType.val();
//if (subtype === "0")
// _this.txtTransactionDate.show();
if (subtype === "6")
_this.selState.show();
else if (subtype === "9")
_this.selFuelType.show();
else if (subtype === "16")
_this.selDistributedBy.show()
}
else {
_this.selSubType.hide();
_this.questionholder.removeAttr('title');
_this.txtBarCodeValidate.show();
}
}
else {
_this.selSubType.hide();
_this.txtBarCodeValidate.hide();
if (!this.question.IsLink)
_this.chkIsRequired.prop('disabled', false);
_this.questionholder.removeAttr('title');
}
if (needsave)
_this.onsave();
}
q.prototype.lookupSourcesChange = function (needsave) {
var _this = this;
var type = _this.selQuestionType.val();
var source = _this.selLookupSource.val();
if (type === "8" && source !== "0") {
_this.additemspan.hide();
_this.optionholder.find('table').remove();
_this.optionmodules = [];
}
else {
_this.additemspan.show();
}
if (needsave)
_this.onsave();
}
q.prototype.subTypeChange = function (needsave) {
var _this = this;
_this.txtTransactionDate.hide();
_this.selState.hide();
_this.selFuelType.hide();
_this.selDistributedBy.hide();
var subtype = _this.selSubType.val();
//if (subtype === "0")
// _this.txtTransactionDate.show();
if (subtype === "6")
_this.selState.show();
else if (subtype === "9")
_this.selFuelType.show();
else if (subtype === "16")
_this.selDistributedBy.show()
if (needsave)
_this.onsave();
}
q.prototype.distributedByChange = function (needsave) {
var _this = this;
if (needsave)
_this.onsave();
}
q.prototype.stateChange = function (needsave) {
var _this = this;
if (needsave)
_this.onsave();
}
q.prototype.transactionDateChange = function (needsave) {
var _this = this;
if (needsave)
_this.onsave();
}
q.prototype.fuelTypeChange = function (needsave) {
var _this = this;
if (needsave)
_this.onsave();
}
q.prototype.addOption = function (item, texteditable) {
var _this = this;
var op = new Option(_this, item);
op.onremove = function (item) {
_this.optionmodules.splice(_this.optionmodules.indexOf(item), 1);
}
if (texteditable != undefined || texteditable != null)
op.texteditable = texteditable;
_this.optionmodules.push(op);
//_this.optiontd.append(op.createContent());
_this.optiondiv.append(op.createContent());
}
q.prototype.onedit = function () {
var _this = this;
var aq = new AddQuestion(_this.sectionmodule, _this.section.Id, _this.question);
if (sectiontype == 0) {
$('#right_popup').empty().append(aq.createContent());
showRightPopup(true);
}
else {
aq.onsave = function (question) {
_this.question.Name = question.Name;
_this.question.DisplayText = question.DisplayText;
_this.question.Notes = question.Notes;
_this.question.LocalNames = question.LocalNames;
_this.question.LocalDisplayTexts = question.LocalDisplayTexts;
_this.question.QuestionType = question.QuestionType;
_this.question.IsRequired = question.IsRequired;
_this.question.CanComment = question.CanComment;
_this.question.IsImportant = question.IsImportant;
_this.question.SeverityLevel = question.SeverityLevel;
_this.question.SelectItems = question.SelectItems;
_this.updateContent(_this.question);
}
$('#right_popup1').empty().append(aq.createContent()).show();
}
}
q.prototype.updateContent = function (question) {
if (this.question != question) {
this.question = question;
}
this.txtName.val(question.Name).data("texts", question.LocalNames);
this.txtDisplayText.val(question.DisplayText).data("texts", question.LocalDisplayTexts);
this.selQuestionType.val(question.QuestionType);
this.questionTypeChange(false);
this.chkIsRequired.attr('checked', question.IsRequired);
this.chkCanComment.attr('checked', question.CanComment);
this.chkIsImportant.attr('checked', question.IsImportant);
this.chkCustomerVisible.attr('checked', question.VisibleToCustomer);
this.selSeverityLevel.val(question.SeverityLevel);
this.txtNotes.val(question.Notes);
this.chkMultipleSelect.attr('checked', question.MultipleSelect);
this.selLookupSource.val(question.LookupSource);
this.lookupSourcesChange(false);
if (question.QuestionType == 15) {
this.selSubType.val(question.SubType);
//if (question.SubType === 0)
// this.txtTransactionDate.val(question.DefaultValue);
if (question.SubType === 6)
this.selState.val(question.DefaultValue);
else if (question.SubType === 9)
this.selFuelType.val(question.DefaultValue);
else if (question.SubType === 16)
this.selDistributedBy.val(question.DefaultValue);
this.subTypeChange(false);
}
this.txtBarCodeValidate.val(question.TextToCompare);
if (this.txtBarCodeValidate.val() == "") {
this.txtBarCodeValidate.attr("isValue", "0");
this.txtBarCodeValidate.val(this.txtBarCodeValidate.attr("promptText"));
this.txtBarCodeValidate.addClass("prompttext");
}
else {
this.txtBarCodeValidate.attr("isValue", "1");
this.txtBarCodeValidate.removeClass("prompttext");
}
};
q.prototype.getQuestionValue = function (noalert, nocheck) {
var question = this.question;
question.Name = this.txtName.val();
question.DisplayText = this.txtDisplayText.val();
var texts = this.txtName.data("texts");
if (texts) {
question.LocalNames = texts;
}
texts = this.txtDisplayText.data("texts");
if (texts) {
question.LocalDisplayTexts = texts;
}
question.QuestionType = this.selQuestionType.val();
question.IsRequired = this.chkIsRequired.prop('checked');
question.CanComment = this.chkCanComment.prop('checked');
question.IsImportant = this.chkIsImportant.prop('checked');
question.VisibleToCustomer = this.chkCustomerVisible.prop('checked');
question.SeverityLevel = this.selSeverityLevel.val();
question.Notes = this.txtNotes.val();
if (question.QuestionType === "8" || question.QuestionType === "9")
question.MultipleSelect = this.chkMultipleSelect.prop('checked');
else
question.MultipleSelect = false;
question.LookupSource = this.selLookupSource.val();
question.SubType = this.selSubType.val();
//if (question.SubType === "0")
// question.DefaultValue = this.txtTransactionDate.val();
if (question.SubType === "6")
question.DefaultValue = this.selState.val();
else if (question.SubType === "9")
question.DefaultValue = this.selFuelType.val();
else if (question.SubType === "16")
question.DefaultValue = this.selDistributedBy.val();
question.TextToCompare = this.txtBarCodeValidate.val();
if (this.txtBarCodeValidate.attr("isValue") === "0") {
question.TextToCompare = "";
}
question.SelectItems = [];
var alerttitle = GetTextByKey("P_IPT_QUESTION", "Question");
if (!nocheck) {
if (!question.Name || question.Name.length == 0) {
if (!noalert)
showAlert(GetTextByKey("P_IPT_QUESTIONNAMENOTBEEMPTY", 'Question Name cannot be empty.'), alerttitle);
return false;
}
if (!question.DisplayText || question.DisplayText.length == 0) {
if (!noalert)
showAlert(GetTextByKey("P_IPT_QUESTIONDISPLAYTEXTNOTBEEMPTY", 'Question Display Text cannot be empty.'), alerttitle);
return false;
}
if (question.QuestionType == "17" && question.IsRequired == true && (!question.TextToCompare || question.TextToCompare.length == 0)) {
if (!noalert)
showAlert(GetTextByKey("P_IPT_TEXTTPCOMPARENOTBEEMPTY", 'Text to compare cannot be empty.'), alerttitle);
return false;
}
}
if (this.optionmodules.length > 0) {
for (var i = 0; i < this.optionmodules.length; i++) {
var selectitem = this.optionmodules[i].getOptionValue();
if (!nocheck) {
if (!selectitem.Text || selectitem.Text.length == 0) {
if (!noalert)
showAlert(GetTextByKey("P_IPT_OPTIONNAMECANNOTBEEMPTY", 'Option name cannot be empty.'), alerttitle);
return false;
}
}
question.SelectItems.push(selectitem)
}
}
//if (!nocheck && !noalert) {
// if (!noalert) {
// if ((question.QuestionType === "8" || question.QuestionType === "9") && question.SelectItems.length == 0) {
// showAlert('There must be at least one choice.', alerttitle);
// return false;
// }
// }
//}
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) {
_this.holder.remove();
return;
}
var p = JSON.stringify([teamintelligence, htmlencode(_this.question.Id)]);
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")
_this.sectionmodule.refresh();
}, function (err) {
showAlert(GetTextByKey("P_IPT_FAILEDTODELETEQUESTION", 'Failed to delete question.'), GetTextByKey("P_IPT_DELETEQUESTION", "Delete Question"));
});
});
};
q.prototype.onsave = function () {
var _this = this;
if (sectiontype == 1) return;
var item = _this.getQuestionValue(true);
if (!item) return;
if (_this.saving) {
_this.datachanged = true;
return;
}
var param = JSON.stringify(item);
param = htmlencode(param);
_this.saving = true;
var p = JSON.stringify([teamintelligence, _this.section.Id, param]);
inspectionrequest("SaveGlobalQuestion", p, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question'));
}
else {
if (!_this.question)
_this.question = {};
_this.question.Id = data[0];
}
_this.saving = false;
if (_this.datachanged)
_this.onsave();
}, function (err) {
showAlert(GetTextByKey("P_IPT_FAILEDTOSAVEQUESTION", 'Failed to save question.'), GetTextByKey("P_IPT_SAVEQUESTION", 'Save Question'));
_this.saving = false;
if (_this.datachanged)
_this.onsave();
});
}
return q;
});

View File

@ -0,0 +1,410 @@
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) {
this.section = section;
this.content = null;
this.holder = null;
this.gsmodule = gsm;
this.pagemodule = pm;
this.txtName = null;
this.txtDisplayText = null;
if (!this.section.Questions)
this.section.Questions = [];
this.questionmodules = [];
};
s.prototype.moduletype = "section";
s.prototype.description = "Section Module";
s.prototype.version = "1.0.0.0";
s.prototype.ondelete = null;
s.prototype.createContent = function () {
var content = $('<div></div>');
this.content = content;
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;
}
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>');
holder.append(package);
}
if (sectiontype == 1) {
var drag = $('<div class="question-icon" style="width:30px;"><em class="spanbtn iconmove rowdrag"></em></div>');
holder.append(drag);
if (sectiontype == 1) {
drag.attr('draggable', true);
holder.bind('dragstart', function (e) {
//var data = e.originalEvent.dataTransfer;
draggingobj = _this;
});
holder.bind('dragend', function (e) {
draggingobj = null;
});
holder.bind('dragover', function (e) {
e.originalEvent.preventDefault()
});
holder.bind('drop', function (e) {
if (!draggingobj || _this === draggingobj)
return;
if (draggingobj.moduletype == "question") {
if (_this.section.IsLink)
return;
$(this).after(draggingobj.holder);
draggingobj.sectionmodule.dragOutQuestion(draggingobj);
_this.dragInQuestion(null, draggingobj, true);
}
else {
var t = $(this);
var after = e.originalEvent.clientY > t.offset().top + t.height() / 2;
if (after)
t.parent().after(draggingobj.holder.parent());
else
t.parent().before(draggingobj.holder.parent());
draggingobj.pagemodule.dragOutSection(draggingobj);
_this.pagemodule.dragInSection(_this.section, draggingobj, after);
}
});
}
else
drag.children().remove();
if ((templatereadonly || !editable))
drag.hide();
}
var btnsection = $('<div class="section-icon" style="width: 30px;"><em class="spanbtn iconangleright" style="font-size:18px;"></em></div>');
btnsection.click(function () {
var icon = btnsection.find('.spanbtn');
if (icon.hasClass('iconangleright')) {
icon.removeClass('iconangleright').addClass('iconangledown');
if (sectiontype == 0) {
_this.getQuestions();
}
else
_this.updateQuestions(_this.section.Questions);
}
else {
if (sectiontype == 1)
_this.getSectionValue(true, true);
icon.removeClass('iconangledown').addClass('iconangleright');
_this.content.children('.questionitem').remove();
}
});
holder.append(btnsection);
this.txtName = $('<input type="text" class="section-input" maxlength="100" autocomplete="off" style="width:156px;" />');
this.txtName.change(function () {
_this.onsave();
});
var addiText = $('<span class="spanbtn iconmultitext" style="font-size:14px;" title="' + GetTextByKey("P_IPT_ADDITIONALTEXTS", "Additional Texts") + '"/>');
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));
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_ADDITIONALTEXTS", "Additional Texts") + '"/>');
addiText.click(function () {
Common.createMultiTextDialog(_this.txtDisplayText, _this.section);
});
var imgicon = $('<span class="spanbtn iconimage" style="font-size:14px;" title="' + GetTextByKey("P_IPT_PICTURES", "Pictures") + '"/>');
imgicon.click(function (e) {
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(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('<em class="spanbtn iconlink" style="cursor:default;margin:0;padding-left:0;padding-right:2px;font-size:10px;"></em>');
holder.find('input').prop('disabled', true);
holder.find('.iconmultitext').remove();
holder.find('.iconimage').remove();
}
if (!templatereadonly && editable) {
if (!_this.section.IsLink) {
funcs.append($('<em class="spanbtn iconadd"></em>').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 = { QuestionType: '0', IsRequired: false, CanComment: false, IsImportant: false, SeverityLevel: 0, LookupSource: 0, SelectItems: [] };
_this.section.Questions.push(question);
_this.addQuestionModule(question);
}).attr('title', GetTextByKey("P_IPT_ADDQUESTION", 'Add Question')));
}
if (sectiontype == 1 && !_this.section.IsLink) {
funcs.append($('<em class="spanbtn iconcopy"></em>').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($('<em class="spanbtn iconedit"></em>').click(function () {
// _this.onedit();
// }).attr('title', 'Edit Section'));
//}
}
if ((sectiontype === 0 && !templatereadonly) || (sectiontype === 1 && !templatereadonly && editable)) {
funcs.append($('<em class="spanbtn icondelete"></em>').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) {//<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD>
// e.originalEvent.preventDefault();
//});
if (templatereadonly || !editable) {
this.txtName.prop('disabled', true);
this.txtDisplayText.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();
this.holder.find('.section-createdby span').text('');
}
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);;
}
};
s.prototype.getSectionValue = function (noalert, nocheck) {
var section = this.section;
section.Name = this.txtName.val();
section.DisplayText = this.txtDisplayText.val();
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);
}
}
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]);
}
};
s.prototype.addQuestionModule = function (q) {
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.questionmodules.push(qmodule);
this.content.append(qmodule.createContent());
};
s.prototype.oncopyquestion = function (question) {
question = JSON.parse(JSON.stringify(question));
question.Id = "";
//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);
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);
}
};
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;
});