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.templating.editor.client.jsni;
35
36
37 import com.google.gwt.core.client.GWT;
38 import com.google.gwt.dom.client.Document;
39 import com.google.gwt.dom.client.Element;
40 import com.google.gwt.dom.client.MetaElement;
41 import com.google.gwt.dom.client.NodeList;
42 import com.google.gwt.http.client.UrlBuilder;
43 import com.google.gwt.i18n.client.Dictionary;
44 import com.google.gwt.user.client.Window;
45
46
47
48
49
50
51 public final class JavascriptUtils {
52
53 private static Dictionary dictionary;
54
55 static {
56
57 JavascriptUtils.exposeMgnlMessagesToGwtDictionary("info.magnolia.module.admininterface.messages");
58 dictionary = Dictionary.getDictionary("mgnlGwtMessages");
59 }
60
61 private JavascriptUtils() {
62
63 }
64
65 public static native void mgnlOpenDialog(String path, String collectionName, String nodeName, String paragraph, String workspace, String dialogPage, String width, String height, String locale)
66
67 ;
68
69 public static native void mgnlMoveNodeStart(String id)
70
71 ;
72
73 public static native void mgnlMoveNodeHigh(Object source)
74
75 ;
76
77 public static native void mgnlMoveNodeEnd(Object source, String path)
78
79 ;
80
81 public static native void mgnlMoveNodeReset(Object source)
82
83 ;
84
85 public static native void mgnlDeleteNode(String path)
86
87 ;
88
89
90
91
92 public static native void exposeMgnlMessagesToGwtDictionary(String basename)
93
94 ;
95
96 public static native void showTree(String workspace, String path)
97
98 ;
99
100 public static native String getContextPath()
101
102 ;
103
104 public static boolean isNotEmpty(final String string) {
105 return !isEmpty(string);
106 }
107
108 public static boolean isEmpty(final String string) {
109 return string == null || string.length() == 0;
110 }
111
112
113
114
115
116
117
118 public static String getI18nMessage(final String key) {
119 try {
120 return dictionary.get(key);
121 } catch(RuntimeException e) {
122 GWT.log("key ["+ key +"] was not found in dictionary", e);
123 return "???" + key + "???";
124 }
125 }
126
127
128
129
130
131 public static String detectCurrentLocale() {
132 String locale = "en";
133 final NodeList<Element> meta = Document.get().getDocumentElement().getElementsByTagName("meta");
134 for (int i = 0; i < meta.getLength(); i++) {
135 MetaElement metaTag = MetaElement.as(meta.getItem(i));
136 if ("gwt:property".equals(metaTag.getName()) && metaTag.getContent().contains("locale")) {
137 String[] split = metaTag.getContent().split("=");
138 locale = split.length == 2 ? split[1] : "en";
139 GWT.log("Detected Locale " + locale);
140 break;
141 }
142 }
143 return locale;
144 }
145
146 public static void moveComponent(String idTarget, String idSource, String path) {
147
148 String pathSource = path+"//"+idSource;
149 String pathTarget = path+"//"+idTarget;
150
151 UrlBuilder urlBuilder = Window.Location.createUrlBuilder();
152 urlBuilder.removeParameter("mgnlIntercept");
153 urlBuilder.removeParameter("mgnlPathSelected");
154 urlBuilder.removeParameter("mgnlPathSortAbove");
155
156 urlBuilder.setParameter("mgnlIntercept", "NODE_SORT");
157 urlBuilder.setParameter("mgnlPathSelected", pathSource);
158 urlBuilder.setParameter("mgnlPathSortAbove",pathTarget);
159
160 Window.Location.replace(urlBuilder.buildString());
161
162 }
163 }