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.Button;
37 import info.magnolia.cms.i18n.I18nContentSupport;
38 import info.magnolia.cms.i18n.I18nContentSupportFactory;
39 import info.magnolia.cms.i18n.MessagesManager;
40 import info.magnolia.cms.security.Permission;
41 import info.magnolia.cms.core.AggregationState;
42 import info.magnolia.context.MgnlContext;
43 import org.apache.commons.lang.StringUtils;
44
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.jsp.JspWriter;
47 import java.io.IOException;
48 import java.io.Writer;
49
50
51
52
53
54
55 public class ButtonEdit extends Button {
56 private String label = "buttons.edit";
57 private String dialogPath;
58 private String dialog;
59
60 private I18nContentSupport i18nSupport = I18nContentSupportFactory.getI18nSupport();
61
62 public ButtonEdit() {
63 }
64
65
66
67
68 public ButtonEdit(HttpServletRequest request) {
69 }
70
71
72
73
74 public ButtonEdit(HttpServletRequest request, String path, String nodeCollectionName, String nodeName, String dialog) {
75 this(path, nodeCollectionName, nodeName, dialog);
76 }
77
78 public ButtonEdit(String path, String nodeCollectionName, String nodeName, String dialog) {
79 this.setPath(path);
80 this.setNodeCollectionName(nodeCollectionName);
81 this.setNodeName(nodeName);
82 this.setDialog(dialog);
83 }
84
85
86
87
88 public void setDefaultOnclick(HttpServletRequest request) {
89 setDefaultOnclick();
90 }
91
92 public void setDefaultOnclick() {
93 String nodeCollectionName = this.getNodeCollectionName();
94 if (nodeCollectionName == null) {
95 nodeCollectionName = StringUtils.EMPTY;
96 }
97 String nodeName = this.getNodeName();
98 if (nodeName == null) {
99 nodeName = StringUtils.EMPTY;
100 }
101
102 String repository = MgnlContext.getAggregationState().getRepository();
103 this.setOnclick("mgnlOpenDialog('"
104 + this.getPath()
105 + "','"
106 + nodeCollectionName
107 + "','"
108 + nodeName
109 + "','"
110 + this.getDialog()
111 + "','"
112 + repository
113 + "',"
114 + (dialogPath != null ? "'" + dialogPath + "'" : "null")
115 + ", null"
116 + ", null"
117 + (i18nSupport.isEnabled()? ", '" + i18nSupport.getLocale().toString() + "'":"")
118 +");");
119 }
120
121 public String getLabel() {
122 return MessagesManager.getWithDefault(label, label);
123 }
124
125 public void setLabel(String s) {
126 this.label = s;
127 }
128
129 public void setDialogPath(String dialogPath) {
130 this.dialogPath = dialogPath;
131 }
132
133 public void setDialog (String dialog) {
134 this.dialog = dialog;
135 }
136
137 public String getDialog () {
138 return this.dialog;
139 }
140
141
142
143
144 public void drawHtml(JspWriter out) throws IOException {
145 drawHtml((Writer)out);
146 }
147
148
149
150
151 public void drawHtml(Writer out) throws IOException {
152 if (this.getRequest() != null) {
153 final AggregationState aggregationState = MgnlContext.getAggregationState();
154 boolean isGranted = aggregationState.getMainContent().isGranted(Permission.SET);
155 if (!aggregationState.isPreviewMode() && isGranted) {
156 println(out, this.getHtml());
157 }
158 }
159 }
160 }