Viewing File: /usr/local/cpanel/whostmgr/docroot/templates/cpanel_customization/views/jupiter/linksController.js
/*
# cpanel - whostmgr/docroot/templates/cpanel_customization/views/jupiter/linksController.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
*/
/* jshint -W100 */
define(
[
"lodash",
"angular",
"cjt/util/locale",
"cjt/directives/autoFocus",
"cjt/decorators/growlDecorator",
"app/services/customizeService",
"app/services/savedService",
],
function(_, angular, LOCALE) {
"use strict";
var module = angular.module("customize.views.linksController", [
"customize.services.customizeService",
"customize.services.savedService",
]);
var controller = module.controller(
"linksController", [
"$scope",
"customizeService",
"savedService",
"growl",
"growlMessages",
"PAGE",
function($scope, customizeService, savedService, growl, growlMessages, PAGE) {
$scope.saving = false;
$scope.urlRegex = /^(https?):\/\/(?:[^:@]+(?::[^@]+)?@)?(?:[^\s:/?#]+|\[[a-f\\d:]+])(?::\\d+)?(?:\/[^?#]*)?(?:\\?[^#]*)?(?:#.*)?$/i;
// Preload links
$scope.model = {
help: PAGE.data.jupiter.help ? angular.copy(PAGE.data.jupiter.help) : { url: "" },
documentation: PAGE.data.jupiter.documentation ? angular.copy(PAGE.data.jupiter.documentation) : { url: "" },
};
// Watch for changes
$scope.$watch("model.help", function() {
savedService.update("links", $scope.customization.$dirty);
}, true);
$scope.$watch("model.documentation", function() {
savedService.update("links", $scope.customization.$dirty);
}, true);
/**
* Saves changes to branding customization
* Persist the customization form if it is valid
* @method save
* @param {Object} $formCtrl Form control
*/
$scope.save = function($formCtrl) {
growlMessages.destroyAllMessages();
if (!$formCtrl.$valid) {
growl.error(LOCALE.maketext("The current customization is invalid."));
return;
}
if ($scope.saving) {
growl.warning(LOCALE.maketext("The system is busy. Try again once the current operation is complete."));
return;
}
$scope.saving = true;
customizeService.update({
documentation: {
url: $scope.model.documentation.url,
},
help: {
url: $scope.model.help.url,
},
}).then(function(response) {
// For subsequent loads of links tab, we need to update PAGE to reflect changes
PAGE.data.jupiter.documentation.url = $scope.model.documentation.url;
PAGE.data.jupiter.help.url = $scope.model.help.url;
$formCtrl.$setPristine();
savedService.update("links", false);
growl.success(LOCALE.maketext("The system successfully updated your links."));
}).catch(function(error) {
growl.error(LOCALE.maketext("The system failed to update your links."));
}).finally(function() {
$scope.saving = false;
});
};
},
]
);
return controller;
}
);
Back to Directory
File Manager