Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Changed the way the UI updates.
Browse files Browse the repository at this point in the history
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
mjm committed Apr 21, 2012
1 parent 66a122f commit 1af1c9a
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 94 deletions.
51 changes: 0 additions & 51 deletions 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 -> $(document).ready ->
$('#add-place').on 'show', (e) -> $('#add-place').on 'show', (e) ->
$('#place_name').val '' $('#place_name').val ''
$('#place_notes').val '' $('#place_notes').val ''
$('#place_walkable').removeAttr 'checked' $('#place_walkable').removeAttr 'checked'
$('select', $(e.target)).val '' $('select', $(e.target)).val ''
# createAddPlaceDialog()
# createEditPlaceDialog()
# createCommentDialog()
11 changes: 8 additions & 3 deletions app/assets/javascripts/bootstrapped.coffee
@@ -1,3 +1,8 @@
$('#container').tooltip window.updatePlaces = ->
selector: 'a[rel="tooltip"]', $.get '/periodic', (data) ->
placement: 'right' $('#places').html(data)

$(document).ready ->
$('#container').tooltip
selector: 'a[rel="tooltip"]',
placement: 'right'
8 changes: 1 addition & 7 deletions app/controllers/places_controller.rb
Expand Up @@ -22,8 +22,6 @@ def periodic


def create def create
@place = Place.create(params[:place].merge(:person => @current_user)) @place = Place.create(params[:place].merge(:person => @current_user))
load_places_data

respond_with(@place) respond_with(@place)
end end


Expand All @@ -35,16 +33,12 @@ def update
@place = @current_user.places.find(params[:id]) @place = @current_user.places.find(params[:id])
@place.attributes = params[:place] @place.attributes = params[:place]
@place.save @place.save

load_places_data
end end


def destroy def destroy
@place = Place.first(:conditions => {:id => params[:id], :person_id => @current_user}) @place = Place.first(:conditions => {:id => params[:id], :person_id => @current_user})
@place.destroy @place.destroy


load_places_data

respond_with(@place) respond_with(@place)
end end


Expand Down
5 changes: 0 additions & 5 deletions app/controllers/votes_controller.rb
Expand Up @@ -5,7 +5,6 @@ class VotesController < ApplicationController
def create def create
Vote.destroy_all(:person_id => @current_user.id) Vote.destroy_all(:person_id => @current_user.id)
@vote = Vote.create(:person => @current_user, :place_id => params[:place], :car_id => params[:car]) @vote = Vote.create(:person => @current_user, :place_id => params[:place], :car_id => params[:car])
load_places_data


respond_with(@vote) respond_with(@vote)
end end
Expand All @@ -19,17 +18,13 @@ def update
@vote.attributes = params[:vote] @vote.attributes = params[:vote]
@vote.save @vote.save


load_places_data

respond_with(@vote) respond_with(@vote)
end end


def destroy def destroy
@vote = Vote.find(params[:id]) @vote = Vote.find(params[:id])
@vote.destroy @vote.destroy


load_places_data

respond_with(@vote) respond_with(@vote)
end end
end end
1 change: 1 addition & 0 deletions app/views/cars/save.js.erb
@@ -1,4 +1,5 @@
<% if @current_car.valid? %> <% if @current_car.valid? %>
updatePlaces();
$('#options').modal('hide'); $('#options').modal('hide');
<%= js_notice t('.success') %> <%= js_notice t('.success') %>
<% else %> <% else %>
Expand Down
7 changes: 2 additions & 5 deletions app/views/places/create.js.erb
@@ -1,10 +1,7 @@
<% if @place.valid? %> <% if @place.valid? %>
$('#places') updatePlaces();
.trigger('beforeupdate')
.html('<%= escape_javascript(render :partial => "places") %>')
.trigger('update');
$('#add-place').modal('hide'); $('#add-place').modal('hide');
<%= js_notice t('.success', :name => @place.name) %> <%= js_notice t('.success', :name => @place.name) %>
<% else %> <% else %>
<%= js_error @place %> <%= js_error @place %>
<% end %> <% end %>
7 changes: 2 additions & 5 deletions app/views/places/destroy.js.erb
@@ -1,5 +1,2 @@
$('#places') updatePlaces();
.trigger('beforeupdate') <%= js_notice t('.success', :name => @place.name) %>
.html('<%= escape_javascript(render :partial => "places") %>')
.trigger('update');
<%= js_notice t('.success', :name => @place.name) %>
7 changes: 2 additions & 5 deletions app/views/places/update.js.erb
@@ -1,10 +1,7 @@
<% if @place.valid? %> <% if @place.valid? %>
$('#places') updatePlaces();
.trigger('beforeupdate')
.html('<%= escape_javascript(render :partial => "places") %>')
.trigger('update');
$('#edit-place').modal('hide'); $('#edit-place').modal('hide');
<%= js_notice t('.success', :name => @place.name) %> <%= js_notice t('.success', :name => @place.name) %>
<% else %> <% else %>
<%= js_error @place %> <%= js_error @place %>
<% end %> <% end %>
1 change: 1 addition & 0 deletions app/views/votes/_vote.html.erb
Expand Up @@ -3,6 +3,7 @@
<%= f.text_area :comment, rows: 6, placeholder: t('.placeholder') %> <%= f.text_area :comment, rows: 6, placeholder: t('.placeholder') %>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn" data-dismiss="close">Cancel</button>
<%= f.submit class: 'btn btn-primary' %> <%= f.submit class: 'btn btn-primary' %>
</div> </div>
<% end %> <% end %>
5 changes: 1 addition & 4 deletions app/views/votes/create.js.erb
@@ -1,8 +1,5 @@
<% if @vote.valid? %> <% if @vote.valid? %>
$('#places') updatePlaces();
.trigger('beforeupdate')
.html('<%= escape_javascript(render partial: "places/places") %>')
.trigger('update');
<%= js_notice t('.success', :name => @vote.place.name) %> <%= js_notice t('.success', :name => @vote.place.name) %>
<% else %> <% else %>
<%= js_error @vote %> <%= js_error @vote %>
Expand Down
7 changes: 2 additions & 5 deletions app/views/votes/destroy.js.erb
@@ -1,5 +1,2 @@
$('#places') updatePlaces();
.trigger('beforeupdate') <%= js_notice t('.success', :name => @vote.place.name) %>
.html('<%= escape_javascript(render :partial => "places/places") %>')
.trigger('update');
<%= js_notice t('.success', :name => @vote.place.name) %>
5 changes: 1 addition & 4 deletions app/views/votes/update.js.erb
@@ -1,7 +1,4 @@
$('#places') updatePlaces();
.trigger('beforeupdate')
.html('<%= escape_javascript(render :partial => "places/places") %>')
.trigger('update');
<% if @vote.valid? %> <% if @vote.valid? %>
$('#comment').modal('hide'); $('#comment').modal('hide');
<%= js_notice t('.success') %> <%= js_notice t('.success') %>
Expand Down

0 comments on commit 1af1c9a

Please sign in to comment.