move index file generation into extra file PVE/ExtJSIndex.pm

And load locale files instead of including them into image.
This commit is contained in:
Dietmar Maurer 2014-08-04 08:32:21 +02:00
parent 5afee956c5
commit cba684d8d6
5 changed files with 74 additions and 56 deletions

66
PVE/ExtJSIndex.pm Normal file
View File

@ -0,0 +1,66 @@
package PVE::ExtJSIndex;
use strict;
use warnings;
sub get_index {
my ($lang, $username, $csrftoken, $console) = @_;
my $page = <<_EOD;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=10">
<title>Proxmox Virtual Environment</title>
<link rel="stylesheet" type="text/css" href="/pve2/ext4/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="/pve2/css/ext-pve.css" />
_EOD
my $langfile = "/usr/share/pve-manager/locale/pve-lang-${lang}.js";
if (-f $langfile) {
$page .= "<script type='text/javascript' src='/pve2/locale/pve-lang-${lang}.js'></script>";
} else {
$page .= '<script type="text/javascript">function gettext(buf) { return buf; }</script>';
}
$page .= <<_EOD;
<script type="text/javascript" src="/pve2/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="/pve2/ext4/pvemanagerlib.js"></script>
<script type="text/javascript" src="/pve2/ext4/locale/ext-lang-${lang}.js"></script>
_EOD
my $jssrc = <<_EOJS;
if (!PVE) PVE = {};
PVE.UserName = '$username'
PVE.CSRFPreventionToken = '$csrftoken';
_EOJS
my $workspace = defined($console) ?
"PVE.ConsoleWorkspace" : "PVE.StdWorkspace";
$jssrc .= <<_EOJS;
// we need this (the java applet ignores the zindex)
Ext.useShims = true;
Ext.History.fieldid = 'x-history-field';
Ext.onReady(function() { Ext.create('$workspace');});
_EOJS
$page .= <<_EOD;
<script type="text/javascript">$jssrc</script>
</head>
<body>
<!-- Fields required for history management -->
<form id="history-form" class="x-hidden">
<input type="hidden" id="x-history-field"/>
</form>
</body>
</html>
_EOD
return $page;
}
1;

View File

@ -6,6 +6,7 @@ PERLSOURCE = \
API2.pm \
API2Tools.pm \
API2Client.pm \
ExtJSIndex.pm \
HTTPServer.pm \
APIDaemon.pm \
REST.pm \

View File

@ -23,6 +23,8 @@ use PVE::API2;
use PVE::API2::Formatter::Standard;
use PVE::API2::Formatter::HTML;
use PVE::ExtJSIndex;
my $pidfile = "/var/run/pveproxy/pveproxy.pid";
my $lockfile = "/var/lock/pveproxy.lck";
@ -78,6 +80,7 @@ eval {
my $dirs = {};
add_dirs($dirs, '/pve2/locale/', '/usr/share/pve-manager/locale/');
add_dirs($dirs, '/pve2/ext4/', '/usr/share/pve-manager/ext4/');
add_dirs($dirs, '/pve2/images/' => '/usr/share/pve-manager/images/');
add_dirs($dirs, '/pve2/css/' => '/usr/share/pve-manager/css/');
@ -194,63 +197,9 @@ sub get_index {
}
}
my $workspace = defined($args->{console}) ?
"PVE.ConsoleWorkspace" : "PVE.StdWorkspace";
$username = '' if !$username;
my $jssrc = <<_EOJS;
if (!PVE) PVE = {};
PVE.UserName = '$username';
PVE.CSRFPreventionToken = '$token';
_EOJS
my $langfile = "/usr/share/pve-manager/ext4/locale/ext-lang-${lang}.js";
$jssrc .= PVE::Tools::file_get_contents($langfile) if -f $langfile;
my $i18nsrc;
$langfile = "/usr/share/pve-manager/root/pve-lang-${lang}.js";
if (-f $langfile) {
$i18nsrc = PVE::Tools::file_get_contents($langfile);
} else {
$i18nsrc = 'function gettext(buf) { return buf; }';
}
$jssrc .= <<_EOJS;
// we need this (the java applet ignores the zindex)
Ext.useShims = true;
Ext.History.fieldid = 'x-history-field';
Ext.onReady(function() { Ext.create('$workspace');});
_EOJS
my $page = <<_EOD;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=10">
<title>Proxmox Virtual Environment</title>
<link rel="stylesheet" type="text/css" href="/pve2/ext4/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="/pve2/css/ext-pve.css" />
<script type="text/javascript">$i18nsrc</script>
<script type="text/javascript" src="/pve2/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="/pve2/ext4/pvemanagerlib.js"></script>
<script type="text/javascript">$jssrc</script>
</head>
<body>
<!-- Fields required for history management -->
<form id="history-form" class="x-hidden">
<input type="hidden" id="x-history-field"/>
</form>
</body>
</html>
_EOD
my $page = PVE::ExtJSIndex::get_index($lang, $username, $token, $args->{console});
my $headers = HTTP::Headers->new(Content_Type => "text/html; charset=utf-8");
my $resp = HTTP::Response->new(200, "OK", $headers, $page);

View File

@ -14,6 +14,7 @@ DOCDIR=${DESTDIR}/usr/share/doc/${PACKAGE}
PODDIR=${DESTDIR}/usr/share/doc/${PACKAGE}/pod
WWWBASEDIR=${DESTDIR}/usr/share/${PACKAGE}
WWWROOTDIR=${WWWBASEDIR}/root
WWWLOCALEDIR=${WWWBASEDIR}/locale
WWWIMAGEDIR=${WWWBASEDIR}/images
WWWEXT4DIR=${WWWBASEDIR}/ext4
WWWCSSDIR=${WWWBASEDIR}/css

View File

@ -20,7 +20,8 @@ pve-lang-%.js: %.po
.PHONY: install
install: $(patsubst %, pve-lang-%.js, $(LINGUAS))
install -m 0644 -o www-data -g www-data $^ ${WWWROOTDIR}
install -d ${WWWLOCALEDIR}
install -m 0644 -o www-data -g www-data $^ ${WWWLOCALEDIR}
clean:
rm -rf *~ *.po.tmp *.js.tmp pve-lang-*.js