Нет описания

teste.js 4.1KB

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