Skip to content

Commit

Permalink
Item13030: moving to jsrender
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Dec 2, 2014
1 parent 36ff70f commit 7114c3f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
5 changes: 3 additions & 2 deletions data/System/JQGridPlugin.txt
Expand Up @@ -86,14 +86,14 @@ When [[Foswiki:Extesions/ImagePlugin][ImagePlugin]] is installed, each Image/Pho
---++ Examples
%IF{
"{AuthScripts}=~'\brest\b'"
then="<blockquote class='foswikiHelp'>
then="<div class='foswikiHelp'>
$percntX$percnt Users of this wiki need to be logged in to use %TOPIC%.

If guests are to make use of %TOPIC% without being logged in, remove the =rest= script from ={AuthScripts}= in [[%SCRIPTURLPATH{"configure"}%#Login$SecurityAndAuthentication][configure]] under Security and Authentication -> Login. See also: [[%SYSTEMWEB%.UserAuthentication][UserAuthentication]]
$percntIF{
\"NOT context authenticated\"
then=\"$n$dollarpercntX$dollarpercnt You are not logged in, so the examples below will not work\"
}$percnt</blockquote>"
}$percnt</div>"
}%
*Users*, demonstrating customised columns:
%TWISTY{showlink="Code..."}%
Expand Down Expand Up @@ -171,6 +171,7 @@ Custom grid connectors must process the following parameters:
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order --> |
| 02 Dec 2014: | (2.40) moving from jquery.tmpl to jsrender |
| 28 Aug 2014: | (2.31) fully specify REST security |
| 11 Apr 2014: | (2.30) work around different styles of inconsistencies in =renderForDisplay= across foswiki core releases |
| 04 Apr 2014: | (2.22) flag rest handlers that don't require authentication |
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/JQGridPlugin.pm
Expand Up @@ -16,8 +16,8 @@ package Foswiki::Plugins::JQGridPlugin;
use strict;
use warnings;

our $VERSION = '2.31';
our $RELEASE = '2.31';
our $VERSION = '2.40';
our $RELEASE = '2.40';
our $SHORTDESCRIPTION = 'jQuery grid widget for Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
our $doInit = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/JQGridPlugin/DEPENDENCIES
@@ -1,3 +1,3 @@
Foswiki::Plugins::JQueryPlugin,>3.31,perl,Required
Foswiki::Plugins::JQueryPlugin,>6.00,perl,Required
Foswiki::Plugins::DBCachePlugin,>3.61,perl,Optional
Foswiki::Plugins::SolrPlugin,>1.00,perl,Optional
57 changes: 29 additions & 28 deletions lib/Foswiki/Plugins/JQGridPlugin/GRID.pm
Expand Up @@ -291,45 +291,46 @@ HERE
$doneSearchOption = 1;
}

# formatter
my $formatter = $params->{$fieldName.'_formatter'};
if ($formatter) {
push @colModel, "formatter:'$formatter'";


} else {
if ($fieldName =~ /^(Date|Changed|Modified|info.date|info.createdate)$/) {
push @colModel, "formatter:'date'";
push @colModel, "formatoptions: {srcformat: 's', newformat: 'd M Y - H:i'}";
push @colModel, "sorttype:'date'";
}
if ($fieldName =~ /^(Topic|TopicTitle)$/) {
push @colModel, "formatter:'topic'";
}
if ($fieldName =~ /(Image|Photo)$/) {
push @colModel, "formatter:'image'";
push @colModel, "search:false" unless $doneSearchOption;
}
}

# format
my $format = $params->{$fieldName.'_format'};
my $templateId; # added to the format opts below
if (defined $format) {

# load the tmpl module
Foswiki::Plugins::JQueryPlugin::createPlugin("tmpl");
# load the render module
Foswiki::Plugins::JQueryPlugin::createPlugin("render");

$templateId = "jqgrid_tmpl_".Digest::MD5::md5_hex($format);
push @colModel, "formatter:'tmpl'";
$templateId = "jqgrid_render_".Digest::MD5::md5_hex($format);
push @colModel, "formatter:'render'";

Foswiki::Func::addToZone("head", $templateId, <<"EOT");
<script id="$templateId" type="text/x-jquery-tmpl">
<div class='foswikiHidden cellValue'>\${value}</div>
<script id="$templateId" type="text/x-jsrender">
<div class='foswikiHidden cellValue'>{{:value}}</div>
$format
</script>
EOT
}
} else {

# formatter
my $formatter = $params->{$fieldName.'_formatter'};
if ($formatter) {
push @colModel, "formatter:'$formatter'";


} else {
if ($fieldName =~ /^(Date|Changed|Modified|info.date|info.createdate)$/) {
push @colModel, "formatter:'date'";
push @colModel, "formatoptions: {srcformat: 's', newformat: 'd M Y - H:i'}";
push @colModel, "sorttype:'date'";
}
if ($fieldName =~ /^(Topic|TopicTitle)$/) {
push @colModel, "formatter:'topic'";
}
if ($fieldName =~ /(Image|Photo)$/) {
push @colModel, "formatter:'image'";
push @colModel, "search:false" unless $doneSearchOption;
}
}
}

# format options
my $formatOpts = $params->{$fieldName.'_formatoptions'};
Expand Down
11 changes: 5 additions & 6 deletions pub/System/JQGridPlugin/jquery.additional-fmatter.js
Expand Up @@ -32,7 +32,7 @@ jQuery(function($) {
target = "",
url,
topic = opts.rowId.replace(/\./, '/'),
viewUrl = foswiki.getPreference("SCRIPTURLPATH")+'/view';
viewUrl = foswiki.getScriptUrlPath("view");

if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
op = $.extend({},op,opts.colModel.formatoptions);
Expand All @@ -52,8 +52,8 @@ jQuery(function($) {
return $.fn.fmatter.defaultFormat(cellVal,opts);
}
};
/* requires jquery.tmpl from http://api.jquery.com/tmpl */
$.fn.fmatter.tmpl = function(cellVal, opts, rowData) {
/* requires jsrender from http://www.jsviews.com/ */
$.fn.fmatter.render = function(cellVal, opts, rowData) {
var data = $.extend({
id: opts.rowId,
value: cellVal
Expand All @@ -72,10 +72,9 @@ jQuery(function($) {
return $.fn.fmatter.defaultFormat(cellVal, opts);
}

return $("#"+data.template).tmpl(data)
.appendTo("<div />").parent()[0].innerHTML;
return $("#"+data.template).render(data);
};
$.fn.fmatter.tmpl.unformat = function(cellText, opts, cellElem) {
$.fn.fmatter.render.unformat = function(cellText, opts, cellElem) {
return $(cellElem).find(".cellValue:first")[0].innerHTML;
};
});
11 changes: 5 additions & 6 deletions pub/System/JQGridPlugin/jquery.jqgrid.uncompressed.js
Expand Up @@ -4496,7 +4496,7 @@ jQuery(function($) {
target = "",
url,
topic = opts.rowId.replace(/\./, '/'),
viewUrl = foswiki.getPreference("SCRIPTURLPATH")+'/view';
viewUrl = foswiki.getScriptUrlPath("view");

if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
op = $.extend({},op,opts.colModel.formatoptions);
Expand All @@ -4516,8 +4516,8 @@ jQuery(function($) {
return $.fn.fmatter.defaultFormat(cellVal,opts);
}
};
/* requires jquery.tmpl from http://api.jquery.com/tmpl */
$.fn.fmatter.tmpl = function(cellVal, opts, rowData) {
/* requires jsrender from http://www.jsviews.com/ */
$.fn.fmatter.render = function(cellVal, opts, rowData) {
var data = $.extend({
id: opts.rowId,
value: cellVal
Expand All @@ -4536,10 +4536,9 @@ jQuery(function($) {
return $.fn.fmatter.defaultFormat(cellVal, opts);
}

return $("#"+data.template).tmpl(data)
.appendTo("<div />").parent()[0].innerHTML;
return $("#"+data.template).render(data);
};
$.fn.fmatter.tmpl.unformat = function(cellText, opts, cellElem) {
$.fn.fmatter.render.unformat = function(cellText, opts, cellElem) {
return $(cellElem).find(".cellValue:first")[0].innerHTML;
};
});
Expand Down

0 comments on commit 7114c3f

Please sign in to comment.