2 * ProductRegistrationController (JavaScript)
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>;.
16 * @author Matthew Vita <matthewvita48@gmail.com>
17 * @link http://www.open-emr.org
22 function ProductRegistrationController() {
25 var _productRegistrationService = new ProductRegistrationService();
27 self.getProductRegistrationStatus = function (callback) {
28 _productRegistrationService.getProductStatus(function (err, data) {
30 return callback(err, null);
37 self.showProductRegistrationModal = function () {
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();
54 $('.product-registration-modal .nothanks').on('click', function(e){
55 _formCancellationHandler();
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();
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);
79 $('.product-registration-modal .message').text('');
81 _productRegistrationService.submitRegistration(email, function (err, data) {
83 return _registrationFailedHandler(err);
86 _registrationCreatedHandler(data);
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);
98 var _formCancellationHandler = function () {
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
105 var _noop = function () {};
106 _productRegistrationService.submitRegistration(false, _noop);
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);
114 self.displayRegistrationInformationIfDivExists(data);
117 var _registrationFailedHandler = function (error) {
118 $('.product-registration-modal .message').text(error);
121 var _closeModal = function (closeWaitTimeMilliseconds) {
122 setTimeout(function () {
123 $('.product-registration-modal').modal('toggle');
124 }, closeWaitTimeMilliseconds || 0);