Trying to get the models and views to have better garbage collection.
Need to remove the model and view that is used for the add forms after
it creates the new model in the collection.
initialize: function(){
// for setting up classes
- this.classes = new app.Collections.Front.RegClasses();
+ this.classes = new app.Collections.Front.RegClasses( [] );
},
// setClasses
// To setup the classes collection
setClasses: function( regClasses ){
+ console.log( regClasses );
this.classes.reset( regClasses );
},
// Using the registrants reg_time lookup the regTime
// var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time});
var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time });
- // console.log( foundRegTime );
+ console.log( 'find reg time' );
+ console.log( foundRegTime );
if ( foundRegTime ) {
// Set the reg_event for this reg_time to the class we found for registrant
foundRegTime.reg_event = foundClass.get('reg_event');
}
// Add the registrant to the regTime.
var nRegTime = foundClass.regTimes.findWhere({id: hasRegTime.get('id')});
+ console.log( 'nRegTime' );
+ console.log(nRegTime);
nRegTime.registrants.create( registrants[i] );
}
// Add times into regTimes collection
var classTimes = this.model.get('times');
+ var timeArs = [];
for ( var key in classTimes ) {
var newTime = new app.Models.Front.RegTime( classTimes[key] );
newTime.set({reg_event: this.model.get('reg_event'), parent: this.model});
- this.model.regTimes.create( newTime );
+ timeArs.push( newTime );
+ // this.model.regTimes.create( newTime );
}
+ this.model.regTimes.reset( timeArs );
// console.log( classTimes );
// this.model.set({ reg_count: this.model.registrants.length });
this.$el.html( this.template( this.model.toJSON() ) );
// Go through the RegTimes Collection and render those
- // var view = this.model.
- // this.model.regTimes.sort();
// var classId = this.model.id;
- var view = this.model.regTimes.map(function(item){
- // item.parent = classId;
- return (new app.Views.Front.RegTime({ model: item })).render().el;
- });
var timeContainer = this.$('.reg-class-times');
- timeContainer.append( view );
if ( loginAccount === '' ) {
this.$('.glm-add-account').hide();
}
if ( !app.timeSpecific ) {
// this.$('.glm-add-new-account').show();
- this.updateTimeSelection();
+ // this.updateTimeSelection();
+ console.log( this.model.regTimes );
+
} else {
var sTime = this.model.get( 'selectedTime' );
if ( !sTime ) {
this.$('.glm-add-new-account').show();
}
}
- this.onRenderComplete();
+ var view = this.model.regTimes.map(function(item){
+ return (new app.Views.Front.RegTime({ model: item })).render().el;
+ });
+ timeContainer.append( view );
return this;
},
this.$el.html( this.template( this.model.toJSON() ) );
this.$emailInput = this.$('.editEmail');
this.$('.reg-edit-form').hide();
- this.setCustomFieldsForm();
+ app.setCustomFieldsForm(this.model.get('reg_event'), '.attendee-cf-' + this.model.id);
return this;
},
this.remove();
},
- setCustomFieldsForm: function(){
- var formData = {
- 'action': 'glm_members_admin_ajax',
- 'glm_action': 'customFieldsFront',
- 'option': 'displayForm',
- 'fid': 'glm_reg_customfields_reg_event_attendee_' + this.model.get('reg_event'),
- 'recordId': '1',
- 'parentFormId': 'abc-123',
- 'formData': false
- };
- $.ajax({
- type: 'POST',
- url: ajaxUrl,
- data: formData,
- encode: true,
- dataType: 'text'
- })
- .done( function( formHtml ) {
- $('.attendee-cf').html( formHtml );
- });
- },
});
// js/views/front/regTime.js
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, 'change', this.render );
return this;
},
zip: zip,
country: country,
});
- // console.log( newRegistrant );
+ // Now we have a new registrant let's save the custom field data.
+ var formData = jQuery( '#attendees-cf-form-new' ).serialize();
+ console.log( 'output form data' );
+ console.log( formData );
+ // app.saveCustomFieldsForm(
+ // jQuery('.attendee-cf-form').serialize()
+ // );
}
- // return false;
- // this.newRegAccount.destroy();
+ this.newRegAccount.destroy();
this.newRegAccountView.remove();
app.regEventLock = false;
},
// cancel add new registrant
cancelAddNew: function(){
this.$('.glm-add-new-account').show();
- // this.newRegAccount.destroy();
+ this.newRegAccount.destroy();
this.newRegAccountView.remove();
app.regEventLock = false;
},
render: function(){
this.$el.html( this.template( this.model.toJSON() ) );
// console.log( this.model.get('reg_event') );
- this.setCustomFieldsForm();
+ app.setCustomFieldsForm(this.model.get('reg_event'), '.attendee-cf-new');
return this;
},
- setCustomFieldsForm: function(){
- var formData = {
- 'action': 'glm_members_admin_ajax',
- 'glm_action': 'customFieldsFront',
- 'option': 'displayForm',
- 'fid': 'glm_reg_customfields_reg_event_attendee_' + this.model.get('reg_event'),
- 'recordId': '1',
- 'parentFormId': 'abc-123',
- 'formData': false
- };
- $.ajax({
- type: 'POST',
- url: ajaxUrl,
- data: formData,
- encode: true,
- dataType: 'text'
- })
- .done( function( formHtml ) {
- $('.attendee-cf').html( formHtml );
- });
- },
-
// verify the email address
verifyEmail: function(){
var email = this.$('.add_reg_email').val().trim();
initialize: function(){
// for setting up classes
- this.classes = new app.Collections.Front.RegClasses();
+ this.classes = new app.Collections.Front.RegClasses( [] );
},
// setClasses
// To setup the classes collection
setClasses: function( regClasses ){
+ console.log( regClasses );
this.classes.reset( regClasses );
},
// Using the registrants reg_time lookup the regTime
// var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time});
var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time });
- // console.log( foundRegTime );
+ console.log( 'find reg time' );
+ console.log( foundRegTime );
if ( foundRegTime ) {
// Set the reg_event for this reg_time to the class we found for registrant
foundRegTime.reg_event = foundClass.get('reg_event');
}
// Add the registrant to the regTime.
var nRegTime = foundClass.regTimes.findWhere({id: hasRegTime.get('id')});
- nRegTime.registrants.create( registrants[i] );
+ console.log( 'nRegTime' );
+ console.log(nRegTime);
+ nRegTime.registrants.add( registrants[i] );
}
}
// Add times into regTimes collection
var classTimes = this.model.get('times');
+ var timeArs = [];
for ( var key in classTimes ) {
var newTime = new app.Models.Front.RegTime( classTimes[key] );
newTime.set({reg_event: this.model.get('reg_event'), parent: this.model});
- this.model.regTimes.create( newTime );
+ timeArs.push( newTime );
+ // this.model.regTimes.create( newTime );
}
+ this.model.regTimes.reset( timeArs );
// console.log( classTimes );
// this.model.set({ reg_count: this.model.registrants.length });
this.$el.html( this.template( this.model.toJSON() ) );
// Go through the RegTimes Collection and render those
- // var view = this.model.
- // this.model.regTimes.sort();
// var classId = this.model.id;
- var view = this.model.regTimes.map(function(item){
- // item.parent = classId;
- return (new app.Views.Front.RegTime({ model: item })).render().el;
- });
var timeContainer = this.$('.reg-class-times');
- timeContainer.append( view );
if ( loginAccount === '' ) {
this.$('.glm-add-account').hide();
}
if ( !app.timeSpecific ) {
// this.$('.glm-add-new-account').show();
- this.updateTimeSelection();
+ // this.updateTimeSelection();
+ console.log( this.model.regTimes );
+
} else {
var sTime = this.model.get( 'selectedTime' );
if ( !sTime ) {
this.$('.glm-add-new-account').show();
}
}
- this.onRenderComplete();
+ var view = this.model.regTimes.map(function(item){
+ return (new app.Views.Front.RegTime({ model: item })).render().el;
+ });
+ timeContainer.append( view );
return this;
},
this.$el.html( this.template( this.model.toJSON() ) );
this.$emailInput = this.$('.editEmail');
this.$('.reg-edit-form').hide();
- this.setCustomFieldsForm();
+ app.setCustomFieldsForm(this.model.get('reg_event'), '.attendee-cf-' + this.model.id);
return this;
},
this.remove();
},
- setCustomFieldsForm: function(){
- var formData = {
- 'action': 'glm_members_admin_ajax',
- 'glm_action': 'customFieldsFront',
- 'option': 'displayForm',
- 'fid': 'glm_reg_customfields_reg_event_attendee_' + this.model.get('reg_event'),
- 'recordId': '1',
- 'parentFormId': 'abc-123',
- 'formData': false
- };
- $.ajax({
- type: 'POST',
- url: ajaxUrl,
- data: formData,
- encode: true,
- dataType: 'text'
- })
- .done( function( formHtml ) {
- $('.attendee-cf').html( formHtml );
- });
- },
});
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, 'change', this.render );
return this;
},
zip: zip,
country: country,
});
- // console.log( newRegistrant );
+ // Now we have a new registrant let's save the custom field data.
+ var formData = jQuery( '#attendees-cf-form-new' ).serialize();
+ console.log( 'output form data' );
+ console.log( formData );
+ // app.saveCustomFieldsForm(
+ // jQuery('.attendee-cf-form').serialize()
+ // );
}
- // return false;
- // this.newRegAccount.destroy();
+ this.newRegAccount.destroy();
this.newRegAccountView.remove();
app.regEventLock = false;
},
// cancel add new registrant
cancelAddNew: function(){
this.$('.glm-add-new-account').show();
- // this.newRegAccount.destroy();
+ this.newRegAccount.destroy();
this.newRegAccountView.remove();
app.regEventLock = false;
},
render: function(){
this.$el.html( this.template( this.model.toJSON() ) );
// console.log( this.model.get('reg_event') );
- this.setCustomFieldsForm();
+ app.setCustomFieldsForm(this.model.get('reg_event'), '.attendee-cf-new');
return this;
},
- setCustomFieldsForm: function(){
- var formData = {
- 'action': 'glm_members_admin_ajax',
- 'glm_action': 'customFieldsFront',
- 'option': 'displayForm',
- 'fid': 'glm_reg_customfields_reg_event_attendee_' + this.model.get('reg_event'),
- 'recordId': '1',
- 'parentFormId': 'abc-123',
- 'formData': false
- };
- $.ajax({
- type: 'POST',
- url: ajaxUrl,
- data: formData,
- encode: true,
- dataType: 'text'
- })
- .done( function( formHtml ) {
- $('.attendee-cf').html( formHtml );
- });
- },
-
// verify the email address
verifyEmail: function(){
var email = this.$('.add_reg_email').val().trim();
<div class="columns large-4 small-12">Email Address</div>
<div class="columns large-8 small-12"><input class="add_reg_email" value="<%- email %>"></div>
</div>
- <form class="attendee-cf-form"><div class="attendee-cf"></div></form>
+ <form id="attendee-cf-form-new"><div class="attendee-cf-new"></div></form>
<div>
<a class="show-hide-address">Address (show/hide)</a>
</div>
Models: { Front: {}, Admin: {} },
Collections: { Front: {}, Admin: {} },
Views: { Front: {}, Admin: {} },
-
- //Times: {$regTimesJSON},
-
isValidEmail: function( email ){
var regex = {literal}/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;{/literal}
return regex.test(email);
return false;
}
},
+ setCustomFieldsForm: function(reg_event_id, target){
+ var formData = {
+ 'action': 'glm_members_admin_ajax',
+ 'glm_action': 'customFieldsFront',
+ 'option': 'displayForm',
+ 'fid': 'glm_reg_customfields_reg_event_attendee_' + reg_event_id,
+ 'recordId': '1',
+ 'parentFormId': 'abc-123',
+ 'formData': false
+ };
+ $.ajax({
+ type: 'POST',
+ url: ajaxUrl,
+ data: formData,
+ encode: true,
+ dataType: 'text'
+ })
+ .done( function( formHtml ) {
+ $(target).html( formHtml );
+ });
+ },
+ saveCustomFieldsForm: function( formData, reg_event_id ){
+ console.log( 'SAVING FORW DATA' );
+ console.log( formData );
+ console.log( reg_event_id );
+ },
{if $regEvent.time_specific.value}
timeSpecific: true,
{else}