Permalink
Browse files

Merge branch 'master' of git://github.com/wlodars/jobberrails

  • Loading branch information...
2 parents 8fe6ea9 + e29f63c commit 4cd1f6a3f350a1bd40daf0a4528b5cb6d86a6bde @jcnetdev committed Aug 8, 2008
Showing 561 changed files with 68,329 additions and 201 deletions.
@@ -15,12 +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
- 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|
format.html { redirect_to admin_categories_url }
format.js # admin/categories/create.js.rjs
@@ -30,10 +33,10 @@ def create
# 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
@@ -42,8 +45,8 @@ 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.sortable 'categoriesContainer', :tag => 'div', :url => saveorder_admin_categories_path
+ page.replace(@category.dom_id, :partial => 'admin/categories/category', :category => @category)
+ page.sortable "categoriesContainer", sortable_categories_container_options
end
}
end
@@ -54,9 +57,9 @@ 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 ...")
+ flash.now[:notice] = "Categories order changed. Saving ..."
respond_to do |format|
format.html { redirect_to admin_categories_url }
@@ -67,8 +70,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.now[:notice] = "Category has been deleted"
+ end
respond_to do |format|
format.html { redirect_to admin_categories_url }
@@ -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 }
@@ -0,0 +1,88 @@
+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])
+ url = @page.url
+
+ respond_to do |format|
+ if @page.update_attributes(params[:page])
+ flash[:notice] = 'Page was successfully updated.'
+ format.html { redirect_to admin_pages_url }
+ else
+ @page.url = url
+ format.html { render :action => "edit" }
+ end
+ end
+ end
+
+ # DELETE /admin/pages/1
+ def destroy
+ @page = Page.find_by_url(params[:id])
+ @page.destroy
+ flash.now[: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
@@ -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?
@@ -1,2 +1,13 @@
-class CompaniesController < ApplicationController
+class CompaniesController < ApplicationController
+
+ # GET /companies
+ def index
+ @companies = Job.companies_count
+ end
+
+ # GET /jobs_at/1
+ def jobs_at
+ @company = Job.find_company(params[:company])
+ @jobs = @company ? Job.find_all_by_company(@company) : nil
+ end
end
@@ -0,0 +1,7 @@
+class PagesController < ApplicationController
+
+ # GET /pages/1
+ def show
+ @page = Page.find_by_url params[:id]
+ end
+end
@@ -16,7 +16,7 @@ def create
else
session[:admin] = admin
flash[:error] = "Invalid login or password!"
- redirect_to login_url
+ render :action => "new"
end
end
@@ -3,39 +3,44 @@ 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 },
+ :method => :delete,
+ :loading => "showOverlay('#{category.dom_id}');",
+ :complete => "Element.hide('overlay');" },
{ :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")}')",
+ :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
@@ -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
@@ -36,7 +36,7 @@ def flash_box(text, options = {})
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
@@ -62,4 +62,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
@@ -1,2 +1,16 @@
module CompaniesHelper
+ def companies_tag_cloud(companies, classes)
+ max, min = 0, 0
+ companies.each { |t|
+ max = t.count.to_i if t.count.to_i > max
+ min = t.count.to_i if t.count.to_i < min
+ }
+
+ divisor = ((max - min) / classes.size) + 1
+
+ companies.each { |t|
+ yield t.name, t.count, url_encode(t.name), classes[(t.count.to_i - min) / divisor]
+ }
+
+ end
end
@@ -0,0 +1,2 @@
+module PagesHelper
+end
View
@@ -1,8 +1,11 @@
class Category < ActiveRecord::Base
+ acts_as_list
has_many :jobs
validates_presence_of :name, :value
validates_uniqueness_of :value
+ validates_length_of :value, :within => 4..30
+ validates_format_of :value, :with => /^[-a-z0-9_]{4,30}$/
def to_param
self.value
@@ -17,5 +20,4 @@ def self.to_select
[category.name, category.id]
end
end
-
end
Oops, something went wrong.

0 comments on commit 4cd1f6a

Please sign in to comment.