← Back to team overview

amm-dev-tem team mailing list archive

[Branch ~amm-dev-tem/amm/trunk] Rev 25: All characteristics of a member (declaration of the person + guardians + ermgency ...) can be set...

 

------------------------------------------------------------
revno: 25
committer: The Whole Life To Learn <thewholelifetolearn@xxxxxxxxx>
branch nick: sources
timestamp: Tue 2011-05-31 17:15:55 +0200
message:
  All characteristics of a member (declaration of the person + guardians + ermgency ...) can be set trough the member formular
added:
  app/views/members/add.ctp
renamed:
  app/views/members/add.ctp => app/views/members/add_existing.ctp
modified:
  app/controllers/members_controller.php
  app/views/members/index.ctp


--
lp:amm
https://code.launchpad.net/~amm-dev-tem/amm/trunk

Your team AMM dev team is subscribed to branch lp:amm.
To unsubscribe from this branch go to https://code.launchpad.net/~amm-dev-tem/amm/trunk/+edit-subscription
=== modified file 'app/controllers/members_controller.php'
--- app/controllers/members_controller.php	2011-05-30 14:30:19 +0000
+++ app/controllers/members_controller.php	2011-05-31 15:15:55 +0000
@@ -19,8 +19,79 @@
 
 	function add() {
 		if (!empty($this->data)) {
-			$this->Member->create();
-			debug($this->Member->data);
+			// Member
+			$this->Member->Person->create();
+			$this->Member->Person->concatName($this->data['Person']);
+			$isInDb = $this->Member->Person->find('first', array('recursive' => -1, 'conditions' => array('Person.name' => $this->data['Person']['name'])));
+			if($isInDb) {
+				$this->data['Member']['person_id'] = $isInDb['Person']['id'];
+			} else {
+				$this->Member->Person->save($this->data);
+				$this->data['Member']['person_id'] = $this->Member->Person->id;
+			}
+			// Guardian 1
+			$this->Member->Guardian1->create();
+			$this->Member->Guardian1->concatName($this->data['Guardian1']);
+			$isInDb = $this->Member->Guardian1->find('first', array('recursive' => -1, 'conditions' => array('Guardian1.name' => $this->data['Guardian1']['name'])));
+			if($isInDb) {
+				$this->data['Member']['guardian1_id'] = $isInDb['Person']['id'];
+			} else {
+				$this->Member->Guardian1->save($this->data);
+				$this->data['Member']['guardian1_id'] = $this->Member->Guardian1->id;
+			}
+			// Guardian 2
+			$this->Member->Guardian2->create();
+			$this->Member->Guardian2->concatName($this->data['Guardian2']);
+			$isInDb = $this->Member->Guardian2->find('first', array('recursive' => -1, 'conditions' => array('Guardian2.name' => $this->data['Guardian2']['name'])));
+			if($isInDb) {
+				$this->data['Member']['guardian2_id'] = $isInDb['Guardian2']['id'];
+			} else {
+				$this->Member->Guardian2->save($this->data);
+				$this->data['Member']['guardian2_id'] = $this->Member->Guardian2->id;
+			}
+			// Emergency 1
+			$this->Member->Emergency1->create();
+			$this->Member->Emergency1->concatName($this->data['Emergency1']);
+			$isInDb = $this->Member->Emergency1->find('first', array('recursive' => -1, 'conditions' => array('Emergency1.name' => $this->data['Emergency1']['name'])));
+			if($isInDb) {
+				$this->data['Member']['emergency1_id'] = $isInDb['Emergency1']['id'];
+			} else {
+				$this->Member->Emergency1->save($this->data);
+				$this->data['Member']['emergency1_id'] = $this->Member->Emergency1->id;
+			}
+			// Emergency 2
+			$this->Member->Emergency2->create();
+			$this->Member->Emergency2->concatName($this->data['Emergency2']);
+			$isInDb = $this->Member->Emergency2->find('first', array('recursive' => -1, 'conditions' => array('Emergency2.name' => $this->data['Emergency2']['name'])));
+			if($isInDb) {
+				$this->data['Member']['emergency2_id'] = $isInDb['Emergency2']['id'];
+			} else {
+				$this->Member->Emergency2->save($this->data);
+				$this->data['Member']['emergency2_id'] = $this->Member->Emergency2->id;
+			}
+
+			$this->Member->create();
+			if ($this->Member->save($this->data, false)) {
+				$this->Session->setFlash(__('The member has been saved', true));
+				$this->redirect(array('action' => 'index'));
+			} else {
+				$this->Session->setFlash(__('The member could not be saved. Please, try again.', true));
+			}
+		}
+		$formulas = $this->Member->Formula->find('list',
+			array(
+				'order' => array(
+					'Formula.name' => 'asc'
+				)
+			)
+		);
+		$authorizations = $this->Member->Authorization->find('list');
+		$this->set(compact('formulas', 'authorizations'));
+	}
+
+	function add_existing() {
+		if (!empty($this->data)) {
+			$this->Member->create();
 			if ($this->Member->save($this->data)) {
 				$this->Session->setFlash(__('The member has been saved', true));
 				$this->redirect(array('action' => 'index'));
@@ -247,4 +318,14 @@
 		$this->Session->setFlash(__('Member was not deleted', true));
 		$this->redirect(array('action' => 'index'));
 	}
+
+//	function ajax_search($field = null, $value = null) {
+//		$this->layout = 'ajax';
+////		echo $field.' '.$value;
+//		$this->set('results', $this->Member->Person->find('all', array(
+//			'conditions' => array(
+//				$field.' LIKE ' => $value.'%'
+//			)
+//		)));
+//	}
 }

=== added file 'app/views/members/add.ctp'
--- app/views/members/add.ctp	1970-01-01 00:00:00 +0000
+++ app/views/members/add.ctp	2011-05-31 15:15:55 +0000
@@ -0,0 +1,353 @@
+<?php
+echo $this->Html->script('jquery-1.6.x.min');
+;?>
+<script type="text/javascript">
+	$(document).ready(function(){
+		function isGuardianNeeded(){
+			var bDay_day = $('#PersonBirthdayDay').val();
+			var bDay_month = $('#PersonBirthdayMonth').val();
+			var bDay_year = $('#PersonBirthdayYear').val();
+			var mShip_day = $('#MemberMembershipDateDay').val();
+			var mShip_month = $('#MemberMembershipDateMonth').val();
+			var mShip_year = $('#MemberMembershipDateYear').val();
+			if((mShip_year - bDay_year) > 18) {
+				return false;
+			} else if((mShip_year - bDay_year) == 18) {
+				if((mShip_month - bDay_month) > 0) {
+					return false;
+				}else if((mShip_month - bDay_month) == 0) {
+					if((mShip_day - bDay_day) >= 0) {
+						return false;
+					}
+				}
+			}
+
+			return true;
+		}
+
+		if(isGuardianNeeded()) {
+			$('.guardian').css('display', '');
+		} else {
+			$('.guardian').css('display', 'none');
+		}
+		$('#PersonBirthdayDay, #PersonBirthdayMonth, #PersonBirthdayYear, #MemberMembershipDateDay, #MemberMembershipDateMonth, #MemberMembershipDateYear').change(function(){
+			if(isGuardianNeeded()) {
+				$('.guardian').css('display', '');
+			} else {
+				$('.guardian').css('display', 'none');
+			}
+		});
+		$('#MemberAddForm').submit(function(){
+			if(!isGuardianNeeded()) {
+				$('.guardian').detach();
+			}
+		});
+//		$('#PersonFirstname').keyup(function(){
+//			if($('#PersonFirstname').val().length >= 2) {
+//				$.ajax({
+//					type: "POST",
+//					url: "ajax_search/Person.firstname/"+$('#PersonFirstname').val(),
+//					success: function(data) {
+//						$('#ajax_search').remove();
+//						$('#PersonFirstname').after(data);
+//					}
+//				});
+//				}
+//		});
+	});
+</script>
+<div class="members form">
+<?php echo $this->Form->create('Member', array('type' => 'file'));?>
+	<fieldset class="member">
+		<legend><?php __('Member informations'); ?></legend>
+	<?php
+	// Member inputs
+		echo $this->Form->input('Person.firstname', array(
+			'label' => __('First name', true),
+			'error' => array(
+			    'notempty' => __('You haven\'t field in your first name.', true)
+			    )
+			)
+		);
+		echo $this->Form->input('Person.lastname', array(
+			'label' => __('Last name', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your name.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Person.surname', array('label' => __('Nickname', true)));
+		echo $this->Form->input('Person.birthday', array(
+			'label' => __('Birthday', true),
+			'dateFormat' => 'DMY',
+			'minYear' => date('Y')-80,
+			'maxYear' => date('Y')
+			)
+		);
+		echo $this->Form->input('Person.address', array(
+			'label' => __('Address', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your address.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Person.addr_comp', array('label' => __('Complementary address', true)));
+		echo $this->Form->input('Person.postal_code', array(
+			'label' => __('Postal code', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your postal code.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Person.town', array(
+			'label' => __('City', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your city\'s name.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Person.phone', array(
+			'label' => __('Phone number', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your phone number.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Person.email', array(
+			'label' => __('Email', true),
+			'error' => array(
+				'email' => __('The email address you field in isn\'t correct (something@xxxxxxxxxxxxx).', true),
+				'notempty' => __('You haven\'t field in your email address.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Person.job', array('label' => __('Job', true)));
+		echo $this->Form->input('Person.picture', array(
+			'label' => __('Photo', true),
+			'type' => 'file',
+			'error' => array(
+				'file' => __('The file you have submitted is not a picture (.jpg, .jpeg, .gif and .png files only are accepted)', true)
+				)
+			)
+		);
+		echo $this->Form->input('Person.notes', array('label' => __('Notes/comments', true)));
+
+		echo $this->Form->input('formula_id',
+			array(
+				'label' => __('Formula', true)
+			)
+		);
+		echo $this->Form->input('membership_date',
+			array(
+				'label' => __('Begin of membership', true),
+				'dateFormat' => 'DMY',
+				'minYear' => date('Y')-2,
+				'maxYear' => date('Y')+1
+			)
+		);
+		echo $this->Form->input('file',
+			array(
+				'label' => __('Medical certificat', true),
+				'type' => 'file'
+			)
+		);
+		echo $this->Form->input('Authorization',
+			array(
+				'label' => __('Authorizations accepted', true)
+			)
+		);
+		echo $this->Form->input('Member.notes', array('label' => __('Membership notes/comments', true)));
+	?>
+	</fieldset>
+	<fieldset class="guardian">
+		<legend><?php __('Guardian 1 informations'); ?></legend>
+	<?php
+
+	// Guardian 1 inputs
+
+		echo $this->Form->input('Guardian1.firstname', array(
+			'label' => __('First name', true),
+			'error' => array(
+			    'notempty' => __('You haven\'t field in your first name.', true)
+			    )
+			)
+		);
+		echo $this->Form->input('Guardian1.lastname', array(
+			'label' => __('Last name', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your name.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian1.address', array(
+			'label' => __('Address', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your address.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian1.addr_comp', array('label' => __('Complementary address', true)));
+		echo $this->Form->input('Guardian1.postal_code', array(
+			'label' => __('Postal code', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your postal code.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian1.town', array(
+			'label' => __('City', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your city\'s name.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian1.phone', array(
+			'label' => __('Phone number', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your phone number.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian1.email', array(
+			'label' => __('Email', true),
+			'error' => array(
+				'email' => __('The email address you field in isn\'t correct (something@xxxxxxxxxxxxx).', true),
+				'notempty' => __('You haven\'t field in your email address.', true)
+				)
+			)
+		);
+	?>
+	</fieldset>
+	<fieldset class="guardian">
+		<legend><?php __('Guardian 2 informations (optionnal)'); ?></legend>
+	<?php
+
+	// Guardian 2 inputs
+
+		echo $this->Form->input('Guardian2.firstname', array(
+			'label' => __('First name', true),
+			'error' => array(
+			    'notempty' => __('You haven\'t field in your first name.', true)
+			    )
+			)
+		);
+		echo $this->Form->input('Guardian2.lastname', array(
+			'label' => __('Last name', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your name.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian2.address', array(
+			'label' => __('Address', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your address.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian2.addr_comp', array('label' => __('Complementary address', true)));
+		echo $this->Form->input('Guardian2.postal_code', array(
+			'label' => __('Postal code', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your postal code.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian2.town', array(
+			'label' => __('City', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your city\'s name.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian2.phone', array(
+			'label' => __('Phone number', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your phone number.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Guardian2.email', array(
+			'label' => __('Email', true),
+			'error' => array(
+				'email' => __('The email address you field in isn\'t correct (something@xxxxxxxxxxxxx).', true),
+				'notempty' => __('You haven\'t field in your email address.', true)
+				)
+			)
+		);
+	?>
+	</fieldset>
+	<fieldset class="emergency">
+		<legend><?php __('Emergency 1 informations'); ?></legend>
+	<?php
+
+	// Emergency 1 inputs
+
+		echo $this->Form->input('Emergency1.firstname', array(
+			'label' => __('First name', true),
+			'error' => array(
+			    'notempty' => __('You haven\'t field in your first name.', true)
+			    )
+			)
+		);
+		echo $this->Form->input('Emergency1.lastname', array(
+			'label' => __('Last name', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your name.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Emergency1.phone', array(
+			'label' => __('Phone number', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your phone number.', true)
+				)
+			)
+		);
+	?>
+	</fieldset>
+	<fieldset class="emergency">
+		<legend><?php __('Emergency 2 informations (optionnal)'); ?></legend>
+	<?php
+
+	// Emergency 2 inputs
+
+		echo $this->Form->input('Emergency2.firstname', array(
+			'label' => __('First name', true),
+			'error' => array(
+			    'notempty' => __('You haven\'t field in your first name.', true)
+			    )
+			)
+		);
+		echo $this->Form->input('Emergency2.lastname', array(
+			'label' => __('Last name', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your name.', true)
+				)
+			)
+		);
+		echo $this->Form->input('Emergency2.phone', array(
+			'label' => __('Phone number', true),
+			'error' => array(
+				'notempty' => __('You haven\'t field in your phone number.', true)
+				)
+			)
+		);
+	?>
+	</fieldset>
+<?php echo $this->Form->end(__('Submit', true));?>
+</div>
+<div class="actions">
+	<h3><?php __('Actions'); ?></h3>
+	<ul>
+
+		<li><?php echo $this->Html->link(__('List Members', true), array('action' => 'index'));?></li>
+		<li><?php echo $this->Html->link(__('List People', true), array('controller' => 'people', 'action' => 'index')); ?> </li>
+		<li><?php echo $this->Html->link(__('New Person', true), array('controller' => 'people', 'action' => 'add')); ?> </li>
+		<li><?php echo $this->Html->link(__('List Formulas', true), array('controller' => 'formulas', 'action' => 'index')); ?> </li>
+		<li><?php echo $this->Html->link(__('New Formula', true), array('controller' => 'formulas', 'action' => 'add')); ?> </li>
+		<li><?php echo $this->Html->link(__('List Authorizations', true), array('controller' => 'authorizations', 'action' => 'index')); ?> </li>
+		<li><?php echo $this->Html->link(__('New Authorization', true), array('controller' => 'authorizations', 'action' => 'add')); ?> </li>
+	</ul>
+</div>
+<?php echo $this->Js->writeBuffer(); ?>
\ No newline at end of file

=== renamed file 'app/views/members/add.ctp' => 'app/views/members/add_existing.ctp'
=== modified file 'app/views/members/index.ctp'
--- app/views/members/index.ctp	2011-05-30 14:30:19 +0000
+++ app/views/members/index.ctp	2011-05-31 15:15:55 +0000
@@ -62,6 +62,7 @@
 	<h3><?php __('Actions'); ?></h3>
 	<ul>
 		<li><?php echo $this->Html->link(__('New Member', true), array('action' => 'add')); ?></li>
+		<li><?php echo $this->Html->link(__('Add Member', true), array('action' => 'add_existing')); ?></li>
 		<li><?php echo $this->Html->link(__('List People', true), array('controller' => 'people', 'action' => 'index')); ?> </li>
 		<li><?php echo $this->Html->link(__('New Person', true), array('controller' => 'people', 'action' => 'add')); ?> </li>
 		<li><?php echo $this->Html->link(__('List Formulas', true), array('controller' => 'formulas', 'action' => 'index')); ?> </li>