From b65549d1e2f7df62c9f941ed92b00759351e0c5f Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 9 Oct 2015 21:04:00 +0200 Subject: 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. --- public/regform.js | 56 ++++++++----------------------------------------------- registration.rb | 8 ++++++++ views/member.erb | 23 +++++++++++++++++++++++ views/song.erb | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 48 deletions(-) create mode 100644 views/member.erb create mode 100644 views/song.erb 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( - '
' + - '

Medlem nr. '+num_members+'

' + - '
' + - ' ' + - ' ' + - '
' + - '
' + - ' ' + - ' ' + - '
' + - '
' + - ' ' + - ' ' + - '
' + - '
' - ) + $.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( - '
' + - '

Låt nr '+num_songs+'

' + - '
' + - ' ' + - ' ' + - '
' + - '
' + - ' ' + - ' '+ - '
' + - '
' + - ' ' + - ' '+ - '
' + - '
' + - ' '+ - ' ' + - '
' + - '
' + - ' '+ - ' ' + - '
' + - '
' + - ' '+ - ' ' + - '
' + - '
' - ) + $.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 @@ +
+

+ Medlem nr. <%= member_number %> + +

+
+ + +
+
+ + +
+
+ + +
+
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 @@ +
+

+ Låt nr <%= song_number %> + +

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
-- cgit v1.2.3