2016-08-05 12:34:10 -07:00
|
|
|
|
define(['jQuery', 'listViewStyle'], function ($) {
|
2016-10-22 22:11:46 -07:00
|
|
|
|
'use strict';
|
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 = '';
|
2016-08-05 12:34:10 -07:00
|
|
|
|
deviceHtml += '<div class="listItem">';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
2016-08-05 12:34:10 -07:00
|
|
|
|
deviceHtml += '<i class="listItemIcon md-icon" style="background:#999;">tablet_android</i>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
2016-08-05 12:34:10 -07:00
|
|
|
|
if (d.AppName && d.LastUserName) {
|
|
|
|
|
deviceHtml += '<div class="listItemBody three-line">';
|
|
|
|
|
} else {
|
|
|
|
|
deviceHtml += '<div class="listItemBody two-line">';
|
|
|
|
|
}
|
2015-08-20 20:21:27 -07:00
|
|
|
|
deviceHtml += '<a class="clearLink" href="device.html?id=' + d.Id + '">';
|
|
|
|
|
|
2016-08-05 12:34:10 -07:00
|
|
|
|
deviceHtml += '<div class="listItemBodyText">';
|
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) {
|
2016-08-05 12:34:10 -07:00
|
|
|
|
deviceHtml += '<div class="listItemBodyText 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) {
|
2016-08-05 12:34:10 -07:00
|
|
|
|
deviceHtml += '<div class="listItemBodyText 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>';
|
2016-08-05 12:34:10 -07:00
|
|
|
|
deviceHtml += '</div>';
|
2014-10-11 13:38:13 -07:00
|
|
|
|
|
2016-08-05 12:34:10 -07:00
|
|
|
|
deviceHtml += '<button type="button" is="paper-icon-button-light" class="btnDeleteDevice" data-id="' + d.Id + '" title="' + Globalize.translate('ButtonDelete') + '"><i class="md-icon">delete</i></button>';
|
2016-05-07 23:31:08 -07:00
|
|
|
|
|
2016-08-05 12:34:10 -07:00
|
|
|
|
deviceHtml += '</div>';
|
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
|
|
|
|
|
2016-08-05 12:34:10 -07:00
|
|
|
|
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
|
|
|
|
});
|