2016-03-18 21:26:17 -07:00
|
|
|
|
define(['jQuery'], function ($) {
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
|
|
|
|
function deleteDevice(page, id) {
|
|
|
|
|
|
|
|
|
|
var msg = Globalize.translate('DeleteDeviceConfirmation');
|
|
|
|
|
|
2016-02-22 11:49:19 -07:00
|
|
|
|
require(['confirm'], function (confirm) {
|
|
|
|
|
|
|
|
|
|
confirm(msg, Globalize.translate('HeaderDeleteDevice')).then(function () {
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
ApiClient.ajax({
|
|
|
|
|
type: "DELETE",
|
|
|
|
|
url: ApiClient.getUrl('Devices', {
|
|
|
|
|
Id: id
|
|
|
|
|
})
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}).then(function () {
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
|
|
|
|
loadData(page);
|
|
|
|
|
});
|
2016-02-22 11:49:19 -07:00
|
|
|
|
});
|
|
|
|
|
|
2014-10-11 13:38:13 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function load(page, devices) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2015-10-16 15:21:03 -07:00
|
|
|
|
if (devices.length) {
|
|
|
|
|
html += '<div class="paperList">';
|
|
|
|
|
}
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
|
|
|
|
html += devices.map(function (d) {
|
|
|
|
|
|
|
|
|
|
var deviceHtml = '';
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '<paper-icon-item>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
2015-10-26 11:55:46 -07:00
|
|
|
|
deviceHtml += '<paper-fab mini style="background:#999;" icon="tablet-android" item-icon></paper-fab>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '<paper-item-body three-line>';
|
|
|
|
|
deviceHtml += '<a class="clearLink" href="device.html?id=' + d.Id + '">';
|
|
|
|
|
|
|
|
|
|
deviceHtml += '<div>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
deviceHtml += d.Name;
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '</div>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
2014-10-11 18:46:02 -07:00
|
|
|
|
if (d.AppName) {
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '<div secondary>';
|
2014-10-11 18:46:02 -07:00
|
|
|
|
deviceHtml += d.AppName;
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '</div>';
|
2014-10-11 18:46:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-11 13:38:13 -07:00
|
|
|
|
if (d.LastUserName) {
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '<div secondary>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
deviceHtml += Globalize.translate('DeviceLastUsedByUserName', d.LastUserName);
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '</div>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deviceHtml += '</a>';
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '</paper-item-body>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '<paper-icon-button icon="delete" data-id="' + d.Id + '" title="' + Globalize.translate('ButtonDelete') + '" class="btnDeleteDevice"></paper-icon-button>';
|
|
|
|
|
deviceHtml += '</paper-icon-item>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
|
|
|
|
return deviceHtml;
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
2015-10-16 15:21:03 -07:00
|
|
|
|
if (devices.length) {
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
|
|
|
|
var elem = $('.devicesList', page).html(html).trigger('create');
|
|
|
|
|
|
|
|
|
|
$('.btnDeleteDevice', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
deleteDevice(page, this.getAttribute('data-id'));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadData(page) {
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Devices', {
|
|
|
|
|
|
2015-01-19 22:19:13 -07:00
|
|
|
|
SupportsPersistentIdentifier: true
|
2014-12-10 23:20:28 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
})).then(function (result) {
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
require(['paper-fab', 'paper-item-body', 'paper-icon-item'], function () {
|
|
|
|
|
load(page, result.Items);
|
|
|
|
|
});
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 10:08:10 -07:00
|
|
|
|
$(document).on('pageshow', "#devicesPage", function () {
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
loadData(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|