legal.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. init: function(component, _) {
  17. if (this.isReady) {
  18. _.setTitle(this.title);
  19. } else {
  20. _.setTitle();
  21. return _.api.one('legal-pages', dashedTypeName);
  22. }
  23. },
  24. ondata: function(data, component, _) {
  25. m.startComputation();
  26. this.title = data.title || defaultTitle;
  27. this.body = data.body;
  28. this.isReady = true;
  29. m.endComputation();
  30. if (component.isActive) {
  31. _.setTitle(data.title);
  32. }
  33. }
  34. },
  35. view: function() {
  36. var _ = this.container;
  37. return m('.page.legal-page.' + dashedTypeName + '-page', [
  38. _.component(Misago.PageHeader, {title: this.vm.title}),
  39. m('.container',
  40. m.trust(this.vm.body)
  41. )
  42. ]);
  43. }
  44. });
  45. };
  46. Misago.TermsOfServiceRoute = legalPageFactory(
  47. 'terms_of_service', gettext('Terms of service'));
  48. Misago.PrivacyPolicyRoute = legalPageFactory(
  49. 'privacy_policy', gettext('Privacy policy'));
  50. }(Misago.prototype));