Merge branch 'contrib' into 0.2.1-FINAL
[mailer.git] / js / admin-network-query-api.js
1 /**
2  * JavaScript for admin ext-network AJAX stuff
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 - 2013 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 // Sends a request out to query a network API
30 function sendNetworkQueryByTypeId (typeId) {
31         // Send out the request
32         return sendAjaxRequest('admin', 'network_query_single_api', '&network_type_id=' + typeId, false);
33 }
34
35 // Queries a single network type handler
36 function doQueryNetworkType (typeId, displayMessage) {
37         // Close all windows
38         closeAllWindows('admin');
39
40         // Update status
41         updateStatusField('status_' + typeId, '', 'CHECKING ...');
42
43         // Does the request work?
44         if (sendNetworkQueryByTypeId(typeId) === false) {
45                 // Display a message?
46                 if (displayMessage === true) {
47                         // Display error message
48                         displayErrorWindow('admin', getAjaxContent());
49                 } // END - if
50         } else {
51                 // Display a message?
52                 if (displayMessage === true) {
53                         // Display success message
54                         displaySuccessWindow('admin', getAjaxContent());
55                 } // END - if
56
57                 // Update status
58                 updateStatusField('status_' + typeId, 'good', 'OKAY');
59
60                 // Worked fine
61                 return true;
62         }
63
64         // Update status
65         updateStatusField('status_' + typeId, 'bad', 'ERROR!');
66
67         // Didn't work
68         return false;
69 }
70
71 // Query all network APIs
72 // @TODO Add support for checkboxes
73 // @TODO Make progress window working
74 function doQueryNetwork (networkId) {
75         // Open progress window
76         //displayProgressWindow('admin', 'Init ...');
77
78         // Do the AJAX request (JSON as content is enabled)
79         if (sendAjaxRequest('admin', 'network_list_by_id', '&network_id=' + networkId, true) === true) {
80                 // Get content (as it is an array)
81                 var queries = getAjaxContent();
82                 var total = getTotalCountFromObject(queries);
83
84                 // Parse the content
85                 $.each(queries, function (i, typeId) {
86                         // Set progress content
87                         //setProgressContent('admin', typeId);
88
89                         // Request it
90                         if (doQueryNetworkType(typeId, false) === false) {
91                                 // Stop processing and display error message
92                                 displayErrorWindow('admin', getAjaxContent() + 'typeId=' + typeId);
93
94                                 // Abort here
95                                 return false;
96                         } // END - if
97
98                         // Update progress bar
99                         updateProgressBar(queries.length);
100
101                         // Wait a little
102                         $('body').delay(500);
103                 });
104
105                 // Is all completed?
106                 if (counterSuccess == total) {
107                         // Display success message
108                         displaySuccessWindow('admin', 'OKAY');
109                 } // END - if
110         } else {
111                 // Display error window
112                 displayErrorWindow('admin', getAjaxContent());
113         }
114 }