Permalink
Browse files

added layout, more flashes and destroy link

  • Loading branch information...
1 parent 367509e commit 154b1945753697f01f1dddd470c0a8f69535bfdb @grosser grosser committed May 2, 2009
View
@@ -1,4 +1,5 @@
-A interface for database stored translation editing as rails engine.
+A interface for database stored translation editing as rails engine.
+Uses your styles/layout and fits seamlessly.
Setup
=====
@@ -23,7 +24,8 @@ Setup
TODO
====
- - layout/title/styles/js/search
+ - specs
+ - search + ordering + pagination
- po/mo to db conversion task
Author
@@ -1,6 +1,15 @@
class TranslationKeysController < ActionController::Base
before_filter :authenticate
- before_filter :find_translation_key, :only=>%w[show edit update]
+ before_filter :find_translation_key, :only=>%w[show edit update destroy]
+
+ #use host layout/helpers
+ helper :all
+ layout :choose_layout
+
+ #prevent 'method missing' for normally controller-side helpers
+ def current_user;nil;end
+ def logged_in?;false;end
+ helper_method :current_user, :logged_in?
def index
@translation_keys = TranslationKey.find(:all)
@@ -15,8 +24,10 @@ def new
def create
@translation_key = TranslationKey.new(params[:translation_key])
if @translation_key.save
+ flash[:notice] = 'Created!'
redirect_to translation_key_path(@translation_key)
else
+ flash[:error] = 'Failed to save!'
render :action=>:edit
end
end
@@ -30,21 +41,33 @@ def edit
def update
if @translation_key.update_attributes(params[:translation_key])
- flash[:notice] = 'Succesfully saved!'
+ flash[:notice] = 'Saved!'
redirect_to @translation_key
else
flash[:error] = 'Failed to save!'
render :action=>:edit
end
end
+ def destroy
+ @translation_key.destroy
+ redirect_to translation_keys_path
+ end
+
protected
+ def self.config
+ @@config ||= YAML::load(File.read(Rails.root.join('config','translation_db_engine.yml'))).with_indifferent_access rescue {}
+ end
+
+ def choose_layout
+ @@config[:layout] || 'application'
+ end
+
def authenticate
- auth = YAML::load(File.read(Rails.root.join('config/translation_db_engine.yml')))['auth'] rescue return
-
+ return unless auth = self.class.config[:auth]
authenticate_or_request_with_http_basic do |username, password|
- username == auth['name'] && password == auth['password']
+ username == auth[:name] && password == auth[:password]
end
end
@@ -1,6 +1,7 @@
<% new = @translation_key.new_record? %>
<h1><%= @translation_key.key || "New translation" %></h1>
<% form_for @translation_key do |f|%>
+ <%= f.error_messages %>
<p>
<%= f.label :key %>
<%= f.text_area :key, :size=>'80x4' %>
@@ -9,9 +10,11 @@
<% f.fields_for :translations do |tf|%>
<p>
<%= tf.label :text, tf.object.locale %>
- <%= tf.text_area :text, :size=>'80x4' %>
+ <%= tf.text_area :text, :size=>'80x2' %>
</p>
+ <%= tf.hidden_field :locale if tf.object.new_record? %>
<% end %>
<%= f.submit(new ? "Create" : "Save") %>
+ <%= link_to 'Back to overview', translation_keys_path %>
<% end %>
@@ -12,13 +12,16 @@
</thead>
<tbody>
<% @translation_keys.each do |key| %>
- <tr>
+ <tr class="<%= cycle "even","odd"%>">
<td><%= key.key %></td>
<% translations = key.translations.map{|t| [t.locale, t]} %>
<% locales.each do |locale| %>
<td><%= translations.assoc(locale)[1].text if translations.assoc(locale) %></td>
<% end %>
- <td><%= link_to "Edit", key %></td>
+ <td>
+ <%= link_to '<b style="color:red">X</b>', key, :confirm=>"Delete key #{key.key} ?", :method=>:delete %>
+ <%= link_to "Edit", key %>
+ </td>
</tr>
<% end %>
</tbody>
@@ -1,4 +1,5 @@
#place this file in RAILS_ROOT/config and change the name/password
auth:
name: translator
- password: test
+ password: test
+layout: application

0 comments on commit 154b194

Please sign in to comment.