survey/app/views/admin/surveys/answer_sets.html.erb

131 lines
4.3 KiB
Plaintext
Raw Normal View History

<style type="text/css">
#survey_answer_search label{
float: left;
margin-right: 0.5em;
line-height: 2;
}
#survey_answer_search input{
float: left;
line-height: 2;
}
</style>
<script type="text/javascript" src="/assets/lib/process.manager.js"></script>
<div id="downloadModal" data-backdrop="static" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="downloadModalLabel" aria-hidden="true">
<div class="modal-header">
<h3 id="downloadModalLabel">Download</h3>
</div>
<div class="modal-body">
<p id="wait-zone" style="text-align: center;">
Please wait while we prepare your download. This may take a while.
<br />
<img src="/assets/spin.gif" />
</p>
<p id="link-zone" style="display: none; text-align: center;">
Please click the link below to download.
<br />
<a href="" id="download-link" target="_blank">Download</a>
</p>
</div>
<div class="modal-footer">
<button class="btn" id="modal-close-btn" style="display:none;" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
<h3><%= @survey.title %></h3>
<div>
<% if @is_answer_list %>
2021-09-12 12:56:09 +00:00
<h4><%=t('survey.taken_by')%>: <%=@user.member_name rescue "NA" %></h4>
<% else %>
<form id="survey_answer_search">
<div>
<label for="search_taken_by"><%=t('survey.taken_by')%>:</label>
<input type="text" id="search_taken_by" name="search" placeholder="<%=t('survey.taken_by')%>" value="<%=params[:search]%>">
<input type="submit" value="<%=t(:search_)%>">
</div>
<div style="clear: both;"></div>
</form>
<% end %>
</div>
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% (@survey_answer_groups || @survey_answers).each do |sa| %>
<tr>
<% user = sa.user.nil? ? nil : (User.find(sa.user) rescue nil) %>
<% if !user.nil? %>
<td><%= user.member_name rescue user.name %></td>
<% else %>
<td>NA</td>
<% end %>
<td><%= (@is_answer_list ? sa.updated_at : sa.last_modified).strftime("%h %d, %Y - %H:%M") rescue nil %></td>
<td>
<% if @answer_repeat && !@is_answer_list %>
<a class="btn btn-primary" href="/admin/surveys/<%= sa.id.to_s %>/answer_list"><%= t("survey.view") %>(<%=sa.survey_answer_ids.count%>)</a>
<button class="btn btn-primary export-xls" data-href="/admin/surveys/<%= sa.id.to_s %>/export_answers"><%= t("survey.export") %></button>
<% else %>
<a class="btn btn-primary" href="/admin/surveys/<%= @is_answer_list ? sa.id : sa.survey_answer_ids.last.to_s %>/answer_set"><%= t("survey.view_answers") %></a>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate((@survey_answer_groups || @survey_answers)), class: "pagination pagination-centered"
end
%>
<script type="text/javascript">
var downloadModal = $("#downloadModal"),
checkForThread = null,
waitZone = $("#wait-zone"),
linkZone = $("#link-zone"),
downloadLink = $("a#download-link"),
modalBtn = $("#modal-close-btn"),
processManager = new ProcessManager();
$(document).on("click", ".export-xls", function(){
var link = $(this).data("href"),
title = null,
id = "<%=@survey.id%>";
linkZone.hide();
waitZone.show();
modalBtn.hide();
$.ajax({
url : link,
type : "get",
dataType : "json"
}).done(function(data){
title = data.title;
checkForThread = new Process(function(){
$.ajax({
url : "/admin/surveys/checkforthread",
type : "get",
data : {"survey_id" : id, "survey_title" : title},
dataType : "json"
}).done(function(data){
if(!data.status){
downloadLink.attr("href", "/uploads/survey_export/" + id + "/" + title + ".xlsx");
waitZone.hide();
linkZone.show();
modalBtn.show();
checkForThread.kill();
}
})
})
checkForThread.setTimeInterval(1000);
checkForThread.setRepeat(Process.CONSTANTS.REPEAT_INFINITE);
processManager.queue(checkForThread);
})
downloadModal.modal("show");
return false;
})
</script>