AdvancedMetadataConfigurationPage.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 + '" />';
  22. html += '<label for="' + id + '">' + type + '</label>';
  23. }
  24. html += "</div>";
  25. $('#divItemTypes', page).html(html).trigger("create");
  26. },
  27. onSubmit: function () {
  28. Dashboard.showLoadingMsg();
  29. var form = this;
  30. ApiClient.getServerConfiguration().done(function (config) {
  31. config.InternetProviderExcludeTypes = $.map($('.chkItemType:checked', form), function (currentCheckbox) {
  32. return currentCheckbox.getAttribute('data-itemtype');
  33. });
  34. ApiClient.updateServerConfiguration(config).done(Dashboard.processServerConfigurationUpdateResult);
  35. });
  36. // Disable default form submission
  37. return false;
  38. }
  39. };
  40. $(document).on('pageshow', "#advancedMetadataConfigurationPage", AdvancedMetadataConfigurationPage.onPageShow);