Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. ### Dev:
  2. - "npm run watch" for local watch and dev bundle generation
  3.  
  4. - "npm run build" for final output
  5.  
  6. ______________________________________
  7.  
  8. ### Lib user
  9.  
  10.  
  11. ##### *Scripts loading inside your template html*
  12. ```html
  13. <!-- Your own javascript for UI handling / framework , your scripts, etc. -->
  14. <script type="text/javascript" src="scripts/main.js"></script>
  15.  
  16. <!-- Mandatory -->
  17. <script src="../dist/dev/ve.core.js"></script>
  18.  
  19. <!-- Add-on API's . Only load if you require them-->
  20. <script src="../dist/dev/ve.public_templates.js"></script>
  21. <script src="../dist/dev/ve.bisnode.js"></script>
  22. <script src="../dist/dev/ve.id_rights.js"></script>
  23. <script src="../dist/dev/ve.bisnode.js"></script>
  24. ```
  25.  
  26. The library exposes the following objects into the global context:
  27.  
  28. ```javascript
  29. Object {} VeLib.core
  30. Object {} VeLib.public_templates // if appropriate script is imported only
  31. Object {} VeLib.id_rights // if appropriate script is imported only
  32. ```
  33. ___
  34.  
  35. **Available actions on each object and their results**
  36.  
  37. Notes:
  38. * A promise with () means an empty returned object in the success callback*
  39. * All operations from add-on must be acted on only after loading the core, like in the examples
  40.  
  41. ###### CORE
  42. ```javascript
  43. VeLib.core = {
  44. init( [ String domain ] ){ return Promise() }
  45. // Sets up the library data and authentication using the url params and must be called immediately
  46. // Optional domain if the library with the template is hosted at your specific url
  47. // Usage: VeLib.core.init("mydomain").then(() => { *your code here* })
  48.  
  49. getTemplateData(){ return Promise(Object data) }
  50. // Useful if some data has already been submitted, you could load this data
  51. // in your variables for initialization purposes
  52.  
  53. putTemplateData(Object userData){ return Promise() }
  54. // input is an object with all the required userData property-value fields present
  55.  
  56.  
  57. }
  58.  
  59. ```
  60.  
  61. ##### Public template
  62.  
  63. VeLib.public_templates methods:
  64.  
  65. ```javascript
  66. init() { return Promise(Object statusInfo)
  67. // Object statusInfo = { needsContextCreation: false || true }
  68. // Will return true if no data already present in the template
  69. // Future use: If the iframe has been opened for the first time ( not forwarded)
  70.  
  71. getTemplateInterface() { return Promise(Array [Object templateObject] ) }
  72. // a templateObject array is returned, methods on these objects are explained a further bit down.
  73. // commonly you would use var template = returnedTemplateObjects[0]
  74.  
  75. submitFormData(){ return Promise() }
  76. // This should be done as late as possible, to avoid unnecessary creation of envelopes and other objects. This submits the data put into all templateObject interfaces. No remote action is done on them until this 'global' function is called
  77.  
  78. getAvailableSigningMethods(){ return Promise( Array [String signingMethod] ) }
  79. // an example would be ["bankid-se", "email"]
  80.  
  81. publish(){ return Promise(String urlForSigning) }
  82. // must be called to finalize process if needsContextCreation is false.
  83. // if instead you want to forward, you will need to issue a forward action instead
  84. // For immediate signing, the user would have to be redirected using the urlForSigning provided
  85.  
  86. addRecipient(Object RecipientObject){ return Promise() }
  87. // Remotely adds a recipient to the envelope
  88. // RecipientObject must be of the form:
  89. // {
  90. // email: String - Your email or somebody else's for forward
  91. // familyName: String
  92. // givenName: String
  93. // signingMethod: String - One of the available signing methods returned by using getAvailableSigningMethods
  94. // }
  95.  
  96. ```
  97.  
  98. ##### The templateObject methods
  99.  
  100. ```javascript
  101. setData() { return void }
  102. // A sync/ non-remote action for bootstraping the template data for global submission (submitFormData)
  103.  
  104. getData() { return Object userDataThatHasBeenAlreadySet}
  105. // useful if you want to check what user data is going to be submitted for a specific template at a specific moment
  106.  
  107. getInfo() { return Object descriptorInformation }
  108. // If you want to get more details about the template, from the envelope definition. No need to call this unless you are explicitly looking for something
  109. ```
  110.  
  111. ##### ID rights API
  112.  
  113. ```javascript
  114.  
  115. getCompanyAuthorities(String organisationNumber) {
  116. return Array(Object authorityObject])
  117. }
  118. ```
  119. ___
  120.  
  121. #### Practical example of method chaining and operations for a case of public template use
  122.  
  123. ```javascript
  124.  
  125. // Call this chunk on initial page load
  126.  
  127. var onYourPageLoadCallback = () => {
  128. VeLib.core.init().then() => {
  129. return VeLib.public_templates.init()
  130. })
  131. .then((statusInfo) => {
  132. myScope.iShouldDisplaySomeForwardingMessage = !statusInfo.needsContextCreation
  133. return VeLib.public_templates.getTemplateInterface()
  134. })
  135. .then((templateObjects) => {
  136. myScope.template = templateObjects[0]
  137. // i save this into an outside context so i can run methods on it when the user submits
  138. })
  139.  
  140. }
  141. // Call this chunk after the user has filled in all data, including the recipient form with all the necessary data required from a recipient,
  142.  
  143. var onYourSubmitAction = () => {
  144. // Call this code as a handler the final "submit" or "send button" you provide
  145. myScope.template.setData(myScope.myGatheredData)
  146. VeLib.public_templates.submitFormData()
  147. .then(() => { return VeLib.public_templates.getAvailableSigningMethods() })
  148. .then((availableMethods) => {
  149. return VeLib.public_templates.addRecipient({
  150. email: myScope.recipient.email,
  151. familyName: myScope.recipient.familyName,
  152. givenName: myScope.recipient.givenName
  153. signingMethod: availableMethods[0]
  154. })
  155. })
  156. .then(() => { VeLib.public_templates.publish()})
  157. .then((redirectUrl) => myInterface.displayRedirectingInSecondsPage(redirectUrl))
  158. }
  159. //Feel free to break the flow at anytime and do additional operations in/on your UI if that is needed, but make sure to maintain the order of operations.
  160. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement