WIP
This commit is contained in:
		
							parent
							
								
									af9ac976dc
								
							
						
					
					
						commit
						7f73046773
					
				
					 5 changed files with 40 additions and 2 deletions
				
			
		|  | @ -11,6 +11,8 @@ export default Controller.extend(ValidationMixin, { | ||||||
|   CollectionSpeciesValidations, |   CollectionSpeciesValidations, | ||||||
|   DatasheetValidations, |   DatasheetValidations, | ||||||
| 
 | 
 | ||||||
|  |   hasMany: ['collectionSpecies', 'datasheets'], | ||||||
|  | 
 | ||||||
|   options: computed('projectOptions', 'studyLocationOptions', |   options: computed('projectOptions', 'studyLocationOptions', | ||||||
|                     'collectionTypeOptions', 'collectionMethodOptions', |                     'collectionTypeOptions', 'collectionMethodOptions', | ||||||
|                     'speciesOptions', 'adfgPermitOptions', function() { |                     'speciesOptions', 'adfgPermitOptions', function() { | ||||||
|  |  | ||||||
|  | @ -11,6 +11,8 @@ export default Controller.extend(ValidationMixin, { | ||||||
|   CollectionSpeciesValidations, |   CollectionSpeciesValidations, | ||||||
|   DatasheetValidations, |   DatasheetValidations, | ||||||
| 
 | 
 | ||||||
|  |   hasMany: ['collectionSpecies', 'datasheets'], | ||||||
|  | 
 | ||||||
|   options: computed('projectOptions', 'studyLocationOptions', |   options: computed('projectOptions', 'studyLocationOptions', | ||||||
|                     'collectionTypeOptions', 'collectionMethodOptions', |                     'collectionTypeOptions', 'collectionMethodOptions', | ||||||
|                     'speciesOptions', 'adfgPermitOptions', function() { |                     'speciesOptions', 'adfgPermitOptions', function() { | ||||||
|  |  | ||||||
							
								
								
									
										32
									
								
								app/mixins/cleanup-form.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								app/mixins/cleanup-form.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,32 @@ | ||||||
|  | import Ember from 'ember'; | ||||||
|  | 
 | ||||||
|  | const { Mixin, run: { once } } = Ember; | ||||||
|  | 
 | ||||||
|  | export default Mixin.create({ | ||||||
|  |   actions: { | ||||||
|  |     willTransition(transition) { | ||||||
|  |       if (confirm('Any unsaved changes will be discarded.')) { | ||||||
|  |         let model = this.get('controller.model'); | ||||||
|  |         let hasMany = this.get('controller.hasMany'); | ||||||
|  | 
 | ||||||
|  |         hasMany.forEach((relationship) => { | ||||||
|  |           model.get(relationship).forEach((r) => { | ||||||
|  |             once(this, () => { | ||||||
|  |               if (r.get('isNew')) { | ||||||
|  |                 r.deleteRecord(); | ||||||
|  |               } else { | ||||||
|  |                 r.rollbackAttributes(); | ||||||
|  |               } | ||||||
|  |             }, this); | ||||||
|  |           }); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         if (model.get('isNew')) { | ||||||
|  |           model.deleteRecord(); | ||||||
|  |         } | ||||||
|  |       } else { | ||||||
|  |         return false; | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |   }, | ||||||
|  | }); | ||||||
|  | @ -1,8 +1,9 @@ | ||||||
| import Ember from 'ember'; | import Ember from 'ember'; | ||||||
|  | import CleanupFormMixin from 'ccdb-web/mixins/cleanup-form'; | ||||||
| 
 | 
 | ||||||
| const { Route, RSVP } = Ember; | const { Route, RSVP } = Ember; | ||||||
| 
 | 
 | ||||||
| export default Route.extend({ | export default Route.extend(CleanupFormMixin, { | ||||||
|   model() { |   model() { | ||||||
|     const store = this.get('store'); |     const store = this.get('store'); | ||||||
|     return RSVP.hash({ |     return RSVP.hash({ | ||||||
|  |  | ||||||
|  | @ -1,8 +1,9 @@ | ||||||
| import Ember from 'ember'; | import Ember from 'ember'; | ||||||
|  | import CleanupFormMixin from 'ccdb-web/mixins/cleanup-form'; | ||||||
| 
 | 
 | ||||||
| const { Route, RSVP } = Ember; | const { Route, RSVP } = Ember; | ||||||
| 
 | 
 | ||||||
| export default Route.extend({ | export default Route.extend(CleanupFormMixin, { | ||||||
|   model() { |   model() { | ||||||
|     const store = this.get('store'); |     const store = this.get('store'); | ||||||
|     const model = this.modelFor('collections.detail'); |     const model = this.modelFor('collections.detail'); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue