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

177 lines
4.5 KiB
JavaScript
Raw Normal View History

define(['listViewStyle'], function () {
var query = {
StartIndex: 0,
Limit: 100000
};
var currentResult;
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
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-08-05 13:25:09 -07:00
html += '<div class="listItem">';
2016-02-23 11:50:22 -07:00
html += '<div class="listItemIconContainer">';
2016-08-05 13:25:09 -07:00
html += '<i class="listItemIcon md-icon">folder</i>';
html += '</div>';
2016-02-23 11:50:22 -07:00
html += '<div class="listItemBody">';
html += "<h2 class='listItemBodyText'>" + (info.DisplayName || info.ItemName) + "</h2>";
html += '</div>';
2016-02-23 11:50:22 -07:00
2016-08-05 13:25:09 -07:00
html += '</div>';
2016-02-23 11:50:22 -07:00
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 = '';
2016-08-05 13:25:09 -07:00
matchStringHtml += '<div class="listItem">';
matchStringHtml += '<div class="listItemBody" style="padding: .1em 1em .4em 5.5em; min-height: 1.5em;">';
2016-02-22 12:42:20 -07:00
2016-08-05 13:25:09 -07:00
matchStringHtml += "<div class='listItemBodyText secondary'>" + m + "</div>";
2016-08-05 13:25:09 -07:00
matchStringHtml += '</div>';
matchStringHtml += '<button type="button" is="emby-button" class="btnDeleteMatchEntry" style="padding: 0;" data-index="' + i + '" data-matchindex="' + matchStringIndex + '" title="' + Globalize.translate('ButtonDelete') + '"><i class="md-icon">delete</i></button>';
2016-08-05 13:25:09 -07:00
matchStringHtml += '</div>';
2016-02-22 12:42:20 -07:00
matchStringIndex++;
return matchStringHtml;
}).join('');
}
2016-02-12 23:39:23 -07:00
if (infos.length) {
html += "</div>";
}
var matchInfos = page.querySelector('.divMatchInfos');
matchInfos.innerHTML = html;
}
2016-04-12 22:28:45 -07:00
function getTabs() {
return [
{
href: 'autoorganizelog.html',
name: Globalize.translate('TabActivityLog')
},
{
href: 'autoorganizetv.html',
name: Globalize.translate('TabTV')
},
{
href: 'autoorganizesmart.html',
name: Globalize.translate('TabSmartMatches')
}];
}
return function (view, params) {
var self = this;
var divInfos = view.querySelector('.divMatchInfos');
divInfos.addEventListener('click', function (e) {
2016-02-12 23:39:23 -07:00
var button = parentWithClass(e.target, 'btnDeleteMatchEntry');
if (button) {
var index = parseInt(button.getAttribute('data-index'));
var matchIndex = parseInt(button.getAttribute('data-matchindex'));
var info = currentResult.Items[index];
var entries = [
{
Name: info.ItemName,
Value: info.MatchStrings[matchIndex]
}];
ApiClient.deleteSmartMatchEntries(entries).then(function () {
reloadList(view);
}, Dashboard.processErrorResponse);
}
});
2016-04-12 22:28:45 -07:00
view.addEventListener('viewshow', function (e) {
LibraryMenu.setTabs('autoorganize', 2, getTabs);
Dashboard.showLoadingMsg();
reloadList(view);
});
view.addEventListener('viewhide', function (e) {
currentResult = null;
});
};
});