fix: restore url and text for immunizations card (#6991)
[openemr.git] / interface / product_registration / product_registration_controller.js
blob1fec554e9f3fbae1b0deaafe270a68374e73d93b
1 /**
2  * ProductRegistrationController (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";
22 function ProductRegistrationController() {
23     var self = this;
25     var _productRegistrationService = new ProductRegistrationService();
27     self.getProductRegistrationStatus = function (callback) {
28         _productRegistrationService.getProductStatus(function (err, data) {
29             if (err) {
30                 return callback(err, null);
31             }
33             callback(null, data);
34         });
35     };
37     self.showProductRegistrationModal = function () {
38         _displayFormView();
39     };
41     var _displayFormView = function () {
42         // Workaround to get i18n keys
43         var buttonObject = {};
44         buttonObject[registrationTranslations.submit] = _formSubmissionHandler;
45         buttonObject[registrationTranslations.noThanks] = _formCancellationHandler;
47         $('.product-registration-modal .modal-header').text(registrationTranslations.title);
49         $('.product-registration-modal .submit').on('click', function(e){
50                 _formSubmissionHandler();
51                 return false;
52             });
54         $('.product-registration-modal .nothanks').on('click', function(e){
55             _formCancellationHandler();
56             return false;
57         });
59         $('.product-registration-modal').modal('toggle');
64         // Wire up "enter key" handler in case user doesn't click the modal buttons manually
65         $('.product-registration-modal .email').on('keypress', function (event) {
66             if (event.which == 13) {
67                 _formSubmissionHandler();
68                 return false;
69             }
70         });
71     };
73     var _formSubmissionHandler = function () {
74         var email = $('.product-registration-modal .email').val() || '';
76         if (email === '' || email.indexOf('@') < 0) {
77             $('.product-registration-modal .message').text(registrationTranslations.pleaseProvideValidEmail);
78         } else {
79             $('.product-registration-modal .message').text('');
81             _productRegistrationService.submitRegistration(email, function (err, data) {
82                 if (err) {
83                     return _registrationFailedHandler(err);
84                 }
86                 _registrationCreatedHandler(data);
87             });
88         }
89     };
91     // If we are on the about_page, show the registration data.
92     self.displayRegistrationInformationIfDivExists = function (data) {
93         if ($('.product-registration').length > 0) {
94             $('.product-registration .email').text(registrationTranslations.registeredEmail + ' ' + data.email);
95         }
96     };
98     var _formCancellationHandler = function () {
99         _closeModal();
101         // Note: not checking output here (don't want to bug the user more this session
102         // after they said "no thanks" to the modal). If anything goes wrong, it will be silent.
103         // The only reasons why this would fail would be because of no connection or our server
104         // is down.
105         var _noop = function () {};
106         _productRegistrationService.submitRegistration(false, _noop);
107     };
109      var _registrationCreatedHandler = function (data) {
110         $('.product-registration-modal .context').remove();
111         $('.product-registration-modal .email').remove();
112         $('.product-registration-modal .message').text(registrationTranslations.registeredSuccess);
113         _closeModal(2500);
114         self.displayRegistrationInformationIfDivExists(data);
115     };
117     var _registrationFailedHandler = function (error) {
118         $('.product-registration-modal .message').text(error);
119     };
121     var _closeModal = function (closeWaitTimeMilliseconds) {
122         setTimeout(function () {
123             $('.product-registration-modal').modal('toggle');
124         }, closeWaitTimeMilliseconds || 0);
125     };