summaryrefslogtreecommitdiff
path: root/themes/default/js/user.js
blob: b389a67ea31db27dd50364e46b8b2e89a03dbea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
$(document).ready(function() {
  $("#gLoginForm").submit(function() {
    process_login();
    return false;
  });
  $("#gLogoutLink").click(function() {
    process_logout();
    return false;
  });
});

function show_form(formName) {
  $(formName + "Link").css({display: "none"});
  $(formName + "Text").css({display: "inline"});
  $(formName + "Close").css({display: "inline"});
  var url = $(formName + "Form").attr("formSrc");
  $.get(url, null, function(data, textStatus) {
    $(formName + "Form").html(data);
    $(formName + "Form").css({display: "block"});  
  });
}

function hide_form(formName) {
  $(formName + "Link").css({display: "inline"});  
  $(formName + "Form").css({display: "none"});  
  $(formName + "Form").html("");  
  $(formName + "Text").css({display: "none"});
  $(formName + "Close").css({display: "none"});
}

function process_login() {
  $.ajax({
    url: $("#gLogin").attr("action"),
    type: "POST",
    data: $("#gLogin").serialize(),
    dataType: "json",
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      alert("textStatus: " + textStatus + "\nerrorThrown: " + errorThrown);
    },
    success: function(data, textStatus) {
      if (data.error_message != "") {
        $("#gLoginMessage").html(data.error_message);
        $("#gLoginMessage").css({display: "block"});
        $("#gLogin").addClass("gError");
      } else {
        window.location.reload();
      }
    }
  });
}

function process_logout() {
  $.ajax({
    url: $("#gLogoutLink").attr("href"),
    type: "GET",
    dataType: "json",
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      alert("textStatus: " + textStatus + "\nerrorThrown: " + errorThrown);
    },
    success: function(data, textStatus) {
      if (data.logout) {
        window.location.reload();
      }
    }
  });
}