Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Editor updates

  • Loading branch information...
commit fb0dc7d5a7f9f2a1421f5f9cbddfbf877d01524e 1 parent 5a3ace7
@trsvax authored
View
65 src/main/java/com/trsvax/bootstrap/components/ContentEditable.java
@@ -1,26 +1,32 @@
package com.trsvax.bootstrap.components;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.tapestry5.Asset;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.AfterRender;
import org.apache.tapestry5.annotations.BeginRender;
-import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.Path;
import org.apache.tapestry5.annotations.SupportsInformalParameters;
import org.apache.tapestry5.dom.Element;
import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.javascript.JavaScriptSupport;
+
-@Import(
-library={
- "classpath:/com/trsvax/bootstrap/assets/components/ckeditor/ckeditor.js"
- }
-)
@SupportsInformalParameters
public class ContentEditable {
@Parameter
- private boolean enable;
+ private String content;
+
+ @Parameter
+ private String uploadURL;
+
+ @Parameter(required=true,defaultPrefix="literal")
+ private String role;
@Parameter(defaultPrefix="literal")
private String event;
@@ -31,16 +37,55 @@
@Inject
private ComponentResources resources;
+ @Inject
+ private JavaScriptSupport javaScriptSupport;
+
+ @Inject
+ private HttpServletRequest httpRequest;
+
+ @Inject
+ @Path("classpath:/com/trsvax/bootstrap/assets/components/ckeditor/ckeditor.js")
+ private Asset ckediter;
+
@BeginRender
- void beginRender(MarkupWriter writer) {
- Element div = writer.element("div");
+ Object beginRender(MarkupWriter writer) {
+ boolean enable = httpRequest.isUserInRole(role);;
+
+ String clientID = javaScriptSupport.allocateClientId(resources);
+
+ Element div = writer.element("div","id",clientID);
if ( enable ) {
Link link = resources.getContainerResources().createEventLink(event, context);
div.attribute("data-url",link.toAbsoluteURI());
div.attribute("contenteditable", "true");
}
- resources.renderInformalParameters(writer);
+ resources.renderInformalParameters(writer);
+
+ if ( enable && uploadURL != null ) {
+ javaScriptSupport.importJavaScriptLibrary(ckediter);
+ javaScriptSupport.addScript("CKEDITOR.inline( '%s', { " +
+ "filebrowserUploadUrl: '%s'," +
+ "filebrowserBrowseUrl: '/studio/browse/view', " +
+ //"coreStyles_bold : { element : 'span', attributes : {'class': 'Bold'} }," +
+ //"coreStyles_italic : { element : 'span', attributes : {'class': 'Italic'} },"+
+ "on: {" +
+ " instanceReady: function(ev) {" +
+ //" this.dataProcessor.writer.selfCloseingEnd = ' />';" +
+ " }" +
+ "}" +
+ "});", clientID, uploadURL);
+ }
+
+ if ( content != null && content.equals("hide") ) {
+ return false;
+ }
+ if ( content != null ) {
+ writer.writeRaw(content);
+ return false;
+ }
+
+ return true;
}
@AfterRender
View
17 src/main/java/com/trsvax/bootstrap/mixins/Pager.java
@@ -2,6 +2,7 @@
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Link;
@@ -14,6 +15,7 @@
import org.apache.tapestry5.services.PageRenderLinkSource;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.ValueEncoderSource;
+import org.slf4j.Logger;
import com.trsvax.bootstrap.environment.LoopEnvironment;
import com.trsvax.bootstrap.environment.LoopValues;
@@ -34,6 +36,12 @@
@Parameter
private Integer currentPage;
+ @Parameter
+ private Object[] context;
+
+ @Parameter(allowNull = false)
+ private Map<String, ?> parameters;
+
@Parameter(defaultPrefix="literal")
private Integer rowsPerPage;
@@ -99,6 +107,9 @@ Integer currentPage() {
return valueEncoderSource.getValueEncoder(Integer.class).toValue(request.getParameter(parameterName));
}
+ @Inject
+ private Logger logger;
+
PaginationValues values( final String event,final String parameterName) {
return new PaginationValues(environment.peek(PaginationEnvironment.class)) {
public Link getLink(Integer count) {
@@ -107,7 +118,13 @@ public Link getLink(Integer count) {
link = resources.getContainerResources().createEventLink(event,count);
} else {
link = pageRenderLinkSource.createPageRenderLink(resources.getPageName());
+ //link = resources.createPageLink(resources.getPageName(), resources.isBound("context"), context);
link.addParameter(parameterName,count.toString());
+ if ( resources.isBound("parameters")) {
+ for(Map.Entry<String,?> entry : parameters.entrySet()) {
+ link.addParameterValue(entry.getKey(), entry.getValue());
+ }
+ }
}
return link;
};
View
4 src/main/java/com/trsvax/bootstrap/services/bootstrapprovider/FormProvider.java
@@ -66,7 +66,6 @@ public boolean cleanupRender(FrameworkMixin mixin, MarkupWriter writer) {
if ( ! type.startsWith(formEnvironment.getPrefix())) {
return false;
}
-
final Set<Element> pop = new HashSet<Element>();
mixin.getRoot().visit( new BeanEditFormVisitor(mixin,type,pop));
for ( Element element : pop ) {
@@ -92,6 +91,7 @@ public void visit(Element element) {
Element buttonContainer;
if ( form(element)) {
+ logger.info("form {}",type);
element.addClassName(type);
return;
}
@@ -116,7 +116,7 @@ public void visit(Element element) {
String value = element.getAttribute("value") == null ? "" : element.getAttribute("value") ;
if ( type != null && type.equals("submit") && ! value.equals("Cancel") ) {
buttonContainer = element.getContainer();
- buttonContainer.forceAttributes("class","form-actions");
+ buttonContainer.forceAttributes("class","form-actions " + this.type);
element.addClassName("btn btn-primary");
} else if ( type != null && type.equals("hidden")) {
//ignore
View
2  src/main/resources/com/trsvax/bootstrap/assets/components/ckeditor/config.js
@@ -5,8 +5,6 @@
CKEDITOR.editorConfig = function( config ) {
config.extraPlugins = 'save';
- config.filebrowserUploadUrl = '/uploader/upload.php';
- config.filebrowserBrowseUrl = '/browser/browse.php';
// Define changes to default configuration here.

0 comments on commit fb0dc7d

Please sign in to comment.
Something went wrong with that request. Please try again.