BaseController.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. sap.ui.define([
  2. "sap/ui/core/mvc/Controller",
  3. "sap/ui/core/routing/History"
  4. ], function (Controller, History) {
  5. "use strict";
  6. return Controller.extend("sap.ui.demo.orderbrowser.controller.BaseController", {
  7. /**
  8. * Convenience method for accessing the router in every controller of the application.
  9. * @public
  10. * @returns {sap.ui.core.routing.Router} the router for this component
  11. */
  12. getRouter : function () {
  13. return this.getOwnerComponent().getRouter();
  14. },
  15. /**
  16. * Convenience method for getting the view model by name in every controller of the application.
  17. * @public
  18. * @param {string} sName the model name
  19. * @returns {sap.ui.model.Model} the model instance
  20. */
  21. getModel : function (sName) {
  22. return this.getView().getModel(sName);
  23. },
  24. /**
  25. * Convenience method for setting the view model in every controller of the application.
  26. * @public
  27. * @param {sap.ui.model.Model} oModel the model instance
  28. * @param {string} sName the model name
  29. * @returns {sap.ui.core.mvc.View} the view instance
  30. */
  31. setModel : function (oModel, sName) {
  32. return this.getView().setModel(oModel, sName);
  33. },
  34. /**
  35. * Convenience method for getting the resource bundle.
  36. * @public
  37. * @returns {sap.ui.model.resource.ResourceModel} the resourceModel of the component
  38. */
  39. getResourceBundle : function () {
  40. return this.getOwnerComponent().getModel("i18n").getResourceBundle();
  41. },
  42. /**
  43. * Event handler for navigating back.
  44. * It there is a history entry we go one step back in the browser history
  45. * If not, it will replace the current entry of the browser history with the master route.
  46. * @public
  47. */
  48. onNavBack : function() {
  49. var sPreviousHash = History.getInstance().getPreviousHash();
  50. if (sPreviousHash !== undefined) {
  51. history.go(-1);
  52. } else {
  53. this.getRouter().navTo("master", {}, true);
  54. }
  55. }
  56. });
  57. });