Commit b6dafd8b authored by lindonb's avatar lindonb

[ENH] In the plugin edit form for PluginModule, show the module parameters for...

[ENH] In the plugin edit form for PluginModule, show the module parameters for the saved or selected module in the form.
parent 0970b242
......@@ -6114,6 +6114,7 @@ tests/testfile.txt -text
/tiki-invite.php -text
/tiki-invited.php -text
/tiki-jscalendar.php -text
/tiki-jsmodule.php -text
/tiki-jsplugin.php -text
/tiki-kaltura_upload.php -text
/tiki-kaltura_video.php -text
......
......@@ -579,7 +579,7 @@ function parseAutoJSON(data) {
/// TODO refactor for 4.n
/* wikiplugin editor */
function popupPluginForm(area_id, type, index, pageName, pluginArgs, bodyContent, edit_icon){
function popupPluginForm(area_id, type, index, pageName, pluginArgs, bodyContent, edit_icon, selectedMod){
if (!$.ui) {
alert("dev notice: no jq.ui here?");
return popup_plugin_form(area_id, type, index, pageName, pluginArgs, bodyContent, edit_icon); // ??
......@@ -653,8 +653,17 @@ function popupPluginForm(area_id, type, index, pageName, pluginArgs, bodyContent
replaceText = false;
}
}
var form = build_plugin_form(type, index, pageName, pluginArgs, bodyContent, selectedMod);
var form = build_plugin_form(type, index, pageName, pluginArgs, bodyContent);
//with PluginModule, if the user selects another module while the edit form is open
//replace the form with a new one with fields to match the parameters for the module selected
$(form).find('tr select[name="params[module]"]').change(function() {
var npluginArgs = $.parseJSON($(form).find('input[name="args"][type="hidden"]').val());
//this is the newly selected module
var selectedMod = $(form).find('tr select[name="params[module]"]').val();
$('div.plugin input[name="type"][value="' + type + '"]').parent().parent().remove();
popupPluginForm(area_id, type, index, pageName, npluginArgs, bodyContent, edit_icon, selectedMod);
});
var $form = $(form).find('tr input[type=submit]').remove();
container.append(form);
......@@ -2521,7 +2530,7 @@ function dialogReplaceReplace( area_id ) {
if(results == null) {
return "";
} else {
} else {
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
};
......
......@@ -1280,7 +1280,7 @@ function popup_plugin_form(area_id, type, index, pageName, pluginArgs, bodyConte
handlePluginFieldsHierarchy(type);
}
function build_plugin_form( type, index, pageName, pluginArgs, bodyContent )
function build_plugin_form( type, index, pageName, pluginArgs, bodyContent, selectedMod )
{
var form = document.createElement( 'form' );
form.method = 'post';
......@@ -1304,8 +1304,40 @@ function build_plugin_form( type, index, pageName, pluginArgs, bodyContent )
hiddenIndex.name = 'index';
hiddenIndex.value = index;
form.appendChild( hiddenIndex );
var meta = tiki_plugins[type];
//
var savedArgs = document.createElement( 'input' );
savedArgs.type = 'hidden';
savedArgs.name = 'args';
savedArgs.value = $.toJSON(pluginArgs);
form.appendChild( savedArgs );
//Convert to JSON and then back to an object to break
//link between meta local variable and tiki_plugins[type] global variable.
//Otherwise each change to meta.params using the extend below was being appended to the global
//Probably a much easier way to do this
var infostring = $.toJSON(tiki_plugins[type]);
var meta = $.parseJSON(infostring);
//For PluginModule, add selected module parameters to the plugin edit form
if (type == 'module') {
//tiki_module_params is a global variable set by tiki-jsmodule.php which is loaded by tiki-setup.php
if (typeof tiki_module_params != 'undefined') {
//user has not change the module selection since opening the form
if (typeof selectedMod == 'undefined') {
//pick up the parameters of the saved module parameter
if (typeof pluginArgs.module != 'undefined') {
$.extend(meta.params, tiki_module_params[pluginArgs.module]);
//otherwise pick up the parameters of the first module option since that will be selected automatically
} else {
$.extend(meta.params, tiki_module_params[meta.params.module.options[0].value]);
}
//user has selected another module while the form was open - pick up parameters for the selected module
} else {
$.extend(meta.params, tiki_module_params[selectedMod]);
}
}
}
var header = document.createElement( 'h3' );
header.innerHTML = meta.name;
......@@ -1367,8 +1399,10 @@ function build_plugin_form( type, index, pageName, pluginArgs, bodyContent )
row = table.insertRow( rowNumber++ );
}
var value = pluginArgs.length < 1?'': pluginArgs[param];// for param like sort
build_plugin_form_row(row, param, meta.params[param].name, meta.params[param].required, value, meta.params[param].description, meta.params[param]);
//for use with PluginModule to identify saved module parameter value
var nsavedArgs = $.parseJSON($(form).find('input[name="args"][type="hidden"]').val());
//last two parameters (selectedMod and savedArgs are only needed for PluginModule
build_plugin_form_row(row, param, meta.params[param].name, meta.params[param].required, value, meta.params[param].description, meta.params[param], selectedMod, nsavedArgs);
delete potentiallyExtraPluginArgs[param];
}
......@@ -1416,8 +1450,8 @@ function build_plugin_form( type, index, pageName, pluginArgs, bodyContent )
return form;
}
function build_plugin_form_row(row, name, label_name, requiredOrSpecial, value, description, paramDef)
//last two parameters (selectedMod and savedArgs are only needed for PluginModule
function build_plugin_form_row(row, name, label_name, requiredOrSpecial, value, description, paramDef, selectedMod, savedArgs)
{
var label = row.insertCell( 0 );
......@@ -1444,8 +1478,21 @@ function build_plugin_form_row(row, name, label_name, requiredOrSpecial, value,
opt.value = paramDef.options[o].value;
var opt_text = document.createTextNode(paramDef.options[o].text);
opt.appendChild(opt_text);
if (value && opt.value == value) {
opt.selected = true;
//either not PluginModule or user has not changed module selection, so use saved value
if (typeof selectedMod == 'undefined') {
if (value && opt.value == value) {
opt.selected = true;
}
} else {
//user changed module selection in PluginModule
if (selectedMod == opt.value) {
opt.selected = true;
} else if (savedArgs.module == opt.value) {
//use later to display saved module parameter value
var savedtext = opt.innerHTML;
opt.style.fontWeight = 'bold';
opt.innerHTML = opt.innerHTML + ' -- ' + tr('saved value');
}
}
input.appendChild(opt);
}
......@@ -1479,6 +1526,17 @@ function build_plugin_form_row(row, name, label_name, requiredOrSpecial, value,
desc.innerHTML = description;
field.appendChild( desc );
}
//in PluginModule, show saved nodule parameter value if user has changed selection
//since the form changes to match the newly selected module, it's useful to show the
//saved module parameter so the user can go back to it
if (typeof savedtext != 'undefined') {
var saved = document.createElement('div');
saved.style.fontSize = 'x-small';
saved.style.fontStyle = 'italic';
saved.style.fontWeight = 'bold';
saved.innerHTML = tr('Saved value:') + ' ' + savedtext;
field.appendChild( saved );
}
if (paramDef && paramDef.filter) {
if (paramDef.filter == "pagename") {
......
......@@ -12,7 +12,7 @@ function wikiplugin_module_info()
$modlib = TikiLib::lib('mod');
$cachelib = TikiLib::lib('cache');
if (! $module_options = $cachelib->getSerialized('module_list_for_plugin' . $lang)) {
if (! $modules_options = $cachelib->getSerialized('module_list_for_plugin' . $lang)) {
$all_modules = $modlib->get_all_modules();
$all_modules_info = array_combine($all_modules, array_map(array( $modlib, 'get_module_info' ), $all_modules));
uasort($all_modules_info, 'compare_names');
......
<?php
// (c) Copyright 2002-2012 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
/*
* This is used to make module-specific parameters available to jquery
* so that the plugin edit popup form for PluginModule can include the parameters for the selected module in the form
* The java script generated defines tiki_module_params["modulename"] with meta data for the parameters of the module.
*
* Cached by language to allow translations
*/
header('content-type: application/x-javascript');
header('Cache-Control: no-cache, pre-check=0, post-check=0');
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+3600*24*365*10) . ' GMT');
require_once 'tiki-filter-base.php';
$filter = TikiFilter::get('xss');
$filter = TikiFilter::get('alpha');
$_REQUEST['language'] = isset($_GET['language']) ? $_GET['language'] = $filter->filter($_GET['language']) : '';
$cache = "temp/cache/module_ALL_".$_REQUEST['language'];
if ( file_exists($cache) ) {
readfile($cache);
exit;
}
include 'tiki-setup.php';
$modlib = TikiLib::lib('mod');
$mods = $modlib->get_all_modules();
ob_start();
?>if ( typeof tiki_module_params == 'undefined' ) { var tiki_module_params = {}; }
<?php
foreach ( $mods as $mod ):
include_once('modules/mod-func-' . $mod . '.php');
$info_func = "module_{$mod}_info";
if (function_exists($info_func)) {
$info = $info_func();
} else {
$info = false;
}
if (count($info['params']) < 1)
continue;
?>
tiki_module_params.<?php echo $mod ?> = <?php echo json_encode($info['params']) ?>;
<?php endforeach;
$content = ob_get_contents();
file_put_contents($cache, $content);
ob_end_flush();
......@@ -227,6 +227,7 @@ if ($prefs['javascript_enabled'] != 'n') {
$headerlib->add_jsfile('lib/jquery_tiki/tiki-jquery.js');
$headerlib->add_jsfile('lib/jquery_tiki/tiki-maps.js');
$headerlib->add_jsfile('lib/jquery/jquery.json-2.2.js');
$headerlib->add_jsfile('tiki-jsmodule.php?language='.$prefs['language'], 'dynamic');
if ($prefs['feature_syntax_highlighter'] == 'y') {
//add codemirror stuff
......
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