You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

produkt.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Component from '@glimmer/component';
  2. import { action } from '@ember/object';
  3. import { tracked } from '@glimmer/tracking';
  4. import { inject as service } from '@ember/service';
  5. import ApplicationAdapter from '../adapters/application';
  6. export default class ProduktController extends Component {
  7. @tracked isLarge = false;
  8. @tracked isSelected;
  9. @service store;
  10. @action toggleSize()
  11. {
  12. this.isLarge = !this.isLarge;
  13. }
  14. @action toggleSelection(produktname)
  15. {
  16. this.isSelected = !this.isSelected;
  17. this.setStatus(produktname, this.isSelected);
  18. }
  19. @action getStatus(produktname)
  20. {
  21. //sucht Produkt im Store
  22. this.store.findAll('produkt')
  23. .then(function(suchergebnis)
  24. {
  25. suchergebnis.forEach(element => {
  26. if(element.titel==produktname)
  27. {
  28. this.isSelected = element.isSelected;
  29. }
  30. });
  31. if(!this.exists)
  32. {
  33. this.isSelected = false;
  34. }
  35. });
  36. }
  37. setStatus(produktname, selection)
  38. {
  39. function failure(reason) {
  40. // handle the error
  41. if(reason != null)
  42. {
  43. ;
  44. }
  45. }
  46. //schreibt den aktuellen Zustand in den Store
  47. this.store.findAll('produkt')
  48. .then(function(suchergebnis)
  49. {
  50. suchergebnis.forEach(element => {
  51. if(element.titel==produktname)
  52. {
  53. element.isSelected = selection;
  54. element.save().catch(failure);
  55. }
  56. });
  57. });
  58. }
  59. }