AdvancedMetadataConfigurationPage.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var AdvancedMetadataConfigurationPage = {
  2. onPageShow: function () {
  3. Dashboard.showLoadingMsg();
  4. var page = this;
  5. var promise1 = ApiClient.getServerConfiguration();
  6. var promise2 = ApiClient.getItemTypes({ HasInternetProvider: true });
  7. $.when(promise1, promise2).done(function (response1, response2) {
  8. AdvancedMetadataConfigurationPage.load(page, response1[0], response2[0]);
  9. });
  10. },
  11. load: function (page, config, itemTypes) {
  12. AdvancedMetadataConfigurationPage.loadItemTypes(page, config, itemTypes);
  13. Dashboard.hideLoadingMsg();
  14. },
  15. loadItemTypes: function (page, configuration, types) {
  16. var html = '<div data-role="controlgroup">';
  17. for (var i = 0, length = types.length; i < length; i++) {
  18. var type = types[i];
  19. var id = "checkbox-" + i + "a";
  20. var checkedAttribute = configuration.InternetProviderExcludeTypes.indexOf(type) != -1 ? ' checked="checked"' : '';
  21. html += '<input' + checkedAttribute + ' class="chkItemType" data-itemtype="' + type + '" type="checkbox" name="' + id + '" id="' + id + '" onchange="AdvancedMetadataConfigurationPage.submit();" />';
  22. html += '<label for="' + id + '">' + type + '</label>';
  23. }
  24. html += "</div>";
  25. $('#divItemTypes', page).html(html).trigger("create");
  26. },
  27. submit: function () {
  28. $('.btnSubmit', $.mobile.activePage)[0].click();
  29. },
  30. onSubmit: function () {
  31. var form = this;
  32. ApiClient.getServerConfiguration().done(function (config) {
  33. config.InternetProviderExcludeTypes = $.map($('.chkItemType:checked', form), function (currentCheckbox) {
  34. return currentCheckbox.getAttribute('data-itemtype');
  35. });
  36. ApiClient.updateServerConfiguration(config);
  37. });
  38. // Disable default form submission
  39. return false;
  40. }
  41. };
  42. $(document).on('pageshow', "#advancedMetadataConfigurationPage", AdvancedMetadataConfigurationPage.onPageShow);