Skip to content

Commit

Permalink
Item12952: support undefined values for selected keys
Browse files Browse the repository at this point in the history
  • Loading branch information
crawford authored and gac410 committed Sep 12, 2014
1 parent 2195822 commit 3f2295d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 27 deletions.
85 changes: 61 additions & 24 deletions pub/System/ConfigurePlugin/configure.uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ var $TRUE = 1;
return $image;
}

// Find all modified values, and return key-values
function modified_values() {
var set = {};
$('.value_modified').each(function() {
var handler = $(this).data('value_handler');
set[handler.spec.keys] = handler.currentValue();
});
return set;
}

// Make an RPC call
function RPC(method, rid, params, report, $whirly) {
$.jsonRpc(
Expand Down Expand Up @@ -87,7 +97,7 @@ var $TRUE = 1;
// Update the key block report
var has = { errors: 0, warnings: 0 };
if (r.reports) {
var $reports = $('#' + id + '_reports');
var $reports = $('#REP' + id);
$.each(r.reports, function(index, rep) {
// An empty information message can be ignored
if (!(rep.level == 'notes' && rep.message == '')) {
Expand All @@ -110,7 +120,7 @@ var $TRUE = 1;
var sid = _id_ify(pel);
refresh_tabs[sid] = {};
$.each(has, function (index, level) {
$('#' + sid + '_reports').first(
$('#REP' + sid).first(
function() {
var $whine = $('<div>' + path + ' > '
+ r.keys
Expand All @@ -129,7 +139,7 @@ var $TRUE = 1;

// Refresh the tab element
$.each(refresh_tabs, function(id, has) {
var $tab = $('#' + id + '_tab');
var $tab = $('#TAB' + id);
if ($tab) {
$tab.removeClass('warnings').removeClass('errors');
if (has['warnings'])
Expand Down Expand Up @@ -202,12 +212,10 @@ var $TRUE = 1;
update_modified_default($node);

var handler = $node.data('value_handler');
var params = { keys: [ handler.spec.keys ], set: {} };
// Find and set *all* modified values
$('.value_modified').each(function() {
var handler = $(this).data('value_handler');
params.set[handler.spec.keys] = handler.currentValue();
});
var params = {
keys: [ handler.spec.keys ],
set: modified_values()
};

RPC('check_current_value',
'ccv' + handler.spec.keys,
Expand All @@ -223,16 +231,11 @@ var $TRUE = 1;
wizard: fb.wizard,
keys: handler.spec.keys,
method: fb.method,
set: {},
set: modified_values(),
cfgusername: $('#username').val(),
cfgpassword: $('#password').val()
};

$('.value_modified').each(function() {
var handler = $(this).data('value_handler');
params.set[handler.spec.keys] = handler.currentValue();
});

RPC('wizard',
'cw' + handler.spec.keys,
params,
Expand All @@ -259,6 +262,40 @@ var $TRUE = 1;
});
$key.append($ui);

if (spec.UNDEFINEDOK == 1) {
// If undefined is OK, then we add a checkbox that
// needs to be clicked to see the value input.
// if it isn't checked, the value is undefined; if it
// is checked, then the value is at least ''. This
// works for all types, but only really makes sense on
// string types.
$node.addClass('undefinedOK');
var id = _id_ify('UOK' + spec.keys);
$key.append("<label for='"+id+"'></label>");
var $butt = $('<input type="checkbox" id="' + id
+ '">');
$butt.attr("title", "Enable this option to take a value");
$butt.click(function() {
if ( $(this).attr("checked") )
$ui.show();
else
$ui.hide();
update_modified_default( $key );
}).show();
// Add a null_if handler to intercent the currentValue
// of the keys (see types.js)
handler.null_if = function () {
return !$butt.attr("checked");
}
if (typeof(spec.current_value) == 'undefined'
|| spec.current_value == null) {
$ui.hide();
} else {
$butt.attr("checked", "checked");
}
$ui.before($butt);
}

var $button = $('<button class="undo_button control_button"></button>');
$button.attr('title', 'Reset to configured value: '
+ spec.current_value);
Expand Down Expand Up @@ -352,7 +389,7 @@ var $TRUE = 1;
},
function(response) {
var $report = $('<div class="reports"></div>');
$report.attr('id', _id_ify(spec.headline) + '_reports');
$report.attr('id', _id_ify('REP-' + spec.headline));
$node.append($report);

if (spec.desc) {
Expand Down Expand Up @@ -465,7 +502,8 @@ var $TRUE = 1;
}
}));

var id = "NO_ID";
var id;

if (entry.keys != null) {
id = _id_ify(entry.keys);
$node.addClass("keyed");
Expand All @@ -491,7 +529,7 @@ var $TRUE = 1;
}
$node.attr('id', id + '_block');
var $report = $('<div class="reports"></div>');
$report.attr('id', id + '_reports');
$report.attr('id', 'REP' + id);
$node.append($report);
if (entry.desc) {
$node.append('<div class="description">'
Expand All @@ -513,7 +551,7 @@ var $TRUE = 1;
// cancel it in the beforeLoad, below.
+ json_rpc_url
+ '"><span class="tab" id="'
+ _id_ify(entry.headline) + '_tab">'
+ _id_ify('TAB' + entry.headline) + '">'
+ entry.headline + '</span></a></li>');
$li.data('spec.entry', entry);
if ($children == null) {
Expand Down Expand Up @@ -601,18 +639,17 @@ var $TRUE = 1;
$('#auth_prompt').dialog("open");
});

$('#showExpert').button();

$('#saveButton').button({disabled: true}).click(function() {
// SMELL: Save wizard v.s. changecfg in ConfigurePlugin
confirm_action = function() {
var params = {
wizard: 'Save',
method: 'save',
set: {}
set: modified_values()
};
$('.value_modified').each(function() {
var handler = $(this).data('value_handler');
params.set[handler.spec.keys] = handler.currentValue();
});

RPC('wizard',
'save',
params,
Expand Down
10 changes: 8 additions & 2 deletions pub/System/ConfigurePlugin/types.uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ function _id_ify(id) {
id = id.replace(/[}{]/g, '-');
id = id.replace(/['"]/g, '');
id = id.replace(/[^A-Za-z0-9_]/g, '-');
return 'cfg' + id;
return 'i' + id;
}

Types.BaseType = Class.extend({
// Set to a function that returns true if the current value
// is to be null
null_if: null,

init: function(spec) {
this.spec = spec;
},
Expand Down Expand Up @@ -57,6 +61,8 @@ Types.BaseType = Class.extend({
},

currentValue: function() {
if (this.null_if != null && this.null_if())
return null;
return this.ui.val();
},

Expand All @@ -75,7 +81,7 @@ Types.BaseType = Class.extend({
isModified: function() {
var cv = this.spec.current_value;
if (typeof(cv) == 'undefined')
cv = '';
cv = null;
return this.currentValue() != cv;
},

Expand Down
2 changes: 1 addition & 1 deletion templates/configure.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ configure.js script.
</head>
<body>
<img src="%PUBURLPATH%/%SYSTEMWEB%/ProjectLogos/foswiki-logo.png" alt="Foswiki configure"/>
<div class="top_level_buttons"><button id="webCheckButton">Study Web Server</button> <input id="showExpert" disabled="disabled" type="checkbox">Show expert options</input> <button id="saveButton">Save</button></div>
<div class="top_level_buttons"><button id="webCheckButton">Study Web Server</button> <input id="showExpert" type="checkbox"><label for="showExpert">Show expert options</label> <button id="saveButton">Save</button></div>
<div style="width:60%">
This is Foswiki <tt>configure</tt>. From this interface you can access all the setup for your Foswiki. Use
<button class="help_button control_button" name="info-icon"></button> to get help on an item.
Expand Down

0 comments on commit 3f2295d

Please sign in to comment.