function UpLoadMaintenanceLogAttachment() { var file = $(''); file.change(function () { var files = this.files; for (var i = 0; i < files.length; i++) { if (files[i].size == 0) { alert(GetTextByKey("P_MRM_ATTACHMENTSTIPS", "Attachment size is 0kb, uploading failed.")); return false; } if (files[i].size > 50 * 1024 * 1024) { alert(GetTextByKey("P_MRM_ATTACHMENTSTIPS1", "Attachment is too large. Maximum file size is 50 MB.")); return false; } } if (!maintenanceid) { OnSave(0, function () { SaveMaintenanceLogAttachmentFiles(files); }); return; } else { SaveMaintenanceLogAttachmentFiles(files); } }).click(); } function SaveMaintenanceLogAttachmentFiles(files) { for (var i = 0; i < files.length; i++) { var iconfile = files[i]; ChangeMaintenanceLogAttachmentFile(iconfile); } } function ChangeMaintenanceLogAttachmentFile(file) { var formData = new FormData(); formData.append("iconFile", file); formData.append("MethodName", "AddAttachment"); formData.append("ClientData", maintenanceid); $.ajax({ url: 'AddMaintenanceRecord.aspx', type: 'POST', dataType: 'json', processData: false, contentType: false, data: formData, async: true, success: function (data) { if (data !== 'OK') { showAlert(data, GetTextByKey("P_MRM_ATTACHMENTS", 'Attachment File')); } else { getMaintenanceLogAttachments(); } }, error: function (err) { showAlert(err.statusText, GetTextByKey("P_MRM_ATTACHMENTS", 'Attachment File')); } }); } function deleteAttachment(attID) { if (confirm(GetTextByKey("P_MRM_DELETEATTACHMENTTIPS", "Are you sure you want to delete the attachment?"))) { maintenancerequest("DeleteAttachment", attID, function (data) { if (data !== 'OK') { showAlert(data, GetTextByKey("P_MRM_DELETEATTACHMENT", 'Delete Attachment')); } else getMaintenanceLogAttachments(); }, function (err) { showAlert(GetTextByKey("P_MRM_FAILEDDELETEATTACHMENT",'Failed to delete this attachment.'), GetTextByKey("P_MRM_DELETEATTACHMENT", 'Delete Attachment')); }); } } function getMaintenanceLogAttachments() { if (maintenanceid) { $('#tbAttas').empty(); maintenancerequest('GetAttachments', maintenanceid, function (data) { if (data && data.length > 0) { $('#tabAttachments').show(); var flist = data; for (var i = 0; i < flist.length; i++) { var trrecoard = $('