text changes to registration mail content
[namibia] / public / templates / page / stockbulkimporter.js
1 var template_stockbulkimporter = function (static)
2 {
3     this.static = static;
4     this.elements = {
5         csvFile: new App.TemplateElement.FieldComponent('csvFile'),
6         importType: new App.TemplateElement.FieldComponent('importType')
7     };
8     this.ti = null;
9     this.init = function (ti) {
10         this.ti = ti;
11         App.DataStore.loadSelectListData('groups', true, 'Company', 'Group.SelectList');
12         App.API.getTask(
13             'StockBulkImporter', 'Stock', 'BulkImport.Upload',
14             null, {}, function () {}, _w.taskContractError
15         );
16
17         var importTypeData = [];
18         if(App.permissions.stockBulkImportDrive)
19         {
20             importTypeData.push({"value": "Drive", "label": "Drive"});
21         }
22         if(App.permissions.stockBulkImportPinnacle)
23         {
24             importTypeData.push({"value": "Pinnacle", "label": "Pinnacle"});
25         }
26
27         App.DataStore.setData('importType', importTypeData);
28
29         this.ti.hydrate({
30             'csvFile': {
31                 type: 'document_button',
32                 id: 'csvFile',
33                 title: 'TransUnion CSV file'
34             },
35             'importType': {
36                 type: 'select',
37                 id: 'importType',
38                 title: 'Import Type',
39                 dataStoreId: 'importType'
40             }
41         });
42
43     };
44     this.construct = function () {
45
46         $('#frmStockBulkUpload').validate({
47             rules: {
48                 csvFile: {required: true},
49                 importType: {required: true}
50             },
51             messages: {
52                 csvFile: {
53                     required: "CSV file required."
54                 },
55                 importType: {
56                     required: "This field required."
57                 }
58             },
59             submitHandler: function (form) {
60                 var data = {Upload: _t['stockbulkimporter'].harvest()};
61
62                 if ('' == data.Upload.csvFile)
63                 {
64                     alert('Please select a file to import.');
65                     return false;
66                 }
67
68                 App.API.execTask(
69                     'StockBulkImporter', data, {},
70                     function (response)
71                     {
72                         alert('Import Running in background!\n\nYou will be notified via email when the import is complete.\n\nPlease note that this page will return to stock grid when you click "OK."');
73                         //window.location.reload(false);
74                         window.location.hash = '/stock';
75                     },
76                     function (response)
77                     {
78                         alert(response.StatusReason);
79                     }
80                 );
81             }
82         });
83         $('#btnSubmitFile').prop('disabled', false);
84     };
85     this.destruct = function () {};
86 };