location.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const locationItemTemplate = require('./location-item.ejs');
  2. const Mn = require('backbone.marionette');
  3. const App = require('../../main');
  4. const LocationView = Mn.View.extend({
  5. template: locationItemTemplate,
  6. className: 'location_block',
  7. ui: {
  8. toggle: 'input[type="checkbox"]',
  9. config: '.config',
  10. delete: '.location-delete'
  11. },
  12. events: {
  13. 'change @ui.toggle': function(el) {
  14. if (el.target.checked) {
  15. this.ui.config.show();
  16. } else {
  17. this.ui.config.hide();
  18. }
  19. },
  20. 'change .model': function (e) {
  21. const map = {};
  22. map[e.target.name] = e.target.value;
  23. this.model.set(map);
  24. },
  25. 'click @ui.delete': function () {
  26. this.model.destroy();
  27. }
  28. },
  29. onRender: function() {
  30. $(this.ui.config).hide();
  31. },
  32. templateContext: function() {
  33. return {
  34. i18n: App.i18n
  35. }
  36. }
  37. });
  38. const LocationCollectionView = Mn.CollectionView.extend({
  39. className: 'locations_container',
  40. childView: LocationView
  41. });
  42. module.exports = {
  43. LocationCollectionView,
  44. LocationView
  45. }