Skip to content

Instantly share code, notes, and snippets.

@Neonik47
Created August 4, 2017 15:39
Show Gist options
  • Save Neonik47/e3b2aef70432959871249c9386e325cc to your computer and use it in GitHub Desktop.
Save Neonik47/e3b2aef70432959871249c9386e325cc to your computer and use it in GitHub Desktop.
class SearchByDocType
constructor: () ->
doc_type_select_listener()
doc_type_select_listener = () ->
def = new SearchByDocType.Default
first_type = new SearchByDocType.FirstType
second_type = new SearchByDocType.SecondType
if $('#document_type').length > 0
$('#document_type').on 'change', () ->
selected_val = $(this).val()
selected = switch selected_val
when 'default', ''
def
when 'first_type'
first_type
when 'second_type'
second_type
else
alert 'Не настроены правила для данного типа документа!'
def
selected.set_up_new_fields()
$('#document_type').trigger 'change'
else
def.set_up_new_fields()
class SearchByDocType.Base
fieldsets: () ->
{
basics_fieldset: $('#basics_fieldset'),
first_fieldset: $('#identity_cards_fieldset'),
second_fieldset: $('#addresses_fieldset'),
}
field_listener: () ->
that = this
@fieldset.on 'change', that.main_validate.bind(that)
main_validate: () ->
@fieldset.length > 1
set_up_new_fields: () ->
that = this
@fieldset().each -> that.main_validate(this)
class SearchByDocType.Default extends SearchByDocType.Base
constructor: () ->
@fieldset = @fieldsets.first_fieldset
field_listener()
main_validate: (fieldset) ->
console.log 'Default Main Validate' if fieldset.length > 3
class SearchByDocType.FirstType extends SearchByDocType.Base
constructor: () ->
@fieldset = @fieldsets.basics_fieldset
field_listener()
main_validate: () ->
console.log 'FirstType Main Validate' if fieldset.length > 5
class SearchByDocType.SecondType extends SearchByDocType.Base
constructor: () ->
@fieldset = @fieldsets.second_fieldset
field_listener()
main_validate: (fieldset) ->
console.log 'SecondType Main Validate' if fieldset.length > 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment