Ewon TechForum
Providing technical solutions to technical requests


viewON : Populate a combo box with the /usr files lists
simon Offline
eWON Support
#1
Hi Guys,

Here is a little tutorial to be able to populate a viewON combobox with the list of files contains in an Ewon directory (/usr for example).

First, upload the file listFile.shtm in your /usr directory through FTP
.zip   listFiles.zip (Size: 370 bytes / Downloads: 2)
This file contains an "ExeSSI" with some BASIC script.  The BASIC script generates the list of files of the /usr in a json format.

Here is the code :

Code:
<%#ExeSSI,
PathToBrowse$ = "/usr/"
FileCount% =  FS "count", PathToBrowse$
FirstLine = 0
JsonOutput$ = '{"files":['
FOR i% = 0 TO FileCount% -1
 FileorDirPath$ = FS "ls", PathToBrowse$, i%
 IsFile% = FS "isFile", PathToBrowse$ + FileorDirPath$
 IF IsFile% = 1 THEN
IF FirstLine = 0 THEN
JsonOutput$ = JsonOutput$ + '"' + FileorDirPath$ + '"'
FirstLine = 1
ELSE
JsonOutput$ = JsonOutput$ + ',"' + FileorDirPath$ + '"'
ENDIF
 ENDIF
NEXT i%
JsonOutput$ = JsonOutput$ + "]}"
PRINT #0, JsonOutput$;
%>


Now, in viewON, create a "combo box" object.  Do not create any animation/action for it.
- Select your view background and create a new Action > Javascript section.
- Set an Interval of 1 ms (means the code will be called once only at the page loading)
- Paste this Javascript code:
Code:
getEwonFiles();
function getEwonFiles()
{
    jQuery.ajax ( { url:"../listFiles.shtm", dataType:"json", success:UpdateFiles, error:UpdateFilesError, timeout:10000 });
    }

function UpdateFiles(json)
{
   $("#UID_1560233833362").empty();
    for (i in json.files) {
       $("#UID_1560233833362").append('<option>'+ json.files[i]+'</option>');
    }
}

function UpdateFilesError(err)
{
    console.log(err);
}


.png   2.png (Size: 15,97 KB / Downloads: 18)

- Select your "combo box" object and copy the object UID from the menu "Graph. Properties > Id" (Get rid of the word "container". Only take "UID<number>".
.png   1.png (Size: 13,34 KB / Downloads: 15)
- Replace the UID in the above JavaScript code by yours in the function "UpdateFiles()" (Keep the "#" !!!)
- Click outside the code view (to loose the focus) and save the view.

Simon
Reply



Possibly Related Threads…
8 hours ago
Last Post: Baplu Sam
Today, 01:47 AM
Last Post: AngelaT
19-03-2020, 10:09 AM
Last Post: simon
  Viewon authentication Started by oliviersav
1 Replies - 194 Views
30-01-2020, 01:48 PM
Last Post: simon
  Viewon Started by insyncs
8 Replies - 1.077 Views
22-11-2019, 08:48 PM
Last Post: bryancit
13-11-2019, 03:44 PM
Last Post: Valentin59
  Viewon questions Started by insyncs
7 Replies - 741 Views
30-10-2019, 08:54 PM
Last Post: insyncs
30-10-2019, 10:50 AM
Last Post: LewisH304
11-10-2019, 03:46 PM
Last Post: simon
15-07-2019, 01:03 PM
Last Post: jswenker



Users browsing this thread:
1 Guest(s)



Theme © Ewon 2019 - Forum software by © MyBB - Cookie policy