Skip to content

Commit

Permalink
Steps to AlternateValue JavaScript links. Serial AddAlternateValue an…
Browse files Browse the repository at this point in the history
…d RemoveAlternateValue links.
  • Loading branch information
TuckerJD committed Oct 23, 2014
1 parent 6fd07c6 commit 5fab5cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
26 changes: 13 additions & 13 deletions app/assets/javascripts/alternate_values.js.coffee
Expand Up @@ -4,34 +4,34 @@
# You can use CoffeeScript in this file: http://coffeescript.org/

destroy_record = (dr_link) ->
$(dr_link).prev(".destroy_field").attr "value", "1"
$(dr_link).closest(".alternate_value_record").hide()
$(dr_link).prev('.destroy_field').attr "value", "1"
$(dr_link).closest('.alternate-value-record').hide()
return

remove_record = (rr_link) ->
$(rr_link).prev(".destroy_field").attr "value", "1"
$(rr_link).closest(".fields").hide()
return

edit_record = (ef_link) ->
$(ef_link).prev(".edit_field").attr "value", "1"
$(ef_link).closest(".fields").hide()
edit_record = (er_link) ->
$(er_link).prev(".edit_field").attr "value", "1"
$(er_link).closest(".fields").hide()
return

add_record = (af_link) ->
a_record = (ar_link) ->
new_id = new Date().getTime()
regexp = new RegExp("new_" + association, "g")
$(af_link).prev().insertBefore content.replace(regexp, new_id)
$(ar_link).prev().insertBefore content.replace(regexp, new_id)
return

a_record = (af_link) ->
add_record = (ar_link) ->
# af_link.attributes.content.value or $(af_link).attr('content')
content = $(af_link).attr("content")
association = $(af_link).attr("association")
content = $(ar_link).attr("content")
association = $(ar_link).attr("association")
new_id = new Date().getTime()
regex = new RegExp("new_" + association, "g")
content = content.replace(regex, new_id)
$(content).insertBefore $(af_link)
$(content).insertBefore $(ar_link)
return

bind_alternate_value_remove = (link) ->
Expand All @@ -51,7 +51,7 @@ $(document).on 'ready page:load', ->

$(".alternate-value-add").click (event) ->
# alert "Add alternate_value by link_id."
a_record(this)
add_record(this)
bind_alternate_value_remove(this)
event.preventDefault() # Prevent link from following its href
return
Expand All @@ -64,7 +64,7 @@ $(document).on 'ready page:load', ->
return

$(".alternate-value-remove").click (event) ->
alert "remove alternate_value by link_id."
# alert "remove alternate_value by link_id."
destroy_record(this)
event.preventDefault() # Prevent link from following its href
return
Expand Down
22 changes: 9 additions & 13 deletions app/views/alternate_values/_alternate_value_fields.html.erb
@@ -1,9 +1,10 @@
<div class="alternate-value-record">
<div class="hide-for-display">
---------------AV Separator ----------------------------------------------------
Start---------------AV Separator ----------------------------------------------------
</div>
<div class="field">
<%= object_tag(avf.object.alternate_object) %>
<%#= "#{avf.object.class.to_s}: " %>
<%#= object_tag(avf.object.alternate_object) %>
</div>
<div class="field">
<%= avf.label :alternate_value %>
Expand All @@ -22,22 +23,17 @@
<br>
<%= avf.number_field :language_id %>
</div>
<div class="field">
<%= avf.label :alternate_object_type %>
<br>
<%= avf.text_field :alternate_object_type %>
</div>
<!--<div class="field">-->
<!--<%#= avf.label :alternate_object_id %>-->
<!--<br>-->
<!--<%#= avf.number_field :alternate_object_id %>-->
<!--</div>-->
<div class="field">
<%= avf.label :alternate_object_attribute %>
<br>
<%= avf.select :alternate_object_attribute, options_for_select(avf.object.alternate_object.class.attribute_names.map(&:to_sym) - NON_ANNOTATABLE_COLUMNS, selected = avf.object.alternate_object_attribute) -%>
</div>

<%#= avf.hidden_field :alternate_object_type %>
<%= avf.hidden_field :alternate_object_id %>

<div class="hide-for-display">
---------------AV Separator ----------------------------------------------------
--------------------AV Separator -------------------------------------------------End
</div>
</div>
8 changes: 4 additions & 4 deletions app/views/serials/show.html.erb
Expand Up @@ -21,10 +21,10 @@
<% for alternate_value in @serial.alternate_values.order('type') %>
<li>
<%= "Type: #{alternate_value.type.gsub('AlternateValue::', '')}, Value: '#{alternate_value.value}', Attribute: '#{alternate_value.alternate_object_attribute}'" %>
<%= edit_alternate_value_link(alternate_value) %>
<%= link_to_edit_alternate_value('jsEdit', alternate_value) %>
<%= destroy_alternate_value_link(alternate_value) %>
<%= link_to_destroy_alternate_value('jsDestroy', alternate_value) %>
<%#= edit_alternate_value_link(alternate_value) %>
<%#= link_to_edit_alternate_value('jsEdit', alternate_value) %>
<%#= destroy_alternate_value_link(alternate_value) %>
<%#= link_to_destroy_alternate_value('jsDestroy', alternate_value) %>
</li>
<% end %>
</ol>
Expand Down

0 comments on commit 5fab5cb

Please sign in to comment.