How can I reuse the file chooser of ckeditor grails plugin? - grails

I'm using the ckeditor plugin for grails (:ckeditor:3.6.2.2) and I'd like to reuse the File Chooser used to select images inside the rich text editor. I'd like to use it in a form for selecting images.
The plugin documentation makes me assume this is possible:
"If you just need the link to the file browser there is a fileBrowserLink tag:
Open file browser
If you want get back the path of the selected item in the file browser simply define a javascript function called ckeditorFileBrowserItemSelected in the page containing the opening link.
<script type="text/javascript" charset="utf-8">
function ckeditorFileBrowserItemSelected(path) {
// do whatever you want with path
alert(path);
}
</script>"
http://stefanogualdi.github.com/grails-ckeditor/docs/ref/Tags/fileBrowser.html
Unfortunately I'm not getting it to work. If I use the above approach to create a link, I'm getting an exception:
errors.GrailsExceptionResolver MissingMethodException occurred when processing request: [GET] /Admin/courseTemplate/create
No signature of method: Users_antonepple_NetBeansProjects_Eppleton_Relaunch_Admin_grails_app_views_courseTemplate_create_gsp.fileBrowserLink() is applicable for argument types: (java.util.LinkedHashMap) values: [[type:Image, userSpace:userone]].
I also tried using the fileBrowser Tag like this:
<ckeditor:fileBrowser type="Image" userSpace="userone">Open file browser</ckeditor:fileBrowser>
As a result the File Manager opens instead of the FileChooser I'm looking for. The File manager doesn't allow to select an image.
What am I doing wrong, and what can I do instead to reuse the File Chooser?

OK, I figured out how to do it. The documentation has a typo instead of this:
Open file browser
it should be:
Open file browser
An advanced grails user would probably have spotted this earlier :-). The second problem was, that there was no way to select an image in the file manager. But as soon as the FileManager is opened in a separate window it has an additional action in a files context menu allowing me to choose an image. So I just need to:
Open file browser
...or open fileBrowser in a dialog and this action becomes available...

Related

cannot load html text into div tag using jquery in Vaadin 7

Many thanks for your help and support in advance. Using vaadin 7 AbstractJavaScriptComponent, I am trying to load html snippet in place of div tag and the screen does not display anything. Could not figure it out the reason. Please help !
window.de_vaadin_ui_myapp_MyWidget = function() {
$(document).ready(function(){
$("#content").load("html/NewFile.html");
});
var element = this.getElement();
this.onStateChange = function() {
element.innerHTML ="<div id=\"content\"></div>";
};
};
the html file is located in the package de.vaadin.ui.myapp.MyWidget.html
There are multiple things that could go wrong here. It would help if you'd describe any relevant log messages or such.
I can see multiple different reasons for why this isn't working for you:
The connector logic is not run at all e.g. because of a typo in the #JavaScript annotation value or the name of the connector function (i.e. de_vaadin_ui_myapp_MyWidget). You can verify that it's actually loaded by adding e.g. console.log(this.getElement()) inside the top level function.
The HTML is requested from the wrong URL. Check the network inspector in the browser's developer tools to see which absolute URL is actually loaded and whether that returns the expected result or only e.g. a 404 response. If this is the problem, you could either move the HTML file to some other place or change the relative URL passed to load to something
The contents of the extended element is reset every time there is a state change event because innerHTML is reassigned. It might help to move the statement that assigns innerHTML outside of the onStateChange handler so that it would only be run once during initialization. This might also cause a situation where $("#content") is run before the div has even been created, causing it to not find the target element.

How to get form values in browser to watir webdriver

I have installed my application and it is running on following URL
http://localhost:3000
Above URL will the load form with some fields, Then I will the fill the data in the required field and then submit form. My div element will displayed at the bottom of the page. Picture will be displayed inside the iframe with in the div element.
User will the above URL and then submit form. After submitting the form, Picture should be downloaded into their local machine.
Right I am calling the following line after form submission, how can I get the existing page into the browser object and download screenshot?
browser = Watir::Browser.new
b.div(:id => "phone_shell").screenshot("/home/user/Documents/preview.png")
I found few problems in your code
screenshot method is not available for element object, it's available for browser object and also you need to call the method save to save the file in the destination folder. So write the following code, it would work.
Code to get the html of the page
b.html
Code to take the screenshot
b.screenshot.save("/home/user/Documents/preview.png")
Now this will save the image in the destination folder.

struts2. add path to url

I'm working with struts2.
An external app calls to my app with url
http://localhost:8080/present/jsp/mi.action?cod=02021
But because of my JSP file system, my action result is in
http://localhost:8080/present/jsp/ALTE/mi.action?cod=02021
(note the difference in ALTE).
The JSP has some lines as
<%# include file="../comuns/comunCssyJs.jsp"%>
The first ../ is to go out ALTE.
If I access with first link the page is loaded but no include files are found. However, with second link there is no problem.
Does someone know what can I do? I know I can change my JSP-s dir-s, but I'd prefer to "add automatically" the ALTE path to the url. is that possible?
Thanks in advance.
Jon
Use Struts2 <s:include> tag http://struts.apache.org/2.x/docs/include.html with <s:url> tag http://struts.apache.org/2.x/docs/url.html.

How to separate javascript libraries and calls in the Rails 3.1 asset pipeline

I'm trying to get the hang of the whole asset pipeline thing, and read the guide and several tutorials about them. But one thing that doesn't become quite clear is wether I should view my javascript asset files as a library or a place to put code that is actually run i.e. $(document).ready. Because by default all the javascript files are included, and it would be weird to have several $(document).ready's in there, not to mention that you don't want the $(document).ready function for every page to be run in the first place. What would be the way to go at this? Use my asset files as a library and put actual calls in my views (ugly)? Or is there a better way to do this?
I too ran into this issue. In a large project you can have somebody put code into document ready to, for example, add a click function to each li within a div with class container.
Now we could all argue that the above code would be too generic and of course may affect li tags in other parts of the application, but the bigger the project, the more likely it is that you will run into a conflict like this leading to unexpected behaviour.
I for one am uncomfortable with a whole bunch of document ready functions running for each and every page loaded. My solution is not necessarily the perfect one, but it's one that I have taken up and will share with you.
In the body tag of each page I add data elements signifying the controller and the action. I then have one document ready script that looks for a class named after the controller with the name Ready appended e.g. HomeReady. It will then call a method on this class (presuming it exists) named after the action. So in your asset coffee file you could write:
class #HomeReady
#index: ->
alert("Hello")
#show: ->
alert("Goodbye")
This allows control right down to the action level. When I came across your question I decided to package this solution into a gem as I have already used it in several projects. You can find it at: https://github.com/intrica/rails_document_ready
If you absolutely don't want a certain piece of initialization code to be run unless the current page is a specific controller/action, then you can try adding an empty element on the page with an id built from that info like "posts_index" using these two helpers:
"#{controller_name}_#{action_name}"
Then in your javascript you can wrap the code inside an if statement that checks for the existence of an element with the appropriate id.
edit: Here's an example of the js partial that I mentioned in the comments.
show.html.haml
= render 'map'
map.html.erb (I normally use haml but it's easier to write js in erb)
<script src='http://www.google.com/jsapi' type='text/javascript'></script>
<script type='text/javascript'>
...
</script>
It's probably not as clean as it could be and it doesn't get the benefits of being part of the asset pipeline but I don't mind because it's only something that gets included on a specific page.

ASP.NET MVC 2 parameters throws JS error

My application works fine when I have only one parameter.
e.g.
/Product/Index/2
/Report/Sales/08-2009
But it failes when I add one more part to the url. Let's say I want to add the end month-year parameter to the url routing. Mow it becomes:
/Report/Sales/05-2009/09-2009
I do get both parameters in my action method. I parse it and retrieve the data and pass the Model to the View. With this scenario it throws the client side JS error when I try to access any of the form elements. I get "object expected" error. The same view works fine using just first parameter. What could be the issues here?
I also loose the CSS styles when this error occurs.
Thanks
well, without seeing any code at all this is difficult to troubleshoot, but I'd say it's likely because you are referencing your javascript and css files using a relative path like:
../content/scripts/myjavascript.js
Adding the second url parameter has caused the browser to be unable to find the urls because you have added what looks like an extra level of depth to the url.
You should provide absolute urls to your scripts and css files. An easy way to do this is to use the "ResolveUrl" method like so:
<%= ResolveUrl("~/Content/Scripts/myjavascript.css") %>

Resources