1 | /** |
---|
2 | * TemplateEditorController Controler |
---|
3 | * |
---|
4 | * Webflow driven template editor |
---|
5 | * |
---|
6 | * @author Jeroen Wesbeek |
---|
7 | * @since 20100415 |
---|
8 | * @package studycapturing |
---|
9 | * |
---|
10 | * Revision information: |
---|
11 | * $Rev: 373 $ |
---|
12 | * $Author: duh $ |
---|
13 | * $Date: 2010-04-22 15:07:09 +0000 (do, 22 apr 2010) $ |
---|
14 | */ |
---|
15 | package dbnp.studycapturing |
---|
16 | import dbnp.data.* |
---|
17 | import dbnp.studycapturing.* |
---|
18 | |
---|
19 | class TemplateEditorController { |
---|
20 | /** |
---|
21 | * index closure |
---|
22 | */ |
---|
23 | def index = { |
---|
24 | // got a entity get parameter? |
---|
25 | def entity = null |
---|
26 | if (params.entity) { |
---|
27 | // decode entity get parameter |
---|
28 | entity = new String(params.entity.toString().decodeBase64()) |
---|
29 | } |
---|
30 | |
---|
31 | // got with the flow! |
---|
32 | redirect(action: 'pages', params:["entity":entity]) |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * Webflow |
---|
37 | */ |
---|
38 | def pagesFlow = { |
---|
39 | // start the flow |
---|
40 | start { |
---|
41 | action { |
---|
42 | // define initial flow variables |
---|
43 | flow.entity = null |
---|
44 | flow.templates = [] |
---|
45 | |
---|
46 | // define success variable |
---|
47 | def errors = true |
---|
48 | |
---|
49 | // got an entity parameter? |
---|
50 | if (params.entity && params.entity instanceof String) { |
---|
51 | // yes, try to dynamicall load the entity |
---|
52 | try { |
---|
53 | // dynamically load the entity |
---|
54 | def entity = Class.forName(params.entity, true, this.getClass().getClassLoader()) |
---|
55 | |
---|
56 | // succes, is entity an instance of TemplateEntity? |
---|
57 | if (entity.superclass =~ /TemplateEntity$/) { |
---|
58 | errors = false |
---|
59 | |
---|
60 | // yes, assign entity to the flow |
---|
61 | flow.entity = entity |
---|
62 | |
---|
63 | // fetch all templates to this entity |
---|
64 | flow.templates = Template.findAllByEntity(entity) |
---|
65 | } |
---|
66 | } catch (Exception e) { } |
---|
67 | } |
---|
68 | |
---|
69 | // success? |
---|
70 | if (errors) { |
---|
71 | error() |
---|
72 | } else { |
---|
73 | success() |
---|
74 | } |
---|
75 | } |
---|
76 | on("success").to "templates" |
---|
77 | on("error").to "errorInvalidEntity" |
---|
78 | } |
---|
79 | |
---|
80 | // error dynamically loading entity |
---|
81 | errorInvalidEntity { |
---|
82 | render(view: "_errorInvalidEntity") |
---|
83 | } |
---|
84 | |
---|
85 | // main template editor page |
---|
86 | templates { |
---|
87 | render(view: "/templateEditor/templates") |
---|
88 | onRender { |
---|
89 | println "render templates" |
---|
90 | } |
---|
91 | on("next").to "start" |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|