Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions front/change_supplier.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
$link->check($_POST["id"], UPDATE);

$link->update($_POST);
echo "<script type='text/javascript' >";
echo "window.parent.location.reload();";
echo "</script>";
echo Html::scriptBlock("window.parent.location.reload();");
} elseif (isset($_POST['delete'])) {
$link->check($_POST['id'], DELETE);
$link->delete($_POST);
Expand Down
4 changes: 1 addition & 3 deletions front/change_user.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
$link->check($_POST["id"], UPDATE);

$link->update($_POST);
echo "<script type='text/javascript' >";
echo "window.parent.location.reload();";
echo "</script>";
echo Html::scriptBlock("window.parent.location.reload();");
} elseif (isset($_POST['delete'])) {
$link->check($_POST['id'], DELETE);
$link->delete($_POST);
Expand Down
4 changes: 1 addition & 3 deletions front/problem_supplier.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
$link->check($_POST["id"], UPDATE);

$link->update($_POST);
echo "<script type='text/javascript' >\n";
echo "window.parent.location.reload();";
echo "</script>";
echo Html::scriptBlock("window.parent.location.reload();");
} elseif (isset($_POST['delete'])) {
$link->check($_POST['id'], DELETE);
$link->delete($_POST);
Expand Down
4 changes: 1 addition & 3 deletions front/problem_user.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
$link->check($_POST["id"], UPDATE);

if ($link->update($_POST)) {
echo "<script type='text/javascript' >";
echo "window.parent.location.reload();";
echo "</script>";
echo Html::scriptBlock("window.parent.location.reload();");
} else {
Html::back();
}
Expand Down
4 changes: 1 addition & 3 deletions front/supplier_ticket.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
$link->check($_POST["id"], UPDATE);

$link->update($_POST);
echo "<script type='text/javascript' >";
echo "window.parent.location.reload();";
echo "</script>";
echo Html::scriptBlock("window.parent.location.reload();");
} elseif (isset($_POST['delete'])) {
$link->check($_POST['id'], DELETE);
$link->delete($_POST);
Expand Down
4 changes: 1 addition & 3 deletions front/ticket_user.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
$link->check($_POST["id"], UPDATE);

if ($link->update($_POST)) {
echo "<script type='text/javascript' >";
echo "window.parent.location.reload();";
echo "</script>";
echo Html::scriptBlock("window.parent.location.reload();");
} else {
Html::back();
}
Expand Down
11 changes: 5 additions & 6 deletions install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

require_once(__DIR__ . '/../front/_check_webserver_config.php');

use Glpi\Application\View\ScriptType;
use Glpi\Application\View\TemplateRenderer;
use Glpi\Locale\LanguageRegistry;
use Glpi\System\Requirement\DbConfiguration;
Expand Down Expand Up @@ -356,12 +357,10 @@ public function __construct(mysqli $dbh)
echo '</div>';
echo '</div>';

echo <<<HTML
<script defer type="module">
import { init_database } from '/js/modules/GlpiInstall.js';
init_database();
</script>
HTML;
echo Html::scriptBlock(<<<JAVASCRIPT
import { init_database } from '/js/modules/GlpiInstall.js';
init_database();
JAVASCRIPT, ScriptType::Module);
} else { // can't create config_db file
echo "<p>" . __s('Impossible to write the database setup file') . "</p>";
$prev_form($host, $user, $password);
Expand Down
11 changes: 5 additions & 6 deletions install/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

require_once(__DIR__ . '/../front/_check_webserver_config.php');

use Glpi\Application\View\ScriptType;
use Glpi\Application\View\TemplateRenderer;
use Glpi\Toolbox\VersionParser;

Expand Down Expand Up @@ -176,12 +177,10 @@ function showSecurityKeyCheckForm(): void
echo '</div>';
echo '</div>';

echo <<<HTML
<script defer type="module">
import { update_database } from '/js/modules/GlpiInstall.js';
update_database();
</script>
HTML;
echo Html::scriptBlock(<<<JAVASCRIPT
import { update_database } from '/js/modules/GlpiInstall.js';
update_database();
JAVASCRIPT, ScriptType::Module);
}
} else {
echo "<h3>";
Expand Down
31 changes: 16 additions & 15 deletions src/CommonITILValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ class="border-0 bg-transparent p-0"
}
}

$script = "";
$html = "";
if ($canedit) {
$edit_title = __s('Edit');
$item_id = (int) $itil->fields['id'];
Expand All @@ -1247,27 +1247,28 @@ class="border-0 bg-transparent p-0"

$rand_id = htmlescape($item_id . $row_id . $rand);

$script = <<<HTML
$script = Html::scriptBlock(<<<JAVASCRIPT
function viewEditValidation{$rand_id}() {
glpi_ajax_dialog({
url: CFG_GLPI.root_doc + "/ajax/viewsubitem.php",
modalclass: 'modal-xl',
params: $params_json,
});
};
document.getElementById('viewvalidation{$rand_id}').addEventListener('click', () => {
viewEditValidation{$rand_id}();
});
JAVASCRIPT);
$html = <<<HTML
<span class="ti ti-edit" style="cursor:pointer" title="{$edit_title}"
id="viewvalidation{$rand_id}">
</span>
<script>
function viewEditValidation{$rand_id}() {
glpi_ajax_dialog({
url: CFG_GLPI.root_doc + "/ajax/viewsubitem.php",
modalclass: 'modal-xl',
params: $params_json,
});
};
document.getElementById('viewvalidation{$rand_id}').addEventListener('click', () => {
viewEditValidation{$rand_id}();
});
</script>
$script
HTML;
}

$values[] = [
'edit' => $script,
'edit' => $html,
'status' => $status,
'type_name' => $type_name,
'target_name' => $target_name,
Expand Down
59 changes: 32 additions & 27 deletions src/Glpi/Api/HL/Controller/CoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,36 +360,38 @@ public function showDocumentation(Request $request): Response
});
$doc_json_paths = json_encode($doc_json_paths, JSON_THROW_ON_ERROR);

$script = Html::scriptBlock(<<<JAVASCRIPT
const ui = window.SwaggerUIBundle({
urls: {$doc_json_paths},
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
layout: 'StandaloneLayout',
docExpansion: 'none',
validatorUrl: 'none',
filter: true,
showExtensions: true,
oauth2RedirectUrl: '{$CFG_GLPI['root_doc']}/api.php/swagger-oauth-redirect',
// Sort operations by name and then by method
operationsSorter: (a, b) => {
const method_order = ['get', 'post', 'put', 'patch', 'delete'];
if (a.get('path') === b.get('path')) {
return method_order.indexOf(a.get('method')) - method_order.indexOf(b.get('method'));
}
return a.get('path').localeCompare(b.get('path'));
},
tagsSorter: (a, b) => a.localeCompare(b),
});
JAVASCRIPT);

$swagger_content .= <<<HTML
<link rel="shortcut icon" type="images/x-icon" href="$favicon" />
</head>
<body style="margin:0; padding:0;">
<div id="swagger-ui"></div>
<script>
const ui = window.SwaggerUIBundle({
urls: {$doc_json_paths},
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
layout: 'StandaloneLayout',
docExpansion: 'none',
validatorUrl: 'none',
filter: true,
showExtensions: true,
oauth2RedirectUrl: '{$CFG_GLPI['root_doc']}/api.php/swagger-oauth-redirect',
// Sort operations by name and then by method
operationsSorter: (a, b) => {
const method_order = ['get', 'post', 'put', 'patch', 'delete'];
if (a.get('path') === b.get('path')) {
return method_order.indexOf(a.get('method')) - method_order.indexOf(b.get('method'));
}
return a.get('path').localeCompare(b.get('path'));
},
tagsSorter: (a, b) => a.localeCompare(b),
});
</script>
$script
</body>
HTML;

Expand Down Expand Up @@ -735,11 +737,14 @@ public function token(Request $request): Response
#[RouteVersion(introduced: '2.0')]
public function swaggerOAuthRedirect(Request $request): Response
{
$js_path = \htmlescape(Html::getPrefixedUrl('/lib/swagger-ui-dist/oauth2-redirect.js'));
$script = Html::script(
url: '/lib/swagger-ui-dist/oauth2-redirect.js',
minify: false
);
$content = <<<HTML
<html lang="en-US">
<head>
<script src="$js_path"></script>
$script
</head>
<body>
</body>
Expand Down
12 changes: 8 additions & 4 deletions src/Glpi/Application/View/Extension/FrontEndAssetsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use DBmysql;
use Entity;
use Glpi\Application\ImportMapGenerator;
use Glpi\Application\View\ScriptType;
use Glpi\Config\ConfigContainer;
use Glpi\Locale\LanguageRegistry;
use Glpi\Toolbox\FrontEnd;
Expand Down Expand Up @@ -354,9 +355,12 @@ public function importmap(): string
{
$import_map = ImportMapGenerator::getInstance()->generate();

return '<script type="importmap">' . json_encode(
$import_map,
JSON_PRETTY_PRINT
) . '</script>';
return Html::scriptBlock(
json_encode(
$import_map,
JSON_PRETTY_PRINT
),
ScriptType::ImportMap,
);
}
}
7 changes: 4 additions & 3 deletions src/Glpi/Marketplace/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ public static function displayList(
$plugin = new Plugin();
$plugin_message = $plugin->getPluginsUpdatableAlert();

$script = Html::scriptBlock(<<<JAVASCRIPT
var marketplace_total_plugin = {$nb_plugins};
JAVASCRIPT);
$marketplace = <<<HTML
<div class='marketplace $tab' data-tab='{$tab}'>
{$tags_list}
Expand All @@ -485,9 +488,7 @@ public static function displayList(
</a>
</div>
</div>
<script>
var marketplace_total_plugin = {$nb_plugins};
</script>
$script
HTML;
echo $marketplace;
} else {
Expand Down
39 changes: 18 additions & 21 deletions src/Reservation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* ---------------------------------------------------------------------
*/

use Glpi\Application\View\ScriptType;
use Glpi\Application\View\TemplateRenderer;
use Glpi\Event;
use Glpi\RichText\RichText;
Expand Down Expand Up @@ -592,16 +593,14 @@ public static function showCalendar(int $ID = 0)
$can_reserve_js = $can_reserve ? "true" : "false";
$now = jsescape(Session::getCurrentTime());
$default_date = jsescape($default_date);
echo <<<HTML
<script type="module">
window.Vue.createApp(window.Vue.components['Reservations/ReservationScheduler'].component, {
id: $ID,
can_reserve: $can_reserve_js,
now: '$now',
default_date: '$default_date',
}).mount('#reservations_planning_$rand');
</script>
HTML;
echo Html::scriptBlock(<<<JAVASCRIPT
window.Vue.createApp(window.Vue.components['Reservations/ReservationScheduler'].component, {
id: $ID,
can_reserve: $can_reserve_js,
now: '$now',
default_date: '$default_date',
}).mount('#reservations_planning_$rand');
JAVASCRIPT, ScriptType::Module);
}

public static function getEvents(array $params): array
Expand Down Expand Up @@ -1067,17 +1066,15 @@ public static function showForItem(CommonDBTM $item, $withtemplate = 0)
&& count(self::getReservableItemtypes()) > 0
) ? "true" : "false";
$now = jsescape(Session::getCurrentTime());
echo <<<HTML
<script type="module">
window.Vue.createApp(window.Vue.components['Reservations/ReservationScheduler'].component, {
id: $ID,
can_reserve: $can_reserve_js,
now: '$now',
default_date: '$default_date',
current_view: 'listFull',
}).mount('#reservations_planning_$rand');
</script>
HTML;
echo Html::scriptBlock(<<<JAVASCRIPT
window.Vue.createApp(window.Vue.components['Reservations/ReservationScheduler'].component, {
id: $ID,
can_reserve: $can_reserve_js,
now: '$now',
default_date: '$default_date',
current_view: 'listFull',
}).mount('#reservations_planning_$rand');
JAVASCRIPT, ScriptType::Module);
echo "</div>";
}

Expand Down
Loading
Loading