Permalink
Browse files

Implemented a more ajax callback approach to the dialogs. Still a WIP

  • Loading branch information...
1 parent 8008c5a commit 38edc9f32a2efb18f0fe704903c648d8c1dbd98d @parndt parndt committed Feb 23, 2012
@@ -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();
@@ -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();
+ }
}
};
@@ -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,
@@ -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
@@ -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>
@@ -0,0 +1 @@
+<%= render '/refinery/message' if request.xhr? %>
@@ -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 %>
@@ -0,0 +1,3 @@
+<head>
+ <script>parent.refinery_dialog_success();</script>
+</head>
View
@@ -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'
@@ -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
@@ -24,7 +24,7 @@ def searching?
params[:search].present?
end
- protected
+ protected
def group_by_date(records)
new_records = []
View
@@ -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]}}'"
)
@@ -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?
@@ -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]}}'"
)
@@ -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?
@@ -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.
@@ -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
)
@@ -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'
@@ -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>
@@ -12,4 +12,4 @@
:class => "reorder_icon" %>
</li>
<% end %>
-</ul>
+</ul>
@@ -1,2 +1,2 @@
-<%= will_paginate @images %>
+<%= will_paginate @images if Refinery::Admin::ImagesController.pageable? %>
<%= render "#{Refinery::Images.preferred_image_view}_view" %>
@@ -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
@@ -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.
@@ -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'
@@ -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>
@@ -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.