jellyfin-web/dashboard-ui/scripts/autoorganizesmart.js

147 lines
3.5 KiB
JavaScript
Raw Normal View History

(function ($, document, window) {
var query = {
StartIndex: 0,
Limit: 100000
};
var currentResult;
function reloadList(page) {
Dashboard.showLoadingMsg();
2016-02-04 19:01:03 -07:00
ApiClient.getSmartMatchInfos(query).then(function (infos) {
currentResult = infos;
populateList(page, infos);
Dashboard.hideLoadingMsg();
2016-02-04 19:01:03 -07:00
2016-02-09 10:13:38 -07:00
}, function () {
Dashboard.hideLoadingMsg();
});
}
function populateList(page, result) {
var infos = result.Items;
if (infos.length > 0) {
infos = infos.sort(function (a, b) {
2016-02-17 20:18:28 -07:00
a = a.OrganizerType + " " + (a.DisplayName || a.ItemName);
b = b.OrganizerType + " " + (b.DisplayName || b.ItemName);
if (a == b) {
return 0;
}
if (a < b) {
return -1;
}
return 1;
});
}
var html = "";
2016-02-12 23:39:23 -07:00
if (infos.length) {
html += '<div class="paperList">';
}
for (var i = 0, length = infos.length; i < length; i++) {
var info = infos[i];
2016-02-23 11:50:22 -07:00
html += '<paper-icon-item>';
html += '<paper-fab mini icon="folder" item-icon class="blue"></paper-fab>';
html += (info.DisplayName || info.ItemName);
html += '</paper-icon-item>';
2016-02-22 12:42:20 -07:00
var matchStringIndex = 0;
2016-02-22 12:42:20 -07:00
html += info.MatchStrings.map(function (m) {
2016-02-22 12:42:20 -07:00
var matchStringHtml = '';
matchStringHtml += '<paper-icon-item>';
2016-02-23 11:50:22 -07:00
matchStringHtml += '<paper-item-body>';
2016-02-22 12:42:20 -07:00
matchStringHtml += "<div secondary>" + m + "</div>";
2016-02-22 12:42:20 -07:00
matchStringHtml += '</paper-item-body>';
2016-02-22 12:42:20 -07:00
matchStringHtml += '<paper-icon-button icon="delete" class="btnDeleteMatchEntry" data-index="' + i + '" data-matchindex="' + matchStringIndex + '" title="' + Globalize.translate('ButtonDelete') + '"></paper-icon-button>';
2016-02-22 12:42:20 -07:00
matchStringHtml += '</paper-icon-item>';
matchStringIndex++;
return matchStringHtml;
}).join('');
}
2016-02-12 23:39:23 -07:00
if (infos.length) {
html += "</div>";
}
$('.divMatchInfos', page).html(html).trigger('create');
}
2016-02-04 19:01:03 -07:00
function onApiFailure(e) {
Dashboard.hideLoadingMsg();
Dashboard.alert({
2016-02-09 10:13:38 -07:00
message: Globalize.translate('DefaultErrorMessage')
2016-02-04 19:01:03 -07:00
});
}
$(document).on('pageinit', "#libraryFileOrganizerSmartMatchPage", function () {
var page = this;
$('.divMatchInfos', page).on('click', '.btnDeleteMatchEntry', function () {
var button = this;
2016-02-12 23:39:23 -07:00
var index = parseInt(button.getAttribute('data-index'));
2016-02-22 12:42:20 -07:00
var matchIndex = parseInt(button.getAttribute('data-matchindex'));
2016-02-12 23:39:23 -07:00
var info = currentResult.Items[index];
2016-02-22 12:42:20 -07:00
var entries = [
{
Name: info.ItemName,
Value: info.MatchStrings[matchIndex]
}];
2016-02-12 23:19:28 -07:00
ApiClient.deleteSmartMatchEntries(entries).then(function () {
reloadList(page);
2016-02-04 19:01:03 -07:00
}, onApiFailure);
});
2016-02-04 19:01:03 -07:00
}).on('pageshow', "#libraryFileOrganizerSmartMatchPage", function () {
var page = this;
Dashboard.showLoadingMsg();
reloadList(page);
}).on('pagebeforehide', "#libraryFileOrganizerSmartMatchPage", function () {
var page = this;
currentResult = null;
});
})(jQuery, document, window);