This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Always Include option on custom forms
Resolves #896
- Loading branch information
Showing
17 changed files
with
163 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Ember from 'ember'; | ||
|
||
const { | ||
isEmpty, | ||
set | ||
} = Ember; | ||
|
||
export default Ember.Service.extend({ | ||
store: Ember.inject.service(), | ||
customForms: {}, | ||
getCustomForms(formTypes) { | ||
let customForms = this.get('customForms'); | ||
let store = this.get('store'); | ||
let formTypesToQuery = formTypes.filter(function(formType) { | ||
if (isEmpty(customForms[formType])) { | ||
return true; | ||
} | ||
}); | ||
if (isEmpty(formTypesToQuery)) { | ||
return Ember.RSVP.resolve(this._getCustomFormsFromCache(formTypes)); | ||
} else { | ||
return store.query('custom-form', { | ||
options: { | ||
keys: formTypesToQuery | ||
}, | ||
mapReduce: 'custom_form_by_type' | ||
}).then((forms) => { | ||
formTypesToQuery.forEach((formType) => { | ||
customForms[formType] = forms.filterBy('formType', formType); | ||
}); | ||
return this._getCustomFormsFromCache(formTypes); | ||
}); | ||
} | ||
}, | ||
|
||
_getCustomFormsFromCache(formTypes) { | ||
let customForms = this.get('customForms'); | ||
let returnForms = []; | ||
formTypes.forEach((formType) => { | ||
returnForms.addObjects(customForms[formType]); | ||
}); | ||
return returnForms; | ||
}, | ||
|
||
resetCustomFormByType(formType) { | ||
let customForms = this.get('customForms'); | ||
delete customForms[formType]; | ||
}, | ||
|
||
setDefaultCustomForms(customFormNames, model) { | ||
return this.getCustomForms(customFormNames).then((customForms) => { | ||
if (!isEmpty(customForms)) { | ||
customForms.forEach((customForm) => { | ||
if (customForm.get('alwaysInclude')) { | ||
set(model, `customForms.${customForm.get('id')}`, Ember.Object.create()); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.