timezone.js not working in zend framework 2 - javascript

I am trying timezone conversion in javascript but I keep getting this in my console while using timezone.js :
warning : Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
error: GET http://exodo/tz/asia 404 (Not Found)
error : Uncaught TypeError: Cannot read property '1' of null
timezoneJS.timezone.zoneFileBasePath = 'tz';
timezoneJS.timezone.defaultZoneFile = ['asia', 'backward', 'northamerica', 'southamerica'];
timezoneJS.timezone.init({ async: false });
var dt = new window.timezoneJS.Date(new Date());
console.debug(dt.toString());
dt.setTimezone('America/Los_Angeles');
alert(dt);
prompt answers will be much appreciated
Thank you

Clearly you see that GET http://exodo/tz/asia 404 (Not Found) is failing.
You'll need the Olson time zone files -- timezoneJS.Date uses the raw Olson data to calculate timezone offsets. The Olson region files are simple, structured text data, which download quickly and parse easily. (They also compress to a very small size.)You can download from here
Put your directory of Olson files somewhere under your Web server root, and point timezoneJS.timezone.zoneFileBasePath to it. Then call the init function. Your code will look something like this:
timezoneJS.timezone.zoneFileBasePath = '/tz';
For more details read How to setup?
timezoneJS.timezone.zoneFileBasePath = '/tz';
timezoneJS.timezone.defaultZoneFile = ['asia', 'backward', 'northamerica', 'southamerica'];
var successFn = function (){
var dt = new window.timezoneJS.Date(new Date());
console.debug(dt.toString());
dt.setTimezone('America/Los_Angeles');
alert(dt);
};
timezoneJS.timezone.init({ callback: successFn });

Related

Reference error: "Workbook" is not defined

I wanna use the next java script code:
function dumpVal(file) {
if (file !=null) {
var wb = new Workbook.create(file);
var sheet = wb.getSheet("Tabelle1");
for (myrow = 1; !isCellEmpty(sheet, myrow, 0); myrow++) {
dataset.setColumnValue("A",getNumericValue(sheet,myrow,0));
dataset.storeResultRow();
}
}
return;
}
but when I am compiling it I receive the next error message: ReferenceError: "Workbook" is not defined.
Can someone to tell me what am I doing wrong?
You recieve the error with the followig line of code:
var wb = new Workbook;
At the point where you create the workbook (new Workbook) you refer to a class called "Workbook". At this point your script dont have a class called Workbook it.
Solution:
You should check your scripts if the class is included and its naming.
Maybe the class is initialized later!
For debug purposes you can try to create the class a line before:
class Workbook{ }
If you recieve an error now because Workbook needs a method called "create", you know that the class is just missing.
I assume that you want to parse excel file from your web application, the library that you are using is for developing add-ins for excel not web application :
Excel JavaScript API programming overview
This article describes how to use the Excel JavaScript API to build add-ins for Excel 2016. It introduces key concepts that are fundamental to using the APIs, such as RequestContext, JavaScript proxy objects, sync(), Excel.run(), and load(). The code examples at the end of the article show you how to apply the concepts.
source :
https://dev.office.com/docs/add-ins/excel/excel-add-ins-javascript-programming-overview
If you want to parse Excel in your web application I suggest to use this library :
https://github.com/SheetJS/js-xlsx
I did not use it so I cant garanty it, but you can look for similar librarys.

Save webpage data to file locally: How can get data from a webpage into JSON file and be able to save that to local machine

I am working on a completely locally run web app which is to be run without any network connection. The idea is to distribute a pack to users (~40) who will use the app to basically fill in bunch of form fields and charts. As changes are made to the page an object with data in JSON format is filled in. I have the page working well now and I have a function to load an existing JSON file and populate any fields that are present in the file. The idea behind this is that someone can be "halfway" through filling out the fields in the app or someone can load up previous work.
My question here is; what is the best system available to get data from a webpage into JSON file and be able to save that to local machine so that it can be distributed (emailed, saved to SP, network drive, access db etc etc) at a later date? The scenario under which the app will be used is a strictly no network access area so this is why I need to be able save and access a file locally. I have a half-solution where I can open a separate tab which has the contents of the file but I really would prefer to have the downloading/saving prompting done for me as most users won't go further than seeing a page with gibberish on it.
the code I have to accomplish this much is:
//Download file
function SaveToDisk() {
var data = JSON.stringify(currentSession);
var fileURL = 'data:text/json;charset=utf8,' + encodeURIComponent(data);
var fileName = $('file-save').val();
console.log(fileURL);
// for non-IE
if (!window.ActiveXObject) {
var save = document.createElement('a');
save.href = fileURL;
save.target = '_blank';
save.download = fileName || 'unknown';
var event = document.createEvent('Event');
event.initEvent('click', true, true);
save.dispatchEvent(event);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
}
// for IE
else if ( !! window.ActiveXObject && document.execCommand) {
var _window = window.open(fileURL, '_blank');
_window.document.close();
_window.document.execCommand('SaveAs', true, fileName || fileURL)
_window.close();
}
}
currentSession object looks like:
//Global JSON variables
var currentSession = {
"sections":{
"header":{
"tool":"",
"subsystem":"",
"engineer":"",
"date":"",
"so":""
},
"whys":{
"why1":{
"error":"",
object:"",
norm:"",
},
why2:{
error:"",
object:"",
norm:"",
},
why3:{
error:"",
object:"",
norm:"",
},
why4:{
error:"",
object:"",
norm:"",
},
why5:{
error:"",
object:"",
norm:"",
}
},
probDescription:{
"F":{
"is":"",
"isnot":""
},
"O":{
"is":"",
"isnot":""
},
"T":{
"is":"",
"isnot":""
},
"L":{
"is":"",
"isnot":""
},
"P":"",
"W":"",
"Pos":"",
"S":""
},
possibleCauses :{
"data":""
},
notes: ""
}
};
UPDATE: Attempting this on windows machine (up to now been testing on mac) on IE9 gives the following error:
SCRIPT5007: Unable to get value of the property 'document': object is null or undefined
at the following line of the above code:
_window.document.close();
Checking up on the line before:
// for IE
else if ( !! window.ActiveXObject && document.execCommand) {
shows me that the if statement checks if activeXObject is present (only in IE???) and something else (div editable???) is true then it goes with the IE solution.
Then it creates a new window with the data url, (not sure what '_blank' is here) and attempts to save the file. So why is it erroring on the _window.document line? It does open a new window with the URL as:
data:application/octet-stream;{data}
Any help here also greatly appreciated(and needed)
All help and suggestions gladly welcomed as I am rather new to all this and still learning.
Thx in advance
To force the download/saving prompt you can change the MIME type to application/octet-stream. The MIME type won't be saved to disk, so you don't have to worry about that later on. The second line in the function should therefore read:
var fileURL = 'data:application/octetstream;charset=utf8,' + encodeURIComponent(data);
Of course there are good reasons that this local saving procedure can not be completely automated. Otherwise viruses could be easily distributed.
If you want to access the file later to distribute it via email, the local storage solutions in html5 do not really help.
Since I work mostly on IE9 and can guarantee that the users will use this I found this answer solved my issue:
https://stackoverflow.com/a/6106417/1770604
I have it implemented like so:
//Make file for attaching to mail
function makefile () {
var fso = new ActiveXObject("Scripting.FileSystemObject"),
FName = $('#file-save').val() + ".json",
data = JSON.stringify(currentSession),
thefile=fso.CreateTextFile("C:\\temp\\" + FName,true);
thefile.Write(data);
thefile.Close();
alert("File created and saved to C:/temp/directory");
}
I have searched as much as possible and to my limited knowledge there are only two solutions to this without using a separate server:
ActiveXObject in IE9 which allows the user to interact with the file system and write to a file in a specified dir - from what i've read this is not a very secure solution however this is my only real option.
Some form of local/portable web server which can be distributed and started without user needing to do anything - I haven't been able to find the answer to this question yet so will keep looking but consider the question answered for now as long as you use IE9.

MarkLogic JavaScript scheduled task

I try to schedule a script using the 'Scheduled Tasks' in ML8. The documentation explains this a bit but only for xQuery.
Now I have a JavaScript file I'd like to schedule.
The error in the log file:
2015-06-23 19:11:00.416 Notice: TaskServer: XDMP-NOEXECUTE: Document is not of executable mimetype. URI: /scheduled/cleanData.js
2015-06-23 19:11:00.416 Notice: TaskServer: in /scheduled/cleanData.js [1.0-ml]
My script:
/* Scheduled script to delete old data */
var now = new Date();
var yearBack = now.setDate(now.getDate() - 65);
var date = new Date(yearBack);
var b = cts.jsonPropertyRangeQuery("Dtm", "<", date);
var c = fn.subsequence(cts.uris("", [], b), 1, 10);
while (true) {
var uri = c.next();
if (uri.done == true){
break;
}
xdmp.log(uri.value, "info"); // log for testing
}
Try the *.sjs extension (Server-side JavaScript).
The *.js extension can be used for static JavaScript resources to return to the client instead of executed on the server.
Hoping that helps,
I believe that ehennum found the issue for you (the extension - which is what the mime-type error is complaining about.
However, on the same subject, not all items in ML work quite as you would expect for Serverside Javascript. For example, using sjs as a target of a trigger is (or recently) did not work. So for things like that, it is also possible to wrap the sjs call inside of xqy using xdmp-invoke.

Read local file in Phonegap

I'm trying to read a local file in Phonegap to load the language strings for the application and I can't make it work :(
The code is pretty straightforward:
var pathToLocalFile = "/home/user/android/assets/www/js/";
var langCache = new FileReader();
langCache.onload = function(data){
col = JSON.parse(data);
refreshAllStrings();
};
langCache.onerror = function(err){
debug.error(err);
};
langCache.readAsText(pathToLocalFile+currentLang+'.json');
This code doesn't work on the Ripple emulator and I replaced it with
var pathToLocalFile = "file:///android_asset/www/js/";
in case of android, with the same result:
Uncaught TypeError: Object #<Console> has no method 'warning' cordova-2.4.0.js:2616
initRead cordova-2.4.0.js:2616
FileReader.readAsText cordova-2.4.0.js:2660
loadLanguage
In the Ripple emulator, I started Chrome with google-chrome -–allow-file-access-from-files and the Android config and manifest has all the permissions for and the plugins set.
Of course I'm missing something, but any idea what this could be?
Regards.
If the file is under the www folder of your app you don't need to add '/home/..' or 'file:///'. You should just be able to load the contents using an "AJAX" fetch even though it is bundled in the app.
$.get('js/filename.ext');
The error you're seeing is actually a result of cordova-2.4.0.js calling a non-existent "warning" method. It should be console.warn. It is attempting to warn you that using a string for the readAsText method is now deprecated, and that you should use a File reference instead.
What should be happening is a console.warn of "Using a string argument with FileReader.readAs functions is deprecated."

Displaying .dcm files with XTK's X.volume()

According to the lesson 15 I pass .dcm file to the volume. I get no errors (e.g. no parsing errors I faced before) but nothing is displayed. What could be wrong with the .dcm files?
Here is a excerpt of the code I use:
function demo(file){
var _dicom = [file];
var r = new X.renderer3D();
r.init();
var v = new X.volume();
v.file = _dicom.map(function(v) {
return file;
});
r.add(v);
r.render();
r.onShowtime = function() {
v.volumeRendering = true;
};
};
I pass the full file path here. Well, I'm not sure it's a correct wording, but I'd lile to know, what dicom settings or parameters could cause such a behaviour, no errors and no diplayed data. Thanks in advance.
Did you try to drag the .dcm file into http://slicedrop.com and see the same effect? DICOM support currently only exists for uncompressed DICOM files and we didn't get Ultrasound too work yet. So on uncompressed MR data or CT data in DICOM it should work.

Categories

Resources