Skip to main content
1-Visitor
February 7, 2020
Question

Java script to select from locally saved PDFs

  • February 7, 2020
  • 1 reply
  • 2342 views

I want to select a file with the file widget similar to how the code below changes images:

$scope.view.wdg['part_img']['imgsrc'] = 'app/resources/Uploaded/1606XLB.png';

 

I think the script should look similar to this:
$scope.view.wdg['part_file']['fileurl'] = 'app/resources/Uploaded/1606-in006_-en-e.pdf';

 

Where 'fileurl' is used, what is the correct call out?

This needs be used completely offline. We want locally saved user manual PDFs to associate with clickable parts.

 

 

This is a script related to the file widget and source of the File URL.

1 reply

21-Topaz I
February 11, 2020

Hi @ForrestA ,

I did some  tests , where tried   to display  PDFs on mobile devices. 

I observered thre  a difference between the behavior in  preview mode and on mobile devices /tested on IOS IPad and on Android Samsung Galaxy S9+

2020-02-11_15-24-30.gif

2020-02-11_15-37-15.gif

 

Here in preview mode in the one test - studio  displays the  pdf directly on the studio panel but this is different on the mobile device (both ios and android) there all 3 tests  will display the pdf in external pdf applicaiton.

I used the following definiton /in Home.json / to see the relevant  properties  settings of the widgets:

 

 

Here the defintion of the Hyperlink and the file Widgets
....
 "name": "twx-col",
 "children": [
 {
 "name": "twx-container-content",
 "children": [
 {
 "attributes": {
 "twx-widget": "",
 "widget-id": "hyperlink-1",
 "widget-name": "hyperlink-1",
 "click-expression": "hyperlinkclick();",
 "text": "sample PDF link",
 "url": "https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf"
 },
 "name": "twx-hyperlink"
 }
 ]
 }
 ]
 },
 {
 "attributes": {
 "twx-widget": "",
 "widget-id": "column-4",
 "widget-name": "column-4",
 "is-widget-container": "true"
 },
 "name": "twx-col",
 "children": [
 {
 "name": "twx-container-content",
 "children": [
 {
 "attributes": {
 "twx-widget": "",
 "widget-id": "file-1",
 "widget-name": "file-1",
 "click-expression": "filelinkclick();",
 "text": "fileURL",
 "url": "Uploaded/[BD-Logbuch]20190208-20190310.pdf"
 },
 "name": "twx-file"
 }
....
and here the definiton of the toggle
....
 {
 "name": "twx-container-content",
 "children": [
 {
 "attributes": {
 "twx-widget": "",
 "widget-id": "toggle-1",
 "widget-name": "toggle-1",
 "click-expression": "toggleLink();",
 "label": "Show PDF"
 },
 "name": "twx-toggle"
 }

 

And the code was something like this:

 

//////////////////////////////////////////////////////////////////
 $scope.toggleLink = function() {
 
 if ( $scope.view.wdg['toggle-1']['value']==true) {

 $scope.clickLink1();
 $scope.clickFile1();
 window.location=$scope.view.wdg['file-1']['url']
 }
 
 }

///////
$scope.hyperlinkclick = function() {console.log("INFO -> Hyperlink click was called")}
$scope.filelinkclick = function() {console.log("INFO -> File click was called")}

$scope.clickLink =function () { 
 console.log("click----Link ---> start"); return;
 
 twx.app.fn.triggerStudioEvent(document.querySelector('[widget-id="hyperlink-1"]'), 'app.view["Home"].wdg["hyperlink-1"].svc.click');
 twx.app.fn.triggerStudioEvent(document.querySelector('[widget-id="file-1"]'), 'app.view["Home"].wdg["file-1"].svc.click');
 console.log("click----Link ---> finish"); 
}
$scope.clickLink1= function(){twx.app.fn.triggerStudioEvent(document.querySelector('[widget-id="hyperlink-1"]'), 'click');};
$scope.clickFile1= function(){twx.app.fn.triggerStudioEvent(document.querySelector('[widget-id="file-1"]'), 'click');};

//////////////
 $scope.toggleButton = function() {
 
 if ( $scope.view.wdg['toggleButton-1']['pressed']==true) {
 
 window.location='app/resources/Uploaded/%5BBD-Logbuch%5D20190208-20190310.pdf'
 console.log($scope.view.wdg['file-1']['url'])
 }
 $timeout(function () { $scope.view.wdg['toggleButton-1']['pressed']=false;}, 1500); 
 }
//////////////////

 

I attached also the studio project where I tested it

 

 

ForrestA1-VisitorAuthor
1-Visitor
February 11, 2020

This is amazing and very impressive, but I need it to work when the device is in airplane mode. A Network connection will slow processing down too much.

 

After testing without a network, the widgets return blank web pages or are unresponsive. 

21-Topaz I
March 4, 2020

Hi @ForrestA ,

I am wondering a little about your comment - that the demo project will cause a problem in offline mode

In the demo project I attached to my previous post all URL's are local referring to the resources/Uploaded folder. This means that the project is loaded only one time. In generally every project should have a problem in airplane mode if it should be loaded from Experience Service. For this your need internet access to the server.

But if you setup your project as enabled offline mode, in this case when you load the project one time to the device this should generally work also in offline /airplane mode.

 

2020-03-04_16-42-50.jpg

 

I tested the project test_pdf from previous post  - where I downloaded it to the device / this time I tested on Android Galaxy S9+ with activated airplane mode. It was working fine , no difference to normal connection because here all links are pointing to the local upload folder that these file are downloaded for offline work when the complete project was downloaded.

In this case I started the project from View , project-> download tab