802 lines
		
	
	
		
			29 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			802 lines
		
	
	
		
			29 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
 | 
						|
function UpLoadWorkOrderAttachment() {
 | 
						|
    var file = $('<input type="file" style="display: none;" multiple="multiple" />');
 | 
						|
    file.change(function () {
 | 
						|
        var files = this.files;
 | 
						|
        if (files.length > 0) {
 | 
						|
            onSaveWOAttachment(files);
 | 
						|
        }
 | 
						|
    }).click();
 | 
						|
}
 | 
						|
 | 
						|
var filesinuploading = [];
 | 
						|
var uploadingindex = -1;
 | 
						|
var fileupload_errors = "";
 | 
						|
function onSaveWOAttachment(files) {
 | 
						|
    fileupload_errors = "";
 | 
						|
    if (!workorderid) {
 | 
						|
        OnSave(0, function () {
 | 
						|
            showLoading();
 | 
						|
            $('.span_attupload').show();
 | 
						|
            $('.span_vieuploadmsg').css('margin-left', 0);
 | 
						|
            $('.span_vieuploadmsg').show();
 | 
						|
            if (filesinuploading.length > 0) {
 | 
						|
                for (var i = 0; i < files.length; i++)
 | 
						|
                    filesinuploading.push(workorderid, files[i]);
 | 
						|
                showUplpadingStatus(0);
 | 
						|
            }
 | 
						|
            else {
 | 
						|
                filesinuploading = files;
 | 
						|
                DoUploadWorkOrderAttachments(workorderid);
 | 
						|
            }
 | 
						|
        });
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        showLoading();
 | 
						|
        $('.span_attupload').show();
 | 
						|
        $('.span_vieuploadmsg').css('margin-left', 0);
 | 
						|
        $('.span_vieuploadmsg').show();
 | 
						|
        if (filesinuploading.length > 0) {
 | 
						|
            for (var i = 0; i < files.length; i++)
 | 
						|
                filesinuploading.push(files[i]);
 | 
						|
            showUplpadingStatus(0);
 | 
						|
        }
 | 
						|
        else {
 | 
						|
            filesinuploading = files;
 | 
						|
            DoUploadWorkOrderAttachments(workorderid);
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
function DoUploadWorkOrderAttachments(woid) {
 | 
						|
    if (woid != workorderid) {
 | 
						|
        filesinuploading = [];
 | 
						|
        uploadingindex = -1;
 | 
						|
        return;
 | 
						|
    }
 | 
						|
    uploadingindex++;
 | 
						|
    if (uploadingindex >= filesinuploading.length) {
 | 
						|
        uploadingindex--;
 | 
						|
        showUplpadingStatus(3);
 | 
						|
        filesinuploading = [];
 | 
						|
        uploadingindex = -1;
 | 
						|
        $('.span_attupload').hide();
 | 
						|
        $('.span_vieuploadmsg').css('margin-left', 200);
 | 
						|
        getWorkOrderAttachments();
 | 
						|
 | 
						|
        hideLoading();
 | 
						|
        if (fileupload_errors !== "")
 | 
						|
            showAlert(fileupload_errors, GetTextByKey("P_WO_XXXXX", 'Upload failed'));
 | 
						|
        return;
 | 
						|
    }
 | 
						|
    var file = filesinuploading[uploadingindex];
 | 
						|
    if (file.name.length > 200) {
 | 
						|
        showUplpadingStatus(2, GetTextByKey("P_WO_XXX", "Attachment name length cannot be greater than 200."));
 | 
						|
        DoUploadWorkOrderAttachments(woid);
 | 
						|
        return;
 | 
						|
    }
 | 
						|
    if (file.size == 0) {
 | 
						|
        showUplpadingStatus(2, GetTextByKey("P_WO_ATTACHMENTSTIPS", "Attachment size is 0kb, uploading failed."));
 | 
						|
        DoUploadWorkOrderAttachments(woid);
 | 
						|
        return;
 | 
						|
    }
 | 
						|
    if (file.size > 50 * 1024 * 1024) {
 | 
						|
        showUplpadingStatus(2, GetTextByKey("P_WO_ATTACHMENTSTIPS1", "Attachment is too large. Maximum file size is 50 MB."));
 | 
						|
        DoUploadWorkOrderAttachments(woid);
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    showUplpadingStatus(0);
 | 
						|
 | 
						|
    var top = $(window).height() / 2 - 100;
 | 
						|
    var left = $(window).width() / 2 - 100;
 | 
						|
    var width = $('#dialogattmask .lable_attuploadname').width();
 | 
						|
    $('#dialogattmask .loading_icon').css({ top: top, left: left });
 | 
						|
    $('#dialogattmask .lable_attuploadname').css({ top: top + 70, left: ($(window).width() - width - 100) / 2 });
 | 
						|
 | 
						|
    var p = JSON.stringify([workorderid, ""]);
 | 
						|
    var formData = new FormData();
 | 
						|
    formData.append("iconFile", file);
 | 
						|
    formData.append("MethodName", "AddAttachment");
 | 
						|
    formData.append("ClientData", p);
 | 
						|
    var url = 'AddWorkOrder.aspx';
 | 
						|
    $.ajax({
 | 
						|
        url: url,
 | 
						|
        type: 'POST',
 | 
						|
        dataType: 'json',
 | 
						|
        processData: false,
 | 
						|
        contentType: false,
 | 
						|
        data: formData,
 | 
						|
        async: true,
 | 
						|
        success: function (data) {
 | 
						|
            if (data !== 'OK') {
 | 
						|
                showAlert(GetTextByKey("P_WO_XXXXX", 'Upload failed'), GetTextByKey("P_WO_ATTACHMENTFILE", 'Attachment File'));
 | 
						|
            }
 | 
						|
            showUplpadingStatus(1);
 | 
						|
            DoUploadWorkOrderAttachments(woid);
 | 
						|
        },
 | 
						|
        error: function (err) {
 | 
						|
            showUplpadingStatus(2, GetTextByKey("P_WO_XXXXX", 'Upload failed'));
 | 
						|
            DoUploadWorkOrderAttachments(woid);
 | 
						|
        }
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
function showUplpadingStatus(status, msg) {
 | 
						|
    if (filesinuploading.length == 0) return;
 | 
						|
    var filename = filesinuploading[uploadingindex].name;
 | 
						|
    if (filename.length > 50)
 | 
						|
        filename = filename.substring(0, 49) + "...";
 | 
						|
 | 
						|
    var statustxt = "";
 | 
						|
    if (status == 0) {
 | 
						|
        statustxt = "Uploading " + filename + " (" + (uploadingindex + 1) + "/" + filesinuploading.length + ")";
 | 
						|
        $('.lable_attuploadname').text(statustxt);
 | 
						|
    }
 | 
						|
    else if (status == 1) {
 | 
						|
        statustxt = filename;
 | 
						|
        $('#attupload_ul').append('<li style="padding-left: 0;height:unset;line-height:24px;"><span class="sbutton iconattsuc">' + statustxt + '</span></li>');
 | 
						|
    }
 | 
						|
    else if (status == 2) {
 | 
						|
        statustxt = filename + " - " + msg;
 | 
						|
        $('#attupload_ul').append('<li style="padding-left: 0;height:unset;line-height:24px;"><span class="sbutton iconatterror">' + statustxt + '</span></li>');
 | 
						|
        if (fileupload_errors === "")
 | 
						|
            fileupload_errors = statustxt;
 | 
						|
        else
 | 
						|
            fileupload_errors = fileupload_errors + " \n " + statustxt;
 | 
						|
    }
 | 
						|
    else if (status == 3) {
 | 
						|
        statustxt = "Upload Completed";
 | 
						|
        statustxt = "";
 | 
						|
        $('.lable_attuploadname').text(statustxt);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
function deleteAttachment(attID) {
 | 
						|
    if (confirm(GetTextByKey("P_WO_DELETEATTACHMENTTIPS", "Are you sure you want to delete the attachment?"))) {
 | 
						|
        worequest("DeleteAttachment", attID, function (data) {
 | 
						|
            if (data !== 'OK') {
 | 
						|
                showAlert(data, GetTextByKey("P_WO_DELETEATTACHMENT", 'Delete Attachment'));
 | 
						|
            }
 | 
						|
            else {
 | 
						|
                getWorkOrderAttachments();
 | 
						|
            }
 | 
						|
        }, function (err) {
 | 
						|
            showAlert(GetTextByKey("P_WO_FAILEDDELETEATTACHMENT", 'Failed to delete this attachment.'), GetTextByKey("P_WO_DELETEATTACHMENT", 'Delete Attachment'));
 | 
						|
        });
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
var allAttachments;
 | 
						|
var viewtype = 0;
 | 
						|
function onViewAttachment(type) {
 | 
						|
    viewtype = type;
 | 
						|
    if (typeof setCookie === "function")
 | 
						|
        setCookie("woattachmentviewtype", viewtype);
 | 
						|
 | 
						|
    $(".woattafoldicon").removeClass("iconchevronright").addClass("iconchevrondown");
 | 
						|
    $(".woattafoldtr").show();
 | 
						|
    showWOAttachments();
 | 
						|
}
 | 
						|
 | 
						|
function showWOAttachments() {
 | 
						|
    $('#div_woatts').empty();
 | 
						|
    $('#div_atts').empty();
 | 
						|
    $('#div_iatts').empty();
 | 
						|
    $('#woattslist_tbody').empty();
 | 
						|
    $('#woassetattslist_tbody').empty();
 | 
						|
    $('#woiptattslist_tbody').empty();
 | 
						|
 | 
						|
    if (!viewtype)
 | 
						|
        viewtype = 0;
 | 
						|
 | 
						|
    if (parseInt(viewtype) === 1) {
 | 
						|
        $('#div_attlarge').hide();
 | 
						|
        $('#div_attlist').show();
 | 
						|
        showAttachmentList(allAttachments);
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        $('#div_attlarge').show();
 | 
						|
        $('#div_attlist').hide();
 | 
						|
        showWorkOrderAttachments(allAttachments);
 | 
						|
    }
 | 
						|
    $('#dialogattmask').height($(document).outerHeight(false)).width($(document).outerWidth(false));
 | 
						|
}
 | 
						|
 | 
						|
function getWorkOrderAttachments(next) {
 | 
						|
    if (workorderid) {
 | 
						|
        worequest('GetAttachments', JSON.stringify([workorderid, machineid]), function (data) {
 | 
						|
            if (data && typeof data != "string") {
 | 
						|
                allAttachments = data;
 | 
						|
                if (next)
 | 
						|
                    next();
 | 
						|
                else {
 | 
						|
                    showWOAttachments(allAttachments);
 | 
						|
                }
 | 
						|
            }
 | 
						|
        });
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
var imgTypes = [".jfif", ".jpg", ".jpeg", ".bmp", ".png", ".tiff", ".gif"];
 | 
						|
var printTypes = ['.pdf', ".jfif", ".jpg", ".jpeg", ".bmp", ".png", ".tiff", ".gif"];//types to be loaded to print
 | 
						|
function showWorkOrderAttachments(attas) {
 | 
						|
    var div_aatts = $('#div_aatts');
 | 
						|
    div_aatts.empty();
 | 
						|
    var div_woatts = $('#div_woatts');
 | 
						|
    div_woatts.empty();
 | 
						|
    var div_iatts = $('#div_iatts');
 | 
						|
    div_iatts.empty();
 | 
						|
    if (attas.AssetAttachments && attas.AssetAttachments.length > 0) {
 | 
						|
        for (var i = 0; i < attas.AssetAttachments.length; i++) {
 | 
						|
            var att = attas.AssetAttachments[i];
 | 
						|
            if (imgTypes.indexOf(att.FileType.toLowerCase()) >= 0)
 | 
						|
                att.ThumbnailUrl = att.Url + "&thumb=1";
 | 
						|
            var div = createAttaDiv(att);
 | 
						|
 | 
						|
            if ($.inArray(att.FileType.toLowerCase(), printTypes) >= 0) {
 | 
						|
                var sprint = $('<span class="attaprint"></span>').attr('title', GetTextByKey("P_WO_PRINT", 'Print')).click(att, function (e) {
 | 
						|
                    openPrintFrame(e.data.AttachmentType, e.data.AttachmentIdStr);
 | 
						|
                });
 | 
						|
                div.append(sprint);
 | 
						|
            }
 | 
						|
 | 
						|
            if (att.FileType.toLowerCase() != "url") {
 | 
						|
                var sdownload = $('<span class="attadownload"></span>').attr('title', GetTextByKey("P_WO_DOWNLOAD", 'Download')).click(att, function (e) {
 | 
						|
                    openDownloadFrame(e.data.Url + "&d=1");
 | 
						|
                });
 | 
						|
                div.append(sdownload);
 | 
						|
            }
 | 
						|
 | 
						|
            div_aatts.append(div);
 | 
						|
        }
 | 
						|
    }
 | 
						|
    if (attas.WorkOrderAttachments && attas.WorkOrderAttachments.length > 0) {
 | 
						|
        for (var i = 0; i < attas.WorkOrderAttachments.length; i++) {
 | 
						|
            var att = attas.WorkOrderAttachments[i];
 | 
						|
 | 
						|
            var pdiv = $('<div class="divattp"></div>');
 | 
						|
            var div = createAttaDiv(att, true);
 | 
						|
 | 
						|
            var div1 = $('<div style=" margin-top: 15px;"></div>');
 | 
						|
            var ext_span = $('<span style="font-weight:500;"></span>').text(GetTextByKey("P_WO_AVAILABLETOCUSTOMER", 'Available to Customer'));
 | 
						|
            var ext_chk = $('<input type="checkbox" />').prop('checked', att.AvailableToCustomer).click(att, function (e) {
 | 
						|
                updateWOAttachmentExtension(e.data.AttachmentId, $(this).prop('checked'));
 | 
						|
            });
 | 
						|
            div1.append(ext_chk).append(ext_span);
 | 
						|
            pdiv.append(div1);
 | 
						|
 | 
						|
            if (AllowDeleteAtta) {
 | 
						|
                var sdel = $('<span class="delete"></span>').attr('title', GetTextByKey("P_WO_DELETE", 'Delete')).click(att, function (e) {
 | 
						|
                    deleteAttachment(e.data.AttachmentId);
 | 
						|
                });
 | 
						|
                div.append(sdel);
 | 
						|
            }
 | 
						|
 | 
						|
            if ($.inArray(att.FileType.toLowerCase(), printTypes) >= 0) {
 | 
						|
                var sprint = $('<span class="attaprint"></span>').attr('title', GetTextByKey("P_WO_PRINT", 'Print')).click(att, function (e) {
 | 
						|
                    openPrintFrame(e.data.AttachmentType, e.data.AttachmentIdStr);
 | 
						|
                });
 | 
						|
                div.append(sprint);
 | 
						|
            }
 | 
						|
 | 
						|
            var sdownload = $('<span class="attadownload"></span>').attr('title', GetTextByKey("P_WO_DOWNLOAD", 'Download')).click(att, function (e) {
 | 
						|
                openDownloadFrame(e.data.Url + "&d=1");
 | 
						|
            });
 | 
						|
            div.append(sdownload);
 | 
						|
            pdiv.append(div);
 | 
						|
 | 
						|
            var caption = att.Notes === "" ? att.FileName : att.Notes;
 | 
						|
            var div3 = $('<div style="text-align:center;clear:both;height:25px;"></div>');
 | 
						|
            var iptcaption = $('<input type="text" style="width: 296px;" class="inp_name" style="height:24px;" maxlength="200"/>').attr('data-ori', caption).val(caption);
 | 
						|
            iptcaption.data('attdata', att);
 | 
						|
            div3.append(iptcaption);
 | 
						|
            iptcaption.focus({ AttachmentId: att.AttachmentId, iptcaption: iptcaption }, function (e) {
 | 
						|
                e.data.iptcaption.addClass('focused');
 | 
						|
            });
 | 
						|
            iptcaption.blur({ div: div, AttachmentId: att.AttachmentId, iptcaption: iptcaption, caption: caption }, function (e) {
 | 
						|
                e.data.iptcaption.removeClass('focused');
 | 
						|
                updateWOAttachmentCaption(e.data);
 | 
						|
            });
 | 
						|
            iptcaption.keydown({ div: div, AttachmentId: att.AttachmentId, iptcaption: iptcaption, caption: caption }, function (e) {
 | 
						|
                if (e.keyCode == 13 || e.keyCode == 9) {
 | 
						|
                    e.data.iptcaption.blur();
 | 
						|
                }
 | 
						|
            });
 | 
						|
            pdiv.append(div3);
 | 
						|
            div_woatts.append(pdiv);
 | 
						|
        }
 | 
						|
    }
 | 
						|
    if (attas.InspectionAttachments && attas.InspectionAttachments.length > 0) {
 | 
						|
        for (var i = 0; i < attas.InspectionAttachments.length; i++) {
 | 
						|
            var att = attas.InspectionAttachments[i];
 | 
						|
            var div = createAttaDiv(att);
 | 
						|
 | 
						|
            if ($.inArray(att.FileType.toLowerCase(), printTypes) >= 0) {
 | 
						|
                var sprint = $('<span class="attaprint"></span>').attr('title', GetTextByKey("P_WO_PRINT", 'Print')).click(att, function (e) {
 | 
						|
                    openPrintFrame(e.data.AttachmentType, e.data.AttachmentIdStr);
 | 
						|
                });
 | 
						|
                div.append(sprint);
 | 
						|
            }
 | 
						|
 | 
						|
            var sdownload = $('<span class="attadownload"></span>').attr('title', GetTextByKey("P_WO_DOWNLOAD", 'Download')).click(att, function (e) {
 | 
						|
                openDownloadFrame(e.data.Url + "&d=1");
 | 
						|
            });
 | 
						|
            div.append(sdownload);
 | 
						|
 | 
						|
            div_iatts.append(div);
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
function createAttaDiv(att, iswoatta) {
 | 
						|
    var div = $('<div class="divatt"></div>').attr('title', att.FileName);
 | 
						|
    if (iswoatta)
 | 
						|
        div.attr('title', att.Notes === "" ? att.FileName : att.Notes)
 | 
						|
 | 
						|
    if (!att.FileType || att.FileType == "") att.FileType = ".jpg";
 | 
						|
    if (imgTypes.indexOf(att.FileType.toLowerCase()) >= 0) {
 | 
						|
        var pic = $('<img class="picture"></img>').attr('src', att.ThumbnailUrl);
 | 
						|
        pic.click(att, function (e) {
 | 
						|
            window.open(e.data.Url, "_blank")
 | 
						|
        });
 | 
						|
        div.append(pic);
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        var sdown = $('<img class="picture" />').click(att, function (e) {
 | 
						|
            window.open(e.data.Url);
 | 
						|
        });
 | 
						|
        setAttachemntIcon(att.FileType, sdown);
 | 
						|
        div.append(sdown);
 | 
						|
    }
 | 
						|
    return div
 | 
						|
}
 | 
						|
 | 
						|
function updateWOAttachmentExtension(attID, chk) {
 | 
						|
    var item = {
 | 
						|
        'Key': "1",
 | 
						|
        'Value': chk
 | 
						|
    };
 | 
						|
 | 
						|
    var param = JSON.stringify(item);
 | 
						|
    param = htmlencode(param);
 | 
						|
 | 
						|
    worequest('UpdateWOAttachmentExtension', JSON.stringify([attID, param]), function (data) {
 | 
						|
        if (data !== 'OK') {
 | 
						|
            showAlert(data, GetTextByKey("P_WO_AVAILABLETOCUSTOMER", 'Available to Customer'));
 | 
						|
        }
 | 
						|
        if (allAttachments && allAttachments.WorkOrderAttachments) {
 | 
						|
            for (var i = 0; i < allAttachments.WorkOrderAttachments.length; i++) {
 | 
						|
                if (allAttachments.WorkOrderAttachments[i].AttachmentId == attID) {
 | 
						|
                    allAttachments.WorkOrderAttachments[i].AvailableToCustomer = chk;
 | 
						|
                    break;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }, function (err) {
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
var grid_panddattachments
 | 
						|
function InitPAndDGrid() {
 | 
						|
    grid_panddattachments = new GridView('#dialog_wopanddattachmentlist');
 | 
						|
    var list_columns = [
 | 
						|
        { name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 30, 'text-align': 'center' } },
 | 
						|
        { name: 'ThumbnailUrl', caption: "", valueIndex: 'ThumbnailUrl', css: { 'width': 42, 'text-align': 'center' } },
 | 
						|
        { name: 'FileName', caption: GetTextByKey("P_WO_NAME", "Name"), valueIndex: 'FileName', css: { 'width': 280, 'text-align': 'left' } }
 | 
						|
    ];
 | 
						|
 | 
						|
    var columns = [];
 | 
						|
    for (var hd in list_columns) {
 | 
						|
        var col = {};
 | 
						|
        if (list_columns[hd].type) {
 | 
						|
            col.type = list_columns[hd].type;
 | 
						|
        }
 | 
						|
        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;
 | 
						|
        columns.push(col);
 | 
						|
 | 
						|
        if (col.name == "Selected") {
 | 
						|
            col.allcheck = true;
 | 
						|
            col.sortable = false;
 | 
						|
        }
 | 
						|
        else if (col.name == "ThumbnailUrl") {
 | 
						|
            col.allowHtml = true;
 | 
						|
            col.filterCustom = true;
 | 
						|
            col.filter = function (item) {
 | 
						|
                if (imgTypes.indexOf(item.FileType.toLowerCase()) >= 0)
 | 
						|
                    return $('<img style="height:30px;width:30px;"></img>').attr('src', item.ThumbnailUrl);
 | 
						|
                else {
 | 
						|
                    var sdown = $('<img style="height:30px;width:30px;line-height:40px;" />')
 | 
						|
                    setAttachemntIcon(item.FileType, sdown);
 | 
						|
                    return sdown;
 | 
						|
                }
 | 
						|
            }
 | 
						|
            col.styleFilter = function () {
 | 
						|
                return { "width": "100%", 'margin': 0 };
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    grid_panddattachments.canMultiSelect = true;
 | 
						|
    grid_panddattachments.columns = columns;
 | 
						|
    grid_panddattachments.init();
 | 
						|
}
 | 
						|
 | 
						|
function openPAndDGDialog(type) {
 | 
						|
    if (!allAttachments) return;
 | 
						|
 | 
						|
    var d = $("#dialog_panddattachments");
 | 
						|
    if (!d.data("loaded")) {
 | 
						|
        d.data("loaded", true);
 | 
						|
        InitPAndDGrid();
 | 
						|
    }
 | 
						|
    if (type == 0) {
 | 
						|
        $("#btnPrintWOAttachments").show();
 | 
						|
        $("#btnDownloadWOAttachments").hide();
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        $("#btnPrintWOAttachments").hide();
 | 
						|
        $("#btnDownloadWOAttachments").show();
 | 
						|
    }
 | 
						|
    var data = [];
 | 
						|
    if (allAttachments.AssetAttachments && allAttachments.AssetAttachments.length > 0)
 | 
						|
        data = data.concat(allAttachments.AssetAttachments);
 | 
						|
    if (allAttachments.WorkOrderAttachments && allAttachments.WorkOrderAttachments.length > 0)
 | 
						|
        data = data.concat(allAttachments.WorkOrderAttachments);
 | 
						|
    if (allAttachments.InspectionAttachments && allAttachments.InspectionAttachments.length > 0)
 | 
						|
        data = data.concat(allAttachments.InspectionAttachments);
 | 
						|
 | 
						|
    var count = 0;
 | 
						|
    var rows = [];
 | 
						|
    for (var i = 0; i < data.length; i++) {
 | 
						|
        var att = data[i];
 | 
						|
        if (att.FileType.toLowerCase() == "url") continue;
 | 
						|
        if (type == 1 || $.inArray(att.FileType.toLowerCase(), printTypes) >= 0) {
 | 
						|
            var fr = {
 | 
						|
                Values: {
 | 
						|
                    FileName: att.Notes === "" ? att.FileName : att.Notes,
 | 
						|
                    FileType: att.FileType,
 | 
						|
                    Url: att.Url,
 | 
						|
                    ThumbnailUrl: att.ThumbnailUrl,
 | 
						|
                    AttachmentType: att.AttachmentType,
 | 
						|
                    AttachmentIdStr: att.AttachmentIdStr,
 | 
						|
                    Selected: false,
 | 
						|
                }
 | 
						|
            };
 | 
						|
            rows.push(fr);
 | 
						|
            count++;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    $('#dialog_panddattachments .dialog-title span.title').text(GetTextByKey("P_WO_ATTACHMENTS", 'Attachments') + " (" + count + ")");
 | 
						|
    showmaskbg(true);
 | 
						|
    d.css({
 | 
						|
        'top': (document.documentElement.clientHeight - d.height()) / 3,
 | 
						|
        'left': (document.documentElement.clientWidth - d.width()) / 2
 | 
						|
    }).showDialogfixed();
 | 
						|
 | 
						|
    setTimeout(function () {
 | 
						|
        grid_panddattachments.setData(rows);
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
function getSelectedPAndDAttas() {
 | 
						|
    var sels = [];
 | 
						|
    if (grid_panddattachments && grid_panddattachments.source) {
 | 
						|
        for (var i = 0; i < grid_panddattachments.source.length; i++) {
 | 
						|
            var a = grid_panddattachments.source[i].Values;
 | 
						|
            if (a.Selected)
 | 
						|
                sels.push(a);
 | 
						|
        }
 | 
						|
    }
 | 
						|
    return sels;
 | 
						|
}
 | 
						|
 | 
						|
function printWOAttachments() {
 | 
						|
    var sels = getSelectedPAndDAttas();
 | 
						|
    if (!sels || sels.length == 0) return;
 | 
						|
    if (sels && sels.length > 0) {
 | 
						|
        for (var i = 0; i < sels.length; i++) {
 | 
						|
            var att = sels[i];
 | 
						|
            if ($.inArray(att.FileType.toLowerCase(), printTypes) >= 0) {
 | 
						|
                openPrintFrame(att.AttachmentType, att.AttachmentIdStr);
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    showmaskbg(false);
 | 
						|
    $('#dialog_panddattachments').hideDialog();
 | 
						|
}
 | 
						|
 | 
						|
function openPrintFrame(attatype, id) {
 | 
						|
    var frame = $("<iframe style='display:none;'></iframe>");
 | 
						|
    $(document.body).after(frame);
 | 
						|
    //frame.attr("src", url);
 | 
						|
    frame.attr("src", _network.root + "Print.aspx?pt=3&at=" + attatype + "&id=" + id);
 | 
						|
 | 
						|
    frame.on('load', function () {
 | 
						|
        setTimeout(function () {
 | 
						|
            frame.contents().find("body").css("text-align", "center");
 | 
						|
            //frame.contents().find("img").css("max-height", window.screen.availHeight).css("max-width", window.screen.availWidth);
 | 
						|
            frame.contents().find("img").css("max-height", "98%").css("max-width", "98%");
 | 
						|
            frame[0].contentWindow.print();
 | 
						|
        });
 | 
						|
        setTimeout(function () {
 | 
						|
            frame.remove();
 | 
						|
        }, 60000);
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
function downloadWOAttachments() {
 | 
						|
    var sels = getSelectedPAndDAttas();
 | 
						|
    if (!sels || sels.length == 0) return;
 | 
						|
    if (sels && sels.length > 0) {
 | 
						|
        for (var i = 0; i < sels.length; i++) {
 | 
						|
            var att = sels[i];
 | 
						|
            openDownloadFrame(att.Url + "&d=1");
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    showmaskbg(false);
 | 
						|
    $('#dialog_panddattachments').hideDialog();
 | 
						|
}
 | 
						|
 | 
						|
function openDownloadFrame(url) {
 | 
						|
    var frame = $("<iframe style='display:none;'></iframe>");
 | 
						|
    $(document.body).after(frame);
 | 
						|
    frame.attr("src", url);
 | 
						|
 | 
						|
    var timer = setInterval(function () {
 | 
						|
        if (frame[0].contentDocument && (frame[0].contentDocument.readyState == "complete" || frame[0].contentDocument.readyState == 4)) {
 | 
						|
            frame.remove();
 | 
						|
            clearInterval(timer);
 | 
						|
        }
 | 
						|
    }, 5000);
 | 
						|
}
 | 
						|
 | 
						|
function updateWOAttachmentCaption(edata) {
 | 
						|
    var attid = edata.AttachmentId;
 | 
						|
    var caption = edata.iptcaption.val();
 | 
						|
 | 
						|
    if (caption === "") {
 | 
						|
        var pcap = edata.caption;
 | 
						|
        if (edata.iptcaption.data('caption'))
 | 
						|
            pcap = edata.iptcaption.data('caption');
 | 
						|
        edata.iptcaption.val(pcap);
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    var att = edata.iptcaption.data('attdata');
 | 
						|
    att.Notes = caption;
 | 
						|
 | 
						|
    if (allAttachments && allAttachments.WorkOrderAttachments) {
 | 
						|
        for (var i = 0; i < allAttachments.WorkOrderAttachments.length; i++) {
 | 
						|
            if (allAttachments.WorkOrderAttachments[i].AttachmentId == att.AttachmentId) {
 | 
						|
                allAttachments.WorkOrderAttachments[i] = att;
 | 
						|
                break;
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    worequest('UpdateWorkOrderAttachmentCaption', JSON.stringify([attid, htmlencode(caption)]), function (data) {
 | 
						|
        if (data !== 'OK') {
 | 
						|
            showAlert(data, GetTextByKey("P_WO_XXX", 'Update Caption'));
 | 
						|
        }
 | 
						|
        else {
 | 
						|
            if (edata.div)
 | 
						|
                edata.div.attr('title', caption);
 | 
						|
            edata.iptcaption.data('caption', caption);
 | 
						|
        }
 | 
						|
    }, function (err) {
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
//***********************************Begin Attachment List************************************//
 | 
						|
 | 
						|
function showAttachmentList(data) {
 | 
						|
    $('#woattslist_tbody').empty();
 | 
						|
    $('#woassetattslist_tbody').empty();
 | 
						|
    $('#woiptattslist_tbody').empty();
 | 
						|
    if (data.WorkOrderAttachments && data.WorkOrderAttachments.length > 0) {
 | 
						|
        for (var i = 0; i < data.WorkOrderAttachments.length; i++) {
 | 
						|
            var att = data.WorkOrderAttachments[i];
 | 
						|
            var tr = createWOAttachmentTr(att);
 | 
						|
            $('#woattslist_tbody').append(tr);
 | 
						|
        }
 | 
						|
    }
 | 
						|
    if (data.AssetAttachments && data.AssetAttachments.length > 0) {
 | 
						|
        for (var i = 0; i < data.AssetAttachments.length; i++) {
 | 
						|
            var att = data.AssetAttachments[i];
 | 
						|
            if (imgTypes.indexOf(att.FileType.toLowerCase()) >= 0)
 | 
						|
                att.ThumbnailUrl = att.Url + "&thumb=1";
 | 
						|
            var tr = createWOOtherAttachmentTr(att);
 | 
						|
            $('#woassetattslist_tbody').append(tr);
 | 
						|
        }
 | 
						|
    }
 | 
						|
    if (data.InspectionAttachments && data.InspectionAttachments.length > 0) {
 | 
						|
        for (var i = 0; i < data.InspectionAttachments.length; i++) {
 | 
						|
            var att = data.InspectionAttachments[i];
 | 
						|
            var tr = createWOOtherAttachmentTr(att);
 | 
						|
            $('#woiptattslist_tbody').append(tr);
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
function createWOAttachmentTr(att) {
 | 
						|
    var caption = att.Notes === "" ? att.FileName : att.Notes;
 | 
						|
    var tr = $('<tr></tr>').attr('data-id', att.AttachmentId);
 | 
						|
    var td;
 | 
						|
    tr.append('<td></td>');
 | 
						|
 | 
						|
    td = $('<td></td>');
 | 
						|
    if (!att.FileType || att.FileType == "")
 | 
						|
        att.FileType = ".jpg";
 | 
						|
 | 
						|
    var divpic = $('<div style="width:60px;height:60px;text-align:center;"></div>');
 | 
						|
    td.append(divpic);
 | 
						|
    if (imgTypes.indexOf(att.FileType.toLowerCase()) >= 0) {
 | 
						|
        var pic = $('<img class="wolist_picture"></img>').attr('src', att.ThumbnailUrl);
 | 
						|
        pic.click(att, function (e) {
 | 
						|
            window.open(e.data.Url, "_blank")
 | 
						|
        });
 | 
						|
        divpic.append(pic);
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        var sdown = $('<img class="wolist_picture" />').click(att, function (e) {
 | 
						|
            window.open(e.data.Url);
 | 
						|
        });
 | 
						|
        setAttachemntIcon(att.FileType, sdown);
 | 
						|
        divpic.append(sdown);
 | 
						|
    }
 | 
						|
    tr.append(td);
 | 
						|
 | 
						|
    td = $('<td style="padding-left:20px;"></td>');
 | 
						|
    var iptcaption = $('<input type="text" class="inp_name" maxlength="200" style="height:24px;"/>').css('width', '100%').attr('data-ori', caption).val(caption);
 | 
						|
    iptcaption.data('attdata', att);
 | 
						|
    td.append(iptcaption);
 | 
						|
    iptcaption.focus({ AttachmentId: att.AttachmentId, iptcaption: iptcaption }, function (e) {
 | 
						|
        e.data.iptcaption.addClass('focused');
 | 
						|
    });
 | 
						|
    iptcaption.blur({ AttachmentId: att.AttachmentId, iptcaption: iptcaption, caption: caption }, function (e) {
 | 
						|
        e.data.iptcaption.removeClass('focused');
 | 
						|
        updateWOAttachmentCaption(e.data);
 | 
						|
    });
 | 
						|
 | 
						|
    iptcaption.keydown({ AttachmentId: att.AttachmentId, iptcaption: iptcaption, caption: caption }, function (e) {
 | 
						|
        if (e.keyCode == 13 || e.keyCode == 9) {
 | 
						|
            e.data.iptcaption.blur();
 | 
						|
        }
 | 
						|
    });
 | 
						|
    tr.append(td);
 | 
						|
 | 
						|
 | 
						|
    td = $('<td></td>');
 | 
						|
    var chk_tocust = $('<input type="checkbox" class="inp_recurring"/>').attr('data-ori', att.AvailableToCustomer).prop('checked', att.AvailableToCustomer);
 | 
						|
    td.append(chk_tocust);
 | 
						|
    chk_tocust.click(att, function (e) {
 | 
						|
        updateWOAttachmentExtension(e.data.AttachmentId, $(this).prop('checked'));
 | 
						|
    });
 | 
						|
    tr.append(td);
 | 
						|
 | 
						|
    td = $('<td class="td_funcs"></td>');
 | 
						|
    var sdel = $('<span class="wolist_icon wolist_delete"></span>').attr('title', GetTextByKey("P_WO_DELETE", 'Delete')).click(att, function (e) {
 | 
						|
        deleteAttachment(e.data.AttachmentId);
 | 
						|
    });
 | 
						|
    td.append(sdel);
 | 
						|
 | 
						|
    var sdownload = $('<span class="wolist_icon wolist_attadownload"></span>').attr('title', GetTextByKey("P_WO_DOWNLOAD", 'Download')).click(att, function (e) {
 | 
						|
        openDownloadFrame(e.data.Url + "&d=1");
 | 
						|
    });
 | 
						|
    td.append(sdownload);
 | 
						|
 | 
						|
    if ($.inArray(att.FileType.toLowerCase(), printTypes) >= 0) {
 | 
						|
        var sprint = $('<span class="wolist_icon wolist_attaprint"></span>').attr('title', GetTextByKey("P_WO_PRINT", 'Print')).click(att, function (e) {
 | 
						|
            openPrintFrame(e.data.AttachmentType, e.data.AttachmentIdStr);
 | 
						|
        });
 | 
						|
        td.append(sprint);
 | 
						|
    }
 | 
						|
 | 
						|
    tr.append(td);
 | 
						|
    return tr;
 | 
						|
}
 | 
						|
 | 
						|
function createWOOtherAttachmentTr(att) {
 | 
						|
    var tr = $('<tr></tr>').attr('data-id', att.AttachmentId);
 | 
						|
    var td;
 | 
						|
    tr.append('<td></td>');
 | 
						|
 | 
						|
    td = $('<td></td>');
 | 
						|
    if (!att.FileType || att.FileType == "")
 | 
						|
        att.FileType = ".jpg";
 | 
						|
 | 
						|
    var divpic = $('<div style="width:60px;height:60px;text-align:center;"></div>');
 | 
						|
    td.append(divpic);
 | 
						|
    if (imgTypes.indexOf(att.FileType.toLowerCase()) >= 0) {
 | 
						|
        var pic = $('<img class="wolist_picture"></img>').attr('src', att.ThumbnailUrl);
 | 
						|
        pic.click(att, function (e) {
 | 
						|
            window.open(e.data.Url, "_blank")
 | 
						|
        });
 | 
						|
        divpic.append(pic);
 | 
						|
    }
 | 
						|
    else {
 | 
						|
        var sdown = $('<img class="wolist_picture" />').click(att, function (e) {
 | 
						|
            window.open(e.data.Url);
 | 
						|
        });
 | 
						|
        setAttachemntIcon(att.FileType, sdown);
 | 
						|
        divpic.append(sdown);
 | 
						|
    }
 | 
						|
    tr.append(td);
 | 
						|
 | 
						|
    td = $('<td style="padding-left:20px;"></td>').text(att.FileName);
 | 
						|
    tr.append(td);
 | 
						|
 | 
						|
    tr.append('<td></td>');
 | 
						|
 | 
						|
    td = $('<td class="td_funcs"></td>');
 | 
						|
    if (att.FileType.toLowerCase() != "url") {
 | 
						|
        var sdownload = $('<span class="wolist_icon wolist_attadownload"></span>').attr('title', GetTextByKey("P_WO_DOWNLOAD", 'Download')).click(att, function (e) {
 | 
						|
            openDownloadFrame(e.data.Url + "&d=1");
 | 
						|
        });
 | 
						|
        td.append(sdownload);
 | 
						|
    }
 | 
						|
 | 
						|
    if ($.inArray(att.FileType.toLowerCase(), printTypes) >= 0) {
 | 
						|
        var sprint = $('<span class="wolist_icon wolist_attaprint"></span>').attr('title', GetTextByKey("P_WO_PRINT", 'Print')).click(att, function (e) {
 | 
						|
            openPrintFrame(e.data.AttachmentType, e.data.AttachmentIdStr);
 | 
						|
        });
 | 
						|
        td.append(sprint);
 | 
						|
    }
 | 
						|
 | 
						|
    tr.append(td);
 | 
						|
    return tr;
 | 
						|
}
 | 
						|
 | 
						|
//***********************************End Attachment List************************************//
 | 
						|
 | 
						|
 | 
						|
function dragOverWOAttachment(ev) {
 | 
						|
    ev.preventDefault();
 | 
						|
    ev.dataTransfer.dropEffect = 'link';
 | 
						|
    //$('#dialogattdragmask').css({ height: $('#tb_woattlarge').height(), top: $('#tb_woattlarge').offset().top });
 | 
						|
    //$('#dialogattdragmask').show();
 | 
						|
 | 
						|
}
 | 
						|
function dropWOAttachment(ev) {
 | 
						|
    //$('#dialogattdragmask').hide();
 | 
						|
    ev.preventDefault();
 | 
						|
    ev.stopPropagation();
 | 
						|
    var df = ev.dataTransfer;
 | 
						|
    var files = [];
 | 
						|
    if (df.items !== undefined) {
 | 
						|
        for (var i = 0; i < df.items.length; i++) {
 | 
						|
            var item = df.items[i];
 | 
						|
            if (item.kind === "file" && (item.webkitGetAsEntry() == null || item.webkitGetAsEntry().isFile)) {
 | 
						|
                var file = item.getAsFile();
 | 
						|
                files.push(file);
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    if (files.length > 0)
 | 
						|
        onSaveWOAttachment(files);
 | 
						|
}
 | 
						|
 | 
						|
function cutWOAttachment(ev) {
 | 
						|
    ev.stopPropagation();
 | 
						|
    var df = ev.clipboardData;
 | 
						|
    var files = [];
 | 
						|
    if (df.items !== undefined) {
 | 
						|
        for (var i = 0; i < df.items.length; i++) {
 | 
						|
            var item = df.items[i];
 | 
						|
            if (item.kind === "file" && (item.webkitGetAsEntry() == null || item.webkitGetAsEntry().isFile)) {
 | 
						|
                var file = item.getAsFile();
 | 
						|
                files.push(file);
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    if (files.length > 0)
 | 
						|
        onSaveWOAttachment(files);
 | 
						|
}
 |