Changeset 14919


Ignore:
Timestamp:
05/29/12 03:31:41 (12 months ago)
Author:
KipLubliner
Message:

Item11891: add delete handler; add debugging parameter; improve reporting of errors

Location:
trunk/SqlGridPlugin
Files:
5 edited

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"}% 
    72<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"}%' 
    114  <a class="jqUIDialogButton jqUIDialogClose {icon:'ui-icon-circle-check'}">%MAKETEXT{"Ok"}%</a> 
    125</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  
    1919edit_needrow_sqlgridbutton="true" 
    2020 
    21 }% 
    22  
    23 Not implemented yet 
    24  
    2521delete_caption_sqlgridbutton="%MAKETEXT{"Delete"}%" 
    2622delete_hover_sqlgridbutton="%MAKETEXT{"Delete current record"}%" 
    2723delete_icon_sqlgridbutton="ui-icon-scissors" 
    28 delete_form_sqlgridbutton="GenericDelFormURL_TODO" 
     24delete_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{"%?"}%" 
    2925delete_formaction_sqlgridbutton="%SCRIPTURL{"rest"}%/SqlGridPlugin/simpledelete" 
    3026delete_needrow_sqlgridbutton="true" 
     27 
     28}% 
     29 
    3130</verbatim> 
     31 
     32---+++ Confirm Dialog 
     33Special arguments: 
     34   * title 
     35   * message 
     36 
     37%STARTSECTION{"confirm"}% 
     38<div title="%ENCODE{"%URLPARAM{title}%" old="&#37;" new="%"}%" class="sqlGridDialog jqUIDialog { modal:true, resizable:true, draggable:true, height:400, width:600}"> 
     39 
     40%ENCODE{"%URLPARAM{message}%" old="&#37;" 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  
    6565    Foswiki::Func::registerRESTHandler( 'simpleupdate', \&restSimpleupdate ); 
    6666    Foswiki::Func::registerRESTHandler( 'simpleinsert', \&restSimpleinsert ); 
     67    Foswiki::Func::registerRESTHandler( 'simpledelete', \&restSimpledelete ); 
     68 
    6769    return 1; 
    6870} 
     
    128130        my $idcol = $params->{idcol_connectorparam} = $params->remove('idcol') || ''; 
    129131        $params->{fromwhere_params_connectorparam} = $params->remove('sqlparams') || ''; 
     132        my $debugging = $params->remove('debugging') || "off"; 
    130133 
    131134        my $theSqlQuery = $params->{sql} || ''; 
     
    140143    if (exists $params->{sqlgridbuttons}) { 
    141144        my %formactionargs = ( dbconn => $dbconn, idcol => $idcol ); 
     145        my %popupargs = ( dbconn => $dbconn, idcol => $idcol ); 
    142146        my %sqlgridbuttons; 
    143147        while (my ($k,$v) = each %{$params}) { 
     
    150154        } 
    151155        my $formactionargs = join ';', map { "$_=$formactionargs{$_}" } keys %formactionargs; 
     156        my $popupargs = join ';', map { "$_=$popupargs{$_}" } keys %popupargs; 
    152157 
    153158        my @buttons = split ',', $params->{sqlgridbuttons}; 
    154159        for my $button (@buttons) { 
    155160            $button =~ s/\s+//g; 
    156             $buttonScripts .= _addGridButton($id, $button, $sqlgridbuttons{$button}, $formactionargs, $params); 
     161            $buttonScripts .= _addGridButton($id, $button, $sqlgridbuttons{$button}, $popupargs, $formactionargs, $params, $debugging); 
    157162        } 
    158163    } 
     
    180185EOQ 
    181186; 
    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 
     196sub _addGridButton ($$$$$$$) { 
     197    my ($id, $button, $buttonParams, $popupargs, $formactionargs, $params, $debugging) = @_; 
     198 
     199        my %funcArgs = ( gridId => "'$id'", debugging => "'$debugging'" ); 
    189200        if (exists $buttonParams->{needrow}) { 
    190201            $funcArgs{requireSelection} = $buttonParams->{needrow}; 
    191202        } 
    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( 
    196206                 'System', 'SqlGridPluginErrorMessages', 'view', 
    197207                 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#*/ 
    203230    my $formAction = $buttonParams->{formaction} || 
    204231            Foswiki::Func::getScriptUrl( 
    205232                 'System', 'SqlGridPluginErrorMessages', 'view', 
    206233                 skin => 'text', 
    207                  errortype => 'noformaction', 
     234                 contenttype => 'application/json', 
     235                 section => 'nopopupaction', 
    208236                 button => $button 
    209237                 ); 
     
    285313} 
    286314 
     315sub restSimpledelete { 
     316    require Foswiki::Plugins::SqlGridPlugin::SimpleCRUD; 
     317    return Foswiki::Plugins::SqlGridPlugin::SimpleCRUD::restSimpledelete(@_); 
     318} 
     319 
    2873201; 
  • trunk/SqlGridPlugin/lib/Foswiki/Plugins/SqlGridPlugin/SimpleCRUD.pm

    r14917 r14919  
    33use strict; 
    44use warnings; 
     5 
     6use constant SUCCESS_JSON => '{ "actionStatus": 200 }'; 
    57 
    68use constant DEBUG => 1; # toggle me 
     
    6264        $sth->finish; 
    6365 
    64         return "1"; 
     66        return SUCCESS_JSON; 
    6567} 
    66  
    6768 
    6869sub restSimpleinsert { 
     
    8485        $sth->finish; 
    8586 
    86         return "1"; 
     87        return SUCCESS_JSON; 
    8788} 
    8889 
     90sub restSimpledelete { 
     91        my ($session, $subject, $verb, $response) = @_; 
     92        my $request = Foswiki::Func::getCgiQuery(); 
     93        writeDebug($request->query_string()) 
     94                if DEBUG; 
    8995 
     96        my ($dbconn, $table, $idcol, $idval, $keys, $args) = _getRestParams($request); 
     97 
     98        my $sql = "DELETE FROM $table WHERE $idcol = ?"; 
     99        my @args = ($idval); 
     100 
     101writeDebug($sql . join ',', @args); 
     102        my $sth = Foswiki::Plugins::SqlPlugin::execute($dbconn, $sql, @args); 
     103        $sth->finish; 
     104 
     105        return SUCCESS_JSON; 
     106} 
    90107 
    911081; 
  • trunk/SqlGridPlugin/pub/System/SqlGridPlugin/gridfuncs.js

    r14916 r14919  
    44                modal:true, 
    55                resizable: false, 
     6                width: 500, 
    67                buttons: { "Ok": function() { $(this).dialog("close"); } } 
    78        }); 
     9} 
     10 
     11function logDebugMessage(gridId, text) { 
     12    var debugDiv = $("#Debug_" + gridId); 
     13    if (debugDiv) { 
     14        debugDiv.append(text + "<br>"); 
     15    } 
    816} 
    917 
     
    1220        var href = args.form; 
    1321        var formAction = args.formAction; 
     22        var debugging = args.debugging; 
    1423 
    1524        var selrow = $('#' + gridId).jqGrid('getGridParam', 'selrow'); 
     
    2938        } 
    3039 
     40    if (debugging == "on") { 
     41        logDebugMessage(gridId, href); 
     42    } 
     43 
    3144        $.get(href, function(content) {  
    3245                var $content = $(content); 
     
    3649 
    3750        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 + '")'; 
    3952        form.attr('onsubmit', onsubmit); 
     53        }) 
     54        .error(function(errObj) { 
     55        myalert(errObj.responseText); 
    4056        }); 
    4157} 
    4258 
    43 function sqlgrid_runFormAction(form, gridId, formAction) { 
     59function sqlgrid_runFormAction(form, gridId, formAction, debugging) { 
    4460    var $popup = $(form).closest('.sqlGridDialog'); 
    4561        var href = formAction; 
     
    5066                } 
    5167        }); 
    52         $.get(href, function(content) { 
     68    if (debugging == "on") { 
     69        logDebugMessage(gridId, href); 
     70    } 
     71        $.getJSON(href, function(data) { 
     72            var result = data.actionStatus; 
    5373                $popup.dialog("close"); 
    5474                $('#'+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); 
    5583        }); 
    5684        return false; 
Note: See TracChangeset for help on using the changeset viewer.