AJAX installation is 'basicly finished' :) Plus I threw in a small christmas present...
[mailer.git] / js / install-common.js
1 /**
2  * JavaScript for common installer functions
3  * --------------------------------------------------------------------
4  * $Revision::                                                        $
5  * $Date::                                                            $
6  * $Tag:: 0.2.1-FINAL                                                 $
7  * $Author::                                                          $
8  * --------------------------------------------------------------------
9  * Copyright (c) 2003 - 2009 by Roland Haeder
10  * Copyright (c) 2009 - 2012 by Mailer Developer Team
11  * For more information visit: http://mxchange.org
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
26  * MA  02110-1301  USA
27  */
28
29 // Installation steps array
30 var installationSteps = new Array();
31
32 // Failed step
33 var failedStep = '';
34 var counterSuccess = 0;
35
36 // Init all installation steps
37 installationSteps[0] = 'import_tables_sql';
38 installationSteps[1] = 'import_menu_sql';
39 installationSteps[2] = 'install_extensions';
40
41 // Always keep as last step
42 installationSteps[installationSteps.length] = 'write_local_config';
43
44 // Switches instaler by redirecting
45 function switchInstaller (installer) {
46         // Switch installer
47         document.location.href = 'install.php?installer=' + installer;
48 }
49
50 // User has clicked on 'finish'
51 function doFinishInstallation () {
52         // First disable all buttons button
53         resetFooterNavigation();
54
55         // Display progress window
56         displayProgressWindow('install', 'Init ...');
57
58         // Start installation loop delayed
59         window.setTimeout('doInstallationLoop()', 500);
60
61         // Wait here
62         window.setTimeout('doWait()', 500);
63 }
64
65 // Do wait
66 function doWait () {
67         // Is still something to do?
68         if ((failedStep == '') && (counterSuccess != installationSteps.length)) {
69                 // Wait one round more
70                 window.setTimeout('doWait()', 500);
71         } else if ((failedStep == '') && (counterSuccess == installationSteps.length)) {
72                 // Close window
73                 closeProgressWindow('install', true, false);
74
75                 // Redirect to old 'finished' page
76                 document.location.href = 'admin.php';
77         } else if (failedStep != '') {
78                 // Something happens that should not happen!
79                 displayErrorWindow('install', 'failedStep=' + failedStep);
80         }
81 }
82
83 // Update progress bar
84 function updateProgressBar () {
85         // Increment counter
86         counterSuccess++;
87
88         // Do only update <= 100% values
89         if (counterSuccess <= installationSteps.length) {
90                 // Update progress bar
91                 $('#progressbar').progressbar({
92                         value: (counterSuccess / installationSteps.length * 100)
93                 });
94         } // END - if
95 }
96
97 // Does the "installation loop"
98 function doInstallationLoop () {
99         // For-loop for all installation steps
100         for (var i = 0; i < installationSteps.length; i++) {
101                 // Output message
102                 outputInstallationStepMessage(installationSteps[i]);
103
104                 // Initialize next step
105                 if (!sendInstallationStepRequest(i) == true) {
106                         // Failed step, so remember it for later display
107                         failedStep = installationSteps[i];
108
109                         // Stop here
110                         break;
111                 } // END - if
112
113                 // Wait a little
114                 $('body').delay(500);
115
116                 // Update progress bar
117                 updateProgressBar();
118         } // END - for
119
120         // Is success counter same as array size
121         if (counterSuccess != installationSteps.length) {
122                 // Display error message
123                 displayErrorWindow('install', getAjaxContent() + ':' + counterSuccess + '/' + installationSteps.length + ':' + failedStep);
124         } // END - if
125 }
126
127 // Sends an "installation step" request out
128 function sendInstallationStepRequest (i) {
129         // Is it set?
130         if (installationSteps[i] == undefined) {
131                 // Not set installation step, so don't send it out
132                 throw new 'installationSteps[' + i + '] is not set.';
133         } // END - if
134
135         // Send out the request
136         return sendAjaxRequest('install', 'do_step', '&step=' + installationSteps[i], true);
137 }
138
139 // Outputs a "step message"
140 function outputInstallationStepMessage (step) {
141         // Set content
142         // @TODO Progress bar is out-of-order: + '<div id="progressbar"></div>'
143         setProgressContent('install', step);
144 }