-
Notifications
You must be signed in to change notification settings - Fork 4
/
JQGridPlugin.pm
122 lines (98 loc) · 3.37 KB
/
JQGridPlugin.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009-2017 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
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. For
# more details read LICENSE in the root of this distribution.
#
# This program 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.
#
package Foswiki::Plugins::JQGridPlugin;
use strict;
use warnings;
our $VERSION = '2.61';
our $RELEASE = '30 Aug 2017';
our $SHORTDESCRIPTION = 'jQuery grid widget for Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
our $doInit = 0;
use Foswiki::Func ();
use Foswiki::Plugins ();
use Foswiki::Plugins::JQueryPlugin ();
use Foswiki::AccessControlException ();
use Error qw(:try);
sub initPlugin {
my ($topic, $web, $user) = @_;
Foswiki::Plugins::JQueryPlugin::registerPlugin('grid', 'Foswiki::Plugins::JQGridPlugin::GRID');
Foswiki::Func::registerTagHandler('GRID', \&handleGrid);
Foswiki::Func::registerRESTHandler('gridconnector', \&restGridConnector,
authenticate => 0,
validate => 0,
http_allow => 'GET,POST',
);
my $selector = Foswiki::Func::getPreferencesValue('JQGRIDPLUGIN_TABLE2GRID');# || '.foswikiTable';
if ($selector) {
$doInit = 1; # delay createplugin
Foswiki::Func::addToZone('head', 'JQGRIDPLUGIN::META', <<HERE);
<meta name='foswiki.JQGridPlugin.table2Grid' content='$selector' />
HERE
}
return 1;
}
sub afterCommonTagsHandler {
return unless $doInit;
$doInit = 0;
my $session = $Foswiki::Plugins::SESSION;
Foswiki::Plugins::JQueryPlugin::createPlugin('Grid', $session);
}
sub handleGrid {
my $session = shift;
my $plugin = Foswiki::Plugins::JQueryPlugin::createPlugin('Grid', $session);
return $plugin->handleGrid(@_) if $plugin;
return '';
}
sub restGridConnector {
my ($session, $subject, $verb, $response) = @_;
my $request = Foswiki::Func::getCgiQuery();
my $connectorID = $request->param('connector') || $Foswiki::cfg{JQGridPlugin}{DefaultConnector} || 'search';
my $connectorClass = $Foswiki::cfg{JQGridPlugin}{Connector}{$connectorID}
|| $Foswiki::cfg{JQGridPlugin}{ExternalConnectors}{$connectorID};
unless ($connectorClass) {
printRESTResult($response, 500, "ERROR: unknown connector");
return '';
}
eval "require $connectorClass";
if ($@) {
printRESTResult($response, 500, "ERROR: loading connector");
return '';
}
my $connector = $connectorClass->new($session);
my $action = $request->param('oper') || 'search';
try {
if ($action eq 'edit') {
$connector->restHandleSave($request, $response);
} else {
$connector->restHandleSearch($request, $response);
}
} catch Foswiki::AccessControlException with {
my $error = shift;
printRESTResult($response, 401, "ERROR: Unauthorized access to $error->{web}.$error->{topic}");
} catch Error::Simple with {
my $error = shift;
printRESTResult($response, 500, "ERROR: ".$error);
};
return '';
}
sub printRESTResult {
my ($response, $status, $text) = @_;
$response->header(
-status => $status,
-type => 'text/html',
);
$response->print("$text\n");
}
1;