コード例 #1
0
module.exports = function() {
  var Admin = LayoutView.extend({
    regions: {
      collectionRegion: '#collection'
    },
    template: require('./admin-route.html'),
    onShow: function() {
      var agencies = new FeedCollectionCollection();
      var instance = this;
      agencies.fetch().done(function() {
        instance.collectionRegion.show(new FeedCollectionCollectionView({
          collection: agencies
        }));
      })

      app.nav.setLocation([]);
    }
  });

  // show your work
  app.appRegion.show(new Admin());
}
コード例 #2
0
module.exports = LayoutView.extend({
  template: require('./feed-version-view.html'),

  regions: {
    routesRegion: '#routes',
    tripsRegion: '#trips',
    stopsRegion: '#stops',
    shapesRegion: '#shapes',
    notesRegion: '.version-notes'
  },

  onShow: function() {
    var result = this.model.get('validationResult');
    try {
      var invalidRoutes = result.routes.invalidValues;
      if (invalidRoutes && invalidRoutes.length > 0) {
        this.routesRegion.show(new InvalidValuesList({
          invalidValues: invalidRoutes,
          type: 'route'
        }));
      }
    } catch (e) {}

    try {
      var invalidStops = result.stops.invalidValues;
      if (invalidStops && invalidStops.length > 0) {
        this.stopsRegion.show(new InvalidValuesList({
          invalidValues: invalidStops,
          type: 'stop'
        }));
      }
    } catch (e) {}

    try {
      var invalidTrips = result.trips.invalidValues;
      if (invalidTrips && invalidTrips.length > 0) {
        this.tripsRegion.show(new InvalidValuesList({
          invalidValues: invalidTrips,
          type: 'trip',
          showRoute: true
        }));
      }
    } catch (e) {}

    try {
      var invalidShapes = result.shapes.invalidValues;
      if (invalidShapes && invalidShapes.length > 0) {
        this.shapesRegion.show(new InvalidValuesList({
          invalidValues: invalidShapes,
          type: 'shape'
        }));
      }
    } catch (e) {}

    // set up notes
    this.notesRegion.show(new NoteCollectionView({
      objectId: this.model.get('id'),
      type: 'FEED_VERSION'
    }));
  }
});
コード例 #3
0
module.exports = LayoutView.extend({
  regions: {
    nameRegion: '.name',
    urlRegion: '.url'
  },
  template: require('./feed-source-item-view.html'),
  tagName: 'tr',

  events: {
    'change .edit-bool': 'editBool',
    'change .feed-source': 'editSource',
    'click .remove-feed': 'removeSource'
  },

  initialize: function() {
    _.bindAll(this, 'editBool', 'editSource', 'removeSource', 'handleUrlRegion');
  },

  // edit a boolean value
  editBool: function(e) {
    var $t = $(e.target);

    var attr = {};
    attr[$t.attr('name')] = $t.is(':checked');

    this.model.set(attr);
    this.model.save();

    // no need to re-render because the checkbox has already been rendered by the browser
  },

  // edit the retrieval method
  editSource: function(e) {
    this.model.set('retrievalMethod', $(e.target).val());
    this.model.save();
  },

  // delete a feed source
  removeSource: function(e) {
    var instance = this;
    app.modalRegion.show(new ConfirmView({
      title: window.Messages('app.confirm'),
      body: window.Messages('app.confirm_delete', this.model.get('name')),
      onProceed: function() {
        instance.model.destroy();
      }
    }));
  },

  onShow: function() {
    var nameField = new EditableTextWidget({
      model: this.model,
      attribute: 'name',
      href: function() {
        if (this.model.id === null) {
          // make it a no-op until saved
          return '#overview/' + this.model.get('feedCollection').id;
        } else {
          return '#feed/' + this.model.get('id');
        }
      }
    });
    this.nameRegion.show(nameField);

    // start out editing name if it's new; this way we ensure it is saved before
    if (_.isUndefined(this.model.id) || _.isNull(this.model.id))
      nameField.edit();

    this.handleUrlRegion();
    this.model.on('change:retrievalMethod', this.handleUrlRegion);
  },

  // figure out what belongs in the URL region: a URL editor, a GTFS Editor selector, or nothing
  handleUrlRegion: function() {
    var retrievalMethod = this.model.get('retrievalMethod');
    if (retrievalMethod == 'FETCHED_AUTOMATICALLY') {
      this.urlRegion.show(new EditableTextWidget({
        model: this.model,
        maxWidth: 35,
        attribute: 'url',
        href: function() {
          return this.model.get('url');
        }
      }));
    } else if (retrievalMethod == 'PRODUCED_IN_HOUSE') {
      this.urlRegion.show(new EditorAgencyView({
        model: this.model
      }));
    } else {
      this.urlRegion.empty();
    }
  }
});
コード例 #4
0
module.exports = LayoutView.extend({
  template: require('./feed-version-navigation-view.html'),

  events: {
    'click .upload-feed': 'uploadFeed',
    'click .update-feed': 'updateFeed'
  },

  // show the feed upload dialog
  uploadFeed: function(e) {
    // model is so that it knows what feed source to upload to
    app.modalRegion.show(new FeedUploadView({
      model: new FeedSource(this.model.get('feedSource'))
    }));
  },

  // fetch the latest version of an autofetched/produced in house feed
  updateFeed: function(e) {
    var fs = this.model.get('feedSource');
    if (fs.retrievalMethod == 'PRODUCED_IN_HOUSE' && (!fs.editorId || !fs.snapshotVersion)) {
      app.modalRegion.show(new OkDialogView({
        title: window.Messages('app.feed_version.cannot_update'),
        body: window.Messages('app.feed_version.editor_select')
      }));
      return;
    }

    // user feedback
    var $t = $(e.target);
    $t.find('span.glyphicon').addClass('spinner');
    $t.attr('disabled', true);
    $t.find('span.button-label').text(window.Messages('app.feed_version.updating'));

    var instance = this;
    $.ajax({
      url: 'api/feedsources/' + this.model.get('feedSource').id + '/fetch',
      method: 'POST',
      success: function(data) {
        $t.find('span').removeClass('spinner');
        $t.attr('disabled', false);
        $t.find('span.button-label').text(window.Messages('app.feed_version.update'));

        if (data === null) {
          window.alert('Feed has not changed');
        } else {
          var newVersion = new FeedVersion(data);
          window.location.hash = '#feed/' + newVersion.get('feedSource').id + '/' + newVersion.id;
        }
      }
    });
  },

  initialize: function(attr) {
    if (_.isUndefined(this.model)) {
      // we create a dummy model simply so we don't have to check in the view if the model exists, only if its properties exist
      // and so we can access the feedSource in a uniform way regardless of whether the version exists
      this.model = new FeedVersion({
        feedSource: attr.feedSource.toJSON()
      });
    }

    _.bindAll(this, 'uploadFeed', 'updateFeed');
  },
})