Skip to content

Commit

Permalink
Item15117: fix support for strikeone protection
Browse files Browse the repository at this point in the history
Item14535: fix use of jsonrpc params
  • Loading branch information
MichaelDaum committed May 5, 2022
1 parent 6fae466 commit 1e9a0ff
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 33 deletions.
3 changes: 2 additions & 1 deletion data/System/MultiSaveContrib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ All form elements that changed their values will be flagged so using css automat

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 05 May 2022: | fix use if jsonrpc params; add support for saving preference values in addition to formfield values|
| 25 Sep 2017: | fixed use of =param()= api |
| 20 Sep 2014: | fixed saving of deselected checkboxes and radioboxes |
| 04 Sep 2013: | fixed manifest |
| 30 May 2013: | initial release |

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Michael Daum"}%
%META:FIELD{name="Copyright" title="Copyright" value="© 2013-2017 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Copyright" title="Copyright" value="© 2013-2022 Michael Daum"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%TOPIC%"}%
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
Expand Down
7 changes: 3 additions & 4 deletions lib/Foswiki/Contrib/MultiSaveContrib.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Extension for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2013-2022 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -18,11 +18,10 @@ package Foswiki::Contrib::MultiSaveContrib;
use strict;
use warnings;

use Foswiki::Plugins();
use Foswiki::Contrib::JsonRpcContrib ();

our $VERSION = '1.20';
our $RELEASE = '25 Sep 2017';
our $VERSION = '2.00';
our $RELEASE = '05 May 2022';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Json-RPC interface to save multiple changes in one transaction';
our $core;
Expand Down
5 changes: 2 additions & 3 deletions lib/Foswiki/Contrib/MultiSaveContrib/Config.spec
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# ---+ Extensions
# ---++ MultiSaveContrib

# **PERL**
# **PERL EXPERT**
# Registers the save method to the json-rpc server
$Foswiki::cfg{JsonRpcContrib}{Handler}{MultiSaveContrib} = {
"save" => {
package => "Foswiki::Contrib::MultiSaveContrib",
function => "jsonRpcMultiSave",
options => {},
}
};

# ---++ JQueryPlugin
# ---+++ Extra plugins

# **STRING**
# **STRING EXPERT**
$Foswiki::cfg{JQueryPlugin}{Plugins}{MultiSave}{Module} = 'Foswiki::Contrib::MultiSaveContrib::JQuery';

# **BOOLEAN**
Expand Down
57 changes: 40 additions & 17 deletions lib/Foswiki/Contrib/MultiSaveContrib/Core.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Extension for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2013-2022 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -98,10 +98,11 @@ sub jsonRpcMultiSave {

writeDebug("called jsonRpcMultiSave()");
my $wikiName = Foswiki::Func::getWikiName();
my @params = $request->multi_param();
my @params = $request->params();
my $formName = $request->param("formName");

writeDebug("saving a $formName") if defined $formName;
#writeDebug("params=".dump(\@params));

# collect required changes
my %changes = ();
Expand All @@ -110,8 +111,8 @@ sub jsonRpcMultiSave {
next unless $key =~ /^multisave\{(.*)\}\{(.*)\}$/;
my $webTopic = $1;
my $fieldName = $2;
my $fieldValue = $request->param($key);
$fieldValue = join(", ", grep {!/^$/} @$fieldValue) if ref($fieldValue);
my @fieldValue = $request->param($key);
my $fieldValue = join(", ", grep {!/^$/} @fieldValue);

writeDebug("found changes for $webTopic, $fieldName=$fieldValue");
$changes{$webTopic}{$fieldName} = $fieldValue;
Expand Down Expand Up @@ -162,20 +163,42 @@ sub jsonRpcMultiSave {
my $mustSave = 0;
foreach my $fieldName (keys %{$changes{$webTopic}}) {
my $fieldValue = $changes{$webTopic}{$fieldName};
my $oldVal = $meta->get("FIELD", $fieldName);
$oldVal = $oldVal->{value} if defined $oldVal;

writeDebug("oldVal=".(defined $oldVal?$oldVal:'undef').", newVal=$fieldValue");
if (defined($oldVal) && $oldVal eq $fieldValue) {
next;
writeDebug("fieldName=$fieldName, fieldValue=$fieldValue");
if ($fieldName =~ /^(Set|Local)\+(.*)$/) {
my $type = $1;
my $prefName = $2;
my $oldVal = $meta->get("PREFERENCE", $prefName);
$oldVal = $oldVal->{value} if defined $oldVal;

writeDebug("oldVal=".(defined $oldVal?$oldVal:'undef').", newVal=$fieldValue");
if (defined($oldVal) && $oldVal eq $fieldValue) {
next;
}

$mustSave = 1;
$meta->putKeyed('PREFERENCE', {
name => $prefName,
title => $prefName,
value => $fieldValue,
type => $type,
});

} else {
my $oldVal = $meta->get("FIELD", $fieldName);
$oldVal = $oldVal->{value} if defined $oldVal;

writeDebug("oldVal=".(defined $oldVal?$oldVal:'undef').", newVal=$fieldValue");
if (defined($oldVal) && $oldVal eq $fieldValue) {
next;
}

$mustSave = 1;
$meta->putKeyed('FIELD', {
name => $fieldName,
title => $fieldName,
value => $fieldValue,
});
}

$mustSave = 1;
$meta->putKeyed('FIELD', {
name => $fieldName,
title => $fieldName,
value => $fieldValue,
});
}

next unless $mustSave;
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Contrib/MultiSaveContrib/JQuery.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sub new {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2013-2017 Michael Daum http://michaeldaumconsulting.com
Copyright (C) 2013-2022 Michael Daum http://michaeldaumconsulting.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down
18 changes: 11 additions & 7 deletions pub/System/MultiSaveContrib/jquery.multisave.uncompressed.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/*
* jQuery MultiSave plugin 0.05
* jQuery MultiSave plugin 1.00
*
* Copyright (c) 2013-2017 Michael Daum http://michaeldaumconsulting.com
* Copyright (c) 2013-2022 Michael Daum http://michaeldaumconsulting.com
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Licensed under the GPL license http://www.gnu.org/licenses/gpl.html
*
*/
"use strict";
jQuery(function($) {

$(".jqMultiSave:not(.jqMultiSaveInited)").livequery(function() {
$(".jqMultiSave").livequery(function() {
var $form = $(this),
$results = $("<div class='jqMultiSaveResults'></div>").appendTo($form),
url = foswiki.getPreference("SCRIPTURL")+"/jsonrpc/MultiSaveContrib/save",
Expand All @@ -21,9 +19,15 @@ jQuery(function($) {
$form.attr("action", url).attr("method","post");
$form.prepend("<input type='hidden' name='formName' value='"+formName+"' />");

$form.addClass("jqMultiSaveInited").ajaxForm({
$form.ajaxForm({
dataType:"json",

beforeSerialize: function() {
if (typeof(foswikiStrikeOne) !== 'undefined') {
foswikiStrikeOne($form[0]);
}
},

beforeSubmit: function() {
$results.hide();
$.blockUI({message:'<h1>Saving ...</h1>'});
Expand Down

0 comments on commit 1e9a0ff

Please sign in to comment.