1

По JS API (логин-страница)

Тема: По JS API (логин-страница)

Добрый день! Вот код страницы, которая реализуют вход
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv=Content-type>
  <title>You title</title>
  <!-- This is a helper class (use optional) -->
  <script type="text/javascript" src="js/base.js"></script>
  <!-- Include JS API (src=<you DNS for Wialon Hosting or Wialon Kit>) -->
  <script type="text/javascript" src="http://hosting.wialon.com/wsdk/script/wialon.js"></script>
  <script type="text/javascript">
    function init() {
      // main initialization JS API
      // use you DNS for Wialon Hosting or Wialon Kit
      wialon.core.Session.getInstance().initSession("http://hosting.wialon.com");
      // TODO: (login, ...)
    }
function apiLogin(login, passw, callback) {
  if (typeof login == "undefined" || login == "") {
    alert("Invalid login name.");
    return;
  } 
  if (typeof passw == "undefined")
    passw = "";
 
  // Perform login
  wialon.core.Session.getInstance().login(login, passw, "", function (code) {
    // Always check the return result - if it's not 0 there's an error
    if (code) {
      alert(wialon.core.Errors.getErrorText(code));
      return;
    }
    if (typeof callback != "undefined")
      callback(code);
  });
}

// Bind an event handler to the "Login" button
jQuery("#login_button_id").click(function() {
  // Get login and password
  var login = jQuery("#login_name_id").val();
  var passw = jQuery("#login_passw_id").val();
  // Authorize
  apiLogin(login, passw, apiLoginResult);
});
  </script>
</head>
<body onload="init();">
    <!-- TODO: you HTML code -->
</body>
</html>
Он не работает. Подскажите немного дальнейшие действия. Спасибо за поддержку.

2

По JS API (логин-страница)

Re: По JS API (логин-страница)

Мы вот так сделали вход с сайта на Wialon Hosting, может это конечно не то что Вам надо

css классы можете свои прописать
Демо вход настроен на юзер-пароль DEMO

<form action="http://web.avtoscaut.ru/login_action.html" method="post">
        <input type="hidden" name="action" value="login"/>
  <div class="input-prepend">
    <span class="add-on"><i class="icon-user"></i></span>
    <input class="span2" name="user" required type="text" placeholder="Логин">
  </div>
  <div class="input-prepend">
    <span class="add-on"><i class="icon-key"></i></span>
    <input class="span2" type="password" required name="passw" placeholder="Пароль">
</div>
<div class="btn-group">
<button type="submit" class="btn" >Войти</button>
<button class="btn" onclick="location.href='http://web.avtoscaut.ru/login_action.html?user=DEMO&passw=DEMO&action=login&skip_auto=1&lang=ru'">Демо-вход</button>
</div>
</form>

Avtonavix
Russia, Novosibirsk
avtonavix.ru
3

По JS API (логин-страница)

Re: По JS API (логин-страница)

Rampage
смотрите примеры sdk.wialon.com

Mobile Development
Gurtam
4

По JS API (логин-страница)

(10/10/2012 12:24:06 отредактировано unitedsecurity)

Re: По JS API (логин-страница)

Rampage
hello rampage i can show you our code. its works fine.




var  login = $("#login").val(); // from html input login
var  pwd = $("#pass").val(); // from html input password

        var mySession = wialon.core.Session.getInstance(); //Simple varible. 
        mySession.initSession("http://testing.wialon.com"); //Here you must insert your hosting where is your wialon service

        mySession.login(login, pwd,"",function(code){                     // "function (code) " code is responce about success or deined. if code is 0 all was OK if not code have his number with error defination [url=http://docs.gurtam.com/en/hosting/sdk/webapi/general/errors]Error list[/url]
        if(code){ 
        alert(wialon.core.Errors.getErrorText(code)); // this is function get error messages
        }else{
       //here you can insert code, it will work when login is success.  for example get session id...
         var sid = wialon.core.Session.getInstance().getId();
alert(sid);
                              }
        });

good luck...

UnitedSecurity

Великий и ужасный Гиоргий Каладзе
5

По JS API (логин-страница)

Re: По JS API (логин-страница)

unitedsecurity пишет:

Rampage
hello rampage i can show you our code. its works fine.




var  login = $("#login").val(); // from html input login
var  pwd = $("#pass").val(); // from html input password

        var mySession = wialon.core.Session.getInstance(); //Simple varible. 
        mySession.initSession("http://testing.wialon.com"); //Here you must insert your hosting where is your wialon service

        mySession.login(login, pwd,"",function(code){                     // "function (code) " code is responce about success or deined. if code is 0 all was OK if not code have his number with error defination [url=http://docs.gurtam.com/en/hosting/sdk/webapi/general/errors]Error list[/url]
        if(code){ 
        alert(wialon.core.Errors.getErrorText(code)); // this is function get error messages
        }else{
       //here you can insert code, it will work when login is success.  for example get session id...
         var sid = wialon.core.Session.getInstance().getId();
alert(sid);
                              }
        });

good luck...

UnitedSecurity

big thanks! Can you hepl me, please...Send me full code with input form(for example)? Early thanks!

6

По JS API (логин-страница)

(11/10/2012 10:19:13 отредактировано unitedsecurity)

Re: По JS API (логин-страница)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns+"http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test Wialon</title>
<script src='http://code.jquery.com/jquery-1.8.2.min.js' language='javascript'> </script> <!--This is Library For Jquery-->
<script src='http://hosting.wialon.com/wsdk/script/wialon.js' language='javascript'> </script> <!--This is Library For Wialon-->
</head>
<body>

Login Form <br />
<input type='text' id='login' /> <br />
<input type='password' id='pass' /> <br />
<input type='submit' id='click' onclick="wialon_login()" />

<script language='javascript'>

function wialon_login(){
var  login = $("#login").val(); // from html input login
var  pwd = $("#pass").val(); // from html input password

        var mySession = wialon.core.Session.getInstance(); //Simple varible. 
        mySession.initSession("http://testing.wialon.com"); //Here you must insert your hosting where is your wialon service
        mySession.login(login, pwd,"",function(code){                     // "function (code) " code is responce about success or deined. if code is 0 all was OK if not code have his number with error defination [url=http://docs.gurtam.com/en/hosting/sdk/webapi/general/errors]Error list[/url]
        if(code){ 
        alert(wialon.core.Errors.getErrorText(code)); // this is function get error messages
        }else{
       //here you can insert code, it will work when login is success.  for example get session id...
         var sid = wialon.core.Session.getInstance().getId();
document.write("you are loged in your session ID is: &nbsp;<span style='color:red'>"+sid+"</span>");
                              }
        });
        }
</script>


</body>
</html>

this is full code but it must be uploaded in server. if you will run this code with simple html from your computer that will not work. i hope you know what i mean. here is example on server for this code HTML EXAMPLE. good luck again

UnitedSecurity

Великий и ужасный Гиоргий Каладзе
7

По JS API (логин-страница)

Re: По JS API (логин-страница)

unitedsecurity пишет:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns+"http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test Wialon</title>
<script src='http://code.jquery.com/jquery-1.8.2.min.js' language='javascript'> </script> <!--This is Library For Jquery-->
<script src='http://hosting.wialon.com/wsdk/script/wialon.js' language='javascript'> </script> <!--This is Library For Wialon-->
</head>
<body>

Login Form <br />
<input type='text' id='login' /> <br />
<input type='password' id='pass' /> <br />
<input type='submit' id='click' onclick="wialon_login()" />

<script language='javascript'>

function wialon_login(){
var  login = $("#login").val(); // from html input login
var  pwd = $("#pass").val(); // from html input password

        var mySession = wialon.core.Session.getInstance(); //Simple varible. 
        mySession.initSession("http://testing.wialon.com"); //Here you must insert your hosting where is your wialon service
        mySession.login(login, pwd,"",function(code){                     // "function (code) " code is responce about success or deined. if code is 0 all was OK if not code have his number with error defination [url=http://docs.gurtam.com/en/hosting/sdk/webapi/general/errors]Error list[/url]
        if(code){ 
        alert(wialon.core.Errors.getErrorText(code)); // this is function get error messages
        }else{
       //here you can insert code, it will work when login is success.  for example get session id...
         var sid = wialon.core.Session.getInstance().getId();
document.write("you are loged in your session ID is: &nbsp;<span style='color:red'>"+sid+"</span>");
                              }
        });
        }
</script>


</body>
</html>

this is full code but it must be uploaded in server. if you will run this code with simple html from your computer that will not work. i hope you know what i mean. here is example on server for this code HTML EXAMPLE. good luck again

UnitedSecurity

thanks. it's wokred. Now. One question. How can including this code in the project?
var AccountUnits = Base.extend({
  constructor: null, 
  /// Hardware types
  hwTypes: [],
     
  /**
  * Main initialization
  */
  init: function () {
    // get hardware types
    wialon.core.Session.getInstance().getHwTypes(qx.lang.Function.bind(function(code, hwCol) {
      if (code != 0) {
        AccountUnits.logMsg("Couldn't get harware types: " + wialon.core.Errors.getErrorText(code), true);
        return;
      }
      for (var i = 0; hwCol && i < hwCol.length; i++) {
        var hw = hwCol[i];
        if (hw && qx.lang.Type.isObject(hw))
          this.hwTypes[hw.id] = hw.name;
      }
    }, this));

    // bind an event handler to accounts select
    jQuery("#accounts_id").change(this, function(e) {
      jQuery("#result_table_id").empty();     
      e.data.searchUnits(jQuery("#accounts_id").val(),jQuery("#accounts_id option:selected").html());
    }); 
   
    // get accounts
    this.getAccounts();
  },
 
  /**
  * Generate table row for unit and append to table
  * @param index {Integer} row index
  * @param unit {wialon.item.Unit} Unit object
  */
  addRow: function(index, unit) {
    if (!unit)
      return;
   
    var account_cell_id = "account_cell_" + unit.getId();
    var html = "<tr><td>" + (index+1) + "</td>" +
          "<td><img src='" + unit.getIconUrl(16) + "'/></td>" +
          "<td>" + unit.getName() + "</td>" +
          "<td id='" + account_cell_id + "'>-</td>" +
          "<td>" + this.hwTypes[unit.getDeviceTypeId()] + "</td>" +
          "<td>" + unit.getUniqueId() + "</td>" +
          "<td>" + unit.getPhoneNumber() + "</td>" +
          "<td>" + this.getCustomFields(unit) + "</td></tr>";
         
    jQuery("#result_table_id").append(html);

    this.getAccount(unit, account_cell_id);
  },

  /**
  * Get account for unit
  * @param unit {wialon.item.Unit} wialon unit object 
  * @param cellID {String} cell ID of the table to insert account name
  */ 
  getAccount: function(unit, cellID) {
   
    if (typeof unit == "undefined" || unit == null || cellID == "")
      return;

    var dataFlags = wialon.item.Item.dataFlag.base;
    wialon.core.Session.getInstance().searchItem(unit.getAccountId(), dataFlags, qx.lang.Function.bind(function(unit, cellID, code, item) {
      if (code != 0) {
        this.logMsg("Couldn't get account for " + unit.getName() + ": " + wialon.core.Errors.getErrorText(code), true);
        return;
      }
      if (item)
        jQuery("#"+cellID).html(item.getName());
    }, this, unit, cellID));
  },
 
  /**
  * Getter for custom fields
  * @param unit {wialon.item.Unit} wialon unit object 
  */ 
  getCustomFields: function(unit) {
    if (typeof unit != "undefined" && unit != null) {
      var customFields = unit.getCustomFields();
      var html = "";
      for (var i in customFields) {
        var field = customFields[i];
        if (html.length)
          html += ", ";
        html += field.n + ": " + field.v;
      }
      return html;       
    }
    return "-";
  },
 
  /**
  * Search units by account
  * @param accountId {Number} account ID
  * @param accountName {String} account name
  */ 
  searchUnits: function(accountId, accountName) {   
    // load library for working with custom fields
    wialon.core.Session.getInstance().loadLibrary("itemCustomFields");
    // load library for working with icons
    wialon.core.Session.getInstance().loadLibrary("itemIcon");
   
    var dataFlags = wialon.item.Item.dataFlag.base |
            wialon.item.Item.dataFlag.customProps |
            wialon.item.Item.dataFlag.billingProps |
            wialon.item.Item.dataFlag.customFields |
            wialon.item.Item.dataFlag.image |
            wialon.item.Unit.dataFlag.restricted;

    // we are looking for all units belonging to the account with 'accountId'
    var searchSpec = {
      itemsType: "avl_unit",           // type of search item
      propName: "sys_billing_account_guid",  // field of search item
      propValueMask: accountId,         // value mask for field
      sortType: "sys_name"
    };
   
    wialon.core.Session.getInstance().searchItems(searchSpec, false, dataFlags, 0, 0, qx.lang.Function.bind(function(accountName, code, data) {
      if (code != 0) {
        this.logMsg("Search error: " + wialon.core.Errors.getErrorText(code), true);
        return;
      }
      if (!data)
        return;
     
      this.logMsg(data.totalItemsCount + " units belong to account \"" + accountName + "\"");
      // Fill table
      for (var i = 0; i < data.items.length; i++)
        this.addRow(i, data.items[i]);         
    }, this, accountName)); 
  },
 
  /**
  * Get accounts and fill the select control
  */   
  getAccounts: function() { 
    // load library for working with accounts
    wialon.core.Session.getInstance().loadLibrary("resourceAccounts");
   
    // we are looking for all accounts
    var searchSpec = {
      itemsType: "avl_resource",  // type of search item
      propName: "sys_name",  // field of search item
      propValueMask: "*", // value mask for field
      sortType: "sys_name"
    };
    // flags for accessing information about account
    var dataFlags = wialon.item.Item.dataFlag.base|wialon.item.Item.dataFlag.billingProps;     
    wialon.core.Session.getInstance().searchItems(searchSpec, true, dataFlags, 0, 0, qx.lang.Function.bind(function(code, data) {
      if (code != 0) {
        this.logMsg("Cannot get account list: " + wialon.core.Errors.getErrorText(code), true);
        return;
      }
      var html = "<option value='*'>All accounts</option>";
      for (var i = 0; i < data.items.length; i++)
        // checking if the resource is account or not
        if (data.items[i].getAccountId() == data.items[i].getId())
          html += "<option value='" + data.items[i].getId() + "'>" + data.items[i].getName() +"</option>"; 
      jQuery("#accounts_id").append(html);
      // now trying to search units
      this.searchUnits(jQuery("#accounts_id").val(), jQuery("#accounts_id option:selected").html());
    }, this));
  },
 
  /**
  * Add log message
  * @param text {String} any text, format "YYYY-MM-DD HH:MM:SS: text"
  * @param isError {Boolean} is true - text red color; is false - text default color
  */
  logMsg: function(text, isError) {
    if (typeof text != "string" || text == "")
      return;   
    if (typeof isError != "undefined")
      text = "<b style='color:red;'>"+text+"</b>";   
    var date = new Date();
    $("#pois_log_id").prepend(wialon.util.DateTime.formatTime(date.getTime()/1000) + ": " + text + "<br>");
  }
});
this is information about units

8

По JS API (логин-страница)

Re: По JS API (логин-страница)

first you learn get units from SERVER with js API. that code wich you show me is so big and if you dont understand what are you doing it not good. i can show you full code for getting units from server...  i work for that ...  but i think you must learn with you how this happend.
i show you little example for getting units from server but not full code:

 function loadpage() {
     var flags = wialon.item.Item.dataFlag.base |      // name, ID,...
          wialon.item.Item.dataFlag.customProps |    // custom properties
          wialon.item.Item.dataFlag.customFields |  // custom fields
          wialon.item.Item.dataFlag.messages |    // get last msg on position msg
          wialon.item.Item.dataFlag.image |      // unit icon
          wialon.item.Unit.dataFlag.restricted |    // UID, HW, phone
          wialon.item.Unit.dataFlag.lastMessage |    // last message
          wialon.item.Unit.dataFlag.driverCode |    // driver code
          wialon.item.Unit.dataFlag.sensors |      // sensor info
          wialon.item.Unit.dataFlag.counters;      // counters info
          
          mySession.loadLibrary('itemCustomFields');
          mySession.loadLibrary('unitSensors');
          mySession.loadLibrary('itemIcon');
          
          var spec = {type:'type',data:'avl_unit',flags:flags,mode:0};
    wialon.core.Session.getInstance().updateDataFlags([spec], qx.lang.Function.bind(function(code) {
            if (code) {
        alert(wialon.core.Errors.getErrorText(code));
        return;
      }
      
      else{
    var units = wialon.core.Session.getInstance().getItems("avl_unit");      


    
      var html = "<table  id='units_result_id'><tr><td>#</td> <td></td> <td>Name</td> <td>Last Move</td> </tr>";
      for (var i = 0; i < units.length; i++){
      var uname = units[i].getName();
      var pos = units[i].getPosition();
      var tm = wialon.util.DateTime.formatTime(pos.t, false);
      var icon = units[i].getIconUrl(24);
      var unitid = units[i].getId();
      var icon= "<img src="+icon+" />";
      var c = i+1;
     html = html+"<tr><td>"+c+"</td> <td>"+icon+"</td>   <td><a onclick=\"showmap('"+unitid+"')\" id='unit_map_" + unitid + "'>"+uname+"</a></td> <td>"+tm+"</td></tr>";

      }
     
     
     
 $("#lunit").html(html); // your div id in html page example:(<div id='#lunit'> </div>)
  
 
     }
      })); 
          
          
    
        }

good luck bro smile

Великий и ужасный Гиоргий Каладзе