$(function () { InitAttachmentGridData(); $('#dialog_adddocument').dialog(function () { showmaskbg(false); }); $(window).resize(function () { $("#documentlist").css("height", $(window).height() - $("#documentlist").offset().top - 4); grid_attachmentdt && grid_attachmentdt.resize(); }).resize(); }); function showAttachments(data) { var rows = []; for (var i = 0; i < data.length; i++) { var r = data[i]; for (var j in r) { if (j === "VisibleOnWorkOrder") r[j] = { DisplayValue: r["VisibleOnWorkOrder"] ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No"), Value: r[j] }; else if (j === "VisibleOnMap") r[j] = { DisplayValue: r["VisibleOnMap"] ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No"), Value: r[j] }; else if (j === "VisibleOnMobile") r[j] = { DisplayValue: r["VisibleOnMobile"] ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No"), Value: r[j] }; else if (j === "AddedOnLocal") r[j] = { DisplayValue: r["AddedOnLocalStr"], Value: r[j] }; } rows.push(r); } grid_attachmentdt.setData(rows); } var grid_attachmentdt; function InitAttachmentGridData() { $('#btnEdit').attr("disabled", "disabled"); grid_attachmentdt = createGridView('#documentlist'); var list_columns = [ { name: 'Name', caption: GetTextByKey("P_MA_NAME", "Name"), valueIndex: 'Name', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } }, { name: 'AddedBy', caption: GetTextByKey("P_MA_UPLOADEDBY", "Uploaded By"), valueIndex: 'AddedBy', allowFilter: true, css: { 'width': 100, 'text-align': 'left' } }, { name: 'VisibleOnWorkOrder', caption: GetTextByKey("P_MA_VISIBLEONWORKORDER", "Visible On Work Order?"), valueIndex: 'VisibleOnWorkOrder', allowFilter: true, css: { 'width': 80, 'text-align': 'left' } }, { name: 'VisibleOnMap', caption: GetTextByKey("P_MA_VISIBLEONMAP", "Visible On Map?"), valueIndex: 'VisibleOnMap', allowFilter: true, css: { 'width': 80, 'text-align': 'left' } }, { name: 'VisibleOnMobile', caption: GetTextByKey("P_MA_VISIBLEONMOBILE", "Visible On Mobile?"), valueIndex: 'VisibleOnMobile', allowFilter: true, css: { 'width': 80, 'text-align': 'left' } }, { name: 'AddedOnLocal', caption: GetTextByKey("P_MA_ADDEDON", "Added On"), valueIndex: 'AddedOnLocal', allowFilter: true, css: { 'width': 80, 'text-align': 'left' } }, { name: 'Description', caption: GetTextByKey("P_MA_DESCRIPTION", "Desctiption"), valueIndex: 'Description', css: { 'width': 200, 'text-align': 'left' } }, { name: 'View', caption: "", css: { 'width': 30, 'text-align': 'center' } }, { name: 'Edit', caption: "", css: { 'width': 30, 'text-align': 'center' } }, { name: 'Delete', caption: "", css: { 'width': 30, 'text-align': 'center' } } ]; var columns = []; // head for (var hd in list_columns) { var col = {}; col.name = list_columns[hd].name; col.caption = list_columns[hd].caption; col.visible = true; col.sortable = true; col.width = list_columns[hd].css.width; col.align = list_columns[hd].css["text-align"] col.key = list_columns[hd].valueIndex; col.allowFilter = list_columns[hd].allowFilter; if (col.name === "View") { col.sortable = false; col.resizable = false; col.type = GridView.ColumnTypes.Icon; col.text = 'eye'; col.iconType = 'fa-light'; col.events = { onclick: function () { openDocumentUrl(); } }; col.attrs = { 'title': GetTextByKey("P_CRE_EDIT", 'Edit') }; } else if (col.name === "Edit") { col.sortable = false; col.resizable = false; col.type = GridView.ColumnTypes.Icon; col.text = 'edit'; col.iconType = 'fa-light'; col.events = { onclick: function () { onEditDocument(); } }; col.attrs = { 'title': GetTextByKey("P_CRE_EDIT", 'Edit') }; } else if (col.name === "Delete") { col.sortable = false; col.resizable = false; col.type = GridView.ColumnTypes.Icon; col.text = 'times'; col.iconType = 'fa-light'; col.events = { onclick: function () { onDeleteDocument(this); } }; col.attrs = { 'title': GetTextByKey("P_CRE_DELETE", 'Delete') }; } columns.push(col); } grid_attachmentdt.canMultiSelect = false; grid_attachmentdt.columns = columns; grid_attachmentdt.init(); grid_attachmentdt.onRowDblClicked = onEditDocument; } function setPreviewAttachment() { filedata = undefined; $("#tbAssetAttas").empty(); $('#tr_document_file').hide(); $('#browseattfile').hide(); } function getAttachments(machineid) { if (!machineid) return; showLoading(); devicerequest("GetAttachments", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } var attdata = []; if (data && data.length > 0) { attdata = data; } else attdata = []; showAttachments(attdata); }, function (err) { hideLoading(); }); } function onEditDocument() { var doc = grid_attachmentdt.source[grid_attachmentdt.selectedIndex]; if (!doc) { return; } openAddDocument(doc); } function openDocumentUrl() { var doc = grid_attachmentdt.source[grid_attachmentdt.selectedIndex]; if (!doc) { return; } window.open(doc.Url); } var assetdocumentid; function openAddDocument(doc) { setPreviewAttachment(); if (doc) { assetdocumentid = doc.Id; $('#tr_document_radio').hide(); $('#dialog_adddoc_name').val(doc.Name); $('#dialog_adddoc_desc').val(doc.Description); $('#dialog_visibleonwo').prop('checked', doc.VisibleOnWorkOrder.Value); $('#dialog_visibleonmap').prop('checked', doc.VisibleOnMap.Value); $('#dialog_visibleonmobile').prop('checked', doc.VisibleOnMobile.Value); if (doc.FileType.toLowerCase() === "url") { $('#dialog_rdourl').prop('checked', true); //$('#dialog_adddoc_url').attr("disabled", true); $('#dialog_adddoc_url').val(doc.Url); $('#tr_document_url').show(); } else { $('#dialog_rdofile').prop('checked', true); $('#tr_document_url').hide(); } } else { assetdocumentid = undefined; $('#dialog_adddoc_url').attr("disabled", false); $('#tr_document_url').show(); $('#tr_document_radio').show(); $('#dialog_adddoc_name').val(''); $('#dialog_adddoc_url').val(''); $('#dialog_adddoc_desc').val(''); $('#dialog_rdourl').prop('checked', true); $('#dialog_visibleonwo').attr("checked", false); $('#dialog_visibleonmap').attr("checked", false); $('#dialog_visibleonmobile').attr("checked", false); } $('#dialog_adddocument .dialog-title span.title').text(GetTextByKey("P_MA_ADDITIONALDOCUMENTATION", 'Additional Documentation')); showmaskbg(true); $('#dialog_adddocument') .attr('act', 'add') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_adddocument').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_adddocument').width()) / 2 }) .showDialogfixed(); $('#dialog_adddoc_name').focus(); } var filedata; function BrowseAssetDocument() { var file = $(''); file.change(function () { var files = this.files; var file = files[0]; if (file.size == 0) { alert(GetTextByKey("P_MA_DOCUMENTTIPS", "Document size is 0kb, uploading failed.")); return false; } if (file.size > 50 * 1024 * 1024) { alert(GetTextByKey("P_MA_DOCUMENTTIPS1", "Document is too large. Maximum file size is 50 MB.")); return false; } filedata = file; if ($('#dialog_adddoc_name').val() === "") $('#dialog_adddoc_name').val(file.name); $('#tbAssetAttas').empty(); var trrecoard = $('