add site
This commit is contained in:
407
Site/Inspection/js/modules/inspects/editinspection.js
Normal file
407
Site/Inspection/js/modules/inspects/editinspection.js
Normal file
@ -0,0 +1,407 @@
|
||||
define(['modules/inspects/editsection', 'modules/inspects/editquestion'], function (Section, Question) {
|
||||
var edit = function (inspection, id) {
|
||||
this.reportId = id;
|
||||
this.instance = inspection;
|
||||
};
|
||||
|
||||
var __proto = edit.prototype;
|
||||
|
||||
function onSave(_this, exit) {
|
||||
var alerttitle = GetTextByKey("P_IPT_EDITINSPECTION", 'Edit Inspection');
|
||||
if (!_this || !_this.report) {
|
||||
showAlert(GetTextByKey("P_IPT_PAGEERROR", 'An unknown error occurred. Please refresh page.'), alerttitle);
|
||||
return;
|
||||
}
|
||||
_this.loading && _this.loading.fadeIn(100);
|
||||
var pages = _this.content.children('div[data-page]');
|
||||
var answers = [];
|
||||
for (var i = 0; i < pages.length; i++) {
|
||||
var qs = $(pages[i]).find('.question-item');
|
||||
for (var j = 0; j < qs.length; j++) {
|
||||
var question = $(qs[j]).data('question');
|
||||
var q = question.question;
|
||||
var a = question.getAnswer();
|
||||
var flag;
|
||||
var msg;
|
||||
var isChoice =
|
||||
q.QuestionType === Question.types.List ||
|
||||
q.QuestionType === Question.types.DropDown ||
|
||||
q.QuestionType === Question.types.YesOrNo ||
|
||||
q.QuestionType === Question.types.EmailList ||
|
||||
q.QuestionType === Question.types.AssetStatus ||
|
||||
(q.QuestionType === Question.types.FuelRecords
|
||||
&& (q.SubType === Question.fueltypes.State ||
|
||||
q.SubType === Question.fueltypes.FuelType));
|
||||
if (q.IsRequired) {
|
||||
if (isChoice) {
|
||||
flag = a.SelectedItems == null || a.SelectedItems.length == 0;
|
||||
} else if (a.Result == null || a.Result.length == 0) {
|
||||
if (q.QuestionType === Question.types.Picture) {
|
||||
flag = false;
|
||||
} else if (q.QuestionType === Question.types.FuelRecords
|
||||
&& (q.SubType === Question.fueltypes.TotalCost ||
|
||||
q.SubType === Question.fueltypes.Picture)) {
|
||||
flag = false;
|
||||
} else {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
} else if (a.Comment == null || a.Comment.length == 0) {
|
||||
if (isChoice) {
|
||||
if (a.SelectedItems == null || a.SelectedItems.length == 0) {
|
||||
continue;
|
||||
}
|
||||
} else if (a.Result == null || a.Result.length == 0) {
|
||||
if (q.QuestionType !== Question.types.Picture) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// check
|
||||
if (!flag && a.Result != null && a.Result.length > 0) {
|
||||
switch (q.QuestionType) {
|
||||
case Question.types.DateAndTime:
|
||||
if (isNaN(new Date(a.Result.replace(' ', 'T')))) {
|
||||
msg = GetTextByKey("P_IPT_SUPPLIEDINPUTISNOTAVALIDTIME", 'Supplied input is not a valid time.');
|
||||
}
|
||||
break;
|
||||
case Question.types.Email:
|
||||
var emails = a.Result.split(';');
|
||||
for (var k = 0; k < emails.length; k++) {
|
||||
if (!/^[0-9a-zA-Z][^@]*@[0-9a-zA-Z.]+$/.test(emails[k].trim())) {
|
||||
msg = GetTextByKey("P_IPT_VALIDEMAILADDRESSFORMATREQUIRED", 'Valid email address format required.');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Question.types.EngingHours:
|
||||
case Question.types.Number:
|
||||
case Question.types.Odometer:
|
||||
case Question.types.FuelUsed:
|
||||
if (isNaN(Number(a.Result))) {
|
||||
msg = GetTextByKey("P_IPT_SUPPLIEDINPUTISNOTAVALIDNUMBER", 'Supplied input is not a valid number.');
|
||||
}
|
||||
break;
|
||||
case Question.types.FuelRemaining:
|
||||
var d = Number(a.Result);
|
||||
if (isNaN(d) || d < 0 || d > 100) {
|
||||
msg = GetTextByKey("P_IPT_SUPPLIEDINPUTISNOTAVALIDPERCENTVALUE", 'Supplied input is not a valid percent value.');
|
||||
}
|
||||
break;
|
||||
case Question.types.Integer:
|
||||
if (isNaN(Number(a.Result)) || a.Result.indexOf('.') >= 0) {
|
||||
msg = 'Supplied input is not a valid integer.';
|
||||
}
|
||||
break;
|
||||
case Question.types.FuelRecords:
|
||||
switch (q.SubType) {
|
||||
case Question.fueltypes.Odometer:
|
||||
case Question.fueltypes.Quantity:
|
||||
if (isNaN(Number(a.Result))) {
|
||||
msg = GetTextByKey("P_IPT_SUPPLIEDINPUTISNOTAVALIDNUMBER", 'Supplied input is not a valid number.');
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag || msg) {
|
||||
showAlert(flag ? GetTextByKey("P_IPT_THEQUESTIONISREQUIRED", 'The question is required.') : (msg || GetTextByKey("P_IPT_QUESTIONRESULTISINVALID", 'Question result is invalid.')), alerttitle, null, function () {
|
||||
if (typeof question.focus === 'function') {
|
||||
question.focus();
|
||||
}
|
||||
});
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
return;
|
||||
}
|
||||
if (q.QuestionType === Question.types.AssetStatus) {
|
||||
a.Result = a.Comment;
|
||||
a.Comment = "";
|
||||
}
|
||||
|
||||
answers.push(a);
|
||||
}
|
||||
}
|
||||
_this.report.Answers = answers;
|
||||
_this.report.Medias = [];
|
||||
console.log(answers);
|
||||
|
||||
var p = JSON.stringify(_this.report);
|
||||
inspectionrequest('UpdateInspectionReport', htmlencode(p), function (result) {
|
||||
if (typeof result === 'string') {
|
||||
showAlert(GetTextByKey("P_IPT_PAGEERROR1", 'An unknown error occurred. ') + result, alerttitle);
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
return;
|
||||
} else if (!result) {
|
||||
showAlert(GetTextByKey("P_IPT_FAILEDTOUPDATEINSPECTION", 'Failed to update inspection.'), alerttitle);
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
return;
|
||||
} else {
|
||||
_this.changed = true;
|
||||
if (exit) {
|
||||
showRightPopup(false);
|
||||
if (typeof _this.instance === 'function') {
|
||||
showAlert(GetTextByKey("P_IPT_UPDATEINSPECTIONSUCCESSFULLY", 'Update inspection successfully.'), alerttitle, null, function () {
|
||||
_this.instance();
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
_this.instance.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
showAlert(GetTextByKey("P_IPT_UPDATEINSPECTIONSUCCESSFULLY", 'Update inspection successfully.'), alerttitle);
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
}, function () {
|
||||
showAlert(GetTextByKey("P_IPT_PAGEERROR", 'An unknown error occurred. Please refresh page.'), alerttitle);
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
});
|
||||
}
|
||||
|
||||
__proto.createContent = function () {
|
||||
var _this = this;
|
||||
var content = $('<div></div>');
|
||||
this.content = content;
|
||||
var funcs = $('<div class="function_title"></div>');
|
||||
var btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE", "Save") + '</span>').click(function () {
|
||||
onSave(_this);
|
||||
});
|
||||
funcs.append(btn);
|
||||
btn = $('<span class="sbutton iconsave">' + GetTextByKey("P_IPT_SAVE1", "Save and Exit") + '</span>').click(function () {
|
||||
onSave(_this, true);
|
||||
});
|
||||
funcs.append(btn);
|
||||
btn = $('<span class="sbutton iconexit">' + GetTextByKey("P_IPT_SAVE2", "Exit Without Saving") + '</span>').click(function () {
|
||||
showRightPopup(false);
|
||||
if (_this.changed) {
|
||||
if (typeof _this.instance === 'function') {
|
||||
_this.instance();
|
||||
} else {
|
||||
_this.instance.refresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
funcs.append(btn);
|
||||
content.append(funcs);
|
||||
|
||||
// committed information
|
||||
var info = $('<div style="margin: 6px 0 0 10px; line-height: 32px"></div>');
|
||||
var templatename = $('<span style="font-size: 1.7em"></span>');
|
||||
info.append(templatename);
|
||||
var committedby = $('<span style="margin-left: 10px"></span>');
|
||||
info.append(committedby);
|
||||
content.append(info);
|
||||
// asset info
|
||||
var assetpanel = $('<div style="margin: 6px 0 0 10px; line-height: 26px"></div>').hide();
|
||||
content.append(assetpanel);
|
||||
|
||||
var ul = $('<ul class="tab_header" style="padding-top: 5px;"></ul>');
|
||||
content.append(ul);
|
||||
|
||||
//var tabIndex = 0;
|
||||
//for (var i = 0; i < this.pages.length; i++) {
|
||||
// var p = this.pages[i];
|
||||
// addTab(p, false);
|
||||
//}
|
||||
var p = JSON.stringify([teamintelligence, this.reportId]);
|
||||
inspectionrequest('GetInspectionReportForEdit', htmlencode(p), function (data) {
|
||||
console.log(data);
|
||||
if (typeof data === 'string') {
|
||||
showAlert(data + GetTextByKey("P_IPT_REFRESHPAGE", ' Please refresh page.'), GetTextByKey("P_IPT_EDITINSPECTION", 'Edit Inspection'));
|
||||
return;
|
||||
}
|
||||
_this.report = data;
|
||||
//if (data.AssetList) {
|
||||
// window.AssetList = data.AssetList;
|
||||
//}
|
||||
if (data.EmailList) {
|
||||
window.EmailList = data.EmailList;
|
||||
}
|
||||
if (data.JobSiteList) {
|
||||
window.JobSiteList = data.JobSiteList;
|
||||
}
|
||||
templatename.text(data.Template.Name);
|
||||
committedby.text(data.CommitTimeLocalStr + ' by ' + data.CommitedByUserName);
|
||||
if (data.Target === 0 && data.Asset) {
|
||||
var asset = data.Asset;
|
||||
var tb = $('<table class="inspect-asset" style="width: 100%"></table>');
|
||||
var tr = $('<tr></tr>');
|
||||
var td = $('<td style="width: 25%"><b style="display: inline-block; width: 85px">' + GetTextByKey("P_IPT_ASSETNAME_COLON", "Asset Name:") + '</b></td>');
|
||||
td.append($('<span style="margin-left: 6px"></span>').text(asset.DisplayName));
|
||||
tr.append(td);
|
||||
td = $('<td colspan="3" style="width: 75%"><b style="display: inline-block; width: 145px">' + GetTextByKey("P_IPT_ASSETNAME2_COLON", "Asset Name(Custom):") + '</b></td>');
|
||||
td.append($('<span style="margin-left: 6px"></span>').text(asset.Name2 || asset.Name));
|
||||
tr.append(td);
|
||||
tb.append(tr);
|
||||
tr = $('<tr></tr>');
|
||||
td = $('<td style="width: 25%"><b style="display: inline-block; width: 85px">' + GetTextByKey("P_IPT_VINSN_COLON", "VIN/SN:") + '</b></td>');
|
||||
td.append($('<span style="margin-left: 6px"></span>').text(asset.VIN));
|
||||
tr.append(td);
|
||||
td = $('<td style="width: 30%"><b style="display: inline-block; width: 145px">' + GetTextByKey("P_IPT_MAKE_COLON", "Make:") + '</b></td>');
|
||||
td.append($('<span style="margin-left: 6px"></span>').text(asset.MakeName));
|
||||
tr.append(td);
|
||||
td = $('<td style="width: 20%"><b>' + GetTextByKey("P_IPT_MODEL_COLON", "Model:") + '</b></td>');
|
||||
td.append($('<span style="margin-left: 6px"></span>').text(asset.ModelName));
|
||||
tr.append(td);
|
||||
td = $('<td style="width: 25%"><b>' + GetTextByKey("P_IPT_ASSETTYPE_COLON", "Asset Type:") + '</b></td>');
|
||||
td.append($('<span style="margin-left: 6px"></span>').text(asset.TypeName));
|
||||
tr.append(td);
|
||||
tb.append(tr);
|
||||
|
||||
if (data.ForWorkOrder) {
|
||||
tr = $('<tr></tr>');
|
||||
td = $('<td style="width: 25%"><b style="display: inline-block; width: 85px">' + GetTextByKey("P_IPT_WORKORDER_COLON", "Work Order:") + '</b></td>');
|
||||
var selwo = $('<select style="margin-left: 6px;width: 160px"></select>');
|
||||
selwo.change(function () {
|
||||
_this.report.WorkOrderId = selwo.find("option:selected").val();
|
||||
});
|
||||
td.append(selwo);//WorkOrderId
|
||||
tr.append(td);
|
||||
|
||||
|
||||
td = $('<td style="width: 25%"><label for="chkcv"><b style="display: inline-block; width: 145px;">' + GetTextByKey("P_IPT_CUSTOMERVISIBLE_COLON", "Customer Visible:") + '</b><label></td>');
|
||||
var chkcv = $('<input id="chkcv" type="checkbox" style="margin-left: 6px;" />');
|
||||
chkcv.change(function () {
|
||||
_this.report.VisibleToCustomer = chkcv.prop("checked");
|
||||
});
|
||||
chkcv.prop("checked", _this.report.VisibleToCustomer);
|
||||
td.append(chkcv);//VisibleToCustomer
|
||||
tr.append(td);
|
||||
|
||||
tb.append(tr);
|
||||
|
||||
selwo.append($("<option></option>").val(-1).text(""));
|
||||
inspectionrequest('GetAssetWorkOrders', data.AssetId, function (list) {
|
||||
if (typeof list === 'string') {
|
||||
} else if (list && list.length > 0) {
|
||||
var txt = "";
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
var wo = list[i];
|
||||
txt = wo.Id;
|
||||
if (wo.CustomerName && $.trim(wo.CustomerName) != "")
|
||||
txt += " - " + wo.CustomerName;
|
||||
selwo.append($("<option></option>").val(wo.Id).text(txt));
|
||||
}
|
||||
}
|
||||
selwo.val(data.WorkOrderId);
|
||||
});
|
||||
}
|
||||
|
||||
assetpanel.empty().show().append(tb);
|
||||
}
|
||||
|
||||
// pages
|
||||
var hasAssets = false;
|
||||
for (var i = 0; i < data.Template.Pages.length; i++) {
|
||||
var page = data.Template.Pages[i];
|
||||
var name = 'page_' + i;
|
||||
var li = $('<li></li>').attr('data-href', name);
|
||||
if (i == 0) {
|
||||
li.addClass('selected');
|
||||
}
|
||||
ul.append(li);
|
||||
li.append($('<span class="spanbtn icondetail"></span>'));
|
||||
li.append($('<span></span>').text(page.DisplayText));
|
||||
|
||||
// content
|
||||
var p = $('<div></div>').attr('data-page', name);
|
||||
var change = (function (panel) {
|
||||
return function (e) {
|
||||
var v = e.data.getAnswer();
|
||||
var left = parseFloat(v && v.Result);
|
||||
if (isNaN(left)) {
|
||||
return;
|
||||
}
|
||||
var items = panel.find('.question-item');
|
||||
var total;
|
||||
var rightObj;
|
||||
var right = e.data.question.SubType === Question.fueltypes.Quantity
|
||||
? Question.fueltypes.UnitCost : Question.fueltypes.Quantity;
|
||||
for (var n = 0; n < items.length; n++) {
|
||||
var q = $(items[n]).data('question');
|
||||
if (q.question.QuestionType === Question.types.FuelRecords) {
|
||||
if (total == null && q.question.SubType === Question.fueltypes.TotalCost) {
|
||||
total = q;
|
||||
if (rightObj != null) {
|
||||
break;
|
||||
}
|
||||
} else if (rightObj == null && q.question.SubType === right) {
|
||||
rightObj = q;
|
||||
if (total != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (total != null && rightObj != null) {
|
||||
var a = rightObj.getAnswer();
|
||||
var val = parseFloat(a && a.Result);
|
||||
if (!isNaN(val)) {
|
||||
total.fillResult((left * val).toFixed(2));
|
||||
}
|
||||
}
|
||||
};
|
||||
})(p);
|
||||
for (var j = 0; j < page.Sections.length; j++) {
|
||||
var section = new Section(page.Sections[j], data);
|
||||
if (!hasAssets && section.section.Questions.filter(function (q) {
|
||||
return q.QuestionType === Question.types.DropDown && (
|
||||
q.LookupSource === Question.sources.Assets ||
|
||||
q.LookupSource === Question.sources.AssetCustomerName);
|
||||
}).length > 0) {
|
||||
hasAssets = true;
|
||||
inspectionrequest('GetAssetBasicInfoForEdit', '', function (list) {
|
||||
if (typeof list === 'string') {
|
||||
console.log(list);
|
||||
} else if (list && list.length > 0) {
|
||||
window.AssetList = list;
|
||||
var pages = _this.content.children('div[data-page]');
|
||||
for (var i = 0; i < pages.length; i++) {
|
||||
var qs = $(pages[i]).find('.question-item');
|
||||
for (var j = 0; j < qs.length; j++) {
|
||||
var question = $(qs[j]).data('question');
|
||||
var q = question.question;
|
||||
if (q.QuestionType === Question.types.DropDown && (
|
||||
q.LookupSource === Question.sources.Assets ||
|
||||
q.LookupSource === Question.sources.AssetCustomerName)) {
|
||||
question.setLoaded && question.setLoaded();
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(GetTextByKey("P_IPT_LOADEDASSETLIST", 'loaded asset list: ') + list.length);
|
||||
} else {
|
||||
console.log(GetTextByKey("P_IPT_FAILEDTODOWNLOADASSETLIST", 'failed to download asset list.'));
|
||||
}
|
||||
});
|
||||
}
|
||||
p.append(section.createContent(change));
|
||||
}
|
||||
content.append(p);
|
||||
|
||||
var items = p.find('.question-item');
|
||||
for (var n = 0; n < items.length; n++) {
|
||||
var q = $(items[n]).data('question');
|
||||
if (q.question.QuestionType === Question.types.FuelRecords
|
||||
&& (q.question.SubType === Question.fueltypes.Quantity ||
|
||||
q.question.SubType === Question.fueltypes.UnitCost)) {
|
||||
change({ data: q });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ul.append($('<li style="clear: both;"></li>'));
|
||||
content.tab();
|
||||
|
||||
_this.loading && _this.loading.fadeOut(100);
|
||||
});
|
||||
|
||||
var loading = $('<div id="mask_bg"></div>');
|
||||
_this.loading = loading;
|
||||
content.append(loading);
|
||||
|
||||
return content;
|
||||
};
|
||||
|
||||
return {
|
||||
EditInspection: edit
|
||||
}
|
||||
});
|
948
Site/Inspection/js/modules/inspects/editquestion.js
Normal file
948
Site/Inspection/js/modules/inspects/editquestion.js
Normal file
@ -0,0 +1,948 @@
|
||||
define([], function () {
|
||||
var QTypes = {
|
||||
SingleLineText: 0,
|
||||
MultipleLineText: 1,
|
||||
Email: 2,
|
||||
Number: 3,
|
||||
Integer: 4,
|
||||
YesOrNo: 5,
|
||||
Date: 6,
|
||||
DateAndTime: 7,
|
||||
DropDown: 8,
|
||||
List: 9,
|
||||
Picture: 10,
|
||||
Odometer: 11,
|
||||
EngingHours: 12,
|
||||
FuelRemaining: 13,
|
||||
EmailList: 14,
|
||||
FuelRecords: 15,
|
||||
BarCode: 16,
|
||||
BarCodeValidate: 17,
|
||||
FuelUsed: 18,
|
||||
AssetStatus: 19
|
||||
};
|
||||
var LookupSources = {
|
||||
None: 0,
|
||||
Jobsites: 1,
|
||||
Assets: 2,
|
||||
Employee: 3,
|
||||
AssetCustomerName: 4
|
||||
};
|
||||
var FuelRecordTypes = {
|
||||
TransactionDate: 0,
|
||||
TicketNumber: 1,
|
||||
DriverName: 2,
|
||||
RetailerName: 3,
|
||||
RetailerAddress: 4,
|
||||
City: 5,
|
||||
State: 6,
|
||||
Zip: 7,
|
||||
Odometer: 8,
|
||||
FuelType: 9,
|
||||
Quantity: 10,
|
||||
UnitCost: 11,
|
||||
TotalCost: 12,
|
||||
BrandName: 13,
|
||||
Notes: 14,
|
||||
Picture: 15,
|
||||
DistributedBy: 16
|
||||
};
|
||||
|
||||
// base question type
|
||||
var question = function (q) {
|
||||
this.question = q;
|
||||
// comment
|
||||
// content
|
||||
// unit
|
||||
this.ui = {};
|
||||
// items
|
||||
this.data = {};
|
||||
};
|
||||
question.prototype.createContent = function (answer, medias, change) {
|
||||
this.answer = answer;
|
||||
var content = $('<div class="question-item" style="line-height: 26px; margin: 0 0 22px 22px"></div>');
|
||||
var q = this.question;
|
||||
|
||||
var div_title = $('<div style="font-weight: bold; font-size: 1.1em"></div>').text(q.DisplayText);
|
||||
if (q.IsRequired) {
|
||||
div_title.append('<span style="color: red; margin-left: 4px">*</span>');
|
||||
}
|
||||
content.append(div_title);
|
||||
if (q.StaticPictures && q.StaticPictures.length > 0) {
|
||||
var div_pic = $('<div></div>');
|
||||
for (var i = 0; i < q.StaticPictures.length; i++) {
|
||||
var pic = q.StaticPictures[i];
|
||||
var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name);
|
||||
img.click(pic.Url, function (e) {
|
||||
window.open(e.data, "_blank")
|
||||
});
|
||||
div_pic.append(img);
|
||||
}
|
||||
content.append(div_pic);
|
||||
}
|
||||
|
||||
var cnt = $('<div style="margin: 6px 0 0 22px"></div>');
|
||||
if (typeof this.createQuestion === 'function') {
|
||||
this.ui.content = this.createQuestion(answer, medias, change);
|
||||
cnt.append(this.ui.content);
|
||||
} else {
|
||||
cnt.append('<div style="font-style: italic; color: #ccc"><Not implemented yet.></div>');
|
||||
}
|
||||
var divComment = $('<div style="padding: 6px 0"></div>');
|
||||
if (q.CanComment) {
|
||||
var comment = $('<textarea class="form-control" style="width: 100%; box-sizing: border-box; height: 70px" placeholder="Comment"></textarea>');
|
||||
comment.attr('maxlength', 500);
|
||||
if (answer && answer.Comment) {
|
||||
comment.val(answer.Comment);
|
||||
}
|
||||
this.ui.comment = comment;
|
||||
divComment.append(comment);
|
||||
}
|
||||
cnt.append(divComment);
|
||||
content.append(cnt);
|
||||
return content;
|
||||
};
|
||||
question.prototype.getAnswer = function () {
|
||||
var answer = this.answer;
|
||||
if (answer == null) {
|
||||
answer = {
|
||||
'QuestionId': this.question.Id,
|
||||
'SeverityLevel': this.question.SeverityLevel
|
||||
};
|
||||
this.answer = answer;
|
||||
}
|
||||
if (this.ui.comment != null) {
|
||||
answer.Comment = this.ui.comment.val();
|
||||
}
|
||||
return answer;
|
||||
};
|
||||
question.prototype.focus = function () {
|
||||
if (this.ui.comment != null) {
|
||||
this.ui.comment.focus();
|
||||
}
|
||||
};
|
||||
|
||||
// input type question
|
||||
var inputQuestion = function (q) {
|
||||
question.call(this, q);
|
||||
};
|
||||
inputQuestion.prototype = Object.create(question.prototype);
|
||||
inputQuestion.prototype.constructor = inputQuestion;
|
||||
inputQuestion.prototype.createQuestion = function (answer, _medias, change) {
|
||||
var content = $('<div></div>');
|
||||
var input;
|
||||
if (this.question.QuestionType === QTypes.MultipleLineText
|
||||
|| (this.question.QuestionType === QTypes.FuelRecords &&
|
||||
this.question.SubType === FuelRecordTypes.Notes)) {
|
||||
input = $('<textarea style="width: 100%; height: 70px"></textarea>');
|
||||
} else {
|
||||
input = $('<input type="text" style="width: 100%; height: 21px"></input>');
|
||||
}
|
||||
if (this.question.QuestionType === QTypes.Email) {
|
||||
input.attr('placeholder', 'name@example.com; ...');
|
||||
} else if (this.question.QuestionType === QTypes.FuelRecords) {
|
||||
if (this.question.SubType === FuelRecordTypes.TotalCost) {
|
||||
input.prop('readonly', true).css('background', '#eee');
|
||||
} else if (this.question.SubType === FuelRecordTypes.Quantity
|
||||
|| this.question.SubType === FuelRecordTypes.UnitCost) {
|
||||
if (typeof change === 'function') {
|
||||
input.on('input propertychange', this, change);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (answer && answer.Result) {
|
||||
input.val(answer.Result);
|
||||
}
|
||||
input.attr('maxlength', 500);
|
||||
input.css('box-sizing', 'border-box');
|
||||
input.addClass('form-control');
|
||||
this.ui.input = input;
|
||||
if (typeof this.createUnit === 'function') {
|
||||
content.append(this.createUnit(answer));
|
||||
content.append($('<div style="margin-right: 110px"></div>').append(input));
|
||||
} else {
|
||||
content.append(input);
|
||||
}
|
||||
|
||||
if (this.question.QuestionType === QTypes.AssetStatus) {
|
||||
if (_medias && _medias.length > 0) {
|
||||
var div_pic = $('<div></div>');
|
||||
for (var i = 0; i < _medias.length; i++) {
|
||||
var pic = _medias[i];
|
||||
var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name);
|
||||
img.click(pic.Url, function (e) {
|
||||
window.open(e.data, "_blank")
|
||||
});
|
||||
div_pic.append(img);
|
||||
}
|
||||
content.append(div_pic);
|
||||
}
|
||||
}
|
||||
|
||||
return content;
|
||||
};
|
||||
inputQuestion.prototype.getAnswer = function () {
|
||||
var answer = question.prototype.getAnswer.call(this);
|
||||
//if (this.question.QuestionType !== QTypes.FuelRecords ||
|
||||
// this.question.SubType !== FuelRecordTypes.TotalCost) {
|
||||
answer.Result = this.ui.input.val();
|
||||
//}
|
||||
return answer;
|
||||
};
|
||||
inputQuestion.prototype.fillResult = function (result) {
|
||||
if (this.ui.input != null) {
|
||||
this.ui.input.val(result);
|
||||
}
|
||||
};
|
||||
inputQuestion.prototype.focus = function () {
|
||||
this.ui.input.focus();
|
||||
};
|
||||
|
||||
// input with dropdown
|
||||
var inputDropQuestion = function (q) {
|
||||
inputQuestion.call(this, q);
|
||||
};
|
||||
inputDropQuestion.prototype = Object.create(inputQuestion.prototype);
|
||||
inputDropQuestion.prototype.constructor = inputDropQuestion;
|
||||
inputDropQuestion.prototype.createUnit = function (answer) {
|
||||
var selector = $('<select style="float: right; width: 100px; height: 21px; margin-top: 2px"></select>');
|
||||
var opts;
|
||||
if (this.question.QuestionType === QTypes.FuelRemaining) {
|
||||
opts = [{ v: 'percent', t: 'Percent' }];
|
||||
} else if (this.question.QuestionType === QTypes.Odometer) {
|
||||
opts = [
|
||||
{ v: 'mile', t: 'Mile(s)' },
|
||||
{ v: 'kilometre', t: 'kilometre' }
|
||||
];
|
||||
} else if (this.question.QuestionType === QTypes.FuelUsed) {
|
||||
opts = [
|
||||
{ v: 'Gallon', t: 'Gallon' },
|
||||
{ v: 'Litre', t: 'Litre' }
|
||||
];
|
||||
} else if (this.question.QuestionType === QTypes.FuelRecords) {
|
||||
if (this.question.SubType === FuelRecordTypes.Odometer) {
|
||||
opts = [
|
||||
{ v: 'mile', t: 'Mile(s)' },
|
||||
{ v: 'kilometre', t: 'Kilometer' }
|
||||
];
|
||||
} else if (this.question.SubType === FuelRecordTypes.Quantity) {
|
||||
opts = [
|
||||
{ v: 'Gallon', t: 'Gallon' },
|
||||
{ v: 'Litre', t: 'Litre' }
|
||||
];
|
||||
}
|
||||
} else {
|
||||
opts = [];
|
||||
}
|
||||
for (var i = 0; i < opts.length; i++) {
|
||||
var o = opts[i];
|
||||
selector.append($('<option></option>').val(o.v).text(o.t));
|
||||
}
|
||||
if (answer && answer.Units) {
|
||||
selector.val(answer.Units);
|
||||
} else {
|
||||
selector.val(opts[0].v);
|
||||
}
|
||||
this.ui.unit = selector;
|
||||
return selector;
|
||||
};
|
||||
inputDropQuestion.prototype.getAnswer = function () {
|
||||
var answer = inputQuestion.prototype.getAnswer.call(this);
|
||||
answer.Units = this.ui.unit.val();
|
||||
return answer;
|
||||
};
|
||||
|
||||
// list question
|
||||
var listQuestion = function (q) {
|
||||
question.call(this, q);
|
||||
};
|
||||
listQuestion.prototype = Object.create(question.prototype);
|
||||
listQuestion.prototype.constructor = listQuestion;
|
||||
listQuestion.prototype.createQuestion = function (answer) {
|
||||
var content = $('<div></div>');
|
||||
var q = this.question;
|
||||
for (var i = 0; i < q.SelectItems.length; i++) {
|
||||
var item = q.SelectItems[i];
|
||||
var line = $('<div></div>');
|
||||
var check;
|
||||
var name = 'item_' + q.Id;
|
||||
var id = name + '_' + i;
|
||||
var left = $('<div style="float: left"></div>');
|
||||
var val = item.Value || item.Text;
|
||||
if (q.MultipleSelect) {
|
||||
check = $('<input type="checkbox"></input>').attr('id', id).val(val);
|
||||
} else {
|
||||
check = $('<input type="radio"></input>').attr({ 'id': id, 'name': name }).val(val);
|
||||
}
|
||||
check.data('item', item);
|
||||
if (answer && answer.SelectedItems) {
|
||||
var s = answer.SelectedItems.filter(function (a) { return (a.Value || a.Text) === val });
|
||||
if (s.length > 0) {
|
||||
check.prop('checked', true);
|
||||
}
|
||||
}
|
||||
left.append(check);
|
||||
var circle = $('<div></div>').css({
|
||||
'width': 12,
|
||||
'height': 12,
|
||||
'border-radius': 6,
|
||||
'display': 'inline-block',
|
||||
'margin-left': 5,
|
||||
'vertical-align': 'middle'
|
||||
});
|
||||
circle.css('background-color', item.BackgroundColor);
|
||||
left.append(circle);
|
||||
line.append(left);
|
||||
line.append($('<label style="margin-left: 45px; display: block"></label>').attr('for', id).text(item.Text));
|
||||
|
||||
content.append(line);
|
||||
}
|
||||
return content;
|
||||
};
|
||||
listQuestion.prototype.getAnswer = function () {
|
||||
var answer = question.prototype.getAnswer.call(this);
|
||||
var checks = this.ui.content.find('input:checked');
|
||||
var items = [];
|
||||
for (var i = 0; i < checks.length; i++) {
|
||||
var item = $(checks[i]).data('item');
|
||||
items.push(item);
|
||||
}
|
||||
answer.SelectedItems = items;
|
||||
if (items.length > 0) {
|
||||
answer.Result = items.map(function (i) { return i.Value || i.Text }).join('\n');
|
||||
//answer.SeverityLevel = items[0].SeverityLevel;
|
||||
} else {
|
||||
answer.Result = '';
|
||||
}
|
||||
return answer;
|
||||
};
|
||||
listQuestion.prototype.focus = function () {
|
||||
var ele = this.ui.content.find('input:first');
|
||||
if (ele.length > 0) {
|
||||
ele.focus();
|
||||
} else {
|
||||
question.prototype.focus.call(this);
|
||||
}
|
||||
};
|
||||
|
||||
// date&time question
|
||||
var dateTimeQuestion = function (q) {
|
||||
question.call(this, q);
|
||||
};
|
||||
dateTimeQuestion.prototype = Object.create(question.prototype);
|
||||
dateTimeQuestion.prototype.constructor = dateTimeQuestion;
|
||||
dateTimeQuestion.prototype.createQuestion = function (answer) {
|
||||
var content = $('<div></div>');
|
||||
var q = this.question;
|
||||
var result;
|
||||
if (answer && answer.Result) {
|
||||
result = answer.Result.split(' ');
|
||||
}
|
||||
var date = $('<input type="text" style="width: 100px; height: 21px"></input>');
|
||||
date.css('box-sizing', 'border-box');
|
||||
date.addClass('form-control');
|
||||
if (result) {
|
||||
date.val(result[0]);
|
||||
}
|
||||
this.ui.date = date;
|
||||
content.append(date);
|
||||
date.datetimepicker({
|
||||
timepicker: false,
|
||||
format: 'Y-m-d',
|
||||
enterLikeTab: false,
|
||||
//onSelectDate: function (v, inp) {
|
||||
|
||||
//}
|
||||
});
|
||||
if (q.QuestionType === QTypes.DateAndTime
|
||||
|| (q.QuestionType === QTypes.FuelRecords &&
|
||||
q.SubType === FuelRecordTypes.TransactionDate)) {
|
||||
var time = $('<input type="text" style="width: 100px; margin-left: 10px; height: 21px"></input>');
|
||||
time.css('box-sizing', 'border-box');
|
||||
time.addClass('form-control');
|
||||
if (result) {
|
||||
time.val(result[1]);
|
||||
}
|
||||
this.ui.time = time;
|
||||
content.append(time);
|
||||
//time.blur(function () {
|
||||
// var dt = new Date('1970-01-01T' + $(this).val());
|
||||
// if (isNaN(dt.getDate())) {
|
||||
// $(this).css('border-color', 'red');
|
||||
// } else {
|
||||
// $(this).css('border-color', '');
|
||||
// }
|
||||
//});
|
||||
//time.datetimepicker({
|
||||
// datepicker: false,
|
||||
// format: 'H:m:s',
|
||||
// enterLikeTab: false
|
||||
//});
|
||||
}
|
||||
return content;
|
||||
};
|
||||
dateTimeQuestion.prototype.getAnswer = function () {
|
||||
var answer = question.prototype.getAnswer.call(this);
|
||||
var date = this.ui.date.val();
|
||||
if (this.ui.time != null) {
|
||||
date += ' ' + this.ui.time.val();
|
||||
}
|
||||
if (date != ' ') {
|
||||
answer.Result = date;
|
||||
}
|
||||
return answer;
|
||||
};
|
||||
dateTimeQuestion.prototype.focus = function () {
|
||||
if (this.ui.time != null) {
|
||||
this.ui.time.focus();
|
||||
} else {
|
||||
this.ui.date.focus();
|
||||
}
|
||||
};
|
||||
|
||||
// drop question
|
||||
var dropQuestion = function (q) {
|
||||
question.call(this, q);
|
||||
};
|
||||
dropQuestion.prototype = Object.create(question.prototype);
|
||||
dropQuestion.prototype.constructor = dropQuestion;
|
||||
dropQuestion.prototype.createQuestion = function (answer) {
|
||||
var _this = this;
|
||||
var content = $('<div></div>').click(function () { _this.openDrop(content.offset()) });
|
||||
var result = $('<div class="drop-result" style="float: left; cursor: pointer"></div>');
|
||||
this.fillResult(result, answer && answer.SelectedItems);
|
||||
content.append(result);
|
||||
var icon = $('<div class="icon-col iconcaretdown" style="float: left; margin-left: 10px; font-weight: bold"></div>');
|
||||
content.append(icon);
|
||||
if (!this.loaded && (
|
||||
this.question.LookupSource === LookupSources.Assets ||
|
||||
this.question.LookupSource === LookupSources.AssetCustomerName)) {
|
||||
var loading = $('<div class="loading c-spin" style="float: left; margin-left: 10px; color: gray"></div>');
|
||||
content.append(loading);
|
||||
}
|
||||
content.append('<div style="clear: both"></div>');
|
||||
return content;
|
||||
};
|
||||
dropQuestion.prototype.setLoaded = function () {
|
||||
this.loaded = true;
|
||||
this.ui.content && this.ui.content.find('.loading').remove();
|
||||
};
|
||||
dropQuestion.prototype.focus = function () {
|
||||
var ele = this.ui.content.find('input:first');
|
||||
if (ele.length > 0) {
|
||||
ele.focus();
|
||||
} else {
|
||||
question.prototype.focus.call(this);
|
||||
}
|
||||
};
|
||||
dropQuestion.prototype.fillResult = function (container, items) {
|
||||
container.empty();
|
||||
if (items && items.length > 0) {
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
var line = $('<div></div>');
|
||||
line.append($('<input type="hidden"></input>').data('item', item).val(item.Value || item.Text));
|
||||
var circle = $('<div></div>').css({
|
||||
'width': 12,
|
||||
'height': 12,
|
||||
'border-radius': 6,
|
||||
'display': 'inline-block',
|
||||
'margin-left': 5,
|
||||
'vertical-align': 'middle'
|
||||
});
|
||||
circle.css('background-color', item.BackgroundColor || '#ccc');
|
||||
line.append(circle);
|
||||
var text;
|
||||
if (this.question.QuestionType === QTypes.EmailList) {
|
||||
text = item.Text + ' <' + item.Value + '>';
|
||||
} else {
|
||||
text = item.Text;
|
||||
}
|
||||
line.append($('<span style="margin-left: 10px"></span>').text(text));
|
||||
container.append(line);
|
||||
}
|
||||
} else {
|
||||
if (this.question.QuestionType === QTypes.EmailList) {
|
||||
container.append($('<span style="color: #ccc">No Emails Selected</span>'));
|
||||
} else {
|
||||
container.append($('<span style="color: #ccc">No Selection</span>'));
|
||||
}
|
||||
}
|
||||
};
|
||||
dropQuestion.prototype.openDrop = function (pos) {
|
||||
var _this = this;
|
||||
var q = this.question;
|
||||
var mask = this.ui.mask;
|
||||
if (mask == null) {
|
||||
mask = $('<div style="position:fixed; left:0;right:0;top:0;bottom:0"></div>');
|
||||
this.ui.mask = mask;
|
||||
}
|
||||
mask.on('mousedown touchstart', function () {
|
||||
if (panel.is(":visible")) {
|
||||
panel.find(".iconcheck").click();
|
||||
}
|
||||
//_this.closeDrop()
|
||||
});
|
||||
$(document.body).append(mask);
|
||||
|
||||
// drop panel
|
||||
var panel = this.ui.droplist;
|
||||
if (panel != null) {
|
||||
panel.remove();
|
||||
}
|
||||
panel = $('<div style="position:absolute;background:white;width:400px;height:300px;border:1px solid #ccc;box-shadow:3px 3px 10px #eee"></div>');
|
||||
var answer = this.answer;
|
||||
var isEmailList = q.QuestionType === QTypes.EmailList;
|
||||
var isEmployee = q.QuestionType === QTypes.DropDown && q.LookupSource === LookupSources.Employee;
|
||||
var refreshList = function (content, items) {
|
||||
content.find('.drop-item').remove();
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
var line = $('<div class="drop-item"></div>');
|
||||
var check;
|
||||
var name = 'item_' + q.Id;
|
||||
var id = name + '_' + i;
|
||||
var left = $('<div style="float: left"></div>');
|
||||
var val = item.Value || item.Text;
|
||||
if (isEmailList || q.MultipleSelect) {
|
||||
check = $('<input type="checkbox"></input>').attr('id', id).val(val);
|
||||
} else {
|
||||
check = $('<input type="radio"></input>').attr({ 'id': id, 'name': name }).val(val);
|
||||
}
|
||||
check.data('item', item);
|
||||
check.change(function () {
|
||||
if (!q.MultipleSelect && q.QuestionType !== QTypes.EmailList) {
|
||||
for (var i = 0; i < _this.data.items.length; i++) {
|
||||
_this.data.items[i].Selected = false;
|
||||
}
|
||||
}
|
||||
$(this).data('item').Selected = $(this).prop('checked');
|
||||
});
|
||||
if (answer && answer.SelectedItems) {
|
||||
var s = answer.SelectedItems.filter(function (a) { return (a.Value || a.Text) === val });
|
||||
if (s.length > 0) {
|
||||
check.prop('checked', true);
|
||||
item.Selected = true;
|
||||
}
|
||||
}
|
||||
left.append(check);
|
||||
var circle = $('<div></div>').css({
|
||||
'width': 12,
|
||||
'height': 12,
|
||||
'border-radius': 6,
|
||||
'display': 'inline-block',
|
||||
'margin-left': 5,
|
||||
'vertical-align': 'middle'
|
||||
});
|
||||
circle.css('background-color', item.BackgroundColor);
|
||||
left.append(circle);
|
||||
line.append(left);
|
||||
line.append($('<label style="margin-left: 45px; display: block"></label>').attr('for', id).text(
|
||||
isEmailList ? item.Text + ' <' + item.Value + '>' : item.Text));
|
||||
|
||||
content.append(line);
|
||||
}
|
||||
};
|
||||
var search = $('<input type="text" placeholder="Search"></input>').css({
|
||||
'height': 29,
|
||||
'line-height': '29px',
|
||||
'padding': '0 6px',
|
||||
'width': '100%',
|
||||
'border': 'none',
|
||||
'border-bottom': '1px solid #ccc',
|
||||
'box-sizing': 'border-box'
|
||||
}).on('propertychange input', function () {
|
||||
var items = _this.data.items;
|
||||
var key = $(this).val().toLowerCase();
|
||||
if (items && items.length > 0) {
|
||||
items = items.filter(function (e) { return e.Text.toLowerCase().indexOf(key) >= 0 });
|
||||
refreshList(panelContent, items);
|
||||
}
|
||||
});
|
||||
var funcs = $('<div style="margin-right: 45px"></div>');
|
||||
funcs.append(search);
|
||||
panel.append($('<div class="sbutton iconcheck"></div>').css({
|
||||
'float': 'right',
|
||||
'padding': '0 10px',
|
||||
'height': 29,
|
||||
'line-height': '29px'
|
||||
}).click(function () {
|
||||
var checks = _this.data.items; // panelContent.find('input:checked');
|
||||
var items = [];
|
||||
for (var i = 0; i < checks.length; i++) {
|
||||
var item = checks[i]; // $(checks[i]).data('item');
|
||||
if (item.Selected) {
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
if (answer == null) {
|
||||
answer = {
|
||||
'QuestionId': q.Id,
|
||||
'SeverityLevel': q.SeverityLevel
|
||||
};
|
||||
_this.answer = answer;
|
||||
}
|
||||
answer.SelectedItems = items;
|
||||
_this.fillResult(_this.ui.content.find('.drop-result'), items);
|
||||
_this.closeDrop();
|
||||
}));
|
||||
panel.append(funcs);
|
||||
// scroller
|
||||
var panelContent = $('<div></div>').css({
|
||||
'overflow-y': 'auto',
|
||||
'line-height': '26px',
|
||||
'box-sizing': 'border-box',
|
||||
'height': 270,
|
||||
'padding': '4px 2px'
|
||||
});
|
||||
panel.append(panelContent);
|
||||
this.ui.panelContent = panelContent;
|
||||
var generateItem = function (text, value) {
|
||||
return {
|
||||
'BackgroundColor': '#cccccc',
|
||||
'SeverityLevel': q.SeverityLevel,
|
||||
'Text': text,
|
||||
'Value': value
|
||||
};
|
||||
};
|
||||
var items;
|
||||
if (q.SelectItems && q.SelectItems.length > 0) {
|
||||
items = q.SelectItems;
|
||||
} else if (isEmailList || isEmployee) {
|
||||
if (window.EmailList) {
|
||||
items = [];
|
||||
for (var i = 0; i < window.EmailList.length; i++) {
|
||||
var item = window.EmailList[i];
|
||||
items.push(generateItem(
|
||||
isEmployee ? (item.UserName + ' <' + item.Email + '>') : item.UserName,
|
||||
isEmailList ? item.Email : item.UserIID));
|
||||
}
|
||||
}
|
||||
} else if (q.LookupSource === LookupSources.Jobsites) {
|
||||
if (window.JobSiteList) {
|
||||
items = [];
|
||||
for (var i = 0; i < window.JobSiteList.length; i++) {
|
||||
var item = window.JobSiteList[i];
|
||||
items.push(generateItem(item.Name, String(item.Id)));
|
||||
}
|
||||
}
|
||||
} else if (q.LookupSource === LookupSources.Assets) {
|
||||
if (window.AssetList) {
|
||||
items = [];
|
||||
for (var i = 0; i < window.AssetList.length; i++) {
|
||||
var item = window.AssetList[i];
|
||||
var assetLabel = [item.Name, item.VIN, item.Make, item.Model, item.AssetType].filter(function (a) { return a && a.length > 0 }).join('/');
|
||||
items.push(generateItem(assetLabel, String(item.Id)));
|
||||
}
|
||||
}
|
||||
} else if (q.LookupSource === LookupSources.AssetCustomerName) {
|
||||
if (window.AssetList) {
|
||||
items = [];
|
||||
for (var i = 0; i < window.AssetList.length; i++) {
|
||||
var item = window.AssetList[i];
|
||||
var assetLabel = item.Name;
|
||||
items.push(generateItem(assetLabel, String(item.Id)));
|
||||
}
|
||||
}
|
||||
} else if (q.QuestionType === QTypes.FuelRecords) {
|
||||
if (q.SubType === FuelRecordTypes.State) {
|
||||
items = [
|
||||
"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"
|
||||
].map(function (s) { return generateItem(s, s) });
|
||||
} else if (q.SubType === FuelRecordTypes.FuelType) {
|
||||
items = [
|
||||
{ value: "BIOD", text: "B20 Diesel 20% Biodiesel" },
|
||||
{ value: "DEF", text: "Diesel Exhaust Fluid" },
|
||||
{ value: "DS+", text: "Premium Diesel #2" },
|
||||
{ value: "DSL", text: "Diesel #1" },
|
||||
{ value: "DSL2", text: "Regular Diesel #2" },
|
||||
{ value: "ETH-S", text: "Super Unleaded Ethanol (10% blend)" },
|
||||
{ value: "ETH", text: "Unleaded Ethanol (10% blend)" },
|
||||
{ value: "FRM", text: "Diesel Off Road (#1 and #2 non" },
|
||||
{ value: "FUL", text: "Miscellaneous Fuel" },
|
||||
{ value: "FUL-", text: "Other Fuel (Non-Taxable)" },
|
||||
{ value: "KERO", text: "Kerosene - Low Sulfur" },
|
||||
{ value: "MOT", text: "Motor Oil" },
|
||||
{ value: "OTH", text: "General Merchandise" },
|
||||
{ value: "SUP4", text: "Unleaded 4" },
|
||||
{ value: "SUP", text: "Unleaded Super" },
|
||||
{ value: "SVC", text: "Repairs" },
|
||||
{ value: "ULSD", text: "Ultra Low Sulfur #2" },
|
||||
{ value: "UN+", text: "Unleaded Plus" },
|
||||
{ value: "UNL", text: "Unleaded Regular" },
|
||||
{ value: "WASH", text: "Car Wash" },
|
||||
{ value: "HYD", text: "Hydraulic" },
|
||||
{ value: "SHY", text: "Synthetic Hydraulic" },
|
||||
{ value: "GRO", text: "Gear Oil" }
|
||||
].map(function (t) { return generateItem(t.text, t.value) });
|
||||
} else if (q.SubType === FuelRecordTypes.DistributedBy) {
|
||||
items = [
|
||||
{ value: "0", text: "Fueling Station" },
|
||||
{ value: "1", text: "Fueling Asset" }
|
||||
].map(function (t) { return generateItem(t.text, t.value) });
|
||||
}
|
||||
}
|
||||
if (items && items.length > 0) {
|
||||
this.data.items = items;
|
||||
refreshList(panelContent, items);
|
||||
}
|
||||
this.ui.droplist = panel;
|
||||
|
||||
var screenHeight = $(window).height();
|
||||
if (pos.top + 300 > screenHeight) {
|
||||
pos.top = screenHeight - 310;
|
||||
}
|
||||
panel.css({ 'left': pos.left, 'top': pos.top });
|
||||
$(document.body).append(panel);
|
||||
};
|
||||
dropQuestion.prototype.closeDrop = function () {
|
||||
this.ui.mask.remove();
|
||||
this.ui.mask = null;
|
||||
this.ui.droplist.remove();
|
||||
};
|
||||
dropQuestion.prototype.getAnswer = function () {
|
||||
var answer = question.prototype.getAnswer.call(this);
|
||||
var checks = this.ui.content.children('.drop-result').find('input');
|
||||
var items = [];
|
||||
for (var i = 0; i < checks.length; i++) {
|
||||
var item = $(checks[i]).data('item');
|
||||
items.push(item);
|
||||
}
|
||||
answer.SelectedItems = items;
|
||||
if (items.length > 0) {
|
||||
answer.Result = items.map(function (i) { return i.Value || i.Text }).join('\n');
|
||||
//answer.SeverityLevel = items[0].SeverityLevel;
|
||||
} else {
|
||||
answer.Result = '';
|
||||
}
|
||||
return answer;
|
||||
};
|
||||
|
||||
// picture question
|
||||
var pictureQuestion = function (q) {
|
||||
question.call(this, q);
|
||||
};
|
||||
pictureQuestion.prototype = Object.create(question.prototype);
|
||||
pictureQuestion.prototype.constructor = pictureQuestion;
|
||||
pictureQuestion.prototype.createQuestion = function (_answer, medias) {
|
||||
var content = $('<div></div>');
|
||||
if (medias && medias.length > 0) {
|
||||
for (var i = 0; i < medias.length; i++) {
|
||||
var m = medias[i];
|
||||
var ele;
|
||||
if (['.mp4', '.mov'].indexOf(m.FileType.toLowerCase()) >= 0) {
|
||||
ele = $('<div></div>').css({
|
||||
'float': 'left',
|
||||
'border': '1px solid #ccc',
|
||||
'height': 38,
|
||||
'width': 38,
|
||||
'text-align': 'center'
|
||||
});
|
||||
ele.append($('<span></span>').css({
|
||||
'margin': '0 auto',
|
||||
'font-family': 'Fontawesome',
|
||||
'font-size': '20px',
|
||||
'line-height': '38px',
|
||||
'color': '#000'
|
||||
}));
|
||||
} else {
|
||||
ele = $('<img></img>').css({
|
||||
'float': 'left',
|
||||
'border': '1px solid #ccc',
|
||||
'padding': '4px',
|
||||
'height': 30,
|
||||
'margin-right': 4
|
||||
}).attr('src', m.ThumbnailUrl);
|
||||
}
|
||||
content.append($('<a target="_blank"></a>').attr('href', m.Url).append(ele));
|
||||
}
|
||||
} else {
|
||||
content.append('<div style="font-style: italic; color: #ccc"><No media.></div>');
|
||||
}
|
||||
content.append('<div style="clear: both"></div>');
|
||||
return content;
|
||||
};
|
||||
|
||||
|
||||
// assetstatus question
|
||||
var assetStatusQuestion = function (q) {
|
||||
question.call(this, q);
|
||||
};
|
||||
assetStatusQuestion.prototype = Object.create(question.prototype);
|
||||
assetStatusQuestion.prototype.constructor = assetStatusQuestion;
|
||||
assetStatusQuestion.prototype.createQuestion = function (answer, medias) {
|
||||
var content = $('<div></div>');
|
||||
var q = this.question;
|
||||
q.SelectItems = [
|
||||
{ Value: "0", Text: "In Use", BackgroundColor: "#93c47d" },
|
||||
{ Value: "1", Text: "Available", BackgroundColor: "#9fc5e8" },
|
||||
{ Value: "2", Text: "Standby", BackgroundColor: "#f3af83" },
|
||||
{ Value: "10", Text: "Down", BackgroundColor: "#dd7e6b" }
|
||||
];
|
||||
for (var i = 0; i < q.SelectItems.length; i++) {
|
||||
var item = q.SelectItems[i];
|
||||
var line = $('<div></div>');
|
||||
var name = 'item_' + q.Id;
|
||||
var id = name + '_' + i;
|
||||
var left = $('<div style="float: left"></div>');
|
||||
var val = item.Value || item.Text;
|
||||
var check = $('<input type="radio"></input>').attr({ 'id': id, 'name': name }).val(val);
|
||||
check.data('item', item);
|
||||
if (answer && answer.SelectedItems) {
|
||||
var s = answer.SelectedItems.filter(function (a) { return (a.Value || a.Text) === val });
|
||||
if (s.length > 0) {
|
||||
check.prop('checked', true);
|
||||
}
|
||||
}
|
||||
left.append(check);
|
||||
var circle = $('<div></div>').css({
|
||||
'width': 12,
|
||||
'height': 12,
|
||||
'border-radius': 6,
|
||||
'display': 'inline-block',
|
||||
'margin-left': 5,
|
||||
'vertical-align': 'middle'
|
||||
});
|
||||
circle.css('background-color', item.BackgroundColor);
|
||||
left.append(circle);
|
||||
line.append(left);
|
||||
line.append($('<label style="margin-left: 45px; display: block"></label>').attr('for', id).text(item.Text));
|
||||
|
||||
content.append(line);
|
||||
content.append('<div style="clear: both"></div>');
|
||||
}
|
||||
|
||||
if (medias && medias.length > 0) {
|
||||
var cnt = $('<div style="margin: 6px 0 0 0px"></div>');
|
||||
for (var i = 0; i < medias.length; i++) {
|
||||
var m = medias[i];
|
||||
var ele;
|
||||
if (['.mp4', '.mov'].indexOf(m.FileType.toLowerCase()) >= 0) {
|
||||
ele = $('<div></div>').css({
|
||||
'float': 'left',
|
||||
'border': '1px solid #ccc',
|
||||
'height': 38,
|
||||
'width': 38,
|
||||
'text-align': 'center'
|
||||
});
|
||||
ele.append($('<span></span>').css({
|
||||
'margin': '0 auto',
|
||||
'font-family': 'Fontawesome',
|
||||
'font-size': '20px',
|
||||
'line-height': '38px',
|
||||
'color': '#000'
|
||||
}));
|
||||
} else {
|
||||
ele = $('<img></img>').css({
|
||||
'float': 'left',
|
||||
'border': '1px solid #ccc',
|
||||
'padding': '4px',
|
||||
'height': 30,
|
||||
'margin-right': 4
|
||||
}).attr('src', m.ThumbnailUrl);
|
||||
}
|
||||
cnt.append($('<a target="_blank"></a>').attr('href', m.Url).append(ele));
|
||||
}
|
||||
content.append(cnt);
|
||||
}
|
||||
content.append('<div style="clear: both"></div>');
|
||||
|
||||
cnt = $('<div style="margin: 6px 0 0 0px"></div>');
|
||||
var divComment = $('<div style="padding: 6px 0"></div>');
|
||||
var comment = $('<textarea class="form-control" style="width: 100%; box-sizing: border-box; height: 70px" placeholder="Comment"></textarea>');
|
||||
comment.attr('maxlength', 500);
|
||||
if (answer && answer.Result) {
|
||||
comment.val(answer.Result);
|
||||
}
|
||||
this.ui.comment = comment;
|
||||
divComment.append(comment);
|
||||
cnt.append(divComment);
|
||||
content.append(cnt);
|
||||
|
||||
return content;
|
||||
};
|
||||
assetStatusQuestion.prototype.getAnswer = function () {
|
||||
var answer = question.prototype.getAnswer.call(this);
|
||||
var checks = this.ui.content.find('input:checked');
|
||||
var items = [];
|
||||
for (var i = 0; i < checks.length; i++) {
|
||||
var item = $(checks[i]).data('item');
|
||||
items.push(item);
|
||||
}
|
||||
answer.SelectedItems = items;
|
||||
if (items.length > 0) {
|
||||
answer.Result = items.map(function (i) { return i.Value || i.Text }).join('\n');
|
||||
//answer.SeverityLevel = items[0].SeverityLevel;
|
||||
} else {
|
||||
answer.Result = '';
|
||||
}
|
||||
return answer;
|
||||
};
|
||||
assetStatusQuestion.prototype.focus = function () {
|
||||
var ele = this.ui.content.find('input:first');
|
||||
if (ele.length > 0) {
|
||||
ele.focus();
|
||||
} else {
|
||||
question.prototype.focus.call(this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return {
|
||||
types: QTypes,
|
||||
sources: LookupSources,
|
||||
fueltypes: FuelRecordTypes,
|
||||
factory: function (q) {
|
||||
switch (q.QuestionType) {
|
||||
case QTypes.Odometer:
|
||||
case QTypes.FuelRemaining:
|
||||
case QTypes.FuelUsed:
|
||||
return new inputDropQuestion(q);
|
||||
case QTypes.YesOrNo:
|
||||
case QTypes.List:
|
||||
return new listQuestion(q);
|
||||
case QTypes.DropDown:
|
||||
case QTypes.EmailList:
|
||||
return new dropQuestion(q);
|
||||
case QTypes.Date:
|
||||
case QTypes.DateAndTime:
|
||||
return new dateTimeQuestion(q);
|
||||
case QTypes.Picture:
|
||||
return new pictureQuestion(q);
|
||||
case QTypes.FuelRecords:
|
||||
switch (q.SubType) {
|
||||
case FuelRecordTypes.TransactionDate:
|
||||
return new dateTimeQuestion(q);
|
||||
case FuelRecordTypes.State:
|
||||
case FuelRecordTypes.FuelType:
|
||||
case FuelRecordTypes.DistributedBy:
|
||||
return new dropQuestion(q);
|
||||
case FuelRecordTypes.Odometer:
|
||||
case FuelRecordTypes.Quantity:
|
||||
return new inputDropQuestion(q);
|
||||
case FuelRecordTypes.Picture:
|
||||
return new pictureQuestion(q);
|
||||
default:
|
||||
return new inputQuestion(q);
|
||||
}
|
||||
break;
|
||||
case QTypes.AssetStatus:
|
||||
return new assetStatusQuestion(q);
|
||||
default:
|
||||
return new inputQuestion(q);
|
||||
}
|
||||
},
|
||||
equals: function (s1, s2) {
|
||||
if (typeof s1 === 'string' && typeof s2 === 'string') {
|
||||
if (s1.toLowerCase() === s2.toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
66
Site/Inspection/js/modules/inspects/editsection.js
Normal file
66
Site/Inspection/js/modules/inspects/editsection.js
Normal file
@ -0,0 +1,66 @@
|
||||
define(['modules/inspects/editquestion'], function (Question) {
|
||||
var ctor = function (section, report) {
|
||||
this.section = section;
|
||||
this.report = report;
|
||||
};
|
||||
|
||||
var __proto = ctor.prototype;
|
||||
__proto.createContent = function (change) {
|
||||
var content = $('<div style="margin-bottom: 20px"></div>');
|
||||
|
||||
if (this.section.StaticPictures && this.section.StaticPictures.length > 0) {
|
||||
var div_pic = $('<div style="background: #eee; padding: 2px 2px;"></div>');
|
||||
for (var i = 0; i < this.section.StaticPictures.length; i++) {
|
||||
var pic = this.section.StaticPictures[i];
|
||||
var img = $('<img style="width:40px;height:40px;margin-left:5px;"/>').attr('src', pic.Url).attr('title', pic.Name);
|
||||
img.click(pic.Url, function (e) {
|
||||
window.open(e.data, "_blank")
|
||||
});
|
||||
div_pic.append(img);
|
||||
}
|
||||
content.append(div_pic);
|
||||
}
|
||||
|
||||
var div_title = $('<div style="background: #eee; padding: 5px 3px; margin: 5px 0; font-size: 1.4em"></div>').text(this.section.DisplayText);
|
||||
content.append(div_title);
|
||||
|
||||
for (var i = 0; i < this.section.Questions.length; i++) {
|
||||
var question = this.section.Questions[i];
|
||||
|
||||
if (question.QuestionType === Question.types.YesOrNo ||
|
||||
question.QuestionType === Question.types.DropDown ||
|
||||
question.QuestionType === Question.types.List) {
|
||||
if (!question.SelectItems || question.SelectItems.length <= 0) {
|
||||
if (question.QuestionType !== Question.types.DropDown ||
|
||||
question.LookupSource === 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var q = Question.factory(question);
|
||||
// get answer and media
|
||||
var answer = this.report.Answers.filter(function (a) { return Question.equals(a.QuestionId, question.Id) })[0];
|
||||
var isPicture = question.QuestionType === Question.types.Picture
|
||||
|| (question.QuestionType === Question.types.FuelRecords &&
|
||||
question.SubType === Question.fueltypes.Picture)
|
||||
|| question.QuestionType === Question.types.AssetStatus;
|
||||
var medias = isPicture && answer && this.report.Medias.filter(function (m) { return Question.equals(m.AnswerId, answer.Id) });
|
||||
|
||||
var qContent;
|
||||
if (question.QuestionType === Question.types.FuelRecords
|
||||
&& (question.SubType === Question.fueltypes.Quantity ||
|
||||
question.SubType === Question.fueltypes.UnitCost)) {
|
||||
qContent = q.createContent(answer, medias, change);
|
||||
} else {
|
||||
qContent = q.createContent(answer, medias);
|
||||
}
|
||||
qContent.data('question', q);
|
||||
content.append(qContent);
|
||||
}
|
||||
|
||||
return content;
|
||||
};
|
||||
|
||||
return ctor;
|
||||
});
|
55
Site/Inspection/js/modules/inspects/inspect.js
Normal file
55
Site/Inspection/js/modules/inspects/inspect.js
Normal file
@ -0,0 +1,55 @@
|
||||
define(['modules/templates/addtemplate'], function (AddTemplate) {
|
||||
var q = function (ipt, inspect) {
|
||||
this.inspect = inspect;
|
||||
this.inspectmodule = ipt;
|
||||
};
|
||||
q.prototype.description = "Inspect";
|
||||
q.prototype.version = "1.0.0.0";
|
||||
|
||||
q.prototype.createContent = function () {
|
||||
var holder = $('<div class="question-holder"></div>');
|
||||
holder.append('<div class="question-cell inspect-templatename" style="width:150px;margin-left:8px;"><span></span></div>');
|
||||
holder.append('<div class="question-cell inspect-assetname" style="width:200px;"><span></span></div>');
|
||||
holder.append('<div class="question-cell inspect-vin" style="width:200px;"><span></span></div>');
|
||||
holder.append('<div class="question-cell inspect-make" style="width:150px;"><span></span></div>');
|
||||
holder.append('<div class="question-cell inspect-model" style="width:150px;"><span></span></div>');
|
||||
holder.append('<div class="question-cell inspect-type" style="width:150px;"><span></span></div>');
|
||||
holder.append('<div class="question-cell inspect-status" style="width:120px;"><span></span></div>');
|
||||
holder.append('<div class="question-cell inspect-committime" style="width:150px;"><span></span></div>');
|
||||
holder.append('<div class="question-cell inspect-commituser" style="width:150px;"><span></span></div>');
|
||||
var funcs = $('<div class="question-cell inspect-func" style="width:92px;text-align:right;padding-right:20px;"></div>');
|
||||
holder.append(funcs);
|
||||
var _this = this;
|
||||
holder.find('.inspect-assetname span').click(function () {
|
||||
window.open("report.aspx?rid=" + _this.inspect.Id, "_blank");
|
||||
});
|
||||
funcs.append($('<em class="spanbtn icondetail"></em>').click(function () {
|
||||
window.open("report.aspx?rid=" + _this.inspect.Id, "_blank");
|
||||
}).attr('title', 'Detail'));
|
||||
this.holder = holder;
|
||||
if (this.inspect != null) {
|
||||
this.updateContent(this.inspect);
|
||||
}
|
||||
return holder;
|
||||
};
|
||||
q.prototype.updateContent = function (inspect) {
|
||||
if (this.inspect != inspect) {
|
||||
this.inspect = inspect;
|
||||
}
|
||||
this.holder.find('.inspect-assetname span').text(inspect.AssetName);
|
||||
this.holder.find('.inspect-vin span').text(inspect.VIN);
|
||||
this.holder.find('.inspect-make span').text(inspect.MakeName);
|
||||
this.holder.find('.inspect-model span').text(inspect.ModelName);
|
||||
this.holder.find('.inspect-type span').text(inspect.TypeName);
|
||||
this.holder.find('.inspect-templatename span').text(inspect.TemplateName);
|
||||
var statustext = '';
|
||||
if (inspect.Status == 0)
|
||||
statustext = 'Draft';
|
||||
else if (inspect.Status == 1)
|
||||
statustext = 'Committed';
|
||||
this.holder.find('.inspect-status span').text(statustext);
|
||||
this.holder.find('.inspect-committime span').text(inspect.CommitTimeLocalStr);
|
||||
this.holder.find('.inspect-commituser span').text(inspect.CommitedByUserName);
|
||||
};
|
||||
return q;
|
||||
});
|
Reference in New Issue
Block a user