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
21 function ProductRegistrationController() {
24 var _productRegistrationService = new ProductRegistrationService();
26 self.getProductRegistrationStatus = function(callback) {
27 _productRegistrationService.getProductStatus(function(err, data) {
28 if (err) { return callback(err, null); }
34 self.showProductRegistrationModal = function() {
38 var _displayFormView = function() {
39 // Workaround to get i18n keys
40 var buttonObject = {};
41 buttonObject[registrationTranslations.submit] = _formSubmissionHandler;
42 buttonObject[registrationTranslations.noThanks] = _formCancellationHandler;
44 jQuery('.product-registration-modal').dialog({
49 title: registrationTranslations.title,
51 buttons: buttonObject,
52 closeText: registrationTranslations.closeTooltip
55 // Wire up "enter key" handler in case user doesn't click the modal buttons manually
56 jQuery('.product-registration-modal .email').on('keypress', function(event) {
57 if (event.which == 13) {
58 _formSubmissionHandler();
64 var _formSubmissionHandler = function() {
65 var email = jQuery('.product-registration-modal .email').val() || '';
67 if (email === '' || email.indexOf('@') < 0) {
68 jQuery('.product-registration-modal .message').text(registrationTranslations.pleaseProvideValidEmail);
70 jQuery('.product-registration-modal .message').text('');
72 _productRegistrationService.submitRegistration(email, function(err, data) {
73 if (err) { return _registrationFailedHandler(err); }
75 _registrationCreatedHandler(data);
80 // If we are on the about_page, show the registration data.
81 self.displayRegistrationInformationIfDivExists = function(data) {
82 if (jQuery('.product-registration').size() > 0) {
83 jQuery('.product-registration .email').text(registrationTranslations.registeredEmail + ' ' + data.email);
84 jQuery('.product-registration .id').text(registrationTranslations.registeredId + ' ' + data.registrationId);
88 var _formCancellationHandler = function() {
91 // Note: not checking output here (don't want to bug the user more this session
92 // after they said "no thanks" to the modal). If anything goes wrong, it will be silent.
93 // The only reasons why this would fail would be because of no connection or our server
95 var _noop = function() {};
96 _productRegistrationService.submitRegistration(false, _noop);
99 var _registrationCreatedHandler = function(data) {
100 jQuery('.product-registration-modal').dialog('option', {
102 title: registrationTranslations.success
105 jQuery('.product-registration-modal .context').remove();
106 jQuery('.product-registration-modal .email').remove();
107 jQuery('.product-registration-modal .message').text(registrationTranslations.registeredSuccess);
109 self.displayRegistrationInformationIfDivExists(data);
112 var _registrationFailedHandler = function(error) {
113 jQuery('.product-registration-modal .message').text(error);
116 var _closeModal = function(closeWaitTimeMilliseconds) {
117 setTimeout(function() {
118 jQuery('.product-registration-modal').dialog('close');
119 }, closeWaitTimeMilliseconds || 0);