diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2015-10-09 21:04:00 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2015-10-09 21:04:00 +0200 |
commit | b65549d1e2f7df62c9f941ed92b00759351e0c5f (patch) | |
tree | efa6c513d8c251f0fd869e73c34dfa9c6d1686d8 | |
parent | bfc6d9a6ceed3a2ee9a38a1afa4dffec972eca83 (diff) | |
download | norsk-urskog-registrations-b65549d1e2f7df62c9f941ed92b00759351e0c5f.tar.gz norsk-urskog-registrations-b65549d1e2f7df62c9f941ed92b00759351e0c5f.tar.bz2 norsk-urskog-registrations-b65549d1e2f7df62c9f941ed92b00759351e0c5f.zip |
Use ajax to get member and song subforms.
This instead of hard coding them in javascript. We will need the forms as ruby/erb
templates anyways so no need to keep them two places.
-rw-r--r-- | public/regform.js | 56 | ||||
-rw-r--r-- | registration.rb | 8 | ||||
-rw-r--r-- | views/member.erb | 23 | ||||
-rw-r--r-- | views/song.erb | 48 |
4 files changed, 87 insertions, 48 deletions
diff --git a/public/regform.js b/public/regform.js index e620b04..42bbd58 100644 --- a/public/regform.js +++ b/public/regform.js @@ -2,58 +2,18 @@ $(function() { var num_members = 0; var num_songs = 0; - $('#add-member-button').click(function() { + $('#add-member-button').click(function(event) { num_members += 1; - $('#form-members').append( - '<div class="member-info">' + - ' <h4>Medlem nr. '+num_members+'<input type="button" name="delete" data-member="'+num_members+'" class="delete-member-button" value="X"></h4>' + - ' <div class="field text required">' + - ' <label for="band-member-'+num_members+'-name">Navn:</label>' + - ' <input type="text" id="band-member-'+num_members+'-name" name="band[members]['+num_members+'][name]">' + - ' </div>' + - ' <div class="field text optional">' + - ' <label>Instrument:</label>' + - ' <input type="text" name="band[members]['+num_members+'][instrument]">' + - ' </div>' + - ' <div class="field class optional">' + - ' <label>Alder:</label>' + - ' <input type="text" name="band[members]['+num_members+'][age]" size="3" pattern="[0-9]{1,2}">' + - ' </div>' + - '</div>' - ) + $.get('member/new/' + num_members, function(data) { + $('#form-members').append(data); + }); }); - $('#add-song-button').click(function() { + $('#add-song-button').click(function(event) { num_songs += 1; - $('#form-songs').append( - '<div class="song-info" id="song-'+num_songs+'-info">' + - ' <h4>Låt nr '+num_songs+'<input type="button" id="delete-song-'+num_songs+'" class="delete-song" value="X"></h4>' + - ' <div class="field text required">' + - ' <label for="band-song-'+num_songs+'-title">Tittel:</label>' + - ' <input type="text" id="band-song-'+num_songs+'-title" name="band[songs]['+num_songs+'][title]">' + - ' </div>' + - ' <div class="field text optional">' + - ' <label for="band-song-'+num_songs+'-time">Lengde:</label>' + - ' <input type="text" pattern="[0-9]{2}:[0-9]{2}" title="Spilletid i min:sek (mm:ss)" id="band-song-'+num_songs+'-time" name="band[songs]['+num_songs+'][time]" size="6">'+ - ' </div>' + - ' <div class="field text optional">' + - ' <label for="band-song-'+num_songs+'-isrc">ISRC-kode:</label>' + - ' <input type="text" title="Dersom låten har vært utgitt før har den en ISRC-kode. Om du vet den så oppgi den her." id="band-song-'+num_songs+'-isrc" name="band[songs]['+num_songs+'][isrc]" size="11">'+ - ' </div>' + - ' <div class="field textarea required">' + - ' <label for="band-song-'+num_songs+'-performers">Utøvere:</label>'+ - ' <textarea cols="40" rows="5" id="band-song-'+num_songs+'-performers" name="band[songs]['+num_songs+'][performers]" title="Fullt navn (ingen pseudonymer) på alle som er med på denne innspillingen."></textarea>' + - ' </div>' + - ' <div class="field textarea required">' + - ' <label for="band-song-'+num_songs+'-composers">Opphavsmenn:</label>'+ - ' <textarea cols="40" rows="5" id="band-song-'+num_songs+'-composers" name="band[songs]['+num_songs+'][composers]" title="Fullt navn (ingen pseudonymer) på alle som har vært med på å skrive denne låten."></textarea>' + - ' </div>' + - ' <div class="field textarea optional">' + - ' <label for="band-song-'+num_songs+'-notes">Andre merknader:</label>'+ - ' <textarea cols="40" rows="5" id="band-song-'+num_songs+'-notes" name="band[songs]['+num_songs+'][notes]" title="Evt andre ting vi burde vite."></textarea>' + - ' </div>' + - '</div>' - ) + $.get('song/new/' + num_songs, function(data) { + $('#form-songs').append(data); + }); }); }); diff --git a/registration.rb b/registration.rb index a62bc2b..e8ddd6f 100644 --- a/registration.rb +++ b/registration.rb @@ -14,6 +14,14 @@ class RegistrationApp < Sinatra::Base erb :index end + get '/member/new/:num' do + erb :member, :layout => false, :locals => { :member_number => params['num'] } + end + + get '/song/new/:num' do + erb :song, :layout => false, :locals => { :song_number => params['num'] } + end + post '/submit' do if request.form_data? #p request['band'] diff --git a/views/member.erb b/views/member.erb new file mode 100644 index 0000000..1e6e78e --- /dev/null +++ b/views/member.erb @@ -0,0 +1,23 @@ +<div class="member-info"> + <h4> + Medlem nr. <%= member_number %> + <input type="button" name="delete" data-member="<%= member_number %>" + class="delete-member-button" value="X"> + </h4> + <div class="field text required"> + <label for="band-member-<%= member_number %>-name">Navn:</label> + <input type="text" id="band-member-<%= member_number %>-name" + name="band[members][<%= member_number %>][name]"> + </div> + <div class="field text optional"> + <label for="band-member-<%= member_number %>-instrument">Instrument:</label> + <input type="text" id="band-member-<%= member_number %>-instrument" + name="band[members][<%= member_number %>][instrument]"> + </div> + <div class="field class optional"> + <label for="band-member-<%= member_number %>-age">Alder:</label> + <input type="text" for="band-member-<%= member_number %>-age" + name="band[members][<%= member_number %>][age]" + size="3" pattern="[0-9]{1,2}"> + </div> +</div> diff --git a/views/song.erb b/views/song.erb new file mode 100644 index 0000000..a217d97 --- /dev/null +++ b/views/song.erb @@ -0,0 +1,48 @@ +<div class="song-info" id="song-<%= song_number %>-info"> + <h4> + Låt nr <%= song_number %> + <input type="button" id="delete-song-<%= song_number %>" class="delete-song" value="X"> + </h4> + <div class="field text required"> + <label for="band-song-<%= song_number %>-title">Tittel:</label> + <input type="text" id="band-song-<%= song_number %>-title" + name="band[songs][<%= song_number %>][title]"> + </div> + <div class="field text optional"> + <label for="band-song-<%= song_number %>-time">Lengde:</label> + <input type="text" pattern="[0-9]{2}:[0-9]{2}" + title="Spilletid i min:sek (mm:ss)" + id="band-song-<%= song_number %>-time" + name="band[songs][<%= song_number %>][time]" + size="6"> + </div> + <div class="field text optional"> + <label for="band-song-<%= song_number %>-isrc">ISRC-kode:</label> + <input type="text" + title="Dersom låten har vært utgitt før har den en ISRC-kode. Om du vet den så oppgi den her." + id="band-song-<%= song_number %>-isrc" + name="band[songs][<%= song_number %>][isrc]" + size="11"> + </div> + <div class="field textarea required"> + <label for="band-song-<%= song_number %>-performers">Utøvere:</label> + <textarea cols="40" rows="5" id="band-song-<%= song_number %>-performers" + name="band[songs][<%= song_number %>][performers]" + title="Fullt navn (ingen pseudonymer) på alle som er med på denne innspillingen."> + </textarea> + </div> + <div class="field textarea required"> + <label for="band-song-<%= song_number %>-composers">Opphavsmenn:</label> + <textarea cols="40" rows="5" id="band-song-<%= song_number %>-composers" + name="band[songs][<%= song_number %>][composers]" + title="Fullt navn (ingen pseudonymer) på alle som har vært med på å skrive denne låten."> + </textarea> + </div> + <div class="field textarea optional"> + <label for="band-song-<%= song_number %>-notes">Andre merknader:</label> + <textarea cols="40" rows="5" id="band-song-<%= song_number %>-notes" + name="band[songs][<%= song_number %>][notes]" + title="Evt andre ting vi burde vite."> + </textarea> + </div> +</div> |