Component.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. sap.ui.define([
  2. "sap/ui/core/UIComponent",
  3. "sap/ui/Device",
  4. "./model/models",
  5. "./controller/ListSelector",
  6. "./controller/ErrorHandler"
  7. ], function (UIComponent, Device, models, ListSelector, ErrorHandler) {
  8. "use strict";
  9. return UIComponent.extend("sap.ui.demo.orderbrowser.Component", {
  10. metadata : {
  11. manifest : "json"
  12. },
  13. /**
  14. * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
  15. * In this method, the device models are set and the router is initialized.
  16. * @public
  17. * @override
  18. */
  19. init : function () {
  20. this.oListSelector = new ListSelector();
  21. this._oErrorHandler = new ErrorHandler(this);
  22. // set the device model
  23. this.setModel(models.createDeviceModel(), "device");
  24. // call the base component's init function and create the App view
  25. UIComponent.prototype.init.apply(this, arguments);
  26. // create the views based on the url/hash
  27. this.getRouter().initialize();
  28. },
  29. /**
  30. * The component is destroyed by UI5 automatically.
  31. * In this method, the ListSelector and ErrorHandler are destroyed.
  32. * @public
  33. * @override
  34. */
  35. destroy : function () {
  36. this.oListSelector.destroy();
  37. this._oErrorHandler.destroy();
  38. // call the base component's destroy function
  39. UIComponent.prototype.destroy.apply(this, arguments);
  40. },
  41. /**
  42. * This method can be called to determine whether the sapUiSizeCompact or sapUiSizeCozy
  43. * design mode class should be set, which influences the size appearance of some controls.
  44. * @public
  45. * @return {string} css class, either 'sapUiSizeCompact' or 'sapUiSizeCozy' - or an empty string if no css class should be set
  46. */
  47. getContentDensityClass : function() {
  48. if (this._sContentDensityClass === undefined) {
  49. // check whether FLP has already set the content density class; do nothing in this case
  50. if (document.body.classList.contains("sapUiSizeCozy") || document.body.classList.contains("sapUiSizeCompact")) {
  51. this._sContentDensityClass = "";
  52. } else if (!Device.support.touch) { // apply "compact" mode if touch is not supported
  53. this._sContentDensityClass = "sapUiSizeCompact";
  54. } else {
  55. // "cozy" in case of touch support; default for most sap.m controls, but needed for desktop-first controls like sap.ui.table.Table
  56. this._sContentDensityClass = "sapUiSizeCozy";
  57. }
  58. }
  59. return this._sContentDensityClass;
  60. }
  61. });
  62. });