SalesCallAssets = function( options ) { let instance = this; this.interactionId = options.interactionId; this.partnerId = options.partnerId; this.partnerType = options.partnerType; this.rootElement = null; } SalesCallAssets.prototype.constructor = SalesCallAssets; SalesCallAssets.prototype.iconForFileExt = function( fileExt ) { if( ! fileExt ) { return null }; fileExt = fileExt.toUpperCase().replace( /^\s+|\s+$/, "" ); let icon = null; switch ( fileExt ) { case 'PPTX' : icon = "pptxfile"; break; case 'PPT' : icon = "pptfile"; break; case 'TXT' : icon = "textdocument"; break; case 'DOCX' : icon = "docxfile"; break; case 'DOC' : icon = "docfile"; break; case 'PDF' : icon = "pdffile"; break; case 'XLS' : icon = "xlsfile"; break; case 'XLSX' : icon = "xlsxfile"; break; case 'JPG' : case 'TIF' : case 'PNG' : icon = "photo"; break; case 'MP4' : icon = "video"; break; } return icon; } SalesCallAssets.prototype.refresh = function() { //console.log("Refreshing SalesCallAssets"); let gridDataSource = this.dataGrid.getDataSource(); gridDataSource.reload(); } SalesCallAssets.prototype.element = function() { if( this.rootElement ) return this.rootElement; let instance = this; let dataSource = Fse.Data.newDataSource( { object : "BCM.SalesCallAssets", paginate : false, objectParams : { interactionId : instance.interactionId, partnerId : instance.partnerId, partnerType : instance.partnerType, includeNoAssetItems : false } } ); instance.dataGrid = $("
").css( { "height" : "100%" }) .dxDataGrid( { height : "100%", width : "100%", dataSource : dataSource, scrolling : { mode : "virtual" }, showBorders : true, hoverStateEnabled: false, sorting: { mode: "none" }, columns : [ { dataField : "salesCallItem", caption : "Item" }, { dataField : "mfrName", caption : "Manufacturer", width : "25%" }, { dataField: "assetDescription", caption: "Asset Description", width: "25%", cellTemplate: function(container, options) { if (options.data.docPath != "") { $("") .attr("href", options.data.docPath) .attr("target", "_blank") .text(options.value) .appendTo(container); } else { $("") .text("SPECSHEET Unavailable") .appendTo(container); } } }, { dataField : "fileExt", caption : "Type", allowEditing : false, width : 45, cellTemplate : function( container, options ) { let fileExt = options.row.data.fileExt; if( ! fileExt ) { return }; let icon = instance.iconForFileExt( fileExt ); if( icon ) { // container.append( $("
").dxButton( { icon : icon, stylingMode : "text" } )); container.append( $("").addClass( "dx-icon-" + icon ).attr( "title", fileExt ).css( "font-size", "20px" ) ); } else { container.append( fileExt ); } } }, { dataField: "included", caption: "Include", width: "10%", cellTemplate: function (container, options) { const rowData = options.data; if (rowData.docPath != "") { $("
").dxCheckBox({ value: options.value, onValueChanged: function (e) { if (rowData.assetType == "NSS") { Fse.CLOS.linkedAssetUpdate(rowData.getDocumentsForSku,'SKU',0,'NSS',rowData.interactionId, undefined, e.value); } else { Fse.CLOS.linkedAssetUpdate(rowData.getDocumentsForSku,'SKU',rowData.fileId,'DOC',rowData.interactionId, undefined, e.value); } } }).appendTo(container); } } } ], toolbar: { items: [ { location: 'after', template: function() { return $("") .text("Show Items Without Assets:") // label .css({ marginRight: "5px", lineHeight: "32px" }); } }, { location: 'after', widget: 'dxCheckBox', options: { value: false, onValueChanged: function(e) { const newDataSource = Fse.Data.newDataSource( { object : "BCM.SalesCallAssets", paginate : false, objectParams : { interactionId : instance.interactionId, partnerId : instance.partnerId, partnerType : instance.partnerType, includeNoAssetItems : e.value} } ); instance.dataGrid.option("dataSource", newDataSource); } } }, { location: 'after', template: function() { return $("") .text("Select/Deselect All:") // label .css({ marginLeft: "10px", marginRight: "5px", lineHeight: "32px" }); } }, { location: 'after', widget: 'dxCheckBox', options: { value: false, onValueChanged: function(e) { instance.element().find(".dx-data-row .dx-checkbox").each(function () { const checkbox = $(this).dxCheckBox("instance"); if (checkbox) { checkbox.option("value", e.value); } }); } } } ] }, onRowPrepared: function (e) { if (e.rowType === "data" && e.rowElement && e.data) { if (e.data.rowNumber % 2 === 0) { $(e.rowElement).css("background-color", "#f5f5f5" ); } } } }).dxDataGrid( "instance" ); instance.rootElement = $("
").css( { "height" : "100%" } ).append( instance.dataGrid.element() ); return instance.rootElement; }