Skip to content

Instantly share code, notes, and snippets.

@k4200
Created July 10, 2011 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4200/1074403 to your computer and use it in GitHub Desktop.
Save k4200/1074403 to your computer and use it in GitHub Desktop.
A trait that modifies CRUDify a bit
// This file is distributed under the same license as that of Lift.
package com.example
package lib
import net.liftweb.mapper._
import net.liftweb.common._
import net.liftweb.http.S
trait MegaCRUDify[KeyType, CrudType <: KeyedMapper[KeyType, CrudType]]
extends CRUDify[KeyType, CrudType] {
self: CrudType with KeyedMetaMapper[KeyType, CrudType] =>
//TODO ugly
def enableCreate: Boolean = createMenuLoc match { case Empty => false ; case _ => true }
def enableEdit: Boolean = editMenuLoc match { case Empty => false ; case _ => true }
def enableDelete: Boolean = deleteMenuLoc match { case Empty => false ; case _ => true }
override def _showAllTemplate =
<lift:crud.all>
<table id={showAllId} class={showAllClass}>
<thead>
<tr>
<crud:header_item><th><crud:name/></th></crud:header_item>
{if(enableCreate){<th>&nbsp;</th>}}
{if(enableEdit){<th>&nbsp;</th>}}
{if(enableDelete){<th>&nbsp;</th>}}
</tr>
</thead>
<tbody>
<crud:row>
<tr>
<crud:row_item><td><crud:value/></td></crud:row_item>
{if(enableCreate){<td><a crud:view_href="">{S.??("View")}</a></td>}}
{if(enableEdit){<td><a crud:edit_href="">{S.??("Edit")}</a></td>}}
{if(enableDelete){<td><a crud:delete_href="">{S.??("Delete")}</a></td>}}
</tr>
</crud:row>
</tbody>
<tfoot>
<tr>
<td colspan="3"><crud:prev>{previousWord}</crud:prev></td>
<td colspan="3"><crud:next>{nextWord}</crud:next></td>
</tr>
</tfoot>
</table>
</lift:crud.all>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment