Skip to content

Commit

Permalink
Implemented a more ajax callback approach to the dialogs. Still a WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Feb 23, 2012
1 parent 8008c5a commit 38edc9f
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 42 deletions.
22 changes: 21 additions & 1 deletion core/app/assets/javascripts/refinery/admin.js.erb
Expand Up @@ -95,6 +95,24 @@ init_modal_dialogs = function(){
});
};

refinery_dialog_success = function(e) {
close_dialog();

$.ajax({
url: window.location.pathname,
cache: false,
success: function(data) {
$('.pagination_container').html(data);

$('#flash_container > #flash').remove();
$('#flash_container').append($('.pagination_container').find('#flash'));

$('#flash').css({'width': 'auto', 'visibility': ''}).fadeIn(550);
init_ajaxy_pagination();
}
});
}

trigger_reordering = function(e, enable) {
$menu = $("#menu");
e.preventDefault();
Expand Down Expand Up @@ -972,7 +990,9 @@ close_dialog = function(e) {
the_body.removeClass('hide-overflow');
the_dialog.filter(':data(dialog)').dialog('close');
the_dialog.remove();
e.preventDefault();
if (e && e.preventDefault) {
e.preventDefault();
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion core/app/assets/javascripts/refinery/core.js
Expand Up @@ -10,7 +10,7 @@ init_flash_messages = function(){
'opacity': 0
, 'visibility':'visible'
}).animate({'opacity': '1'}, 550);
$('#flash_close').click(function(e) {
$('#flash_close').live('click', function(e) {
try {
$('#flash').animate({
'opacity': 0,
Expand Down
6 changes: 5 additions & 1 deletion core/app/controllers/refinery/fast_controller.rb
@@ -1,9 +1,13 @@
module ::Refinery
module Refinery
class FastController < ActionController::Base

def wymiframe
render :template => "/refinery/wymiframe", :layout => false
end

def message
render :partial => '/refinery/message', :layout => false
end

end
end
24 changes: 14 additions & 10 deletions core/app/views/layouts/refinery/admin_dialog.html.erb
@@ -1,13 +1,17 @@
<!DOCTYPE html>
<%= render '/refinery/html_tag' %>
<%= render '/refinery/admin/head' %>
<body id='dialog_container' class='dialog <%= I18n.locale %><%= ' wym_iframe_body' if params[:wymeditor].presence %>'>
<div id='tooltip_container'></div>
<div id="flash_container">
<%= render '/refinery/message' %>
</div>
<div id='content' class='clearfix'>
<%= yield %>
</div>
</body>
<% if @dialog_successful ||= params[:dialog_successful]%>
<%= render '/refinery/admin/dialog_success' %>
<% else %>
<%= render '/refinery/admin/head' %>
<body id='dialog_container' class='dialog <%= I18n.locale %><%= ' wym_iframe_body' if params[:wymeditor].presence %>'>
<div id='tooltip_container'></div>
<div id="flash_container">
<%= render '/refinery/message' %>
</div>
<div id='content' class='clearfix'>
<%= yield %>
</div>
</body>
<% end %>
</html>
1 change: 1 addition & 0 deletions core/app/views/layouts/refinery/flash.html.erb
@@ -0,0 +1 @@
<%= render '/refinery/message' if request.xhr? %>
7 changes: 2 additions & 5 deletions core/app/views/refinery/_message.html.erb
@@ -1,10 +1,7 @@
<% flash.each do |key, value| %>
<div id='flash' class="flash flash_<%= key %>" style='visibility: hidden;' >
<%= value %>
<% if key.to_s == "message" %>
<%= link_to t('.close_this_message'), "", {:id => "flash_close"} %>
<% else %>
<%= link_to t('.close'), "", {:id => "flash_close"} %>
<% end %>
<%= link_to t(".close#{'_this_message' if key.to_s == "message"}"), "",
:id => "flash_close" %>
</div>
<% end %>
3 changes: 3 additions & 0 deletions core/app/views/refinery/admin/_dialog_success.html.erb
@@ -0,0 +1,3 @@
<head>
<script>parent.refinery_dialog_success();</script>
</head>
5 changes: 3 additions & 2 deletions core/config/routes.rb
@@ -1,6 +1,7 @@
Refinery::Core::Engine.routes.draw do
filter(:refinery_locales) if defined?(RoutingFilter::RefineryLocales) # optionally use i18n.
match 'wymiframe(/:id)', :to => 'fast#wymiframe', :as => :wymiframe
get 'wymiframe(/:id)', :to => 'fast#wymiframe', :as => :wymiframe
get 'refinery/message', :to => 'fast#message', :as => :message

namespace :admin, :path => 'refinery' do
root :to => 'dashboard#index'
Expand All @@ -9,5 +10,5 @@

match '/refinery/update_menu_positions', :to => 'admin/refinery_core#update_plugin_positions'

match '/sitemap.xml' => 'sitemap#index', :defaults => { :format => 'xml' }
get '/sitemap.xml' => 'sitemap#index', :defaults => { :format => 'xml' }
end
2 changes: 1 addition & 1 deletion core/lib/refinery/admin/base_controller.rb
Expand Up @@ -24,7 +24,7 @@ def searching?
params[:search].present?
end

protected
protected

def group_by_date(records)
new_records = []
Expand Down
31 changes: 21 additions & 10 deletions core/lib/refinery/crud.rb
Expand Up @@ -75,7 +75,7 @@ def create
end
if (@#{singular_name} = #{class_name}.create(params[:#{singular_name}])).valid?
(request.xhr? ? flash.now : flash).notice = t(
flash.notice = t(
'refinery.crudify.created',
:what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'"
)
Expand All @@ -91,7 +91,9 @@ def create
end
end
else
redirect_back_or_default(#{options[:redirect_to_url]})
self.index
@dialog_successful = true
render :index
end
else
unless request.xhr?
Expand All @@ -111,7 +113,7 @@ def edit
def update
if @#{singular_name}.update_attributes(params[:#{singular_name}])
(request.xhr? ? flash.now : flash).notice = t(
flash.notice = t(
'refinery.crudify.updated',
:what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'"
)
Expand All @@ -127,7 +129,9 @@ def update
end
end
else
redirect_back_or_default(#{options[:redirect_to_url]})
self.index
@dialog_successful = true
render :index
end
else
unless request.xhr?
Expand Down Expand Up @@ -183,7 +187,7 @@ def paginate_all_#{plural_name}
# If the controller is being accessed via an ajax request
# then render only the collection of items.
def render_partial_response?
render :partial => '#{plural_name}' if request.xhr?
render :partial => '#{plural_name}' and return if request.xhr?
end
# Returns a weighted set of results based on the query specified by the user.
Expand Down Expand Up @@ -300,12 +304,19 @@ def update_child_positions(_node, #{singular_name})
end

module_eval %(
def self.sortable?
#{options[:sortable].to_s}
end
class << self
def pageable?
#{options[:paging].to_s}
end
alias_method :paging?, :pageable?
def self.searchable?
#{options[:searchable].to_s}
def sortable?
#{options[:sortable].to_s}
end
def searchable?
#{options[:searchable].to_s}
end
end
)

Expand Down
7 changes: 6 additions & 1 deletion images/app/controllers/refinery/admin/images_controller.rb
Expand Up @@ -55,7 +55,12 @@ def create
unless params[:insert]
if @images.all?(&:valid?)
flash.notice = t('created', :scope => 'refinery.crudify', :what => "'#{@images.map(&:title).join("', '")}'")
redirect_to refinery.admin_images_path
unless from_dialog?
redirect_to refinery.admin_images_path
else
@dialog_successful = true
render :nothing => true, :layout => true
end
else
self.new # important for dialogs
render :action => 'new'
Expand Down
4 changes: 2 additions & 2 deletions images/app/views/refinery/admin/images/_actions.html.erb
Expand Up @@ -3,7 +3,7 @@
<%= render '/refinery/admin/search', :url => refinery.admin_images_path %>
</li>
<li>
<%= link_to t('.create_new_image'), refinery.new_admin_image_path, :class => "add_icon" %>
<%= link_to t('.create_new_image'), refinery.new_admin_image_path(:dialog => true), :class => "add_icon" %>
</li>
<% other_image_views.each do |image_view| %>
<li>
Expand All @@ -12,4 +12,4 @@
:class => "reorder_icon" %>
</li>
<% end %>
</ul>
</ul>
2 changes: 1 addition & 1 deletion images/app/views/refinery/admin/images/_images.html.erb
@@ -1,2 +1,2 @@
<%= will_paginate @images %>
<%= will_paginate @images if Refinery::Admin::ImagesController.pageable? %>
<%= render "#{Refinery::Images.preferred_image_view}_view" %>
8 changes: 4 additions & 4 deletions pages/app/controllers/refinery/admin/pages_controller.rb
Expand Up @@ -29,21 +29,20 @@ def children

def preview
@menu_pages = ::Refinery::Menu.new(::Refinery::Page.fast_menu)
@page = find_page

if @page
if @page ||= page
# Preview existing pages
@page.attributes = params[:page]
present(@page)
render(:template => '/refinery/pages/show', :layout => 'preview') and return
render :template => '/refinery/pages/show', :layout => 'refinery/preview' and return
else
# Preview a non-persisted page
@page = Page.new(params[:page])
end

if @page.valid?
present(@page)
render :template => '/refinery/pages/show', :layout => 'preview'
render :template => '/refinery/pages/show', :layout => 'refinery/preview'
else
render :action => :edit
end
Expand All @@ -58,6 +57,7 @@ def find_page
Refinery::Page.find(params[:id])
end
end
alias_method :page, :find_page

# We can safely assume ::Refinery::I18n is defined because this method only gets
# Invoked when the before_filter from the plugin is run.
Expand Down
File renamed without changes.
Expand Up @@ -21,7 +21,12 @@ def create
unless params[:insert]
if @resources.all?(&:valid?)
flash.notice = t('created', :scope => 'refinery.crudify', :what => "'#{@resources.map(&:title).join("', '")}'")
redirect_to refinery.admin_resources_path
unless from_dialog?
redirect_to refinery.admin_resources_path
else
@dialog_successful = true
render :nothing => true, :layout => true
end
else
self.new # important for dialogs
render :action => 'new'
Expand Down
Expand Up @@ -3,6 +3,6 @@
<%= render '/refinery/admin/search', :url => refinery.admin_resources_path %>
</li>
<li>
<%= link_to t('.upload_new'), refinery.new_admin_resource_path, :class => "add_icon" %>
<%= link_to t('.upload_new'), refinery.new_admin_resource_path(:dialog => true), :class => "add_icon" %>
</li>
</ul>
Expand Up @@ -3,6 +3,6 @@
<%= render '/refinery/admin/search', :url => refinery.admin_settings_path %>
</li>
<li>
<%= link_to t('.new'), refinery.new_admin_setting_path, :class => "add_icon" %>
<%= link_to t('.new'), refinery.new_admin_setting_path(:dialog => true), :class => "add_icon" %>
</li>
</ul>

0 comments on commit 38edc9f

Please sign in to comment.