js for preventing user do stupid things durning ajax

This commit is contained in:
Matthew K. Fu JuYuan 2012-05-22 13:22:24 +08:00
parent e05cf2a2d6
commit ae006cc29f
7 changed files with 44 additions and 22 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

@ -0,0 +1,14 @@
// $.ready(function(){
// $('body').bind("ajaxSend", function(){
// $('<div class="modal-backdrop fade in"></div>').appendTo('body');
// }).bind("ajaxComplete", function(){
// $('body > div.modal-backdrop').hide().remove();
// });
// });
jQuery(document).ajaxStart(function(){
$('<div class="modal-backdrop fade in" id="sys_modal"><img src="/assets/ajax-loader.gif" style="margin-top: 25%;margin-left: 50%;"></div>').appendTo('body');
});
jQuery(document).ajaxComplete(function(){
$("#sys_modal").hide().remove();
});

View File

@ -9,6 +9,7 @@
<![endif]-->
<%= stylesheet_link_tag "new_admin" %>
<%= javascript_include_tag "new_admin" %>
<%= javascript_include_tag "inc/ajax_setting" %>
<%= yield :page_specific_css %>
<%= yield :page_specific_javascript %>
<%= csrf_meta_tag %>

View File

@ -20,7 +20,7 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
else
@bulletin_category = @bulletin_categorys.first
end
preload_object_auth = @bulletin_category.object_auths.where(title: 'fact_check').empty?? (@bulletin_category.object_auths.create! :title=> 'fact_check') : @bulletin_category.object_auths.where(title: 'fact_check')
preload_object_auth = @bulletin_category.get_object_auth_by_title('fact_check')
@users_array = preload_object_auth.first.privilege_users rescue []
respond_to do |format|
format.html

View File

@ -4,7 +4,7 @@ class Panel::News::BackEnd::NewsApprovalsController < OrbitBackendController
include AdminHelper
def preview_and_approve
@news_bulletin = NewsBulletin.find params[:news_bulletin_id]
@news_bulletin = NewsBulletin.find params[:news_category][:id]
end
def approve
@ -14,19 +14,13 @@ class Panel::News::BackEnd::NewsApprovalsController < OrbitBackendController
def setting
@sys_users = User.all(conditions: {admin: false})
@news_bulletin_categorys = NewsBulletinCategory.all
if params.has_key?(:category_id)
first_category = NewsBulletinCategory.find params[:category_id]
if params[:commit] == 'Update'
privilege_users = params[:users].collect{|key,value| User.find key } rescue []
preload_object_auth_ary = first_category.object_auths.where(title: 'fact_check') || (first_category.object_auths.create :title=> 'fact_check')
preload_object_auth = preload_object_auth_ary.first
preload_object_auth.privilege_users = privilege_users
preload_object_auth.save!
end
@options_from_collection_for_select_news_bulletin_categorys = @news_bulletin_categorys.collect{|bc| [bc.i18n_variable[I18n.locale],bc.id] }
if params.has_key? :news_category
@news_bulletin_categorys = NewsBulletinCategory.find params[:news_category][:id]
else
first_category = @news_bulletin_categorys.first
@news_bulletin_categorys = @news_bulletin_categorys.first
end
preload_object_auth = first_category.object_auths.where(title: 'fact_check').empty?? (first_category.object_auths.create! :title=> 'fact_check') : first_category.object_auths.where(title: 'fact_check')
preload_object_auth = @news_bulletin_categorys.get_object_auth_by_title('fact_check')
@users_array = preload_object_auth.first.privilege_users rescue []
respond_to do |format|
format.html
@ -44,12 +38,12 @@ class Panel::News::BackEnd::NewsApprovalsController < OrbitBackendController
end
def user_list
@news_bulletin_category = NewsBulletinCategory.find params[:category_id]
@news_bulletin_category = NewsBulletinCategory.find params[:news_category][:id]
end
protected
def update_setting_by_params
category = NewsBulletinCategory.find params[:category_id]
category = NewsBulletinCategory.find params[:news_category][:id]
privilege_users = params[:users].collect{|key,value| User.find key } rescue []
object_auth_ary = category.object_auths.where(title: 'fact_check') || (category.object_auths.create :title=> 'fact_check')
object_auth = object_auth_ary.first

View File

@ -13,7 +13,7 @@
<li class="accordion-group">
<div class="form-search" style="margin: 5px 10px;">
<%= label_tag :category, t("news.news_bulletin.category") %>
<%= select_tag "category_id", options_from_collection_for_select(@news_bulletin_categorys, "id", "key") %>
<%= select "news_category",'id', @options_from_collection_for_select_news_bulletin_categorys %>
<%= search_field_tag 'user_filter' %>
</div>
</li>
@ -34,9 +34,21 @@
<script type="text/javascript" charset="utf-8">
var availableTags = [];
$(function() {
$('#category_id').change(function() {
$(this).parents('form').submit();
});
$(document).ready(function() {
$(".prevent_enter_submit_form").bind("keypress", function(e) {
if (e.keyCode == 13) {
return false;
}
});
$('#news_category_id').change(function() {
$.ajax({
type: 'GET',
dataType: "script",
url:$(this).parents("from").attr("href"),
data:$(this).parents("form").serialize()
});//.ajaxStart(function(){$('body').append('<div class="modal-backdrop fade in" id="modal_layer"></div>')});//.ajaxStop(function(){"#modal_layer"}).remove();
});
});
</script>

View File

@ -1 +1,2 @@
$("#users_checkbox_ary").replaceWith('<%= (render :partial => 'privilege_user', :locals => {:users => @users_array}).html_safe%>');
$("#users_checkbox_ary").replaceWith('<%= escape_javascript(render :partial => "privilege_user", :locals => {:users => @users_array})%>');
permissionCheckbox();