Skip to content

Commit 291e0d9

Browse files
committed
Change pages titles with ajax calls
1 parent 20d42ef commit 291e0d9

File tree

9 files changed

+41
-11
lines changed

9 files changed

+41
-11
lines changed

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/app.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/service-worker.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Action/Modules/Files/MyFilesAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private function getFilesPageTitle(string $subdirectoryPath): string
315315
$pageTitle = $this->app->translator->translate(
316316
'files.title',
317317
[
318-
'{{folder}}' => $subdirectoryPath
318+
'{{folder}}' => basename($subdirectoryPath),
319319
]
320320
);
321321

src/Action/Modules/Images/MyImagesAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private function getImagesCategoryPageTitle(string $subdirectoryPath): string
236236
$pageTitle = $this->app->translator->translate(
237237
'images.title',
238238
[
239-
'{{folder}}' => $subdirectoryPath
239+
'{{folder}}' => basename($subdirectoryPath),
240240
]
241241
);
242242

src/Action/Modules/Videos/MyVideoAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private function getVideoCategoryPageTitle(string $subdirectoryPath): string
186186
$pageTitle = $this->app->translator->translate(
187187
'video.title',
188188
[
189-
'{{folder}}' => $subdirectoryPath
189+
'{{folder}}' => basename($subdirectoryPath),
190190
]
191191
);
192192

src/assets/scripts/DTO/AjaxResponseDto.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AbstractDto from "./AbstractDto";
2+
import StringUtils from "../core/utils/StringUtils";
23

34
/**
45
* @description Main object used to convert standard array response from backend (upon ajax calls)
@@ -72,6 +73,11 @@ export default class AjaxResponseDto extends AbstractDto {
7273
*/
7374
public dataBag;
7475

76+
/**
77+
* @type string
78+
*/
79+
public pageTitle: string = "";
80+
7581
/**
7682
* Builds DTO from data array
7783
* @param array
@@ -92,6 +98,7 @@ export default class AjaxResponseDto extends AbstractDto {
9298
ajaxResponseDto.invalidFormFields = ajaxResponseDto.getFromArray(array, 'invalid_form_fields', []);
9399
ajaxResponseDto.routeUrl = ajaxResponseDto.getFromArray(array, 'route_url', "");
94100
ajaxResponseDto.constantValue = ajaxResponseDto.getFromArray(array, 'constant_value', "");
101+
ajaxResponseDto.pageTitle = ajaxResponseDto.getFromArray(array, 'page_title', "");
95102
ajaxResponseDto.dataBag = ajaxResponseDto.getFromArray(array, 'data_bag', {});
96103

97104
return ajaxResponseDto;
@@ -205,4 +212,11 @@ export default class AjaxResponseDto extends AbstractDto {
205212
return (0 !== Object.keys(this.dataBag).length);
206213
}
207214

215+
/**
216+
* @returns {string}
217+
*/
218+
public isTitleSet(): boolean
219+
{
220+
return !StringUtils.isEmptyString(this.pageTitle);
221+
}
208222
}

src/assets/scripts/core/Application.ts

+11
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@ export default class Application {
1414
}
1515
}
1616

17+
/**
18+
* @description will set page title in <HEAD> tag
19+
*
20+
* @param title
21+
*/
22+
public static setTitle(title: string): void
23+
{
24+
let $titleTag = $('title');
25+
$titleTag.text("PMS - " + title);
26+
}
27+
1728
}

src/assets/scripts/core/ajax/AjaxEvents.ts

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Initializer from "../../Initializer";
1313
import AbstractAjax from "./AbstractAjax";
1414
import Ajax from "./Ajax";
1515
import BootboxWrapper from "../../libs/bootbox/BootboxWrapper";
16+
import Application from "../Application";
1617

1718
/**
1819
* @default This class contains definitions of events and it's logic attached on GUI elements
@@ -132,6 +133,10 @@ export default class AjaxEvents extends AbstractAjax {
132133
}
133134
});
134135

136+
if( ajaxResponseDto.isTitleSet() ){
137+
Application.setTitle(ajaxResponseDto.pageTitle);
138+
}
139+
135140
if( ajaxResponseDto.reloadPage ){
136141
if( ajaxResponseDto.isReloadMessageSet() ){
137142
_this.bootstrapNotify.showBlueNotification(ajaxResponseDto.reloadMessage);

0 commit comments

Comments
 (0)