Adding another regClass to dummy array for output testing
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 1 Sep 2017 20:56:57 +0000 (16:56 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 1 Sep 2017 20:56:57 +0000 (16:56 -0400)
Now I have more than one regClass outputting.

data/event_setup.php
js/models/regClass.js
js/regApp.js
js/views/regClass.js
views/front/registrations/registration.html

index 5f99189..7321015 100644 (file)
@@ -67,45 +67,45 @@ $regEventSample = array(
             'reg_rate_name'         => 'Early Bird',
             'reg_rate_base_price'   => 100.00,
             'reg_rate_per_reg'      => 10.00,
-            'reg_rate'  => array
-            (
-                1 => array
-                (
-                    'id'                    => 1300,
-                    'reg_event'             => 1000,
-                    'reg_class'             => 1200,
-                    'name'                  => 'Early Bird',
-                    'start_days'            => 60,
-                    'end_days'              => 31,
-                    'base_rate'             => 100.00,
-                    'per_registrant'        => 10.00,
-                    'registrant_credits'    => 1
-                ),
-                2 => array
-                (
-                    'id'                    => 1301,
-                    'reg_event'             => 1000,
-                    'reg_class'             => 1200,
-                    'name'                  => 'Standard Registration',
-                    'start_days'            => 30,
-                    'end_days'              => 11,
-                    'base_rate'             => 120.00,
-                    'per_registrant'        => 12.00,
-                    'registrant_credits'    => 1
-                ),
-                3 => array
-                (
-                    'id'                    => 1302,
-                    'reg_event'             => 1000,
-                    'reg_class'             => 1200,
-                    'name'                  => 'Last Chance',
-                    'start_days'            => 10,
-                    'end_days'              => 2,           // no registration after 2 days before event
-                    'base_rate'             => 160.00,
-                    'per_registrant'        => 16.00,
-                    'registrant_credits'    => 1
-                ),
-            )
+            // 'reg_rate'  => array
+            // (
+            //     1 => array
+            //     (
+            //         'id'                    => 1300,
+            //         'reg_event'             => 1000,
+            //         'reg_class'             => 1200,
+            //         'name'                  => 'Early Bird',
+            //         'start_days'            => 60,
+            //         'end_days'              => 31,
+            //         'base_rate'             => 100.00,
+            //         'per_registrant'        => 10.00,
+            //         'registrant_credits'    => 1
+            //     ),
+            //     2 => array
+            //     (
+            //         'id'                    => 1301,
+            //         'reg_event'             => 1000,
+            //         'reg_class'             => 1200,
+            //         'name'                  => 'Standard Registration',
+            //         'start_days'            => 30,
+            //         'end_days'              => 11,
+            //         'base_rate'             => 120.00,
+            //         'per_registrant'        => 12.00,
+            //         'registrant_credits'    => 1
+            //     ),
+            //     3 => array
+            //     (
+            //         'id'                    => 1302,
+            //         'reg_event'             => 1000,
+            //         'reg_class'             => 1200,
+            //         'name'                  => 'Last Chance',
+            //         'start_days'            => 10,
+            //         'end_days'              => 2,           // no registration after 2 days before event
+            //         'base_rate'             => 160.00,
+            //         'per_registrant'        => 16.00,
+            //         'registrant_credits'    => 1
+            //     ),
+            // )
         ),
 
         2 => array(
@@ -116,45 +116,45 @@ $regEventSample = array(
             'reg_rate_name'         => 'Early Bird',
             'reg_rate_base_price'   => 100.00,
             'reg_rate_per_reg'      => 10.00,
-            'reg_rate'  => array
-            (
-                1 => array
-                (
-                    'id'                    => 1300,
-                    'reg_event'             => 1000,
-                    'reg_class'             => 1200,
-                    'name'                  => 'Early Bird',
-                    'start_days'            => 60,
-                    'end_days'              => 31,
-                    'base_rate'             => 100.00,
-                    'per_registrant'        => 10.00,
-                    'registrant_credits'    => 1
-                ),
-                2 => array
-                (
-                    'id'                    => 1301,
-                    'reg_event'             => 1000,
-                    'reg_class'             => 1200,
-                    'name'                  => 'Standard Registration',
-                    'start_days'            => 30,
-                    'end_days'              => 11,
-                    'base_rate'             => 120.00,
-                    'per_registrant'        => 12.00,
-                    'registrant_credits'    => 1
-                ),
-                3 => array
-                (
-                    'id'                    => 1302,
-                    'reg_event'             => 1000,
-                    'reg_class'             => 1200,
-                    'name'                  => 'Last Chance',
-                    'start_days'            => 10,
-                    'end_days'              => 2,           // no registration after 2 days before event
-                    'base_rate'             => 160.00,
-                    'per_registrant'        => 16.00,
-                    'registrant_credits'    => 1
-                ),
-            )
+            // 'reg_rate'  => array
+            // (
+            //     1 => array
+            //     (
+            //         'id'                    => 1300,
+            //         'reg_event'             => 1000,
+            //         'reg_class'             => 1200,
+            //         'name'                  => 'Early Bird',
+            //         'start_days'            => 60,
+            //         'end_days'              => 31,
+            //         'base_rate'             => 100.00,
+            //         'per_registrant'        => 10.00,
+            //         'registrant_credits'    => 1
+            //     ),
+            //     2 => array
+            //     (
+            //         'id'                    => 1301,
+            //         'reg_event'             => 1000,
+            //         'reg_class'             => 1200,
+            //         'name'                  => 'Standard Registration',
+            //         'start_days'            => 30,
+            //         'end_days'              => 11,
+            //         'base_rate'             => 120.00,
+            //         'per_registrant'        => 12.00,
+            //         'registrant_credits'    => 1
+            //     ),
+            //     3 => array
+            //     (
+            //         'id'                    => 1302,
+            //         'reg_event'             => 1000,
+            //         'reg_class'             => 1200,
+            //         'name'                  => 'Last Chance',
+            //         'start_days'            => 10,
+            //         'end_days'              => 2,           // no registration after 2 days before event
+            //         'base_rate'             => 160.00,
+            //         'per_registrant'        => 16.00,
+            //         'registrant_credits'    => 1
+            //     ),
+            // )
         ),
 
         // reg_rates - Date range / rate for a reg class (one or more)
index 6de34a6..b5fceba 100644 (file)
@@ -11,12 +11,12 @@ app.Models.RegClass = Backbone.Model.extend({
         reg_rate_name: '',
         reg_rate_base_price: '',
         reg_rate_per_reg: '',
+        reg_count: 0,
     },
 
     initialize: function(){
         this.accounts = new app.Collections.Accounts;
-        this.accounts.fetch();
+        //this.accounts.fetch();
     },
 
-
 });
index fe88720..3fd3f5b 100644 (file)
@@ -1 +1 @@
-app.Models.Account=Backbone.Model.extend({defaults:{id:"",email:"",parent:""},initialize:function(){this.on("invalid",function(e,t){console.log(t)})},validate:function(e,t){if(void 0===e.email||""===e.email)return"Need an email address!"}}),app.Models.AccountDetail=app.Models.Account.extend({defaults:{id:"",fname:"",lname:"",org:"",title:"",addr1:"",addr2:"",city:"",state:"",zip:"",country:"",phone:"",fax:"",email_ok:!1,is_member:!1,date_created:"",email:"",parent:""}}),app.Models.Login=Backbone.Model.extend({defaults:{username:"",password:""},urlRoot:appLoginUrl,initialize:function(){this.on("invalid",function(e,t){console.log(t)})},validate:function(e,t){return void 0===e.username||""===e.username?"Username required!":void 0===e.password||""===e.password?"Password required!":void 0}}),app.Models.RegClass=Backbone.Model.extend({defaults:{reg_event:0,name:"",descr:"",reg_rate_name:"",reg_rate_base_price:"",reg_rate_per_reg:""},initialize:function(){this.accounts=new app.Collections.Accounts,this.accounts.fetch()}}),app.Models.RegEvent=Backbone.Model.extend({defaults:{name:"regEvent",event_name:"",event_code:"",notify_email:"",attendees_max:0,attendees_max_per_reg:0,reg_hold_minutes:0,cart_hold_days:0,terms:""},initialize:function(){this.classes=new app.Collections.RegClasses},setClasses:function(e){this.classes.reset(e)}}),app.Models.regRate=Backbone.Model.extend({defaults:{reg_event:0,reg_class:"",name:"",start_days:0,end_days:0,base_rate:0,per_registrant:0,registrant_credits:0},initialize:function(){}}),app.Collections.Accounts=Backbone.Collection.extend({model:app.Models.Account,localStorage:new Backbone.LocalStorage("Accounts"),sync:function(e,t,i){console.log("sync called on collection. method: "+e)}}),app.Collections.RegClasses=Backbone.Collection.extend({model:app.Models.RegClass}),app.Collections.RegRates=Backbone.Collection.extend({model:app.Models.RegRate}),app.Views.Account=Backbone.View.extend({tagName:"div",className:"glm-reg-level-registrant clearfix",template:_.template($("#account-template").html()),events:{"click label":"edit","click .glm-reg-level-registrant-delete":"deleteOne","click .saveRegistrant":"close"},initialize:function(){return this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"destroy",this.remove),this},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.$nameInput=this.$(".editName"),this.$emailInput=this.$(".editEmail"),this},deleteOne:function(){this.model.destroy()},edit:function(){this.$el.addClass("editing"),this.$nameInput.focus()},close:function(){var e=this.$nameInput.val().trim(),t=this.$emailInput.val().trim();e&&t?this.model.save({name:e,email:t}):this.clear(),this.$el.removeClass("editing")}}),Backbone.emulateJSON=!0,Backbone.emulateHTTP=!0,app.Views.App=Backbone.View.extend({el:"#regApp",initialize:function(){this.event=new app.Views.RegEvent({model:app.Models.regEvent}),this.render()},render:function(){return this.$el.append(this.event.render().el),this},events:{"click #appLogin":"login"},login:function(){this.loginView=new app.Views.Login({model:new app.Models.Login}),this.$el.append(this.loginView.render().el),$("#appLogin").hide()}}),app.Views.Login=Backbone.View.extend({tagName:"div",className:"glm-reg-login",template:_.template($("#eventReg-account-login").html()),events:{"click .accountLogin":"loginToAccount","click #loginCancel":"closeLoginForm"},initialize:function(){return this},closeLoginForm:function(){this.remove(),$("#appLogin").show()},loginToAccount:function(){$.ajax({url:ajaxUrl})},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.$userInput=this.$(".login"),this.$pwdInput=this.$(".password"),this}}),app.Views.RegClass=Backbone.View.extend({tagName:"div",className:"glm-reg-level",template:_.template($("#regClass-template").html()),initialize:function(){return this.listenTo(this.model.accounts,"add",this.addOne),this.listenTo(this.model.accounts,"create",this.addOne),this.listenTo(this.model.accounts,"reset",this.addAll),this},events:{"click .addRegistrant":"newEntry"},newEntry:function(){this.$newEmail=this.$(".addEmail"),this.$newEmail.val().trim()&&$.ajax({context:this,url:ajaxUrl+"&glm_action=account&option=checkEmail",dataType:"json",data:"email="+this.$newEmail.val().trim()}).done(function(e){!0!==e.validEmail?alert("Must be a valid email address!"):!0!==e.valid?alert("No account matched that email address!"):void 0!==e.id&&void 0!==e.email&&(this.model.accounts.create({id:e.id,email:e.email}),this.$newEmail.val(""))}).fail(function(e){console.log("Fail: "+e)})},render:function(){return this.$el.html(this.template(this.model.toJSON())),this},addOne:function(e){if(e.isValid()){var t=new app.Views.Account({model:e});this.$el.append(t.render().el)}},addAll:function(){this.$(".glm-reg-level").html("")}}),app.Views.RegEvent=Backbone.View.extend({tagName:"div",className:"glm-reg-event-item clearfix",template:_.template($("#regEvent-template").html()),initialize:function(){this.listenTo(this.model,"change",this.render)},render:function(){this.$el.html(this.template(this.model.toJSON()));var e=app.Models.regEvent.classes.map(function(e){return new app.Views.RegClass({model:e}).render().el});return this.$el.append(e),this}});
\ No newline at end of file
+app.Models.Account=Backbone.Model.extend({defaults:{id:"",email:"",parent:""},initialize:function(){this.on("invalid",function(e,t){console.log(t)})},validate:function(e,t){if(void 0===e.email||""===e.email)return"Need an email address!"}}),app.Models.AccountDetail=app.Models.Account.extend({defaults:{id:"",fname:"",lname:"",org:"",title:"",addr1:"",addr2:"",city:"",state:"",zip:"",country:"",phone:"",fax:"",email_ok:!1,is_member:!1,date_created:"",email:"",parent:""}}),app.Models.Login=Backbone.Model.extend({defaults:{username:"",password:""},urlRoot:appLoginUrl,initialize:function(){this.on("invalid",function(e,t){console.log(t)})},validate:function(e,t){return void 0===e.username||""===e.username?"Username required!":void 0===e.password||""===e.password?"Password required!":void 0}}),app.Models.RegClass=Backbone.Model.extend({defaults:{reg_event:0,name:"",descr:"",reg_rate_name:"",reg_rate_base_price:"",reg_rate_per_reg:"",reg_count:0},initialize:function(){this.accounts=new app.Collections.Accounts}}),app.Models.RegEvent=Backbone.Model.extend({defaults:{name:"regEvent",event_name:"",event_code:"",notify_email:"",attendees_max:0,attendees_max_per_reg:0,reg_hold_minutes:0,cart_hold_days:0,terms:""},initialize:function(){this.classes=new app.Collections.RegClasses},setClasses:function(e){this.classes.reset(e)}}),app.Models.regRate=Backbone.Model.extend({defaults:{reg_event:0,reg_class:"",name:"",start_days:0,end_days:0,base_rate:0,per_registrant:0,registrant_credits:0},initialize:function(){}}),app.Collections.Accounts=Backbone.Collection.extend({model:app.Models.Account,localStorage:new Backbone.LocalStorage("Accounts"),sync:function(e,t,i){console.log("sync called on collection. method: "+e)}}),app.Collections.RegClasses=Backbone.Collection.extend({model:app.Models.RegClass}),app.Collections.RegRates=Backbone.Collection.extend({model:app.Models.RegRate}),app.Views.Account=Backbone.View.extend({tagName:"div",className:"glm-reg-level-registrant clearfix",template:_.template($("#account-template").html()),events:{"click label":"edit","click .glm-reg-level-registrant-delete":"deleteOne","click .saveRegistrant":"close"},initialize:function(){return this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"destroy",this.remove),this},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.$nameInput=this.$(".editName"),this.$emailInput=this.$(".editEmail"),this},deleteOne:function(){this.model.destroy()},edit:function(){this.$el.addClass("editing"),this.$nameInput.focus()},close:function(){var e=this.$nameInput.val().trim(),t=this.$emailInput.val().trim();e&&t?this.model.save({name:e,email:t}):this.clear(),this.$el.removeClass("editing")}}),Backbone.emulateJSON=!0,Backbone.emulateHTTP=!0,app.Views.App=Backbone.View.extend({el:"#regApp",initialize:function(){this.event=new app.Views.RegEvent({model:app.Models.regEvent}),this.render()},render:function(){return this.$el.append(this.event.render().el),this},events:{"click #appLogin":"login"},login:function(){this.loginView=new app.Views.Login({model:new app.Models.Login}),this.$el.append(this.loginView.render().el),$("#appLogin").hide()}}),app.Views.Login=Backbone.View.extend({tagName:"div",className:"glm-reg-login",template:_.template($("#eventReg-account-login").html()),events:{"click .accountLogin":"loginToAccount","click #loginCancel":"closeLoginForm"},initialize:function(){return this},closeLoginForm:function(){this.remove(),$("#appLogin").show()},loginToAccount:function(){$.ajax({url:ajaxUrl})},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.$userInput=this.$(".login"),this.$pwdInput=this.$(".password"),this}}),app.Views.RegClass=Backbone.View.extend({tagName:"div",className:"glm-reg-level",template:_.template($("#regClass-template").html()),initialize:function(){return this.listenTo(this.model.accounts,"add",this.addOne),this.listenTo(this.model.accounts,"create",this.addOne),this.listenTo(this.model.accounts,"reset",this.addAll),this.listenTo(this.model,"change",this.updateCount),this},events:{"click .addRegistrant":"newEntry"},newEntry:function(){this.$newEmail=this.$(".addEmail"),this.$newEmail.val().trim()&&$.ajax({context:this,url:ajaxUrl+"&glm_action=account&option=checkEmail",dataType:"json",data:"email="+this.$newEmail.val().trim()}).done(function(e){!0!==e.validEmail?alert("Must be a valid email address!"):!0!==e.valid?alert("No account matched that email address!"):void 0!==e.id&&void 0!==e.email&&(this.model.accounts.create({id:e.id,email:e.email,parent:this.model.id}),this.model.trigger("change"),this.$newEmail.val(""))}).fail(function(e){console.log("Fail: "+e)})},render:function(){return this.$el.html(this.template(this.model.toJSON())),this},updateCount:function(){return this.model.reg_count=this.model.accounts.length,console.log("Updating Count: "+this.model.reg_count),this.render,this},addOne:function(e){if(e.isValid()){var t=new app.Views.Account({model:e});this.$el.append(t.render().el)}},addAll:function(){this.$(".glm-reg-level").html("")}}),app.Views.RegEvent=Backbone.View.extend({tagName:"div",className:"glm-reg-event-item clearfix",template:_.template($("#regEvent-template").html()),initialize:function(){this.listenTo(this.model,"change",this.render)},render:function(){this.$el.html(this.template(this.model.toJSON()));var e=app.Models.regEvent.classes.map(function(e){return new app.Views.RegClass({model:e}).render().el});return this.$el.append(e),this}});
\ No newline at end of file
index 8bc88e1..e86bda0 100644 (file)
@@ -11,6 +11,8 @@ app.Views.RegClass = Backbone.View.extend({
         this.listenTo( this.model.accounts, 'add', this.addOne );
         this.listenTo( this.model.accounts, 'create', this.addOne );
         this.listenTo( this.model.accounts, 'reset', this.addAll );
+        this.listenTo( this.model, 'change', this.updateCount );
+        //this.listenTo( this.model, 'change:accounts', this.render );
 
         //this.model.accounts.fetch();
         return this;
@@ -45,8 +47,10 @@ app.Views.RegClass = Backbone.View.extend({
             } else if ( account.id !== undefined && account.email !== undefined ) {
                 this.model.accounts.create({
                     id: account.id,
-                    email: account.email
+                    email: account.email,
+                    parent: this.model.id
                 });
+                this.model.trigger('change');
                 this.$newEmail.val('');
             }
         })
@@ -60,6 +64,13 @@ app.Views.RegClass = Backbone.View.extend({
         return this;
     },
 
+    updateCount: function(){
+        this.model.reg_count = this.model.accounts.length;
+        console.log( 'Updating Count: ' + this.model.reg_count );
+        this.render;
+        return this;
+    },
+
     addOne: function( item ){
         if ( item.isValid() ) {
             var view = new app.Views.Account({ model: item });
index 9fa0866..372d2af 100644 (file)
@@ -33,7 +33,7 @@
     </div>
 </script>
 <script type="text/template" id="regClass-template">
-    <h3><%= name %></h3>
+    <h3><%= name %> Count: <%= reg_count %></h3>
     <p><%= descr %></p>
     <div>
         <div>Current Rate: <%= reg_rate_name %></div>