-
Notifications
You must be signed in to change notification settings - Fork 0
/
CategoryPage.scala
51 lines (43 loc) · 1.7 KB
/
CategoryPage.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
package net.shop
package web.pages
import scala.util.Failure
import scala.util.Success
import scala.xml._
import scala.xml._
import net.shift._
import net.shift._
import net.shift.engine.http._
import net.shift.engine.http._
import net.shift.loc._
import net.shift.template._
import net.shift.template._
import net.shift.template.Binds._
import net.shift.template.Snippet._
import net.shop.utils.ShopUtils._
import net.shop.web.ShopApplication
import net.shop.api.ShopError
object CategoryPage extends Cart[Request] { self =>
override def snippets = List(title, item) ++ super.snippets
def pageTitle(s: PageState[Request]) = Loc.loc0(s.lang)("categories").text
val item = reqSnip("item") {
s =>
{
val prods = ShopApplication.persistence.allCategories match {
case Success(list) =>
list flatMap { cat =>
(bind(s.node) {
case "li" attributes HasClass("item", a) / childs => <li>{ childs }</li>
case "div" attributes HasClass("cat_box", a) / childs => <div id={ cat stringId } style={ "background: url('" + categoryImagePath(cat) + "') no-repeat" }>{ childs }</div> % a
case "div" attributes HasClasses("info_tag_text" :: _, a) / _ => <div>{ cat.title_?(s.state.lang.name) }</div> % a
}) match {
case Success(n) => n
case Failure(ShopError(msg, _)) => errorTag(Loc.loc0(s.state.lang)(msg).text)
case Failure(f) => errorTag(f toString)
}
}
case Failure(t) => <div class="error">{ Loc.loc0(s.state.lang)("no.categories").text }</div>
}
Success(s.state.initialState, prods.toSeq)
}
}
}