Skip to content

Commit

Permalink
Add fnctionality to declare modal new in the controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
briandmcnabb committed Nov 11, 2012
1 parent c98491b commit 842239f
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 23 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/CartoCMS/_resources.css.scss
Expand Up @@ -145,6 +145,10 @@ form {
appearance: button;
}

textarea[id$="_description"] {
height: 315px;
}

.boolean_toggler {
input { @extend .hidden; }
label {
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/cms/assets_controller.rb
Expand Up @@ -6,7 +6,12 @@ class Cms::AssetsController < Cms::ResourceController
# Configuration
defaults resource_class: @resource_class || Asset
actions :index, :create, :edit, :update, :destroy
belongs_to :slide, polymorphic: true, optional: true

belongs_to :slide, polymorphic: true, optional: true
belongs_to :story, polymorphic: true, optional: true
belongs_to :person, polymorphic: true, optional: true
belongs_to :work, polymorphic: true, optional: true

respond_to :json
respond_to :js, only: :destroy

Expand Down
1 change: 1 addition & 0 deletions app/controllers/cms/pages_controller.rb
@@ -1,4 +1,5 @@
class Cms::PagesController < Cms::ResourceController
before_filter ->{ config_new_resource_link(modal: true) }, only: [:index]
require "mercury/params_mapper"
include Mercury::ParamsMapper
respond_to :json
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/cms/resource_controller.rb
Expand Up @@ -13,4 +13,12 @@ def destroy
format.js { render nothing: true }
end
end



private

def config_new_resource_link(options={})
@new_resource_link_config ||= options
end
end
11 changes: 8 additions & 3 deletions app/helpers/link_helper.rb
Expand Up @@ -8,13 +8,18 @@ def link_to_modal(*args, &block)
end

def new_resource_link
if content_for?(:new_resource_link)
content_for(:new_resource_link)
if @new_resource_link_config[:modal]
link_to_modal '#', class: 'btn btn-small-dark' do
out = ""
out << content_tag(:i, '', class: "icon-plus icon-white")
out << (@new_resource_link_config[:text] || "new")
out.html_safe
end
else
link_to new_resource_path, class: 'btn btn-small-dark' do
out = ""
out << content_tag(:i, '', class: "icon-plus icon-white")
out << "new"
out << (@new_resource_link_config.try(:fetch, :text) || "new")
out.html_safe
end
end
Expand Down
3 changes: 0 additions & 3 deletions app/views/cms/pages/_index-table.html.haml
@@ -1,6 +1,3 @@
- content_for :new_resource_link do
- link_to_modal("#{content_tag(:i, '', class: 'icon-plus icon-white')}new".html_safe, '#', class: 'btn btn-small-dark')

%table.table.table-striped
%colgroup
%col
Expand Down
5 changes: 4 additions & 1 deletion app/views/cms/resource/_index-list.html.haml
Expand Up @@ -7,4 +7,7 @@
%p= resource.description.truncate(75)
.action_links.pull-right
= link_to 'edit', [:edit, :cms, resource], class: 'icon-pencil ir'
= link_to 'destroy', [:cms, resource], class: 'icon-trash ir', remote: true, method: :delete, confirm: "Are you sure?"
= link_to 'destroy', [:cms, resource], class: 'icon-trash ir', remote: true, method: :delete, confirm: "Are you sure?"

- if @new_resource_link_config.try(:fetch, :modal)
= render(partial: 'form-modal', layout: 'layouts/modal') rescue render(partial: 'cms/shared/missing_modal_template', layout: 'layouts/modal')
5 changes: 4 additions & 1 deletion app/views/cms/resource/_index-table.html.haml
Expand Up @@ -25,4 +25,7 @@
- if _routes_context.respond_to? :edit
= link_to 'edit', edit_resource_path(resource), class: 'icon-pencil ir'
- if _routes_context.respond_to? :destroy
= link_to 'destroy', resource_path(resource), class: 'icon-trash ir', remote: true, method: :delete, confirm: "Are you sure?"
= link_to 'destroy', resource_path(resource), class: 'icon-trash ir', remote: true, method: :delete, confirm: "Are you sure?"

- if @new_resource_link_config.try(:fetch, :modal)
= render(partial: 'form-modal', layout: 'layouts/modal') rescue render(partial: 'cms/shared/missing_modal_template', layout: 'layouts/modal')
13 changes: 13 additions & 0 deletions app/views/cms/shared/_image_drop_zone.html.haml
@@ -0,0 +1,13 @@
.span5.vline-center
#dropzone.well.fade.vline-wrap{class: ('empty' unless resource.image)}
= render partial: 'cms/assets/single-file/uploader', locals: { parent: resource }
- if resource.image
%figure.template-download
.preview
= link_to edit_cms_asset_path(resource.image), title: resource.image.asset_path do
= image_tag resource.image.asset_path.url(:medium)
.hover_links
= link_to [:edit, :cms, resource.image] do
%i.icon-pencil
= link_to [:cms, resource.image], remote: true, method: :delete, confirm: "Are you sure?" do
%i.icon-trash
4 changes: 4 additions & 0 deletions app/views/cms/shared/_missing_modal_template.html.haml
@@ -0,0 +1,4 @@
.modal-body
.close{ data: { dismiss: 'modal' } } &times;
%h1 You need to add the following partial:
%h3= "#{params[:controller]}/_form-modal.html.*"
15 changes: 1 addition & 14 deletions app/views/cms/slides/_form.html.haml
@@ -1,20 +1,7 @@
- panel_back_path [:edit, :cms, resource.slider]

.row
.span5.vline-center
#dropzone.well.fade.vline-wrap{class: ('empty' unless resource.image)}
= render partial: 'cms/assets/single-file/uploader', locals: { parent: resource }
- if resource.image
%figure.template-download
.preview
= link_to edit_cms_asset_path(resource.image), title: resource.image.asset_path do
= image_tag resource.image.asset_path.url(:medium)
.hover_links
= link_to [:edit, :cms, resource.image] do
%i.icon-pencil
= link_to [:cms, resource.image], remote: true, method: :delete, confirm: "Are you sure?" do
%i.icon-trash

= render 'cms/shared/image_drop_zone'
.pull-right
= simple_form_for [:cms, resource], remote: true do |f|
= f.input :name, input_html: { class: 'span8'}
Expand Down

0 comments on commit 842239f

Please sign in to comment.