forked from saurabh/orbit4-5
Category and Tag validation
This commit is contained in:
parent
df91ad152c
commit
3f285d9c1e
3
Gemfile
3
Gemfile
|
@ -34,9 +34,6 @@ gem "mini_magick", github: 'minimagick/minimagick'
|
|||
gem 'carrierwave'
|
||||
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
|
||||
|
||||
# Form helper
|
||||
gem 'dynamic_form'
|
||||
|
||||
gem 'kaminari'
|
||||
gem "impressionist"
|
||||
gem "chartkick"
|
||||
|
|
|
@ -2,6 +2,7 @@ class Admin::CategoriesController < OrbitAdminController
|
|||
before_action :setup_vars
|
||||
|
||||
def index
|
||||
@category = Category.new
|
||||
unless @module_app.nil?
|
||||
@categories = @module_app.categories
|
||||
end
|
||||
|
|
|
@ -10,6 +10,8 @@ class Category
|
|||
|
||||
scope :enabled, ->{ where(:disable.in => [false, nil, ''])}
|
||||
|
||||
validates :title, presence: true
|
||||
|
||||
def category_sub_managers
|
||||
Authorization.category_authorized_users(self).pluck(:user_id)
|
||||
end
|
||||
|
|
|
@ -8,6 +8,8 @@ class Tag
|
|||
has_many :taggings, dependent: :destroy
|
||||
has_and_belongs_to_many :module_app
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
def show_names_slash
|
||||
span_names = []
|
||||
Site.first.in_use_locales.each do |locale|
|
||||
|
|
|
@ -16,8 +16,13 @@
|
|||
<fieldset>
|
||||
<%= f.fields_for :title_translations do |f| %>
|
||||
<% @site_in_use_locales.each do |locale| %>
|
||||
<%= label_tag "name-#{locale}", "#{t(:name)} (#{t(locale)})" %>
|
||||
<%= f.text_field locale, :class => 'input-large', :value => (@category.title_translations[locale] rescue ''), placeholder: t(:name), id: locale %>
|
||||
<div class="control-group">
|
||||
<label class="control-label"><%= "#{t(:name)} (#{t(locale)})" %></label>
|
||||
<div class="controls">
|
||||
<input class="input-large" id="<%=locale%>" name="category[title_translations][<%=locale%>]" placeholder="<%=t(:name)%>" type="text">
|
||||
<span class="help-inline hide"><%= t('front_page.name_field_helper') %></span>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= label_tag "disable" do %>
|
||||
|
@ -26,7 +31,7 @@
|
|||
<% end %>
|
||||
<div class="form-actions">
|
||||
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
|
||||
<%= f.submit t(:submit), class: 'btn btn-primary btn-small' %>
|
||||
<%= f.submit t(:submit), class: 'btn btn-primary btn-small', id: "category_submit" %>
|
||||
</div>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
@ -34,3 +39,36 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var validate = function(dom){
|
||||
var valid = true;
|
||||
if($(dom).val()==""){
|
||||
valid=false;
|
||||
$(dom).parent().parent().addClass('error');
|
||||
$(dom).next().removeClass('hide');
|
||||
}else{
|
||||
$(dom).parent().parent().removeClass('error');
|
||||
$(dom).next().addClass('hide');
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
$(function(){
|
||||
$.each($('form input:text'),function(){
|
||||
$(this).blur(function(){
|
||||
validate($(this));
|
||||
});
|
||||
$(this).keyup(function(){
|
||||
validate($(this));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$("#category_submit").click(function(){
|
||||
var valid = true;
|
||||
$.each($("form input:text"),function(){
|
||||
if(!validate($(this))) valid=false;
|
||||
});
|
||||
if(!valid) return false;
|
||||
});
|
||||
</script>
|
|
@ -3,7 +3,12 @@
|
|||
|
||||
<%= f.fields_for :name_translations do |f| %>
|
||||
<% @site_in_use_locales.each do |locale| %>
|
||||
<%= f.label :locale, "#{t(:name)} #{t(locale)}" %>
|
||||
<%= f.text_field locale, class: 'input-large', placeholder: "#{t(:name)} #{t(locale)}", value: (@tag.name_translations[locale] rescue nil), id: locale %>
|
||||
<div class="control-group">
|
||||
<label class="control-label"><%= "#{t(:name)} (#{t(locale)})" %></label>
|
||||
<div class="controls">
|
||||
<input class="input-large" id="<%=locale%>" name="tag[name_translations][<%=locale%>]" placeholder="<%=t(:name)%>" type="text">
|
||||
<span class="help-inline hide"><%= t('front_page.name_field_helper') %></span>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<%= render :partial => "form", :locals => { :f => f } %>
|
||||
<div class="form-actions">
|
||||
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
|
||||
<%= f.submit t(:submit), class: 'btn btn-primary btn-small' %>
|
||||
<%= f.submit t(:submit), class: 'btn btn-primary btn-small', id: "tag_submit" %>
|
||||
</div>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
@ -78,4 +78,38 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var validate = function(dom){
|
||||
var valid = true;
|
||||
if($(dom).val()==""){
|
||||
valid=false;
|
||||
$(dom).parent().parent().addClass('error');
|
||||
$(dom).next().removeClass('hide');
|
||||
}else{
|
||||
$(dom).parent().parent().removeClass('error');
|
||||
$(dom).next().addClass('hide');
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
$(function(){
|
||||
$.each($('.set_new form input:text'),function(){
|
||||
$(this).blur(function(){
|
||||
validate($(this));
|
||||
});
|
||||
$(this).keyup(function(){
|
||||
validate($(this));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$("#tag_submit").click(function(){
|
||||
var valid = true;
|
||||
$.each($(".set_new form input:text"),function(){
|
||||
if(!validate($(this))) valid=false;
|
||||
});
|
||||
if(!valid) return false;
|
||||
});
|
||||
</script>
|
||||
<!-- pageslide:end -->
|
|
@ -13,7 +13,7 @@
|
|||
<div class="accordion-body collapse" id="collapse-<%= field %>">
|
||||
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
|
||||
<% fields[field].each do |val| %>
|
||||
<%= link_to t(val[:title]), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %>
|
||||
<%= link_to (val[:title].blank? ? "" : t(val[:title])), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="filter-clear">
|
||||
|
|
Loading…
Reference in New Issue