fix: restore url and text for immunizations card (#6991)
[openemr.git] / interface / product_registration / product_registration_service.js
blob14b057f3267b99167b5d278c737b78414409078d
1 /**
2  * ProductRegistrationService (JavaScript)
3  *
4  * LICENSE: This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
14  *
15  * @package OpenEMR
16  * @author  Matthew Vita <matthewvita48@gmail.com>
17  * @link    http://www.open-emr.org
18  */
20 "use strict";
21 function ProductRegistrationService() {
22     var self = this;
24     self.getProductStatus = function(callback) {
25         $.ajax({
26             url: registrationConstants.webroot + '/interface/product_registration/product_registration_controller.php',
27             type: 'GET',
28             dataType: 'json',
29             success: function(response) {
30                 _genericAjaxSuccessHandler(response, callback);
31             },
32             error: function(jqXHR) {
33                 _genericAjaxFailureHandler(jqXHR, callback);
34             }
35         });
36     };
38     self.submitRegistration = function(email, callback) {
39         $.ajax({
40             url: registrationConstants.webroot + '/interface/product_registration/product_registration_controller.php',
41             type: 'POST',
42             dataType: 'json',
43             data: {
44                 email: email
45             },
46             success: function(response) {
47                 _genericAjaxSuccessHandler(response, callback);
48             },
49             error: function(jqXHR) {
50                 _genericAjaxFailureHandler(jqXHR, callback);
51             }
52         });
53     };
55     var _genericAjaxSuccessHandler = function(response, callback) {
56         if (response) {
57             return callback(null, response);
58         }
60         return callback(registrationTranslations.genericError, null);
61     };
63     var _genericAjaxFailureHandler = function(jqXHR, callback) {
64         if (jqXHR && Object.prototype.hasOwnProperty.call(jqXHR, 'responseText')) {
65             try {
66                 var rawErrorObject = jqXHR.responseText;
67                 var parsedErrorObject = JSON.parse(rawErrorObject);
69                 if (parsedErrorObject && Object.prototype.hasOwnProperty.call(parsedErrorObject, 'message')) {
70                     callback(parsedErrorObject.message, null);
71                 }
72             } catch (jsonParseException) {
73                 callback(registrationTranslations.genericError, null);
74             }
75         } else {
76             callback(registrationTranslations.genericError, null);
77         }
78     };