PageSourceSearch

https://myportal.smartstartinc.com/js/ViewModels/Account/Documents…6EGVhwYhpCjq6afz_wTnChTjmoI_ejWpcvugJ2bHe3w

js smartstartinc.com collected 2026-10-01 12:36:00 UTC 7,165 bytes, 201 lines download raw bytes

1function DocumentsVm(container) {
2    var self = this;    
3	self.showAddDocSection = ko.observable(false);
4	self.showAddDocButton = ko.observable(true);
5	self.showSwitchAccountError = ko.observable(false);
6	self.accountId = ko.observable("");
7	self.isFirst = ko.observable(true);
8	self.description = ko.observable("");
9	self.docType = ko.observable("");
10	self.docList = ko.observableArray();
11    self.characterCount = ko.observable("200");
12    self.container = '#' + container;
13	self.count = ko.computed(function () {
14		var countNum = self.description().length;
15		return countNum + " / " + self.characterCount();;
16	});
17
18	ko.bindingHandlers.limitCharacters = {
19		update: function (element, valueAccessor, allBindingsAccessor, self) {
20			element.value = element.value.substr(0, valueAccessor());
21			allBindingsAccessor().value(element.value.substr(0, valueAccessor()));
22		}
23	};
24
25    self.addDocClicked = function () {
26        self.showAddDocSection(true);
27        self.showAddDocButton(false);        
28        self.description('');
29        self.docList([]);
30        self.docType('');
31    };
32
33    self.addContentClicked = function () {
34        $('#Content').click();
35    };
36
37    self.cancelDocClicked = function () {
38        self.showAddDocSection(false);
39        self.showAddDocButton(true);
40    };
41
42	self.fileInputClicked = function () {
43		$('#Content').click();
44	}
45	self.docs = ko.computed(function () {
46		if (self.docList().length > 0) {
47			return self.docList().join();
48        }
49		else {
50			return '';
51        }
52	})
53
54    self.loadDocuments = function (highlight) {
55        if (self.accountId()) {
56            var url = window.location.origin + "/Account/SwitchAccountsForDocuments?accountId=" + self.accountId();
57            if (highlight === true) {
58                url += "&highlight=" + highlight;
59            }
60            var options = {};
61            options.url = url;
62            options.type = "POST";
63            options.dataType = "html";
64            options.contentType = "application/json";
65            options.success = function (result) {
66                self.showSwitchAccountError(false);
67                var div = document.getElementById("documentPartial");
68                if (div) {
69                    ko.cleanNode(div);
70                    $(div).html(result);
71                    ko.applyBindings(self, div);
72                }
73                self.setupFileSelect();
74                self.cancelDocClicked();
75            };
76            options.error = function (err) {
77                self.showSwitchAccountError(true);
78                self.addDocClicked();
79            };
80            options.spinner = true;
81            options.spinnerSelector = self.container || "#documentPartial";
82            ajaxHelper(options);
83        }
84    }
85
86	self.accountId.subscribe(function (newValue) {
87		if (!self.isFirst()) {
88            self.loadDocuments();
89		}
90		else {
91			self.isFirst(false);
92		}
93	});
94
95    self.setupFileSelect = function () {
96
97        $(document).on("change", "#Content", function () {
98            var files = $(this)[0].files;
99            self.docList([]);
100            for (var i = 0; i < files.length; i++) {
101                var file = files[i];
102                if (!(file.type.indexOf('image') > -1 || file.type.indexOf('pdf') > -1)) {
103                    VmStore.ShowErrorModal(localizationHelper.error.fileNotSupported + '<br />' + file.name);
104                    $(this).val(null);
105                    return false;
106                }
107                if (file.size > maxDocumentFileSize) {
108                    VmStore.ShowErrorModal(localizationHelper.error.fileTooLarge + '<br />' + file.name);
109                    $(this).val(null);
110                    return false;
111                }               
112                self.docList.push(file.name);
113            }
114        });
115    };
116
117    self.submitEnabled = ko.computed(function () {
118        return self.docs() != '' && self.description() != '';
119    });
120
121    self.submitDocumentFormAsync = function () {        
122        var fd = new FormData(document.getElementById("account-document-form"));        
123        fd.append('Content', document.getElementById("Content").files);
124        fd.append('Description', self.description());
125        fd.append('DocumentType', self.docType());
126
127        $.ajax({
128            url: $('#account-document-form').attr('action'),
129            data: fd,            
130            type: 'POST',
131            processData: false,
132            contentType: false,
133            dataType:"json",
134            //Compatability with 1.5.1 
135            beforeSend: function (x) {
136                if (x && x.overrideMimeType) {
137                    x.overrideMimeType("multipart/form-data");
138                }
139                AddSpinner('body');
140                ConfirmPageLeaveOrReload();
141            },
142            xhr: function () {
143                var xhr = new window.XMLHttpRequest();
144
145                xhr.upload.addEventListener("progress", function (evt) {
146                    if (evt.lengthComputable) {
147                        var percentComplete = evt.loaded / evt.total;
148                        percentComplete = parseInt(percentComplete * 100);
149                        $('#spinner-upload-progress').text(percentComplete + '%');
150                    }
151                }, false);
152
153                return xhr;
154            },
155            success: function (data) {
156                if (data === true) {
157                    ConfirmPageLeaveOrReload(false);
158                    self.loadDocuments(true);
159                    self.cancelDocClicked();
160                }
161            },
162            error: function (err) {
163                VmStore.ShowErrorModal(err.responseText || localizationHelper.error.genericError);
164            },
165            complete: function () {                
166                RemoveSpinner('body');
167                ConfirmPageLeaveOrReload(false);
168            }
169        });        
170    };
171
172    self.downloadDocument = function (documentId, fileName) {
173        AddSpinner('#docsViewPartial');
174
175        fetch(window.location.origin + "/Account/GetDocumentById?documentId=" + documentId)
176            .then(function (resp) {
177                if (resp.ok) {
178                    return resp.blob();
179                }
180                else {
181                    throw new Error();
182                }
183            })
184            .then(function (blob) {
185                const url = window.URL.createObjectURL(blob);
186                const a = document.createElement('a');
187                a.style.display = 'none';
188                a.href = url;
189                a.download = fileName;
190                document.body.appendChild(a);
191                a.click();
192                window.URL.revokeObjectURL(url);
193                RemoveSpinner('#docsViewPartial');
194            })
195            .catch(function () {
196                RemoveSpinner('#docsViewPartial');
197                VmStore.ShowErrorModal(localizationHelper.error.genericError);
198            });
199    }
200}
201

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.