From 44af3aadf40c4a490977020053f7c065916fa63c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 22 Aug 2019 11:15:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E7=A8=8B=E8=AE=A4=E8=AF=81=EF=BC=9A?= =?UTF-8?q?=E6=AF=95=E4=B8=9A=E8=A6=81=E6=B1=82=E5=92=8C=E6=8C=87=E6=A0=87?= =?UTF-8?q?=E7=82=B9=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BC=9A=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=90=8E=E7=BB=AD=E5=85=B6=E5=AE=83=E5=87=A0=E4=B8=AA=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9F=A9=E9=98=B5=E7=9A=84=E9=A1=B5=E9=9D=A2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=A2=E5=A4=B1=EF=BC=8C=E9=9C=80=E8=A6=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ec_graduation_requirements_controller.rb | 9 ++++-- .../ec_graduation_subitems_controller.rb | 4 +++ .../_requirement_item.html.erb | 25 ++++++++++++++++ .../_requirement_lists.html.erb | 30 ++----------------- .../ec_graduation_requirements/edit.js.erb | 13 ++++---- .../ec_graduation_subitems/destroy.js.erb | 9 ++++++ .../ec_years/graduation_requirement.html.erb | 8 ++--- 7 files changed, 59 insertions(+), 39 deletions(-) create mode 100644 app/views/ec_graduation_requirements/_requirement_item.html.erb create mode 100644 app/views/ec_graduation_subitems/destroy.js.erb diff --git a/app/controllers/ec_graduation_requirements_controller.rb b/app/controllers/ec_graduation_requirements_controller.rb index 091588cd..79c678de 100644 --- a/app/controllers/ec_graduation_requirements_controller.rb +++ b/app/controllers/ec_graduation_requirements_controller.rb @@ -50,9 +50,14 @@ class EcGraduationRequirementsController < ApplicationController @year = requirement.ec_year @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.ec_graduation_subitems.destroy_all + # requirement.ec_graduation_subitems.destroy_all params[:subitems].try(:each_with_index) do |sub, index| - EcGraduationSubitem.create(:content => sub, :position => index+1, :ec_graduation_requirement_id => requirement.id) + 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) + end end @ec_graduation_requirements = requirement.ec_year.ec_graduation_requirements diff --git a/app/controllers/ec_graduation_subitems_controller.rb b/app/controllers/ec_graduation_subitems_controller.rb index b281e3f3..1248f450 100644 --- a/app/controllers/ec_graduation_subitems_controller.rb +++ b/app/controllers/ec_graduation_subitems_controller.rb @@ -82,9 +82,13 @@ class EcGraduationSubitemsController < ApplicationController # DELETE /ec_graduation_subitems/1.json def destroy @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 respond_to do |format| + format.js format.html { redirect_to ec_graduation_subitems_url } format.json { head :no_content } end diff --git a/app/views/ec_graduation_requirements/_requirement_item.html.erb b/app/views/ec_graduation_requirements/_requirement_item.html.erb new file mode 100644 index 00000000..95aed9a9 --- /dev/null +++ b/app/views/ec_graduation_requirements/_requirement_item.html.erb @@ -0,0 +1,25 @@ +
  • +

    + <%= requirement.position %> + <%= requirement.content %> + + <% if template_major %> + <% if requirement.position == @ec_graduation_requirements.count %> + + <% end %> + + + <% end %> + +

    + <% if requirement.ec_graduation_subitems.present? %> +
    + <% requirement.ec_graduation_subitems.each do |sub| %> +

    + <%= "#{requirement.position}-#{sub.position}" %> + <%= sub.content %> +

    + <% end %> +
    + <% end %> +
  • diff --git a/app/views/ec_graduation_requirements/_requirement_lists.html.erb b/app/views/ec_graduation_requirements/_requirement_lists.html.erb index 623e910a..fe88fc46 100644 --- a/app/views/ec_graduation_requirements/_requirement_lists.html.erb +++ b/app/views/ec_graduation_requirements/_requirement_lists.html.erb @@ -1,31 +1,7 @@ <% if @ec_graduation_requirements.present? && @ec_graduation_requirements.count>0 %> -<% @ec_graduation_requirements.each_with_index do |requirement, index| %> -
  • -

    - <%= requirement.position %> - <%= requirement.content %> - - <% if @template_major %> - <% if index+1 == @ec_graduation_requirements.count %> - - <% end %> - - - <% end %> - -

    - <% if requirement.ec_graduation_subitems.present? %> -
    - <% requirement.ec_graduation_subitems.each_with_index do |sub, index| %> -

    - <%= "#{requirement.position}-#{sub.position}" %> - <%= sub.content %> -

    - <% end %> -
    - <% end %> -
  • -<% end %> + <% @ec_graduation_requirements.each_with_index do |requirement| %> + <%= render :partial => "ec_graduation_requirements/requirement_item", :locals => {:requirement => requirement, :template_major => @template_major} %> + <% end %> <% elsif @template_major %>
    diff --git a/app/views/ec_graduation_requirements/edit.js.erb b/app/views/ec_graduation_requirements/edit.js.erb index fab4ee00..b453c724 100644 --- a/app/views/ec_graduation_requirements/edit.js.erb +++ b/app/views/ec_graduation_requirements/edit.js.erb @@ -1,5 +1,5 @@ if($("#form_data_for_requirements").length==0){ -var html_begin = "
    " +var html_begin = "
  • " var html_requirement = '

    ' + '<%= @ec_graduation_requirement.position %>' + @@ -10,13 +10,13 @@ var html_requirement = '

    ' + var html_subitems = ""; <% @ec_graduation_requirement.ec_graduation_subitems.each do |sub| %> - html_subitems += '

    ' + + html_subitems += '

    ' + '' + '* <%= "#{@ec_graduation_requirement.position}-#{sub.position}" %>' + '' + '' + '' + - '' + + ''"+', \'确定要删除吗\')">' + '' + '

    '; <% end %> @@ -26,13 +26,14 @@ var html_submit = "

    ');\">取消" + "

    " -var html_end = "
  • " +var html_end = "
    " var html = html_begin + html_requirement + html_subitems + html_submit + html_end console.log("require_<%= @ec_graduation_requirement.id %>"); -$("body").append(''); -$("#require_<%= @ec_graduation_requirement.id %>").empty().append(html); +//$("body").append(''); +$("#require_<%= @ec_graduation_requirement.id %>").hide(); +$(html).insertAfter($("#require_<%= @ec_graduation_requirement.id %>")); $("#requirementNew").find("input[name='requirement']").focus(); }else{ $("#edit_add_notice").removeClass("none").html("请先保存!"); diff --git a/app/views/ec_graduation_subitems/destroy.js.erb b/app/views/ec_graduation_subitems/destroy.js.erb new file mode 100644 index 00000000..b5662344 --- /dev/null +++ b/app/views/ec_graduation_subitems/destroy.js.erb @@ -0,0 +1,9 @@ +$("#edit_subitem_<%= @ec_graduation_subitem.id %>").remove(); +var num=$("#sequenceNum").html(); +var sub=$(".sequence"); +for(var i=0;i").replaceWith("<%= j(render :partial => "ec_graduation_requirements/requirement_item", +:locals => {:requirement => @ec_graduation_requirement, :template_major => true}) %>"); \ No newline at end of file diff --git a/app/views/ec_years/graduation_requirement.html.erb b/app/views/ec_years/graduation_requirement.html.erb index 76833188..cbc23732 100644 --- a/app/views/ec_years/graduation_requirement.html.erb +++ b/app/views/ec_years/graduation_requirement.html.erb @@ -55,7 +55,7 @@ for(var i=0;i确定
    ' pop_box_new(html, 500, 205); } - }) + }); $("input[name='subitems[]'],input[name='requirement']").live("input",function(){ $(this).removeClass("bor-red"); @@ -128,8 +128,8 @@ //取消添加 function removePanel(value){ if(value!=undefined){ - $("#"+value).html($("#editFormContent").html()); - $("#editFormContent").remove(); + $("#"+value).show(); + // $("#editFormContent").remove(); } $("#form_data_for_requirements").remove(); flagAdd=true;