From 84c90eb6e831de268d258f9d8e38f5de98b43867 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 15 Nov 2017 13:18:10 -0500 Subject: [PATCH] Updating the javascript code with comments Add some documentation to the js code and cleaning some stuff up. --- js/collections/front/accounts.js | 1 + js/collections/front/regRates.js | 2 - js/collections/front/regRequestRegistrants.js | 4 + js/collections/front/regTimes.js | 4 + js/frontRegApp.js | 201 ++++++------------ js/models/front/account.js | 2 + js/models/front/regEvent.js | 6 + js/models/front/regRequestRegistrant.js | 2 + js/models/front/request.js | 1 + js/views/front/account.js | 3 + js/views/front/app.js | 8 + js/views/front/regClass.js | 110 ++-------- js/views/front/regEvent.js | 2 + js/views/front/regRequestRegistrant.js | 42 +--- js/views/front/regTime.js | 8 + js/views/front/registrantForm.js | 6 + 16 files changed, 132 insertions(+), 270 deletions(-) diff --git a/js/collections/front/accounts.js b/js/collections/front/accounts.js index d017c0c..94d4969 100644 --- a/js/collections/front/accounts.js +++ b/js/collections/front/accounts.js @@ -4,6 +4,7 @@ app.Collections.Front.Accounts = Backbone.Collection.extend({ model: app.Models.Front.Account, + // url used for all ajax request url: ajaxUrl+'&glm_action=regFront&collection=accounts', }); diff --git a/js/collections/front/regRates.js b/js/collections/front/regRates.js index ef101ce..851dc58 100644 --- a/js/collections/front/regRates.js +++ b/js/collections/front/regRates.js @@ -3,6 +3,4 @@ // Registration Rate Collection app.Collections.Front.RegRates = Backbone.Collection.extend({ model: app.Models.Front.RegRate, - - // localStorage }); diff --git a/js/collections/front/regRequestRegistrants.js b/js/collections/front/regRequestRegistrants.js index 1485022..6658715 100644 --- a/js/collections/front/regRequestRegistrants.js +++ b/js/collections/front/regRequestRegistrants.js @@ -1,6 +1,10 @@ app.Collections.Front.RegRequestRegistrants = Backbone.Collection.extend({ model: app.Models.Front.RegRequestRegistrant, + + // url used for all ajax request url: ajaxUrl+'&glm_action=regFront&collection=registrant=', + + // comparator used for keeping the collection sorted. comparator: function(reg1, reg2){ if ( reg1.get('lname') < reg2.get('lname') ) { return -1; diff --git a/js/collections/front/regTimes.js b/js/collections/front/regTimes.js index 93dd379..58a5e44 100644 --- a/js/collections/front/regTimes.js +++ b/js/collections/front/regTimes.js @@ -3,7 +3,11 @@ // reg time collection app.Collections.Front.RegTimes = Backbone.Collection.extend({ model: app.Models.Front.RegTime, + + // url is used for all ajax calls for models in this collection url: ajaxUrl+'&glm_action=regFront&collection=regTime=', + + // comparator is used to keep the collection ordered comparator: function(regTime1, regTime2){ var time1 = regTime1.get('start_datetime'); var time2 = regTime2.get('start_datetime'); diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 3e734da..57727cc 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -13,6 +13,7 @@ app.Models.Front.Account = Backbone.Model.extend({ validated: false, }, + // url used for ajax request url: ajaxUrl+'&glm_action=regFront&collection=account', initialize: function(){ @@ -21,6 +22,7 @@ app.Models.Front.Account = Backbone.Model.extend({ }); }, + // validate method for the model validate: function( attribs, options ){ if ( attribs.email === undefined || attribs.email === '' ) { return 'Need an email address!'; @@ -136,10 +138,16 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ this.classes = new app.Collections.Front.RegClasses(); }, + // setClasses + // To setup the classes collection setClasses: function( regClasses ){ this.classes.reset( regClasses ); }, + // setClassRegistrants + // To setup the registrant + // Has to create a regTime first for the class + // Then is can add the registrant into that regTime model. setClassRegistrants: function( registrants ){ for ( var i = 0; i < registrants.length; i++ ) { // console.log(registrants[i]); @@ -225,8 +233,10 @@ app.Models.Front.RegRequestRegistrant = Backbone.Model.extend({ country: '', }, + // url used for ajax request url: ajaxUrl+'&glm_action=regFront&collection=registrant', + // Validate method for the model validate: function( attribs, options ){ if ( attribs.fname === undefined || attribs.fname === '' ) { return 'First Name Required'; @@ -305,6 +315,7 @@ app.Models.Front.Request = Backbone.Model.extend({ last_update: '', }, + // url used for ajax request url: ajaxUrl+'&glm_action=regFront&collection=request', }); @@ -315,6 +326,7 @@ app.Models.Front.Request = Backbone.Model.extend({ app.Collections.Front.Accounts = Backbone.Collection.extend({ model: app.Models.Front.Account, + // url used for all ajax request url: ajaxUrl+'&glm_action=regFront&collection=accounts', }); @@ -358,13 +370,15 @@ app.Collections.Front.RegEvents = Backbone.Collection.extend({ // Registration Rate Collection app.Collections.Front.RegRates = Backbone.Collection.extend({ model: app.Models.Front.RegRate, - - // localStorage }); app.Collections.Front.RegRequestRegistrants = Backbone.Collection.extend({ model: app.Models.Front.RegRequestRegistrant, + + // url used for all ajax request url: ajaxUrl+'&glm_action=regFront&collection=registrant=', + + // comparator used for keeping the collection sorted. comparator: function(reg1, reg2){ if ( reg1.get('lname') < reg2.get('lname') ) { return -1; @@ -381,7 +395,11 @@ app.Collections.Front.RegRequestRegistrants = Backbone.Collection.extend({ // reg time collection app.Collections.Front.RegTimes = Backbone.Collection.extend({ model: app.Models.Front.RegTime, + + // url is used for all ajax calls for models in this collection url: ajaxUrl+'&glm_action=regFront&collection=regTime=', + + // comparator is used to keep the collection ordered comparator: function(regTime1, regTime2){ var time1 = regTime1.get('start_datetime'); var time2 = regTime2.get('start_datetime'); @@ -405,14 +423,17 @@ app.Views.Front.Account = Backbone.View.extend({ template: _.template( jQuery('#account-template').html() ), + // used to bind events for the view events: { }, + // setup the view initialize: function(){ this.listenTo( this.model, 'change', this.render ); return this; }, + // render the view render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); return this; @@ -430,12 +451,16 @@ app.Views.Front.App = Backbone.View.extend({ el: '#regApp', + // initialize + // used for init settings initialize: function(){ this.cart = cart; this.event = new app.Views.Front.RegEvent({ model: regEvent }); this.render(); }, + // render + // Used to render the view render: function(){ // Check to see if there's a login // if ( loginAccount ) { @@ -445,10 +470,14 @@ app.Views.Front.App = Backbone.View.extend({ return this; }, + // events + // used to bind events for the view events: { 'click #glm-reg-cart-continue': 'continue', }, + // continue + // used to goto the next page (cart) continue: function(){ window.location.href = nextPageUrl; }, @@ -464,27 +493,28 @@ app.Views.Front.RegClass = Backbone.View.extend({ template: _.template( jQuery('#regClass-template').html() ), + // used for initializing the view initialize: function(){ - this.listenTo( this.model.registrants, 'add', this.addOne ); - this.listenTo( this.model.registrants, 'create', this.addOne ); - this.listenTo( this.model.registrants, 'remove', this.deleteOne ); this.listenTo( this.model, 'change', this.render ); this.listenTo( this.model.regTimes, 'add', this.render ); return this; }, + // used for binding events to the view events: { 'click .addRegistrant': 'newEntry', 'click .fc-event-container': 'updateTimeSelection', 'click .show-hide-address': 'toggleClass', }, + // togle the ereg-addr class for the registrant form toggleClass: function(){ this.$('.ereg-addr').toggle(); }, + // used to add the regTime view/model to the class updateTimeSelection: function(e){ var timeId = this.$('.timeSelection').val().trim(); // Check to see if the time is already in the collection @@ -509,6 +539,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ } }, + // used to render the regClass view render: function(){ // this.model.set({ reg_count: this.model.registrants.length }); this.$el.html( this.template( this.model.toJSON() ) ); @@ -540,6 +571,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ return this; }, + // return the times object as an array getTimeArray: function(){ var times = this.model.get( 'times' ); var timeParts = []; @@ -556,6 +588,8 @@ app.Views.Front.RegClass = Backbone.View.extend({ return timeParts; }, + // called durring render to check for this.el in document + // then it can setup the fullCaldendar onRenderComplete: function() { if (!$.contains(document.documentElement, this.el)) { var that = this; @@ -569,6 +603,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ } }, + // called to setup the fullCalendar per class setCalendar: function(){ var times = this.model.get( 'times' ); var startTime = this.model.get('startingTime'); @@ -597,10 +632,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ }); }, - deleteOne: function( item ){ - this.render(); - }, - + // used to add login account to the class addAccount: function(){ // Check to make sure the loginAccount is not empty if ( loginAccount !== '' ) { @@ -634,81 +666,13 @@ app.Views.Front.RegClass = Backbone.View.extend({ } }, - addNew: function(){ - var findByEmail = []; - var fname = this.$('.add_reg_fname').val().trim(); - var lname = this.$('.add_reg_lname').val().trim(); - var email = this.$('.add_reg_email').val().trim(); - var addr1 = this.$('.add_reg_addr1').val().trim(); - var addr2 = this.$('.add_reg_addr2').val().trim(); - var city = this.$('.add_reg_city').val().trim(); - var state = this.$('.add_reg_state').val().trim(); - var zip = this.$('.add_reg_zip').val().trim(); - var country = this.$('.add_reg_country').val().trim(); - var sTime = this.model.get( 'selectedTime' ); - if ( this.$('#add_reg-select-time').length ) { - var times = this.model.get( 'times' ); - var rateId = null; - // Setup the needed reg_rate - _.each( times, function( time ){ - if ( time.id == sTime ) { - rateId = time.rate_id; - } - } ); - } else { - var times = this.model.get( 'times' ); - var rateId = null; - _.each( times, function( time ){ - rateId = time.rate_id; - } ); - } - if ( app.timeSpecific && !sTime ) { - alert( 'You must select a time!' ); - return; - } - if ( fname === '' || lname === '' ) { - alert( 'First and Last name required!' ); - return; - } - if ( email === '' ) { - var confAnsw = confirm( 'You have no email address! Are you sure you want to add this registrant?' ); - if ( !confAnsw ) { - return; - } - } else { - findByEmail = this.model.registrants.where({email: email}); - } - var regRequest = cart.get( 'request' ); - if ( findByEmail.length === 0 ) { - this.model.registrants.create({ - option: 'add', - reg_request: regRequest.id, - reg_time: sTime, - reg_event: this.model.get( 'reg_event' ), - reg_class: this.model.get( 'id' ), - event_name: regEvent.get( 'event_name' ), - reg_rate: rateId, - email: email, - fname: fname, - lname: lname, - addr1: addr1, - addr2: addr2, - city: city, - state: state, - zip: zip, - country: country, - }); - } - // this.newRegAccount.destroy(); - this.newRegAccountView.remove(); - // app.calendar = false; - }, - + // cancel add new cancelAddNew: function(){ this.$('.glm-add-new-account').show(); this.newRegAccountView.remove(); }, + // add new account addNewAccount: function(){ this.$('.glm-add-new-account').hide(); // Create the new Registrant View @@ -721,18 +685,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ this.$el.append( this.newRegAccountView.render().el ); }, - toggleClassOpen: function(){ - this.$('.reg-class-detail').show(); - this.$('.toggle-class-open').hide(); - this.$('.toggle-class-close').show(); - }, - - toggleClassClose: function(){ - this.$('.reg-class-detail').hide(); - this.$('.toggle-class-close').hide(); - this.$('.toggle-class-open').show(); - }, - // For the new entry check the email from the server and see // if there's already an account setup. newEntry: function(){ @@ -780,15 +732,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ }); }, - addOne: function( item ){ - this.model.set({selectedTime: item.get('reg_time') }) - this.render(); - }, - - addAll: function(){ - jQuery('.glm-reg-level').html(''); - }, - }); // js/views/regEvent.js @@ -807,6 +750,7 @@ app.Views.Front.RegEvent = Backbone.View.extend({ this.listenTo( this.model, 'change', this.render ); }, + // render the view render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); var view = regEvent.classes.map(function(item){ @@ -817,6 +761,7 @@ app.Views.Front.RegEvent = Backbone.View.extend({ return this; }, + // setup the count of classes getClassCount: function(){ return this.model.classes.length; }, @@ -830,11 +775,13 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ template: _.template( jQuery('#registrant-template').html() ), + // used to setup initial class initialize: function(){ this.listenTo( this.model, 'change', this.render ); return this; }, + // used for binding events to the view events: { 'click .glm-reg-level-registrant-delete': 'deleteOne', 'click .glm-registrant-edit': 'editRegistrant', @@ -842,6 +789,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ 'click .update-registrant': 'update', }, + // update the model update: function(){ var modelId = this.model.get( 'id' ); var fname = this.$('.reg_fname').val().trim(); @@ -889,49 +837,17 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ this.$('.reg-edit-form').hide(); }, - setCalendar: function(){ - var modelId = this.model.get( 'id' ); - // Find the class for this registrant - // Use findWhere to get the correct regClass - var regLevel = regEvent.classes.findWhere({ id: this.model.get( 'reg_class' ) }); - var times = regLevel.get( 'times' ); - $( '#eventCalendar-' + modelId ).fullCalendar({ - events: function(start, end, timezone, callback) { - var events = []; - _.each( times, function( time ){ - events.push({ - title: time.name, - start: time.start_datetime.datetime, - end: time.end_datetime.datetime, - allday: time.all_day.value, - reg_time: time.id, - }); - }); - callback( events ); - }, - defaultDate: startTime, - timeFormat: 'h:mma', - fixedWeekCount: false, - eventClick: function( calEvent, jsEvent, view ){ - $('.fc-event').css( 'background-color', '#3a67ad' ); - $(this).css( 'background-color', 'red' ); - jQuery( '#reg-time-' + modelId ).val( calEvent.reg_time ); - jQuery( '#reg-time-display-' + modelId ).html( calEvent.start.format( 'L LT' ) ); - }, - }); - }, + // cancel the edit of model cancelEdit: function(){ this.$('.reg-edit-form').hide(); }, + // show the edit form editRegistrant: function(){ this.$('.reg-edit-form').show(); - if ( app.timeSpecific === true ) { - this.$('#reg-select-time').val( this.model.get( 'reg_time' ) ); - this.setCalendar(); - } }, + // render the view render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); this.$emailInput = this.$('.editEmail'); @@ -939,6 +855,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ return this; }, + // delete the model/view deleteOne: function(){ // Remove model here var modelId = this.model.get('id'); @@ -961,6 +878,7 @@ app.Views.Front.RegTime = Backbone.View.extend({ template: _.template( jQuery('#regTime-template').html() ), + // initialize the view initialize: function(){ this.listenTo( this.model.registrants, 'add', this.addOne ); this.listenTo( this.model.registrants, 'create', this.addOne ); @@ -969,12 +887,14 @@ app.Views.Front.RegTime = Backbone.View.extend({ return this; }, + // bind event to the view events: { 'click .glm-add-new-account': 'addNewAccount', 'click .add-new-registrant': 'insertNew', 'click .add-new-registrant-cancel': 'cancelAddNew', }, + // render the view render: function(){ this.model.set({ reg_count: this.model.registrants.length }); this.$el.html( this.template( this.model.toJSON() ) ); @@ -987,6 +907,7 @@ app.Views.Front.RegTime = Backbone.View.extend({ return this; }, + // add new account addNewAccount: function(){ this.$('.glm-add-new-account').hide(); // Create the new Registrant View @@ -999,6 +920,7 @@ app.Views.Front.RegTime = Backbone.View.extend({ this.$el.append( this.newRegAccountView.render().el ); }, + // insert new registrant insertNew: function(){ var findByEmail = []; var fname = this.$('.add_reg_fname').val().trim(); @@ -1067,17 +989,20 @@ app.Views.Front.RegTime = Backbone.View.extend({ // app.calendar = false; }, + // cancel add new registrant cancelAddNew: function(){ this.$('.glm-add-new-account').show(); // this.newRegAccount.destroy(); this.newRegAccountView.remove(); }, + // add a registrant to collection addOne: function( item ){ this.model.set({selectedTime: item.get('reg_time') }) this.render(); }, + // delete a registrant in collection deleteOne: function( item ){ this.render(); }, @@ -1096,19 +1021,23 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ template: _.template( jQuery('#eventReg-registrant-add').html() ), + // bind events to the view events: { 'focusout .add_reg_email': 'verifyEmail' }, + // setup the view initialize: function(){ return this; }, + // render the view render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); return this; }, + // verify the email address verifyEmail: function(){ var email = this.$('.add_reg_email').val().trim(); if ( email == '' ) { @@ -1146,6 +1075,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ } }, + // lock the form lockForm: function(){ this.$('.add_reg_fname').prop('disabled', true); this.$('.add_reg_lname').prop('disabled', true); @@ -1157,6 +1087,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ this.$('.add_reg_country').prop('disabled', true); }, + // unlock the form unLockForm: function(){ this.$('.add_reg_fname').prop('disabled', false); this.$('.add_reg_lname').prop('disabled', false); diff --git a/js/models/front/account.js b/js/models/front/account.js index da45b24..f7f71ad 100644 --- a/js/models/front/account.js +++ b/js/models/front/account.js @@ -13,6 +13,7 @@ app.Models.Front.Account = Backbone.Model.extend({ validated: false, }, + // url used for ajax request url: ajaxUrl+'&glm_action=regFront&collection=account', initialize: function(){ @@ -21,6 +22,7 @@ app.Models.Front.Account = Backbone.Model.extend({ }); }, + // validate method for the model validate: function( attribs, options ){ if ( attribs.email === undefined || attribs.email === '' ) { return 'Need an email address!'; diff --git a/js/models/front/regEvent.js b/js/models/front/regEvent.js index 11e6c3d..b72425e 100644 --- a/js/models/front/regEvent.js +++ b/js/models/front/regEvent.js @@ -22,10 +22,16 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ this.classes = new app.Collections.Front.RegClasses(); }, + // setClasses + // To setup the classes collection setClasses: function( regClasses ){ this.classes.reset( regClasses ); }, + // setClassRegistrants + // To setup the registrant + // Has to create a regTime first for the class + // Then is can add the registrant into that regTime model. setClassRegistrants: function( registrants ){ for ( var i = 0; i < registrants.length; i++ ) { // console.log(registrants[i]); diff --git a/js/models/front/regRequestRegistrant.js b/js/models/front/regRequestRegistrant.js index 5fc6819..e1b08b1 100644 --- a/js/models/front/regRequestRegistrant.js +++ b/js/models/front/regRequestRegistrant.js @@ -27,8 +27,10 @@ app.Models.Front.RegRequestRegistrant = Backbone.Model.extend({ country: '', }, + // url used for ajax request url: ajaxUrl+'&glm_action=regFront&collection=registrant', + // Validate method for the model validate: function( attribs, options ){ if ( attribs.fname === undefined || attribs.fname === '' ) { return 'First Name Required'; diff --git a/js/models/front/request.js b/js/models/front/request.js index 2bf8929..d4b8b96 100644 --- a/js/models/front/request.js +++ b/js/models/front/request.js @@ -32,6 +32,7 @@ app.Models.Front.Request = Backbone.Model.extend({ last_update: '', }, + // url used for ajax request url: ajaxUrl+'&glm_action=regFront&collection=request', }); diff --git a/js/views/front/account.js b/js/views/front/account.js index 623e5a4..5fd6fe8 100644 --- a/js/views/front/account.js +++ b/js/views/front/account.js @@ -8,14 +8,17 @@ app.Views.Front.Account = Backbone.View.extend({ template: _.template( jQuery('#account-template').html() ), + // used to bind events for the view events: { }, + // setup the view initialize: function(){ this.listenTo( this.model, 'change', this.render ); return this; }, + // render the view render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); return this; diff --git a/js/views/front/app.js b/js/views/front/app.js index 005dc60..71b0caa 100644 --- a/js/views/front/app.js +++ b/js/views/front/app.js @@ -8,12 +8,16 @@ app.Views.Front.App = Backbone.View.extend({ el: '#regApp', + // initialize + // used for init settings initialize: function(){ this.cart = cart; this.event = new app.Views.Front.RegEvent({ model: regEvent }); this.render(); }, + // render + // Used to render the view render: function(){ // Check to see if there's a login // if ( loginAccount ) { @@ -23,10 +27,14 @@ app.Views.Front.App = Backbone.View.extend({ return this; }, + // events + // used to bind events for the view events: { 'click #glm-reg-cart-continue': 'continue', }, + // continue + // used to goto the next page (cart) continue: function(){ window.location.href = nextPageUrl; }, diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index 6fdbcb1..a5617c1 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -7,27 +7,28 @@ app.Views.Front.RegClass = Backbone.View.extend({ template: _.template( jQuery('#regClass-template').html() ), + // used for initializing the view initialize: function(){ - this.listenTo( this.model.registrants, 'add', this.addOne ); - this.listenTo( this.model.registrants, 'create', this.addOne ); - this.listenTo( this.model.registrants, 'remove', this.deleteOne ); this.listenTo( this.model, 'change', this.render ); this.listenTo( this.model.regTimes, 'add', this.render ); return this; }, + // used for binding events to the view events: { 'click .addRegistrant': 'newEntry', 'click .fc-event-container': 'updateTimeSelection', 'click .show-hide-address': 'toggleClass', }, + // togle the ereg-addr class for the registrant form toggleClass: function(){ this.$('.ereg-addr').toggle(); }, + // used to add the regTime view/model to the class updateTimeSelection: function(e){ var timeId = this.$('.timeSelection').val().trim(); // Check to see if the time is already in the collection @@ -52,6 +53,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ } }, + // used to render the regClass view render: function(){ // this.model.set({ reg_count: this.model.registrants.length }); this.$el.html( this.template( this.model.toJSON() ) ); @@ -83,6 +85,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ return this; }, + // return the times object as an array getTimeArray: function(){ var times = this.model.get( 'times' ); var timeParts = []; @@ -99,6 +102,8 @@ app.Views.Front.RegClass = Backbone.View.extend({ return timeParts; }, + // called durring render to check for this.el in document + // then it can setup the fullCaldendar onRenderComplete: function() { if (!$.contains(document.documentElement, this.el)) { var that = this; @@ -112,6 +117,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ } }, + // called to setup the fullCalendar per class setCalendar: function(){ var times = this.model.get( 'times' ); var startTime = this.model.get('startingTime'); @@ -140,10 +146,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ }); }, - deleteOne: function( item ){ - this.render(); - }, - + // used to add login account to the class addAccount: function(){ // Check to make sure the loginAccount is not empty if ( loginAccount !== '' ) { @@ -177,81 +180,13 @@ app.Views.Front.RegClass = Backbone.View.extend({ } }, - addNew: function(){ - var findByEmail = []; - var fname = this.$('.add_reg_fname').val().trim(); - var lname = this.$('.add_reg_lname').val().trim(); - var email = this.$('.add_reg_email').val().trim(); - var addr1 = this.$('.add_reg_addr1').val().trim(); - var addr2 = this.$('.add_reg_addr2').val().trim(); - var city = this.$('.add_reg_city').val().trim(); - var state = this.$('.add_reg_state').val().trim(); - var zip = this.$('.add_reg_zip').val().trim(); - var country = this.$('.add_reg_country').val().trim(); - var sTime = this.model.get( 'selectedTime' ); - if ( this.$('#add_reg-select-time').length ) { - var times = this.model.get( 'times' ); - var rateId = null; - // Setup the needed reg_rate - _.each( times, function( time ){ - if ( time.id == sTime ) { - rateId = time.rate_id; - } - } ); - } else { - var times = this.model.get( 'times' ); - var rateId = null; - _.each( times, function( time ){ - rateId = time.rate_id; - } ); - } - if ( app.timeSpecific && !sTime ) { - alert( 'You must select a time!' ); - return; - } - if ( fname === '' || lname === '' ) { - alert( 'First and Last name required!' ); - return; - } - if ( email === '' ) { - var confAnsw = confirm( 'You have no email address! Are you sure you want to add this registrant?' ); - if ( !confAnsw ) { - return; - } - } else { - findByEmail = this.model.registrants.where({email: email}); - } - var regRequest = cart.get( 'request' ); - if ( findByEmail.length === 0 ) { - this.model.registrants.create({ - option: 'add', - reg_request: regRequest.id, - reg_time: sTime, - reg_event: this.model.get( 'reg_event' ), - reg_class: this.model.get( 'id' ), - event_name: regEvent.get( 'event_name' ), - reg_rate: rateId, - email: email, - fname: fname, - lname: lname, - addr1: addr1, - addr2: addr2, - city: city, - state: state, - zip: zip, - country: country, - }); - } - // this.newRegAccount.destroy(); - this.newRegAccountView.remove(); - // app.calendar = false; - }, - + // cancel add new cancelAddNew: function(){ this.$('.glm-add-new-account').show(); this.newRegAccountView.remove(); }, + // add new account addNewAccount: function(){ this.$('.glm-add-new-account').hide(); // Create the new Registrant View @@ -264,18 +199,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ this.$el.append( this.newRegAccountView.render().el ); }, - toggleClassOpen: function(){ - this.$('.reg-class-detail').show(); - this.$('.toggle-class-open').hide(); - this.$('.toggle-class-close').show(); - }, - - toggleClassClose: function(){ - this.$('.reg-class-detail').hide(); - this.$('.toggle-class-close').hide(); - this.$('.toggle-class-open').show(); - }, - // For the new entry check the email from the server and see // if there's already an account setup. newEntry: function(){ @@ -323,13 +246,4 @@ app.Views.Front.RegClass = Backbone.View.extend({ }); }, - addOne: function( item ){ - this.model.set({selectedTime: item.get('reg_time') }) - this.render(); - }, - - addAll: function(){ - jQuery('.glm-reg-level').html(''); - }, - }); diff --git a/js/views/front/regEvent.js b/js/views/front/regEvent.js index 17d8456..6038a8f 100644 --- a/js/views/front/regEvent.js +++ b/js/views/front/regEvent.js @@ -14,6 +14,7 @@ app.Views.Front.RegEvent = Backbone.View.extend({ this.listenTo( this.model, 'change', this.render ); }, + // render the view render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); var view = regEvent.classes.map(function(item){ @@ -24,6 +25,7 @@ app.Views.Front.RegEvent = Backbone.View.extend({ return this; }, + // setup the count of classes getClassCount: function(){ return this.model.classes.length; }, diff --git a/js/views/front/regRequestRegistrant.js b/js/views/front/regRequestRegistrant.js index 262fb73..f1be6a2 100644 --- a/js/views/front/regRequestRegistrant.js +++ b/js/views/front/regRequestRegistrant.js @@ -5,11 +5,13 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ template: _.template( jQuery('#registrant-template').html() ), + // used to setup initial class initialize: function(){ this.listenTo( this.model, 'change', this.render ); return this; }, + // used for binding events to the view events: { 'click .glm-reg-level-registrant-delete': 'deleteOne', 'click .glm-registrant-edit': 'editRegistrant', @@ -17,6 +19,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ 'click .update-registrant': 'update', }, + // update the model update: function(){ var modelId = this.model.get( 'id' ); var fname = this.$('.reg_fname').val().trim(); @@ -64,49 +67,17 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ this.$('.reg-edit-form').hide(); }, - setCalendar: function(){ - var modelId = this.model.get( 'id' ); - // Find the class for this registrant - // Use findWhere to get the correct regClass - var regLevel = regEvent.classes.findWhere({ id: this.model.get( 'reg_class' ) }); - var times = regLevel.get( 'times' ); - $( '#eventCalendar-' + modelId ).fullCalendar({ - events: function(start, end, timezone, callback) { - var events = []; - _.each( times, function( time ){ - events.push({ - title: time.name, - start: time.start_datetime.datetime, - end: time.end_datetime.datetime, - allday: time.all_day.value, - reg_time: time.id, - }); - }); - callback( events ); - }, - defaultDate: startTime, - timeFormat: 'h:mma', - fixedWeekCount: false, - eventClick: function( calEvent, jsEvent, view ){ - $('.fc-event').css( 'background-color', '#3a67ad' ); - $(this).css( 'background-color', 'red' ); - jQuery( '#reg-time-' + modelId ).val( calEvent.reg_time ); - jQuery( '#reg-time-display-' + modelId ).html( calEvent.start.format( 'L LT' ) ); - }, - }); - }, + // cancel the edit of model cancelEdit: function(){ this.$('.reg-edit-form').hide(); }, + // show the edit form editRegistrant: function(){ this.$('.reg-edit-form').show(); - if ( app.timeSpecific === true ) { - this.$('#reg-select-time').val( this.model.get( 'reg_time' ) ); - this.setCalendar(); - } }, + // render the view render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); this.$emailInput = this.$('.editEmail'); @@ -114,6 +85,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ return this; }, + // delete the model/view deleteOne: function(){ // Remove model here var modelId = this.model.get('id'); diff --git a/js/views/front/regTime.js b/js/views/front/regTime.js index 00979a3..499264d 100644 --- a/js/views/front/regTime.js +++ b/js/views/front/regTime.js @@ -7,6 +7,7 @@ app.Views.Front.RegTime = Backbone.View.extend({ template: _.template( jQuery('#regTime-template').html() ), + // initialize the view initialize: function(){ this.listenTo( this.model.registrants, 'add', this.addOne ); this.listenTo( this.model.registrants, 'create', this.addOne ); @@ -15,12 +16,14 @@ app.Views.Front.RegTime = Backbone.View.extend({ return this; }, + // bind event to the view events: { 'click .glm-add-new-account': 'addNewAccount', 'click .add-new-registrant': 'insertNew', 'click .add-new-registrant-cancel': 'cancelAddNew', }, + // render the view render: function(){ this.model.set({ reg_count: this.model.registrants.length }); this.$el.html( this.template( this.model.toJSON() ) ); @@ -33,6 +36,7 @@ app.Views.Front.RegTime = Backbone.View.extend({ return this; }, + // add new account addNewAccount: function(){ this.$('.glm-add-new-account').hide(); // Create the new Registrant View @@ -45,6 +49,7 @@ app.Views.Front.RegTime = Backbone.View.extend({ this.$el.append( this.newRegAccountView.render().el ); }, + // insert new registrant insertNew: function(){ var findByEmail = []; var fname = this.$('.add_reg_fname').val().trim(); @@ -113,17 +118,20 @@ app.Views.Front.RegTime = Backbone.View.extend({ // app.calendar = false; }, + // cancel add new registrant cancelAddNew: function(){ this.$('.glm-add-new-account').show(); // this.newRegAccount.destroy(); this.newRegAccountView.remove(); }, + // add a registrant to collection addOne: function( item ){ this.model.set({selectedTime: item.get('reg_time') }) this.render(); }, + // delete a registrant in collection deleteOne: function( item ){ this.render(); }, diff --git a/js/views/front/registrantForm.js b/js/views/front/registrantForm.js index 72793a9..7765ec0 100644 --- a/js/views/front/registrantForm.js +++ b/js/views/front/registrantForm.js @@ -11,19 +11,23 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ template: _.template( jQuery('#eventReg-registrant-add').html() ), + // bind events to the view events: { 'focusout .add_reg_email': 'verifyEmail' }, + // setup the view initialize: function(){ return this; }, + // render the view render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); return this; }, + // verify the email address verifyEmail: function(){ var email = this.$('.add_reg_email').val().trim(); if ( email == '' ) { @@ -61,6 +65,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ } }, + // lock the form lockForm: function(){ this.$('.add_reg_fname').prop('disabled', true); this.$('.add_reg_lname').prop('disabled', true); @@ -72,6 +77,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ this.$('.add_reg_country').prop('disabled', true); }, + // unlock the form unLockForm: function(){ this.$('.add_reg_fname').prop('disabled', false); this.$('.add_reg_lname').prop('disabled', false); -- 2.17.1