url: ajaxUrl+'&glm_action=regFront&collection=account',
- // sync: function( method, model ){
- // console.log( 'sync in model' );
- // // console.log( method );
- // // console.log( model );
- // switch ( method ) {
- // case 'delete':
- // console.log( 'Delete called in account model' );
- // break;
- // }
- // Backbone.sync.apply(this, arguments);
- //
- // },
-
initialize: function(){
this.on( 'invalid', function( model, error ){
console.log( error );
},
});
-// js/models/login.js
-
-// Login Model
-app.Models.Front.Login = Backbone.Model.extend({
-
- defaults: {
- username: '',
- password: '',
- message: '',
- },
-
- urlRoot: appLoginUrl,
-
- initialize: function(){
- this.on( 'invalid', function( model, error ){
- console.log( error );
- });
- },
-
- validate: function( attribs, options ){
- if ( attribs.username === undefined || attribs.username === '' ){
- return 'Username required!';
- }
- if ( attribs.password === undefined || attribs.password === '' ){
- return 'Password required!';
- }
- },
-
-});
-
// js/models/regClass.js
// Registration Class Model
}
},
- // sync: function( method, model ){
- // //console.log( 'sync in model' );
- // // console.log( method );
- // // console.log( model );
- // switch ( method ) {
- // case 'delete':
- // console.log( 'Delete called in registrant model' );
- // return false;
- // //this.url = url + 'model=' + model.toJSON();
- // break;
- // }
- // Backbone.sync.apply(this, arguments);
- //
- // },
-});
-
-app.Models.Front.Register = Backbone.Model.extend({
- defaults: {
- validEmail: false,
- name: 'register',
- email: '',
- emailError: '',
- password: '',
- fname: '',
- lname: '',
- org: '',
- title: '',
- addr1: '',
- addr2: '',
- city: '',
- state: '',
- zip: '',
- country: '',
- phone: '',
- fax: '',
- },
-
- urlRoot: ajaxUrl + 'glm_action=register',
-
- validate: function(){
- // Validation stuff here
- },
});
app.Models.Front.Request = Backbone.Model.extend({
app.Collections.Front.Accounts = Backbone.Collection.extend({
model: app.Models.Front.Account,
- // initialize: function( parent ){
- // this.parent = parent;
- // },
-
url: ajaxUrl+'&glm_action=regFront&collection=accounts',
- // create: function( model ){
- // console.log( model );
- // //model.save();
- // //localStorage.setItem('Account-' + model.parent + '-'+ model.id, JSON.stringify( model ) );
- // //this.add( model );
- // },
-
- // remove: function( model ){
- // //localStorage.removeItem( localStorage.key('Account-' + model.parent + '-'+ model.id ) );
- // //console.log( 'Delete called in collection ' );
- // },
-
- // read: function(){
- // console.log( 'Read called' );
- // },
-
- // save: function(){
- // console.log('Update Called');
- // },
-
- // fetch: function(){
- // var newModels = [];
- // for ( var i = 0; i < localStorage.length; i++ ) {
- // var curItem = JSON.parse( localStorage.getItem( localStorage.key( i ) ) );
- // if ( curItem.parent === this.parent ) {
- // // now add it to this collection
- // newModels.push( new app.Models.Front.Account( curItem ) );
- // }
- // }
- // this.reset( newModels );
- // },
-
});
render: function(){
// Check to see if there's a login
if ( loginAccount ) {
- // jQuery('#appLogin').hide();
jQuery('#register').hide();
- // this.accountView = new app.Views.Front.Account({ model: loginAccount });
- // this.$el.append( this.accountView.render().el );
}
this.$el.append( this.event.render().el );
return this;
},
events: {
- // 'click #appLogin': 'login',
'click #glm-reg-cart-continue': 'continue',
- // 'click #accountLogin': 'loginToAccount',
- // 'click #accountRegister': 'registerNewAccount',
- // 'click #accountLogout': 'logout',
- // 'click #register': 'register',
},
continue: function(){
- console.log( cart );
// Confirm they are done and goto the next page
var isDone = confirm( 'Are you done?' );
if ( isDone ) {
window.location.href = nextPageUrl;
}
- // Need to update the cart
- },
-
- // logout: function(){
- // // Send data to Logout
- // jQuery.ajax({
- // context: this,
- // url: appAccountUrl,
- // dataType: 'json',
- // data: 'option=logout'
- // })
- // .done(function( msg ){
- // // Here we can update.
- // loginAccount = '';
- // this.accountView.remove();
- // this.render();
- // this.event.model.classes.map(function(item){
- // item.set({ loggedIn: false });
- // });
- // jQuery('#appLogin').show();
- // // Need to reload the page now
- // window.location.href = thisPageUrl;
- // })
- // .fail(function(msg){
- // console.log('Fail:');
- // console.log( msg );
- // });
- // },
-
- loginToAccount: function(){
- this.$userInput = jQuery('.login');
- this.$pwdInput = jQuery('.password');
-
- // Send data to login ajax and verify user login
- jQuery.ajax({
- context: this,
- url: appAccountUrl,
- dataType: 'json',
- data: 'option=login&username=' + this.$userInput.val().trim() + '&password=' + this.$pwdInput.val().trim()
- })
- .done(function(account){
- if ( account.valid !== false ) {
- // Create account model and assign to this.loginAccount
- loginAccount = new app.Models.Front.Account({
- id: account.id,
- email: account.email,
- fname: account.fname,
- lname: account.lname
- });
- // Destroy the model and remove the view
- this.loginModel.destroy();
- this.loginView.remove();
- this.render();
- this.event.model.classes.map(function(item){
- item.set({ loggedIn: true });
- });
- } else {
- console.log( 'Login failed' );
- this.loginModel.set({ message: 'Failed login!' });
- }
- })
- .fail(function(msg){
- console.log('Fail: ' );
- console.log( msg );
- });
- },
-
- registerNewAccount: function(){
- this.$email = this.$('.account_email').val().trim();
- this.$password = this.$('.account_password').val().trim();
- this.$fname = this.$('.account_fname').val().trim();
- this.$lname = this.$('.account_lname').val().trim();
- this.$addr1 = this.$('.account_addr1').val().trim();
- this.$addr2 = this.$('.account_addr2').val().trim();
- this.$city = this.$('.account_city').val().trim();
- this.$state = this.$('.account_state').val().trim();
- this.$zip = this.$('.account_zip').val().trim();
- this.$country = this.$('.account_country').val().trim();
-
- // Send request to backend
- jQuery.ajax({
- context: this,
- url: appAccountUrl,
- dataType: 'json',
- data:{
- option: 'register',
- email: this.$email,
- password: this.$password,
- fname: this.$fname,
- lname: this.$lname,
- addr1: this.$addr1,
- addr2: this.$addr2,
- city: this.$city,
- state: this.$state,
- zip: this.$zip,
- country: this.$country,
- }
- })
- .done(function(account){
- console.log('return from ajax for register new');
- console.log(account);
- if ( account.id != undefined && account.id !== '' ) {
- // Account was created.
- // Now use this account for login.
- loginAccount = new app.Models.Front.Account({
- id: account.id,
- email: account.email,
- fname: account.fname,
- lname: account.lname
- });
- this.registerModel.destroy();
- this.registerView.remove();
- this.render();
- }
- })
- .fail(function(msg){
- console.log('Fail: ' );
- console.log( msg );
- });
- },
-
- // login: function(){
- // this.loginModel = new app.Models.Front.Login();
- // this.loginView = new app.Views.Front.Login({ model: this.loginModel });
- // this.$el.append( this.loginView.render().el );
- // jQuery('#accountHeader').hide();
- // },
-
- // register: function(){
- // this.registerModel = new app.Models.Front.Register();
- // this.registerView = new app.Views.Front.Register({ model: this.registerModel });
- // this.$el.append( this.registerView.render().el );
- // jQuery('#accountHeader').hide();
- // },
-
-});
-
-// js/views/login.js
-
-// Login View
-app.Views.Front.Login = Backbone.View.extend({
- tagName: 'div',
-
- className: 'glm-reg-login',
-
- template: _.template( jQuery('#eventReg-account-login').html() ),
-
- events: {
- 'click #loginCancel': 'closeLoginForm',
- //'keydown': 'keyAction',
- },
-
- initialize: function(){
- this.listenTo( this.model, 'change', this.render );
- return this;
- },
-
- closeLoginForm: function(){
- this.remove();
- jQuery('#accountHeader').show();
- return;
- },
-
- render: function(){
- this.$el.html( this.template( this.model.toJSON() ) );
- //jQuery('.login').focus();
- return this;
- },
-
- keyAction: function(e){
- if ( e.which === 13 ) {
- console.log( 'Enter key used' );
- }
},
});
});
-app.Views.Front.Register = Backbone.View.extend({
- tagName: 'div',
-
- className: 'glm-reg-register',
-
- template: _.template( jQuery('#register-new-account').html() ),
-
- events: {
- 'click #registerCancel': 'closeForm',
- 'focusout .account_email': 'checkEmail',
- 'focusout .account_password': 'checkPassword',
- },
-
- initialize: function(){
- this.listenTo( this.model, 'change', this.render );
- },
-
- render: function(){
- this.$el.html( this.template( this.model.toJSON() ) );
- return this;
- },
-
- closeForm: function(){
- this.remove();
- jQuery('#accountHeader').show();
- return;
- },
-
- addErrorMsg: function( error ){
- var errors = this.model.get( 'errors' );
- console.log( 'in addErrorMsg' );
- errors.push( error );
- console.log( errors );
- },
-
- checkEmail: function(){
- console.log( 'focusout for email' );
- this.$('.account_email').removeClass('error');
- this.model.set({ emailError: '' });
- // if they entered email then test for existing email
- if ( this.model.get( 'validEmail' ) === true ){
- return;
- }
- var cEmail = this.$('.account_email').val().trim();
- if ( cEmail === undefined || cEmail === '' ) {
- return;
- }
- console.log( cEmail );
- jQuery.ajax({
- context: this,
- url: ajaxUrl + '&glm_action=account&option=checkEmail',
- dataType: 'json',
- data:{
- email: cEmail,
- }
- })
- .done(function(account){
- if ( account.validEmail !== true ) {
- this.$('.account_email').addClass('error');
- //this.model.errors.push('Must be a valid email address!');
- //this.addErrorMsg( 'Must be a valid email address!' );
- //alert('Must be a valid email address!');
- //jQuery('.account_email').focus();
- this.model.set({ emailError: 'Must be a valid email address!' });
- } else if ( account.id !== undefined && account.email !== undefined ) {
- alert('There is an account already with that email address.\nPlease use another one!');
- jQuery('.account_email').val('');
- //jQuery('.account_email').focus();
- } else {
- // email is not existing account and valid
- this.model.set({ validEmail: true });
- this.$('.account_email').removeClass('error');
- }
- })
- .fail(function(msg){
- console.log('Fail: ' + msg);
- });
- },
-
- checkPassword: function(){
- console.log( 'focusout for password' );
- this.$('.account_password').removeClass('error');
- // only check if there's something in the field
- var tPass = this.$('.account_password').val().trim();
- if ( tPass === '' ) {
- return;
- }
- jQuery.ajax({
- context: this,
- url: ajaxUrl + '&glm_action=account&option=checkPassword',
- dataType: 'json',
- data: {
- password: this.$('.account_password').val().trim()
- }
- })
- .done(function(data){
- console.log( data );
- if ( data.msg ) {
- this.$('.account_password').addClass('error');
- alert( 'Password Error: \n' + data.msg );
- } else {
- this.$('.account_password').removeClass('error');
- }
- })
- .fail(function(msg){
- console.log( 'Fail: ' + msg );
- });
- },
-
-});
-
app.Views.Front.RegistrantForm = Backbone.View.extend({
tagName: 'div',
render: function(){
// Check to see if there's a login
if ( loginAccount ) {
- // jQuery('#appLogin').hide();
jQuery('#register').hide();
- // this.accountView = new app.Views.Front.Account({ model: loginAccount });
- // this.$el.append( this.accountView.render().el );
}
this.$el.append( this.event.render().el );
return this;
},
events: {
- // 'click #appLogin': 'login',
'click #glm-reg-cart-continue': 'continue',
- // 'click #accountLogin': 'loginToAccount',
- // 'click #accountRegister': 'registerNewAccount',
- // 'click #accountLogout': 'logout',
- // 'click #register': 'register',
},
continue: function(){
- console.log( cart );
// Confirm they are done and goto the next page
var isDone = confirm( 'Are you done?' );
if ( isDone ) {
window.location.href = nextPageUrl;
}
- // Need to update the cart
},
- // logout: function(){
- // // Send data to Logout
- // jQuery.ajax({
- // context: this,
- // url: appAccountUrl,
- // dataType: 'json',
- // data: 'option=logout'
- // })
- // .done(function( msg ){
- // // Here we can update.
- // loginAccount = '';
- // this.accountView.remove();
- // this.render();
- // this.event.model.classes.map(function(item){
- // item.set({ loggedIn: false });
- // });
- // jQuery('#appLogin').show();
- // // Need to reload the page now
- // window.location.href = thisPageUrl;
- // })
- // .fail(function(msg){
- // console.log('Fail:');
- // console.log( msg );
- // });
- // },
-
- loginToAccount: function(){
- this.$userInput = jQuery('.login');
- this.$pwdInput = jQuery('.password');
-
- // Send data to login ajax and verify user login
- jQuery.ajax({
- context: this,
- url: appAccountUrl,
- dataType: 'json',
- data: 'option=login&username=' + this.$userInput.val().trim() + '&password=' + this.$pwdInput.val().trim()
- })
- .done(function(account){
- if ( account.valid !== false ) {
- // Create account model and assign to this.loginAccount
- loginAccount = new app.Models.Front.Account({
- id: account.id,
- email: account.email,
- fname: account.fname,
- lname: account.lname
- });
- // Destroy the model and remove the view
- this.loginModel.destroy();
- this.loginView.remove();
- this.render();
- this.event.model.classes.map(function(item){
- item.set({ loggedIn: true });
- });
- } else {
- console.log( 'Login failed' );
- this.loginModel.set({ message: 'Failed login!' });
- }
- })
- .fail(function(msg){
- console.log('Fail: ' );
- console.log( msg );
- });
- },
-
- registerNewAccount: function(){
- this.$email = this.$('.account_email').val().trim();
- this.$password = this.$('.account_password').val().trim();
- this.$fname = this.$('.account_fname').val().trim();
- this.$lname = this.$('.account_lname').val().trim();
- this.$addr1 = this.$('.account_addr1').val().trim();
- this.$addr2 = this.$('.account_addr2').val().trim();
- this.$city = this.$('.account_city').val().trim();
- this.$state = this.$('.account_state').val().trim();
- this.$zip = this.$('.account_zip').val().trim();
- this.$country = this.$('.account_country').val().trim();
-
- // Send request to backend
- jQuery.ajax({
- context: this,
- url: appAccountUrl,
- dataType: 'json',
- data:{
- option: 'register',
- email: this.$email,
- password: this.$password,
- fname: this.$fname,
- lname: this.$lname,
- addr1: this.$addr1,
- addr2: this.$addr2,
- city: this.$city,
- state: this.$state,
- zip: this.$zip,
- country: this.$country,
- }
- })
- .done(function(account){
- console.log('return from ajax for register new');
- console.log(account);
- if ( account.id != undefined && account.id !== '' ) {
- // Account was created.
- // Now use this account for login.
- loginAccount = new app.Models.Front.Account({
- id: account.id,
- email: account.email,
- fname: account.fname,
- lname: account.lname
- });
- this.registerModel.destroy();
- this.registerView.remove();
- this.render();
- }
- })
- .fail(function(msg){
- console.log('Fail: ' );
- console.log( msg );
- });
- },
-
- // login: function(){
- // this.loginModel = new app.Models.Front.Login();
- // this.loginView = new app.Views.Front.Login({ model: this.loginModel });
- // this.$el.append( this.loginView.render().el );
- // jQuery('#accountHeader').hide();
- // },
-
- // register: function(){
- // this.registerModel = new app.Models.Front.Register();
- // this.registerView = new app.Views.Front.Register({ model: this.registerModel });
- // this.$el.append( this.registerView.render().el );
- // jQuery('#accountHeader').hide();
- // },
-
});
+++ /dev/null
-app.Views.Front.Register = Backbone.View.extend({
- tagName: 'div',
-
- className: 'glm-reg-register',
-
- template: _.template( jQuery('#register-new-account').html() ),
-
- events: {
- 'click #registerCancel': 'closeForm',
- 'focusout .account_email': 'checkEmail',
- 'focusout .account_password': 'checkPassword',
- },
-
- initialize: function(){
- this.listenTo( this.model, 'change', this.render );
- },
-
- render: function(){
- this.$el.html( this.template( this.model.toJSON() ) );
- return this;
- },
-
- closeForm: function(){
- this.remove();
- jQuery('#accountHeader').show();
- return;
- },
-
- addErrorMsg: function( error ){
- var errors = this.model.get( 'errors' );
- console.log( 'in addErrorMsg' );
- errors.push( error );
- console.log( errors );
- },
-
- checkEmail: function(){
- console.log( 'focusout for email' );
- this.$('.account_email').removeClass('error');
- this.model.set({ emailError: '' });
- // if they entered email then test for existing email
- if ( this.model.get( 'validEmail' ) === true ){
- return;
- }
- var cEmail = this.$('.account_email').val().trim();
- if ( cEmail === undefined || cEmail === '' ) {
- return;
- }
- console.log( cEmail );
- jQuery.ajax({
- context: this,
- url: ajaxUrl + '&glm_action=account&option=checkEmail',
- dataType: 'json',
- data:{
- email: cEmail,
- }
- })
- .done(function(account){
- if ( account.validEmail !== true ) {
- this.$('.account_email').addClass('error');
- //this.model.errors.push('Must be a valid email address!');
- //this.addErrorMsg( 'Must be a valid email address!' );
- //alert('Must be a valid email address!');
- //jQuery('.account_email').focus();
- this.model.set({ emailError: 'Must be a valid email address!' });
- } else if ( account.id !== undefined && account.email !== undefined ) {
- alert('There is an account already with that email address.\nPlease use another one!');
- jQuery('.account_email').val('');
- //jQuery('.account_email').focus();
- } else {
- // email is not existing account and valid
- this.model.set({ validEmail: true });
- this.$('.account_email').removeClass('error');
- }
- })
- .fail(function(msg){
- console.log('Fail: ' + msg);
- });
- },
-
- checkPassword: function(){
- console.log( 'focusout for password' );
- this.$('.account_password').removeClass('error');
- // only check if there's something in the field
- var tPass = this.$('.account_password').val().trim();
- if ( tPass === '' ) {
- return;
- }
- jQuery.ajax({
- context: this,
- url: ajaxUrl + '&glm_action=account&option=checkPassword',
- dataType: 'json',
- data: {
- password: this.$('.account_password').val().trim()
- }
- })
- .done(function(data){
- console.log( data );
- if ( data.msg ) {
- this.$('.account_password').addClass('error');
- alert( 'Password Error: \n' + data.msg );
- } else {
- this.$('.account_password').removeClass('error');
- }
- })
- .fail(function(msg){
- console.log( 'Fail: ' + msg );
- });
- },
-
-});