Permalink
Browse files

Added pages management and improved slightly admin panel

  • Loading branch information...
1 parent 6ccd6ec commit 770b6a8458a75bdf978f00d99446f8afae2a12a4 @wlodars wlodars committed Jul 16, 2008
Showing 548 changed files with 67,819 additions and 89 deletions.
@@ -15,15 +15,15 @@ def show
# POST /admin/categories
def create
- max_position = Category.find_by_sql "SELECT MAX(position) as position FROM categories"
- max_id = Category.find_by_sql "SELECT MAX(id) as id FROM categories"
- @category = Category.new(:name => 'New category', :value => "newcategory#{max_id[0].id + 1}", :position => max_position[0].position + 1)
- @category.save
+ @category = Category.new(:name => 'New category',
+ :value => "newcategory#{Category.last.id + 1}")
flash_notice("Category has been added")
respond_to do |format|
- format.html { redirect_to admin_categories_url }
- format.js # admin/categories/create.js.rjs
+ if @category.save
+ format.html { redirect_to admin_categories_url }
+ format.js # admin/categories/create.js.rjs
+ end
end
end
@@ -42,7 +42,7 @@ def update
render :update do |page|
@category.reload
page.alert @category.errors.full_messages.join("\n")
- page.replace("category_#{@category.id}", :partial => 'admin/categories/category', :category => @category)
+ page.replace(@category.dom_id, :partial => 'admin/categories/category', :category => @category)
page.sortable 'categoriesContainer', :tag => 'div', :url => saveorder_admin_categories_path
end
}
@@ -54,7 +54,7 @@ def update
def saveorder
params[:categoriesContainer].each_with_index do |id, position|
category = Category.find(id)
- category.update_attribute('position', position)
+ category.update_attribute('position', position + 1)
end
flash_notice("Categories order changed. Saving ...")
@@ -67,8 +67,11 @@ def saveorder
# DELETE /admin/categories/1
def destroy
@category = Category.find(params[:id])
- @category.destroy if @category.jobs.empty?
- flash_notice("Category has been deleted")
+
+ if @category.jobs.empty?
+ @category.destroy
+ flash_notice("Category has been deleted")
+ end
respond_to do |format|
format.html { redirect_to admin_categories_url }
@@ -0,0 +1,86 @@
+class Admin::PagesController < ApplicationController
+ before_filter :login_required
+ before_filter :form_message_style, :only => [:new, :edit]
+ layout 'admin'
+
+ uses_tiny_mce(:options => { :theme => 'advanced',
+ :mode => "textareas",
+ :theme_advanced_toolbar_location => "top",
+ :theme_advanced_toolbar_align => "left",
+ :theme_advanced_statusbar_location => "bottom",
+ :theme_advanced_buttons1 => %w{ bold italic underline strikethrough | justifyleft
+ justifycenter justifyright justifyfull | styleselect formatselect fontselect fontsizeselect },
+ :theme_advanced_buttons2 => %w{ cut copy paste pastetext pasteword | search
+ replace | bullist numlist | outdent indent blockquote | undo redo | link
+ unlink anchor image cleanup help code | forecolor backcolor },
+ :theme_advanced_buttons3 => %w{ tablecontrols | hr removeformat visualaid |
+ sub sup | charmap media advhr | ltr rtl },
+ :theme_advanced_buttons4 => %w{ insertlayer moveforward movebackward absolute |
+ styleprops | cite abbr acronym del ins attribs },
+ :editor_selector => 'mceEditor',
+ :plugins => %w{ style layer table save advhr advimage advlink media searchreplace
+ contextmenu paste directionality nonbreaking xhtmlxtras } },
+ :only => [:new, :create, :edit, :update])
+
+ # GET /admin/pages
+ def index
+ @pages = Page.all(:order => 'title')
+ end
+
+ # GET /admin/pages/new
+ def new
+ @page = Page.new
+ end
+
+ # POST /admin/pages
+ def create
+ @page = Page.new(params[:page])
+
+ respond_to do |format|
+ if @page.save
+ flash[:notice] = 'Page was successfully created.'
+ format.html { redirect_to admin_pages_url }
+ else
+ format.html { render :action => "new" }
+ end
+ end
+ end
+
+ # GET /admin/pages/1/edit
+ def edit
+ @page = Page.find_by_url params[:id]
+
+ @form_style = '' if @page.has_form
+ end
+
+ # PUT /admin/pages/1
+ def update
+ @page = Page.find_by_url(params[:id])
+
+ respond_to do |format|
+ if @page.update_attributes(params[:page])
+ flash[:notice] = 'Page was successfully updated.'
+ format.html { redirect_to admin_pages_url }
+ else
+ format.html { render :action => "edit" }
+ end
+ end
+ end
+
+ # DELETE /admin/pages/1
+ def destroy
+ @page = Page.find_by_url(params[:id])
+ @page.destroy
+ flash_notice("Page has been deleted")
+
+ respond_to do |format|
+ format.html { redirect_to(admin_pages_url) }
+ format.js # admin/pages/destroy.js.rjs
+ end
+ end
+
+ private
+ def form_message_style
+ @form_style = 'display:none'
+ end
+end
@@ -0,0 +1,7 @@
+class PagesController < ApplicationController
+
+ # GET /pages/1
+ def show
+ @page = Page.find_by_url params[:id]
+ end
+end
@@ -3,24 +3,24 @@ def admin_category_nav_item(category)
category_nav_item(category, true)
end
- def show_save_category(category_id)
- "Element.show('saveCategory#{category_id}')"
+ def show_save_category(category)
+ "Element.show('#{category.dom_id("save")}')"
end
- def link_to_delete_category(category_id)
+ def link_to_delete_category(category)
link_to_remote(image_tag("icon-delete.png", :alt => 'Delete') + " Delete", {
- :url => admin_category_url(category_id),
+ :url => admin_category_url(category.id),
:confirm => 'Are you sure you want to delete this category?',
:method => :delete },
{ :class => 'deleteCategory'})
end
- def link_to_save_category(category_id)
+ def link_to_save_category(category)
link_to_remote(image_tag("disk.png", :alt => 'Save') + " Save", {
- :url => admin_category_url(category_id),
+ :url => admin_category_url(category.id),
:method => :put,
- :with => "'name='+$F('name[#{category_id}]')+'&url='+$F('url[#{category_id}]')" },
- { :id => "saveCategory#{category_id}",
+ :with => "'name='+$F('#{category.dom_id("name")}')+'&url='+$F('#{category.dom_id("url")}')" },
+ { :id => "#{category.dom_id("save")}",
:class => 'saveCategory', :style => 'display:none;' })
end
@@ -6,28 +6,28 @@ def activation_image_tag(job)
end
image_tag("icon_#{activate}.gif",
:alt => activate.capitalize,
- :id => "activate_#{job.id}")
+ :id => job.dom_id("activate"))
end
def link_to_activate_deactivate_job(job)
link_to_remote(activation_image_tag(job), {
- :url => admin_job_url(job.id),
+ :url => admin_job_url(job),
:method => :put,
- :loading => "Element.hide('activ_butt_#{job.id}');Element.show('loading_#{job.id}')",
- :complete => "Element.hide('loading_#{job.id}');Element.show('activ_butt_#{job.id}')"},
- { :id => "activ_butt_#{job.id}"} )
+ :loading => "Element.hide('#{job.dom_id("activ_butt")}');Element.show('#{job.dom_id("loading")}')",
+ :complete => "Element.hide('#{job.dom_id("loading")}');Element.show('#{job.dom_id("activ_butt")}')"},
+ { :id => "#{job.dom_id("activ_butt")}"} )
end
- def link_to_delete_job(job_id)
+ def link_to_delete_job(job)
link_to_remote(image_tag("icon-delete.png", :alt => 'Delete'),
- :url => admin_job_url(job_id),
+ :url => admin_job_url(job),
:confirm => 'Are you sure you want to delete this post?',
:method => :delete)
end
- def saving_job_image_tag(job_id)
+ def saving_job_image_tag(job)
image_tag("ajax-loader.gif", :alt => "Saving...",
:style => 'display:none',
- :id => "loading_#{job_id}")
+ :id => job.dom_id("loading"))
end
end
@@ -0,0 +1,11 @@
+module Admin::PagesHelper
+ def observe_has_form
+ observe_field "page_has_form", :frequency => 0.5,
+ :function => "if(element.checked) {
+ Element.show('has_form_label');
+ Element.show('has_form_textarea');
+ } else {
+ Element.hide('has_form_label');Element.hide('has_form_textarea');
+ }"
+ end
+end
@@ -0,0 +1,2 @@
+module PagesHelper
+end
View
@@ -1,8 +1,10 @@
class Category < ActiveRecord::Base
+ acts_as_list
has_many :jobs
validates_presence_of :name, :value
validates_uniqueness_of :value
+ validates_format_of :value, :with => /^[-a-z0-9_]{4,20}$/
def to_param
self.value
@@ -17,5 +19,4 @@ def self.to_select
[category.name, category.id]
end
end
-
end
View
@@ -0,0 +1,9 @@
+class Page < ActiveRecord::Base
+ validates_presence_of :url, :message => 'Please fill in the URL'
+ validates_uniqueness_of :url, :message => 'The URL is already in use. Please select another URL'
+ validates_presence_of :title, :message => 'Please fill in the Title'
+
+ def to_param
+ self.url
+ end
+end
@@ -1,14 +1,14 @@
-.categoryItem{:id => "category_#{category.id}"}
+.categoryItem{:id => category.dom_id}
.categoryHandle
.categoryWrapper
.categoryManagement{:style => 'float:right;width:10%;'}
- = link_to_delete_category(category.id)
- = link_to_save_category(category.id)
+ = link_to_delete_category(category)
+ = link_to_save_category(category)
%label
%span Name:
- = text_field_tag "name[#{category.id}]", category.name, :size => 60
- = observe_field "name[#{category.id}]", :frequency => 1, :function => show_save_category(category.id)
+ = text_field_tag category.dom_id("name"), category.name, :size => 60
+ = observe_field category.dom_id("name"), :frequency => 1, :function => show_save_category(category)
%label
%span URL:
- = text_field_tag "url[#{category.id}]", category.value, :size => 60
- = observe_field "url[#{category.id}]", :frequency => 1, :function => show_save_category(category.id)
+ = text_field_tag category.dom_id("url"), category.value, :size => 60
+ = observe_field category.dom_id("url"), :frequency => 1, :function => show_save_category(category)
@@ -1,7 +1,7 @@
if @category.jobs.empty?
- page["category_#{@category.id}"].visual_effect :fade, "category_#{@category.id}"
+ page[@category.dom_id].visual_effect :fade, @category.dom_id
page.delay(1) do
- page.remove "category_#{@category.id}"
+ page.remove @category.dom_id
end
page.replace_html "categories", :partial => 'admin/categories/list'
page.display_notice
@@ -3,7 +3,7 @@
#categoriesContainer
= partial @categories
-= sortable_element_categories_container
+= sortable_element "categoriesContainer", :url => saveorder_admin_categories_path, :tag => "div", :complete => visual_effect(:highlight, 'categoriesContainer')
#overlay{:style => "display: none; top: 145px; left: 157px;height: 72px;"}
= image_tag("ajax-loader.gif", :alt => "Loading...")
@@ -1,5 +1,5 @@
-page["category_#{@category.id}"].visual_effect :pulsate, "category_#{@category.id}"
-page.hide "saveCategory#{@category.id}"
+page[@category.dom_id].visual_effect :pulsate, @category.dom_id
+page.hide @category.dom_id("save")
@category = nil
page.replace_html "categories", :partial => 'admin/categories/list'
page.display_notice
@@ -2,7 +2,7 @@
-# Display Job Posts
%table.job-posts{:cellspacing => 0}
- jobs.each do |job|
- %tr.job_item{:id => "job_" + job.id.to_s}
+ %tr.job-item{:id => job.dom_id}
%td
= job_type_image(job.job_type)
= link_to job.title, admin_job_url(job), :title => job.title
@@ -17,9 +17,9 @@
%td{:style => 'text-align:left;width:15%'}
-# activate/deactivate link
= link_to_activate_deactivate_job(job)
- = saving_job_image_tag(job.id)
+ = saving_job_image_tag(job)
-# delete link
- = link_to_delete_job(job.id)
+ = link_to_delete_job(job)
- else
#no-ads No jobs, yet.
@@ -1,2 +1,2 @@
-page["job_#{@job.id}"].visual_effect :fade, "job_#{@job.id}"
+page[@job.dom_id].visual_effect :fade, @job.dom_id
page.display_notice
@@ -1,2 +1,2 @@
-page.replace "activate_#{@job.id}", activation_image_tag(@job)
+page.replace @job.dom_id("activate"), activation_image_tag(@job)
page.display_notice
@@ -0,0 +1,51 @@
+- form_for [:admin, @page], :html => {:id => 'publish_form'} do |f|
+ %p= submit_tag @page.new_record? ? "Add page" : "Modify page", :class => 'submit_button'
+ %fieldset
+ %legend SEO
+ %table{:cellspacing => 0, :cellpadding => 0, :border => 0}
+ %tr
+ %td{:colspan => 2}
+ = f.label(:url, "URL")
+ = error_message_on(:page, :url)
+ %tr
+ %td{:colspan => 2}= f.text_field :url, :class => 'text_field'
+
+ %tr
+ %td{:colspan => 2}= f.label :page_title
+ %tr
+ %td{:colspan => 2}= f.text_field :page_title, :class => 'text_field'
+
+ %tr
+ %td{:width => '50%'}= f.label :keywords
+ %td{:width => '50%'}= f.label :description
+
+ %tr
+ %td{:width => '50%'}= f.text_area :keywords, :class => 'textarea_field_small', :rows => 6
+ %td{:width => '50%'}= f.text_area :description, :class => 'textarea_field_small', :rows => 6
+
+ %p= submit_tag @page.new_record? ? "Add page" : "Modify page", :class => 'submit_button'
+
+ %fieldset
+ %legend Content
+ %table{:cellspacing => 0, :cellpadding => 0, :border => 0}
+ %tr
+ %td{:colspan => 2}
+ = f.label :title
+ = error_message_on(:page, :title)
+ %tr
+ %td{:colspan => 2}= f.text_field :title, :class => 'text_field'
+
+ %tr
+ %td{:colspan => 2}= f.label :content
+ %tr
+ %td{:colspan => 2}= f.text_area :content, :class => "textarea_field mceEditor", :rows => 40
+
+ %tr
+ %td{:colspan => 2}= f.check_box(:has_form) + ' Has contact form?'
+ = observe_has_form
+ %tr#has_form_label{:style => @form_style}
+ %td{:colspan => 2}= f.label :form_message
+ %tr#has_form_textarea{:style => @form_style}
+ %td{:colspan => 2}= f.text_area :form_message, :class => "textarea_field mceEditor", :rows => 20
+
+ %p= submit_tag @page.new_record? ? "Add page" : "Modify page", :class => 'submit_button'
Oops, something went wrong.

0 comments on commit 770b6a8

Please sign in to comment.