Created
January 6, 2017 05:04
-
-
Save jekku/29e58551837243eb1552cf26a8a5e5b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Crm.ArtistSearchVariableMixin = Em.Mixin.create | |
perPage: null | |
sortPage: null | |
# selected questions | |
selectedQuestions: {} | |
selectedQuestionIds: [] | |
selectedQuestionAnswers: [] | |
selectedEthnicities: (-> | |
ethnicities = @get('qethnicity') | |
collection = Crm.Collections.Statistics.Ethnicity.content | |
selected = [] | |
if ethnicities | |
ethnicities.forEach (ethnicity) => | |
ethnicity = collection.findBy('value', ethnicity) | |
selected.addObject ethnicity | |
selected | |
).property('qethnicity') | |
# Mixins for the search variables | |
# | |
queryParams: [ | |
'per_page', 'page', 'sort', | |
'qfirst_name', 'qlast_name', 'qguardian_first_name', | |
'qguardian_last_name', 'qguardian_email', 'qguardian_phone', | |
'qcountry', 'qstate', 'qgender', 'qstatus', 'qpriority', | |
'qenrollment_from', 'qenrollment_to', 'qpostcode' | |
'qrating', 'qcampaign', 'qage_from', 'qage_to', | |
'qevent_date', 'qevent_type', 'qevent_status', | |
'qethnicity', 'qheight', 'qweight', 'qchest', 'qwaist_size', 'qhair_color' | |
'qcomplexion', 'qeye_color', 'qhair_length', 'qdress_size', | |
'qbra_size', 'qbust_size', 'qhip_size', 'qsuit_size', 'qinside_leg_size', | |
'qoutside_leg_size', 'qshoe_size', 'qkids_clothing_size', | |
'qquestion_ids', 'qquestion_answers' | |
] | |
# Page instance writer | |
# | |
per_page: null | |
page: null | |
sort: null | |
# Instance writer for each properties on search variables | |
# | |
# Basic Search | |
# | |
qfirst_name: null | |
qlast_name: null | |
qguardian_first_name: null | |
qguardian_last_name: null | |
qguardian_email: null | |
qguardian_phone: null | |
qcountry: null | |
qstate: null | |
qpostcode: null | |
qgender: null | |
qstatus: null | |
qpriority: null | |
qenrollment_from: null | |
qenrollment_to: null | |
# Advanced Search | |
# | |
qrating: null | |
qcampaign: null | |
qage_from: null | |
qage_to: null | |
# Advanced Schedule Search | |
qevent_date: null | |
qevent_type: null | |
qevent_status: null | |
# Advanced Statistics Search | |
# | |
qethnicity: [] | |
qheight: null | |
qweight: null | |
qchest: null | |
qwaist_size: null | |
qcomplexion: null | |
qeye_color: null | |
qhair_color: null | |
qhair_length: null | |
qdress_size: null | |
qbra_size: null | |
qbust_size: null | |
qhip_size: null | |
qsuit_size: null | |
qinside_leg_size: null | |
qoutside_leg_size: null | |
qshoe_size: null | |
qkids_clothing_size: null | |
# Advanced Question Search | |
# | |
qquestion_ids: [] | |
qquestion_answers: [] | |
# Search Form Field | |
# | |
# Basic Search Field | |
# | |
qfirstNameField: null | |
qlastNameField: null | |
qguardianFirstNameField:null | |
qguardianLastNameField:null | |
qguardianEmailField:null | |
qguardianPhoneField:null | |
qcountryField: null | |
qstateField: null | |
qpostcodeField: null | |
qgenderField: null | |
qstatusField: null | |
qpriorityField: null | |
qenrollmentFromField: null | |
qenrollmentToField: null | |
# Advanced Search Field | |
# | |
qratingField: null | |
qcampaignField: null | |
qageFromField: null | |
qageToField: null | |
# Advanced Schedule Field | |
# | |
qeventDateField: null | |
qeventTypeField: null | |
qeventStatusField: null | |
# Advanced Statistics Field | |
# | |
qheightField: null | |
qweightField: null | |
qchestField: null | |
qwaistSizeField: null | |
qcomplexionField: null | |
qeyeColorField: null | |
qhairColorField: null | |
qhairLengthField: null | |
qdressSizeField: null | |
qbraSizeField: null | |
qbustSizeField: null | |
qhipSizeField: null | |
qsuitSizeField: null | |
qinsideLegSizeField: null | |
qoutsideLegSizeField: null | |
qshoeSizeField: null | |
qkidsClothingSize: null | |
Crm.ArtistSearchMixin = Em.Mixin.create | |
ageRange: (-> | |
ranges = [ | |
{ label: "1 month", value: "1.month" } | |
{ label: "2 months", value: "2.month" } | |
{ label: "3 months", value: "3.month" } | |
{ label: "4 months", value: "4.month" } | |
{ label: "5 months", value: "5.month" } | |
{ label: "6 months", value: "6.month" } | |
{ label: "7 months", value: "7.month" } | |
{ label: "8 months", value: "8.month" } | |
{ label: "9 months", value: "9.month" } | |
{ label: "10 months", value: "10.month" } | |
{ label: "11 months", value: "11.month" } | |
] | |
year = 1 | |
while year < 100 | |
yearName = if (year > 1) then "years" else "year" | |
label = "%@ %@".fmt(year, yearName) | |
ranges.push label: label, value: "%@.year" .fmt(year) | |
year++ | |
ranges | |
).property() #I purposely did not bind this to any property | |
Crm.ArtistsSearchBulkActions = Em.Mixin.create | |
selectedArtists: [] | |
artistStatusBulkChanged: (-> | |
status = @get 'artistStatusBulk' | |
artists = @get 'selectedArtists' | |
if status | |
artists.forEach (artist) -> | |
artist.set('status', status) | |
artist.save().then ((response) -> | |
Crm.Humane.success "#{artist.get('fullName')} status has been changed to #{artist.get('status')}" | |
), (response) -> | |
Crm.Humane.error "Error: Failed to update status of #{artist.get('fullName')}" | |
artist.rollback() | |
).observes('artistStatusBulk') | |
actions: | |
toggleArtist: (artist) -> | |
artists = @get('selectedArtists') | |
if artists.indexOf(artist) == -1 | |
artists.addObject(artist) | |
else | |
artists.removeObject(artist) | |
openDeleteModal: -> | |
@set 'deleteModalIsOpen', true | |
closeDeleteModal: -> | |
@set 'deleteModalIsOpen', false | |
deleteArtists: -> | |
artists = @get 'selectedArtists' | |
content = @get 'content' | |
artists.forEach (artist) -> | |
artist.destroyRecord().then ((response) -> | |
Crm.Humane.success "#{artist.get('fullName')} has been successfully deleted." | |
artists.removeObject artist | |
content.removeObject artist | |
), (response) -> | |
artist.rollback() | |
Crm.Humane.error "Error: Failed to delete artist #{artist.get('fullName')}" | |
@send 'closeDeleteModal' | |
@send 'clearArtists' | |
clearArtists: -> | |
@set 'selectedArtists', [] | |
@set 'artistStatusBulk', '' | |
Crm.ArtistsSearchController = Em.ArrayController.extend Crm.ArtistPaginateMixin, | |
Crm.ArtistSearchMixin, Crm.ArtistSearchVariableMixin, Crm.ArtistsSearchBulkActions, | |
ratings: [] | |
campaigns: [] | |
questions: [] | |
isSpinning: true | |
isSearching: false | |
deleteModalIsOpen: false | |
advancedFilterClass: 'artistAdvancedFilter hide' | |
isAdvancedFilterOpen: false | |
isAdvanceOptionApplied: false | |
isCallback: ( -> | |
status = @get('qstatusField') | |
status is 'Callback' | |
).property('qstatusField') | |
perPageChanged: (-> | |
perPage = @get('perPage') | |
@set 'per_page', perPage | |
).observes('perPage') | |
sortPageChanged: (-> | |
@set 'sort', @get('sortPage') | |
).observes('sortPage') | |
actions: | |
resetFilter: -> | |
query = {} | |
@get('queryParams').forEach (param) => | |
query[param] = null | |
@set 'isAdvanceOptionApplied', false | |
@setProperties query | |
#advance filter | |
openAdvanceOption: -> | |
@set 'advancedFilterClass', 'artistAdvancedFilter' | |
@set 'isAdvancedFilterOpen', true | |
hideAdvanceOption: -> | |
@set 'advancedFilterClass', 'artistAdvancedFilter hide' | |
@set 'isAdvancedFilterOpen', false | |
#end of advance filter | |
applyAdvanceOption: -> | |
@set 'isAdvanceOptionApplied', true | |
@send 'hideAdvanceOption' | |
@send 'searchArtists' | |
searchArtists: -> | |
query = {} | |
@get('queryParams').forEach (param) => | |
query[param] = @get("#{param.camelize()}Field") || null | |
ethnicities = @get('selectedEthnicities').mapBy('value') | |
query['qethnicity'] = ethnicities || null | |
questionIds = @get('selectedQuestionIds') | |
query['qquestion_ids'] = questionIds || null | |
questionAnswers = @get('selectedQuestionAnswers') | |
query['qquestion_answers'] = questionAnswers || null | |
@setProperties query |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment