forked from saurabh/orbit4-5
83 lines
2.8 KiB
Plaintext
83 lines
2.8 KiB
Plaintext
<div id="group_categories">
|
|
<%= render :partial => "group_categories" %>
|
|
</div>
|
|
<a href="" class="btn btn-primary" data-toggle="modal" data-target="#categoryModal">+</a>
|
|
<div class="modal fade" id="categoryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
|
<h4 class="modal-title" id="myModalLabel"><%= t(:new_category) %></h4>
|
|
</div>
|
|
<div class="modal-body">
|
|
<% @site_in_use_locales.each do |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">Please enter category title</span>
|
|
</div>
|
|
</div>
|
|
<% end %>
|
|
<div class="text-error text-center"><%= t(:category_notice) %></div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-default pull-left" data-dismiss="modal"><%= t(:close) %></button>
|
|
<button type="button" class="btn btn-primary" id="add_category"><%= t(:add) %></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
$(function(){
|
|
$("#add_category").click(createCategory);
|
|
|
|
$("#categoryModal .modal-body").keypress(function(e) {
|
|
if(e.which == 13) {
|
|
createCategory();
|
|
return false;
|
|
}
|
|
});
|
|
|
|
$.each($('#categoryModal .input-large'),function(){
|
|
$(this).blur(function(){
|
|
if($(this).val()==""){
|
|
$(this).parent().parent().addClass('error');
|
|
$(this).next().removeClass('hide');
|
|
}else{
|
|
$(this).parent().parent().removeClass('error');
|
|
$(this).next().addClass('hide');
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
var createCategory = function(){
|
|
var valid = true;
|
|
$.each($('#categoryModal .input-large'),function(){
|
|
if($(this).val()==""){
|
|
$(this).parent().parent().addClass('error');
|
|
$(this).next().removeClass('hide');
|
|
valid = false;
|
|
}else{
|
|
$(this).parent().parent().removeClass('error');
|
|
$(this).next().addClass('hide');
|
|
}
|
|
});
|
|
|
|
if(valid){
|
|
$.ajax({
|
|
url : "/admin/groups/create_category",
|
|
type : "post",
|
|
data: $("input[name^='category']").serialize(),
|
|
}).done(function(data){
|
|
$.each($('#categoryModal .input-large'),function(){
|
|
$(this).val("");
|
|
});
|
|
$("#group_categories").html(data);
|
|
$('#categoryModal').modal('hide');
|
|
});
|
|
}
|
|
}
|
|
</script> |