Changeset 4


Ignore:
Timestamp:
Jan 17, 2011, 3:49:20 PM (12 years ago)
Author:
robert@…
Message:

Implemented trash in order to prevent deletion of data

Location:
trunk
Files:
13 added
9 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/BaseFilters.groovy

    r3 r4  
    4949                                // If a user is already logged in, let him continue
    5050                                if( session.user && session.user != null ) {
     51                                        // If we don't refresh the user object, an old hiberante session could still be attached to the object
     52                                        // raising errors later on (Lazy loading errors)
     53                                        session.user.refresh();
     54                                       
    5155                                        return true;
    5256                                }
     
    7882                                                if (!session.user){ // when not found, create a new user
    7983                                                        session.user = new User(identifier: user.id, username: user.username).save(flush: true)
    80                                                 }                                                       
    81                                                
     84                                                }
    8285                                        } catch(Exception e) {
    8386                                                log.error("Unable to fetch user from GSCF", e)
  • trunk/grails-app/controllers/nl/tno/metagenomics/AssayController.groovy

    r3 r4  
    433433        }
    434434
    435         /**
    436          * Updates existing run
    437          */
    438         def updateRun = {
    439                 // load study with id specified by param.id
    440                 def assay = Assay.get(params.id as Long)
    441 
    442                 if (!assay) {
    443                         flash.message = "No assay found with id: $params.id"
    444                         redirect('action': 'errorPage')
    445                         return
    446                 }
    447 
    448                 if( !params.run_id ) {
    449                         flash.message = "No run id given"
    450                         redirect(action: 'show', id: params.id)
    451                         return
    452                 }
    453 
    454                 def run
    455 
    456                 try {
    457                         run = Run.findById( params.run_id as Long )
    458                 } catch( Exception e ) {
    459                         throw e
    460                         flash.message = "Incorrect run id given: "
    461                         redirect(action: 'show', id: params.id)
    462                         return
    463                 }
    464 
    465                 // Set properties to the run
    466                 params.parameterFile = params.editParameterFile
    467                 run.setPropertiesFromForm( params );
    468 
    469                 if( run.save() ) {
    470                         flash.message = "Run succesfully saved";
    471                 } else {
    472                         flash.error = "Run could not be saved: " + run.getErrors();
    473                 }
    474 
    475                 redirect( action: 'show', id: params.id)
    476         }
    477 
    478435        def errorPage = {
    479436                render "An error has occured. $flash.message"
  • trunk/grails-app/controllers/nl/tno/metagenomics/RunController.groovy

    r2 r4  
    77class RunController {
    88        def fileService
     9       
     10        /** 
     11         * Shows information about this run in dialog style
     12         */
     13        def show = {
     14                Run run = Run.get( params.id as long );
     15                Assay assay = Assay.get( params.assayId as long );
     16               
     17                if( !run ) {
     18                        render "Run not found";
     19                        return
     20                }
     21               
     22                if( !assay ) {
     23                        render "Assay not found";
     24                        return
     25                }
     26               
     27                [assay: assay, run: run]
     28        }
     29       
     30        /**
     31         * Shows a form to edit the specified run in dialog mode
     32         */
     33        def editForm = {
     34                Run run = Run.get( params.id as long );
     35                Assay assay = Assay.get( params.assayId as long );
     36               
     37                if( !run ) {
     38                        render "Run not found";
     39                        return
     40                }
     41               
     42                if( !assay ) {
     43                        render "Assay not found";
     44                        return
     45                }
     46               
     47                [assay: assay, run: run]
     48        }
    949       
    1050    def create = {
     
    2666                redirect( controller: "assay", action: "show", id: params.id )
    2767        }
     68       
     69        def update = {
     70                if( !params.assayId ) {
     71                        flash.error = "No assay id given"
     72                        redirect(controller: 'assay', action: 'errorpage')
     73                        return
     74                }
     75                def assay = Assay.get(params.assayId as Long)
     76               
     77                // load run with id specified by param.id
     78                if (!assay) {
     79                        flash.message = "No assay found with id: ${params.assayId}"
     80                        redirect(controller: 'assay', 'action': 'errorPage')
     81                        return
     82                }
     83
     84
     85                def run
     86
     87                try {
     88                        run = Run.get( params.id as Long );
     89                } catch( Exception e ) {
     90                        throw e
     91                        flash.message = "Incorrect run id given: "
     92                        redirect(controller: 'assay', action: 'show', id: params.assayId)
     93                        return
     94                }
     95
     96                // Set properties to the run
     97                params.parameterFile = params.editParameterFile
     98                run.setPropertiesFromForm( params );
     99
     100                if( run.save() ) {
     101                        flash.message = "Run succesfully saved";
     102                } else {
     103                        flash.error = "Run could not be saved: " + run.getErrors();
     104                }
     105
     106                redirect( controller: 'assay', action: 'show', id: params.assayId)
     107        }
     108       
     109        def delete = {
     110                Run run = Run.get( params.id as long );
     111
     112                // Don't remove runs for which data exists
     113                if( run.sequenceData?.size() ) {
     114                        flash.message = "Run could not be deleted because samples are associated with it.";
     115                        redirect( controller: "assay", action: "show", id: params.assayId )
     116                }
     117               
     118                // Remove all associations
     119                run.assays.each {
     120                        run.removeFromAssays( it );
     121                }
     122               
     123                def name = run.name
     124                run.delete();
     125                flash.message = "Run " + name + " has been deleted from the system."
     126
     127                redirect( controller: "assay", action: "show", id: params.assayId )
     128               
     129        }
    28130}
  • trunk/grails-app/controllers/nl/tno/metagenomics/StudyController.groovy

    r3 r4  
    55        def gscfService
    66        def fileService
     7        def trashService
    78       
    89        def index = {
     
    1617                fileService.cleanDirectory();
    1718               
     19                // Clean the trash if needed
     20                trashService.cleanTrash();
     21               
    1822                // Filter studies for the ones the user is allowed to see
    19                 def studies = Study.findAll();
    20                 [studies: studies.findAll { it.canRead( session.user ) }, gscfAddUrl: gscfService.urlAddStudy(), lastSynchronized: synchronizationService.lastFullSynchronization ]
     23                def studies = Study.list();
     24                [studies: studies.findAll { it.canRead( session.user ) },
     25                        gscfAddUrl: gscfService.urlAddStudy(),
     26                        lastSynchronized: synchronizationService.lastFullSynchronization ]
    2127        }
    2228
  • trunk/grails-app/controllers/nl/tno/metagenomics/integration/RestController.groovy

    r3 r4  
    343343                        render url as JSON
    344344                }
    345         }.metagenomics.baseURL
     345        }
    346346       
    347347        /***************************************************/
  • trunk/grails-app/controllers/nl/tno/metagenomics/integration/SynchronizeController.groovy

    r3 r4  
    1717                //              /synchronize    -> fails with an error, redirects to /study
    1818                //                      etc...
    19                 synchronizationService.lastFullSynchronization = new Date();
     19                // synchronizationService.lastFullSynchronization = new Date();
    2020                       
    2121                [ url: redirectUrl ]
     
    2727
    2828                synchronizationService.fullSynchronization();
    29                
     29
    3030                render "";
    3131        }
  • trunk/grails-app/domain/nl/tno/metagenomics/AssaySample.groovy

    r3 r4  
    142142                _averageQuality = -1;
    143143        }
     144       
     145        /**
     146         * Check whether this assay-sample combination contains information that should be saved in trash on a delete
     147         * @return
     148         */
     149        public boolean containsData() {
     150                return tagSequence || oligoNumber || numFiles() > 0;
     151        }
     152       
     153        /**
     154         * Move information that should be kept on delete to another assaySample object.
     155         *
     156         * N.B. The sequencedata objects are really moved, so removed from the original object!
     157         *
     158         * @param otherAssaySample      Object to move
     159         */
     160        public void moveValuableDataTo( AssaySample otherAssaySample ) {
     161                // Copy properties
     162                otherAssaySample.tagSequence = tagSequence;
     163                otherAssaySample.oligoNumber = oligoNumber;
     164               
     165                // Move attached data
     166                def dataList = sequenceData?.toList()
     167                def otherAssay = otherAssaySample.assay;
     168               
     169                if( dataList && dataList.size() > 0 ) {
     170                        for( def j = dataList.size() - 1; j >= 0; j-- ) {
     171                                // Check whether the run of this sequenceData object is also connected to the assay
     172                                def run = dataList[j].run;
     173                               
     174                                if( !otherAssay.runs || !otherAssay.runs.contains( run ) ) {
     175                                        otherAssay.addToRuns( run );
     176                                }
     177                               
     178                                // Copy data
     179                                dataList[j].sample = otherAssaySample;
     180                                this.removeFromSequenceData( dataList[j] );
     181                                otherAssaySample.addToSequenceData( dataList[j] );
     182                                dataList[j].save();
     183                        }
     184                }
     185        }
    144186}
  • trunk/grails-app/domain/nl/tno/metagenomics/Study.groovy

    r2 r4  
    1313        String studyToken
    1414        String name
     15
     16        // Set to true only on the specific study object that acts as
     17        // a trash can for deleted objects. If objects are deleted in GSCF but still
     18        // contain data in this module, they will be moved to the trashcan.
     19        Boolean trashcan = false
    1520       
    1621        // If a study is set to be dirty, it should be updated
     
    3136        static constraints = {
    3237                studyToken(unique:true)
     38                trashcan(nullable:true)
     39                isDirty(nullable:true)
    3340        }
    3441       
     
    7077                return authorization.isOwner
    7178        }
     79
    7280}
  • trunk/grails-app/services/nl/tno/metagenomics/FastaService.groovy

    r3 r4  
    131131
    132132                        // Best matching sample
     133                        // TODO: Implement method to search for sample matches in a provided excel sheet
    133134                        def sampleIdx = fuzzySearchService.mostSimilarWithIndex( matchWith, samples.sample.name );
    134135                        def assaySample = null
     
    316317                                                lookingForFirstQualityScores = false;
    317318
    318                                                 quality = updateQuality( quality, line );
     319                                                // Don't compute average quality because it takes too much time
     320                                                //quality = updateQuality( quality, line );
    319321                                        }
    320322                                } else {
    321                                         quality = updateQuality( quality, line );
     323                                        // Don't compute average quality because it takes too much time
     324                                        //quality = updateQuality( quality, line );
    322325                                }
    323326                               
  • trunk/grails-app/services/nl/tno/metagenomics/integration/GscfService.groovy

    r3 r4  
    213213         * @return ArrayList
    214214         */
    215         public HashMap getAuthorizationLevel(String sessionToken, String studyToken) {
     215        public HashMap getAuthorizationLevel(String sessionToken, String studyToken) throws ResourceNotFoundException {
    216216                ArrayList list
    217217
  • trunk/grails-app/services/nl/tno/metagenomics/integration/SynchronizationService.groovy

    r3 r4  
    77class SynchronizationService {
    88        def gscfService
     9        def trashService
    910
    1011        String sessionToken = ""        // Session token to use for communication
     
    8182                        return
    8283
    83                 def previousEager = eager
    84                 eager = true
    85                 synchronizeStudies();
    86                 eager = previousEager
     84                def previousEager = this.eager
     85                this.eager = true
     86                this.synchronizeStudies();
     87                this.eager = previousEager
    8788               
    8889                SynchronizationService.lastFullSynchronization = new Date();
     
    9596        public ArrayList<Study> synchronizeStudies() {
    9697                if( !performSynchronization() )
    97                         return Study.findAll()
     98                        return Study.list()
    9899
    99100                // When eager fetching is enabled, ask for all studies, otherwise only ask for studies marked dirty
     
    102103                def studies
    103104                if( eager ) {
    104                         studies = Study.findAll()
     105                        studies = Study.list().findAll { !it.trashcan };
     106                        log.trace "Eager synchronization: " + studies.size();
    105107                } else {
    106108                        studies = Study.findAllWhere( [isDirty: true] );
    107                 }
    108 
     109                        log.trace "Default synchronization: " + studies.size()
     110                }
     111               
    109112                // Perform no synchronization if no studies have to be synchronized
    110113                // Perform synchronization on only one study directly, because otherwise
     
    235238                        return null
    236239
     240                // Trashcan should never be synchronized
     241                if( study.trashcan )
     242                        return study
     243                       
    237244                // If the study hasn't changed, don't update anything
    238245                if( !eager && !study.isDirty )
     
    249256                } catch( ResourceNotFoundException e ) {
    250257                        // Study can't be found within GSCF.
    251                         // TODO: How to handle the data that remains
    252                         study.delete()
     258                        trashService.moveToTrash( study );
    253259                        return null
    254260                } catch( Exception e ) { // All other exceptions
     
    335341                        for( int i = numStudyAssays - 1; i >= 0; i-- ) {
    336342                                def existingAssay = studyAssays[i];
    337 
    338                                 existingAssay.delete()
    339                                 study.removeFromAssays( existingAssay );
     343                               
     344                                // Move data to trash
     345                                trashService.moveToTrash( existingAssay );
    340346                        }
    341347
     
    408414
    409415                                // The assay has been removed
    410                                 // TODO: What to do with the data associated with this Assay (e.g. sequences)? See also GSCF ticket #255
    411                                 existingAssay.delete();
    412                                 study.removeFromAssays( existingAssay );
     416                                trashService.moveToTrash( existingAssay );
    413417                        }
    414418                }
     
    446450                } catch( ResourceNotFoundException e ) {
    447451                        // Study has been deleted, remove all authorization on that study
    448                         // TODO: handle deletion
    449452                        log.trace( "Study " + study.studyToken + " has been deleted. Remove all authorization on that study")
    450 
    451                         Auth.findAllByStudy( study ).each {
    452                                 it.delete()
    453                         }
     453                        trashService.moveToTrash( study );
    454454
    455455                        return null
     
    501501                } catch( ResourceNotFoundException e ) {
    502502                        // Assay can't be found within GSCF.
    503                         // TODO: How to handle the data that remains
    504                         assay.delete()
     503                        trashService.moveToTrash( assay );
    505504                        return null
    506505                } catch( Exception e ) { // All other exceptions are thrown
     
    511510                }
    512511
    513                 // If new assay is empty, something went wrong
     512                // If new assay is empty, this means that the assay does exist, but now belongs to another module. Remove it from our system
    514513                if( newAssay.size() == 0 ) {
    515                         throw new Exception( "No data returned for assay " + assay.assayToken + " but no error has occurred either. Please contact your system administrator" );
     514                        log.info( "No data is returned by GSCF for assay  " + assay.assayToken + "; probably the assay is connected to another module." )
     515                        trashService.moveToTrash( assay );
    516516                        return null;
    517517                }
     
    577577                } catch( ResourceNotFoundException e ) {
    578578                        // Assay can't be found within GSCF. Samples will be removed
    579                         // TODO: How to handle the data that remains
    580                         assay.removeAssaySamples();
     579                        trashService.moveToTrash( assay );
    581580
    582581                        return null
     
    593592                        return []
    594593                }
    595 
    596594
    597595                synchronizeAssaySamples( assay, newSamples );
     
    678676
    679677                                        // The sample has been removed
    680                                         // TODO: What to do with the data associated with this AssaySample (e.g. sequences)? See also GSCF ticket #255
    681                                         existingSample.delete();
    682                                         assay.removeFromAssaySamples( existingSample );
     678                                        trashService.moveToTrash( existingSample.sample );
    683679                                }
    684680                        }
  • trunk/grails-app/taglib/nl/tno/metagenomics/UploadTagLib.groovy

    r2 r4  
    2323                out << '<script type="text/javascript">';
    2424                out << '  $(document).ready( function() { ';
    25                 out << '    var filename = "' + attrs.value + '";';
     25                out << '    var filename = "' + ( attrs.value ?: '' ) + '";';
    2626                out << '    fileUploadField( "' + attrs.name + '", ' + ( multiple ? 'true' : 'false' ) + ( attrs.onUpload ? ', function(params) { ' + attrs.onUpload + '(params); }' : '' ) + ( attrs.onDelete ? ', function(params) { ' + attrs.onDelete + '(params); }' : '' ) + ');';
    2727                out << '    if( filename != "" ) {';
  • trunk/grails-app/views/assay/_addRunDialog.gsp

    r2 r4  
    3131                                                        <th nowrap>date</th>
    3232                                                        <th nowrap>other assays</th>
     33                                                        <th class="nonsortable"></th>
    3334                                                </tr>
    3435                                        </thead>                               
     
    4950                                                                        </g:else>
    5051                                                                </td>
     52                                                                <td>
     53                                                                        <g:if test="${run.sequenceData?.size()}">
     54                                                                                <img src="${fam.icon(name: 'delete')}" class="disabled" title="You can't delete this run because samples are associated with this run." />
     55                                                                        </g:if>
     56                                                                        <g:else>
     57                                                                                <g:if test="${run.assays?.size() > 0}">
     58                                                                                        <g:link onClick="return confirm( 'Are you sure you want to delete this run from the system? If you delete this run, it will also be deleted from the other assays it is associated to!' );" controller="run" action="delete" id="${run.id}" params="[assayId: assay.id]"><img src="${fam.icon(name: 'delete')}" /></g:link>
     59                                                                                </g:if>
     60                                                                                <g:else>
     61                                                                                        <g:link onClick="return confirm( 'Are you sure you want to delete this run from the system?' );" controller="run" action="delete" id="${run.id}" params="[assayId: assay.id]"><img src="${fam.icon(name: 'delete')}" /></g:link>
     62                                                                                </g:else>
     63                                                                        </g:else>
     64                                                                </td>
    5165                                                        </tr>
    5266                                                </g:each>
  • trunk/grails-app/views/assay/show.gsp

    r3 r4  
    2727                        </g:each>
    2828                       
    29                         $(function() {
    30                                 $('.uploadedFile').each( function( idx, el ) {
     29                        function initializeUploadedFiles( selector ) {
     30                                if( selector == undefined )
     31                                        selector = "";
     32                               
     33                                $( selector + ' .uploadedFile').each( function( idx, el ) {
    3134                                        $(el).html( createFileHTML( $(el).text(), 'getPermanent' ) );
    3235                                });
    33                         });
     36                        }
     37
     38                        // Initializefiles on load
     39                        $(function() { initializeUploadedFiles(); });
    3440                </script>
    3541        </head>
     
    97103                        <g:render template="addFilesDialog" model="[assay: assay]" />
    98104                </g:if>
    99                 <g:render template="showSampleDialog" model="[assay: assay]" />
     105                <div id="showSampleDialog" class="dialog"></div>
    100106        </g:else>       
    101107
     
    140146                                                </td>
    141147                                                <td class="button"><a href="#" onClick="showEditRunDialog( ${run.id}, '${run.name?.encodeAsJavaScript()}', '${run.date ? run.date.format( 'yyyy-mm-dd' ).encodeAsJavaScript() : ''}', '${run.machine?.encodeAsJavaScript()}', '${run.supplier?.encodeAsJavaScript()}', '${run.parameterFile?.encodeAsJavaScript()}' ); return false;"><img src="${fam.icon(name: 'application_edit')}" /></a></td>
    142                                                 <td class="button"><g:link onClick="return confirm( 'Are you sure you want to remove the selected run from this assay?' );" controller="assay" action="removeRun" id="${assay.id}" params="${[run_id: run.id]}" ><img src="${fam.icon(name: 'application_delete')}" /></g:link></td>
     148                                                <td class="button">
     149                                                        <g:if test="${run.samples(assay.id).size()}">
     150                                                                <img src="${fam.icon(name: 'application_delete')}" class="disabled" title="You can't remove this assay because sequences from this assay are coupled to this run." />
     151                                                        </g:if>
     152                                                        <g:else>
     153                                                                <g:link onClick="return confirm( 'Are you sure you want to remove the selected run from this assay?' );" controller="assay" action="removeRun" id="${assay.id}" params="${[run_id: run.id]}" ><img src="${fam.icon(name: 'application_delete')}" /></g:link>
     154                                                        </g:else>
     155                                                </td>
    143156                                        </tr>
    144157                                </g:each>
     
    149162                <input type="button" value="Add run" onClick="showAddRunDialog();">
    150163                <g:render template="addRunDialog" model="[assay: assay]" />
    151                 <g:render template="editRunDialog" model="[assay: assay]" />
     164                <div id="editRunDialog" class="dialog"></div>
    152165        </g:if>
    153         <g:render template="showRunDialog" model="[assay: assay]" />
    154        
     166        <div id="showRunDialog" class="dialog"></div>
    155167</body>
    156168</html>
  • trunk/web-app/css/metagenomics.css

    r3 r4  
    473473    display: none;
    474474}
     475
     476.disabled {
     477        opacity: 0.5;
     478        -moz-opacity:0.5;
     479        -khtml-opacity:0.5;
     480        filter:alpha(opacity=50);
     481}
     482
     483.ui-dialog a:link, .ui-dialog a:visited, .ui-dialog a:hover {
     484        color: #006dba;
     485        text-decoration: none;
     486}
  • trunk/web-app/js/assay.show.runDialogs.js

    r2 r4  
    4242       
    4343        // Initialize date picker for add run dialog
    44         $( "#run_date, #edit_run_date" ).datepicker({
     44        $( "#run_date" ).datepicker({
    4545                changeMonth: true,
    4646                changeYear: true,
     
    6666 */
    6767function showEditRunDialog(id, name, date, machine, supplier, parameterFile) {
    68         $( '#edit_run_id' ).val( id );
    69        
    70         $( '#edit_run_name' ).val( name );
    71         $( '#edit_run_date' ).val( date );
    72         $( '#edit_run_machine' ).val( machine );
    73         $( '#edit_run_supplier' ).val( supplier );
    74        
    75         editFile( 'editParameterFile', parameterFile)
    76         $( "#editRunDialog" ).dialog( "open" );
     68        $( "#editRunDialog" ).load( baseUrl + "/run/editForm/" + id + "?assayId=" + assayId, [], function() {
     69                // Initialize date picker for add run dialog
     70                $( "#edit_run_date" ).datepicker({
     71                        changeMonth: true,
     72                        changeYear: true,
     73                        dateFormat: 'yy-mm-dd'
     74                });     
     75               
     76                $( "#editRunDialog" ).dialog( "open" );
     77        } );
    7778}
    7879
  • trunk/web-app/js/assay.show.showRunDialog.js

    r3 r4  
    1515 */
    1616function showRun( id ) {
    17         $( '#showRunDialog div.showRun' ).hide()
    18         $( '#showRunDialog div#showRun_' + id ).show()
    19        
    20         var titleEl = $( '#showRunDialog div#showRun_' + id + ' h2' ).first();
    21         titleEl.hide();
    22         $( "#showRunDialog" ).dialog( "option", "title", "Run " + titleEl.text() );
    23         $( "#showRunDialog" ).dialog( "open" );
     17        $( "#showRunDialog" ).load( baseUrl + "/run/show/" + id + "?assayId=" + assayId, [], function() {
     18                var titleEl = $( '#showRunDialog h2' ).first();
     19                titleEl.hide();
     20               
     21                initializeUploadedFiles( '#showRunDialog' );
     22                initializePagination( '#showRunDialog' );
     23                               
     24                $( "#showRunDialog" ).dialog( "option", "title", "Run " + titleEl.text() );
     25                $( "#showRunDialog" ).dialog( "open" );
     26        } );
    2427}
  • trunk/web-app/js/assay.show.showSampleDialog.js

    r3 r4  
    1515 */
    1616function showSample( id ) {
    17         $( '#showSampleDialog div.showSample' ).hide()
    18         $( '#showSampleDialog div#showSample_' + id ).show()
    19        
    20         var titleEl = $( '#showSampleDialog div#showSample_' + id + ' h2' ).first();
    21         titleEl.hide();
    22         $( "#showSampleDialog" ).dialog( "option", "title", "Sample " + titleEl.text() );
    23         $( "#showSampleDialog" ).dialog( "open" );
     17        $( "#showSampleDialog" ).load( baseUrl + "/assaySample/show/" + id, [], function() {
     18                var titleEl = $( '#showSampleDialog h2' ).first();
     19                titleEl.hide();
     20               
     21                initializeUploadedFiles( "#showSampleDialog" );
     22                initializePagination( "#showSampleDialog" );
     23                               
     24                $( "#showSampleDialog" ).dialog( "option", "title", "Sample " + titleEl.text() );
     25                $( "#showSampleDialog" ).dialog( "open" );
     26        } );
    2427}
  • trunk/web-app/js/paginate.js

    r2 r4  
    1         $(function() {
    2                 $('.paginate').each(function(idx, el) {
    3                         var $el = $(el);
    4                         $el.dataTable({
    5                                 bJQueryUI: true,
    6                                 bFilter: false,
    7                                 bLengthChange: false,
    8                                 iCookieDuration: 86400,                         // Save cookie one day
    9                                 sPaginationType: 'full_numbers',
    10                                 iDisplayLength: 10,                                     // Number of items shown on one page.
    11                                 aoColumnDefs: [
    12                                         { "bSortable": false, "aTargets": ["nonsortable"] }     // Disable sorting on all columns with th.nonsortable
    13                                 ]                                               
    14                         });
    15                 });
    16                
    17                 // Remove the top bar of the datatable and hide pagination with only one page
    18                 $(".dataTables_wrapper").each(function(idx, el) {
    19                         var $el = $(el);
    20                        
    21                         // Hide pagination if only one page is present (that is: if no buttons can be clicked)
    22                         if($el.find('span span.ui-state-default:not(.ui-state-disabled)').size() == 0 ){
    23                                 $el.find('div.fg-toolbar').css( 'display', 'none' );
    24                         } else {
    25                                 $el.find('div.fg-toolbar').css( 'display', 'block' );
    26                                 $el.find( 'div.ui-toolbar' ).first().hide();
    27                                
    28                                 // Check whether a h1, h2 or h3 is present above the table, and move it into the table
    29                                 /*
    30                                 var $previousElement = $el.prev();
    31                                 if( $previousElement != undefined && $previousElement.get(0) != undefined ) {
    32                                         var tagName = $previousElement.get(0).tagName.toLowerCase();
    33                                         if( tagName == "h1" || tagName == "h2" || tagName == "h3" ) {
    34                                                 // Put the margin that was on the title onto the table
    35                                                 $el.css( "margin-top", $previousElement.css( "margin-top" ) );
    36                                                 $previousElement.css( "margin-top", '4px' );
    37                                                 $previousElement.css( "marginBottom", '4px' );
    38 
    39                                                 // If so, move the element into the table
    40                                                 $previousElement.remove();
    41                                                 $el.find( 'div.ui-toolbar' ).first().append( $previousElement );
    42                                         }
    43                                 }
    44                                 */                                             
    45                         }
     1function initializePagination( selector ) {
     2        if( selector == undefined ) {
     3                selector = ''
     4        }
     5       
     6        $( selector + ' .paginate').each(function(idx, el) {
     7                var $el = $(el);
     8                $el.dataTable({
     9                        bJQueryUI: true,
     10                        bFilter: false,
     11                        bLengthChange: false,
     12                        iCookieDuration: 86400,                         // Save cookie one day
     13                        sPaginationType: 'full_numbers',
     14                        iDisplayLength: 10,                                     // Number of items shown on one page.
     15                        aoColumnDefs: [
     16                                { "bSortable": false, "aTargets": ["nonsortable"] }     // Disable sorting on all columns with th.nonsortable
     17                        ]                                               
    4618                });
    4719        });
     20       
     21        // Remove the top bar of the datatable and hide pagination with only one page
     22        $( selector + " .dataTables_wrapper").each(function(idx, el) {
     23                var $el = $(el);
     24               
     25                // Hide pagination if only one page is present (that is: if no buttons can be clicked)
     26                if($el.find('span span.ui-state-default:not(.ui-state-disabled)').size() == 0 ){
     27                        $el.find('div.fg-toolbar').css( 'display', 'none' );
     28                } else {
     29                        $el.find('div.fg-toolbar').css( 'display', 'block' );
     30                        $el.find( 'div.ui-toolbar' ).first().hide();
     31                       
     32                        // Check whether a h1, h2 or h3 is present above the table, and move it into the table
     33                        /*
     34                        var $previousElement = $el.prev();
     35                        if( $previousElement != undefined && $previousElement.get(0) != undefined ) {
     36                                var tagName = $previousElement.get(0).tagName.toLowerCase();
     37                                if( tagName == "h1" || tagName == "h2" || tagName == "h3" ) {
     38                                        // Put the margin that was on the title onto the table
     39                                        $el.css( "margin-top", $previousElement.css( "margin-top" ) );
     40                                        $previousElement.css( "margin-top", '4px' );
     41                                        $previousElement.css( "marginBottom", '4px' );
     42
     43                                        // If so, move the element into the table
     44                                        $previousElement.remove();
     45                                        $el.find( 'div.ui-toolbar' ).first().append( $previousElement );
     46                                }
     47                        }
     48                        */                                             
     49                }
     50        });
     51       
     52}
     53
     54$(function() { initializePagination(); });
Note: See TracChangeset for help on using the changeset viewer.