legal.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. (function (Misago) {
  2. 'use strict';
  3. var legalPageFactory = function(typeName, defaultTitle) {
  4. var dashedTypeName = typeName.replace(/_/g, '-');
  5. return Misago.route({
  6. controller: function() {
  7. var _ = this.container;
  8. if (Misago.get(_.settings, typeName + '_link')) {
  9. window.location = Misago.get(_.settings, typeName + '_link');
  10. } else {
  11. this.vm.init(this, _);
  12. }
  13. },
  14. vm: {
  15. isReady: false,
  16. isBusy: false,
  17. init: function(component, _) {
  18. if (this.isReady) {
  19. _.setTitle(this.title);
  20. } else {
  21. _.setTitle();
  22. if (!this.isBusy) {
  23. this.isBusy = true;
  24. return _.api.one('legal-pages', dashedTypeName);
  25. }
  26. }
  27. },
  28. ondata: function(data, component, _) {
  29. m.startComputation();
  30. this.title = data.title || defaultTitle;
  31. this.body = data.body;
  32. this.isReady = true;
  33. m.endComputation();
  34. if (component.isActive) {
  35. _.setTitle(data.title);
  36. }
  37. }
  38. },
  39. view: function() {
  40. var _ = this.container;
  41. return m('.page.page-legal.page-legal-' + dashedTypeName, [
  42. _.component(Misago.PageHeader, {title: this.vm.title}),
  43. m('.container',
  44. m.trust(this.vm.body)
  45. )
  46. ]);
  47. }
  48. });
  49. };
  50. Misago.TermsOfServiceRoute = legalPageFactory(
  51. 'terms_of_service', gettext('Terms of service'));
  52. Misago.PrivacyPolicyRoute = legalPageFactory(
  53. 'privacy_policy', gettext('Privacy policy'));
  54. }(Misago.prototype));