mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
Merge branch 'MDL-57149-master' of git://github.com/junpataleta/moodle
This commit is contained in:
commit
b06f33d5cc
110
admin/tool/langimport/classes/output/langimport_page.php
Normal file
110
admin/tool/langimport/classes/output/langimport_page.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Language import page.
|
||||
*
|
||||
* @package tool_langimport
|
||||
* @copyright 2016 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_langimport\output;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use moodle_url;
|
||||
use renderable;
|
||||
use renderer_base;
|
||||
use stdClass;
|
||||
use templatable;
|
||||
|
||||
/**
|
||||
* Language import page class.
|
||||
*
|
||||
* @package tool_langimport
|
||||
* @copyright 2016 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class langimport_page implements renderable, templatable {
|
||||
|
||||
/** @var array Array of currently installed languages. */
|
||||
protected $installedlanguages;
|
||||
|
||||
/** @var array Array of languages that can be installed. */
|
||||
protected $availablelanguages;
|
||||
|
||||
/** @var moodle_url The URL to be used for uninstalling the selected existing language packs. */
|
||||
protected $uninstallurl;
|
||||
|
||||
/** @var moodle_url The URL to be used for updating the installed language packs. */
|
||||
protected $updateurl;
|
||||
|
||||
/** @var moodle_url The URL to be used for installing the selected language packs to be installed. */
|
||||
protected $installurl;
|
||||
|
||||
|
||||
/**
|
||||
* langimport_page constructor.
|
||||
*
|
||||
* @param array $installedlanguages Array of currently installed languages.
|
||||
* @param array $availablelanguages Array of languages that can be installed.
|
||||
* @param moodle_url $uninstallurl The URL to be used for uninstalling the selected existing language packs.
|
||||
* @param moodle_url $updateurl The URL to be used for updating the installed language packs.
|
||||
* @param moodle_url $installurl The URL to be used for installing the selected language packs to be installed.
|
||||
*/
|
||||
public function __construct($installedlanguages, $availablelanguages, $uninstallurl, $updateurl, $installurl) {
|
||||
$this->installedlanguages = $installedlanguages;
|
||||
$this->availablelanguages = $availablelanguages;
|
||||
$this->uninstallurl = $uninstallurl;
|
||||
$this->updateurl = $updateurl;
|
||||
$this->installurl = $installurl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the data.
|
||||
*
|
||||
* @param renderer_base $output
|
||||
* @return stdClass
|
||||
*/
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$data = new stdClass();
|
||||
$data->uninstallurl = $this->uninstallurl;
|
||||
$data->sesskey = sesskey();
|
||||
|
||||
$data->installedoptions = [];
|
||||
foreach ($this->installedlanguages as $code => $language) {
|
||||
$option = new stdClass();
|
||||
$option->value = $code;
|
||||
$option->text = $language;
|
||||
$data->installedoptions[] = $option;
|
||||
}
|
||||
|
||||
$data->updateurl = $this->updateurl;
|
||||
|
||||
if (!empty($this->availablelanguages)) {
|
||||
$data->toinstalloptions = [];
|
||||
foreach ($this->availablelanguages as $code => $language) {
|
||||
$option = new stdClass();
|
||||
$option->value = $code;
|
||||
$option->text = $language;
|
||||
$data->toinstalloptions[] = $option;
|
||||
}
|
||||
$data->installurl = $this->installurl;
|
||||
$data->caninstall = true;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
50
admin/tool/langimport/classes/output/renderer.php
Normal file
50
admin/tool/langimport/classes/output/renderer.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Renderers.
|
||||
*
|
||||
* @package tool_langimport
|
||||
* @copyright 2016 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_langimport\output;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use plugin_renderer_base;
|
||||
|
||||
/**
|
||||
* Renderer class.
|
||||
*
|
||||
* @package tool_langimport
|
||||
* @copyright 2016 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Defer to template.
|
||||
*
|
||||
* @param langimport_page $page
|
||||
* @return string
|
||||
*/
|
||||
public function render_langimport_page(langimport_page $page) {
|
||||
$data = $page->export_for_template($this);
|
||||
return parent::render_from_template('tool_langimport/langimport', $data);
|
||||
}
|
||||
}
|
@ -124,23 +124,22 @@ if ($availablelangs = $controller->availablelangs) {
|
||||
} else {
|
||||
$remote = false;
|
||||
$availablelangs = array();
|
||||
echo $OUTPUT->box_start();
|
||||
$a = [
|
||||
'src' => $controller->lang_pack_url(),
|
||||
'dest' => $CFG->dataroot.'/lang/',
|
||||
];
|
||||
print_string('downloadnotavailable', 'tool_langimport', $a);
|
||||
echo $OUTPUT->box_end();
|
||||
$errormessage = get_string('downloadnotavailable', 'tool_langimport', $a);
|
||||
\core\notification::error($errormessage);
|
||||
}
|
||||
|
||||
if ($controller->info) {
|
||||
$info = implode('<br />', $controller->info);
|
||||
echo $OUTPUT->notification($info, 'notifysuccess');
|
||||
\core\notification::success($info);
|
||||
}
|
||||
|
||||
if ($controller->errors) {
|
||||
$info = implode('<br />', $controller->errors);
|
||||
echo $OUTPUT->notification($info, 'notifyproblem');
|
||||
\core\notification::error($info);
|
||||
}
|
||||
|
||||
if ($missingparents) {
|
||||
@ -155,67 +154,29 @@ if ($missingparents) {
|
||||
}
|
||||
}
|
||||
$info = get_string('missinglangparent', 'tool_langimport', $a);
|
||||
echo $OUTPUT->notification($info, 'notifyproblem');
|
||||
\core\notification::error($info);
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->box_start();
|
||||
|
||||
echo html_writer::start_tag('table');
|
||||
echo html_writer::start_tag('tr');
|
||||
|
||||
// list of installed languages
|
||||
$url = new moodle_url('/admin/tool/langimport/index.php', array('mode' => DELETION_OF_SELECTED_LANG));
|
||||
echo html_writer::start_tag('td', array('valign' => 'top'));
|
||||
echo html_writer::start_tag('form', array('id' => 'uninstallform', 'action' => $url->out(), 'method' => 'post'));
|
||||
echo html_writer::start_tag('fieldset');
|
||||
echo html_writer::label(get_string('installedlangs', 'tool_langimport'), 'menuuninstalllang');
|
||||
echo html_writer::empty_tag('br');
|
||||
echo html_writer::select($installedlangs, 'uninstalllang[]', '', false, array('size' => 15, 'multiple' => 'multiple'));
|
||||
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
|
||||
echo html_writer::empty_tag('br');
|
||||
echo html_writer::empty_tag('input', array('id' => 'languninstallbutton',
|
||||
'type' => 'submit',
|
||||
'value' => get_string('uninstall', 'tool_langimport'))
|
||||
);
|
||||
echo html_writer::end_tag('fieldset');
|
||||
echo html_writer::end_tag('form');
|
||||
$uninstallurl = new moodle_url('/admin/tool/langimport/index.php', array('mode' => DELETION_OF_SELECTED_LANG));
|
||||
$updateurl = null;
|
||||
if ($remote) {
|
||||
$url = new moodle_url('/admin/tool/langimport/index.php', array('mode' => UPDATE_ALL_LANG));
|
||||
echo html_writer::start_tag('form', array('id' => 'updateform', 'action' => $url->out(), 'method' => 'post'));
|
||||
echo html_writer::tag('fieldset', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('updatelangs','tool_langimport'))));
|
||||
echo html_writer::end_tag('form');
|
||||
$updateurl = new moodle_url('/admin/tool/langimport/index.php', array('mode' => UPDATE_ALL_LANG));
|
||||
}
|
||||
echo html_writer::end_tag('td');
|
||||
$installurl = new moodle_url('/admin/tool/langimport/index.php', array('mode' => INSTALLATION_OF_SELECTED_LANG));
|
||||
|
||||
// list of available languages
|
||||
// List of available languages.
|
||||
$options = array();
|
||||
foreach ($availablelangs as $alang) {
|
||||
if (!empty($alang[0]) and trim($alang[0]) !== 'en' and !$controller->is_installed_lang($alang[0], $alang[1])) {
|
||||
$options[$alang[0]] = $alang[2].' ‎('.$alang[0].')‎';
|
||||
}
|
||||
}
|
||||
if (!empty($options)) {
|
||||
echo html_writer::start_tag('td', array('valign' => 'top'));
|
||||
$url = new moodle_url('/admin/tool/langimport/index.php', array('mode' => INSTALLATION_OF_SELECTED_LANG));
|
||||
echo html_writer::start_tag('form', array('id' => 'installform', 'action' => $url->out(), 'method' => 'post'));
|
||||
echo html_writer::start_tag('fieldset');
|
||||
echo html_writer::label(get_string('availablelangs','install'), 'menupack');
|
||||
echo html_writer::empty_tag('br');
|
||||
echo html_writer::select($options, 'pack[]', '', false, array('size' => 15, 'multiple' => 'multiple'));
|
||||
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
|
||||
echo html_writer::empty_tag('br');
|
||||
echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('install','tool_langimport')));
|
||||
echo html_writer::end_tag('fieldset');
|
||||
echo html_writer::end_tag('form');
|
||||
echo html_writer::end_tag('td');
|
||||
}
|
||||
|
||||
echo html_writer::end_tag('tr');
|
||||
echo html_writer::end_tag('table');
|
||||
echo $OUTPUT->box_end();
|
||||
$renderable = new \tool_langimport\output\langimport_page($installedlangs, $options, $uninstallurl, $updateurl, $installurl);
|
||||
$output = $PAGE->get_renderer('tool_langimport');
|
||||
echo $output->render($renderable);
|
||||
|
||||
$uninstallurl = new moodle_url('/admin/tool/langimport/index.php');
|
||||
$PAGE->requires->strings_for_js(array('uninstallconfirm', 'uninstall', 'selectlangs', 'noenglishuninstall'),
|
||||
'tool_langimport');
|
||||
$PAGE->requires->yui_module('moodle-core-languninstallconfirm',
|
||||
@ -223,4 +184,3 @@ $PAGE->requires->yui_module('moodle-core-languninstallconfirm',
|
||||
array(array('uninstallUrl' => $uninstallurl->out()))
|
||||
);
|
||||
echo $OUTPUT->footer();
|
||||
die();
|
||||
|
@ -1,9 +1,5 @@
|
||||
#page-admin-tool-langimport-index .generalbox table {
|
||||
#page-admin-tool-langimport-index .langimport {
|
||||
margin: auto;
|
||||
float: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#page-admin-tool-langimport-index .generalbox,
|
||||
#page-admin-tool-langimport-index .generalbox table {
|
||||
text-align: center;
|
||||
}
|
||||
|
117
admin/tool/langimport/templates/langimport.mustache
Normal file
117
admin/tool/langimport/templates/langimport.mustache
Normal file
@ -0,0 +1,117 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template tool_langimport/langimport
|
||||
|
||||
Template for the language import page.
|
||||
|
||||
Classes required for JS:
|
||||
* none
|
||||
|
||||
Data attributes required for JS:
|
||||
* none
|
||||
|
||||
Context variables required for this template:
|
||||
* sesskey string The session key.
|
||||
* uninstallurl string The URL for the uninstall action.
|
||||
* updateurl string The URL for the update-language-packs action.
|
||||
* installurl string The URL for the install action.
|
||||
* installedoptions array The list of languages installed.
|
||||
* toinstalloptions array The list of languages to be installed.
|
||||
* caninstall boolean Flag to indicate if there are language packs that can be installed.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"sesskey": "sesskey",
|
||||
"uninstallurl": "#",
|
||||
"updateurl": "#",
|
||||
"installurl": "#",
|
||||
"installedoptions": [
|
||||
{
|
||||
"value": "en",
|
||||
"text": "English",
|
||||
"selected": true
|
||||
}
|
||||
],
|
||||
"toinstalloptions": [
|
||||
{
|
||||
"value": "ja",
|
||||
"text": "Japanese"
|
||||
},
|
||||
{
|
||||
"value": "fr",
|
||||
"text": "French"
|
||||
},
|
||||
{
|
||||
"value": "es",
|
||||
"text": "Spanish"
|
||||
}
|
||||
],
|
||||
"caninstall": true
|
||||
}
|
||||
}}
|
||||
<div class="container-fluid langimport">
|
||||
<div class="row row-fluid rtl-compatible">
|
||||
<div class="col-md-{{#caninstall}}6{{/caninstall}}{{^caninstall}}12{{/caninstall}} span{{#caninstall}}6{{/caninstall}}{{^caninstall}}12{{/caninstall}} m-b-1">
|
||||
<form id="uninstallform" action="{{uninstallurl}}" method="post">
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label for="menuuninstalllang">{{#str}}installedlangs, tool_langimport{{/str}}</label>
|
||||
<select size="15" multiple="multiple" id="menuuninstalllang" class="form-control input-block-level" name="uninstalllang[]">
|
||||
{{#installedoptions}}
|
||||
<option value="{{value}}" {{#selected}}selected="selected"{{/selected}}>{{{text}}}</option>
|
||||
{{/installedoptions}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="hidden" name="sesskey" value="{{sesskey}}">
|
||||
<input id="languninstallbutton" type="submit" value="{{#str}}uninstall, tool_langimport{{/str}}" class="btn btn-default">
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
{{#updateurl}}
|
||||
<div>
|
||||
<form id="updateform" action="{{updateurl}}" method="post">
|
||||
<fieldset>
|
||||
<input type="submit" value="{{#str}}updatelangs, tool_langimport{{/str}}" class="btn btn-default">
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
{{/updateurl}}
|
||||
</div>
|
||||
{{#caninstall}}
|
||||
<div class="col-md-6 span6 m-b-1">
|
||||
<form id="installform" action="{{installurl}}" method="post">
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label for="menupack">{{#str}}availablelangs, install{{/str}}</label>
|
||||
<select size="15" multiple="multiple" class="form-control input-block-level" id="menupack" name="pack[]">
|
||||
{{#toinstalloptions}}
|
||||
<option value="{{value}}" {{#selected}}selected="selected"{{/selected}}>{{{text}}}</option>
|
||||
{{/toinstalloptions}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="hidden" name="sesskey" value="{{sesskey}}">
|
||||
<input type="submit" value="{{#str}}install, tool_langimport{{/str}}" class="btn btn-default">
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
{{/caninstall}}
|
||||
</div>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user