/
Crudify.scala
816 lines (665 loc) · 23 KB
/
Crudify.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
/*
* Copyright 2006-2011 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftweb
package proto
import sitemap._
import Loc._
import http._
import util._
import common._
import Helpers._
import scala.xml._
/**
* This trait automatically adds CRUD (Create, read, update and delete) operations
* to an existing persistence mechanism.
* Various methods can be overridden to
* customize which operations are available to a user and how things are displayed.
* For example, you can disable deletion of entities by overriding deleteMenuLoc to Empty.
*
*/
trait Crudify {
/**
* The type of records we're manipulating
*/
type TheCrudType
/**
* A generic representation of a field. For example, this represents the
* abstract "name" field and is used along with an instance of TheCrudType
* to compute the BaseField that is the "name" field on the specific instance
* of TheCrudType
*/
type FieldPointerType
/**
* This trait represents a Bridge between TheCrudType
* and the Crudify trait. It's not necessary to mix this
* trait into TheCrudType, but instead provide a mechanism
* for promoting a TheCrudType to CrudBridge
*/
protected trait CrudBridge {
/**
* Delete the instance of TheCrudType from the backing store
*/
def delete_! : Boolean
/**
* Save an instance of TheCrudType in backing store
*/
def save : Boolean
/**
* Validate the fields in TheCrudType and return a List[FieldError]
* representing the errors.
*/
def validate: List[FieldError]
/**
* Return a string representation of the primary key field
*/
def primaryKeyFieldAsString: String
}
/**
* This method will instantiate a bridge from TheCrudType so
* that the appropriate logical operations can be performed
* on TheCrudType
*/
protected implicit def buildBridge(from: TheCrudType): CrudBridge
protected trait FieldPointerBridge {
/**
* What is the display name of this field?
*/
def displayHtml: NodeSeq
}
/**
* Based on a FieldPointer, build a FieldPointerBridge
*/
protected implicit def buildFieldBridge(from: FieldPointerType): FieldPointerBridge
lazy val Prefix = calcPrefix
lazy val ListItems = calcListItems
lazy val ViewItem = calcViewItem
lazy val CreateItem = calcCreateItem
lazy val EditItem = calcEditItem
lazy val DeleteItem = calcDeleteItem
/**
* What's the prefix for this CRUD. Typically the table name
*/
def calcPrefix: List[String]
/**
* Vend a new instance of TheCrudType
*/
def create: TheCrudType
def calcListItems = "list"
def calcViewItem = "view"
def calcCreateItem = "create"
def calcEditItem = "edit"
def calcDeleteItem = "delete"
def displayName = displayHtml.text
def displayHtml: NodeSeq = Text(calcPrefix.head)
/**
* The fields displayed on the list page. By default all
* the displayed fields, but this list
* can be shortened.
*/
def fieldsForList: List[FieldPointerType] = fieldsForDisplay
/**
* When displaying a record, what fields do we display
*/
def fieldsForDisplay: List[FieldPointerType]
/**
* The list of fields to present on a form form editting
*/
def fieldsForEditing: List[FieldPointerType] = fieldsForDisplay
def pageWrapper(body: NodeSeq): NodeSeq =
<lift:surround with="default" at="content">
{
body
}
</lift:surround>
/**
* The menu item for listing items (make this "Empty" to disable)
*/
def showAllMenuLoc: Box[Menu] =
Full(Menu(Loc("List "+Prefix, listPath, showAllMenuName,
addlMenuLocParams ::: (
locSnippets :: Loc.Template(showAllTemplate) ::
showAllMenuLocParams))))
/**
* Override to include new Params for the show all menu
*/
def showAllMenuLocParams: List[Loc.AnyLocParam] = Nil
/**
* The menu item for creating items (make this "Empty" to disable)
*/
def createMenuLoc: Box[Menu] =
Full(Menu(Loc("Create "+Prefix, createPath, createMenuName,
(addlMenuLocParams ::: (
locSnippets :: Loc.Template(createTemplate) ::
createMenuLocParams)))))
/**
* Override to include new Params for the create menu
*/
def createMenuLocParams: List[Loc.AnyLocParam] = Nil
/**
* If there are any Loc.LocParams that need to be
* added to every menu (e.g., a guard for access control
* of the Crudify screens)
*/
protected def addlMenuLocParams: List[Loc.AnyLocParam] = Nil
/**
* Customize the display of a row for displayRecord
*/
protected def doDisplayRecordRow(entry: TheCrudType)(in: NodeSeq): NodeSeq =
for {
pointer <- fieldsForDisplay
field <- computeFieldFromPointer(entry, pointer).toList
if field.shouldDisplay_?
node <- bind("crud", in,
"name" -> field.displayHtml,
"value" -> field.asHtml)
} yield node
/**
* Customize the display of records for view menu loc
*/
protected def displayRecord(entry: TheCrudType)(in: NodeSeq): NodeSeq = {
bind("crud", in, "row" -> doDisplayRecordRow(entry) _)
}
/**
* The menu item for viewing an item (make this "Empty" to disable)
*/
def viewMenuLoc: Box[Menu] =
Full(Menu(new Loc[TheCrudType]{
// the name of the page
def name = "View "+Prefix
override val snippets: SnippetTest = {
case ("crud.view", Full(wp: TheCrudType)) => displayRecord(wp) _
}
def defaultValue = Empty
lazy val params = addlMenuLocParams ::: viewMenuLocParams
/**
* What's the text of the link?
*/
val text = new Loc.LinkText(calcLinkText _)
def calcLinkText(in: TheCrudType): NodeSeq = Text(S.??("crudify.menu.view.displayName", displayName))
/**
* Rewrite the request and emit the type-safe parameter
*/
override val rewrite: LocRewrite =
Full(NamedPF(name) {
case RewriteRequest(pp , _, _) if hasParamFor(pp, viewPath) =>
(RewriteResponse(viewPath),
findForParam(pp.wholePath.last).open_!)
})
override def calcTemplate = Full(viewTemplate)
val link =
new Loc.Link[TheCrudType](viewPath, false) {
override def createLink(in: TheCrudType) =
Full(Text(viewPathString+"/"+obscurePrimaryKey(in)))
}
}))
/**
* Override to include new Params for the view menu
*/
def viewMenuLocParams: List[Loc.LocParam[TheCrudType]] = Nil
/**
* The menu item for editing an item (make this "Empty" to disable)
*/
def editMenuLoc: Box[Menu] = {
Full(Menu(new Loc[TheCrudType]{
// the name of the page
def name = "Edit "+Prefix
override val snippets: SnippetTest = {
case ("crud.edit", Full(wp: TheCrudType)) => crudDoForm(wp, S.??("Save"))
}
def defaultValue = Empty
lazy val params = addlMenuLocParams ::: editMenuLocParams
/**
* What's the text of the link?
*/
val text = new Loc.LinkText(calcLinkText _)
def calcLinkText(in: TheCrudType): NodeSeq = Text(S.??("crudify.menu.edit.displayName", displayName))
/**
* Rewrite the request and emit the type-safe parameter
*/
override val rewrite: LocRewrite =
Full(NamedPF(name) {
case RewriteRequest(pp , _, _) if hasParamFor(pp, editPath) =>
(RewriteResponse(editPath),
findForParam(pp.wholePath.last).open_!)
})
override def calcTemplate = Full(editTemplate)
val link =
new Loc.Link[TheCrudType](editPath, false) {
override def createLink(in: TheCrudType) =
Full(Text(editPathString+"/"+obscurePrimaryKey(in)))
}
}))
}
/**
* Override to include new Params for the edit menu
*/
def editMenuLocParams: List[Loc.LocParam[TheCrudType]] = Nil
/**
* The String displayed for menu editing
*/
def editMenuName = S.??("Edit")+" "+displayName
/**
* This is the template that's used to render the page after the
* optional wrapping of the template in the page wrapper
*/
def editTemplate(): NodeSeq = pageWrapper(_editTemplate)
def editId = "edit_page"
def editClass = "edit_class"
def editErrorClass = "edit_error_class"
/**
* The core template for editting. Does not include any
* page wrapping
*/
protected def _editTemplate = {
<lift:crud.edit form="post">
<table id={editId} class={editClass}>
<crud:field>
<tr>
<td>
<crud:name/>
</td>
<td>
<crud:form/>
</td>
</tr>
</crud:field>
<tr>
<td> </td>
<td><crud:submit>{editButton}</crud:submit></td>
</tr>
</table>
</lift:crud.edit>
}
def editButton = S.??("Save")
/**
* Override this method to change how fields are displayed for delete
*/
protected def doDeleteFields(item: TheCrudType)(html: NodeSeq): NodeSeq =
for {
pointer <- fieldsForDisplay
field <- computeFieldFromPointer(item, pointer).toList
if field.shouldDisplay_?
node <- bind("crud", html,
"name" -> field.displayHtml,
"value" -> field.asHtml)
} yield node
/**
* Override this method to change the behavior of deleting an item
*/
protected def doDeleteSubmit(item: TheCrudType, from: String)() = {
S.notice(S ? "Deleted")
item.delete_!
S.redirectTo(from)
}
/**
* Override this method to change how the delete screen is built
*/
protected def crudyDelete(item: TheCrudType)(html: NodeSeq): NodeSeq = {
val from = referer
bind("crud", html,
"field" -> doDeleteFields(item) _,
"submit" ->
((text: NodeSeq) => SHtml.submit(text.text,
doDeleteSubmit(item, from) _)))
}
/**
* The menu item for deleting an item (make this "Empty" to disable)
*/
def deleteMenuLoc: Box[Menu] = {
Full(Menu(new Loc[TheCrudType]{
// the name of the page
def name = "Delete "+Prefix
override val snippets: SnippetTest = {
case ("crud.delete", Full(wp: TheCrudType)) => crudyDelete(wp)
}
def defaultValue = Empty
lazy val params = addlMenuLocParams ::: deleteMenuLocParams
/**
* What's the text of the link?
*/
val text = new Loc.LinkText(calcLinkText _)
def calcLinkText(in: TheCrudType): NodeSeq = Text(S.??("crudify.menu.delete.displayName", displayName))
/**
* Rewrite the request and emit the type-safe parameter
*/
override val rewrite: LocRewrite =
Full(NamedPF(name) {
case RewriteRequest(pp , _, _) if hasParamFor(pp, deletePath) =>
(RewriteResponse(deletePath),
findForParam(pp.wholePath.last).open_!)
})
override def calcTemplate = Full(deleteTemplate)
val link =
new Loc.Link[TheCrudType](deletePath, false) {
override def createLink(in: TheCrudType) =
Full(Text(deletePathString+"/"+obscurePrimaryKey(in)))
}
}))
}
private def hasParamFor(pp: ParsePath, toTest: List[String]): Boolean = {
pp.wholePath.startsWith(toTest) &&
pp.wholePath.length == (toTest.length + 1) &&
findForParam(pp.wholePath.last).isDefined
}
/**
* Override to include new Params for the delete menu
*/
def deleteMenuLocParams: List[Loc.LocParam[TheCrudType]] = Nil
def deleteMenuName = S.??("Delete")+" "+displayName
/**
* This is the template that's used to render the page after the
* optional wrapping of the template in the page wrapper
*/
def deleteTemplate(): NodeSeq = pageWrapper(_deleteTemplate)
def deleteId = "delete_page"
def deleteClass = "delete_class"
/**
* The core template for deleting. Does not include any
* page wrapping
*/
def _deleteTemplate =
<lift:crud.delete form="post">
<table id={deleteId} class={deleteClass}>
<crud:field>
<tr>
<td>
<crud:name/>
</td>
<td>
<crud:value/>
</td>
</tr>
</crud:field>
<tr>
<td> </td>
<td><crud:submit>{deleteButton}</crud:submit></td>
</tr>
</table>
</lift:crud.delete>
def deleteButton = S.??("Delete")
def createMenuName = S.??("Create")+" "+displayName
/**
* This is the template that's used to render the page after the
* optional wrapping of the template in the page wrapper
*/
def createTemplate(): NodeSeq = pageWrapper(_createTemplate)
def createId = "create_page"
def createClass = "create_class"
/**
* The core template for creating. Does not include any
* page wrapping
*/
def _createTemplate =
<lift:crud.create form="post">
<table id={createId} class={createClass}>
<crud:field>
<tr>
<td>
<crud:name/>
</td>
<td>
<crud:form/>
</td>
</tr>
</crud:field>
<tr>
<td> </td>
<td><crud:submit>{createButton}</crud:submit></td>
</tr>
</table>
</lift:crud.create>
def createButton = S.??("Create")
def viewMenuName = S.??("View")+" "+displayName
/**
* This is the template that's used to render the page after the
* optional wrapping of the template in the page wrapper
*/
def viewTemplate(): NodeSeq = pageWrapper(_viewTemplate)
def viewId = "view_page"
def viewClass = "view_class"
/**
* The core template for viewing. Does not include any
* page wrapping
*/
def _viewTemplate =
<lift:crud.view>
<table id={viewId} class={viewClass}>
<crud:row>
<tr>
<td><crud:name/></td>
<td><crud:value/></td>
</tr>
</crud:row>
</table>
</lift:crud.view>
def showAllMenuName = S.??("List")+" "+displayName
/**
* This is the template that's used to render the page after the
* optional wrapping of the template in the page wrapper
*/
def showAllTemplate(): NodeSeq = pageWrapper(_showAllTemplate)
def showAllId = "show_all"
def showAllClass = "show_all"
/**
* The core template for showing record. Does not include any
* page wrapping
*/
def _showAllTemplate =
<lift:crud.all>
<table id={showAllId} class={showAllClass}>
<thead>
<tr>
<crud:header_item><th><crud:name/></th></crud:header_item>
<th> </th>
<th> </th>
<th> </th>
</tr>
</thead>
<tbody>
<crud:row>
<tr>
<crud:row_item><td><crud:value/></td></crud:row_item>
<td><a crud:view_href="">{S.??("View")}</a></td>
<td><a crud:edit_href="">{S.??("Edit")}</a></td>
<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>
def nextWord = S.??("Next")
def previousWord = S.??("Previous")
lazy val listPath = Prefix ::: List(ListItems)
lazy val listPathString: String = mp(listPath)
lazy val createPath = Prefix ::: List(CreateItem)
lazy val createPathString: String = mp(createPath)
lazy val viewPath = Prefix ::: List(ViewItem)
lazy val viewPathString: String = mp(viewPath)
lazy val editPath = Prefix ::: List(EditItem)
lazy val editPathString: String = mp(editPath)
lazy val deletePath = Prefix ::: List(DeleteItem)
lazy val deletePathString: String = mp(deletePath)
private def mp(in: List[String]) = in.mkString("/", "/", "")
def menus: List[Menu] =
List(showAllMenuLoc, createMenuLoc, viewMenuLoc,
editMenuLoc, deleteMenuLoc).flatMap(x => x)
/**
* Given a range, find the records. Your implementation of this
* method should enforce ordering (e.g., on primary key)
*/
def findForList(start: Long, count: Int): List[TheCrudType]
/**
* Given a String that represents the primary key, find an instance of
* TheCrudType
*/
def findForParam(in: String): Box[TheCrudType]
/**
* Given an instance of TheCrudType and FieldPointerType, convert
* that to an actual instance of a BaseField on the instance of TheCrudType
*/
protected def computeFieldFromPointer(instance: TheCrudType, pointer: FieldPointerType): Box[BaseField]
/**
* This method defines how many rows are displayed per page. By
* default, it's hard coded at 20, but you can make it session specific
* or change the default by overriding this method
*/
protected def rowsPerPage: Int = 20
/**
* Override this method to customize how header items are treated
*/
protected def doCrudAllHeaderItems(in: NodeSeq): NodeSeq =
fieldsForList.flatMap(f =>
bind("crud", in, "name" -> f.displayHtml))
/**
* Override this method to customize how a crudAll line is generated
*/
protected def doCrudAllRowItem(c: TheCrudType)(in: NodeSeq): NodeSeq =
for {
pointer <- fieldsForList
field <- computeFieldFromPointer(c, pointer).toList
node <- bind("crud", in, "value" -> field.asHtml)
} yield node
/**
* Override this method to determine how all the rows on a crud
* page are displayed
*/
protected def doCrudAllRows(list: List[TheCrudType])(in: NodeSeq): NodeSeq =
list.take(rowsPerPage).flatMap{
c =>
bind("crud", in , "row_item" -> doCrudAllRowItem(c) _,
FuncAttrBindParam("edit_href", { ignore : NodeSeq =>
Text(editPathString+"/"+(obscurePrimaryKey(c))) },"href"),
FuncAttrBindParam("view_href", { ignore : NodeSeq =>
Text(viewPathString+"/"+
(obscurePrimaryKey(c)))},"href"),
FuncAttrBindParam("delete_href", { ignore : NodeSeq =>
Text(deletePathString+"/"+
(obscurePrimaryKey(c)))},"href")
)}
/**
* Override this method to change how the previous link is
* generated
*/
protected def crudAllPrev(first: Long)(in: NodeSeq) =
if (first < rowsPerPage) <xml:group> </xml:group>
else <a href={listPathString+
"?first="+(0L max (first -
rowsPerPage.toLong))}>{in}</a>
/**
* Override this method to change how the next link is generated
*/
protected def crudAllNext(first: Long, list: List[TheCrudType])(in: NodeSeq) =
if (list.length < rowsPerPage) <xml:group> </xml:group>
else <a href={listPathString+"?first="+(first +
rowsPerPage.toLong)}>{in}</a>
/**
* Override this method if you want to change the behavior
* of displaying records via the crud.all snippet
*/
protected def doCrudAll(in: NodeSeq): NodeSeq = {
val first = S.param("first").map(toLong) openOr 0L
val list = findForList(first, rowsPerPage)
bind("crud", in, "header_item" -> doCrudAllHeaderItems _,
"row" -> doCrudAllRows(list) _,
"prev" -> crudAllPrev(first) _,
"next" -> crudAllNext(first, list) _)
}
lazy val locSnippets = new DispatchLocSnippets {
val dispatch: PartialFunction[String, NodeSeq => NodeSeq] = {
case "crud.all" => doCrudAll
case "crud.create" => crudDoForm(create, S.??("Created"))
}
}
/**
* This method can be used to obscure the primary key. This is more secure
* because end users will not have access to the primary key.
*/
def obscurePrimaryKey(in: TheCrudType): String = obscurePrimaryKey(in.primaryKeyFieldAsString)
/**
* This method can be used to obscure the primary key. This is more secure
* because end users will not have access to the primary key. This method
* actually does the obfuscation. You can use Mapper's KeyObfuscator class
* to implement a nice implementation of this method for session-by-session
* obfuscation.<br/><br/>
*
* By default, there's no obfuscation. Note that if you obfuscate the
* primary key, you need to update the findForParam method to accept
* the obfuscated keys (and translate them back.)
*/
def obscurePrimaryKey(in: String): String = in
def referer: String = S.referer openOr listPathString
/**
* As the field names are being displayed for editting, this method
* is called with the XHTML that will be displayed as the field name
* an a flag indicating that the field is required (or not). You
* can wrap the fieldName in a span with a css class indicating that
* the field is required or otherwise do something to update the field
* name indiciating to the user that the field is required. By default
* the method wraps the fieldName in a span with the class attribute set
* to "required_field"
*/
def wrapNameInRequired(fieldName: NodeSeq, required: Boolean): NodeSeq = {
if (required) {
<span class="required_field">{fieldName}</span>
} else {
fieldName
}
}
def crudDoForm(item: TheCrudType, noticeMsg: String)(in: NodeSeq): NodeSeq = {
val from = referer
val snipName = S.currentSnippet
def loop(html:NodeSeq): NodeSeq = {
def error(field: BaseField): NodeSeq =
field.uniqueFieldId match {
case fid @ Full(id) => S.getNotices.filter(_._3 == fid).flatMap(err =>
List(Text(" "), <span class={editErrorClass}>{err._2}</span>) )
case _ => NodeSeq.Empty
}
def doFields(html: NodeSeq): NodeSeq =
for {
pointer <- fieldsForEditing
field <- computeFieldFromPointer(item, pointer).toList
if field.show_?
form <- field.toForm.toList
node <- bind("crud", html,
"name" -> (wrapNameInRequired(field.displayHtml,
field.required_?) ++
error(field)),
"form" -> form)
} yield node
def doSubmit() = item.validate match {
case Nil =>
S.notice(noticeMsg)
item.save
S.redirectTo(from)
case xs =>
S.error(xs)
snipName.foreach(S.mapSnippet(_, loop))
}
bind("crud", html,
"field" -> doFields _,
"submit" ->
((text: NodeSeq) => SHtml.submit(text.text, doSubmit _)))
}
loop(in)
}
}