444 lines
17 KiB
JavaScript
444 lines
17 KiB
JavaScript
$(function () {
|
|
$("#dialog_segmenthour").keydown(numberinput);
|
|
$("#dialog_segmentcost").keydown(numberinput);
|
|
});
|
|
|
|
function numberinput(e) {
|
|
var keyCode = e.which;
|
|
if (keyCode === 9//tab
|
|
|| keyCode === 8 || keyCode === 46 //delete
|
|
|| keyCode === 110 || keyCode === 190//.
|
|
|| keyCode === 37 || keyCode === 39//left right
|
|
|| keyCode === 55 || keyCode === 56//home end
|
|
|| (keyCode >= 48 && keyCode <= 57)
|
|
|| (keyCode >= 96 && keyCode <= 105))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
function GetSegmentDataSource(next) {
|
|
worequest("GetSegmentDataSource", '', function (data) {
|
|
if (data.Users && data.Users.length > 0) {
|
|
userdata = data.Users;
|
|
$('#dialog_segmentuser').dropdownSource(userdata);
|
|
}
|
|
if (data.JobSites && data.JobSites.length > 0) {
|
|
var jss = [{ ID: '-1', Name: ' ', html: ' ' }];
|
|
for (var js of data.JobSites) {
|
|
jss.push(js);
|
|
}
|
|
jobsitedata = jss;
|
|
$("#dialog_segmentjobsite").dropdownSource(jobsitedata);
|
|
}
|
|
if (data.Components && data.Components.length > 0) {
|
|
var source = [];
|
|
for (var type of data.Components) {
|
|
source.push({ value: type });
|
|
}
|
|
components = source;
|
|
$("#dialog_segmentcomponent").dropdownSource(components);
|
|
}
|
|
if (data.SegmentTypes && data.SegmentTypes.length > 0) {
|
|
var source = [];
|
|
for (var type of data.SegmentTypes) {
|
|
source.push({ value: type });
|
|
}
|
|
segmenttypes = source;
|
|
$("#dialog_segmenttype").dropdownSource(segmenttypes);
|
|
}
|
|
|
|
if (next)
|
|
next();
|
|
|
|
}, function (err) {
|
|
console.log(err);;
|
|
});
|
|
}
|
|
|
|
function GetSegmentDataSource1(next) {
|
|
worequest("GetSegmentDataSource1", '', function (data) {
|
|
if (data.Components && data.Components.length > 0) {
|
|
var source = [];
|
|
for (var type of data.Components) {
|
|
source.push({ value: type });
|
|
}
|
|
components = source;
|
|
$("#dialog_segmentcomponent").dropdownSource(components);
|
|
}
|
|
if (data.SegmentTypes && data.SegmentTypes.length > 0) {
|
|
var source = [];
|
|
for (var type of data.SegmentTypes) {
|
|
source.push({ value: type });
|
|
}
|
|
segmenttypes = source;
|
|
$("#dialog_segmenttype").dropdownSource(segmenttypes);
|
|
}
|
|
|
|
if (next)
|
|
next();
|
|
|
|
}, function (err) {
|
|
console.log(err);;
|
|
});
|
|
}
|
|
|
|
function SetCompleted(index) {
|
|
var date = $('#dialog_segmentcompleteddate' + index).val();
|
|
if (date.length > 0 && checkDate(date)) {
|
|
$('#dialog_segmentcompleted' + index).prop('checked', true);
|
|
}
|
|
}
|
|
|
|
var segmentdata = [];
|
|
function initControl(index) {
|
|
$('#dialog_segmentcompleteddate' + index).datetimepicker({
|
|
timepicker: false,
|
|
format: 'm/d/Y',
|
|
enterLikeTab: false,
|
|
onSelectDate: function (v, inp) {
|
|
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
|
|
inp.parent().data('val', [date]);
|
|
}
|
|
});
|
|
|
|
$('#dialog_segmentuser' + index).dropdown(userdata || [], {
|
|
search: true,
|
|
valueKey: 'IID',
|
|
textKey: 'DisplayName'
|
|
});
|
|
|
|
|
|
$("#dialog_segmentjobsite" + index).dropdown(jobsitedata || [], {
|
|
search: true,
|
|
valueKey: 'ID',
|
|
textKey: 'Name'
|
|
});
|
|
|
|
|
|
$("#dialog_segmenttype" + index).dropdown(segmenttypes || [], {
|
|
input: true,
|
|
maxlength: 50,
|
|
textKey: 'value'
|
|
});
|
|
|
|
|
|
$("#dialog_segmentcomponent" + index).dropdown(components || [], {
|
|
input: true,
|
|
maxlength: 40,
|
|
textKey: 'value'
|
|
});
|
|
}
|
|
|
|
function getSegments(callbake) {
|
|
segmentindex = 0;
|
|
$('#tab_segments .segments_table').remove();
|
|
if (!workorderid || workorderid == "") return;
|
|
worequest("GetSegments", workorderid, function (data) {
|
|
if (typeof (data) === "string") {
|
|
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
if (data && data.length > 0) {
|
|
//$('#dialog_workordercosts').attr('disabled', true);
|
|
segmentdata = data;
|
|
var wocost = 0;
|
|
for (var i = 0; i < segmentdata.length; i++) {
|
|
wocost += segmentdata[i].Cost;
|
|
showSegment(segmentdata[i]);
|
|
}
|
|
$('#dialog_workordercosts').val(wocost);
|
|
}
|
|
else {
|
|
//$('#dialog_workordercosts').attr('disabled', false);
|
|
if (workorderdata)
|
|
$('#dialog_workordercosts').val(workorderdata.WorkOrderTotalCost == 0 ? "" : workorderdata.WorkOrderTotalCost);
|
|
segmentdata = [];
|
|
if (callbake)
|
|
callbake();
|
|
}
|
|
|
|
}, function (err) {
|
|
});
|
|
}
|
|
|
|
var segmentindex = 0;
|
|
function showSegment(segment) {
|
|
segmentindex++;
|
|
var div_segments = $('#tab_segments');
|
|
var table = $('<table id="tabsegment_' + segmentindex + '" class="segments_table"></table>');
|
|
table.data('index', segmentindex);
|
|
var tr1 = $('<tr></tr>');
|
|
var tr1_td1 = $('<td class="label" style="font-size:14px;font-weight:500;text-align:left;">' + GetTextByKey("P_WO_SEGMENT", "Segment") + " " + segmentindex + '</td>"');
|
|
if (!WOReadOnly) {
|
|
var s_del = $('<span class="sbutton icondelete" onclick="DeleteSegment(' + segmentindex + ');"></span>');
|
|
tr1_td1.append(s_del);
|
|
}
|
|
var tr1_td2 = $('<td></td>"');
|
|
tr1.append(tr1_td1).append(tr1_td2);
|
|
table.append(tr1);
|
|
|
|
var tr = $('<tr></tr>');
|
|
var td1 = $('<td class="label">' + GetTextByKey("P_WO_USER_COLON", " User:") + '</td>"');
|
|
var td2 = $('<td></td>"');
|
|
var sel_user = $('<div id="dialog_segmentuser' + segmentindex + '" class="dropdown"></div>').css("width", 320);
|
|
td2.append(sel_user);
|
|
var td3 = $('<td class="label">' + GetTextByKey("P_WO_COMPLETED_COLON", "Completed:") + '</td>"');
|
|
var td4 = $('<td></td>"');
|
|
var chk_completed = $('<input type="checkbox" id="dialog_segmentcompleted' + segmentindex + '" class="inputbox" />');
|
|
td4.append(chk_completed);
|
|
tr.append(td1).append(td2).append(td3).append(td4);
|
|
table.append(tr);
|
|
|
|
tr = $('<tr></tr>');
|
|
td1 = $('<td class="label">' + GetTextByKey("P_WO_HOURS_COLON", "Hours:") + '</td>"');
|
|
td2 = $('<td></td>"');
|
|
var input_hour = $('<input type="text" id="dialog_segmenthour' + segmentindex + '" class="inputbox" maxlength="12" />')
|
|
.keydown(numberinput);
|
|
td2.append(input_hour);
|
|
td3 = $('<td class="label">' + GetTextByKey("P_WO_COMPLETEDDATE_COLON", "Completed Date:") + '</td>"');
|
|
td4 = $('<td></td>"');
|
|
var input_completeddate = $('<input type="text" id="dialog_segmentcompleteddate' + segmentindex + '" class="inputbox" onchange="SetCompleted(' + segmentindex + ')" />');
|
|
td4.append(input_completeddate);
|
|
tr.append(td1).append(td2).append(td3).append(td4);
|
|
table.append(tr);
|
|
|
|
|
|
tr = $('<tr></tr>');
|
|
td1 = $('<td class="label">' + GetTextByKey("P_WO_JOBSITE_COLON", "Jobsite:") + '</td>"');
|
|
td2 = $('<td></td>"');
|
|
var sel_jobsite = $('<div id="dialog_segmentjobsite' + segmentindex + '" class="dropdown"></div>').css("width", 320);
|
|
td2.append(sel_jobsite);
|
|
td3 = $('<td class="label"><span>' + GetTextByKey("P_WO_DESCRIPTION_COLON", "Description:") + '</span><span class="redasterisk">*</span></td>"');
|
|
td4 = $('<td></td>"');
|
|
var input_desc = $('<input type="text" id="dialog_segmentdesc' + segmentindex + '" class="inputbox" maxlength="200" />');
|
|
td4.append(input_desc);
|
|
tr.append(td1).append(td2).append(td3).append(td4);
|
|
table.append(tr);
|
|
|
|
tr = $('<tr></tr>');
|
|
td1 = $('<td class="label">' + GetTextByKey("P_WO_COST_COLON", "Cost:") + '</td>"');
|
|
td2 = $('<td></td>"');
|
|
var input_cost = $('<input type="text" id="dialog_segmentcost' + segmentindex + '" class="inputbox" />')
|
|
.keydown(numberinput);
|
|
td2.append(input_cost);
|
|
td3 = $('<td class="label">' + GetTextByKey("P_WO_NOTES_COLON", "Notes:") + '</td>"');
|
|
td4 = $('<td rowspan="4"></td>"').css("vertical-align", "top");
|
|
var textarea_notes = $('<textarea id="dialog_segmentnotes' + segmentindex + '" class="inputbox" maxlength="500" style="width: 450px; height: 120px;"></textarea>')
|
|
td4.append(textarea_notes);
|
|
tr.append(td1).append(td2).append(td3).append(td4);
|
|
table.append(tr);
|
|
|
|
tr = $('<tr></tr>');
|
|
td1 = $('<td class="label">' + GetTextByKey("P_WO_XXXXXX_COLON", "Segment Type:") + '</td>"');
|
|
td2 = $('<td></td>"');
|
|
var sel_segmenttype = $('<div id="dialog_segmenttype' + segmentindex + '" class="dropdown"></div>').css("width", 320);
|
|
td2.append(sel_segmenttype);
|
|
tr.append(td1).append(td2);
|
|
table.append(tr);
|
|
|
|
tr = $('<tr></tr>');
|
|
td1 = $('<td class="label">' + GetTextByKey("P_WO_COMPONENT_COLON", "Component:") + '</td>"');
|
|
td2 = $('<td></td>"');
|
|
var sel_component = $('<div id="dialog_segmentcomponent' + segmentindex + '" class="dropdown"></div>').css("width", 320);
|
|
td2.append(sel_component);
|
|
tr.append(td1).append(td2);
|
|
table.append(tr);
|
|
|
|
tr = $('<tr></tr>');
|
|
td1 = $('<td class="label">' + GetTextByKey("P_WO_XXXXXX_COLON", "Billable:") + '</td>"');
|
|
td2 = $('<td></td>"');
|
|
var chk_billable = $('<input type="checkbox" id="dialog_segmentbillable' + segmentindex + '" class="inputbox" />');
|
|
td2.append(chk_billable);
|
|
tr.append(td1).append(td2);
|
|
table.append(tr);
|
|
|
|
if (!WOReadOnly) {
|
|
tr = $('<tr></tr>');
|
|
td1 = $('<td colspan="4" style="text-align: right;"></td>"');
|
|
var input_save = $('<input type="button" value="Save" style="width:80px;height:25px;" id="btn_savesegment' + segmentindex + '" onclick="SaveSegment(' + segmentindex + ')" />').val(GetTextByKey("P_WO_SAVE", "Save"));
|
|
var input_cancel = $('<input type="button" value="Cancel" style="width:80px;height:25px;margin-left:10px;" onclick="CancelSegment(' + segmentindex + ')"/>').val(GetTextByKey("P_WO_CANCEL", "Cancel"));
|
|
td1.append(input_save).append(input_cancel);
|
|
tr.append(td1);
|
|
table.append(tr);
|
|
}
|
|
|
|
div_segments.append(table);
|
|
|
|
initControl(segmentindex);
|
|
$('#tabsegment_' + segmentindex).data('segment', segment);
|
|
$('#dialog_segmentuser' + segmentindex).dropdownVal(segment.UserIID);
|
|
$('#dialog_segmentdesc' + segmentindex).val(segment.Description);
|
|
$('#dialog_segmenthour' + segmentindex).val(segment.Hours === 0 ? "" : segment.Hours);
|
|
$('#dialog_segmentnotes' + segmentindex).val(segment.Notes);
|
|
$('#dialog_segmentjobsite' + segmentindex).dropdownVal(segment.JobsiteID);
|
|
$('#dialog_segmentcost' + segmentindex).val(segment.Cost === 0 ? "" : segment.Cost);
|
|
$('#dialog_segmenttype' + segmentindex).dropdownVal(segment.SegmentType);
|
|
$('#dialog_segmentcompleted' + segmentindex).prop('checked', segment.Completed);
|
|
$('#dialog_segmentcompleteddate' + segmentindex).val(segment.CompletedDateStr);
|
|
$('#dialog_segmentcomponent' + segmentindex).dropdownVal(segment.Component);
|
|
$('#dialog_segmentbillable' + segmentindex).prop('checked', segment.Billable);
|
|
}
|
|
|
|
function OnAddSegment() {
|
|
if (!workorderid || workorderid === "") {
|
|
showAlert(GetTextByKey("P_WO_SAVEWORKORDERFIRST", "Please save work order first."), GetTextByKey("P_WO_ADDSEGMENT", "Add Segment"));
|
|
return;
|
|
}
|
|
|
|
$('#dialog_segmentuser').dropdownVal('');
|
|
$('#dialog_segmentdesc').val('');
|
|
$('#dialog_segmenthour').val('');
|
|
$('#dialog_segmentnotes').val('');
|
|
$('#dialog_segmentjobsite').dropdownVal('');
|
|
$('#dialog_segmentcost').val('');
|
|
$('#dialog_segmentcompleted').prop('checked', false);
|
|
$('#dialog_segmentcompleteddate').val('');
|
|
$('#dialog_segmenttype').dropdownVal('');
|
|
$('#dialog_segmentcomponent').dropdownVal('');
|
|
$('#dialog_segmentbillable').prop('checked', false);
|
|
|
|
showPopup();
|
|
}
|
|
|
|
function DeleteSegment(index) {
|
|
var segment = $('#tabsegment_' + index).data('segment');
|
|
if (!segment)
|
|
return;
|
|
showConfirm(GetTextByKey("P_WO_DOYOUWANTTODELETETHESEGMENT", 'Do you want to delete the segment?'), GetTextByKey("P_WO_DELETESEGMENT", 'Delete Segment'), function () {
|
|
worequest("DeleteSegment", segment.SegmentID, function (data) {
|
|
GetSegmentDataSource1(function () {
|
|
getSegments(getTotalCost);
|
|
});
|
|
}, function (err) {
|
|
showAlert(GetTextByKey("P_WO_FAILEDDELETESEGMENT", 'Failed to delete this segment.'), GetTextByKey("P_WO_DELETESEGMENT", 'Delete Segment'));
|
|
});
|
|
});
|
|
|
|
}
|
|
|
|
function CancelSegment(index) {
|
|
var segment = $('#tabsegment_' + index).data('segment');
|
|
if (!segment)
|
|
return;
|
|
$('#dialog_segmentuser' + index).dropdownVal(segment.UserIID);
|
|
$('#dialog_segmentdesc' + index).val(segment.Description);
|
|
$('#dialog_segmenthour' + index).val(segment.Hours);
|
|
$('#dialog_segmentnotes' + index).val(segment.Notes);
|
|
$('#dialog_segmentjobsite' + index).dropdownVal(segment.JobsiteID);
|
|
$('#dialog_segmentcost' + index).val(segment.Cost);
|
|
$('#dialog_segmentcompleted' + index).prop('checked', segment.Completed);
|
|
$('#dialog_segmentcompleteddate' + index).val(segment.CompletedDateStr);
|
|
$('#dialog_segmenttype' + index).dropdownVal(segment.SegmentType);
|
|
$('#dialog_segmentcomponent' + index).dropdownVal(segment.Component);
|
|
$('#dialog_segmentbillable' + index).prop('checked', segment.Billable);
|
|
}
|
|
|
|
function SaveSegment(index) {
|
|
$('#btn_savesegment' + index).attr('disabled', true);
|
|
var segmentid = -1;
|
|
var alerttitle = GetTextByKey("P_WO_ADDSEGMENT", "Add Segment");
|
|
if (index !== "") {
|
|
var alerttitle = GetTextByKey("P_WO_EDITSEGMENT", "Edit Segment");
|
|
var segment = $('#tabsegment_' + index).data('segment');
|
|
if (!segment)
|
|
return;
|
|
segmentid = segment.SegmentID;
|
|
}
|
|
var item = {
|
|
'SegmentID': segmentid,
|
|
'WorkOrderID': workorderid,
|
|
'UserIID': $('#dialog_segmentuser' + index).dropdownVal(),
|
|
'Description': $('#dialog_segmentdesc' + index).val(),
|
|
'Hours': $('#dialog_segmenthour' + index).val(),
|
|
'Notes': $('#dialog_segmentnotes' + index).val(),
|
|
'JobsiteID': $('#dialog_segmentjobsite' + index).dropdownVal(),
|
|
'Cost': $('#dialog_segmentcost' + index).val(),
|
|
'Completed': $('#dialog_segmentcompleted' + index).prop('checked'),
|
|
'CompletedDate': $('#dialog_segmentcompleteddate' + index).val(),
|
|
'SegmentType': $('#dialog_segmenttype' + index).dropdownVal(),
|
|
'Component': $('#dialog_segmentcomponent' + index).dropdownVal(),
|
|
'Billable': $('#dialog_segmentbillable' + index).prop('checked')
|
|
};
|
|
|
|
if (item.Description === "" || item.Description.length == 0) {
|
|
showAlert(GetTextByKey("P_WO_DESCRIPTIONREQUIRED", 'Description is required.'), alerttitle);
|
|
$('#btn_savesegment' + index).attr('disabled', false);
|
|
return;
|
|
}
|
|
|
|
if (item.Hours !== "") {
|
|
if (isNaN(item.Hours)) {
|
|
showAlert(GetTextByKey("P_WO_HOURSFORMATERROR", 'Hours format error.'), alerttitle);
|
|
$('#btn_savesegment' + index).attr('disabled', false);
|
|
return;
|
|
}
|
|
else {
|
|
if (item.Hours <= 0) {
|
|
showAlert(GetTextByKey("P_WO_HOURSMUSTBEGREATERTHAN0", 'Hours must be greater than 0.'), alerttitle);
|
|
$('#btn_savesegment' + index).attr('disabled', false);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (item.Cost !== "") {
|
|
if (isNaN(item.Cost)) {
|
|
showAlert(GetTextByKey("P_WO_COSTFORMATERROR", 'Cost format error.'), alerttitle);
|
|
$('#btn_savesegment' + index).attr('disabled', false);
|
|
return;
|
|
}
|
|
else {
|
|
if (item.Cost <= 0) {
|
|
showAlert(GetTextByKey("P_WO_COSTMUSTBEGREATERTHAN0", 'Cost must be greater than 0.'), alerttitle);
|
|
$('#btn_savesegment' + index).attr('disabled', false);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (item.Cost === "")
|
|
item.Cost = -1;
|
|
if (item.Hours === "")
|
|
item.Hours = -1;
|
|
|
|
var param = JSON.stringify(item);
|
|
param = htmlencode(param);
|
|
worequest("SaveSegment", param, function (data) {
|
|
if (typeof (data) === "string") {
|
|
$('#btn_savesegment' + index).attr('disabled', false);
|
|
showAlert(data, alerttitle);
|
|
} else {
|
|
$('#btn_savesegment' + index).attr('disabled', false);
|
|
if (index !== "") {
|
|
showAlert(GetTextByKey("P_WO_SAVSUCCESSFULLY", "Saved successfully."), alerttitle);
|
|
}
|
|
GetSegmentDataSource1(function () {
|
|
getSegments(getTotalCost);
|
|
});
|
|
hidePopup();
|
|
}
|
|
}, function (err) {
|
|
$('#btn_savesegment' + index).attr('disabled', false);
|
|
console.log(err);
|
|
showAlert(GetTextByKey("P_WO_FAILEDTOSAVESEGMENT", 'Failed to save segment.'), alerttitle);
|
|
});
|
|
|
|
}
|
|
|
|
function showPopup() {
|
|
$('#popupmask').css('height', $('#dialog_workorder').height());
|
|
$('#popupmask').show();
|
|
$('#popupdialog').show();
|
|
$('#popupdialog').css({
|
|
"top": ($("#popupmask").height() - $('#popupdialog').height()) / 2,
|
|
"left": ($("#popupmask").width() - $('#popupdialog').width()) / 2
|
|
});
|
|
|
|
$('#dialog_segmentuser').focus();
|
|
}
|
|
|
|
function hidePopup() {
|
|
$('#popupmask').hide();
|
|
$('#popupdialog').hide();
|
|
} |