diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb index f6fb0ba98..719578c78 100644 --- a/app/controllers/statistics_controller.rb +++ b/app/controllers/statistics_controller.rb @@ -1,8 +1,12 @@ +# encoding=utf-8 class StatisticsController < ApplicationController # GET /statistics # GET /statistics.json layout 'base_statistic' before_filter :get_date, :only => [:index, :new] + before_filter :require_login + before_filter :find_statistic, :only => [:show, :edit, :update, :destroy] + before_filter :require_manager, :only =>[:edit, :update, :destroy] def index type = (params[:type] == "reorder_popu" ? "size" : "created_at") @@ -35,7 +39,6 @@ class StatisticsController < ApplicationController # GET /statistics/1 # GET /statistics/1.json def show - @statistic = Statistic.find(params[:id]) @attachments = @statistic.attachments respond_to do |format| format.html # show.html.erb @@ -57,7 +60,6 @@ class StatisticsController < ApplicationController # GET /statistics/1/edit def edit @main_categories = MainCategory.all - @statistic = Statistic.find(params[:id]) main_category = MainCategory.find(@statistic.main_category_id) @sub_categories = main_category.sub_categories end @@ -70,7 +72,7 @@ class StatisticsController < ApplicationController @statistic.save_attachments_containers(params[:attachments], User.current, true) respond_to do |format| if @statistic.save - format.html { redirect_to @statistic, notice: 'Statistic was successfully created.' } + format.html { redirect_to @statistic, notice: '创建成功' } format.json { render json: @statistic, status: :created, location: @statistic } else format.html { render action: "new" } @@ -82,7 +84,7 @@ class StatisticsController < ApplicationController # PUT /statistics/1 # PUT /statistics/1.json def update - @statistic = Statistic.find(params[:id]) + respond_to do |format| if @statistic.update_attributes(params[:statistic]) # @statistic.save_attachments_containers(params[:attachments], User.current, true) @@ -94,7 +96,7 @@ class StatisticsController < ApplicationController end # @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) - format.html { redirect_to @statistic, notice: 'Statistic was successfully updated.' } + format.html { redirect_to @statistic, notice: '更新成功' } format.json { head :no_content } else format.html { render action: "edit" } @@ -106,7 +108,6 @@ class StatisticsController < ApplicationController # DELETE /statistics/1 # DELETE /statistics/1.json def destroy - @statistic = Statistic.find(params[:id]) @statistic.destroy respond_to do |format| @@ -133,4 +134,13 @@ class StatisticsController < ApplicationController @sub_categories = params[:main_category_id].present? ? SubCategory.where(:main_category_id => params[:main_category_id]) : SubCategory.all end + def find_statistic + @statistic = Statistic.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + + def require_manager + render_403 unless (User.current.id == @statistic.user_id || User.current.admin?) + end end diff --git a/app/views/statistics/_form.html.erb b/app/views/statistics/_form.html.erb index b907c1931..140e44a7d 100644 --- a/app/views/statistics/_form.html.erb +++ b/app/views/statistics/_form.html.erb @@ -15,12 +15,12 @@ <% end %>
- + <%= f.text_field :name, :class => "wb85" %>

请输入数据名称

- + <%= f.select :main_category_id, (@main_categories.collect { |mc| [mc.name, mc.id] }), {:no_label => true}, :onchange => 'getSubCategory(this.options[this.options.selectedIndex].value)', :class => "w150" %> @@ -31,13 +31,13 @@
- +
<%= f.text_area :description, :class => "wb85 h200 mb20", :style => "display: none;" %>
- +
<%= render :partial => 'attachments/form_statistic', :locals => {:container => @statistic, :isReply => @isReply} %>
diff --git a/app/views/statistics/_statistics_list.html.erb b/app/views/statistics/_statistics_list.html.erb index 5de8a1026..2a34603ef 100644 --- a/app/views/statistics/_statistics_list.html.erb +++ b/app/views/statistics/_statistics_list.html.erb @@ -1,16 +1,18 @@ <% @statistics.each do |statistic| %>
-
-
    -
  • -
      -
    • <%= link_to '编辑', edit_statistic_path(statistic) %>
    • -
    • <%= link_to '删除', statistic, method: :delete, data: { confirm: 'Are you sure?' } %>
    • + <% if User.current.id == statistic.user_id || User.current.admin? %> +
      +
        +
      • +
          +
        • <%= link_to '编辑', edit_statistic_path(statistic) %>
        • +
        • <%= link_to '删除', statistic, method: :delete, data: { confirm: 'Are you sure?' } %>
        • +
        +
      - -
    -
+
+ <% end %>
<%= link_to "#{statistic.name}", statistic %>

<%= statistic.description.try(:html_safe) %>

@@ -19,9 +21,10 @@
<%= statistic.creator.show_name %> - <%= format_time statistic.created_at %> <%= statistic.main_category.name %> <%= statistic.sub_category.try(:name) %> + <%= format_time statistic.created_at %> + <%= statistic.size %> KB
diff --git a/app/views/statistics/show.html.erb b/app/views/statistics/show.html.erb index 125e9688e..f92d3e92f 100644 --- a/app/views/statistics/show.html.erb +++ b/app/views/statistics/show.html.erb @@ -1,14 +1,17 @@ <%= stylesheet_link_tag '/editormd/css/editormd','/editormd/css/editormd.min.css' %> <%= javascript_include_tag '/editormd/lib/marked.min.js','/editormd/lib/prettify.min.js','/editormd/lib/raphael.min.js','/editormd/lib/underscore.min.js','/editormd/lib/sequence-diagram.min.js', '/editormd/lib/flowchart.min.js','/editormd/lib/jquery.flowchart.min.js','/editormd/editormd.js' %> -
-
+
+
<%= @statistic.name %> + <% if User.current.id == @statistic.user_id || User.current.admin? %> + <%= link_to '编辑', edit_statistic_path(@statistic) ,:class => "submit_btn fr mr45" %> + <% end %>
- +
@@ -17,14 +20,6 @@ <%= format_time @statistic.created_at %>
-
- - <%= @statistic.user_id %> -
-
- - <%= @statistic.status %> -
<%# 附件局部刷新 %> <% if @attachments.present? %>
@@ -36,7 +31,6 @@ <% end %>
- <%= link_to '编辑', edit_statistic_path(@statistic) ,:class => "submit_btn" %> <%= link_to '返回', statistics_path ,:class=>"grey_btn" %>
diff --git a/public/stylesheets/css/public.css b/public/stylesheets/css/public.css index e14ce29a5..c588072dd 100644 --- a/public/stylesheets/css/public.css +++ b/public/stylesheets/css/public.css @@ -952,9 +952,9 @@ a.syllabusbox_a_blue{ color:#3b94d6;} .mainCon{position: relative;min-height: 100%;height: auto !important;height: 100%;} .pos_footer{position: absolute;bottom: 0;width: 100%;clear: both;z-index: 99999; } #create_new_statis form div.field{clear: both;zoom: 1;} -#create_new_statis form label{float: left;width: 10%;text-align: center;font-size: 14px;height: 35px;line-height: 35px;} -#create_new_statis form label span{color: red} -#create_new_statis .line_field input,#create_new_statis .line_field select{float: left;height: 35px;line-height: 35px;border-radius: 4px;} +#create_new_statis form label.field_lab{float: left;width: 10%;text-align: center;font-size: 14px;height: 35px;line-height: 35px;} +#create_new_statis form label.field_lab span{color: red} +#create_new_statis .line_field input[type='text'],#create_new_statis .line_field select{float: left;height: 35px;line-height: 35px;border-radius: 4px;} .input_tag{height: 30px!important;border-radius: 3px!important;width: 160px} .tag_modal span{display: inline-block;border-radius: 3px;border:1px solid #dddddd;background: #FFFFFF;padding: 3px 7px;margin-right: 5px ;margin-top: 3px} .tag_del{cursor: pointer} @@ -985,7 +985,7 @@ a.syllabusbox_a_blue{ color:#3b94d6;} .list_tag{border: 1px solid #F8DF8C;background: #FFFCE6;color: #3BA6DD;margin-right:10px;padding: 2px 4px;border-radius: 3px} .attachment_file{color: #FF8D00!important;} .data_info span{font-size: 14px;width: 17%;text-align: left;display: inline-block} -.data_info span:nth-child(2){width:26% } +.data_info span:nth-child(2){width:15% } span.down{display: block;position: absolute;top: 13px;right: 4px;width: 12px;height: 10px;background: url(/images/user/icons_user_leftnav.png) -3px -347px no-repeat;} .submit_btn{padding-bottom: 5px;