工程认证:毕业要求和指标点修改,会导致后续其它几个相关矩阵的页面数据丢失,需要优化实现

dev_aliyun
cxt 5 years ago
parent f90c750826
commit 44af3aadf4

@ -50,10 +50,15 @@ class EcGraduationRequirementsController < ApplicationController
@year = requirement.ec_year @year = requirement.ec_year
@template_major = admin_or_business? || @year.ec_major_school.school.ec_school_users.pluck(:user_id).include?(User.current.id) @template_major = admin_or_business? || @year.ec_major_school.school.ec_school_users.pluck(:user_id).include?(User.current.id)
requirement.update_attribute(:content, params[:requirement]) requirement.update_attribute(:content, params[:requirement])
requirement.ec_graduation_subitems.destroy_all # requirement.ec_graduation_subitems.destroy_all
params[:subitems].try(:each_with_index) do |sub, index| params[:subitems].try(:each_with_index) do |sub, index|
subitem = requirement.ec_graduation_subitems.where(position: index+1).first
if subitem.present?
subitem.update_attributes(:content => sub)
else
EcGraduationSubitem.create(:content => sub, :position => index+1, :ec_graduation_requirement_id => requirement.id) EcGraduationSubitem.create(:content => sub, :position => index+1, :ec_graduation_requirement_id => requirement.id)
end end
end
@ec_graduation_requirements = requirement.ec_year.ec_graduation_requirements @ec_graduation_requirements = requirement.ec_year.ec_graduation_requirements
end end

@ -82,9 +82,13 @@ class EcGraduationSubitemsController < ApplicationController
# DELETE /ec_graduation_subitems/1.json # DELETE /ec_graduation_subitems/1.json
def destroy def destroy
@ec_graduation_subitem = EcGraduationSubitem.find(params[:id]) @ec_graduation_subitem = EcGraduationSubitem.find(params[:id])
@ec_graduation_requirement = @ec_graduation_subitem.ec_graduation_requirement
@ec_graduation_requirement.ec_graduation_subitems.where("position > #{@ec_graduation_subitem.position}").update_all("position = position - 1")
@ec_graduation_requirements = @ec_graduation_requirement.ec_year.ec_graduation_requirements
@ec_graduation_subitem.destroy @ec_graduation_subitem.destroy
respond_to do |format| respond_to do |format|
format.js
format.html { redirect_to ec_graduation_subitems_url } format.html { redirect_to ec_graduation_subitems_url }
format.json { head :no_content } format.json { head :no_content }
end end

@ -0,0 +1,25 @@
<li class="clearfix" id="require_<%= requirement.id %>">
<p class="clearfix df">
<span class="fl column-second"><%= requirement.position %></span>
<span class="fl flex1 font-bd lineh-20 pt3"><%= requirement.content %></span>
<span class="lineh-20 pt5">
<% if template_major %>
<% if requirement.position == @ec_graduation_requirements.count %>
<a href="javascript:void(0)" class="newAddSubentry" onclick="ShowPanel();" data-tip-down="添加"><i class="iconfont icon-tianjiafangda color-green ml15"></i></a>
<% end %>
<a href="javascript:void(0)" onclick="delete_confirm_box_2('<%= ec_graduation_requirement_path(requirement) %>','是否确认删除?')" data-remote="true" data-method="DELETE" class="mr15 fl" data-tip-down="删除"><i class="iconfont icon-shanchu color-grey-c font-15 fl mt2"></i></a>
<a href="<%= edit_ec_graduation_requirement_path(requirement) %>" class="fl" data-tip-down="编辑" data-remote="true"><i class="iconfont icon-bianjidaibeijing color-green "></i></a>
<% end %>
</span>
</p>
<% if requirement.ec_graduation_subitems.present? %>
<div class="mt10">
<% requirement.ec_graduation_subitems.each do |sub| %>
<p class="clearfix df pr48 mb5 lineh-20">
<span class="fl column-second"><%= "#{requirement.position}-#{sub.position}" %></span>
<span class="fl flex1"><%= sub.content %></span>
</p>
<% end %>
</div>
<% end %>
</li>

@ -1,31 +1,7 @@
<% if @ec_graduation_requirements.present? && @ec_graduation_requirements.count>0 %> <% if @ec_graduation_requirements.present? && @ec_graduation_requirements.count>0 %>
<% @ec_graduation_requirements.each_with_index do |requirement, index| %> <% @ec_graduation_requirements.each_with_index do |requirement| %>
<li class="clearfix" id="require_<%= requirement.id %>"> <%= render :partial => "ec_graduation_requirements/requirement_item", :locals => {:requirement => requirement, :template_major => @template_major} %>
<p class="clearfix df">
<span class="fl column-second"><%= requirement.position %></span>
<span class="fl flex1 font-bd lineh-20 pt3"><%= requirement.content %></span>
<span class="lineh-20 pt5">
<% if @template_major %>
<% if index+1 == @ec_graduation_requirements.count %>
<a href="javascript:void(0)" class="newAddSubentry" onclick="ShowPanel();" data-tip-down="添加"><i class="iconfont icon-tianjiafangda color-green ml15"></i></a>
<% end %> <% end %>
<a href="javascript:void(0)" onclick="delete_confirm_box_2('<%= ec_graduation_requirement_path(requirement) %>','是否确认删除?')" data-remote="true" data-method="DELETE" class="mr15 fl" data-tip-down="删除"><i class="iconfont icon-shanchu color-grey-c font-15 fl mt2"></i></a>
<a href="<%= edit_ec_graduation_requirement_path(requirement) %>" class="fl" data-tip-down="编辑" data-remote="true"><i class="iconfont icon-bianjidaibeijing color-green "></i></a>
<% end %>
</span>
</p>
<% if requirement.ec_graduation_subitems.present? %>
<div class="mt10">
<% requirement.ec_graduation_subitems.each_with_index do |sub, index| %>
<p class="clearfix df pr48 mb5 lineh-20">
<span class="fl column-second"><%= "#{requirement.position}-#{sub.position}" %></span>
<span class="fl flex1"><%= sub.content %></span>
</p>
<% end %>
</div>
<% end %>
</li>
<% end %>
<% elsif @template_major %> <% elsif @template_major %>
<form id="form_data_for_requirements"> <form id="form_data_for_requirements">
<div class="clearfix ml30 mr30 pt20 pb20 bor-top-greyE" id="requirementNew"> <div class="clearfix ml30 mr30 pt20 pb20 bor-top-greyE" id="requirementNew">

@ -1,5 +1,5 @@
if($("#form_data_for_requirements").length==0){ if($("#form_data_for_requirements").length==0){
var html_begin = "<form id=\"form_data_for_requirements\"><div class=\"clearfix mt20\" id=\"requirementNew\">" var html_begin = "<form id=\"form_data_for_requirements\"><li class=\"clearfix\"><div class=\"clearfix mt20\" id=\"requirementNew\">"
var html_requirement = '<p class="df mb20">' + var html_requirement = '<p class="df mb20">' +
'<span class="column-second lineh-40" id="sequenceNum"><%= @ec_graduation_requirement.position %></span>' + '<span class="column-second lineh-40" id="sequenceNum"><%= @ec_graduation_requirement.position %></span>' +
@ -10,13 +10,13 @@ var html_requirement = '<p class="df mb20">' +
var html_subitems = ""; var html_subitems = "";
<% @ec_graduation_requirement.ec_graduation_subitems.each do |sub| %> <% @ec_graduation_requirement.ec_graduation_subitems.each do |sub| %>
html_subitems += '<p class="df mb10">' + html_subitems += '<p id="edit_subitem_<%= sub.id %>" class="df mb10">' +
'<span class="column-second lineh-40">' + '<span class="column-second lineh-40">' +
'<span class="color-red">* </span><span class="sequence"><%= "#{@ec_graduation_requirement.position}-#{sub.position}" %></span>' + '<span class="color-red">* </span><span class="sequence"><%= "#{@ec_graduation_requirement.position}-#{sub.position}" %></span>' +
'</span>' + '</span>' +
'<input type="text" class="input-flex-40 mr20" name="subitems[]" value="<%= sub.content %>">' + '<input type="text" class="input-flex-40 mr20" name="subitems[]" value="<%= sub.content %>">' +
'<span class="lineh-40">' + '<span class="lineh-40">' +
'<a href="javascript:void(0)" class="fl subDel" data-tip-down="删除"><i class="iconfont icon-shanchu color-grey-c font-15 fl mt2"></i></a>' + '<a href="javascript:void(0)" class="fl" data-tip-down="删除" onclick="delete_confirm_box_2('+"'<%= ec_graduation_subitem_path(sub) %>'"+', \'确定要删除吗\')"><i class="iconfont icon-shanchu color-grey-c font-15 fl mt2"></i></a>' +
'</span>' + '</span>' +
'</p>'; '</p>';
<% end %> <% end %>
@ -26,13 +26,14 @@ var html_submit = "<p class=\"edu-txt-right clearfix pr35\" id=\"AddPanelOperati
"<a href=\"javascript:void(0)\" class=\"defalutCancelbtn fr mr20\" onclick=\"removePanel('require_<%= @ec_graduation_requirement.id %>');\">取消</a>" + "<a href=\"javascript:void(0)\" class=\"defalutCancelbtn fr mr20\" onclick=\"removePanel('require_<%= @ec_graduation_requirement.id %>');\">取消</a>" +
"</p>" "</p>"
var html_end = "</div></form>" var html_end = "</div></li></form>"
var html = html_begin + html_requirement + html_subitems + html_submit + html_end var html = html_begin + html_requirement + html_subitems + html_submit + html_end
console.log("require_<%= @ec_graduation_requirement.id %>"); console.log("require_<%= @ec_graduation_requirement.id %>");
$("body").append('<div style="display: none" id="editFormContent">'+$("#require_<%= @ec_graduation_requirement.id %>").html()+'</div>'); //$("body").append('<div style="display: none" id="editFormContent">'+$("#require_<%= @ec_graduation_requirement.id %>").html()+'</div>');
$("#require_<%= @ec_graduation_requirement.id %>").empty().append(html); $("#require_<%= @ec_graduation_requirement.id %>").hide();
$(html).insertAfter($("#require_<%= @ec_graduation_requirement.id %>"));
$("#requirementNew").find("input[name='requirement']").focus(); $("#requirementNew").find("input[name='requirement']").focus();
}else{ }else{
$("#edit_add_notice").removeClass("none").html("请先保存!"); $("#edit_add_notice").removeClass("none").html("请先保存!");

@ -0,0 +1,9 @@
$("#edit_subitem_<%= @ec_graduation_subitem.id %>").remove();
var num=$("#sequenceNum").html();
var sub=$(".sequence");
for(var i=0;i<parseInt(sub.length);i++){
$(sub).eq(i).html(num+"-"+(i+1));
}
LeaveTitle($("[data-tip-down]"),$(".data-tip-down"));
$("#require_<%= @ec_graduation_requirement.id %>").replaceWith("<%= j(render :partial => "ec_graduation_requirements/requirement_item",
:locals => {:requirement => @ec_graduation_requirement, :template_major => true}) %>");

@ -55,7 +55,7 @@
for(var i=0;i<sub.length;i++){ for(var i=0;i<sub.length;i++){
$(sub).eq(i).html(num+"-"+(i+1)); $(sub).eq(i).html(num+"-"+(i+1));
} }
}) });
//删除子项 //删除子项
$(".subDel").live('click', function () { $(".subDel").live('click', function () {
del_item=$(this); del_item=$(this);
@ -69,7 +69,7 @@
'<a href="javascript:void(0)" class="task-btn task-btn-orange fr" onclick="deleteSubItem(del_item);hideModal();">确定</a></div></div>' '<a href="javascript:void(0)" class="task-btn task-btn-orange fr" onclick="deleteSubItem(del_item);hideModal();">确定</a></div></div>'
pop_box_new(html, 500, 205); pop_box_new(html, 500, 205);
} }
}) });
$("input[name='subitems[]'],input[name='requirement']").live("input",function(){ $("input[name='subitems[]'],input[name='requirement']").live("input",function(){
$(this).removeClass("bor-red"); $(this).removeClass("bor-red");
@ -128,8 +128,8 @@
//取消添加 //取消添加
function removePanel(value){ function removePanel(value){
if(value!=undefined){ if(value!=undefined){
$("#"+value).html($("#editFormContent").html()); $("#"+value).show();
$("#editFormContent").remove(); // $("#editFormContent").remove();
} }
$("#form_data_for_requirements").remove(); $("#form_data_for_requirements").remove();
flagAdd=true; flagAdd=true;

Loading…
Cancel
Save