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? %>
<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>
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
<% else %>
<form id="module-search-form">
<div class="sc-field">
@ -15,16 +23,15 @@
<h4><%= @seminar.title %></h4>
<div id="index_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">
<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 %>
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
</div>
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
<% end %>

View File

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