- Created a custom entity field named “custentity_jj_catalog_folder_id ” on the customer record to save the folder id containing the pdf files that needed to be displayed on the catalog page.
- Create an extension named ” Catalog ” with version 1.0.0 to show the customer specific catalog page.
- The extension contain view file , router file , model file and suitescript files
- Created a new tab named catalog in the Myaccount tree that eill navigate to the catalog
- Created a router page for the catalog , passed the controm to backend from the router page to obtain the files
- The resultobtained is then passed to the view file , where we arranged the result details as per our requirement
- The result is then passed to the tpl file named jj_catalog_catalog
- The responsive styles are added on the scss file
- Obtain the value of the folder id saved on the custom field by using the profile model on the backend
- Store it on a variable for the further use
- Create a file search to obtain all the pdf files stored on the folder.
- Pass the data obtained from the search to front end to show it on the router page
define(
'JJ.Catalog.Catalog', [
'JJ.Catalog.Catalog.Router'
],
function (
CatalogRouter
) {
'use strict';
return {
mountToApp: function mountToApp(container) {
var layout = container.getComponent('Layout');
if (layout) {
var myAccountMenu = container.getComponent("MyAccountMenu");
var preordersMenuGroup = {
id: "Catalog",
name: "Catalog",
index: 7,
url: "Catalog",
permissionoperator: "OR",
permission: [
{
group: "transactions",
id: "tranSalesOrd",
level: "1"
},
{
group: "transactions",
id: "tranEstimate",
level: "1"
}
]
}
}
myAccountMenu.addGroup(preordersMenuGroup);
return new CatalogRouter(container);
}
};
});
define(
'JJ.Catalog.Catalog.Router', [
'JJ.Catalog.Catalog.View', 'Backbone', 'JJ.Catalog.Catalog.Model'
],
function (
CatalogView, Backbone, Model
) {
'use strict';
var length;
return Backbone.Router.extend({
routes: {
'Catalog': 'Catalog',
}
,
initialize: function (Application) {
this.application = Application;
},
//fetch the list of documents from NetSuite.
Catalog: function () {
var self = null;
try {
self = this;
var model = new Model();
var promise = jQuery.Deferred();
model.fetch().done(function (result) {
length = result.length
promise.resolve();
});
promise.done(function () {
var view = new CatalogView({ application: self.application, model: model, length: length });
view.showContent();
});
} catch (e) {
console.log('error in router', e);
}
}
});
});
// @module JJ.Catalog.Catalog
define('JJ.Catalog.Catalog.View', [
'jj_catalog_catalog.tpl',
'Backbone',
'Utils'
], function (
jj_catalog_catalog_tpl,
Backbone,
Utils
) {
'use strict';
// @class JJ.Catalog.Catalog.View @extends Backbone.View
return Backbone.View.extend({
template: jj_catalog_catalog_tpl,
title: Utils.translate('Catalog'),
page_header: Utils.translate('Catalog')
,
initialize: function (options) {
this.data = options.model.attributes;
this.length = options.length;
}
,
events: {}
,
bindings: {}
,
childViews: {
}
//@method getContext @return JJ.Catalog.Catalog.View.Context
,
getContext: function getContext() {
//@class JJ.Catalog.Catalog.View.Context
var details = [];
var zeroDoc = this.data.Document;
var documentSize = false;
if (zeroDoc == null) {
documentSize = true;
}
var url = SC.ENVIRONMENT.embEndpointUrl.url;
var baseUrl = url.match(/^(https?:\/\/[^/]+\.com)/);
baseUrl=baseUrl[1];
//@class jj.Downloadpage.EN.View.Context
for (var i = 0; i < this.data.Document; i++) {
details[i] = {
name: this.data.name[i],
url: baseUrl + this.data.url[i]
}
}
return {
details: details,
documentSize: documentSize
}
}
});
});
define("Catalog.ServiceController", ["ServiceController","JJ.Catalog.Catalog"], function(
ServiceController, Catalog
) {
"use strict";
return ServiceController.extend({
name: "Catalog.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);
}
},
post: function post() {
// not implemented
},
put: function put() {
// not implemented
},
delete: function() {
// not implemented
}
});
});
// JJ.Catalog.Catalog.js
// Load all your starter dependencies in backend for your extension here
// ----------------
define('JJ.Catalog.Catalog', [
'Catalog.ServiceController',
'SC.Model',
'SC.Models.Init',
'underscore'
], function (
CatalogServiceController,
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", "PDF"],
"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 = {
Document: length,
name: name,
folder: folder,
documentSize: documentSize,
url: url,
fileType: fileType,
success: true
};
var results = JSON.stringify(result);
return results;
} else {
return {
Document: null,
length: 0
};
}
} else {
return {
Document: null,
length: 0
};
}
} catch (e) {
console.error('error at model', e);
}
}
})
});