Brak opisu

functions.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var mktSuite = (function(){
  2. var actions = {}
  3. var urlAPIMkt = "http://142.93.247.97:8081"
  4. var auth = "eyJ1dWlkIjoiNjM2MzJkY2YtNWQzMi00NTJhLTkzMjItYjQ5NGMwNmMwNmQ5NWI4M2Y3NjAyZTZkZiIsImF1dGgiOiI5M2YzZGQzZjBkZmE4NzY5ZjMyNzMxYjFhZmVkMmY5NTZmOWM3Yzg0YzhiODQzYzY5YjE4M2ViZGE2NGQxN2NlIn0="
  5. var auth2 = "eyJ1dWlkIjoiOWJhZDg3ZDEtMDY3Ny00ZGMxLTllMDAtMDA1ZTZlYTkzYTBiNWI4NTdlNjU1YjE0NyIsImF1dGgiOiJmZDhmODU3NzFhYWRmZmFjZmQ4ZjdiMDI3NWY3YzdjY2RjNDg3MjhiOTM4NGYyNGM1OGViMzE3YzdlM2QwYmNiIn0="
  6. var account = null
  7. function call(method, uri, data, success, process) {
  8. $.ajax({
  9. xhr: function() {
  10. var xhr = new window.XMLHttpRequest();
  11. if(process) {
  12. xhr.upload.addEventListener("progress", function(evt) {
  13. if (evt.lengthComputable) {
  14. var percentComplete = evt.loaded / evt.total;
  15. percentComplete = parseInt(percentComplete * 100);
  16. process(percentComplete)
  17. }
  18. }, false);
  19. }
  20. return xhr;
  21. },
  22. url: urlAPIMkt + uri,
  23. data: data,
  24. type: method,
  25. // contentType: false,
  26. // processData: false,
  27. crossDomain: true,
  28. beforeSend: function(xhr){
  29. xhr.setRequestHeader('Auth', auth)
  30. xhr.setRequestHeader('account', account)
  31. },
  32. success: function(data) {
  33. success(data)
  34. }
  35. });
  36. }
  37. var accounts = null
  38. actions.authentication = function(success) {
  39. call('GET', '/account', null, function (data) {
  40. accounts = data.accounts;
  41. if (accounts != null) {
  42. actions.validation(accounts[0], success)
  43. } else {
  44. alert("Não possui contas")
  45. }
  46. })
  47. }
  48. actions.validation = function (data, success) {
  49. var token = data.token
  50. call('POST', '/account/auth', { account: token }, function (data) {
  51. account = data.token
  52. success()
  53. console.log(account);
  54. })
  55. }
  56. actions.contactList = function () {
  57. call('GET', '/contactlist', null, function (data) {
  58. console.log(data);
  59. })
  60. }
  61. return actions
  62. })();
  63. mktSuite.authentication(function() {
  64. mktSuite.contactList()
  65. })