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 package info.magnolia.cms.gui.inline;
35
36 import info.magnolia.cms.gui.control.Bar;
37 import info.magnolia.cms.gui.control.Button;
38 import info.magnolia.cms.i18n.I18nContentSupport;
39 import info.magnolia.cms.i18n.I18nContentSupportFactory;
40 import info.magnolia.cms.i18n.MessagesManager;
41 import info.magnolia.cms.security.Permission;
42 import info.magnolia.cms.core.AggregationState;
43 import info.magnolia.context.MgnlContext;
44 import org.apache.commons.lang.StringUtils;
45
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.jsp.JspWriter;
48 import java.io.IOException;
49 import java.io.Writer;
50
51
52
53
54
55
56 public class BarNew extends Bar {
57
58 private String paragraph;
59
60 private Button buttonNew = new Button();
61
62 private I18nContentSupport i18nSupport = I18nContentSupportFactory.getI18nSupport();
63
64
65
66
67 public BarNew(HttpServletRequest request) {
68 }
69
70 public BarNew() {
71
72 }
73
74
75
76
77 public void setDefaultButtons() {
78 this.setButtonNew();
79 }
80
81
82
83
84 public void placeDefaultButtons() {
85 if (this.getButtonNew() != null) {
86 this.getButtonsLeft().add(0, this.getButtonNew());
87 }
88 }
89
90 public Button getButtonNew() {
91 return this.buttonNew;
92 }
93
94 public void setButtonNew(Button b) {
95 this.buttonNew = b;
96 }
97
98 public void setButtonNew() {
99 this.setButtonNew(this.getPath(), this.getNodeCollectionName(StringUtils.EMPTY), this
100 .getNodeName(StringUtils.EMPTY), this.getParagraph());
101 }
102
103
104
105
106
107
108
109
110 public void setButtonNew(String path, String nodeCollectionName, String nodeName, String paragraph) {
111 Button b = new Button();
112 final String labelKey = StringUtils.isBlank(paragraph) ? "buttons.noparagraph" : "buttons.new";
113 b.setLabel(MessagesManager.getMessages().get(labelKey));
114 String repository = MgnlContext.getAggregationState().getRepository();
115
116 if (StringUtils.contains(paragraph, ',')) {
117 b.setOnclick(onClickForNewButton(path, nodeCollectionName, nodeName, paragraph, repository, "selectParagraph"));
118 } else if (StringUtils.isNotBlank(paragraph)) {
119
120 b.setOnclick(onClickForNewButton(path, nodeCollectionName, nodeName, paragraph, repository, "editParagraph"));
121 }
122 this.setButtonNew(b);
123 }
124
125 protected String onClickForNewButton(String path, String nodeCollectionName, String nodeName, String paragraph, String repository, String dialogName) {
126 return "mgnlOpenDialog('"
127 + path
128 + "','"
129 + nodeCollectionName
130 + "','"
131 + nodeName
132 + "','"
133 + paragraph
134 + "','"
135 + repository
136 + "','.magnolia/dialogs/" + dialogName + ".html'"
137 + ", null"
138 + ", null"
139 + (i18nSupport.isEnabled()? ", '" + i18nSupport.getLocale().toString() + "'":"")
140 +");";
141 }
142
143
144
145
146 public void drawHtml(JspWriter out) throws IOException {
147 drawHtml((Writer) out);
148 }
149
150
151
152
153 public void drawHtml(Writer out) throws IOException {
154 final AggregationState aggregationState = MgnlContext.getAggregationState();
155 boolean isGranted = aggregationState.getMainContent().isGranted(Permission.SET);
156 if (!aggregationState.isPreviewMode() && isGranted) {
157 this.setEvent("onmousedown", "mgnlMoveNodeEnd(this,'" + this.getPath() + "');");
158 this.setEvent("onmouseover", "mgnlMoveNodeHigh(this);");
159 this.setEvent("onmouseout", "mgnlMoveNodeReset(this);");
160 this.setId(this.getNodeCollectionName() + "__" + this.getNodeName());
161 println(out, this.getHtml());
162 }
163 }
164
165 public String getParagraph() {
166 return this.paragraph;
167 }
168
169 public void setParagraph(String paragraph) {
170 this.paragraph = paragraph;
171 }
172 }