add site
This commit is contained in:
673
Site/Inspection/js/modules/templates/addtemplate.js
Normal file
673
Site/Inspection/js/modules/templates/addtemplate.js
Normal file
@ -0,0 +1,673 @@
|
||||
define(['modules/templates/pages', 'modules/templates/filters', 'modules/templates/picture'], function (Pages, Filters, Picture) {
|
||||
var s = function (gs, template) {
|
||||
this.template = template || {};
|
||||
currenttemplate = this.template;
|
||||
this.gsmodule = gs;
|
||||
this.datasaved = false;
|
||||
this.content = null;
|
||||
};
|
||||
s.prototype.description = "Add or edit template";
|
||||
s.prototype.version = "1.0.0.0";
|
||||
|
||||
var namecontrol = undefined;
|
||||
var locationenabledcontrol = undefined;
|
||||
var needsignaturecontrol = undefined;
|
||||
var forworkordercontrol = undefined;
|
||||
var displaycommittimecontrol = undefined;
|
||||
var displaycommitbycontrol = undefined;
|
||||
var displayinspectiontitlecontrol = undefined;
|
||||
var layoutcontrol = undefined;
|
||||
var lockedcontrol = undefined;
|
||||
var notescontrol = undefined;
|
||||
var otheremailcontrol = undefined;
|
||||
var pages = undefined;
|
||||
var filtertd = undefined;
|
||||
var filtersmodule = undefined;
|
||||
var picturesdiv = undefined;
|
||||
var picturesadd = undefined;
|
||||
var grid_contactdt;
|
||||
var pagesicon = undefined;
|
||||
var pagescontent = undefined;
|
||||
|
||||
|
||||
s.prototype.createContent = function () {
|
||||
var content = $('<div style="min-width:1350px;"></div>');
|
||||
this.content = content;
|
||||
var _this = this;
|
||||
function createHeader() {
|
||||
var header = $('<div></div>');
|
||||
|
||||
var func = $('<div class="function_title"></div>');
|
||||
if (!templatereadonly) {
|
||||
var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE", "Save") + '</span>').click(function () {
|
||||
onSave(0, 0);
|
||||
});
|
||||
func.append(btn);
|
||||
btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE1", "Save and Exit") + '</span>').click(function () {
|
||||
onSave(1, 0);
|
||||
});
|
||||
func.append(btn);
|
||||
if ((templatestatus == 0 || (!_this.template.Id && templatestatus == 1))
|
||||
&& (!_this.template.Id || _this.template.Editable || IsForesight)) {
|
||||
btn = $('<span class="sbutton iconshare">' + GetTextByKey("P_IPT_SAVEANDPUBLISH", "Save and Publish") + '</span>').click(function () {
|
||||
onSave(1, 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);
|
||||
header.append(func)
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
function createTemplateContent() {
|
||||
var div_main = $('<div class="content_main" style="overflow: auto;margin-top:5px;"></div>');
|
||||
var div_content = $('<div class="edit-content"></div>');
|
||||
div_main.append(div_content);
|
||||
var tb = $('<table></table>');
|
||||
div_content.append(tb);
|
||||
|
||||
var tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
var td = $('<td class="label" style="width:160px;"></td>');
|
||||
tr.append(td);
|
||||
//tr.append('<td class="label" style="width:100px;">Name:<span class="redasterisk">*</span></td>');
|
||||
|
||||
var btnsummary = $('<span class="section-icon" style="width:30px;margin-left:8px;margin-right:10px;font-size:18px;color:#666;cursor:pointer;">' + GetTextByKey("P_IPT_SUMMARY", "Summary") + '<em class="spanbtn iconangledown" style="font-size:18px;color:#666;"></em></span>');
|
||||
btnsummary.click(function () {
|
||||
var icon = btnsummary.find('.spanbtn');
|
||||
if (icon.hasClass('iconangledown')) {
|
||||
icon.removeClass('iconangledown').addClass('iconangleright');
|
||||
_this.content.find('.templatetr').hide();
|
||||
}
|
||||
else {
|
||||
icon.removeClass('iconangleright').addClass('iconangledown');
|
||||
_this.content.find('.templatetr').show();
|
||||
}
|
||||
});
|
||||
td.append(btnsummary).append('<span>' + GetTextByKey("P_IPT_NAME_COLON", "Name:") + '</span><span class="redasterisk">*</span>');
|
||||
|
||||
namecontrol = $('<input type="text" class="form-control" maxlength="100" autocomplete="off"/>');
|
||||
tr.append($('<td></td>').append(namecontrol));
|
||||
|
||||
tr = $('<tr class="templatetr"></tr>');
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:160px;">' + GetTextByKey("P_IPT_LOCATIONENABLED_COLON", "Location Enabled:") + '</td>');
|
||||
locationenabledcontrol = $('<input type="checkbox"/>');
|
||||
needsignaturecontrol = $('<input type="checkbox"/>');
|
||||
var td = $('<td></td>').append(
|
||||
locationenabledcontrol,
|
||||
$('<span style="margin-left:40px"></span>').text(GetTextByKey("P_IPT_SIGNATUREREQUIRED_COLON", "Signature Required:")),
|
||||
needsignaturecontrol
|
||||
);
|
||||
if (!teamintelligence) {
|
||||
td.append($('<span style="margin-left:40px"></span>').text(GetTextByKey("P_IPT_FORWORKORDER_COLON", "For Work Order:")));
|
||||
forworkordercontrol = $('<input type="checkbox"/>');
|
||||
td.append(forworkordercontrol);
|
||||
}
|
||||
tr.append(td);
|
||||
|
||||
tr = $('<tr class="templatetr"></tr>');
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:160px;">' + GetTextByKey("P_IPT_XXXXX_COLON", "Display Commit Time:") + '</td>');
|
||||
displaycommittimecontrol = $('<input type="checkbox" checked="checked"/>');
|
||||
displaycommitbycontrol = $('<input type="checkbox" checked="checked"/>');
|
||||
displayinspectiontitlecontrol = $('<input type="checkbox" checked="checked"/>');
|
||||
var td = $('<td></td>').append(
|
||||
displaycommittimecontrol,
|
||||
$('<span style="margin-left:40px"></span>').text(GetTextByKey("P_IPT_XXXXXX_COLON", "Display Commit By:")),
|
||||
displaycommitbycontrol,
|
||||
$('<span style="margin-left:40px"></span>').text(GetTextByKey("P_IPT_XXXXXX_COLON", "Display Inspection Title:")),
|
||||
displayinspectiontitlecontrol
|
||||
);
|
||||
tr.append(td);
|
||||
|
||||
tr = $('<tr class="templatetr"></tr>');
|
||||
tb.append(tr);
|
||||
tr.append($('<td class="label" style="width:160px;"></td>').text(GetTextByKey("P_LAYOUT_COLON", "Layout:")));
|
||||
layoutcontrol = $('<select id="select-layout" class="form-control" style="height: 24px"></select>');
|
||||
tr.append($('<td></td>').append(layoutcontrol));
|
||||
|
||||
if (!teamintelligence) {
|
||||
tr = $('<tr class="templatetr" style="height:30px;"></tr>');
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:160px;vertical-align:top;">' + GetTextByKey("P_IPT_FILTER_COLON", "Filter:") + '</td>')
|
||||
.attr("title", GetTextByKey("P_IPT_FILTERTOOLTIPS", "Multiple filters can be applied that act as independent assignments"));
|
||||
filtertd = $('<td></td>');
|
||||
tr.append(filtertd);
|
||||
}
|
||||
|
||||
picturesdiv = $('<div style="width:540px;"><div>');
|
||||
tr = $('<tr class="templatetr" style="height:30px;"></tr>');
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:160px;vertical-align:top;">' + GetTextByKey("P_IPT_PICTURE_COLON", "Picture:") + '</td>');
|
||||
picturesadd = $('<span class="sbutton iconadd">' + GetTextByKey("P_IPT_ADD", "Add") + '</span>').click(function () {
|
||||
var picturemodule = new Picture(true, _this.template, setPictures);
|
||||
picturemodule.createContent();
|
||||
});
|
||||
tr.append($('<td></td>').append(picturesadd));
|
||||
tr = $('<tr class="templatetr" style="height:30px;"></tr>');
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:160px;vertical-align:top;"></td>');
|
||||
tr.append($('<td></td>').append(picturesdiv));
|
||||
|
||||
if (IsForesight) {
|
||||
tr = $('<tr class="templatetr"></tr>');
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:160px;">' + GetTextByKey("P_IPT_LOCKED_COLON", "Locked:") + '</td>');
|
||||
lockedcontrol = $('<input type="checkbox"/>');
|
||||
lockedcontrol.prop('checked', false);
|
||||
tr.append($('<td></td>').append(lockedcontrol));
|
||||
lockedcontrol.click(function () {
|
||||
editable = !$(this).prop("checked");
|
||||
_this.template.Editable = editable;
|
||||
updateContent();
|
||||
});
|
||||
}
|
||||
|
||||
tr = $('<tr class="templatetr"></tr>');
|
||||
tb.append(tr);
|
||||
tr.append('<td class="label" style="width:160px;">' + GetTextByKey("P_IPT_NOTES_COLON", "Notes:") + '</td>');
|
||||
notescontrol = $('<textarea id="dialog_notes" class="inputbox form-control" maxlength="500" autocomplete="off" style="width: 540px; margin-top: 6px;height:80px;"></textarea>');
|
||||
tr.append($('<td></td>').append(notescontrol));
|
||||
|
||||
//Email
|
||||
tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
td = $('<td class="label" style="width:160px;"></td>');
|
||||
tr.append(td);
|
||||
var btnemail = $('<span class="section-icon" style="float:left;width:65px;margin-left:42px;margin-top:10px;margin-right:10px;font-size:18px;color:#666;cursor:pointer;">' + GetTextByKey("P_IPT_EMAIL", "Email") + '<em class="spanbtn iconangledown" style="font-size:18px;color:#666;"></em></span>');
|
||||
btnemail.click(function () {
|
||||
var icon = btnemail.find('.spanbtn');
|
||||
if (icon.hasClass('iconangledown')) {
|
||||
icon.removeClass('iconangledown').addClass('iconangleright');
|
||||
_this.content.find('.emailtd').hide();
|
||||
}
|
||||
else {
|
||||
icon.removeClass('iconangleright').addClass('iconangledown');
|
||||
_this.content.find('.emailtd').show();
|
||||
}
|
||||
});
|
||||
td.append(btnemail);
|
||||
|
||||
tr.append($('<td class="emailtd"></td>').append(createEmailContent()));
|
||||
|
||||
|
||||
return div_main;
|
||||
}
|
||||
|
||||
function createEmailContent() {
|
||||
var tb = $('<table style="line-height:25px;margin-top:10px;"></table>');
|
||||
|
||||
var tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
tr.append($('<td>' + GetTextByKey('P_IPT_SENDTHISTO', 'Who do you want to send this to? Select from existing relationships or manual entry.') + '</td>'));
|
||||
|
||||
tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
tr.append($('<td></td>').append(InitContactGridData()));
|
||||
|
||||
tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
tr.append($('<td>' + GetTextByKey("P_IPT_EMAILADDRESSESTIPS", "Separate multiple manually entered email addresses with a semi-colon (;).") + '</td>'));
|
||||
|
||||
tr = $('<tr></tr>');
|
||||
tb.append(tr);
|
||||
otheremailcontrol = $('<input type="text" class="form-control" maxlength="1000" autocomplete="off" style="margin-left:5px;width: 312px;" autocomplete="off" />');
|
||||
tr.append($('<td><span>' + GetTextByKey("P_IPT_OTHEREMAILADDRESS", "Other Email Address") + '</span></td>').append(otheremailcontrol));
|
||||
|
||||
td = $('<td></td>');
|
||||
tr.append(td);
|
||||
|
||||
return tb;
|
||||
}
|
||||
|
||||
function InitContactGridData() {
|
||||
var div_grid = $('<div style="width:430px;height:160px;"></div>');
|
||||
grid_contactdt = new GridView(div_grid);
|
||||
grid_contactdt.lang = {
|
||||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||||
};
|
||||
var list_columns = [
|
||||
{ name: 'UserName', caption: GetTextByKey("P_IPT_CONTACTNAME", "Contact Name"), valueIndex: 'UserName', css: { 'width': 180, 'text-align': 'left' } },
|
||||
{ name: 'ContactType', caption: GetTextByKey("P_IPT_CONTACTTYPE", "Contact Type"), valueIndex: 'ContactType', css: { 'width': 180, 'text-align': 'left' } },
|
||||
//{ name: 'Text', caption: "Text", valueIndex: 'Text', type: 3, css: { 'width': 45, 'text-align': 'center' } },
|
||||
{ name: 'Selected', caption: GetTextByKey("P_IPT_EMAIL", "Email"), valueIndex: 'Selected', type: 3, css: { 'width': 45, 'text-align': 'center' } }
|
||||
];
|
||||
var columns = [];
|
||||
// head
|
||||
for (var hd in list_columns) {
|
||||
var col = {};
|
||||
col.name = list_columns[hd].name;
|
||||
col.caption = list_columns[hd].caption;
|
||||
col.visible = true;
|
||||
col.sortable = true;
|
||||
col.width = list_columns[hd].css.width;
|
||||
col.align = list_columns[hd].css["text-align"]
|
||||
col.key = list_columns[hd].valueIndex;
|
||||
if (list_columns[hd].type) {
|
||||
col.type = list_columns[hd].type;
|
||||
}
|
||||
columns.push(col);
|
||||
if (col.name === "Email") {
|
||||
col.attrs = function (item) {
|
||||
}
|
||||
}
|
||||
}
|
||||
grid_contactdt.canMultiSelect = false;
|
||||
grid_contactdt.columns = columns;
|
||||
grid_contactdt.init();
|
||||
|
||||
grid_contactdt.selectedrowchanged = function (rowindex) {
|
||||
var rowdata = grid_contactdt.source[rowindex];
|
||||
if (rowdata) {
|
||||
}
|
||||
}
|
||||
return div_grid;
|
||||
}
|
||||
|
||||
function GetInspectEmailList() {
|
||||
inspectionrequest("GetInspectEmailList", teamintelligence, function (data) {
|
||||
if (typeof (data) !== "string") {
|
||||
showInspectEmailList(data);
|
||||
}
|
||||
}, function (err) {
|
||||
});
|
||||
}
|
||||
|
||||
function getReportLayouts() {
|
||||
inspectionrequest('GetInspectLayouts', JSON.stringify([teamintelligence ? 1 : 0, '']), function (data) {
|
||||
if ($.isArray(data)) {
|
||||
var sid = _this.template && _this.template.ReportLayoutId;
|
||||
layoutcontrol.empty().append($('<option value=""> </option>').prop('selected', sid == null || sid == ''));
|
||||
for (var l of data) {
|
||||
layoutcontrol.append($('<option></option>').val(l.Id).text(l.Name).prop('selected', sid == l.Id));
|
||||
}
|
||||
}
|
||||
}, function () { });
|
||||
}
|
||||
|
||||
function showInspectEmailList(data) {
|
||||
var rows = [];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var r = data[i];
|
||||
r.Selected = false;
|
||||
if (_this.template && _this.template.EmailList) {
|
||||
for (var j = 0; j < _this.template.EmailList.length; j++) {
|
||||
if (r.UserIID.toLowerCase() == _this.template.EmailList[j].UserIID.toLowerCase()) {
|
||||
r.Selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
var fr = { Values: r };
|
||||
rows.push(fr);
|
||||
}
|
||||
|
||||
grid_contactdt.setData(rows);
|
||||
}
|
||||
|
||||
function getTemplateInfo(id) {
|
||||
var p = JSON.stringify([teamintelligence, htmlencode(id)]);
|
||||
inspectionrequest("GetTemplate", p, function (data) {
|
||||
if (typeof (data) !== "string") {
|
||||
_this.template = data;
|
||||
currenttemplate = _this.template;
|
||||
getReportLayouts();
|
||||
GetInspectEmailList();
|
||||
updateContent();
|
||||
}
|
||||
}, function (err) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateContent() {
|
||||
if (pagesicon) {
|
||||
pagesicon.remove();
|
||||
pagesicon = undefined;
|
||||
}
|
||||
if (pagescontent) {
|
||||
pagescontent.remove();
|
||||
pagescontent = undefined;
|
||||
}
|
||||
if (filtertd)
|
||||
filtertd.empty();
|
||||
|
||||
pagesicon = $('<div class="section-icon" style="width:30px;margin:10px 0 5px 15px;font-size:18px;color:#666;">' + GetTextByKey("P_IPT_PAGES", "Pages") + '</div>');
|
||||
content.append(pagesicon);
|
||||
var template = _this.template;
|
||||
|
||||
if (template.Id) {
|
||||
if ((!template.IssueId || template.IssueId == "") && (template.Editable))
|
||||
editable = true;
|
||||
else
|
||||
editable = false;
|
||||
|
||||
namecontrol.val(template.Name);
|
||||
locationenabledcontrol.prop('checked', template.LocationEnabled);
|
||||
needsignaturecontrol.prop('checked', template.NeedSignature);
|
||||
if (forworkordercontrol)
|
||||
forworkordercontrol.prop('checked', template.ForWorkOrder);
|
||||
|
||||
displaycommittimecontrol.prop('checked', template.DisplayCommitTime);
|
||||
displaycommitbycontrol.prop('checked', template.DisplayCommitBy);
|
||||
displayinspectiontitlecontrol.prop('checked', template.DisplayInspectionTitle);
|
||||
|
||||
layoutcontrol.val(template.ReportLayoutId);
|
||||
if (IsForesight) {
|
||||
lockedcontrol.prop('checked', !template.Editable);
|
||||
if (template.IssueId && template.IssueId != "")
|
||||
lockedcontrol.prop('disabled', true);
|
||||
}
|
||||
|
||||
notescontrol.val(template.Notes);
|
||||
otheremailcontrol.val(template.Emails);
|
||||
setPictures();
|
||||
var next = function () {
|
||||
pages = new Pages(template.Pages);
|
||||
pagescontent = pages.createContent();
|
||||
content.append(pagescontent);
|
||||
if (!teamintelligence) {
|
||||
filtersmodule = new Filters(template.Filters)
|
||||
filtertd.append(filtersmodule.createContent(template));
|
||||
}
|
||||
};
|
||||
inspectionrequest("GetFuelTypes", '', function (data) {
|
||||
if ($.isArray(data)) {
|
||||
window.fuelTypes = data;
|
||||
}
|
||||
next();
|
||||
}, function () {
|
||||
// TODO: network error
|
||||
});
|
||||
}
|
||||
else {
|
||||
var next = function () {
|
||||
pages = new Pages();
|
||||
pagescontent = pages.createContent();
|
||||
content.append(pagescontent);
|
||||
if (!teamintelligence) {
|
||||
filtersmodule = new Filters()
|
||||
filtertd.append(filtersmodule.createContent());
|
||||
}
|
||||
};
|
||||
inspectionrequest("GetFuelTypes", '', function (data) {
|
||||
if ($.isArray(data)) {
|
||||
window.fuelTypes = data;
|
||||
}
|
||||
next();
|
||||
}, function () {
|
||||
// TODO: network error
|
||||
});
|
||||
}
|
||||
|
||||
setEditable();
|
||||
}
|
||||
|
||||
function setPictures() {
|
||||
$(picturesdiv).empty();
|
||||
if (_this.template.StaticPictures && _this.template.StaticPictures.length > 0) {
|
||||
for (var i = 0; i < _this.template.StaticPictures.length; i++) {
|
||||
var p = _this.template.StaticPictures[i];
|
||||
var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', p.Url).attr('title', p.Name);
|
||||
$(picturesdiv).append(img);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setEditable() {
|
||||
if (editable) {
|
||||
namecontrol.prop('disabled', false);
|
||||
locationenabledcontrol.prop('disabled', false);
|
||||
needsignaturecontrol.prop('disabled', false);
|
||||
|
||||
if (forworkordercontrol)
|
||||
forworkordercontrol.prop('disabled', false);
|
||||
|
||||
displaycommittimecontrol.prop('disabled', false);
|
||||
displaycommitbycontrol.prop('disabled', false);
|
||||
displayinspectiontitlecontrol.prop('disabled', false);
|
||||
|
||||
layoutcontrol.prop('disabled', false);
|
||||
notescontrol.prop('disabled', false);
|
||||
picturesadd.show();
|
||||
}
|
||||
else {
|
||||
namecontrol.prop('disabled', true);
|
||||
locationenabledcontrol.prop('disabled', true);
|
||||
needsignaturecontrol.prop('disabled', true);
|
||||
if (forworkordercontrol)
|
||||
forworkordercontrol.prop('disabled', true);
|
||||
|
||||
displaycommittimecontrol.prop('disabled', true);
|
||||
displaycommitbycontrol.prop('disabled', true);
|
||||
displayinspectiontitlecontrol.prop('disabled', true);
|
||||
|
||||
layoutcontrol.prop('disabled', true);
|
||||
notescontrol.prop('disabled', true);
|
||||
picturesadd.hide();
|
||||
}
|
||||
}
|
||||
|
||||
function setDisabled() {
|
||||
namecontrol.prop('disabled', true);
|
||||
locationenabledcontrol.prop('disabled', true);
|
||||
needsignaturecontrol.prop('disabled', true);
|
||||
if (forworkordercontrol)
|
||||
forworkordercontrol.prop('disabled', true);
|
||||
|
||||
displaycommittimecontrol.prop('disabled', true);
|
||||
displaycommitbycontrol.prop('disabled', true);
|
||||
displayinspectiontitlecontrol.prop('disabled', true);
|
||||
|
||||
layoutcontrol.prop('disabled', true);
|
||||
notescontrol.prop('disabled', true);
|
||||
otheremailcontrol.prop('disabled', true);
|
||||
if (IsForesight)
|
||||
lockedcontrol.prop('disabled', true);
|
||||
}
|
||||
|
||||
function CheckEmail(mail) {
|
||||
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
|
||||
if (mail.length == 0)
|
||||
return true;
|
||||
return filter.test(mail);
|
||||
}
|
||||
|
||||
function getSubTypeName(type) {
|
||||
var typename = "";
|
||||
if (type === "0")
|
||||
typename = GetTextByKey("P_IPT_ST_TRANSACTIONDATE", "Transaction Date");
|
||||
if (type === "1")
|
||||
typename = GetTextByKey("P_IPT_ST_TICKETRECEIPTNUMBER", "Ticket/Receipt Number");
|
||||
if (type === "2")
|
||||
typename = GetTextByKey("P_IPT_ST_DRIVERNAME", "Driver Name");
|
||||
else if (type === "3")
|
||||
typename = GetTextByKey("P_IPT_ST_RETAILERNAME", "Retailer Name");
|
||||
else if (type === "4")
|
||||
typename = GetTextByKey("P_IPT_ST_RETAILERADDRESS", "Retailer Address");
|
||||
else if (type === "5")
|
||||
typename = GetTextByKey("P_IPT_ST_CITY", "City");
|
||||
else if (type === "6")
|
||||
typename = GetTextByKey("P_IPT_ST_STATE", "State");
|
||||
else if (type === "7")
|
||||
typename = GetTextByKey("P_IPT_ST_ZIP", "Zip");
|
||||
else if (type === "8")
|
||||
typename = GetTextByKey("P_IPT_ST_ODOMETER", "Odometer");
|
||||
else if (type === "9")
|
||||
typename = GetTextByKey("P_IPT_ST_FUELTYPE", "Fuel Type");
|
||||
else if (type === "10")
|
||||
typename = GetTextByKey("P_IPT_ST_QUANTITY", "Quantity");
|
||||
else if (type === "11")
|
||||
typename = GetTextByKey("P_IPT_ST_UOMCOST", "Unit Cost");
|
||||
else if (type === "12")
|
||||
typename = GetTextByKey("P_IPT_ST_TOTALCOST", "Total Cost");
|
||||
else if (type === "13")
|
||||
typename = GetTextByKey("P_IPT_ST_BRANDNAME", "Brand Name");
|
||||
else if (type === "14")
|
||||
typename = GetTextByKey("P_IPT_ST_NOTES", "Notes");
|
||||
else if (type === "15")
|
||||
typename = GetTextByKey("P_IPT_ST_PICTURE", "Picture");
|
||||
else if (type === "16")
|
||||
typename = GetTextByKey("P_IPT_ST_DISTRIBUTEDBY", "Distributed By");
|
||||
return typename;
|
||||
}
|
||||
|
||||
function onSave(exit, publish) {
|
||||
var item = {
|
||||
'Name': namecontrol.val(),
|
||||
'LocationEnabled': locationenabledcontrol.prop('checked'),
|
||||
'NeedSignature': needsignaturecontrol.prop('checked'),
|
||||
'ReportLayoutId': layoutcontrol.val(),
|
||||
'DisplayCommitTime': displaycommittimecontrol.prop('checked'),
|
||||
'DisplayCommitBy': displaycommitbycontrol.prop('checked'),
|
||||
'DisplayInspectionTitle': displayinspectiontitlecontrol.prop('checked'),
|
||||
'Notes': notescontrol.val()
|
||||
};
|
||||
if (forworkordercontrol)
|
||||
item.ForWorkOrder = forworkordercontrol.prop('checked');
|
||||
|
||||
if (teamintelligence)
|
||||
item.Target = 1;
|
||||
|
||||
var alerttitle;
|
||||
if (_this.template.Id) {
|
||||
item.Id = _this.template.Id;
|
||||
item.Editable = _this.template.Editable;
|
||||
item.IssueId = _this.template.IssueId;
|
||||
alerttitle = GetTextByKey("P_IPT_EDITTEMPLATE", "Edit Template");
|
||||
} else {
|
||||
item.Id = -1;
|
||||
item.Editable = true;
|
||||
alerttitle = GetTextByKey("P_IPT_ADDTEMPLATE", "Add Template");
|
||||
}
|
||||
|
||||
if (IsForesight)
|
||||
item.Editable = !lockedcontrol.prop('checked');
|
||||
|
||||
if (publish === 1)
|
||||
item.Status = 1;
|
||||
else if (_this.template && _this.template.Status == 1)
|
||||
item.Status = 1;
|
||||
else
|
||||
item.Status = 0;
|
||||
|
||||
if (!item.Name || item.Name.length == 0) {
|
||||
showAlert(GetTextByKey("P_IPT_NAMENOTBEEMPTY", 'Name cannot be empty.'), alerttitle);
|
||||
return;
|
||||
}
|
||||
|
||||
//email
|
||||
var emailaddress = [];
|
||||
var otheremailaddressstr = otheremailcontrol.val();
|
||||
if (otheremailaddressstr !== "")
|
||||
emailaddress = otheremailaddressstr.split(';');
|
||||
item.Emails = "";
|
||||
for (var i = 0; i < emailaddress.length; i++) {
|
||||
var email = $.trim(emailaddress[i]);
|
||||
if (!CheckEmail(email)) {
|
||||
showAlert(GetTextByKey('P_IPT_OTHEREMAILADDRESSISINVALID', 'The other email address {0} is invalid.').replace('{0}', emailaddress[i]), alerttitle);
|
||||
return;
|
||||
}
|
||||
if (item.Emails === "")
|
||||
item.Emails = email;
|
||||
else
|
||||
item.Emails = item.Emails + ";" + email;
|
||||
}
|
||||
item.Emails = otheremailaddressstr;
|
||||
item.EmailList = [];
|
||||
for (var i = 0; i < grid_contactdt.source.length; i++) {
|
||||
var ct = grid_contactdt.source[i].Values;
|
||||
if (ct.Selected)
|
||||
item.EmailList.push(ct);
|
||||
}
|
||||
|
||||
if (pages) {
|
||||
item.Pages = pages.getPagesValue();
|
||||
if (!item.Pages)
|
||||
return;
|
||||
|
||||
var subtypes = [];
|
||||
for (var i = 0; i < item.Pages.length; i++) {
|
||||
var page = item.Pages[i];
|
||||
for (var j = 0; j < page.Sections.length; j++) {
|
||||
var section = page.Sections[j];
|
||||
for (var k = 0; k < section.Questions.length; k++) {
|
||||
var question = section.Questions[k];
|
||||
if (question.QuestionType == "15" && question.SubType !== "15") {
|
||||
var type = question.SubType;
|
||||
|
||||
if (subtypes.indexOf(type) >= 0) {
|
||||
var typename = getSubTypeName(type);
|
||||
showAlert(GetTextByKey("P_IPT_ONLYONEQUESTIONCANBEINCLUDEDINTHETEMPLATE", "Only one {0} question can be included in the template.").replace('{0}', typename), GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template'));
|
||||
return;
|
||||
}
|
||||
else
|
||||
subtypes.push(type);
|
||||
}
|
||||
if (question.QuestionType == "17" && question.IsRequired == true && (!question.TextToCompare || question.TextToCompare.length == 0)) {
|
||||
showAlert(GetTextByKey("P_IPT_TEXTTPCOMPARENOTBEEMPTY", "Text to compare cannot be empty."), GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item.Filters = [];
|
||||
if (!teamintelligence && filtersmodule) {
|
||||
item.Filters = filtersmodule.getFiltersValue();
|
||||
}
|
||||
|
||||
item.StaticPictures = _this.template.StaticPictures;
|
||||
|
||||
var param = JSON.stringify(item);
|
||||
var p = JSON.stringify([teamintelligence, htmlencode(param)]);
|
||||
|
||||
inspectionrequest("SaveTemplate", p, function (data) {
|
||||
if (typeof (data) === "string") {
|
||||
showAlert(data, GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template'));
|
||||
} else {
|
||||
if (!_this.template.Id) {
|
||||
_this.template.Id = data[0];
|
||||
}
|
||||
if (exit == 0) {
|
||||
showAlert(GetTextByKey("P_IPT_SAVSUCCESSFULLY", 'Saved successfully.'), GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template'));
|
||||
_this.datasaved = true;
|
||||
}
|
||||
if (exit == 1) {
|
||||
_this.gsmodule.refresh();
|
||||
showRightPopup(false);
|
||||
}
|
||||
}
|
||||
}, function (err) {
|
||||
showAlert(GetTextByKey("P_IPT_FAILEDTOSAVETEMPLATE", 'Failed to save Template.'), GetTextByKey("P_IPT_SAVETEMPLATE", 'Save Template'));
|
||||
});
|
||||
}
|
||||
|
||||
content.append(createHeader());
|
||||
content.append(createTemplateContent());
|
||||
|
||||
if (this.template.Id)
|
||||
getTemplateInfo(this.template.Id);
|
||||
else {
|
||||
getReportLayouts();
|
||||
GetInspectEmailList();
|
||||
updateContent();
|
||||
}
|
||||
|
||||
if (templatereadonly)
|
||||
setDisabled();
|
||||
return content;
|
||||
}
|
||||
return s;
|
||||
});
|
||||
|
Reference in New Issue
Block a user