Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed the way the UI updates.

Any action that needs the UI to update tells the client to make a
request for new data instead of supplying the data itself. This will
make it easier to preserve UI state for auto-updates.
  • Loading branch information...
commit 1af1c9a2afb55afc4ad8bdaf020a49bf0e2634bb 1 parent 66a122f
@mjm authored
View
51 app/assets/javascripts/application/place_dialog.coffee
@@ -1,57 +1,6 @@
-createAddPlaceDialog = ->
- addDialog = $('#add-place-dialog')
- addForm = addDialog.find 'form'
-
- placeNameField = $('#place_name')
- notesField = $('#place_notes')
- walkingField = $('#place_walkable')
- timeFields = $('#add-place-dialog select')
- submitButton = $('#add-place-dialog input[type=submit]')
-
- addDialog.dialog
- autoOpen: false
- modal: true
- title: $('#add-place').text()
- resizable: false
- buttons: [{
- text: submitButton.val()
- click: ->
- addForm.submit()
- }]
- open: ->
- placeNameField.val ''
- notesField.val ''
- timeFields.val ''
- walkingField.removeAttr 'checked'
- placeNameField.focus()
-
- $('#add-place').button(icons: {primary:"ui-icon-plusthick"}).click ->
- addDialog.dialog 'open'
-
- submitButton.hide()
-
-createEditPlaceDialog = ->
- editDialog = $('#edit-place-dialog')
- editDialog.dialog
- autoOpen: false
- modal: true
- title: editDialog.attr('title')
- resizable: false
-
-createCommentDialog = ->
- commentDialog = $('#comment-dialog')
- commentDialog.dialog
- autoOpen: false
- modal: true
- title: commentDialog.attr('title')
- resizable: false
-
$(document).ready ->
$('#add-place').on 'show', (e) ->
$('#place_name').val ''
$('#place_notes').val ''
$('#place_walkable').removeAttr 'checked'
$('select', $(e.target)).val ''
-# createAddPlaceDialog()
-# createEditPlaceDialog()
-# createCommentDialog()
View
11 app/assets/javascripts/bootstrapped.coffee
@@ -1,3 +1,8 @@
-$('#container').tooltip
- selector: 'a[rel="tooltip"]',
- placement: 'right'
+window.updatePlaces = ->
+ $.get '/periodic', (data) ->
+ $('#places').html(data)
+
+$(document).ready ->
+ $('#container').tooltip
+ selector: 'a[rel="tooltip"]',
+ placement: 'right'
View
8 app/controllers/places_controller.rb
@@ -22,8 +22,6 @@ def periodic
def create
@place = Place.create(params[:place].merge(:person => @current_user))
- load_places_data
-
respond_with(@place)
end
@@ -35,16 +33,12 @@ def update
@place = @current_user.places.find(params[:id])
@place.attributes = params[:place]
@place.save
-
- load_places_data
end
def destroy
@place = Place.first(:conditions => {:id => params[:id], :person_id => @current_user})
@place.destroy
-
- load_places_data
-
+
respond_with(@place)
end
View
5 app/controllers/votes_controller.rb
@@ -5,7 +5,6 @@ class VotesController < ApplicationController
def create
Vote.destroy_all(:person_id => @current_user.id)
@vote = Vote.create(:person => @current_user, :place_id => params[:place], :car_id => params[:car])
- load_places_data
respond_with(@vote)
end
@@ -19,8 +18,6 @@ def update
@vote.attributes = params[:vote]
@vote.save
- load_places_data
-
respond_with(@vote)
end
@@ -28,8 +25,6 @@ def destroy
@vote = Vote.find(params[:id])
@vote.destroy
- load_places_data
-
respond_with(@vote)
end
end
View
1  app/views/cars/save.js.erb
@@ -1,4 +1,5 @@
<% if @current_car.valid? %>
+ updatePlaces();
$('#options').modal('hide');
<%= js_notice t('.success') %>
<% else %>
View
7 app/views/places/create.js.erb
@@ -1,10 +1,7 @@
<% if @place.valid? %>
-$('#places')
- .trigger('beforeupdate')
- .html('<%= escape_javascript(render :partial => "places") %>')
- .trigger('update');
+updatePlaces();
$('#add-place').modal('hide');
<%= js_notice t('.success', :name => @place.name) %>
<% else %>
<%= js_error @place %>
-<% end %>
+<% end %>
View
7 app/views/places/destroy.js.erb
@@ -1,5 +1,2 @@
-$('#places')
- .trigger('beforeupdate')
- .html('<%= escape_javascript(render :partial => "places") %>')
- .trigger('update');
-<%= js_notice t('.success', :name => @place.name) %>
+updatePlaces();
+<%= js_notice t('.success', :name => @place.name) %>
View
7 app/views/places/update.js.erb
@@ -1,10 +1,7 @@
<% if @place.valid? %>
-$('#places')
- .trigger('beforeupdate')
- .html('<%= escape_javascript(render :partial => "places") %>')
- .trigger('update');
+updatePlaces();
$('#edit-place').modal('hide');
<%= js_notice t('.success', :name => @place.name) %>
<% else %>
<%= js_error @place %>
-<% end %>
+<% end %>
View
1  app/views/votes/_vote.html.erb
@@ -3,6 +3,7 @@
<%= f.text_area :comment, rows: 6, placeholder: t('.placeholder') %>
</div>
<div class="modal-footer">
+ <button class="btn" data-dismiss="close">Cancel</button>
<%= f.submit class: 'btn btn-primary' %>
</div>
<% end %>
View
5 app/views/votes/create.js.erb
@@ -1,8 +1,5 @@
<% if @vote.valid? %>
-$('#places')
- .trigger('beforeupdate')
- .html('<%= escape_javascript(render partial: "places/places") %>')
- .trigger('update');
+updatePlaces();
<%= js_notice t('.success', :name => @vote.place.name) %>
<% else %>
<%= js_error @vote %>
View
7 app/views/votes/destroy.js.erb
@@ -1,5 +1,2 @@
-$('#places')
- .trigger('beforeupdate')
- .html('<%= escape_javascript(render :partial => "places/places") %>')
- .trigger('update');
-<%= js_notice t('.success', :name => @vote.place.name) %>
+updatePlaces();
+<%= js_notice t('.success', :name => @vote.place.name) %>
View
5 app/views/votes/update.js.erb
@@ -1,7 +1,4 @@
-$('#places')
- .trigger('beforeupdate')
- .html('<%= escape_javascript(render :partial => "places/places") %>')
- .trigger('update');
+updatePlaces();
<% if @vote.valid? %>
$('#comment').modal('hide');
<%= js_notice t('.success') %>
Please sign in to comment.
Something went wrong with that request. Please try again.