19 package org.turro.elephant.web;
22 import java.io.IOException;
23 import java.nio.file.Path;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.turro.string.Strings;
27 import org.turro.auth.Authentication;
28 import org.turro.collections.CollectionUtil;
29 import org.turro.command.Context;
30 import org.turro.diff.Diffs;
31 import org.turro.elephant.context.ElephantContext;
32 import org.turro.elephant.impl.util.FileUtil;
33 import org.turro.elephant.sitemap.SitemapGenerator;
34 import org.turro.elephant.util.Messages;
35 import org.turro.elephant.web.context.WebContext;
36 import org.turro.file.Folder;
37 import org.turro.file.zul.control.RepositoryControl;
38 import org.turro.wiki.parsing.StyledElement;
39 import org.turro.zkoss.dialog.InputDialog;
40 import org.turro.zkoss.dialog.InputField;
41 import org.turro.zkoss.dialog.Windows;
42 import org.turro.zkoss.text.WikiEditor;
43 import org.zkoss.zk.ui.Component;
44 import org.zkoss.zk.ui.HtmlBasedComponent;
45 import org.zkoss.zk.ui.event.Event;
46 import org.zkoss.zk.ui.select.SelectorComposer;
47 import org.zkoss.zk.ui.select.annotation.Listen;
48 import org.zkoss.zk.ui.select.annotation.Wire;
49 import org.zkoss.zk.ui.util.Clients;
50 import org.zkoss.zul.Button;
51 import org.zkoss.zul.Checkbox;
52 import org.zkoss.zul.Include;
53 import org.zkoss.zul.Textbox;
54 import org.zkoss.zul.Toolbarbutton;
64 @Wire(
"#contextTree")
private ContextTree contextTree;
66 @Wire(
"#contextId")
private Include contextId;
67 @Wire(
"#createChild")
private Toolbarbutton createChild;
68 @Wire(
"#removeContext")
private Toolbarbutton removeContext;
70 @Wire(
"#formDetail")
private Include formDetail;
71 @Wire(
"#saveDetail")
private Toolbarbutton saveDetail;
73 @Wire(
"#formPage")
private Include formPage;
74 @Wire(
"#savePage")
private Toolbarbutton savePage;
76 @Wire(
"#formElement")
private Include formElement;
77 @Wire(
"#addAttribute")
private Toolbarbutton addAttribute;
78 @Wire(
"#saveElement")
private Toolbarbutton saveElement;
83 @Wire(
"#removeVersion")
private Toolbarbutton removeVersion;
84 @Wire(
"#diffVersion")
private Toolbarbutton diffVersion;
85 @Wire(
"#autoremove")
private Checkbox autoremove;
86 @Wire(
"#saveContent")
private Button saveContent;
87 @Wire(
"#wikiEditor")
private WikiEditor wikiEditor;
89 @Wire(
"#formRepository")
private Include formRepository;
92 @Wire(
"#formSocial")
private Include formSocial;
94 @Listen(
"onSelect = #contextTree")
98 contextId.invalidate();
99 formDetail.invalidate();
100 formPage.invalidate();
101 formElement.invalidate();
102 formRepository.invalidate();
103 formSocial.invalidate();
104 saveDetail.setDisabled(
true);
105 savePage.setDisabled(
true);
106 saveElement.setDisabled(
true);
107 createChild.setDisabled(contextItem ==
null);
108 removeContext.setDisabled(contextItem ==
null);
109 addAttribute.setDisabled(contextItem ==
null);
113 @Listen(
"onClick = #saveDetail; onClick = #savePage; onClick = #saveElement")
120 @Listen(
"onClick = #createChild")
127 protected HtmlBasedComponent createEditor() {
128 Textbox tb =
new Textbox();
129 tb.setConstraint(
"/[a-z][a-z0-9\\-]+/: {Start with a lowercase letter, then lowercase letters, numbers or hypens}");
133 }, (Context context) -> {
135 if(fields.length > 0) {
137 if(
"Name".equals(f.getLabel())) {
138 createAndSelect((String) f.getValue());
146 @Listen(
"onClick = #removeContext")
151 Clients.showNotification(
"Cannot remove root");
162 @Listen(
"onClick = #addAttribute")
168 }, (Context context) -> {
170 if(fields.length > 0) {
172 if(
"Name".equals(f.getLabel())) {
173 createAttribute((String) f.getValue());
181 @Listen(
"onSelect = #base; onSelect = #blang")
186 @Listen(
"onSelect = #bversion")
192 removeVersion.setDisabled(
false);
193 diffVersion.setDisabled(
false);
195 }
catch (IOException ex) {
203 @Listen(
"onClick = #removeVersion")
212 @Listen(
"onClick = #diffVersion")
221 Windows.
showHtml(
"Diff", Diffs.diff(oldText, newText).efficiency().html());
222 }
catch (IOException ex) {
223 Logger.getLogger(
ContextComposer.class.getName()).log(Level.SEVERE,
null, ex);
227 @Listen(
"onClick = #saveContent")
231 autoremove.isChecked());
235 @Listen(
"onChange = *; onCheck = *; onSelect = *")
237 saveDetail.setDisabled(
false);
238 savePage.setDisabled(
false);
239 saveElement.setDisabled(
false);
247 saveDetail.setDisabled(
true);
248 saveDetail.setAutodisable(
"+self");
249 savePage.setDisabled(
true);
250 savePage.setAutodisable(
"+self");
251 saveElement.setDisabled(
true);
252 saveElement.setAutodisable(
"+self");
253 saveContent.setDisabled(
true);
254 saveContent.setAutodisable(
"+self");
255 createChild.setDisabled(
true);
256 removeContext.setDisabled(
true);
261 private void saveAttributes(
ElContext context) {
262 if(context !=
null) {
264 saveDetail.setDisabled(
true);
265 savePage.setDisabled(
true);
266 saveElement.setDisabled(
true);
272 comp.setAttribute(
"edit", editingContext);
273 super.doBeforeComposeChildren(comp);
278 private void updateContent() {
279 saveContent.setDisabled(
true);
290 private void updateVersion() {
291 removeVersion.setDisabled(
true);
292 diffVersion.setDisabled(
true);
298 private void createAndSelect(String child) {
299 if(Strings.isBlank(child)) {
300 Clients.showNotification(
"Write a valid lowercase context");
303 Path newChild = Path.of(editingContext.
getPath(), child);
304 if(WebContext.createFolders(newChild)) {
306 WebContext.saveTo(newChild, wc);
307 ElContextMap.reset();
312 Clients.showNotification(
"Context already exists");
316 private void createAttribute(String name) {
317 if(Strings.isBlank(name)) {
318 Clients.showNotification(
"Write a valid name");
322 formElement.invalidate();
static IContact getIContact()
static String getRootWebPath()
static String logMsg(String msg)
static String getContentWithLineBreaks(File file)
static void generateSitemap()
static Messages confirmDeletion()
Messages add(String word)
void onChange(Event event)
void onAddAttribute(Event event)
void onRemoveContext(Event event)
void onCreateChild(Event event)
void onBaseChange(Event event)
void onRemoveVersion(Event event)
void onSaveDetail(Event event)
void onSaveContent(Event event)
void onSelectContext(Event event)
void onVersionChange(Event event)
void onDiffVersion(Event event)
void doBeforeComposeChildren(Component comp)
void selectPath(String path)
void saveContent(IContact contact, String base, String lang, String wiki, String html, boolean autoremove)
void setContext(ElContext context)
boolean isEditable(String base, String lang)
void removeVersion(String base, String lang, String version)
WebContext getWebContext()
Set< String > getDefaultLocales()
void resetDefaultLocales()
String getRepositoryPath()
WebResources getResources()
static String relativeRepository()
static void saveTo(Path path, WebContext context)
Map< String, String > getAttributes()
Set< String > getBaseNames()
File getEditable(String base, String lang, String version)
Set< String > getVersions(String base, String lang)
void setPath(String path)
static void showHtml(String title, String html)
void setReadonly(boolean value)
void setImageFolder(String folder)
void setValue(String value)
void setNoTreeRepository(boolean noTreeRepository)
void setFileFolder(String folder)
void addResolver(IWikiResolver resolver)