]> jfr.im git - z_archive/KronOS.git/blame - public/js/application.js
Moved Core (models -> libraries); changed more things to Json lib
[z_archive/KronOS.git] / public / js / application.js
CommitLineData
f255c3e2 1var state
9d2ed0ce 2
90b2985c 3function loadDefaults() {
4d35980c
JR
4 jQuery.getJSON("/backend/logged_in", function(resp) {
5 if (!resp.contents) {
90b2985c 6 loadLoginModal();
9d2ed0ce 7 } else {
4d35980c 8 loadUsername();
90b2985c 9 loadMenu();
55433e7f 10 loadBackground();
9d2ed0ce 11 }
38e368d2 12 });
90b2985c
CS
13}
14
55433e7f
CS
15function loadBackground() {
16 background = '<style>body { background-image:url(\'/public/img/default-background.jpg\'); background-position: center top; } </style>'
17 jQuery('body').append(background);
18}
19
90b2985c
CS
20function loadLoginModal() {
21 jQuery.ajax({
22 url: "/backend/login_modal",
f255c3e2
JR
23 success: function (data) {
24 jQuery('body').append(data);
25 jQuery('#loginModal').modal({
26 backdrop: 'static',
27 keyboard: false,
28 });
29 jQuery('#loginModal').modal('show');
30 },
90b2985c 31 dataType: 'html'
90b2985c
CS
32 });
33
34}
35
4d35980c
JR
36function loadUsername() {
37 jQuery("#username").html(state.name);
38}
39
90b2985c 40function loadMenu() {
4d35980c
JR
41 jQuery.getJSON("/backend/get_menu", function(resp) {
42 if (resp.success) {
43 var menuitems = []
44 jQuery.each(resp.contents, function(key, val) {
45 menuitems.push('<li><a href="' + val + '">' + key + '</li>');
46 });
47 jQuery('<ul/>', {
48 'class': 'nav',
49 html: menuitems.join('')
50 }).appendTo('.menudiv');
51 } else {
52 throwError(resp.error, 'error', '#desktop');
53 }
90b2985c
CS
54 });
55
56}
57
af724f74
CS
58function submitLogin() {
59 loginData = {
60 'username': jQuery('#inputUsername').val(),
61 'password': jQuery('#inputPassword').val()
62 };
f255c3e2
JR
63 jQuery.post('/account/login', loginData, function(resp) {
64 if (resp.success) {
65 for (key in resp.data) {
66 state[key] = resp.data[key]
67 }
af724f74 68 jQuery('#loginModal').modal('hide');
4d35980c 69 loadUsername();
af724f74
CS
70 loadMenu();
71 loadBackground();
7d24cfef
CS
72 } else {
73 throwError(resp.error, 'error', '.messagebody');
f255c3e2 74 }
af724f74
CS
75 }, "json");
76}
77
7d24cfef 78function throwError(e, t, c) {
4d35980c
JR
79 var n = jQuery(".alert").length;
80 if (n>2) {
81 jQuery(".alert").first().remove();
82 }
83
7d24cfef
CS
84 error = '<div class="alert alert-block alert-' + t + '"><button type="button" class="close" data-dismiss="alert">&times;</button>' + e + '</div>'
85 jQuery(c).append(error);
86}
87
4d35980c
JR
88function logout() {
89 state = {}
90 loadDefaults();
91}
92
f255c3e2
JR
93jQuery(function () {
94 state = {}
95
96 jQuery.noConflict();
97 loadDefaults();
98});