<commit_before>import Ember from 'ember';
const ZERO = 0;
export default Ember.Mixin.create({
	actions: {
		/**
		 * There are 4 outcomes when a beforeSave/Validate function is given in the extending component
		 * They depenend on what is returned by beforeSave/Validate)
		 * 
		 * 1. beforeSave/Validate = false : Stop propagation of any actions
		 * 2. beforeSave/Validate = {force: false} : Fall through to bubbling the save action, no force
		 * 3. beforeSave/Validate = {force: true} : Fall through to bubbling the save action, with force
		 * 4. beforeSave/Validate = undefined : Run the rest of the save action (as if no beforeSave was called)
		 */
		onSave(force){
			this.set('onSaveFired', !(this.get('onSaveFired'))); //can be used to listen for all onSave events
			let changeset = this.get(`${this.get('changeset')}`);
			let forceClose;

			const beforeValidate = this.get('beforeValidate');
			if(beforeValidate !== undefined){
				if(beforeValidate === false){
					return false; //stop propagation
				}
				if(typeof beforeValidate === 'object'){
					forceClose = beforeValidate.force;
				}
			}

			if(!forceClose && !force){
				
				changeset.validate();
				if(!changeset.get('errors.length')){		
					const beforeSave = this.get('beforeSave');
			
					if(beforeSave !== undefined){
						if(beforeSave === false){
							return false; //stop propagation
						}
						if(typeof beforeSave === 'object'){
							forceClose = beforeSave.force;
						}
					}

					changeset.validate(); //must vaildate possible changes in beforeSave
				}
				if(changeset.get('errors.length')){ //not an else b/c its a new test after validate call above
					let changesetErrors = changeset.get('errors').map((err) => {
						return err.validation[ZERO]; 
					});
					this.set('changesetErrors', changesetErrors); 
					this.get('handleOnSaveErrors');
					return false; //stop propagation
					//changeset.rollback(); ?
				}
			}
			changeset.execute(); //this is safe, won't result in any changes if there are errors
			Ember.run.schedule('actions', this, function() {
				this.sendAction('onSave', forceClose || force); 
			});	
			return false; //stop propagation, use explicit send action above
		},
		onClose(force){
			this.set('onCloseFired', !(this.get('onCloseFired'))); //can be used to listen for all onClose events
			
			let changeset = this.get(`${this.get('changeset')}`);
				
			changeset.validate();
			if(changeset.get('errors.length')){
				this.set('isInvalid', true);
				let changesetErrors = changeset.get('errors').map((err) => {
					return err.validation[ZERO]; 
				}); 
				this.set('changesetErrors', changesetErrors);
				this.get('handleOnCloseErrors');
			} else {
				changeset.execute();
				//changeset.rollback(); ?
			}
			if (force || (!this.get('isDirty') && !this.get('isInvalid')) ){
				Ember.$('.ui.modal').modal('hide');<commit_msg>make model keys with errors exposed. Use Ember's notifyPropertyChange for hook listeners<commit_after>import Ember from 'ember';
const ZERO = 0;
export default Ember.Mixin.create({
	actions: {
		/**
		 * There are 4 outcomes when a beforeSave/Validate function is given in the extending component
		 * They depenend on what is returned by beforeSave/Validate)
		 * 
		 * 1. beforeSave/Validate = false : Stop propagation of any actions
		 * 2. beforeSave/Validate = {force: false} : Fall through to bubbling the save action, no force
		 * 3. beforeSave/Validate = {force: true} : Fall through to bubbling the save action, with force
		 * 4. beforeSave/Validate = undefined : Run the rest of the save action (as if no beforeSave was called)
		 */
		onSave(force){
			this.notifyPropertyChange('onSaveFired');
			
			let changeset = this.get(`${this.get('changeset')}`);
			let forceClose;

			const beforeValidate = this.get('beforeValidate');
			if(beforeValidate !== undefined){
				if(beforeValidate === false){
					return false; //stop propagation
				}
				if(typeof beforeValidate === 'object'){
					forceClose = beforeValidate.force;
				}
			}

			if(!forceClose && !force){
				
				changeset.validate();
				if(!changeset.get('errors.length')){		
					const beforeSave = this.get('beforeSave');
			
					if(beforeSave !== undefined){
						if(beforeSave === false){
							return false; //stop propagation
						}
						if(typeof beforeSave === 'object'){
							forceClose = beforeSave.force;
						}
					}

					changeset.validate(); //must vaildate possible changes in beforeSave
				}
				if(changeset.get('errors.length')){ //not an else b/c its a new test after validate call above
					let changesetErrors = changeset.get('errors').map((err) => {
						return err.validation[ZERO]; 
					});
					let changesetErrorKeys = Object.keys(changeset.get('error'));
					this.set('changesetErrors', changesetErrors);
					this.set('changesetErrorKeys', changesetErrorKeys); 
					this.get('handleOnSaveErrors');
					return false; //stop propagation
					//changeset.rollback(); ?
				}
			}
			changeset.execute(); //this is safe, won't result in any changes if there are errors
			Ember.run.schedule('actions', this, function() {
				this.sendAction('onSave', forceClose || force); 
			});	
			return false; //stop propagation, use explicit send action above
		},
		onClose(force){
			this.notifyPropertyChange('onCloseFired');
			
			let changeset = this.get(`${this.get('changeset')}`);
				
			changeset.validate();
			if(changeset.get('errors.length')){
				this.set('isInvalid', true);
				let changesetErrors = changeset.get('errors').map((err) => {
					return err.validation[ZERO]; 
				});
				let changesetErrorKeys = Object.keys(changeset.get('error'));
				this.set('changesetErrors', changesetErrors);
				this.set('changesetErrorKeys', changesetErrorKeys); 
				this.get('handleOnCloseErrors');
			} else {
				changeset.execute();
				//changeset.rollback(); ?
			}
			if (force || (!this.get('isDirty') && !this.get('isInvalid')) ){
				Ember.$('.ui.modal').modal('hide');
{'fraction_non_alphanumeric': 0.1427856547122602, 'fraction_numerical': 0.002001668056713928, 'mean_word_length': 3.35439360929557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5875067', 'n_tokens_mistral': 2208, 'n_tokens_neox': 1761, 'n_words': 464}