(function ($, document, window) { var query = { StartIndex: 0, Limit: 100000 }; var currentResult; function reloadList(page) { Dashboard.showLoadingMsg(); ApiClient.getSmartMatchInfos(query).then(function (infos) { currentResult = infos; populateList(page, infos); Dashboard.hideLoadingMsg(); }, onApiFailure); } function populateList(page, result) { var infos = result.Items; if (infos.length > 0) { infos = infos.sort(function (a, b) { a = a.OrganizerType + " " + a.Name; b = b.OrganizerType + " " + b.Name; if (a == b) { return 0; } if (a < b) { return -1; } return 1; }); } var html = ""; var currentType; for (var i = 0, length = infos.length; i < length; i++) { var info = infos[i]; if (info.OrganizerType != currentType) { currentType = info.OrganizerType; if (html.length > 0) { html += ""; } html += "

" + currentType + "

"; html += '"; $('.divMatchInfos', page).html(html).trigger('create'); } function onApiFailure(e) { Dashboard.hideLoadingMsg(); Dashboard.alert({ title: Globalize.translate('AutoOrganizeError'), message: Globalize.translate('ErrorOrganizingFileWithErrorCode', e.getResponseHeader("X-Application-Error-Code")) }); } $(document).on('pageinit', "#libraryFileOrganizerSmartMatchPage", function () { var page = this; $('.divMatchInfos', page).on('click', '.btnDeleteMatchEntry', function () { var button = this; var id = button.getAttribute('data-id'); var options = { MatchString: button.getAttribute('data-matchstring') }; ApiClient.deleteSmartMatchEntry(id, options).then(function () { reloadList(page); }, onApiFailure); }); }).on('pageshow', "#libraryFileOrganizerSmartMatchPage", function () { var page = this; Dashboard.showLoadingMsg(); reloadList(page); }).on('pagebeforehide', "#libraryFileOrganizerSmartMatchPage", function () { var page = this; currentResult = null; }); })(jQuery, document, window);