diff --git a/public/app/app.js b/public/app/app.js index 8b3d4b2..065b84c 100644 --- a/public/app/app.js +++ b/public/app/app.js @@ -12,6 +12,9 @@ define([ // Localize or create a new JavaScript Template object. var JST = window.JST = window.JST || {}; + BostonGlobe = {}; + BostonGlobe.vent = _.extend({}, Backbone.Events); + // Configure LayoutManager with Backbone Boilerplate defaults. Backbone.Layout.configure({ // Allow LayoutManager to augment Backbone.View.prototype. diff --git a/public/app/modules/articles.js b/public/app/modules/articles.js index 42a3b50..b2d642c 100644 --- a/public/app/modules/articles.js +++ b/public/app/modules/articles.js @@ -305,6 +305,13 @@ define([ Article.Views.AuthorListItem = Backbone.View.extend({ template: "articles/authorListItem", tagName: "li", + events: { + "click" : "onAuthorListSelection" + }, + onAuthorListSelection: function(e){ + url = "http://50.17.92.83/s?key=chris&bq=(and%20byname:'" + encodeURIComponent(this.model.attributes.name) + "'%20printpublicationdate:" + moment().subtract("days", 60).format("YYYYMMDD") + ".." + moment().format("YYYYMMDD") + ")&return-fields=id&start=0&size=50&rank=-printpublicationdate"; + BostonGlobe.vent.trigger("Job.Views.Form:enqueueNewJob",{url:url , name:"author: " + this.model.attributes.name}); + }, serialize: function() { return this.model.toJSON(); } @@ -322,4 +329,4 @@ define([ }); return Article; -}); \ No newline at end of file +}); diff --git a/public/app/modules/jobs.js b/public/app/modules/jobs.js index 6d32a8c..64fa217 100644 --- a/public/app/modules/jobs.js +++ b/public/app/modules/jobs.js @@ -107,16 +107,15 @@ define([ // pass a job_list option pointing to the job list view. initialize : function(attrs, options) { this.job_list = options.job_list; + + BostonGlobe.vent.on("Job.Views.Form:enqueueNewJob", this.enqueueNewJob, this) + }, - // interrupt normal form submission to use backbon'e save - // method instead. - onSubmit : function(e) { + enqueueNewJob : function(args){ // save the url in our job model. - var url_value = this.$el.find('#url').val(); - var name = this.$el.find('#query_name').val(); - this.model.set({ 'url': url_value, 'name' : name }); + this.model.set({ 'url':args.url, 'name' : args.name }); // save the model. On success add it to the job list! this.model.save({}, { wait: true }).then(_.bind(function() { @@ -133,11 +132,18 @@ define([ this.$el.find('#query_name').val(''); }, this)); + }, - + // interrupt normal form submission to use backbon'e save + // method instead. + onSubmit : function(e) { + // save the url in our job model. + var url_value = this.$el.find('#url').val(); + var name = this.$el.find('#query_name').val(); + this.enqueueNewJob({url:url_value, name: name}); return false; } }); return Job; -}); \ No newline at end of file +});