Viewing File: /usr/local/cpanel/whostmgr/docroot/templates/gsw/initial_setup/views/legalController.js
/*
* views/legalController.js Copyright 2022 cPanel, L.L.C.
* All rights reserved.
* copyright@cpanel.net http://cpanel.net
* This code is subject to the cPanel license. Unauthorized copying is prohibited
*/
/* eslint-env amd */
define([
"angular",
"cjt/util/locale",
"ngSanitize",
"cjt/directives/actionButtonDirective",
"cjt/services/alertService",
"app/services/setupService",
"shared/js/license_purchase/services/storeService",
], function(angular, LOCALE) {
"use strict";
function LegalController(PAGE, $anchorScroll, $location, $timeout, setupService, storeService, alertService, $window, $sce) {
this.PAGE = PAGE;
this.agreements = PAGE.agreements;
this.$anchorScroll = $anchorScroll;
this.$location = $location;
this.$timeout = $timeout;
this.setupService = setupService;
this.alertService = alertService;
this.$window = $window;
this.storeService = storeService;
// Mark agreement contents as trusted so the PDFs can be shown
this.agreements = this.agreements.map((a) => {
return Object.assign(a, { content: $sce.trustAsHtml(a.content.toString()) });
});
if (PAGE.has_accepted_legal_agreements) {
this.continueToNextStep();
return;
}
this.setTopButtonMargin();
}
LegalController.$inject = [
"PAGE",
"$anchorScroll",
"$location",
"$timeout",
"setupService",
"storeService",
"alertService",
"$window",
"$sce",
];
/**
* Adds left and right margin to the floating "top" button to make sure
* that it accounts for the scrollbar width, if any. We use left and right
* margin so that it works for both LTR and RTL cases.
*
* @method setTopButtonMargin
*/
LegalController.prototype.setTopButtonMargin = function() {
this.$timeout(function() {
var panelElem = angular.element(".panel-body").get(0);
var topElem = angular.element("#top-link").get(0);
if (!panelElem || !topElem) {
return;
}
var scrollbarWidth = panelElem.offsetWidth - panelElem.clientWidth;
topElem.style.opacity = 1;
if (scrollbarWidth) {
topElem.style.marginLeft = scrollbarWidth + "px";
topElem.style.marginRight = scrollbarWidth + "px";
}
}, 1500);
};
/**
* Scrolls to the specified id using the location hash
*
* @method scrollTo
* @param {String} id The id of the anchor to scroll the view to
*/
LegalController.prototype.scrollTo = function(id) {
this.$location.hash(id);
this.$anchorScroll();
};
/**
* Records the user's acceptance of all of the legal agreements.
*
* @method acceptAll
* @return {Promise} When resolved, the server has successfully recorded the acceptance.
*/
LegalController.prototype.acceptAll = function() {
var self = this;
self.isAccepting = true;
self.alertService.clear();
return this.setupService.recordAcceptance().then(function() {
self.PAGE.has_accepted_legal_agreements = true;
self.continueToNextStep();
}).catch(function(error) {
self.alertService.add({
type: "danger",
id: "eula-api-error-alert",
message: LOCALE.maketext("The system could not process your agreement: [_1]", error),
replace: true,
});
}).finally(function() {
self.isAccepting = false;
});
};
LegalController.prototype.continueToNextStep = function() {
var self = this;
// TODO: Start using "cjt/services/viewNavigationApi" instead of $location.path() to propagate debug mode
if (self.PAGE.has_license) {
if (self.PAGE.has_completed_initial_setup || self.PAGE.is_dnsonly !== 0) {
self.$window.location.href = "../initial_setup_wizard1_do";
} else {
self.$location.path("/info");
}
} else {
self.storeService.isEligibleForTrial().then(function(isEligible) {
if (isEligible) {
self.setupService.isEligibleForTrial = true;
self.$location.path("/trial-activation/login");
} else {
if (self.PAGE.has_completed_initial_setup || self.PAGE.is_dnsonly !== 0) {
self.$window.location.href = "../initial_setup_wizard1_do";
} else {
self.setupService.isEligibleForTrial = false;
self.$location.path("/info");
}
}
}, function error() {
if (self.PAGE.has_completed_initial_setup || self.PAGE.is_dnsonly !== 0) {
self.$window.location.href = "../initial_setup_wizard1_do";
} else {
self.setupService.isEligibleForTrial = false;
self.$location.path("/info");
}
});
}
};
angular
.module("whm.initialSetup.legalController", [
"ngSanitize",
"cjt2.directives.actionButton",
"cjt2.services.alert",
"whm.initialSetup.setupService",
"whm.storeService",
])
.controller("legalController", LegalController);
return LegalController;
});
Back to Directory
File Manager