WIP Working on moving some stuff from regClass into the regTime view.
Will need to fix the creation of registrants and make sure the data it
is sending back to ajax calls is correct.
/*}}} End Errors */
+.glm-add-new-account {
+ font-size: 1rem;
+}
+
#glm-reg-widget {
display: inline-block;
}
--- /dev/null
+// js/collections/regTimes.js
+
+// reg time collection
+app.Collections.Front.RegTimes = Backbone.Collection.extend({
+ model: app.Models.Front.RegTime,
+
+ url: ajaxUrl+'&glm_action=regFront&collection=regTime=',
+});
initialize: function(){
this.registrants = new app.Collections.Front.RegRequestRegistrants( [] );
+ this.regTimes = new app.Collections.Front.RegTimes( [] );
},
- setRegistrants: function( registrants ) {
- this.registrants.reset( registrants );
- },
+ // setRegistrants: function( registrants ) {
+ // this.registrants.reset( registrants );
+ // },
// Check to see if the current login user in the list of registrants
hasMe: function() {
setClassRegistrants: function( registrants ){
for ( var i = 0; i < registrants.length; i++ ) {
var foundClass = this.classes.findWhere({ id: registrants[i].class_id });
+ console.log( foundClass );
if ( foundClass != undefined ) {
foundClass.registrants.create( registrants[i] );
var newReg = foundClass.registrants.pop();
});
+// js/models/front/regTime.js
+// Event Reg Time Model
+app.Models.Front.RegTime = Backbone.Model.extend({
+
+ // Default regTime values
+ defaults: {
+ id: 0,
+ reg_event: 0,
+ event_time: 0,
+ start_datetime: '',
+ end_datetime: '',
+ all_day: false,
+ attendees: false,
+ attendee_max: 0,
+ attendee_count: 0,
+ attendees_pending: 0,
+ attendees_available: 0,
+ descr: '',
+ parent: null,
+ },
+
+ initialize: function(){
+ // Initial setting for model
+ this.registrants = new app.Collections.Front.RegRequestRegistrants( [] );
+ },
+});
+
app.Models.Front.Request = Backbone.Model.extend({
defaults: {
name: 'request',
});
+// js/collections/regTimes.js
+
+// reg time collection
+app.Collections.Front.RegTimes = Backbone.Collection.extend({
+ model: app.Models.Front.RegTime,
+
+ url: ajaxUrl+'&glm_action=regFront&collection=regTime=',
+});
+
// js/views/account.js
// Event Registrant View
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;
},
events: {
'click .addRegistrant': 'newEntry',
- 'click .glm-add-account': 'addAccount',
- 'click .glm-add-new-account': 'addNewAccount',
- 'click .add-new-registrant': 'addNew',
- 'click .add-new-registrant-cancel': 'cancelAddNew',
+ // 'click .glm-add-account': 'addAccount',
+ // 'click .glm-add-new-account': 'addNewAccount',
+ // 'click .add-new-registrant': 'addNew',
+ // 'click .add-new-registrant-cancel': 'cancelAddNew',
'click .timeSelection': 'updateTimeSelection',
},
- updateTimeSelection: function(){
- // Need to remove the newRegModal and views
- if ( this.newRegAccount ) {
- this.newRegAccount.destroy();
- this.newRegAccountView.remove();
+ updateTimeSelection: function(e){
+ // console.log(e);
+ // if ( this.newRegAccount ) {
+ // this.newRegAccount.destroy();
+ // this.newRegAccountView.remove();
+ // }
+ // Check to see if the time is already in the collection
+ // If it is then do nothing
+ var findRegTime = this.model.regTimes.get( e.currentTarget.value );
+ if ( !findRegTime ) {
+ this.model.set({ selectedTime: parseInt( e.currentTarget.value ) });
+ // Add the RegTime model/view into this view
+ var foundRegTime = app.times.get( e.currentTarget.value );
+ foundRegTime.set({parent: this.model});
+ this.model.regTimes.create( foundRegTime );
}
- this.model.set({ selectedTime: parseInt( this.$('.timeSelection:checked').val() ) });
- console.log( this.$('.timeSelection:checked').val());
},
render: function(){
this.model.set({ reg_count: this.model.registrants.length });
this.$el.html( this.template( this.model.toJSON() ) );
- // Need to see if this class has attendees and render them
- var view = this.model.registrants.map(function(item){
- return (new app.Views.Front.RegRequestRegistrant({ model: item })).render().el;
+ // Go through the RegTimes Collection and render those
+ // var view = this.model.
+ var view = this.model.regTimes.map(function(item){
+ return (new app.Views.Front.RegTime({ model: item })).render().el;
});
- var accountContainer = this.$('.reg-class-accounts');
- accountContainer.append(view);
+ var timeContainer = this.$('.reg-class-times');
+ timeContainer.append( view );
+
+ // Need to see if this class has attendees and render them
+ // var view = this.model.registrants.map(function(item){
+ // return (new app.Views.Front.RegRequestRegistrant({ model: item })).render().el;
+ // });
+ // var accountContainer = this.$('.reg-class-accounts');
+ // accountContainer.append(view);
+
if ( app.timeSpecific ) {
// Need to require that the user select the time before entering attendees.
}
var times = this.model.get( 'times' );
var timeParts = [];
_.each( times, function(time){
- var testDate = new Date( time.start_datetime.datetime );
- timeParts.push( {id: time.id,date: testDate, name: time.name} );
+ var fDate = new Date( time.start_datetime.datetime );
+ var tDate = new Date( time.end_datetime.datetime );
+ timeParts.push( {
+ id: time.id,
+ fromDate: fDate,
+ toDate: tDate,
+ name: time.name
+ } );
});
// console.log( timeParts );
return timeParts;
},
cancelAddNew: function(){
+ this.$('.glm-add-new-account').show();
// this.newRegAccount.destroy();
this.newRegAccountView.remove();
// app.calendar = false;
},
addNewAccount: function(){
+ this.$('.glm-add-new-account').hide();
// Create the new Registrant View
if ( app.timeSpecific ) {
this.newRegAccount = new app.Models.Front.RegRequestRegistrant({ reg_time: this.model.get( 'selectedTime' ) });
});
+// js/views/regClass.js
+var newId = 0;
+app.Views.Front.RegTime = Backbone.View.extend({
+ tagName: 'div',
+
+ className: 'glm-row',
+
+ template: _.template( jQuery('#regTime-template').html() ),
+
+ initialize: function(){
+ return this;
+ },
+
+ events: {
+ 'click .glm-add-new-account': 'addNewAccount',
+ 'click .add-new-registrant': 'insertNew',
+ 'click .add-new-registrant-cancel': 'cancelAddNew',
+ },
+
+ render: function(){
+ this.model.set({ reg_count: this.model.registrants.length });
+ this.$el.html( this.template( this.model.toJSON() ) );
+ // Need to see if this has attendees and render them
+ var view = this.model.registrants.map(function(item){
+ return (new app.Views.Front.RegRequestRegistrant({ model: item })).render().el;
+ });
+ var accountContainer = this.$('.reg-class-accounts');
+ accountContainer.append(view);
+ return this;
+ },
+
+ addNewAccount: function(){
+ this.$('.glm-add-new-account').hide();
+ // Create the new Registrant View
+ if ( app.timeSpecific ) {
+ this.newRegAccount = new app.Models.Front.RegRequestRegistrant({ reg_time: this.model.get( 'selectedTime' ) });
+ } else {
+ this.newRegAccount = new app.Models.Front.RegRequestRegistrant();
+ }
+ this.newRegAccountView = new app.Views.Front.RegistrantForm({model: this.newRegAccount});
+ this.$el.append( this.newRegAccountView.render().el );
+ },
+
+ insertNew: 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 ( 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: this.model.get( 'id' ),
+ reg_event: this.model.get( 'reg_event' ), // Todo: use correct reg_event
+ reg_class: this.model.get( 'id' ), // Todo: use correct reg_class
+ 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;
+ },
+
+ cancelAddNew: function(){
+ this.$('.glm-add-new-account').show();
+ // this.newRegAccount.destroy();
+ this.newRegAccountView.remove();
+ // app.calendar = false;
+ if ( loginAccount != '' && this.model.hasMe() ) {
+ this.$('.glm-add-account').hide();
+ // console.log('hiding');
+ } else if ( loginAccount != '' ) {
+ this.$('.glm-add-account').show();
+ // console.log('showing');
+ }
+ },
+
+
+});
+
app.Views.Front.RegistrantForm = Backbone.View.extend({
tagName: 'div',
initialize: function(){
this.registrants = new app.Collections.Front.RegRequestRegistrants( [] );
+ this.regTimes = new app.Collections.Front.RegTimes( [] );
},
- setRegistrants: function( registrants ) {
- this.registrants.reset( registrants );
- },
+ // setRegistrants: function( registrants ) {
+ // this.registrants.reset( registrants );
+ // },
// Check to see if the current login user in the list of registrants
hasMe: function() {
setClassRegistrants: function( registrants ){
for ( var i = 0; i < registrants.length; i++ ) {
var foundClass = this.classes.findWhere({ id: registrants[i].class_id });
+ console.log( foundClass );
if ( foundClass != undefined ) {
foundClass.registrants.create( registrants[i] );
var newReg = foundClass.registrants.pop();
--- /dev/null
+// js/models/front/regTime.js
+// Event Reg Time Model
+app.Models.Front.RegTime = Backbone.Model.extend({
+
+ // Default regTime values
+ defaults: {
+ id: 0,
+ reg_event: 0,
+ event_time: 0,
+ start_datetime: '',
+ end_datetime: '',
+ all_day: false,
+ attendees: false,
+ attendee_max: 0,
+ attendee_count: 0,
+ attendees_pending: 0,
+ attendees_available: 0,
+ descr: '',
+ parent: null,
+ },
+
+ initialize: function(){
+ // Initial setting for model
+ this.registrants = new app.Collections.Front.RegRequestRegistrants( [] );
+ },
+});
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;
},
events: {
'click .addRegistrant': 'newEntry',
- 'click .glm-add-account': 'addAccount',
- 'click .glm-add-new-account': 'addNewAccount',
- 'click .add-new-registrant': 'addNew',
- 'click .add-new-registrant-cancel': 'cancelAddNew',
+ // 'click .glm-add-account': 'addAccount',
+ // 'click .glm-add-new-account': 'addNewAccount',
+ // 'click .add-new-registrant': 'addNew',
+ // 'click .add-new-registrant-cancel': 'cancelAddNew',
'click .timeSelection': 'updateTimeSelection',
},
- updateTimeSelection: function(){
- // Need to remove the newRegModal and views
- if ( this.newRegAccount ) {
- this.newRegAccount.destroy();
- this.newRegAccountView.remove();
+ updateTimeSelection: function(e){
+ // console.log(e);
+ // if ( this.newRegAccount ) {
+ // this.newRegAccount.destroy();
+ // this.newRegAccountView.remove();
+ // }
+ // Check to see if the time is already in the collection
+ // If it is then do nothing
+ var findRegTime = this.model.regTimes.get( e.currentTarget.value );
+ if ( !findRegTime ) {
+ this.model.set({ selectedTime: parseInt( e.currentTarget.value ) });
+ // Add the RegTime model/view into this view
+ var foundRegTime = app.times.get( e.currentTarget.value );
+ foundRegTime.set({parent: this.model});
+ this.model.regTimes.create( foundRegTime );
}
- this.model.set({ selectedTime: parseInt( this.$('.timeSelection:checked').val() ) });
- console.log( this.$('.timeSelection:checked').val());
},
render: function(){
this.model.set({ reg_count: this.model.registrants.length });
this.$el.html( this.template( this.model.toJSON() ) );
- // Need to see if this class has attendees and render them
- var view = this.model.registrants.map(function(item){
- return (new app.Views.Front.RegRequestRegistrant({ model: item })).render().el;
+ // Go through the RegTimes Collection and render those
+ // var view = this.model.
+ var view = this.model.regTimes.map(function(item){
+ return (new app.Views.Front.RegTime({ model: item })).render().el;
});
- var accountContainer = this.$('.reg-class-accounts');
- accountContainer.append(view);
+ var timeContainer = this.$('.reg-class-times');
+ timeContainer.append( view );
+
+ // Need to see if this class has attendees and render them
+ // var view = this.model.registrants.map(function(item){
+ // return (new app.Views.Front.RegRequestRegistrant({ model: item })).render().el;
+ // });
+ // var accountContainer = this.$('.reg-class-accounts');
+ // accountContainer.append(view);
+
if ( app.timeSpecific ) {
// Need to require that the user select the time before entering attendees.
}
var times = this.model.get( 'times' );
var timeParts = [];
_.each( times, function(time){
- var testDate = new Date( time.start_datetime.datetime );
- timeParts.push( {id: time.id,date: testDate, name: time.name} );
+ var fDate = new Date( time.start_datetime.datetime );
+ var tDate = new Date( time.end_datetime.datetime );
+ timeParts.push( {
+ id: time.id,
+ fromDate: fDate,
+ toDate: tDate,
+ name: time.name
+ } );
});
// console.log( timeParts );
return timeParts;
},
cancelAddNew: function(){
+ this.$('.glm-add-new-account').show();
// this.newRegAccount.destroy();
this.newRegAccountView.remove();
// app.calendar = false;
},
addNewAccount: function(){
+ this.$('.glm-add-new-account').hide();
// Create the new Registrant View
if ( app.timeSpecific ) {
this.newRegAccount = new app.Models.Front.RegRequestRegistrant({ reg_time: this.model.get( 'selectedTime' ) });
--- /dev/null
+// js/views/regClass.js
+var newId = 0;
+app.Views.Front.RegTime = Backbone.View.extend({
+ tagName: 'div',
+
+ className: 'glm-row',
+
+ template: _.template( jQuery('#regTime-template').html() ),
+
+ initialize: function(){
+ return this;
+ },
+
+ events: {
+ 'click .glm-add-new-account': 'addNewAccount',
+ 'click .add-new-registrant': 'insertNew',
+ 'click .add-new-registrant-cancel': 'cancelAddNew',
+ },
+
+ render: function(){
+ this.model.set({ reg_count: this.model.registrants.length });
+ this.$el.html( this.template( this.model.toJSON() ) );
+ // Need to see if this has attendees and render them
+ var view = this.model.registrants.map(function(item){
+ return (new app.Views.Front.RegRequestRegistrant({ model: item })).render().el;
+ });
+ var accountContainer = this.$('.reg-class-accounts');
+ accountContainer.append(view);
+ return this;
+ },
+
+ addNewAccount: function(){
+ this.$('.glm-add-new-account').hide();
+ // Create the new Registrant View
+ if ( app.timeSpecific ) {
+ this.newRegAccount = new app.Models.Front.RegRequestRegistrant({ reg_time: this.model.get( 'selectedTime' ) });
+ } else {
+ this.newRegAccount = new app.Models.Front.RegRequestRegistrant();
+ }
+ this.newRegAccountView = new app.Views.Front.RegistrantForm({model: this.newRegAccount});
+ this.$el.append( this.newRegAccountView.render().el );
+ },
+
+ insertNew: 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 ( 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: this.model.get( 'id' ),
+ reg_event: this.model.get( 'reg_event' ), // Todo: use correct reg_event
+ reg_class: this.model.get( 'id' ), // Todo: use correct reg_class
+ 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;
+ },
+
+ cancelAddNew: function(){
+ this.$('.glm-add-new-account').show();
+ // this.newRegAccount.destroy();
+ this.newRegAccountView.remove();
+ // app.calendar = false;
+ if ( loginAccount != '' && this.model.hasMe() ) {
+ this.$('.glm-add-account').hide();
+ // console.log('hiding');
+ } else if ( loginAccount != '' ) {
+ this.$('.glm-add-account').show();
+ // console.log('showing');
+ }
+ },
+
+
+});
$jsonClasses = array();
$regClasses = array();
+ $regTimes = array();
if ( isset( $regEvent['reg_class'] ) && is_array( $regEvent['reg_class'] ) ) {
// Loop through the $regEvent['reg_class'] array to build $rClass array
if ( $regEvent['time_specific'] ) {
$rClass['selectedTime'] = $time['id'];
}
+ if ( empty( $regtimes ) ) {
+ $regTimes[] = json_encode( $time, JSON_NUMERIC_CHECK );
+ }
}
$jsonClasses[] = json_encode( $rClass, JSON_NUMERIC_CHECK );
} else if ( !isset( $rClass['times'] ) || empty( $rClass['times'] ) ) {
// Build the regClass JSON for the template.
$regClassJSON = '[' . implode( ',', $jsonClasses ) . ']';
- $regCartJSON = json_encode( $cart );
+ $regCartJSON = json_encode( $cart );
+ $regTimesJSON = '[' . implode( ',', $regTimes ) . ']';
+ // echo '<pre>$regTimes: ' . print_r( $regTimesJSON, true ) . '</pre>';
// Get terms into JSON
$termsJSON = json_encode( $this->config['terms'] );
'thisJsUrl' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js',
'regEventJSON' => json_encode( $event, JSON_NUMERIC_CHECK ),
'regClassesJSON' => $regClassJSON,
+ 'regTimesJSON' => $regTimesJSON,
'regCartJSON' => $regCartJSON,
'regRequestJSON' => $regRequestJSON,
'loginAccount' => $loginAccount,
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-jshint": "^2.0.4",
+ "gulp-notify": "^3.0.0",
"gulp-plumber": "^1.1.0",
"gulp-sourcemaps": "^2.6.1",
"gulp-uglify": "^3.0.0",
<% _.each( this.getTimeArray(), function(time){ %>
<% if ( curSchedule != time.name ) { %>
<div>
- <%= time.name %>
- <%= time.date.toLocaleDateString('en-US') %>
+ <%= time.fromDate.toLocaleDateString('en-US') %>
</div>
<% } %>
<% curSchedule = time.name; %>
<label class="reg-time">
- <input class="timeSelection" type="radio" name="timeOption" value="<%= time.id %>"
- <% if ( selectedTime == time.id ) { %>
- checked
- <% } %>
- /> <%= time.date.toLocaleTimeString('en-US', {hour: '2-digit', minute: '2-digit'}) %>
+ <button class="tiny timeSelection" value="<%= time.id %>">
+ <%= time.fromDate.toLocaleTimeString('en-US', {hour: '2-digit', minute: '2-digit'}) %>
+ -
+ <%= time.toDate.toLocaleTimeString('en-US', {hour: '2-digit', minute: '2-digit'}) %>
+ </button>
</label>
<% }); %>
<% } else { %>
<% if ( loggedIn ) { %>
<button class="glm-add-account tiny">Add Me</button>
<% } %>
- <button class="glm-add-new-account tiny">Add {/literal}{$terms.reg_term_attendee_cap}{literal}</button>
- <div class="reg-class-accounts">
- {/literal}{$terms.reg_term_attendee_plur_cap}{literal}
+ <div class="reg-class-times">
</div>
</div>
</div>
</div>
</script>
{/literal}
+{* Template for regTime *}{literal}
+<script type="text/template" id="regTime-template">
+ <b><%= start_datetime.datetime %></b>
+ <div class="reg-class-accounts">
+ {/literal}{$terms.reg_term_attendee_plur_cap}{literal}
+ <span class="glm-add-new-account dashicons dashicons-plus"></span>
+ </div>
+</script>
+{/literal}
{* Template for registrant add form *}{literal}
<script type="text/template" id="eventReg-registrant-add">
{/literal}{if $regEvent.time_specific.value}
<div class="glm-columns glm-large-8 glm-small-12"><input class="add_reg_country" value="<%- country %>"></div>
</div>
{/literal}{if $regEvent.time_specific.value}
- Selected Time: <span id="add_reg-select-time-display"></span>
+ <!-- Selected Time: <span id="add_reg-select-time-display"></span> -->
<input type="hidden" id="add_reg-select-time">
{/if}{literal}
</div>
regEvent.setClasses( {$regClassesJSON} );
regEvent.setClassRegistrants( {$regJSON} );
var glmApp = new app.Views.Front.App();
+ app.times = new app.Collections.Front.RegTimes( {$regTimesJSON} );
});
</script>