Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ko.validation.init( { decorateInputElement: true, errorElementClass: 'has-error' } );
- var viewModel = function() {
- var self = this;
- this.authToken = ko.observable(false);
- this.user = ko.observable(false);
- this.fundName = ko.observable();
- this.fundId = ko.observable();
- self.fundCode = ko.observable(false);
- this.selectedPack = ko.observable(new packModel());
- this.selectedFund = ko.observable(false);
- this.fundList = ko.observableArray([]);
- this.searchActive = ko.observable(false);
- this.downloadActive = ko.observable(false);
- this.searchPerformed = ko.observable(false);
- this.isFundSelected = ko.observable(false);
- this.isGenerating = ko.observable(false);
- this.orderRequest = ko.observable();
- this.orderResponse = ko.observable();
- this.orderId = ko.observable();
- this.documentDate = ko.observable();
- this.documentPayload = ko.observableArray([]);
- this.documentPending = ko.observable(0);
- this.documentRequests = ko.observable(0);
- this.documentResults = ko.observable(0);
- this.documentSuccess = ko.observable(0);
- this.documentErrors = ko.observable(0);
- this.orderList = ko.observable(new completedOrderModel());
- this.orderListPending = ko.observable(true);
- this.documentPacks = ko.observableArray([]);
- var today = new Date().toISOString().substr(0, 10);
- this.documentPercentage = ko.computed(function() {
- return Math.ceil(percentage = self.documentResults() / self.documentRequests() * 100);
- });
- this.endpoint = ko.computed(function() {
- if (self.fundCode() === false) return false;
- else return '/api/docgen/fund/' + self.fundCode();
- });
- this.order = ko.computed(function() {
- return ko.observable({ order: self.orderId(), product: self.selectedPack.productId });
- });
- this.authDetails = ko.observable({
- password: 'Xj68B7dNGNDDGxg',
- username: 'springdoks_headless@heffron.com.au',
- client_id: '5_2vc4nignqc84cggcs0wc8kkk40oks8owcgk008okw0gs8480kw',
- client_secret: '3uceloicaiwwww0swc040kso4c8k8o84s0ocs0oc0wcs8s8o4s',
- grant_type: 'password'
- });
- var dateTime = new Date();
- dateTime = moment(dateTime).format("YYYY-MM-DD");
- console.log('new date ' + dateTime);
- this.initPacks = function() {
- self.documentPacks.push
- (
- new packModel('NAB - Fund Establishment Pack', '6', [
- new documentModel('NAB FSU Cover Letter', 'coverletter', 'NAB_FSU_ADMIN_Cover_Letter.docx', null, false, [], self),
- new documentModel('Financial Services Guide', 'fsg', 'FSG.docx', null, false, [
- new documentDataModel(this.documentDate() ? this.documentDate() : dateTime, 'productId', 6, null, null)
- ], self),
- new documentModel('Consent To Act', 'consenttoact', 'Consent_to_act.docx', 632, true, [], self),
- new documentModel('Trustee Declarations', 'trusteedeclaration', 'Trustee_Declaration.pdf', 634, true, [], self),
- new documentModel('Fund Establishment Minute', 'minute', 'FSU_Minute.docx', 564, true, [
- new documentDataModel('Does this minute require a meeting notice?', 'meetingNoticeRequired', false, [ { optionVar: 'Yes', valueVar: true }, { optionVar: 'No', valueVar: false } ], 'radio')
- ], self),
- new documentModel('Trust Deed', 'fsudeed', null, 631, true, [
- new documentDataModel(null, 'templateNameCorporate', 'FSU_Deed_Corporate.docx', null, null),
- new documentDataModel(null, 'templateNameIndividual', 'FSU_Deed_Individual.docx', null, null),
- new documentDataModel(null, 'deedVersion', '3.01', null, null),
- ], self),
- new documentModel('SMSF Rules version 3.01', 'static', 'SMSF_Rules_Version_3.01.pdf', null, null, null, self),
- new documentModel('Product Disclosure Statement', 'pds', 'PDS.docx', 108, true, [], self),
- new documentModel('Member Application Minute', 'minute', 'MemberApplication_Minute.docx', 568, true, [
- new documentDataModel(null, 'meetingNoticeRequired', false, null, null)
- ], self),
- new documentModel('Member Application', 'memberapplications', 'Member_Application.docx', 502, true, [], self),
- new documentModel('Service Agreement', 'serviceagreement', 'NAB_FSU_ServiceAgreement.docx', 100, [true], null, self),
- new documentModel('Minute Appointing Heffron as Administrator', 'minute', 'HeffronAppointmentLPOA_Minute.docx', 566, true, [
- new documentDataModel('Does this minute require a meeting notice?', 'meetingNoticeRequired', false, [ { optionVar: 'Yes', valueVar: true }, { optionVar: 'No', valueVar: false } ], 'radio')
- ], self),
- new documentModel('Limited Power of Attorney', 'lpoa', 'LPOA.docx', 262, [true], null, self),
- new documentModel('Nab 100 Point Identification Check', 'static', 'NAB_100point_Identification.PDF', null, null, null, self),
- new documentModel('Nab Withholding Tax Statement', 'static', 'NAB_Withholding_Tax_Statement.PDF', null, null, null, self)
- ],
- [
- { 'title': 'Cover Letter Address', 'text': 'IF DIRECT... Fund Contact Profile -> Legal Documents, IF REFERRED... Referrer Person -> Business Postal.' },
- { 'title': 'PDS & Direct Debit Request Address (and phone if PDS)', 'text': 'Fund Contact Profile -> Legal Documents.' },
- { 'title': 'For any member/trustee Addresses', 'text': 'Person\'s Residential Address.' },
- { 'title': 'Corporate Trustee Company', 'text': 'Registered Office Address' },
- { 'title': 'ATO Direct Debit Address', 'text': 'Heffron\'s Postal Address' }
- ], self)
- );
- self.documentPacks.push(
- new packModel('Corporate Trustee Establishment', '7', [
- new documentModel('Corporate Trustee Cover Letter', 'coverletter', null, null, false, [
- new documentDataModel('Is Heffron the registered address for this corporation?', 'templateName', null, [ { optionVar: 'Yes', valueVar: 'CORP_TRUSTEE_Heffron_RegAddr_Cover_Letter.docx' }, { optionVar: 'No', valueVar: 'CORP_TRUSTEE_Heffron_NOT_RegAddr_Cover_Letter.docx' } ], 'radio')
- ], self),
- ],
- [
- { 'title': 'Cover Letter Address', 'text': 'IF DIRECT... Fund Contact Profile -> Legal Documents, IF REFERRED... Referrer Person -> Business Postal' }
- ], self)
- );
- self.documentPacks.push(
- new packModel('NAB - Welcome Pack', '6', [
- new documentModel('Welcome Pack Cover Letter', 'coverletter', 'NAB_FSU_ADMIN_Cover_Letter.docx', null, false, [], self),
- new documentModel('Information regarding Death Benefits', 'static', 'Information_Concerning_Death_Benefits.pdf', null, null, null, self),
- new documentModel('Notice of Preferred Beneficiaries (for each member)', 'dbn', 'Notice_of_Preferred_Beneficiaries.docx', 302, [true], null, self),
- new documentModel('Investment Strategy Minute', 'minute', 'InvestmentStrategy_Minute.docx', 565, [true], null, self),
- new documentModel('Investment Strategy (blank)', 'investmentstrategy', 'InvestmentStrategy_Blank.docx', 105, [true], null, self),
- new documentModel('ATO Standard Choice Form)', 'standardchoice', 'Superannuation_standard_choice_form.pdf', 369, [true], null, self),
- new documentModel('Direct Debit Request)', 'directdebitrequest', 'Direct_Debit_Request', 261, [true], null, self),
- ],
- [
- { 'title': 'Cover Letter Address', 'text': 'IF DIRECT... Fund Contact Profile -> Legal Documents, IF REFERRED... Referrer Person -> Business Postal' }
- ], self)
- );
- }
- // This is how I do an AJAX POST against HELiX - to Authenticate
- $.post("/api/oauth/v2/token", self.authDetails(), function(data) {
- self.authToken(data);
- }).done( function() {
- $.ajax({
- url: "/api/helix/user/authenticated",
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + self.authToken().access_token
- },
- success: function(response) {
- // If the response comes back, add the JSON array to my fundList variable.
- if (response.data) {
- self.user(response.data);
- }
- }
- });
- }).done( function() {
- self.orderListPending(true);
- self.fetchOrders();
- });
- this.newOrder = function() {
- self.orderList([]);
- self.initPacks();
- }
- this.fetchFunds = function() {
- self.searchActive(true);
- self.fundList.removeAll();
- // This is how I do an AJAX GET against HELiX - to Search for Funds
- $.ajax({
- url: "/api/helix/fund/search?offset=0&limit=5&filters[name]=" + self.fundName(),
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + self.authToken().access_token
- },
- success: function(response) {
- self.searchPerformed(true);
- self.searchActive(false);
- // If the response comes back, add the JSON array to my fundList variable.
- if (response) {
- self.fundList(response.data);
- }
- }
- });
- }
- this.fetchOrders = function() {
- $.ajax({
- url: "/api/helix/order?filters&limit=20&order_by[createdDate]=DESC&serialize=fundOrders",
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + self.authToken().access_token
- },
- success: function(response) {
- // If the response comes back, add the JSON array to my fundList variable.
- if (response.data) {
- self.orderList(response.data);
- }
- },
- complete: function() {
- self.orderListPending(false);
- }
- });
- }
- this.selectFund = function(data) {
- self.orderResponse(false);
- self.selectedFund(data);
- self.fundList([]);
- self.fundName(data.name);
- self.fundId(data.id);
- self.fundCode(data.fundCode);
- self.createOrder(new orderModel(1, self.user().id));
- }
- this.createOrder = function (order) {
- self.orderRequest(order);
- self.orderRequest().addFund(self.fundId());
- $.ajax({
- url: "/api/helix/order",
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + self.authToken().access_token
- },
- type: 'POST',
- contentType: 'application/json',
- data: ko.toJSON(self.orderRequest()),
- success: function(response) {
- if (response.data) {
- self.orderResponse(response.data);
- self.orderId(self.orderResponse().id);
- }
- },
- async: false
- });
- };
- this.updateOrder = function () {
- $.ajax({
- url: "/api/helix/order/" + self.orderId() + "/product",
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + self.authToken().access_token
- },
- type: 'POST',
- contentType: 'application/json',
- data: ko.toJSON( { product: self.selectedPack().productId } ),
- async: false
- });
- };
- this.generateDocuments = function() {
- self.updateOrder();
- self.isGenerating(true);
- $.each(self.selectedPack().documents(), function(key, doc) {
- if (doc.generateDocument() === true) {
- self.documentPayload.push(doc);
- self.documentPending(self.documentPending() + 1);
- self.documentRequests(self.documentRequests() + 1);
- }
- });
- $.each(self.documentPayload(), function(key, doc) {
- if (doc.isGenerated() === false && doc.isError() === false) self.generateDocument(key, doc);
- });
- self.documentPacks.remove(self.selectedPack());
- }
- this.generateDocument = function(key, doc) {
- $.ajax({
- beforeSend: function(xhr) {
- doc.isGenerating(true);
- doc.isGenerated(false);
- xhr.setRequestHeader ("Authorization", "Basic " + btoa(self.authDetails().username + ":" + self.authDetails().password));
- },
- url: doc.url() + '&docNumber=' + (key + 1),
- type: 'GET',
- contentType: 'application/json',
- data: true,
- timeout: 300000,
- success: function(response) {
- doc.isGenerated(true);
- self.documentSuccess(self.documentSuccess() + 1);
- },
- error: function(response) {
- doc.isError(true);
- self.documentErrors(self.documentErrors() + 1);
- },
- complete: function(response) {
- doc.isGenerating(false);
- doc.documentResponse(response);
- self.documentResults(self.documentResults() + 1);
- self.documentPending(self.documentPending() - 1);
- },
- async: true
- });
- }
- this.addAnotherProduct = function() {
- self.selectedPack();
- self.documentResults(0);
- self.documentSuccess(0);
- self.documentErrors(0);
- self.documentPending(0);
- self.documentRequests(0);
- self.isGenerating(false);
- };
- this.completeOrder = function() {
- self.orderListPending(true);
- self.fetchOrders();
- self.fundName('');
- self.fundId('');
- self.selectedPack('');
- self.selectedFund(false);
- self.fundList([]);
- self.searchActive(false);
- self.searchPerformed(false);
- self.isFundSelected(false);
- self.isGenerating(false);
- self.orderRequest('');
- self.orderResponse('');
- self.documentDate('');
- self.documentPayload([]);
- self.documentResults(0);
- self.documentSuccess(0);
- self.documentErrors(0);
- self.documentPending(0);
- self.documentRequests(0);
- }
- };
- var orderModel = function(status, user, product) {
- self = this;
- this.status = ko.observable(status);
- this.user = ko.observable(user);
- this.product = ko.observable(product);
- this.funds = ko.observableArray([]);
- this.addFund = function(fundId) {
- self.funds().push( { fund: fundId } );
- }
- }
- var packModel = function(name, productId, documents, instructions, parent) {
- self = this;
- this.name = name;
- this.productId = productId;
- this.documents = ko.observableArray(documents);
- this.instructions = ko.observableArray(instructions);
- }
- var documentModel = function(name, endpoint, filename, docTypeId, barcode, data, parent) {
- self = this;
- this.name = ko.observable(name);
- this.endpointName = ko.observable(endpoint);
- this.templateName = ko.observable(filename);
- this.docTypeId = ko.observable(docTypeId);
- this.barcode = ko.observable(barcode);
- this.orderId = ko.observable(false);
- this.documentDate = ko.observable(false);
- this.generateDocument = ko.observable(true);
- this.documentResponse = ko.observable(false);
- this.isGenerating = ko.observable(false);
- this.isError = ko.observable(false);
- this.isGenerated = ko.observable(false);
- parent.orderId.subscribe(function(orderId) {
- this.orderId(orderId);
- }.bind(this));
- parent.documentDate.subscribe(function(documentDate) {
- this.documentDate(documentDate);
- }.bind(this));
- this.data = ko.observableArray(data);
- this.url = ko.computed(function() {
- if (parent.endpoint() === false || this.orderId === false) return false;
- else {
- // Our default baseline URL
- url = parent.endpoint() + '/' + this.endpointName() + '?orderId=' + this.orderId();
- // Our optional additional parameters
- if (this.templateName()) url = url + '&templateName=' + this.templateName();
- if (this.docTypeId()) url = url + '&docTypeId=' + this.docTypeId();
- if (this.barcode()) url = url + '&generateBarcode=true';
- if (this.documentDate() !== false) url = url + '&documentDate=' + this.documentDate();
- // Our dynamically generated optional parameters
- if (this.data() !== null) {
- for (var i = 0, len = this.data().length; i < len; i++) {
- url = url + '&' + this.data()[i].variable() + '=' + this.data()[i].value();
- }
- }
- return url;
- }
- }, self);
- }
- var documentDataModel = function(description, variable, value, options, type) {
- self = this;
- this.description = ko.observable(description);
- this.variable = ko.observable(variable);
- this.value = ko.observable(value);
- this.options = ko.observableArray(options);
- this.type = ko.observable(type);
- }
- var completedOrderModel = ko.mapping.fromJS(SPRiNGDOKS);
- // This is telling KnockoutJS to load & fire up our viewModel
- var SPRiNGDOKS = new viewModel();
- ko.applyBindings(SPRiNGDOKS);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement