Skip to content

Commit

Permalink
RT-15358 More information in Renew modal when the renewperiod is set …
Browse files Browse the repository at this point in the history
…on more than 1 year
  • Loading branch information
zbrag committed Dec 3, 2024
1 parent 28f9b90 commit 9598405
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
13 changes: 13 additions & 0 deletions modules/registrars/realtimeregister/src/Assets/Js/renew.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const renewButton = document.querySelector('input[type="button"][data-toggle="modal"][data-target="#modalRenew"]');

if (renewButton) {
renewButton.addEventListener('click', () => {
if (document.getElementsByName('regperiod')[1].value !== '1') {
$('#modalRenew').on('show.bs.modal', function (e) {
document.getElementById('modalRenewBody').innerHTML = 'Please pay attention, the registration period is set to <b>' + document.getElementsByName('regperiod')[1].value + ' years</b>, are you sure you want to send the domain renewal request to the registrar?';
});
} else {
document.getElementById('modalRenewBody').innerHTML = 'Are you sure you want to send the domain renewal request to the registrar?';
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use RealtimeRegister\Domain\Enum\ResumeTypeEnum;
use RealtimeRegisterDomains\Actions\Action;
use RealtimeRegisterDomains\App;
use RealtimeRegisterDomains\Enums\ScriptLocationType;
use RealtimeRegisterDomains\Models\Whmcs\Domain;
use RealtimeRegisterDomains\Request;
use RealtimeRegisterDomains\Services\LogService;
Expand Down Expand Up @@ -66,6 +67,8 @@ public function __invoke(Request $request): array|string
}
}

App::assets()->addScript('renew.js', ScriptLocationType::Footer);

return $adminButtons;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ class CheckCredentials extends Hook

public function __invoke(DataObject $vars): void
{
App::assets()->addScript("checkCredentials.js");

if ($_POST['action'] === $this->ACTION && $_POST['module'] == 'realtimeregister') {
App::assets()->addScript("checkCredentials.js");
self::checkConnection();
}
}
Expand Down
14 changes: 12 additions & 2 deletions modules/registrars/realtimeregister/src/Services/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,23 @@ public function addScript(string $name, ScriptLocationType $scriptLocationType =
$payload['type'] = 'script';

if ($scriptLocationType === ScriptLocationType::Header) {
$this->addToHeader($payload);
$this->addItemIfNotExists(self::$head, $name, $payload, [$this, 'addToHeader']);
} else {
$this->addToFooter($payload);
$this->addItemIfNotExists(self::$footer, $name, $payload, [$this, 'addToFooter']);
}
return $this;
}

private function addItemIfNotExists(array $list, string $name, array $payload, callable $addMethod): void
{
foreach ($list as $item) {
if ($item['name'] === $name) {
return;
}
}
$addMethod($payload);
}

private static function getPath(string $path): string
{
return str_replace(
Expand Down
14 changes: 14 additions & 0 deletions modules/registrars/realtimeregister/tests/Services/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,18 @@ public function testAddPrependHead()

$this->assertEquals($payload, $asset->renderHead());
}

public function testAddSameItemMultipleTimes()
{
$asset = new Assets();
$asset->addScript('Hello.js');
$asset->addScript('Hello.js');
$asset->addScript('Hello.js');

$this->assertEquals(
'<script src="/modules/registrars/' . App::NAME . '/src/Assets/Js/Hello.js?'
. App::VERSION . '"></script>',
$asset->renderHead()
);
}
}

0 comments on commit 9598405

Please sign in to comment.