123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- var mktSuite = {}
- mktSuite.list = []
- var urlAPIMkt = "https://mkt.sprinta.com.br:8082"
- mktSuite.call = function(method, uri, data, success, process) {
- $.ajax({
- xhr: function() {
- var xhr = new window.XMLHttpRequest();
- xhr.upload.addEventListener("progress", function(evt) {
- if (evt.lengthComputable) {
- var percentComplete = evt.loaded / evt.total;
- percentComplete = parseInt(percentComplete * 100);
- process(percentComplete)
- }
- }, false);
- return xhr;
- },
- url: urlAPIMkt + uri,
- data: data,
- type: method,
- contentType: false,
- processData: false,
- crossDomain: true,
- beforeSend: function(xhr){xhr.setRequestHeader('Auth', mktSuite.getAuthorization())},
- success: function(data) {
- success(data)
- }
- });
- }
- mktSuite.calltest = function(method, uri, data, success, process) {
- $.ajax({
- xhr: function() {
- var xhr = new window.XMLHttpRequest();
- xhr.upload.addEventListener("progress", function(evt) {
- if (evt.lengthComputable) {
- var percentComplete = evt.loaded / evt.total;
- percentComplete = parseInt(percentComplete * 100);
- process(percentComplete)
- }
- }, false);
- return xhr;
- },
- url: "http://localhost:8081" + uri,
- data: data,
- type: method,
- contentType: false,
- processData: false,
- crossDomain: true,
- beforeSend: function(xhr){xhr.setRequestHeader('Auth', mktSuite.getAuthorization())},
- success: function(data) {
- success(data)
- }
- });
- }
- mktSuite.getAuthorization = function() {
- var cname = 'authorization'
- var name = cname + "=";
- var decodedCookie = decodeURIComponent(document.cookie);
- var ca = decodedCookie.split(';');
- for(var i = 0; i <ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0) == ' ') {
- c = c.substring(1);
- }
- if (c.indexOf(name) == 0) {
- return c.substring(name.length, c.length);
- }
- }
- return "";
- }
- mktSuite.load = function() {
- mktSuite.call("GET", "/contactlist/r", "", function(resp) {
- mktSuite.list = resp.result
- mktSuite.renderList()
- })
- }
- mktSuite.goToSave = function() {
- mktSuite.boxCreateNew()
- scroll('mktSuite-save')
- }
- mktSuite.fileChoosen = function(e) {
- $('#fileNameDescription').html(
- '<b>' + e.files[0].name + '</b><br/>' +
- 'Tipo: ' + e.files[0].type
- )
- }
- mktSuite.boxCreateNew = function() {
- if(mktSuite.list.length === 0) {
- alert("Você não tem mktSuite cadastradas")
- return
- }
- tpl = tmpl('form-save-item', {mktSuite: mktSuite.list})
- $('#mktSuite-save').html(tpl)
- }
- mktSuite.renderList = function() {
- tpl = tmpl('mktSuite-items', {mktSuite: mktSuite.list})
- $('#mktSuite-list').html(tpl)
- }
- mktSuite.uploadFile = function(evt) {
- evt.preventDefault()
- evt.stopPropagation()
- if(validation.form(evt)) {
- validation.clearAllErrors()
- form.attr('data-status', 'loading')
- formData = new FormData( form[0] )
- var listid = form[0].contactListId.value
- var item = mktSuite.list.find(function(item) {
- return item.id == listid
- })
- var inx = mktSuite.list.indexOf(item)
- mktSuite.call("POST", "/upload/r", formData, function(resp) {
- form.attr('data-status', 'done')
- if(resp.errors) {
- alert(resp.errors[0].message)
- } else {
- mktSuite.list[inx].pendingFiles = mktSuite.list[inx].pendingFiles + 1
- mktSuite.renderList()
- alert("Importação efetuada e processando")
- mktSuite.boxCreateNew()
- }
- },
- function(progress) {
- $('.btn-submit-progress-bar').css('width', progress+'%');
- })
- }
- }
- window.onload = function() {
- mktSuite.load()
- }
- Collapse
|