1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <meta charset="utf-8" />
5
    <title>Wialon Playground - Resources and accounts</title>
6
    <script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"></script>
7
    <script type="text/javascript" src="//hst-api.wialon.host/wsdk/script/wialon.js"></script>
8
</head>
9
<body>
10
11
Select resource: <select id="res"><option></option></select>
12
<div id="log"></div>
13
14
</body>
15
</html>
HTML
1
 
1
#log { border: 1px solid #c6c6c6; }
CSS
47
 
1
// Print message to log
2
function msg(text) { $("#log").prepend(text + "<br/>"); };
3
4
function init() { // Execute after login succeed
5
    var sess = wialon.core.Session.getInstance(); // get instance of current Session
6
    // flags to specify what kind of data should be returned
7
    var flags = wialon.item.Item.dataFlag.base | wialon.item.Item.dataFlag.billingProps;
8
    sess.loadLibrary("resourceAccounts"); // load Accounts Library
9
    sess.updateDataFlags( // load items to current session
10
        [{type: "type", data: "avl_resource", flags: flags, mode: 0}], // Items specification
11
        function (code) { // updateDataFlags callback
12
            if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } // exit if error code
13
            var res = sess.getItems("avl_resource"); // get loaded 'avl_resource' items
14
            if (!res || !res.length){ msg("No resources found"); return; } // check if resources found
15
            for (var i=0; i<res.length; i++) // construct Select list using found resources
16
                $("#res").append("<option value='"+ res[i].getId() +"'>"+ res[i].getName() +"</option>");
17
            // bind action to select change
JS
Result
Source code of example Close ✕
1
 
1
/*source*/