|
@@ -0,0 +1,162 @@
|
|
1
|
+var mktSuite = {}
|
|
2
|
+mktSuite.list = []
|
|
3
|
+
|
|
4
|
+var urlAPIMkt = "https://mkt.sprinta.com.br:8082"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+mktSuite.call = function(method, uri, data, success, process) {
|
|
8
|
+
|
|
9
|
+ $.ajax({
|
|
10
|
+ xhr: function() {
|
|
11
|
+ var xhr = new window.XMLHttpRequest();
|
|
12
|
+
|
|
13
|
+ xhr.upload.addEventListener("progress", function(evt) {
|
|
14
|
+ if (evt.lengthComputable) {
|
|
15
|
+ var percentComplete = evt.loaded / evt.total;
|
|
16
|
+ percentComplete = parseInt(percentComplete * 100);
|
|
17
|
+ process(percentComplete)
|
|
18
|
+ }
|
|
19
|
+ }, false);
|
|
20
|
+
|
|
21
|
+ return xhr;
|
|
22
|
+ },
|
|
23
|
+ url: urlAPIMkt + uri,
|
|
24
|
+ data: data,
|
|
25
|
+ type: method,
|
|
26
|
+ contentType: false,
|
|
27
|
+ processData: false,
|
|
28
|
+ crossDomain: true,
|
|
29
|
+ beforeSend: function(xhr){xhr.setRequestHeader('Auth', mktSuite.getAuthorization())},
|
|
30
|
+ success: function(data) {
|
|
31
|
+ success(data)
|
|
32
|
+ }
|
|
33
|
+ });
|
|
34
|
+}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+mktSuite.calltest = function(method, uri, data, success, process) {
|
|
38
|
+
|
|
39
|
+ $.ajax({
|
|
40
|
+ xhr: function() {
|
|
41
|
+ var xhr = new window.XMLHttpRequest();
|
|
42
|
+
|
|
43
|
+ xhr.upload.addEventListener("progress", function(evt) {
|
|
44
|
+ if (evt.lengthComputable) {
|
|
45
|
+ var percentComplete = evt.loaded / evt.total;
|
|
46
|
+ percentComplete = parseInt(percentComplete * 100);
|
|
47
|
+ process(percentComplete)
|
|
48
|
+ }
|
|
49
|
+ }, false);
|
|
50
|
+
|
|
51
|
+ return xhr;
|
|
52
|
+ },
|
|
53
|
+ url: "http://localhost:8081" + uri,
|
|
54
|
+ data: data,
|
|
55
|
+ type: method,
|
|
56
|
+ contentType: false,
|
|
57
|
+ processData: false,
|
|
58
|
+ crossDomain: true,
|
|
59
|
+ beforeSend: function(xhr){xhr.setRequestHeader('Auth', mktSuite.getAuthorization())},
|
|
60
|
+ success: function(data) {
|
|
61
|
+ success(data)
|
|
62
|
+ }
|
|
63
|
+ });
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+mktSuite.getAuthorization = function() {
|
|
67
|
+ var cname = 'authorization'
|
|
68
|
+ var name = cname + "=";
|
|
69
|
+ var decodedCookie = decodeURIComponent(document.cookie);
|
|
70
|
+ var ca = decodedCookie.split(';');
|
|
71
|
+ for(var i = 0; i <ca.length; i++) {
|
|
72
|
+ var c = ca[i];
|
|
73
|
+ while (c.charAt(0) == ' ') {
|
|
74
|
+ c = c.substring(1);
|
|
75
|
+ }
|
|
76
|
+ if (c.indexOf(name) == 0) {
|
|
77
|
+ return c.substring(name.length, c.length);
|
|
78
|
+ }
|
|
79
|
+ }
|
|
80
|
+ return "";
|
|
81
|
+}
|
|
82
|
+
|
|
83
|
+mktSuite.load = function() {
|
|
84
|
+ mktSuite.call("GET", "/contactlist/r", "", function(resp) {
|
|
85
|
+ mktSuite.list = resp.result
|
|
86
|
+ mktSuite.renderList()
|
|
87
|
+ })
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+mktSuite.goToSave = function() {
|
|
91
|
+ mktSuite.boxCreateNew()
|
|
92
|
+
|
|
93
|
+ scroll('mktSuite-save')
|
|
94
|
+}
|
|
95
|
+
|
|
96
|
+mktSuite.fileChoosen = function(e) {
|
|
97
|
+ $('#fileNameDescription').html(
|
|
98
|
+ '<b>' + e.files[0].name + '</b><br/>' +
|
|
99
|
+ 'Tipo: ' + e.files[0].type
|
|
100
|
+ )
|
|
101
|
+}
|
|
102
|
+
|
|
103
|
+mktSuite.boxCreateNew = function() {
|
|
104
|
+ if(mktSuite.list.length === 0) {
|
|
105
|
+ alert("Você não tem mktSuite cadastradas")
|
|
106
|
+ return
|
|
107
|
+ }
|
|
108
|
+ tpl = tmpl('form-save-item', {mktSuite: mktSuite.list})
|
|
109
|
+ $('#mktSuite-save').html(tpl)
|
|
110
|
+}
|
|
111
|
+
|
|
112
|
+mktSuite.renderList = function() {
|
|
113
|
+ tpl = tmpl('mktSuite-items', {mktSuite: mktSuite.list})
|
|
114
|
+ $('#mktSuite-list').html(tpl)
|
|
115
|
+}
|
|
116
|
+
|
|
117
|
+mktSuite.uploadFile = function(evt) {
|
|
118
|
+ evt.preventDefault()
|
|
119
|
+ evt.stopPropagation()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+ if(validation.form(evt)) {
|
|
123
|
+ validation.clearAllErrors()
|
|
124
|
+ form.attr('data-status', 'loading')
|
|
125
|
+
|
|
126
|
+ formData = new FormData( form[0] )
|
|
127
|
+
|
|
128
|
+ var listid = form[0].contactListId.value
|
|
129
|
+
|
|
130
|
+ var item = mktSuite.list.find(function(item) {
|
|
131
|
+ return item.id == listid
|
|
132
|
+ })
|
|
133
|
+
|
|
134
|
+ var inx = mktSuite.list.indexOf(item)
|
|
135
|
+
|
|
136
|
+ mktSuite.call("POST", "/upload/r", formData, function(resp) {
|
|
137
|
+
|
|
138
|
+ form.attr('data-status', 'done')
|
|
139
|
+ if(resp.errors) {
|
|
140
|
+ alert(resp.errors[0].message)
|
|
141
|
+ } else {
|
|
142
|
+ mktSuite.list[inx].pendingFiles = mktSuite.list[inx].pendingFiles + 1
|
|
143
|
+ mktSuite.renderList()
|
|
144
|
+
|
|
145
|
+ alert("Importação efetuada e processando")
|
|
146
|
+ mktSuite.boxCreateNew()
|
|
147
|
+ }
|
|
148
|
+ },
|
|
149
|
+ function(progress) {
|
|
150
|
+ $('.btn-submit-progress-bar').css('width', progress+'%');
|
|
151
|
+ })
|
|
152
|
+ }
|
|
153
|
+}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+window.onload = function() {
|
|
157
|
+ mktSuite.load()
|
|
158
|
+}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+Collapse
|