From: Steve Sutton Date: Wed, 23 Aug 2017 20:07:57 +0000 (-0400) Subject: Organizing view files for Event reg front end. X-Git-Tag: v1.0.0^2~450 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=7f881cbcfab5998db8e57db2b5ae394150123b2a;p=WP-Plugins%2Fglm-member-db-registrations.git Organizing view files for Event reg front end. Renaming the eventRegistrantList view file to appView. --- diff --git a/js/eventRegApp.js b/js/eventRegApp.js index 0c26225..6bf10ea 100644 --- a/js/eventRegApp.js +++ b/js/eventRegApp.js @@ -9,6 +9,6 @@ app.EventRegistrants = new app.EventRegistrantList(); jQuery(document).ready(function($){ - new app.EventRegistrantListView(); + new app.AppView(); }); diff --git a/js/views/appView.js b/js/views/appView.js new file mode 100644 index 0000000..4c7aa7f --- /dev/null +++ b/js/views/appView.js @@ -0,0 +1,67 @@ +// js/views/appView.js +var app = app || {}; + +// Event Registrant List View +app.AppView = Backbone.View.extend({ + + el: '.glm-reg-level', + + initialize: function(){ + this.$newName = this.$('.addName'); + this.$newEmail = this.$('.addEmail'); + + this.listenTo( app.EventRegistrants, 'add', this.addOne ); + this.listenTo( app.EventRegistrants, 'reset', this.addAll ); + app.EventRegistrants.fetch(); + //this.collection.bind('add', this.onModelAdded, this); + //this.render(); + }, + + deleteOne: function( el ){ + console.log( el ); + console.log( 'deleteOne called on listView' ); + //app.EventRegistrants.fetch(); + }, + + events: { + 'click .addRegistrant': 'newEntry', + }, + + newEntry: function(){ + if ( !this.$newName.val().trim() || !this.$newEmail.val().trim() ) { + return; + } + var emailMatches = app.EventRegistrants.where({email: this.$newEmail.val().trim()}); + app.EventRegistrants.create( this.newAttributes() ); + this.$newName.val(''); + this.$newEmail.val(''); + }, + + newAttributes: function(){ + return { + name: this.$newName.val().trim(), + email: this.$newEmail.val().trim() + }; + }, + + addOne: function(item){ + if ( item.isValid() ) { + var view = new app.EventRegistrantView({ model: item }); + this.$el.append( view.render().el ); + } + }, + + addAll: function(){ + this.$('.glm-reg-level').html(''); + app.EventRegistrants.each(this.addOne, this); + }, + + render: function(){ + var eventRegistrantView = this.collection.map(function(item){ + return (new app.EventRegistrantView({ model: item })).render().el; + }); + this.$el.append(eventRegistrantView); + return this; + }, + +}); diff --git a/js/views/eventRegistrantList.js b/js/views/eventRegistrantList.js deleted file mode 100644 index a355aee..0000000 --- a/js/views/eventRegistrantList.js +++ /dev/null @@ -1,67 +0,0 @@ -// js/views/eventRegistrantList.js -var app = app || {}; - -// Event Registrant List View -app.EventRegistrantListView = Backbone.View.extend({ - - el: '.glm-reg-level', - - initialize: function(){ - this.$newName = this.$('.addName'); - this.$newEmail = this.$('.addEmail'); - - this.listenTo( app.EventRegistrants, 'add', this.addOne ); - this.listenTo( app.EventRegistrants, 'reset', this.addAll ); - app.EventRegistrants.fetch(); - //this.collection.bind('add', this.onModelAdded, this); - //this.render(); - }, - - deleteOne: function( el ){ - console.log( el ); - console.log( 'deleteOne called on listView' ); - //app.EventRegistrants.fetch(); - }, - - events: { - 'click .addRegistrant': 'newEntry', - }, - - newEntry: function(){ - if ( !this.$newName.val().trim() || !this.$newEmail.val().trim() ) { - return; - } - var emailMatches = app.EventRegistrants.where({email: this.$newEmail.val().trim()}); - app.EventRegistrants.create( this.newAttributes() ); - this.$newName.val(''); - this.$newEmail.val(''); - }, - - newAttributes: function(){ - return { - name: this.$newName.val().trim(), - email: this.$newEmail.val().trim() - }; - }, - - addOne: function(item){ - if ( item.isValid() ) { - var view = new app.EventRegistrantView({ model: item }); - this.$el.append( view.render().el ); - } - }, - - addAll: function(){ - this.$('.glm-reg-level').html(''); - app.EventRegistrants.each(this.addOne, this); - }, - - render: function(){ - var eventRegistrantView = this.collection.map(function(item){ - return (new app.EventRegistrantView({ model: item })).render().el; - }); - this.$el.append(eventRegistrantView); - return this; - }, - -}); diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index a8c8800..d91acc9 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -40,7 +40,7 @@ $scripts = array( 'backbone-local' => 'js/lib/backbone.localStorage.min.js', 'registrantView' => 'js/views/eventRegistrant.js', - 'registrantListView' => 'js/views/eventRegistrantList.js', + 'appView' => 'js/views/appView.js', 'registrantModel' => 'js/models/eventRegistrant.js', 'registrantList' => 'js/collections/eventRegistrantList.js', 'mybackboneapp' => 'js/eventRegApp.js',