refactor + fix bugs + complete translations in English + api security option in content types

This commit is contained in:
dinedine 2010-06-10 16:50:50 +02:00
parent d0ff08c9a1
commit 6b0dafc223
18 changed files with 144 additions and 97 deletions

View File

@ -22,7 +22,8 @@ module Admin
protected
def set_content_type
@content_type = current_site.content_types.where(:slug => params[:slug]).first
@content_type = current_site.content_types.where(:slug => params[:slug]).first
render :json => { :error => 'Api not enabled'} and return false unless @content_type.api_enabled
end
end

View File

@ -3,8 +3,8 @@ class AssetCollection
include Locomotive::Mongoid::Document
## fields ##
field :name, :type => String
field :slug, :type => String
field :name
field :slug
## associations ##
belongs_to_related :site

View File

@ -8,6 +8,7 @@ class ContentType
field :slug
field :order_by
field :highlighted_field_name
field :api_enabled, :type => Boolean, :default => false
## associations ##
belongs_to_related :site

View File

@ -3,11 +3,11 @@ class PagePart
include Mongoid::Document
## fields ##
field :name, :type => String
field :slug, :type => String
field :value, :type => String
field :name
field :slug
field :value
field :disabled, :type => Boolean, :default => false
field :value, :type => String
field :value
## associations ##
embedded_in :page, :inverse_of => :parts

View File

@ -4,7 +4,7 @@ class Site
## fields ##
field :name
field :subdomain, :type => String
field :subdomain
field :domains, :type => Array, :default => []
## associations ##

View File

@ -1,7 +1,8 @@
- title link_to(@collection.name.blank? ? @collection.name_was : @collection.name, '#', :rel => 'asset_collection_name', :title => t('.ask_for_name'), :class => 'editable')
- content_for :head do
= javascript_include_tag 'admin/asset_collections', 'admin/custom_fields'
= javascript_include_tag 'admin/plugins/fancybox', 'admin/asset_collections', 'admin/custom_fields'
= stylesheet_link_tag 'admin/plugins/fancybox', 'admin/box'
- content_for :submenu do
= render 'admin/shared/menu/assets'
@ -25,6 +26,8 @@
= f.input :name
= f.input :slug, :required => false
= render 'admin/shared/custom_fields', :f => f, :collection_name => 'assets'
= render 'admin/custom_fields/index', :f => f, :collection_name => 'assets'
= render 'admin/shared/form_actions', :delete_button => link_to(content_tag(:span, t('.destroy')), admin_asset_collection_url(@collection), :confirm => t('admin.messages.confirm'), :method => :delete, :class => 'button small remove'), :button_label => :update
= render 'admin/shared/form_actions', :delete_button => link_to(content_tag(:span, t('.destroy')), admin_asset_collection_url(@collection), :confirm => t('admin.messages.confirm'), :method => :delete, :class => 'button small remove'), :button_label => :update
= render 'admin/custom_fields/edit_field'

View File

@ -13,4 +13,6 @@
= f.foldable_inputs :name => :options, :class => 'switchable' do
= f.input :highlighted_field_name, :as => :select, :collection => options_for_highlighted_field(f.object, 'contents'), :include_blank => false
= f.input :order_by, :as => :select, :collection => options_for_order_by(f.object, 'contents'), :include_blank => false
= f.custom_input :api_enabled, :css => 'toggle' do
= f.check_box :api_enabled

View File

@ -15,4 +15,4 @@
= render 'admin/shared/form_actions', :back_url => admin_contents_url(@content_type.slug), :button_label => :update
= render 'admin/custom_fields/edit'
= render 'admin/custom_fields/edit_field'

View File

@ -14,4 +14,4 @@
= render 'admin/shared/form_actions', :back_url => admin_pages_url, :button_label => :create
= render 'admin/custom_fields/edit'
= render 'admin/custom_fields/edit_field'

View File

@ -2,7 +2,7 @@
- custom_fields = f.object.send(collection_name.to_sym)
- ordered_custom_fields = f.object.send(:"ordered_#{collection_name}")
= f.foldable_inputs :name => :custom_fields, :class => 'editable-list fields off' do
= f.foldable_inputs :name => :custom_fields, :class => 'editable-list fields' do
- ordered_custom_fields.each do |field|
= f.fields_for collection_name.to_sym, field, :child_index => field._index do |g|
%li{ :class => "item added #{'error' unless field.errors.empty?}"}

View File

@ -1,59 +0,0 @@
- collection_name = "#{collection_name.singularize}_custom_fields"
- custom_fields = f.object.send(collection_name.to_sym)
- ordered_custom_fields = f.object.send(:"ordered_#{collection_name}")
= f.foldable_inputs :name => :custom_fields, :class => 'editable-list fields' do
- ordered_custom_fields.each do |field|
= f.fields_for collection_name.to_sym, field, :child_index => field._index do |g|
%li{ :class => "item added #{'error' unless field.errors.empty?}"}
%span.handle
= image_tag 'admin/form/icons/drag.png'
= g.hidden_field :position, :class => 'position'
= g.hidden_field :_alias, :class => 'alias'
= g.hidden_field :hint, :class => 'hint'
= g.text_field :label
—
%em= t("admin.custom_fields.kind.#{field.kind.downcase}")
= g.select :kind, options_for_field_kind
 
%span.actions
= link_to image_tag('admin/form/pen.png'), '#', :class => 'edit first'
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove', :confirm => t('admin.messages.confirm')
= f.fields_for collection_name.to_sym, custom_fields.build(:label => 'field name'), :child_index => '-1' do |g|
%li{ :class => 'item template' }
%span.handle
= image_tag 'admin/form/icons/drag.png'
= g.hidden_field :position, :class => 'position'
= g.hidden_field :_alias, :class => 'alias'
= g.hidden_field :hint, :class => 'hint'
= g.text_field :label, :class => 'string label void'
—
%em
= g.select :kind, options_for_field_kind
 
%span.actions
= link_to image_tag('admin/form/pen.png'), '#', :class => 'edit first'
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove', :confirm => t('admin.messages.confirm')
%button{ :class => 'button light add', :type => 'button' }
%span= t('admin.buttons.new_item')

View File

@ -65,90 +65,174 @@ en:
pages:
index:
title: Listing pages
help: "Pages are organized as a tree. You can order pages as well as folders"
no_items: "There are no pages for now. Just click <a href=\"{{url}}\">here</a> to create the first one."
new: new page
lastest_items: Lastest pages
new:
title: New page
help: "Please fill in the below form to create your page. Be careful, by default, the page is not published."
page:
updated_at: updated at
edit:
show: show
help: "The page title can be updated by clicking it."
ask_for_title: "Please type the new page title"
messages:
successful_create: "Page was successfully created."
successful_update: "Page was successfully updated."
successful_destroy: "Page was successfully deleted."
failed_create: "Page was not created."
failed_update: "Page was not updated."
layouts:
index:
title: Listing layouts
help: "Layouts give the look of a page (1, 2 or many columns)."
no_items: "There are no layouts for now. Just click <a href=\"{{url}}\">here</a> to create the first one."
new: new layout
new:
title: New layout
help: "Fill in the form below to create your layout."
edit:
title: Editing layout
help: "Fill in the form below to update your layout."
new: new layout
layout:
updated_at: Updated at
messages:
successful_create: "Layout was successfully created."
successful_update: "Layout was successfully updated."
successful_destroy: "Layout was successfully deleted."
failed_create: "Layout was not created."
failed_update: "Layout was not updated."
snippets:
index:
title: Listing snippets
help: "Snippets are portion of HTML code which can be found at different places within the site (such as a footer)."
no_items: "There are no snippets for now. Just click <a href=\"{{url}}\">here</a> to create the first one."
new: new snippet
new:
title: New snippet
help: "Fill in the form below to update your snippet."
edit:
title: Editing snippet
help: "Fill in the form below to update your snippet."
snippet:
updated_at: Updated at
messages:
successful_create: "Snippet was successfully created."
successful_update: "Snippet was successfully updated."
successful_destroy: "Snippet was successfully deleted."
failed_create: "Snippet was not created."
failed_update: "Snippet was not updated."
sites:
new:
title: New site
help: "Fill in the form below to create your new site."
messages:
successful_create: "Site was successfully created."
failed_create: "Site was not created."
current_sites:
edit:
new_membership: add account
help: "The site name can be updated by clicking it."
ask_for_name: "Please type the new site name"
messages:
successful_update: "My site was successfully updated."
failed_update: "My site was not updated."
memberships:
new:
title: New membership
help: "Please give the account email to add. If it does not exist, you will be redirected to the account creation form."
messages:
successful_create: "Membership was successfully created."
failed_create: "Membership was not created."
accounts:
new:
title: New account
messages:
successful_create: "Account was successfully created."
failed_create: "Account was not created."
my_accounts:
edit:
help: "Your name can be updated by clicking it."
new_site: new site
en: English
fr: French
ask_for_name: "Please type your new name"
messages:
successful_update: "My account was successfully updated."
failed_update: "My account was not updated."
theme_assets:
index:
title: Listing theme files
help: "Theme assets represent files needed by layouts and snippets. If you need to manage an image gallery, go to the Assets section instead."
new: new file
css_and_js: Style and javascript
images: Images
no_items: "There are no files for now. Just click <a href=\"{{url}}\">here</a> to create the first one."
new:
title: New file
help: "You have the choice to either upload any file or to copy/paste a stylesheet or a javascript in plain text."
edit:
title: "Editing {{file}}"
help: "You can use it by copying/pasting the following url: {{url}}"
form:
picker_link: Insert a file into the code
choose_file: Choose file
choose_plain_text: Choose plain text
images:
title: Listing images
messages:
successful_create: "File was successfully created."
successful_update: "File was successfully updated."
successful_destroy: "File was successfully deleted."
failed_create: "File was not created."
failed_update: "File was not updated."
asset_collections:
index:
title: Asset collections
help: "The collection name can be updated by clicking it. You can customize assets in a collection by adding new fields."
new: new collection
no_items: "There are no collections for now. Just click <a href=\"{{url}}\">here</a> to create the first one."
new:
title: New collection
help: "For now, just type a name. Other settings will come once the form is sent."
edit:
help: "The collection name can be updated by clicking it. Uploading several files at once is possible, just click on the 'upload files' button at the right corner."
help: "The collection name can be updated by clicking it. You can customize assets in a collection by adding new fields."
add_asset: add asset
destroy: remove collection
no_items: "There are no assets for now. Just click <a href=\"{{url}}\">here</a> to create the first one."
ask_for_name: "Please type the new name"
messages:
successful_create: "Collection was successfully created."
successful_update: "Collection was successfully updated."
successful_destroy: "Collection was successfully deleted."
failed_create: "Collection was not created."
failed_update: "Collection was not updated."
assets:
new:
title: New asset
help: "Fill in the form below to create your asset."
edit:
title: Edit asset
help: "Fill in the form below to update your asset."
messages:
successful_create: "Asset was successfully created."
successful_update: "Asset was successfully updated."
successful_destroy: "Asset was successfully deleted."
failed_create: "Asset was not created."
failed_update: "Asset was not updated."
content_types:
index:
@ -165,6 +249,12 @@ en:
order_by:
updated_at: 'By "updated at" date'
position_in_list: Manually
messages:
successful_create: "Model was successfully created."
successful_update: "Model was successfully updated."
successful_destroy: "Model was successfully deleted."
failed_create: "Model was not created."
failed_update: "Model was not updated."
contents:
index:
@ -175,12 +265,19 @@ en:
new: new item
no_items: "There are no items for now. Just click <a href=\"{{url}}\">here</a> to create the first one."
lastest_items: "Lastest items"
updated_at: "Updated at"
new:
title: '{{type}} &mdash; new item'
edit:
title: '{{type}} &mdash; editing item'
form:
edit_categories: Edit options
messages:
successful_create: "Content was successfully created."
successful_update: "Content was successfully updated."
successful_destroy: "Content was successfully deleted."
failed_create: "Content was not created."
failed_update: "Content was not updated."
formtastic:
titles:
@ -205,7 +302,7 @@ en:
edit:
source: Replace file
custom_fields:
custom_field:
field:
_alias: Alias
hints:

View File

@ -1,12 +1,8 @@
BOARD:
x make an engine:
x move initializers to lib/...
- write doc about setting up the parent app
x helpers do not work
- deploy on Heroku
- missing translation in english
- password resets (url is not handled correctly)
- mongoid hack for nested attributes
BACKLOG:
@ -26,8 +22,7 @@ BACKLOG:
- refactor slugify method (use parameterize + create a module)
BUGS:
- when assigning new layout, disabled parts show up :-( (js problem)
- password resets (url is not handled correctly)
NICE TO HAVE:
- asset collections: custom resizing if image
@ -117,3 +112,9 @@ x new custom field type: category
x model
x ui
x liquid
x [BUG] when assigning new layout, disabled parts show up :-( (js problem)
x make an engine:
x move initializers to lib/...
x helpers do not work
x missing translation in english
x api security option in content types

View File

@ -23,7 +23,7 @@ $(document).ready(function() {
$(parts).each(function() {
// console.log("iterating..." + this.slug);
var control = $('#control-part-' + this.slug);
// adding missing part
if (control.size() == 0) {
// console.log('adding part');
@ -42,10 +42,15 @@ $(document).ready(function() {
var wrapper = $('#parts-' + index);
// updating part
control.html('<span>' + this.name + '</span>').addClass('enabled').show();
wrapper.find('input.disabled').val('false');
wrapper.show();
}
wrapper.find('input.disabled').val(this.disabled == true ? 'true' : 'false');
if (this.disabled == false) {
control.html('<span>' + this.name + '</span>').addClass('enabled').show();
wrapper.show();
} else {
control.hide();
wrapper.hide();
}
}
});
// removing or hiding parts

View File

@ -149,7 +149,7 @@ ul.assets li.asset div.image div.inside {
ul.assets li.asset div.actions {
position: absolute;
top: 8px;
top: 4px;
right: 12px;
}
@ -234,7 +234,7 @@ div#uploadAssetsInputQueue { display: none; }
#pages-list li .more {
position: absolute;
top: 3px;
top: 6px;
right: 20px;
font-size: 0.7em;
color: #8b8d9a;

View File

@ -224,7 +224,7 @@ form.formtastic fieldset ol li.item em {
form.formtastic fieldset ol li.item span.actions {
position: absolute;
top: 7px;
top: 5px;
right: 10px;
width: 50px;
height: 16px;

View File

@ -66,8 +66,8 @@ describe AssetCollection do
end
it 'should have an unique alias' do
@collection.asset_custom_fields.first._alias.should == "description"
@collection.asset_custom_fields.last._alias.should == "active"
@collection.asset_custom_fields.first.safe_alias.should == "description"
@collection.asset_custom_fields.last.safe_alias.should == "active"
end
end
@ -75,7 +75,6 @@ describe AssetCollection do
context 'build and save' do
it 'should build asset' do
puts "___ TEST #1 ___"
asset = @collection.assets.build
lambda {
asset.description
@ -85,14 +84,12 @@ describe AssetCollection do
end
it 'should assign values to newly built asset' do
puts "___ TEST #2 ___"
asset = build_asset(@collection)
asset.description.should == 'Lorem ipsum'
asset.active.should == true
end
it 'should save asset' do
puts "___ TEST #3 ___"
asset = build_asset(@collection)
asset.save and @collection.reload
asset = @collection.assets.first
@ -101,7 +98,6 @@ describe AssetCollection do
end
it 'should not modify assets from another collection' do
puts "___ TEST #4 ___"
asset = build_asset(@collection)
asset.save and @collection.reload
new_collection = AssetCollection.new