Permalink
Browse files

Work in progress

  • Loading branch information...
1 parent c72db32 commit 05b81f4cb32aaea8258b2aabb5b0999350c3346b Egils Mūzis committed Apr 28, 2011
@@ -18,6 +18,16 @@ def create
end
end
+ def update
+ @lov = Lov.find(params[:id])
+ if @lov.update_attributes(params[:lov])
+ flash[:info] = "Ieraksts veiksmīgi saglabāts"
+ redirect_to :action => :edit, :id => @lov.id
+ else
+ render :action => :new
+ end
+ end
+
def edit
@lov = Lov.find(params[:id])
render :action => :new
@@ -0,0 +1,55 @@
+class PeopleAttributeGroupsController < ApplicationController
+
+ def index
+ prepare_collection
+ end
+
+ def new
+ @group = PeopleAttributeGroup.new
+ end
+
+ def create
+ @group = PeopleAttributeGroup.new(params[:people_attribute_group])
+ if @group.save
+ flash[:info] = "Ieraksts veiksmīgi saglabāts"
+ redirect_to :action => :edit, :id => @group.id
+ else
+ render :action => :new
+ end
+ end
+
+ def update
+ @group = PeopleAttributeGroup.find(params[:id])
+ if @group.update_attributes(params[:people_attribute_group])
+ flash[:info] = "Ieraksts veiksmīgi saglabāts"
+ redirect_to :action => :edit, :id => @group.id
+ else
+ render :action => :new
+ end
+ end
+
+ def edit
+ @group = PeopleAttributeGroup.find(params[:id])
+ render :action => :new
+ end
+
+ def destroy
+ group = PeopleAttributeGroup.find(params[:id]).destroy
+ flash[:info] = "Ieraksts veiksmīgi dzēsts"
+ redirect_to :action => :index
+ end
+
+ def search
+ prepare_collection
+ render :action => "index"
+ end
+
+ private
+
+ def prepare_collection
+ @groups = PeopleAttributeGroup.search(params[:search]).order_by(params[:sort]).paginate(:page => params[:page],
+ :per_page => Biomed::Application::PAGINATION_PAGE_SIZE)
+ flash.now[:error] = "Netika atrasts neviens ieraksts" if @groups.empty?
+ end
+
+end
@@ -35,6 +35,10 @@ def custom_error_messages_for(records, options={})
end
end
+ def timestamp
+ Time.now.to_f.to_s.gsub('.','')
+ end
+
private
def sort_direction(current)
@@ -0,0 +1,20 @@
+class PeopleAttribute
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ field :name, :type => String
+ field :data_type, :type => String
+ field :order, :type => Integer
+
+ DATA_TYPES = [
+ { :value => "string", :text => "Teksts", :method => :value_string },
+ { :value => "integer", :text => "Skaitlis", :method => :value_integer },
+ { :value => "date", :text => "Datums", :method => :value_date },
+ { :value => "boolean", :text => "Pazīme", :method => :value_boolean }
+ ]
+
+ def value
+ method = DATA_TYPES.find{|v| v[:name] == data_type }[:method]
+ people_attribute_value.try(method)
+ end
+
+end
@@ -0,0 +1,14 @@
+class PeopleAttributeGroup
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ include Mongoid::Search
+
+ field :name, :type => String
+
+ embeds_many :people_attributes
+ accepts_nested_attributes_for :people_attributes, :reject_if => lambda {|a| a.name.blank? || a.data_type.blank? }
+
+ validates_presence_of :name
+
+ search_in :name, { :allow_empty_search => true, :match => :any }
+end
@@ -0,0 +1,9 @@
+class PeopleAttributeValue
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ field :value_string, :type => String
+ field :value_integer, :type => String
+ field :value_date, :type => Date
+ field :value_boolean, :type => Boolean
+
+end
@@ -17,7 +17,7 @@
<% [{:name => "Paraugi", :link => root_path, :controller => "specimens"},
{:name => "Personas", :link => "#"},
{:name => "Paraugu datu konfigurācija", :link => "#"},
- {:name => "Personu datu konfigurācija", :link => "#"},
+ {:name => "Personu datu konfigurācija", :link => people_attribute_groups_path, :controller => "people_attribute_groups"},
{:name => "Vērtību saraksti", :link => lovs_path, :controller => "lovs"}].each do |h| %>
<%= link_to h[:name], h[:link], :class => "pill button #{"active" if controller_name == h[:controller]}" %>
<% end %>
@@ -16,7 +16,7 @@
<th class="actions">&nbsp;</th>
</thead>
<% @lovs.each do |o| %>
- <tr>
+ <tr controller="<%= controller_name %>" o_id="<%= o.id %>">
<td><%= o.name %></td>
<td><%= o.values.join(", ") %></td>
<td><%= link_to "Dzēst", { :action => :destroy, :id => o.id}, :method => :delete, :class => "danger icon trash button", :confirm => "Vai esat pārliecināts?" %></td>
@@ -1,13 +1,17 @@
<h2>Vērtību saraksts</h2>
<%= render_flash_messages %>
<%= form_for @lov do |f| %>
- <%= custom_error_messages_for([f.object]) %>
+ <% unless f.object.errors.empty? %>
+ <div class="errors">
+ <%= custom_error_messages_for([f.object]) %>
+ </div>
+ <% end %>
<div class="form_field">
- <%= f.label :name, "Nosaukums" %>
+ <%= f.label :name, "Nosaukums<span class='required'>*</span>".html_safe %>
<%= f.text_field :name %>
</div>
<div class="form_field">
- <%= f.label :values, "Vērtības" %>
+ <%= f.label :values, "Vērtības<span class='required'>*</span>".html_safe %>
<%= f.text_field :values, :class => "has_qtip", :qtext => "Vērtības atdalīt ar komatiem", :value => f.object.values.try(:join,",") %>
</div>
<div class="form_actions">
@@ -0,0 +1,29 @@
+<div id="index_page">
+ <%= link_to "Pievienot jaunu", { :action => :new }, :class => "button icon add positive right" %>
+ <h2>Datu grupas</h2>
+ <%= render_flash_messages %>
+ <div id="search_box">
+ <%= form_tag("/#{controller_name}/search") do %>
+ <%= text_field_tag "search", params[:search], :class => "search_field" %>
+ <%= link_to "Meklēt", "#", :class => "button icon search submit" %>
+ <% end %>
+ </div>
+ <% unless @groups.empty? %>
+ <table class="index_table">
+ <thead>
+ <th><%= sortable "Nosaukums", "name", controller_name, params %></th>
+ <th class="actions">&nbsp;</th>
+ </thead>
+ <% @groups.each do |o| %>
+ <tr controller="<%= controller_name %>" o_id="<%= o.id %>">
+ <td><%= o.name %></td>
+ <td><%= link_to "Dzēst", { :action => :destroy, :id => o.id}, :method => :delete, :class => "danger icon trash button", :confirm => "Vai esat pārliecināts?" %></td>
+ </tr>
+ <% end %>
+ <tbody>
+ </tbody>
+ </table>
+ <% end %>
+ <%= will_paginate(@groups, Biomed::Application::PAGINATION_DISPLAY_OPTIONS.merge(
+ {:params => { :action => :index, :search => params[:search] }})) %>
+</div>
@@ -0,0 +1,21 @@
+<h2>Datu grupa</h2>
+<%= render_flash_messages %>
+<%= form_for @group do |f| %>
+ <% unless f.object.errors.empty? %>
+ <div class="errors">
+ <%= custom_error_messages_for([f.object]) %>
+ </div>
+ <% end %>
+ <div class="form_field">
+ <%= f.label :name, "Nosaukums<span class='required'>*</span>".html_safe %>
+ <%= f.text_field :name %>
+ </div>
+ <% @group.people_attributes.each do |o| %>
+ <%= render :partial => "/people_attributes/people_attribute", :locals => { :attribute => o } %>
+ <% end %>
+ <%= link_to "Pievienot jaunu vērtību", "#", :class => "button pill add_new_people_attribute"%>
+ <div class="form_actions">
+ <%= f.submit "Sablagāt", :class => "button" %>
+ <%= link_to "Atpakaļ", people_attribute_groups_path, :class => "button" %>
+ </div>
+<% end %>
@@ -0,0 +1,10 @@
+<%= fields_for "people_attribute_group[people_attributes_attributes][#{attribute.id||timestamp}]", attribute do |ff| %>
+ <div class="form_field">
+ <%= ff.label :name, "Vērtības nosaukums<span class='required'>*</span>".html_safe %>
+ <%= ff.text_field :name %>
+ </div>
+ <div class="form_field">
+ <%= ff.label :data_type, "Datu tips<span class='required'>*</span>".html_safe %>
+ <%= ff.text_field :date_type %>
+ </div>
+<% end %>
View
@@ -5,10 +5,13 @@ lv:
messages: &errors_messages
empty: "nedrīkst būt tukšs/-i"
blank: "nedrīkst būt tukšs/-i"
+ taken: "nedrīkst atkārtoties"
attributes:
lov:
name: "Nosaukums"
values: "Vērtības"
+ people_attribute_group:
+ name: "Nosaukums"
support:
array:
View
@@ -6,8 +6,13 @@
post :login, :to => "sessions#login"
get :logout, :to => "sessions#logout"
- resources :specimens
- resources :lovs do
+ resources :people_attribute_groups, :except => [:show] do
+ collection do
+ match :search
+ end
+ end
+ resources :specimens, :except => [:show]
+ resources :lovs, :except => [:show] do
collection do
match :search
end
@@ -1,6 +1,8 @@
$(document).ready(function(){
submit_link_handler.call(this);
qtip_handler.call(this);
+ show_action_handler.call(this);
+ add_people_attribute_handler.call(this);
});
function submit_link_handler(){
@@ -10,6 +12,14 @@ function submit_link_handler(){
})
}
+function show_action_handler(){
+ $("table.index_table tbody tr").live("click",function(){
+ var controller = $(this).attr("controller");
+ var id = $(this).attr("o_id");
+ window.location = "/"+controller+"/"+id+"/edit";
+ });
+}
+
function qtip_handler(){
$(".has_qtip").each(function(){
var qtext = $(this).attr("qtext");
@@ -39,4 +49,10 @@ function qtip_handler(){
}
})
});
+}
+
+function add_people_attribute_handler(){
+ $(".add_new_people_attribute").live("click",function(){
+ alert("yo");
+ })
}
@@ -129,7 +129,8 @@ input {
background-color: #C7F464;
}
#flash_error {
- background-color: #C44D58;
+ background-color: #FFE6E6;
+ color: #E81717;
}
.flash {
font-weight: bold;
@@ -216,7 +217,24 @@ div.form_field input {
}
div.form_field label {
padding: 9px;
+ padding-right: 15px;
}
.form_actions {
- margin: 20px 0 5px 100px;
-}
+ margin: 20px 0 5px 106px;
+}
+.errors ul {
+ list-style: none;
+ padding: 6px 12px;
+ background: #FCE8F0;
+ color: #dc1a41;
+}
+span.required {
+ color: red;
+ font-size: 14px;
+ line-height: 1;
+ padding-left: 5px;
+}
+.add_new_people_attribute {
+ margin-top: 15px;
+ padding: 0.2em 1em;
+}

0 comments on commit 05b81f4

Please sign in to comment.