First batch of removal of the headers needed for revision-functions.php
[mailer.git] / js / admin-network-query-api.js
1 /**
2  * JavaScript for admin ext-network AJAX stuff
3  * --------------------------------------------------------------------
4  * Copyright (c) 2003 - 2009 by Roland Haeder
5  * Copyright (c) 2009 - 2013 by Mailer Developer Team
6  * For more information visit: http://mxchange.org
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21  * MA  02110-1301  USA
22  */
23
24 // Sends a request out to query a network API
25 function sendNetworkQueryByTypeId (typeId) {
26         // Send out the request
27         return sendAjaxRequest('admin', 'network_query_single_api', '&network_type_id=' + typeId, false);
28 }
29
30 // Queries a single network type handler
31 function doQueryNetworkType (typeId, displayMessage) {
32         // Close all windows
33         closeAllWindows('admin');
34
35         // Update status
36         updateStatusField('status_' + typeId, '', 'CHECKING ...');
37
38         // Does the request work?
39         if (sendNetworkQueryByTypeId(typeId) === false) {
40                 // Display a message?
41                 if (displayMessage === true) {
42                         // Display error message
43                         displayErrorWindow('admin', getAjaxContent());
44                 } // END - if
45         } else {
46                 // Display a message?
47                 if (displayMessage === true) {
48                         // Display success message
49                         displaySuccessWindow('admin', getAjaxContent());
50                 } // END - if
51
52                 // Update status
53                 updateStatusField('status_' + typeId, 'good', 'OKAY');
54
55                 // Worked fine
56                 return true;
57         }
58
59         // Update status
60         updateStatusField('status_' + typeId, 'bad', 'ERROR!');
61
62         // Didn't work
63         return false;
64 }
65
66 // Query all network APIs
67 // @TODO Add support for checkboxes
68 // @TODO Make progress window working
69 function doQueryNetwork (networkId) {
70         // Open progress window
71         //displayProgressWindow('admin', 'Init ...');
72
73         // Do the AJAX request (JSON as content is enabled)
74         if (sendAjaxRequest('admin', 'network_list_by_id', '&network_id=' + networkId, true) === true) {
75                 // Get content (as it is an array)
76                 var queries = getAjaxContent();
77                 var total = getTotalCountFromObject(queries);
78
79                 // Parse the content
80                 $.each(queries, function (i, typeId) {
81                         // Set progress content
82                         //setProgressContent('admin', typeId);
83
84                         // Request it
85                         if (doQueryNetworkType(typeId, false) === false) {
86                                 // Stop processing and display error message
87                                 displayErrorWindow('admin', getAjaxContent() + 'typeId=' + typeId);
88
89                                 // Abort here
90                                 return false;
91                         } // END - if
92
93                         // Update progress bar
94                         updateProgressBar(queries.length);
95
96                         // Wait a little
97                         $('body').delay(500);
98                 });
99
100                 // Is all completed?
101                 if (counterSuccess == total) {
102                         // Display success message
103                         displaySuccessWindow('admin', 'OKAY');
104                 } // END - if
105         } else {
106                 // Display error window
107                 displayErrorWindow('admin', getAjaxContent());
108         }
109 }