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: <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