Added V4: Access Control (work in progress)
[ssproject1617.git] / testcms-final-anon / install / assets / js / app.js
1 $(function() {
2 var body = $('body'), form = $('form'), notes = $('.notes');
3
4 // remove no js error
5 body.find('.nojs').remove();
6
7 // Do some fancy fading in, and get rid of that damn error.
8 body.hide().fadeIn()
9
10 // remove previous notifications
11 var remove_notes = function() {
12 notes.find('p').remove();
13 notes.hide();
14 };
15
16 // Check when the MySQL form has been submitted, and AJAX a request off.
17 var check = function() {
18 // remove previous notifications
19 remove_notes();
20
21 // dim fieldset
22 $('#diagnose').animate({'opacity': 0.5}, 250, function() {
23 $.ajax({
24 'type': 'POST',
25 'url': 'diagnose.php',
26 'data': form.serialize(),
27 'success': check_result
28 });
29 });
30
31 return false;
32 };
33
34 var check_result = function(data) {
35 $('#diagnose').animate({'opacity': 1});
36
37 if(data == 'good') {
38 notes.show().append('<p class="success">&#10003; Database test successful.</p>').fadeIn();
39 } else {
40 notes.show().append('<p class="error">' + data + '</p>').fadeIn();
41 }
42 };
43
44 var submit = function() {
45 $.ajax({
46 'type': 'POST',
47 'url': 'installer.php',
48 'data': form.serialize(),
49 'dataType': 'json',
50 'success': submit_result
51 });
52
53 return false;
54 };
55
56 var submit_result = function(data) {
57 // remove previous notifications
58 remove_notes();
59
60 if(data.installed) {
61 var content = $('.content');
62
63 content.animate({'opacity': 0}, function() {
64 var btn_text = 'Continue to your site.';
65
66 var html = '<h2>Thanks for installing!</h2>';
67 html += '<p>We created an account for you.<br>The username is <b>admin</b>, and the password is <strong>' + data.password + '</strong>.</p>';
68
69 if(data.warnings.length) {
70 btn_text = 'OK, I understand, Continue to your site.';
71
72 html += '<ul style="padding-bottom: 1em;">';
73
74 for(var i = 0; i < data.warnings.length; i++) {
75 var warn = data.warnings[i];
76 html += '<li>' + warn + '</li>';
77 }
78
79 html += '</ul>';
80 }
81
82 html += '<p><a href="../" class="button" style="float: none; display: inline-block;">' + btn_text + '</a></p>';
83
84 content.html(html).animate({'opacity': 1});
85 });
86 } else {
87 notes.show().append('<p class="error">' + data.errors.join(', ') + '</p>').fadeIn();
88 }
89 };
90
91 // Bind normal form submit
92 form.bind('submit', submit);
93
94 // Bind db check
95 $('a[href$=#check]').bind('click', check);
96 });