Commit 91356a1b authored by Nigel McNie's avatar Nigel McNie
Browse files

Export UI - selection of what to export page.

This page presents a choice of export format, and whether to export everything or just a list of views. It simplifies the UI by hiding the view selector if javascript is enabled.
parent 010dcd27
......@@ -27,26 +27,59 @@
define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/export');
require(dirname(dirname(__FILE__)) . '/init.php');
define('TITLE', get_string('export', 'export'));
define('TITLE', get_string('exportyourportfolio', 'export'));
require_once('file.php');
$form = pieform(array(
'name' => 'export',
'elements' => array(
'format' => array(
'type' => 'select',
'title' => 'Export format',
'options' => array(
'leap' => 'LEAP2A',
'html' => 'HTML',
),
'defaultvalue' => 'html',
),
'submit' => array(
'type' => 'submit',
'value' => 'Get export',
$exportoptions = array();
foreach (plugins_installed('export') as $plugin) {
safe_require('export', $plugin->name);
$exportoptions[$plugin->name] = array(
'text' => call_static_method(generate_class_name('export', $plugin->name), 'get_title'),
'description' => call_static_method(generate_class_name('export', $plugin->name), 'get_description'),
);
}
$elements = array(
'format' => array(
'type' => 'radio',
'options' => $exportoptions,
'defaultvalue' => 'html',
'separator' => '</div><div>',
),
'what' => array(
'type' => 'radio',
'options' => array(
'all' => get_string('allmydata', 'export'),
'views' => get_string('justsomeviewsanddata', 'export'),
),
'separator' => '</div><div>',
'defaultvalue' => 'all',
),
);
if ($viewids = get_column('view', 'id', 'owner', $USER->get('id'))) {
foreach ($viewids as $viewid) {
$view = new View($viewid);
$elements['view_' . $viewid] = array(
'type' => 'checkbox',
'title' => $view->get('title'),
'description' => $view->get('description'),
'viewlink' => get_config('wwwroot') . 'view/view.php?id=' . $viewid,
);
}
}
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('generateexport', 'export'),
);
$form = pieform(array(
'name' => 'export',
'template' => 'export.php',
'templatedir' => pieform_template_dir('export.php'),
'autofocus' => false,
'elements' => $elements
));
......@@ -57,15 +90,37 @@ function export_submit(Pieform $form, $values) {
$user = new User();
$user->find_by_id($USER->get('id'));
$class = 'PluginExport' . ucfirst($values['format']);
$exporter = new $class($user, EXPORT_ALL_VIEWS, EXPORT_ALL_ARTEFACTS);
$class = generate_class_name('export', $values['format']);
switch($values['what']) {
case 'all':
$exporter = new $class($user, PluginExport::EXPORT_ALL_VIEWS, PluginExport::EXPORT_ALL_ARTEFACTS);
break;
case 'views':
$views = array();
foreach ($values as $key => $value) {
if (substr($key, 0, 5) == 'view_' && $value) {
$views[] = intval(substr($key, 5));
}
}
$exporter = new $class($user, $views, PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS);
break;
default:
throw new SystemException("Unable to export a portfolio using those options");
}
$zipfile = $exporter->export();
serve_file($exporter->get('exportdir') . $zipfile, $zipfile, 'application/x-zip', array('lifetime' => 0));
exit;
}
$smarty = smarty();
$smarty = smarty(
array('js/preview.js', 'js/export.js'),
array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'),
array(),
array('stylesheets' => array('style/views.css'))
);
$smarty->assign('heading', '');
$smarty->assign('form', $form);
$smarty->display('export/index.tpl');
......
/**
* JS behaviour for the export UI
*
* Copyright (C) 2009 Catalyst IT
*
* This file is licensed under the same terms as Mahara itself
*/
addLoadEvent(function() {
var container = $('whatviews');
var containerVisible = false;
var radios = [];
function toggleRadios(state) {
forEach(radios, function(r) {
r.disabled = state;
});
}
var enableRadios = partial(toggleRadios, '');
var disableRadios = partial(toggleRadios, 'disabled');
// Make the radio buttons show/hide the view selector
forEach(getElementsByTagAndClassName('input', 'radio', 'whattoexport-buttons'), function(radio) {
radios.push(radio);
connect(radio, 'onclick', function(e) {
if (radio.value == 'views' && radio.checked && !containerVisible) {
disableRadios();
containerVisible = true;
slideDown(container, {'duration': 0.5, 'afterFinish': enableRadios, 'beforeSetup': function() { removeElementClass(container, 'js-hidden'); }});
}
else if (radio.checked && radio.value != 'views' && containerVisible) {
disableRadios();
containerVisible = false;
slideUp(container, {'duration': 0.5, 'afterFinish': enableRadios});
}
});
});
// Hook up 'click to preview' links
forEach(getElementsByTagAndClassName('a', 'viewlink', container), function(i) {
disconnectAll(i);
setNodeAttribute(i, 'title', 'Click to preview');
connect(i, 'onclick', function (e) {
e.stop();
var href = getNodeAttribute(this, 'href');
var params = parseQueryString(href.substring(href.indexOf('?') + 1, href.length));
sendjsonrequest(config['wwwroot'] + 'view/viewcontent.json.php', params, 'POST', partial(showPreview, 'big'));
});
});
});
......@@ -26,4 +26,14 @@
defined('INTERNAL') || die();
$string['export'] = 'Export';
$string['allmydata'] = 'All my data';
$string['chooseanexportformat'] = 'Choose an export format';
$string['clicktopreview'] = 'Click to preview';
$string['Export'] = 'Export';
$string['exportyourportfolio'] = 'Export Your Portfolio';
$string['generateexport'] = 'Generate export';
$string['justsomeviewsanddata'] = 'Just some views and their associated data';
$string['viewstoexport'] = 'Views to export';
$string['whatdoyouwanttoexport'] = 'What do you want to export?';
?>
......@@ -1697,7 +1697,7 @@ function mahara_standard_nav() {
array(
'path' => 'myportfolio/export',
'url' => 'export/',
'title' => get_string('export', 'export'),
'title' => get_string('Export', 'export'),
'weight' => 30,
),
array(
......
<?php
function export_form_cell_html($element) {
$strclicktopreview = get_string('clicktopreview', 'export');
$previewimg = theme_get_url('images/icon-display.png');
$strpreview = get_string('Preview');
return <<<EOF
<td>
{$element['html']} {$element['labelhtml']}
<div>{$element['description']}</div>
<div><a href="{$element['viewlink']}" class="viewlink nojs-hidden-inline" target="_blank">{$strclicktopreview}</a></div>
</td>
EOF;
}
echo $form_tag;
echo '<h3>' . get_string('chooseanexportformat', 'export') . '</h3>';
echo '<div class="element">';
echo '<div>' . $elements['format']['html'] . '</div>';
echo '</div>';
echo '<h3>' . get_string('whatdoyouwanttoexport', 'export') . '</h3>';
echo '<div class="element" id="whattoexport-buttons">';
echo '<div>'. $elements['what']['html'] . '</div>';
echo '</div>';
echo '<div id="whatviews" class="js-hidden"><fieldset><legend>' . get_string('viewstoexport', 'export') . "</legend>\n";
$body = array();
$row = $col = 0;
foreach ($elements as $key => $element) {
if (substr($key, 0, 5) == 'view_') {
$body[$row][$col] = export_form_cell_html($element);
$col++;
if ($col % 3 == 0) {
$row++;
$col = 0;
}
}
}
if ($body) {
echo "<table>\n";
foreach ($body as $rownum => $row) {
if ($rownum == 0) {
switch (count($row)) {
case 2:
echo '<colgroup><col width="50%"><col width="50%"></colgroup>' . "\n";
break;
case 3:
echo '<colgroup><col width="33%"><col width="33%"><col width="33%"></colgroup>' . "\n";
break;
}
}
echo ' <tr class="r' . $rownum % 2 . "\">\n";
$i = 0;
foreach ($row as $col) {
echo $col . "\n";
$i++;
}
for (; $i < 3; $i++) {
echo "<td></td>\n";
}
echo " </tr>\n";
}
echo "</table>\n";
}
echo '</fieldset></div>';
echo '<div id="export_submit_container">';
echo $elements['submit']['html'];
echo '</div>';
echo $hidden_elements;
echo '</form>';
?>
......@@ -2691,6 +2691,42 @@ span.breadcrumbs a {
display: block;
}
/* EXPORT */
#export h3 {
margin: .5em 0;
}
#export .radio-description {
padding-left: 2em;
}
#export fieldset {
padding: .5em;
margin: .5em;
}
#export .element div {
padding-bottom: .25em;
}
#export .view {
float: left;
padding-right: 2em;
white-space: nowrap;
}
#export fieldset {
border: none;
}
#export fieldset table {
width: 95%;
margin: 0 auto;
}
#export fieldset table div {
padding-left: 1.75em;
}
#export fieldset label {
color: #8598a7;
}
#export_submit_container {
text-align: center;
}
/* ADMIN HOME */
/* Administration Home styles */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment