i18next version 1.7.2 cannot read property 'status' of null error - i18next

I had a difficulty in using i18next to get i18n'ed versions of strings.
I am having cannot read property 'status' of null error on line 1381 of i18next-1.7.2.js
my json files are located in locales/translation-en.json,... etc.
My init code is like below:
i18n.init({ lng:"en" , resGetPath: "locales/__ns__-__lng__.json", ns:"translation"},
function(t) {
text.nodeValue = i18n.t("app.name");
....
});
Cannot read property 'length' of null (javascript) didn't apply for my case.

When I inspected the source code of i18next-1.7.2 line:1382
It seems that there is a missing null check in the code.
error is null and error.status is being checked.
So I added a simple null check.
Here is the change in the code:
Old code (from original i18next-1.7.2.js) :
if (error.status == 200) {
// file loaded but invalid json, stop waste time !
f.log('There is a typo in: ' + url);
} else if (error.status == 404) {
f.log('Does not exist: ' + url);
} else {
f.log(error.status + ' when loading ' + url);
}
done(error, {});
proposed code:
if (error == null){
done(error, {});
}else{
if (error.status == 200) {
// file loaded but invalid json, stop waste time !
f.log('There is a typo in: ' + url);
} else if (error.status == 404) {
f.log('Does not exist: ' + url);
} else {
f.log(error.status + ' when loading ' + url);
}
done(error, {});
}
When I changed the code like above, it didn't work.
When I included jquery.js file it worked.
Developer of i18next Jamuhl knows about the subject.

Related

setAsync returns success status but not inserting data in MAC installed outlook

here I am implementing an email tracking system using image insertion , and i used 'Office.context.mailbox.item.body.setAsync' office API , everywhere it is working but not in installed MAC outlook though it returns 'success' in asyncResult.status.Please help me out.
Also, as a reference you can try the below mentioned code snippet:
var htmlData = '<img src=\"https://www.w3schools.com/css/paris.jpg\">';
Office.context.mailbox.item.body.setAsync(
htmlData,
{coercionType: "html"},
function (asyncResult) {
if (asyncResult.status == "failed") {
console.log("Action failed with error: " + asyncResult.error.message);
}
else {
console.log("Successfully set body text");
}
}
);
/* ReadWriteItem or ReadWriteMailbox */
/* Set body content */
Office.context.mailbox.item.body.setAsync(
'<img src=\"https://www.w3schools.com/css/paris.jpg\">',
{coercionType: "html"},
function (asyncResult) {
if (asyncResult.status == "failed") {
console.log("Action failed with error: " + asyncResult.error.message);
} else {
console.log("Successfully set body text");
}
});
I used above code and it worked in 15.40

Google App Script custom error on .withFailureHandler

I would like to throw a custom error in a function called with google.script.run from code.gs so I could display adequate information in a side bar. So far I've tested the following code with no luck:
code.gs
function UserException(type, text) {
this.type = type;
this.text = text;
//this.stack = (new Error()).stack;
}
UserException.prototype = Object.create(Error.prototype);
UserException.prototype.constructor = UserException;
function assignRangeToTechnician(technician)
{
if(technician!=null)
{
//some code
}else
throw new UserException("Error","Technician was not selected");
}
sidebar.html
...
<script>
function btnSelectTech()
{
google.script.run
.withSuccessHandler(rangeSelected)
.withFailureHandler(techniciansMessage)
.assignRangeToTechnician(document.getElementById('selectTechnician').value);
}
function techniciansMessage(Message)
{
var outputMessage = document.getElementById('message');
//here is where I log the Message value
google.script.run.myLog("In techniciansMessage() - Message: " + Message);
if (Message == null)
outputMessage.innerHTML = "<p style='color:red;'>Error occured</p>";
else
if (Message.type == "Error")
outputMessage.innerHTML = "<p style='color:red;'>" + Message.text + "</p>";
else if (Message.type == "Message")
outputMessage.innerHTML = "<p style='color:#f3f3f3;'>" + Message.text + "</p>";
}
</script>
...
When I run the code the .withFailureHandler is called but the Message doesn't hold the proper value. When I log that message I read "Error: " as a content of a 'Message' parameter.
Could you please help?
Thank you.
You may refer with this SO thread. Try adding an error parameter to your function. Example:
google.script.run.withFailureHandler(function (error) {
showError(error, 'getMe');
}).getMe();
Additional reference which might help: https://github.com/google/google-apps-script-samples/blob/master/translate/Sidebar.js.html

Worklight JavaScript HTTP adapter unable to receive request data

I am trying to understand how MFP JSONStore & HTTP adapters work. I downloaded the source code here. I followed the steps to build the app. I also deployed this adapter here. But when I tried to push the dirty data to the adapter, I got noting there. The adapter still logs undefined.
Here is the push function code:
function pushToAdapter(){
alert("pushToAdapter");
try {
WL.JSONStore.get(collectionName).push().then(function (res) {
if(Array.isArray(res) && res.length < 1){ // I changed this to res.length > 1
document.getElementById("resultsDiv").innerHTML = "Documents Pushed Successfuly";
} else {
document.getElementById("resultsDiv").innerHTML = "Failed To Push Documents to Adapter: "+ res[0].errorObject;
}
}).fail(function (errorObject) {
alert(errorObject.msg);
});
} catch (e) {
alert("Failed To Push Documents to Adapter");
}
}
& this is the adapter code:
function pushPeople(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: pushPeople called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function addPerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: addPerson called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function removePerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: removePerson called.');
MFP.Logger.debug('Got data from JSONStore to REMOVE: ' + JSON.stringify(data)); //always undefined
return;
}
Please note that I am using a patched version of cordova-plugin-mfp-jsonstore. It is the same as this version except for lines 5238 (as follows):
resourceRequest = new WLResourceRequest('adapters/' + invocationData.adapter + '/' + invocationData.procedure, WLResourceRequest.POST);
resourceRequest.setHeader('Content-Type','application/x-www-form-urlencoded'); //patched version
resourceRequest.send().then(ipOpts.onSuccess, ipOpts.onFailure);
Looks like the parameters were not being passed as a part of the push request. You can use the jsonstore.js provided here and verify if it solves your problem. This will be officially released in the next iFix.

Problems with download link in phonegap android pdf

Someone know how to download an file (pdf) using phonegap for android
I already looked a lot of tutorial but any of them work for me.
THank you.
You will need to make use of the FileTransfer object here: http://docs.phonegap.com/en/3.3.0/cordova_file_file.md.html#FileTransfer.
With this, you will need to call the download method - passing in the file URI, destination and success/error callbacks.
I.e., if I want to download a PDF, you could do so as follows:
var win = function(r) {
console.log("Should not be called.");
}
var fail = function(error) {
// error.code == FileTransferError.ABORT_ERR
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
var ft = new FileTransfer();
ft.download(
'http://www.mydomain.com/mypdfdoc.pdf',
myURI, // you can obtain this via a window.requestFileSystem(...)
function (fileEntry) {
// do something with fileEntry
},
function (error) {
// handle error appropriately
});

Browser loading php script after submitting form using jQuery Form plugin

I'm trying to implement a form using the jQuery Form plugin. The form has three text fields and a file input and I am validating the form in the beforeSend callback. The problem is, whether the validation passes or not, the php script that handles the file upload gets loaded in the browser, which, obviously is not what I want to happen - I need to stay on the form's page.
You can take a look at the form and it's dependent files at http://www.eventidewebdesign.com/public/testUpload/. Indexing is on for that directory, so you can take a look at all of the related files. The form itself is on testUpload.php.
I'd appreciate it if someone could take a look at my code and help me figure out what's going on here.
Please write the following script instead of your, this will work.
<script>
$(document).ready( function() {
// Initialize and populate the datepicker
$('#sermonDate').datepicker();
var currentDate = new Date();
$("#sermonDate").datepicker('setDate',currentDate);
$("#sermonDate").datepicker('option',{ dateFormat: 'mm/dd/yy' });
/*
* Upload
*/
// Reset validation and progress elements
var formValid = true,
percentVal = '0%';
$('#uploadedFile, #sermonTitle, #speakerName, #sermonDate').removeClass('error');
$('#status, #required').empty().removeClass();
$('.statusBar').width(percentVal)
$('.percent').html(percentVal);
$('#frmSermonUpload').ajaxForm({
beforeSend: function() {
if (!ValidateUploadForm()) {
formValid = false;
console.log('validateuploadform returned false');
} else {
console.log('validateuploadform returned true');
formValid = true;
}
console.log('in beforeSend. formValid: ' + formValid);
if (!formValid) {
$('#uploadedFile').val('');
return false;
}
},
uploadProgress: function(event, position, total, percentComplete) {
console.log('in uploadProgress function. formValid: ' + formValid);
if (formValid) {
var percentVal = percentComplete + '%';
$('.statusBar').width(percentVal)
$('.percent').html(percentVal);
}
},
complete: function(xhr) {
console.log('in complete function. formValid: ' + formValid);
if (formValid) {
console.log('xhr.responseText: ' + xhr.responseText);
console.log('formValid: ' + formValid);
if (xhr.responseText === 'success') {
$('.statusBar').width('100%');
$('.percent').html('100%');
$('#status').html('Successfully uploaded the sermon.').addClass('successUpload');
// Clear the form
ClearForm();
} else if (xhr.responseText === 'fail') {
$('#status').html('There was a problem uploading the file. Try again.<br>If the problem persists, contact your system administrator.').addClass('errorUpload');
}
}
}
}); // End Upload Status Bar
});
function ValidateUploadForm() {
// Reset errors and clear message
$('#uploadedFile, #sermonTitle, #speakerName, #sermonDate').removeClass('error');
$('#required').empty();
var result = true;
title = $('#sermonTitle').val(),
speaker = $('#speakerName').val(),
date = $('#sermonDate').val(),
fileName = $('#uploadedFile').val();
extension = $('#uploadedFile').val().split('.').pop().toLowerCase();
//if (fileName !== '' && extension !== 'mp3') {
if ((fileName === '') || (extension !== 'mp3')) {
$('#uploadedFile').addClass('error');
$('#required').html('Only mp3 files are allowed!');
return false;
} else if (fileName === '') {
result = false;
} else if (title === '') {
$('#sermonTitle').addClass('error');
result = false;
} else if (speaker === '') {
$('#speakerName').addClass('error');
result = false;
} else if (date === '') {
$('#sermonDate').addClass('error');
result = false;
}
console.log('returning ' + result + ' from the validateuploadform function');
if (!result) { $('#required').html('All fields are required.'); }
return result;
}
function ClearForm() {
$('#uploadedFile, #sermonTitle, #sermonDate, #speakerName').val('').removeClass();
}
</script>