AdvancedMetadataConfigurationPage.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. Dashboard.showLoadingMsg();
  32. var form = this;
  33. ApiClient.getServerConfiguration().done(function (config) {
  34. config.InternetProviderExcludeTypes = $.map($('.chkItemType:checked', form), function (currentCheckbox) {
  35. return currentCheckbox.getAttribute('data-itemtype');
  36. });
  37. ApiClient.updateServerConfiguration(config);
  38. });
  39. // Disable default form submission
  40. return false;
  41. }
  42. };
  43. $(document).on('pageshow', "#advancedMetadataConfigurationPage", AdvancedMetadataConfigurationPage.onPageShow);