Library section of the website to include and support the display and download of various file types, like Excel documents, images, PDF and video links.
- Display and Download Functionality: Ensure that Excel documents, images, PDF and video links can be both displayed and downloaded directly from the Library section.
- Organization of Files:
- Organize each type of document into specific folders within the library for easier navigation and access.
Entry point
define(
'JJ.Library.Library', [
'JJ.Library.View',
'Library.FolderView'
],
function (
LibraryView,
LibraryFolderView
) {
'use strict';
return {
mountToApp: function mountToApp(container) {
var myAccountMenu = container.getComponent("MyAccountMenu");
var pageType = container.getComponent('PageType');
var preordersMenuGroup = {
id: "Library",
name: "Library",
index: 7,
permissionoperator: "OR",
permission: [
{
group: "transactions",
id: "tranSalesOrd",
level: "1"
},
{
group: "transactions",
id: "tranEstimate",
level: "1"
}
]
}
myAccountMenu.addGroup(preordersMenuGroup);
var myAccountMenu = container.getComponent("MyAccountMenu");
var preOrdersViewAll = {
id: "Library",
groupid: "Library",
name: "View All",
index: 1,
url: "library",
permissionoperator: "OR",
permission: [
{
group: "transactions",
id: "tranSalesOrd",
level: "1"
},
{
group: "transactions",
id: "tranEstimate",
level: "1"
}
]
}
myAccountMenu.addGroupEntry(preOrdersViewAll);
pageType.registerPageType({
name: 'Library',
routes: ['library'],
view: LibraryFolderView,
});
pageType.registerPageType({
name: 'libraryFolder',
routes: ['libraryFolder'],
view: LibraryView,
});
}
};
});
Folder view
// @module JJ.Catalog.
define('Library.FolderView', [
'jj_library_library_main.tpl',
'Backbone',
'Utils'
], function (
jj_library_library_main_tpl,
Backbone,
Utils
) {
'use strict';
// @class JJ.Catalog.Catalog.View @extends Backbone.View
return Backbone.View.extend({
template: jj_library_library_main_tpl,
title: Utils.translate('Library'),
page_header: Utils.translate('Library')
,
initialize: function (options) { }
,
getContext: function getContext() {
var folder = [
{ type: 'images', name: Utils.translate('Images') },
{ type: 'documents', name: Utils.translate('Documents') },
{ type: 'videos', name: Utils.translate('Videos') }
];
return {
folder: folder
}
}
});
});
File View
// @module JJ.Catalog.Catalog
define('JJ.Library.View', [
'jj_library_library.tpl',
'Backbone',
'Utils',
'GlobalViews.Pagination.View',
'JJ.Library.Library.Model'
], function (
jj_library_library_tpl,
Backbone,
Utils,
GlobalViewsPaginationView,
LibraryModel
) {
'use strict';
// @class JJ.Catalog.Catalog.View @extends Backbone.View
return Backbone.View.extend({
template: jj_library_library_tpl,
title: Utils.translate('Library'),
page_header: Utils.translate('Library')
,
initialize: function (options) {
this.model = new LibraryModel();
var self = this;
var currentPage = 1; // Start on the first page
var fileType = null;
if (options.routerArguments && options.routerArguments[0]) {
var params = Utils.parseUrlOptions(options.routerArguments[0]);
fileType = params.option ? params.option : null;
if (params.page) {
currentPage = params.page.toString();
}
}
this.currentPage = currentPage;
this.fileType = fileType;
this.isLoading = true;
this.pageSize = SC.CONFIGURATION.Library.pageSize;
this.model.fetch().done(function (result) {
self.data = result;
var images = [];
var documents = [];
var videos = [];
var data = result;
const createFileObject = (i) => ({
name: data.name[i],
size: data.documentSize[i],
folder: data.folder[i],
url: data.url[i]
});
data.fileType.forEach((type, i) => {
switch (type) {
case 'JPGIMAGE':
case 'SVG':
case 'PJPGIMAGE':
case 'PNGIMAGE':
images.push(createFileObject(i));
break;
case 'PDF':
case 'EXCEL':
case 'WORD':
documents.push(createFileObject(i));
break;
case 'MPEGMOVIE':
videos.push(createFileObject(i));
break;
}
});
self.images = images;
self.documents = documents;
self.videos = videos;
var fileContent;
var subhead;
var documentLength;
if (fileType === ("videos")) {
fileContent = videos;
documentLength = videos ? videos.length : 0;
subhead = Utils.translate('Videos');
} else if (fileType === ("documents")) {
fileContent = documents;
documentLength = documents ? documents.length : 0;
subhead = Utils.translate('Documents');
} else if (fileType === ("images")) {
fileContent = images;
documentLength = images ? images.length : 0;
subhead = Utils.translate('Images');
}
self.fileContent = fileContent;
self.documentLength = documentLength;
self.subhead = subhead;
self.isLoading = false;
self.render();
});
},
childViews: {
'GlobalViews.Pagination': function () {
var self = this;
if (self.fileContent && self.documentLength > 0) {
return new GlobalViewsPaginationView(
_.extend(
{
totalPages: Math.ceil(self.documentLength / self.pageSize)
}
, SC.CONFIGURATION.defaultPaginationSettings
)
);
}
}
},
getContext: function getContext() {
//@class JJ.Catalog.Catalog.View.Context
var details = [];
var fileContent = this.fileContent;
var documentLength = this.documentLength;
var baseUrl = SC.ENVIRONMENT.checkoutUrl;
var subhead = this.subhead;
if (documentLength != 0) {
var startIndex = (this.currentPage - 1) * this.pageSize;
var endIndex = Math.min(startIndex + this.pageSize, documentLength);
for (var i = startIndex; i < endIndex; i++) {
details.push({
name: fileContent[i].name,
url: baseUrl + fileContent[i].url
});
}
}
var noFileMessage = "There is no " + this.fileType + " for you!";
return {
details: details,
subhead: subhead,
documentSize: documentLength === 0,
noFileMessage: noFileMessage,
currentPage: this.currentPage,
isLoading: this.isLoading,
showPagination: documentLength > this.pageSize
}
}
});
});
Suitescript files
Entry point:
define("Library.ServiceController", ["ServiceController","JJ.Library.Library"], function(
ServiceController, Catalog
) {
"use strict";
return ServiceController.extend({
name: "Library.ServiceController",
// The values in this object are the validation needed for the current service.
options: {
common: {}
},
get: function get() {
try {
var result = Catalog.getDocuments();
return result;
} catch (e) {
console.error('errorOrderApproval ServiceController', e);
}
}
});
});
____________________________________________________________
model file:
// JJ.Catalog.Catalog.js
// Load all your starter dependencies in backend for your extension here
// ----------------
define('JJ.Library.Library', [
'Library.ServiceController',
'SC.Model',
'SC.Models.Init',
'underscore'
], function (
LibraryServiceController,
SCModel,
ModelsInit, _
) {
'use strict';
return SCModel.extend({
getDocuments: function () {
try {
var fileType = [],
url = [],
documentSize = [],
folder = [],
name = [];
var currentCustomer = nlapiLoadRecord('customer', nlapiGetUser());
var folderid = currentCustomer.getFieldValue('custentity_jj_catalog_folder_id');
if (!!folderid) {
var fileSearch = nlapiSearchRecord("file", null,
[
["filetype","anyof","JPGIMAGE","SVG","MPEGMOVIE","PDF","EXCEL","PJPGIMAGE","PNGIMAGE","WORD"],
"AND",
["folder", "anyof", folderid]
],
[
new nlobjSearchColumn("name").setSort(false),
new nlobjSearchColumn("folder"),
new nlobjSearchColumn("documentsize"),
new nlobjSearchColumn("url"),
new nlobjSearchColumn("filetype")
]
);
if (fileSearch) {
var length = fileSearch.length;
for (var i = 0; i < fileSearch.length; i++) {
name.push(fileSearch[i].getValue('name'));
folder.push(fileSearch[i].getValue('folder'));
documentSize.push(fileSearch[i].getValue('documentsize'));
url.push(fileSearch[i].getValue('url'));
fileType.push(fileSearch[i].getValue('filetype'));
}
var result = {
Library: length,
name: name,
folder: folder,
documentSize: documentSize,
url: url,
fileType: fileType,
success: true
};
var results = JSON.stringify(result);
return results;
} else {
return {
Library: null,
length: 0
};
}
} else {
return {
Library: null,
length: 0
};
}
} catch (e) {
console.error('error at model', e);
}
}
})
});