Fire Elfinder Error Dialog from Command - javascript

I am working on making my own command (view commands) for elFinder, and it works pretty good.
The only thing that I have a problem with is when I do my custom ajax call to the connector, the error doesn't popup. It is valid JSON error output.
I was thinking if it somehow was possible to fire the error dialog myself from the command file?
I'm trying to do this from inside the this.exec = function(data) { ... } function in my command.

Your error call should be like this within that function. this.fm.error() or fm.error() in this case is used to fire the error dialog.
this.exec = function(data) {
var fm = this.fm,
dfrd = $.Deferred()
.fail(function(error) {
fm.error(error);
})
return dfrd;
}

Related

PhantomJS onPrompt callback

I am trying to get the onPrompt callback working with PhantomJS.
Just for testing I have a basic angular application that prompts the user on initialization and displays that data on the page.
It works fine when I enter the information into the prompt manually, but it will not work when using the PhantomJS onPrompt callback.
Here's the angular app:
angular
.module('app')
.controller('test', TestController)
function TestController() {
var vm = this;
vm.$onInit = onInit;
vm.testData = '';
function onInit() {
vm.testData = prompt('Name?');
}
}
This is the code I running with PhantomJS
var page = require('webpage').create();
page.open('http://localhost:3000', function() {
console.log('test')
page.onPrompt = function(msg, defaultVal) {
console.log("MESSAGE", msg)
return "Dog";
};
page.render('test.pdf');
phantom.exit();
});
I would expect to get a console.log that says "MESSAGE" and the text from the prompt and also a screenshot of my page with "Dog" displayed.
I get a screenshot of a blank page and no console log.
I would ideally like to use this callback with node webshot as an option. webshot phantom callbacks
Thanks for the help.
There is a context in which interaction with the actual interaction with the page takes place - usually within the page.evaluate(..) function. The onPrompt callback will execute within that context and will not print to the console as you expect - I think you need to marshal the output back to the console by setting the onConsoleMessage callback first:
page.onConsoleMessage = function (msg) {
console.log(msg);
};
And then it should print to the console as you expect :)

Handling errors with jQuery $.getScript

I am using a function that automatically loads .js files for modules with jQuery .getScript() function. The problem is that if the loaded script has any errors in it I cannot find a way to display the error line from the file loaded. I found a way to display the error type and error message but not the error line.
jQuery.getScript(main.constants.BASEURL + main.modules[activeModule].path + 'js/functions.js')
.done(function() {
Module.init();
})
.fail(function(jqxhr, settings, exception) {
errorObj = {};
if (arguments[0].readyState == 0) {
errorObj.message = 'Failed to load script!';
//script failed to load
}
else {
errorObj.type = arguments[1];
errorObj.message = arguments[2]['message'];
errorObj.lineNo = ??; //This is what I need to find
//script loaded but failed to parse
}
console.log(errorObj);
});
If you dynamiclly add a new script tag to head you will see line numbers, use scripts element onload to init the module

Debugging a Windows store app - error messages always show the same line number

I've set up error logging on my windows store app, which reports the error message and the line number in the code.
I've been getting two error messages from the same line, line 301. The error messages are
The process cannot access the file because it is being used by another process.
Access is denied.
Based on the First error message I presume the error is with my autosave function, but without the line number I can't say where it's failing. Here's my autosave code
function autosave()
{
if ((localSettings.values["useAutoSave"] == null || localSettings.values["useAutoSave"] == "true")) {
editorContent = editor.textContent;
var text_length = editorContent.length;
if (editedSinceSave && text_length > 0) {
localSettings.values["lastContent"] = text_length;
setStatus("<span class='loader'></span>autosaving", 2000);
writeTempFile();
}
}
window.setTimeout(autosave, _autosave_timeout);
}
function writeTempFile()
{
try{
tempFolder.createFileAsync("tempFile.txt", Windows.Storage.CreationCollisionOption.replaceExisting)
.then(function (theFile) {
return Windows.Storage.FileIO.writeTextAsync(theFile, editor.textContent);
}).done(function () {
localSettings.values["lastPos"] = _lastStartPos;
});
}
catch (e) {
// statements to handle any exceptions
logError(e); // pass exception object to error handler
}
}
Even we I move all my functions around and recompile my code, the error is always at line 301. I suspect that the errorline I'm seeing is actually from whatever underlying js files are used to run my app, but I don't know where to access them. How the hell do I debug this?
Make sure there's not a capability that you have not declared. It doesn't look like your code is using anything special, but it's worth a try.

Suppress JavaScript error on page for specific condition

I am getting a javascript error "Invalid argument on Line: 2 Char: 141544 in sp.ui.rte.js" on a SharePoint development. This appears to be a known issue from google within the SharePoint js files - http://wss.boman.biz/Lists/Posts/Post.aspx?List=c0143750-7a4e-4df3-9dba-8a3651407969&ID=69
After analysing the impact I decided that rather than changing the js in the SharePoint 14 hive I want to suppress the error message for just this error. I was trying to do the following:
ClientScriptManager cs = Page.ClientScript;
//Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered("Alert"))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append("<script type=text/javascript> window.onerror = function (msg, url, num) {return true;} </");
cstext1.Append("script>");
cs.RegisterStartupScript(this.GetType(), "Alert", cstext1.ToString());
}
The problem is this will suppress all js errors on the page not just the sp.ui.rte.js ones. Is it possible to do a string search on the URL (http://SHAREPOINT/_layouts/sp.ui.rte.js?rev=uY%2BcHuH6ine5hasQwHX1cw%3D%3D - where the only consistent value between sites will be /_layouts/sp.ui.rte.js? ) to just search and suppress this exact error?
Thanks for any help!
Use try/catch block around code in JS. If message matches something you want to ignore, just do nothing. Propagate everything else.
Your original approach with .onerror would work too if you change it to analyze message and propagate everything not matching ignored string as well.
So far this has been the most successful fix I have found and currently using:
function fixRTEBug() {
// This Fix for parentElement bug in RTE should survive Service Packs and CU's
function SubstituteRTERangeParentElement() {
var originalRTERangeParentElement = RTE.Range.prototype.parentElement;
RTE.Range.prototype.parentElement = function () {
try {
originalRTERangeParentElement();
} catch (e) { }
}
}
SubstituteRTERangeParentElement();
}
ExecuteOrDelayUntilScriptLoaded(fixRTEBug, "sp.ui.rte.js");

Ajax Error Reporting With PrototypeJS

I am wondering if there is script or something out there that will report javascript/PrototypeJS errors that happen in Ajax calls. It can be time consuming to fill code with console.log and/or alerts. It would be great if there was something like a browser plugin that would do it.
Anybody have any tools or tips?
Firefox has Firebug.
Chrome has Developer Tools (already built in).
Internet Explorer has Developer Toolbar (already built in).
To catch the errors in script you can use Ajax.Responders,
Ajax.Responders.register({
onException: function(request, exception) {
if (window.console) console.log(exception);
}
});
You mean like, http errors? Some http errors are logged to firebug, like 404 or 500.
You can extend Ajax.Request and make it report any http response status you want without having to repeat code.
Ajax.MyRequest = Class.create(Ajax.Request, {
initialize: function($super, url, options) {
function debuggerHandler(response) {
if(console && console.error) {
console.error("ERROR: " + response.responseText);
}
}
var debuggers = ["onFailure"]; //add any custom http status code
options = Object.clone(options) || {};
var handler;
var old;
for(var d in debuggers) {
handler = debuggers[d];
if(options[d]) {
old = options[d];
handler = function(response) {
old(response);
debuggers[d](response);
}
}
options[d] = handler;
}
$super(url, options);
}
});
Then, instead of calling Ajax.Request, you call Ajax.MyRequest and every ajax call will go through the debugger handlers and through any handler that you want to treat the error individually. Like:
new Ajax.MyRequest("/thisresourcedoesnotexist");
Will throw a 404 and log to console.error.
new Ajax.MyRequest("/thisresourcedoesnotexist", {
on404: function() {
console.error("But I want to treat this one");
}
});
Will throw a 404, execute the custom handler and log to console.error.
There is a number of ways to improve this approach. This is just the general idea.

Categories

Resources