Fix xhr bug.

This commit is contained in:
BoHung Chiu 2021-04-24 20:11:23 +08:00
parent 67e1dd153f
commit a6fde99d96
2 changed files with 89 additions and 78 deletions

View File

@ -1,7 +1,15 @@
<% if request.xhr? %> <% if request.xhr? %>
<div id="index_table"> <%= render :partial => "seminar_signup_render_table" %>
<%= render :partial => "seminar_signup_render_table" %> <div class="bottomnav clearfix">
<div class="pagination pagination-centered"><%= (paginate(@seminar_signups) rescue nil) %></div>
<% if @can_edit %>
<div class="action pull-right">
<%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t("seminar.field_display_setting"), seminar_signup_admin_setting_admin_seminar_path(params[:id]) + "?page=table", :class => 'btn btn-primary' %>
</div>
<% end %>
</div> </div>
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
<% else %> <% else %>
<form id="module-search-form"> <form id="module-search-form">
<div class="sc-field"> <div class="sc-field">
@ -15,16 +23,15 @@
<h4><%= @seminar.title %></h4> <h4><%= @seminar.title %></h4>
<div id="index_table"> <div id="index_table">
<%= render :partial => "seminar_signup_render_table" %> <%= render :partial => "seminar_signup_render_table" %>
</div> <div class="bottomnav clearfix">
<div class="pagination pagination-centered"><%= (paginate(@seminar_signups) rescue nil) %></div>
<% if @can_edit %>
<div class="action pull-right">
<%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t("seminar.field_display_setting"), seminar_signup_admin_setting_admin_seminar_path(params[:id]) + "?page=table", :class => 'btn btn-primary' %>
</div>
<% end %>
</div>
<div class="bottomnav clearfix"> <%= render 'layouts/delete_modal', delete_options: @delete_options %>
<div class="pagination pagination-centered"><%= (paginate(@seminar_signups) rescue nil) %></div>
<% if @can_edit %>
<div class="action pull-right">
<%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t("seminar.field_display_setting"), seminar_signup_admin_setting_admin_seminar_path(params[:id]) + "?page=table", :class => 'btn btn-primary' %>
</div>
<% end %>
</div> </div>
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
<% end %> <% end %>

View File

@ -1,22 +1,24 @@
<script> <% unless request.xhr? %>
if(document.querySelectorAll("#orbit-bar").length==0) location.reload(); <script>
</script> if(document.querySelectorAll("#orbit-bar").length==0) location.reload();
<div id="jquery_form_dialog"> </script>
<div style="clear:both;"></div> <div id="jquery_form_dialog">
<div id="jquery_form_content"> <div style="clear:both;"></div>
<div id="jquery_form_content">
</div>
</div> </div>
</div> <% if @can_edit %>
<% if @can_edit %> <% if params[:type].blank?%>
<% if params[:type].blank?%> <label><input id="copy_mode_on" type="checkbox"><%=t("seminar.copy_mode_on")%></label>
<label><input id="copy_mode_on" type="checkbox"><%=t("seminar.copy_mode_on")%></label>
<% end %>
<ul class="pull-right">
<li><a href="?type=" class="btn <%='active' if params[:type].blank? %>"><%= t('seminar.dashboard') %></a></li>
<% if @seminar.enable_summary_choice %>
<li><a href="?type=session" class="btn <%='active' if params[:type] == 'session'%>"><%= t('seminar.session_dashboard') %></a></li>
<% end %> <% end %>
<li><a href="?type=table" class="btn <%='active' if params[:type] == 'table'%>"><%= t('seminar.table') %></a></li> <ul class="pull-right">
</ul> <li><a href="?type=" class="btn <%='active' if params[:type].blank? %>"><%= t('seminar.dashboard') %></a></li>
<% if @seminar.enable_summary_choice %>
<li><a href="?type=session" class="btn <%='active' if params[:type] == 'session'%>"><%= t('seminar.session_dashboard') %></a></li>
<% end %>
<li><a href="?type=table" class="btn <%='active' if params[:type] == 'table'%>"><%= t('seminar.table') %></a></li>
</ul>
<% end %>
<% end %> <% end %>
<% if params[:type] == "table" || (!@can_edit) %> <% if params[:type] == "table" || (!@can_edit) %>
<div style="clear: both;"></div> <div style="clear: both;"></div>
@ -26,54 +28,56 @@
<% else %> <% else %>
<%= render :partial => 'seminar_signup_dashboard' %> <%= render :partial => 'seminar_signup_dashboard' %>
<% end %> <% end %>
<style type="text/css"> <% unless request.xhr? %>
.pull-right li{ <style type="text/css">
float: left; .pull-right li{
} float: left;
li{ }
list-style: none; li{
} list-style: none;
</style> }
<script> </style>
$(document).on("submit","#jquery_form",function(e) { <script>
var form = $(this); $(document).on("submit","#jquery_form",function(e) {
var url = form.attr('action'); var form = $(this);
var method = form.attr('method'); var url = form.attr('action');
method = method || "POST"; var method = form.attr('method');
$.ajax({ method = method || "POST";
type: method, $.ajax({
url: url, type: method,
data: form.serialize(), // serializes the form's elements. url: url,
success: function(data) data: form.serialize(), // serializes the form's elements.
{ success: function(data)
if(data["success"]){ {
window.open_target_td.html(data["val"]+Array.from(window.open_target_td.find(">*").map(function(i,v){ if(data["success"]){
return $(v).prop("outerHTML"); window.open_target_td.html(data["val"]+Array.from(window.open_target_td.find(">*").map(function(i,v){
})).join("")); return $(v).prop("outerHTML");
}else{ })).join(""));
console.log(data); }else{
} console.log(data);
} }
}); }
});
e.preventDefault(); // avoid to execute the actual submit of the form. e.preventDefault(); // avoid to execute the actual submit of the form.
}); });
$(document).on('click', '.jquery_edit', function(){ $(document).on('click', '.jquery_edit', function(){
var href = $(this).data("href"); var href = $(this).data("href");
window.open_target_td = $(this).parents("td"); window.open_target_td = $(this).parents("td");
$.get(href).done(function(html){ $.get(href).done(function(html){
$("#jquery_form_content").html(html); $("#jquery_form_content").html(html);
$("#jquery_form_dialog").dialog({ $("#jquery_form_dialog").dialog({
resizable: true, resizable: true,
minHeight: 300, minHeight: 300,
maxHeight: 400, maxHeight: 400,
modal: true, modal: true,
width: '80%', width: '80%',
close: function(){$( this ).dialog( "close" )}, close: function(){$( this ).dialog( "close" )},
buttons: { buttons: {
"<%= t('submit') %>": function(){$( this ).dialog( "close" );$("#jquery_form").submit()} "<%= t('submit') %>": function(){$( this ).dialog( "close" );$("#jquery_form").submit()}
} }
}); });
})
}) })
}) </script>
</script> <% end %>