Guest User

Untitled

a guest
Dec 14th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. /*
  2. * COOKIE HELPERS
  3. */
  4. getCookie: function(c_name) {
  5. var i, x, y, ARRcookies = document.cookie.split(";");
  6.  
  7. for (i = 0; i < ARRcookies.length; i++) {
  8. x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
  9. y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
  10. x = x.replace(/^\s+|\s+$/g,"");
  11. if (x === c_name) {
  12. return unescape(y);
  13. };
  14. };
  15. },
  16.  
  17. setCookie: function(c_name, value) {
  18. var exdate = new Date();
  19. exdate.setHours(exdate.getHours() + 1);
  20. var c_value = escape(value) + "; expires=" + exdate.toUTCString();
  21. document.cookie=c_name + "=" + c_value;
  22. },
  23.  
  24.  
  25. /*
  26. * ERRORS and ALERT HANDLING
  27. */
  28.  
  29. // Default alert when there is a validation error
  30. displayValidationErrors: function (messages) {
  31. for (var key in messages) {
  32. if (messages.hasOwnProperty(key)) {
  33. this.addValidationError(key, messages[key]);
  34. }
  35. }
  36. this.showAlert('Uh oh...', 'Please fix validation errors and try again.', 'alert-error');
  37. },
  38.  
  39. addValidationError: function (field, message) {
  40. var controlGroup = $('#' + field).parent().parent();
  41. controlGroup.addClass('error');
  42. $('.help-block', controlGroup).html(message);
  43. },
  44.  
  45. removeValidationError: function (field) {
  46. var controlGroup = $('#' + field).parent().parent();
  47. controlGroup.removeClass('error');
  48. $('.help-block', controlGroup).html('');
  49. },
  50.  
  51. // Show alert classes and hide after specified timeout
  52. showAlert: function(title, text, klass) {
  53. $('.alert').removeClass("alert-error alert-warning alert-success alert-info");
  54. $('.alert').addClass(klass);
  55. $('.alert').html('<button class="close" data-dismiss="alert">×</button><strong>' + title + '</strong> ' + text);
  56. $('.alert').show('fast');
  57. setTimeout(function() {
  58. $('.alert').hide();
  59. }, 7000 );
  60. },
  61.  
  62. jsonResponse: function(code){
  63. jsonCodes = [],
  64. jsonCodes[400] = 'Unrecognized command',
  65. jsonCodes[401] = 'Permission denied',
  66. jsonCodes[402] = 'Missing argument',
  67. jsonCodes[401] = 'Incorrect password',
  68. jsonCodes[404] = 'Account not found',
  69. jsonCodes[405] = 'Email not validated',
  70. jsonCodes[408] = 'Token expired',
  71. jsonCodes[411] = 'Insufficient privileges',
  72. jsonCodes[500] = 'Internal server error';
  73. return jsonCodes[code];
  74. }
Add Comment
Please, Sign In to add comment