Permalink
Browse files

Extended some admin views and changed integration tests

  • Loading branch information...
1 parent 6b587c9 commit 24bc8579dccafbe85e6397ce4a23fea8430fd8f5 @wlodars wlodars committed Jul 23, 2008
@@ -15,25 +15,28 @@ def show
# POST /admin/categories
def create
- @category = Category.new(:name => 'New category',
- :value => "newcategory#{Category.last.id + 1}")
- flash_notice("Category has been added")
+ begin
+ @category = Category.new(:name => 'New category',
+ :value => "newcategory#{rand(Time.now)}")
+ @category.save!
+ rescue ActiveRecord::RecordInvalid
+ retry
+ end
+ flash.now[:notice] = "Category has been added"
respond_to do |format|
- if @category.save
- format.html { redirect_to admin_categories_url }
- format.js # admin/categories/create.js.rjs
- end
+ format.html { redirect_to admin_categories_url }
+ format.js # admin/categories/create.js.rjs
end
end
# PUT /admin/categories/1
def update
@category = Category.find(params[:id])
- flash_notice("Category has been updated")
respond_to do |format|
if @category.update_attributes(:name => params[:name], :value => params[:url])
+ flash.now[:notice] = "Category has been updated"
format.html { redirect_to admin_categories_url }
format.js # admin/categories/update.js.rjs
else
@@ -43,7 +46,7 @@ def update
@category.reload
page.alert @category.errors.full_messages.join("\n")
page.replace(@category.dom_id, :partial => 'admin/categories/category', :category => @category)
- page.sortable 'categoriesContainer', :tag => 'div', :url => saveorder_admin_categories_path
+ page.sortable "categoriesContainer", sortable_categories_container_options
end
}
end
@@ -56,7 +59,7 @@ def saveorder
category = Category.find(id)
category.update_attribute('position', position + 1)
end
- flash_notice("Categories order changed. Saving ...")
+ flash.now[:notice] = "Categories order changed. Saving ..."
respond_to do |format|
format.html { redirect_to admin_categories_url }
@@ -70,7 +73,7 @@ def destroy
if @category.jobs.empty?
@category.destroy
- flash_notice("Category has been deleted")
+ flash.now[:notice] = "Category has been deleted"
end
respond_to do |format|
@@ -15,10 +15,10 @@ def show
# PUT /admin/jobs/1
def update
@job = Job.find(params[:id])
- flash_notice("Job has been activated/deactivated")
respond_to do |format|
if @job.update_attributes(:is_active => @job.is_active ? false : true)
+ flash.now[:notice] = @job.is_active ? "Job has been activated" : "Job has been deactivated"
format.html { redirect_to admin_jobs_url }
format.js # admin/jobs/update.js.rjs
end
@@ -29,7 +29,7 @@ def update
def destroy
@job = Job.find(params[:id])
@job.destroy
- flash_notice("Job has been deleted")
+ flash.now[:notice] = "Job has been deleted"
respond_to do |format|
format.html { redirect_to admin_jobs_url }
@@ -73,7 +73,7 @@ def update
def destroy
@page = Page.find_by_url(params[:id])
@page.destroy
- flash_notice("Page has been deleted")
+ flash.now[:notice] = "Page has been deleted"
respond_to do |format|
format.html { redirect_to(admin_pages_url) }
@@ -20,11 +20,6 @@ def login_required
redirect_to login_url
end
end
-
- def flash_notice(string)
- flash[:notice] = string
- flash.discard(:notice)
- end
protected
def production?
@@ -15,7 +15,7 @@ def create
redirect_to admin_url
else
flash[:error] = "Invalid login or password!"
- redirect_to login_url
+ render :action => "new"
end
end
@@ -11,31 +11,36 @@ def link_to_delete_category(category)
link_to_remote(image_tag("icon-delete.png", :alt => 'Delete') + " Delete", {
:url => admin_category_url(category.id),
:confirm => 'Are you sure you want to delete this category?',
- :method => :delete },
+ :method => :delete,
+ :loading => "showOverlay('#{category.dom_id}');",
+ :complete => "Element.hide('overlay');" },
{ :class => 'deleteCategory'})
end
def link_to_save_category(category)
link_to_remote(image_tag("disk.png", :alt => 'Save') + " Save", {
:url => admin_category_url(category.id),
:method => :put,
- :with => "'name='+$F('#{category.dom_id("name")}')+'&url='+$F('#{category.dom_id("url")}')" },
+ :with => "'name='+$F('#{category.dom_id("name")}')+'&url='+$F('#{category.dom_id("url")}')",
+ :loading => "showOverlay('#{category.dom_id}');",
+ :complete => "Element.hide('overlay');" },
{ :id => "#{category.dom_id("save")}",
:class => 'saveCategory', :style => 'display:none;' })
end
- def sortable_element_categories_container
- sortable_element "categoriesContainer",
- :url => saveorder_admin_categories_path,
+ def sortable_categories_container_options
+ {:url => saveorder_admin_categories_path,
:tag => "div",
- :complete => visual_effect(:highlight, 'categoriesContainer')
+ :handle => "categoryHandle",
+ :loading => "showOverlay('categoriesContainer');",
+ :complete => "Element.hide('overlay');"}
end
def link_to_add_category
link_to_remote image_tag("add.png", :alt => 'Add') + " Add new category",
:url => admin_categories_path,
:method => :post,
- :loading => "Element.show('overlay')",
- :complete => "Element.hide('overlay');"
+ :loading => "Element.show('add-category-overlay')",
+ :complete => "Element.hide('add-category-overlay');"
end
end
@@ -24,7 +24,7 @@ def error_message_for(record, attribute, error_msg = nil)
end
def display_notice
- page.insert_html :after, 'footer', :partial => 'layouts/admin_flash_boxes'
+ page.replace_html "messagesContainer", :partial => 'layouts/admin_flash_boxes'
end
# Additional View Helpers
@@ -51,4 +51,18 @@ def link_to_image(image_path, label, url, options={})
nbsp +
link_to(label, url, options)
end
+
+ def navigation_list(links)
+ link_html = ''
+ links.each do |link|
+ link_html << content_tag('li', link_to(link[:text], link[:url]),
+ add_class_if(current_section(link[:url]), 'selected'))
+ end
+ content_tag('ul', link_html, :id => "nav-admin")
+ end
+
+ private
+ def current_section(link)
+ @controller.controller_path == link.sub(/\//, "")
+ end
end
@@ -4,7 +4,8 @@ class Category < ActiveRecord::Base
validates_presence_of :name, :value
validates_uniqueness_of :value
- validates_format_of :value, :with => /^[-a-z0-9_]{4,20}$/
+ validates_length_of :value, :within => 4..30
+ validates_format_of :value, :with => /^[-a-z0-9_]{4,30}$/
def to_param
self.value
@@ -1,6 +1,5 @@
page.insert_html :bottom, 'categoriesContainer', :partial => 'admin/categories/category'
-page.sortable 'categoriesContainer', :tag => 'div', :url => saveorder_admin_categories_path,
- :complete => visual_effect(:highlight, 'categoriesContainer')
+page.sortable "categoriesContainer", sortable_categories_container_options
@category = nil
page.replace_html "categories", :partial => 'admin/categories/list'
page.display_notice
@@ -3,9 +3,9 @@
#categoriesContainer
= partial @categories
-= sortable_element "categoriesContainer", :url => saveorder_admin_categories_path, :tag => "div", :complete => visual_effect(:highlight, 'categoriesContainer')
+= sortable_element "categoriesContainer", sortable_categories_container_options
-#overlay{:style => "display: none; top: 145px; left: 157px;height: 72px;"}
+#add-category-overlay{:style => "display: none; top: 145px; left: 157px;height: 72px;"}
= image_tag("ajax-loader.gif", :alt => "Loading...")
%p
= link_to_add_category
@@ -1,14 +1,7 @@
#header
%h1#logo= link_to AppConfig.site_name, root_path
- if logged_in?
- %ul#top{:style => 'padding-top:40px'}
- %li= link_to "Pages", admin_pages_path
- = bull
- %li= link_to "Categories", admin_categories_path
- = bull
- %li= link_to "Change your password", "#"
- = bull
- %li= link_to "Logout", logout_path
+ = navigation_list [{:text => 'Pages', :url => admin_pages_path}, {:text => 'Categories', :url => admin_categories_path}, {:text => "Change your password", :url => "#"}, {:text => "Logout »", :url => logout_path}]
- unless logged_in?
#categs-nav
@@ -22,6 +22,9 @@
#content
= yield
-
+
+ #overlay{:style => 'display:none'}
+ = image_tag("ajax-loader.gif", :alt => "Loading...")
+ #messagesContainer= render :partial => 'layouts/admin_flash_boxes'
#footer
- = render :partial => 'layouts/admin_flash_boxes'
+
@@ -0,0 +1,29 @@
+$j(document).ready(function() {
+ $j("div.categoryHandle").mousedown(function() {
+ $j(this).fadeTo(500, 0.4).addClass('draggingItem').get(0);
+ });
+ $j("div.categoryHandle").mouseup(function() {
+ $j(this).fadeTo(500,1).removeClass('draggingItem');
+ });
+});
+
+function showOverlay(element) {
+ var el = document.getElementById('overlay');
+ var elTo = document.getElementById(element);
+ if (!elTo) {
+ return;
+ }
+ var sz = elTo.positionedOffset(elTo);
+
+ if (element != "categoriesContainer") {
+ var tt = document.getElementById("categoriesContainer").positionedOffset(elTo);
+ el.style.top = tt.top + sz.top + 'px';
+ el.style.left = tt.left + sz.left + 'px';
+ } else {
+ el.style.top = sz.top + 'px';
+ el.style.left = sz.left + 'px';
+ }
+ el.style.width = elTo.offsetWidth + 'px';
+ el.style.height = elTo.offsetHeight + 'px';
+ el.style.display = 'block';
+}
@@ -961,7 +961,7 @@ div#categs-nav {
background-color:#F5F5F5;
border:1px solid #CCCCCC;
margin:0pt 0pt 5px;
- position:relative;
+ /*position:relative;*/
width:650px;
margin-left:10px;
}
@@ -1008,14 +1008,14 @@ div.footer {
width:100%;
}
-#overlay {
+#add-category-overlay {
vertical-align:middle;
background-color:#FFFFFF;
opacity:0.7;
width:650px;
}
-#overlay img {
+#add-category-overlay img {
left:50%;
margin-left:-12px;
margin-top:-12px;
@@ -1095,4 +1095,48 @@ table.pages-container td {
background-color:#F6F6F6;
padding:10px;
width:735px;
+}
+
+#messagesContainer {
+ left:50%;
+ margin-left:-150px;
+ position:absolute;
+ top:0pt;
+ width:300px;
+}
+
+#overlay {
+ background-color:#FFFFFF;
+ display:none;
+ opacity:0.7;
+ position:absolute;
+}
+
+#overlay img {
+ left:50%;
+ margin-left:-12px;
+ margin-top:-12px;
+ position:absolute;
+ top:50%;
+ z-index:3000;
+}
+
+.draggingItem {
+ background: #E86857;
+ z-index: 4000;
+}
+
+#header ul#nav-admin {
+ position:absolute;
+ right:0pt;
+ top:80px;
+}
+
+#header ul#nav-admin li {
+ float:left;
+ padding-left:20px;
+}
+
+#header ul#nav-admin li.selected {
+ font-weight:bold;
}
@@ -20,8 +20,7 @@ def test_should_fail_login
def test_should_show_error_after_failed_login
post :create, :login => 'quentin', :password => 'bad password'
- assert_response :redirect
- assert_redirected_to login_url
+
assert_equal "Invalid login or password!", flash[:error]
end
Oops, something went wrong. Retry.

0 comments on commit 24bc857

Please sign in to comment.