Changeset 14919
- Timestamp:
- 05/29/12 03:31:41 (12 months ago)
- Location:
- trunk/SqlGridPlugin
- Files:
-
- 5 edited
-
data/System/SqlGridPluginErrorMessages.txt (modified) (1 diff)
-
data/System/SqlGridPluginSimpleTable.txt (modified) (1 diff)
-
lib/Foswiki/Plugins/SqlGridPlugin.pm (modified) (6 diffs)
-
lib/Foswiki/Plugins/SqlGridPlugin/SimpleCRUD.pm (modified) (3 diffs)
-
pub/System/SqlGridPlugin/gridfuncs.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/SqlGridPlugin/data/System/SqlGridPluginErrorMessages.txt
r14916 r14919 1 <!-- 2 * Set message_noform=%IF{" $'URLPARAM{errortype}' = 'noform'" then="No form specified"}% 3 * Set message_noformaction=%IF{" $'URLPARAM{errortype}' = 'noformaction'" then="No form action specified"}% 4 * Set message = %message_noform%%message_noformaction% for button '%URLPARAM{"button"}%' 5 --> 6 1 %STARTSECTION{"nopopup"}% 7 2 <div title="Error" class="jqUIDialog { modal:true, resizable:false, draggable:false, height:400, width:600}"> 8 9 ---+++ %message% 10 3 ---+++ No popup specified for button '%URLPARAM{"button"}%' 11 4 <a class="jqUIDialogButton jqUIDialogClose {icon:'ui-icon-circle-check'}">%MAKETEXT{"Ok"}%</a> 12 5 </div> 6 %ENDSECTION{"nopopup"}% 7 8 %STARTSECTION{"nopopupaction"}%{ "actionStatus": 500, "message": "no popup action specified for button '%URLPARAM{"button"}%'" } 9 %ENDSECTION{"nopopupaction"}% -
trunk/SqlGridPlugin/data/System/SqlGridPluginSimpleTable.txt
r14913 r14919 19 19 edit_needrow_sqlgridbutton="true" 20 20 21 }%22 23 Not implemented yet24 25 21 delete_caption_sqlgridbutton="%MAKETEXT{"Delete"}%" 26 22 delete_hover_sqlgridbutton="%MAKETEXT{"Delete current record"}%" 27 23 delete_icon_sqlgridbutton="ui-icon-scissors" 28 delete_form_sqlgridbutton=" GenericDelFormURL_TODO"24 delete_form_sqlgridbutton="%SCRIPTURL{"view"}%/%WEB%/%TOPIC%?skin=text;section=confirm;title=%ENCODE{"%MAKETEXT{"Delete Record"}%"}%;message=%ENCODE{"%MAKETEXT{"Delete record"}% %"}%%ENCODE{"URLPARAM{_selected_row}"}%%ENCODE{"%?"}%" 29 25 delete_formaction_sqlgridbutton="%SCRIPTURL{"rest"}%/SqlGridPlugin/simpledelete" 30 26 delete_needrow_sqlgridbutton="true" 27 28 }% 29 31 30 </verbatim> 31 32 ---+++ Confirm Dialog 33 Special arguments: 34 * title 35 * message 36 37 %STARTSECTION{"confirm"}% 38 <div title="%ENCODE{"%URLPARAM{title}%" old="%" new="%"}%" class="sqlGridDialog jqUIDialog { modal:true, resizable:true, draggable:true, height:400, width:600}"> 39 40 %ENCODE{"%URLPARAM{message}%" old="%" new="%"}% 41 42 <form class='foswikiForm' > 43 <input type='hidden' name='col_%URLPARAM{idcol}%' value='%URLPARAM{_selected_row}%'/> 44 </form> 45 <a class="jqUIDialogButton jqUIDialogSubmit {icon:'ui-icon-circle-check'}">%MAKETEXT{"Ok"}%</a> 46 <a class="jqUIDialogButton jqUIDialogClose {icon:'ui-icon-cancel'}">%MAKETEXT{"Cancel"}%</a> 47 </div> 48 %ENDSECTION{"confirm"}% -
trunk/SqlGridPlugin/lib/Foswiki/Plugins/SqlGridPlugin.pm
r14917 r14919 65 65 Foswiki::Func::registerRESTHandler( 'simpleupdate', \&restSimpleupdate ); 66 66 Foswiki::Func::registerRESTHandler( 'simpleinsert', \&restSimpleinsert ); 67 Foswiki::Func::registerRESTHandler( 'simpledelete', \&restSimpledelete ); 68 67 69 return 1; 68 70 } … … 128 130 my $idcol = $params->{idcol_connectorparam} = $params->remove('idcol') || ''; 129 131 $params->{fromwhere_params_connectorparam} = $params->remove('sqlparams') || ''; 132 my $debugging = $params->remove('debugging') || "off"; 130 133 131 134 my $theSqlQuery = $params->{sql} || ''; … … 140 143 if (exists $params->{sqlgridbuttons}) { 141 144 my %formactionargs = ( dbconn => $dbconn, idcol => $idcol ); 145 my %popupargs = ( dbconn => $dbconn, idcol => $idcol ); 142 146 my %sqlgridbuttons; 143 147 while (my ($k,$v) = each %{$params}) { … … 150 154 } 151 155 my $formactionargs = join ';', map { "$_=$formactionargs{$_}" } keys %formactionargs; 156 my $popupargs = join ';', map { "$_=$popupargs{$_}" } keys %popupargs; 152 157 153 158 my @buttons = split ',', $params->{sqlgridbuttons}; 154 159 for my $button (@buttons) { 155 160 $button =~ s/\s+//g; 156 $buttonScripts .= _addGridButton($id, $button, $sqlgridbuttons{$button}, $ formactionargs, $params);161 $buttonScripts .= _addGridButton($id, $button, $sqlgridbuttons{$button}, $popupargs, $formactionargs, $params, $debugging); 157 162 } 158 163 } … … 180 185 EOQ 181 186 ; 182 return "$script\n\%GRID{" . $params->stringify() . "}\%"; 183 } 184 185 sub _addGridButton ($$$$$) { 186 my ($id, $button, $buttonParams, $formactionargs, $params) = @_; 187 188 my %funcArgs = ( gridId => "'$id'" ); 187 188 my $debugDiv=""; 189 if ($debugging eq "on") { 190 $debugDiv = "\n<div id='Debug_$id'> *DEBUGGING ON* <br></div>"; 191 } 192 193 return "$script\n\%GRID{" . $params->stringify() . "}\%$debugDiv"; 194 } 195 196 sub _addGridButton ($$$$$$$) { 197 my ($id, $button, $buttonParams, $popupargs, $formactionargs, $params, $debugging) = @_; 198 199 my %funcArgs = ( gridId => "'$id'", debugging => "'$debugging'" ); 189 200 if (exists $buttonParams->{needrow}) { 190 201 $funcArgs{requireSelection} = $buttonParams->{needrow}; 191 202 } 192 if ($buttonParams->{form}) { 193 $funcArgs{form} = "'" . $buttonParams->{form} . "'"; 194 } else { 195 $funcArgs{form} = "'" . Foswiki::Func::getScriptUrl( 203 204 my $popup = $buttonParams->{form} || 205 Foswiki::Func::getScriptUrl( 196 206 'System', 'SqlGridPluginErrorMessages', 'view', 197 207 skin => 'text', 198 errortype => 'noform', 199 button => $button 200 ) . "'"; 201 } 202 208 section => 'nopopup', 209 button => $button); 210 if ($popupargs) { 211 if ($popup =~ /\?/) { 212 $popup .= ";$popupargs"; 213 } else { 214 $popup .= "?$popupargs"; 215 } 216 } 217 $funcArgs{form} = "'$popup'"; 218 #/* 219 # if ($buttonParams->{form}) { 220 # $funcArgs{form} = "'" . $buttonParams->{form} . "'"; 221 # } else { 222 # $funcArgs{form} = "'" . Foswiki::Func::getScriptUrl( 223 # 'System', 'SqlGridPluginErrorMessages', 'view', 224 # skin => 'text', 225 # section => 'nopopup', 226 # button => $button 227 # ) . "'"; 228 # } 229 #*/ 203 230 my $formAction = $buttonParams->{formaction} || 204 231 Foswiki::Func::getScriptUrl( 205 232 'System', 'SqlGridPluginErrorMessages', 'view', 206 233 skin => 'text', 207 errortype => 'noformaction', 234 contenttype => 'application/json', 235 section => 'nopopupaction', 208 236 button => $button 209 237 ); … … 285 313 } 286 314 315 sub restSimpledelete { 316 require Foswiki::Plugins::SqlGridPlugin::SimpleCRUD; 317 return Foswiki::Plugins::SqlGridPlugin::SimpleCRUD::restSimpledelete(@_); 318 } 319 287 320 1; -
trunk/SqlGridPlugin/lib/Foswiki/Plugins/SqlGridPlugin/SimpleCRUD.pm
r14917 r14919 3 3 use strict; 4 4 use warnings; 5 6 use constant SUCCESS_JSON => '{ "actionStatus": 200 }'; 5 7 6 8 use constant DEBUG => 1; # toggle me … … 62 64 $sth->finish; 63 65 64 return "1";66 return SUCCESS_JSON; 65 67 } 66 67 68 68 69 sub restSimpleinsert { … … 84 85 $sth->finish; 85 86 86 return "1";87 return SUCCESS_JSON; 87 88 } 88 89 90 sub restSimpledelete { 91 my ($session, $subject, $verb, $response) = @_; 92 my $request = Foswiki::Func::getCgiQuery(); 93 writeDebug($request->query_string()) 94 if DEBUG; 89 95 96 my ($dbconn, $table, $idcol, $idval, $keys, $args) = _getRestParams($request); 97 98 my $sql = "DELETE FROM $table WHERE $idcol = ?"; 99 my @args = ($idval); 100 101 writeDebug($sql . join ',', @args); 102 my $sth = Foswiki::Plugins::SqlPlugin::execute($dbconn, $sql, @args); 103 $sth->finish; 104 105 return SUCCESS_JSON; 106 } 90 107 91 108 1; -
trunk/SqlGridPlugin/pub/System/SqlGridPlugin/gridfuncs.js
r14916 r14919 4 4 modal:true, 5 5 resizable: false, 6 width: 500, 6 7 buttons: { "Ok": function() { $(this).dialog("close"); } } 7 8 }); 9 } 10 11 function logDebugMessage(gridId, text) { 12 var debugDiv = $("#Debug_" + gridId); 13 if (debugDiv) { 14 debugDiv.append(text + "<br>"); 15 } 8 16 } 9 17 … … 12 20 var href = args.form; 13 21 var formAction = args.formAction; 22 var debugging = args.debugging; 14 23 15 24 var selrow = $('#' + gridId).jqGrid('getGridParam', 'selrow'); … … 29 38 } 30 39 40 if (debugging == "on") { 41 logDebugMessage(gridId, href); 42 } 43 31 44 $.get(href, function(content) { 32 45 var $content = $(content); … … 36 49 37 50 var form = $content.find("form:first"); 38 var onsubmit = 'return sqlgrid_runFormAction(this, "' + gridId + '", "' + formAction + '" )';51 var onsubmit = 'return sqlgrid_runFormAction(this, "' + gridId + '", "' + formAction + '", "' + debugging + '")'; 39 52 form.attr('onsubmit', onsubmit); 53 }) 54 .error(function(errObj) { 55 myalert(errObj.responseText); 40 56 }); 41 57 } 42 58 43 function sqlgrid_runFormAction(form, gridId, formAction ) {59 function sqlgrid_runFormAction(form, gridId, formAction, debugging) { 44 60 var $popup = $(form).closest('.sqlGridDialog'); 45 61 var href = formAction; … … 50 66 } 51 67 }); 52 $.get(href, function(content) { 68 if (debugging == "on") { 69 logDebugMessage(gridId, href); 70 } 71 $.getJSON(href, function(data) { 72 var result = data.actionStatus; 53 73 $popup.dialog("close"); 54 74 $('#'+gridId).trigger("reloadGrid"); 75 if (result != 200) { 76 myalert(data.message); 77 } 78 }) 79 .error(function(errObj) { 80 $popup.dialog("close"); 81 $('#'+gridId).trigger("reloadGrid"); 82 myalert(errObj.responseText); 55 83 }); 56 84 return false;
Note: See TracChangeset
for help on using the changeset viewer.
