Ignore:
Timestamp:
Mar 24, 2009, 3:30:12 AM (15 years ago)
Author:
gav
Message:

Start creating 'Detail views for Task. Add to BootStrap?. Small change to css.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/TaskRewrite/src/grails-app/controllers/TaskController.groovy

    r74 r84  
    66
    77    // the delete, save and update actions only accept POST requests
    8     static allowedMethods = [delete:'POST', save:'POST', update:'POST']
     8    static allowedMethods = [delete:'POST', deleteDetailed:'POST', save:'POST', saveDetailed:'POST', updateDetailed:'POST']
    99
     10    @Secured(['ROLE_AppAdmin'])
    1011    def list = {
    1112        if(!params.max) params.max = 10
     
    1314    }
    1415
     16    def listDetailed = {
     17        if(!params.max) params.max = 10
     18        [ taskInstanceList: Task.list( params ) ]
     19    }
     20
     21    @Secured(['ROLE_AppAdmin'])
    1522    def show = {
    1623        def taskInstance = Task.get( params.id )
     
    2330    }
    2431
     32    def showDetailed = {
     33        def taskInstance = Task.get( params.id )
     34
     35        if(!taskInstance) {
     36            flash.message = "Task not found with id ${params.id}"
     37            redirect(action:list)
     38        }
     39        else { return [ taskInstance : taskInstance ] }
     40    }
     41
     42    @Secured(['ROLE_AppAdmin'])     
    2543    def delete = {
    2644        def taskInstance = Task.get( params.id )
     
    3654    }
    3755
     56    def deleteDetailed = {
     57        def taskInstance = Task.get( params.id )
     58        if(taskInstance) {
     59            taskInstance.delete()
     60            flash.message = "Task ${params.id} deleted"
     61            redirect(action:list)
     62        }
     63        else {
     64            flash.message = "Task not found with id ${params.id}"
     65            redirect(action:list)
     66        }
     67    }
     68
     69    @Secured(['ROLE_AppAdmin'])
    3870    def edit = {
    3971        def taskInstance = Task.get( params.id )
     
    4880    }
    4981
     82    def editDetailed = {
     83        def taskInstance = Task.get( params.id )
     84
     85        if(!taskInstance) {
     86            flash.message = "Task not found with id ${params.id}"
     87            redirect(action:list)
     88        }
     89        else {
     90            def criteria = taskInstance.createCriteria()
     91            def results = criteria {
     92                and {
     93                    notEqual('id', taskInstance.id)
     94                    }
     95            }
     96            return [ taskInstance : taskInstance, possibleParentList: results ]
     97        }
     98    }
     99
     100    @Secured(['ROLE_AppAdmin'])
    50101    def update = {
    51102        def taskInstance = Task.get( params.id )
     
    66117    }
    67118
     119    def updateDetailed = {
     120        def taskInstance = Task.get( params.id )
     121        if(taskInstance) {
     122            taskInstance.properties = params
     123            if(!taskInstance.hasErrors() && taskInstance.save()) {
     124                flash.message = "Task ${params.id} updated"
     125                redirect(action:show,id:taskInstance.id)
     126            }
     127            else {
     128                render(view:'edit',model:[taskInstance:taskInstance])
     129            }
     130        }
     131        else {
     132            flash.message = "Task not found with id ${params.id}"
     133            redirect(action:edit,id:params.id)
     134        }
     135    }
     136
     137    @Secured(['ROLE_AppAdmin'])
    68138    def create = {
    69139        def taskInstance = new Task()
     
    72142    }
    73143
     144    def createDetailed = {
     145        def taskInstance = new Task()
     146        taskInstance.properties = params
     147        return ['taskInstance':taskInstance]
     148    }
     149
     150    @Secured(['ROLE_AppAdmin'])
    74151    def save = {
    75152        def taskInstance = new Task(params)
     
    82159        }
    83160    }
     161
     162    def saveDetailed = {
     163        def taskInstance = new Task(params)
     164        if(!taskInstance.hasErrors() && taskInstance.save()) {
     165            flash.message = "Task ${taskInstance.id} created"
     166            redirect(action:showDetailed,id:taskInstance.id)
     167        }
     168        else {
     169            render(view:'createDetailed',model:[taskInstance:taskInstance])
     170        }
     171    }
    84172}
Note: See TracChangeset for help on using the changeset viewer.