Skip to content

Commit 41fb4ef

Browse files
updated example
1 parent 85ce824 commit 41fb4ef

File tree

3 files changed

+51
-51
lines changed

3 files changed

+51
-51
lines changed

lib/eSignature/controllers/eg030ApplyBrandToTemplate.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
const path = require('path');
8-
const { applyBrandToTemplate, getBrandsAndTemplates } = require('../examples/applyBrandToTemplate');
8+
const { applyBrandToTemplate, getBrands } = require('../examples/applyBrandToTemplate');
99
const validator = require('validator');
1010
const dsConfig = require('../../../config/index.js').config;
1111

@@ -31,6 +31,18 @@ eg030ApplyBrandToTemplate.createController = async (req, res) => {
3131
res.redirect(mustAuthenticate);
3232
}
3333

34+
if (!req.session.templateId) {
35+
res.render('pages/examples/eg030ApplyBrandToTemplate', {
36+
eg: eg, csrfToken: req.csrfToken(),
37+
title: "Apply brand to template",
38+
templateOk: req.session.templateId,
39+
sourceFile: path.basename(__filename),
40+
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/' + path.basename(__filename),
41+
documentation: dsConfig.documentation + eg,
42+
showDoc: dsConfig.documentation
43+
});
44+
}
45+
3446
const { body } = req;
3547

3648
//Step 1. Obtain your OAuth token
@@ -39,7 +51,7 @@ eg030ApplyBrandToTemplate.createController = async (req, res) => {
3951
basePath: req.session.basePath,
4052
accountId: req.session.accountId, // Represents your {ACCOUNT_ID}
4153
brandId: validator.escape(body.brandId),
42-
templateId: validator.escape(body.templateId),
54+
templateId: req.session.templateId,
4355
status: req.status,
4456
templateRoles: [
4557
{
@@ -95,18 +107,18 @@ eg030ApplyBrandToTemplate.getController = async (req, res) => {
95107
basePath: req.session.basePath,
96108
accountId: req.session.accountId, // represents your {ACCOUNT_ID}
97109
};
98-
const results = await getBrandsAndTemplates(args);
110+
const brandsResponse = await getBrands(args);
99111

100112
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
101113
res.render('pages/examples/eg030ApplyBrandToTemplate', {
102114
eg: eg, csrfToken: req.csrfToken(),
103115
title: "Apply brand to template",
116+
templateOk: req.session.templateId,
104117
sourceFile: sourceFile,
105118
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
106119
documentation: dsConfig.documentation + eg,
107120
showDoc: dsConfig.documentation,
108-
brands: results.brandsResponse.brands || [],
109-
templates: results.templatesResponse.envelopeTemplates || []
121+
brands: brandsResponse.brands || []
110122
});
111123
} else {
112124
// Save the current operation so it will be resumed after authentication

lib/eSignature/examples/applyBrandToTemplate.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,15 @@ const applyBrandToTemplate = async (args) => {
3434
/**
3535
* Form page for this application
3636
*/
37-
const getBrandsAndTemplates = async (args) => {
37+
const getBrands = async (args) => {
3838
let dsApiClient = new docusign.ApiClient();
3939
dsApiClient.setBasePath(args.basePath);
4040
dsApiClient.addDefaultHeader("Authorization", "Bearer " + args.accessToken);
4141

42-
let templatesApi = new docusign.TemplatesApi(dsApiClient);
43-
templatesResponse = await templatesApi.listTemplates(args.accountId);
44-
4542
let brandApi = new docusign.AccountsApi(dsApiClient);
4643
brandsResponse = await brandApi.listBrands(args.accountId);
4744

48-
return {
49-
templatesResponse: templatesResponse,
50-
brandsResponse: brandsResponse,
51-
};
45+
return brandsResponse;
5246
};
5347

54-
module.exports = { applyBrandToTemplate, getBrandsAndTemplates };
48+
module.exports = { applyBrandToTemplate, getBrands };
Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<% include ../../partials/examplesHead %>
22

33
<h4>30. Applying a brand to a template</h4>
4-
<p>
5-
This code example demonstrates how to apply a brand to a
6-
</p>
4+
<% if (templateOk) { %>
5+
<p>This code example demonstrates how to apply a brand to a template</p>
6+
<p>The access-code to utilize the example provided is: <strong>NJ9@D1</strong></p>
7+
<% } %>
78

89
<% include ../../partials/docBody %>
910

@@ -12,67 +13,60 @@
1213
<a target='_blank' href="https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopes/create/">Envelopes::create</a>.
1314
</p>
1415

15-
<p>The access-code to utilize the example provided is: <strong>NJ9@D1</strong></p>
1616
<% include ../../partials/gitSource %>
1717

18-
<% if (brands.length !== 0 && templates.length !== 0) { %>
19-
<form class="eg" action="" method="post" data-busy="form">
20-
<div class="form-group">
18+
<% if (templateOk) { %>
19+
<% if (brands.length !== 0) { %>
20+
<form class="eg" action="" method="post" data-busy="form">
21+
<div class="form-group">
2122
<label for="signerEmail">Signer Email</label>
2223
<input type="email" class="form-control" id="signerEmail" name="signerEmail"
2324
aria-describedby="emailHelp" placeholder="pat@example.com" required
2425
value="<%= locals.dsConfig.signerEmail%>">
2526
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
26-
</div>
27-
<div class="form-group">
27+
</div>
28+
<div class="form-group">
2829
<label for="signerName">Signer Name</label>
2930
<input type="text" class="form-control" id="signerName" placeholder="Pat Johnson" name="signerName"
3031
value="<%= locals.dsConfig.signerName%>" required>
31-
</div>
32-
<div class="form-group">
32+
</div>
33+
<div class="form-group">
3334
<label for="ccEmail">CC Email</label>
3435
<input type="email" class="form-control" id="ccEmail" name="ccEmail"
3536
aria-describedby="emailHelp" placeholder="pat@example.com" required />
3637
<small id="emailHelp" class="form-text text-muted">The email and/or name for the cc recipient must be different from the signer.</small>
37-
</div>
38-
<div class="form-group">
38+
</div>
39+
<div class="form-group">
3940
<label for="ccName">CC Name</label>
4041
<input type="text" class="form-control" id="ccName" placeholder="Pat Johnson" name="ccName"
4142
required>
42-
</div>
43-
<div class="form-group">
44-
<label for="templateId">Envelope template</label>
45-
<select id="templateId" name="templateId" class="form-control">
46-
<% templates.forEach( template => { %>
47-
<option value="<%= template.templateId %>" selected> <%= template.name %> </option>
48-
<% }) %>
49-
</select>
50-
</div>
51-
<div class="form-group">
43+
</div>
44+
<div class="form-group">
5245
<label for="brandId">Brand</label>
5346
<select id="brandId" name="brandId" class="form-control">
5447
<% brands.forEach( brand => { %>
5548
<option value="<%= brand.brandId %>" selected> <%= brand.brandName %> </option>
5649
<% }) %>
5750
</select>
58-
</div>
59-
<input type="hidden" name="_csrf" value="<%- csrfToken %>">
60-
<button type="submit" class="btn btn-docu">Submit</button>
61-
</form>
62-
<% } else if(brands.length === 0) { %>
63-
<p>Problem: please first create the brand using <a href="eg028">example 28.</a> <br/>
64-
Thank you.</p>
51+
</div>
52+
<input type="hidden" name="_csrf" value="<%- csrfToken %>">
53+
<button type="submit" class="btn btn-docu">Submit</button>
54+
</form>
55+
<% } else { %>
56+
<p>Problem: please first create the brand using <a href="eg028">example 28.</a> <br/>
57+
Thank you.</p>
6558
66-
<form class="eg" action="eg028" method="get">
59+
<form class="eg" action="eg028" method="get">
6760
<button type="submit" class="btn btn-docu">Continue</button>
68-
</form>
69-
<% } else if(templates.length === 0) { %>
61+
</form>
62+
<% } %>
63+
<% } else { %>
7064
<p>Problem: please first create the template using <a href="eg008">example 8.</a> <br/>
7165
Thank you.</p>
72-
73-
<form class="eg" action="eg008" method="get">
74-
<button type="submit" class="btn btn-docu">Continue</button>
75-
</form>
66+
67+
<form class="eg" action="eg008" method="get">
68+
<button type="submit" class="btn btn-docu">Continue</button>
69+
</form>
7670
<% } %>
7771
7872
<% include ../../partials/examplesFoot %>

0 commit comments

Comments
 (0)