Changeset 452

Show
Ignore:
Timestamp:
01/22/07 14:25:42 (2 years ago)
Author:
timo
Message:
  • Changed the migration to rename all report tables to use the word "form". Note that the columns in other tables are not yet renamed.
  • Renamed most of the files which used the word "report" to use the word "form". Also searched and replaced "Report"->"Form" and "report"->"form" inside them.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/workorder_report_rename/app/controllers/form_category_controller.rb

    r378 r452  
    22# See license agreement for additional rights 
    33 
    4 # Class: ReportCategoryController 
     4# Class: FormCategoryController 
    55# ==================================== 
    66# 
     
    99# <ApplicationController> 
    1010# 
    11 class ReportCategoryController < ApplicationController 
     11class FormCategoryController < ApplicationController 
    1212  prepend_before_filter :login_required 
    1313 
    1414  def list 
    1515    @help = 'general' 
    16     @title = _('Report categories') 
     16    @title = _('Form categories') 
    1717    @fields = [ [_('Name'), :name], 
    1818                [_('Parent'), :parent_name], 
    19                 [_('Tag'), :report_tag], 
    20                 [_('Report type count'), :report_type_count] 
     19                [_('Tag'), :form_tag], 
     20                [_('Form type count'), :form_type_count] 
    2121              ] 
    22     @items = items_for_page(ReportCategory, :order => 'parent_id, report_tag_id, name') 
     22    @items = items_for_page(FormCategory, :order => 'parent_id, form_tag_id, name') 
    2323    render(:partial => 'shared/list_items', :layout => 'mainlevel') 
    2424  end 
     
    2626  def create 
    2727    @help = 'general' 
    28     @title = _('Create a new report category') 
     28    @title = _('Create a new form category') 
    2929    @fields = [ 
    3030                [_('Name'), :text_field, 'name', { :size => 40, :maxlength => 40 }], 
    31                 [_('Tag'), :select, 'report_tag_id', ReportTag.find(:all, :order => 'name').map {|tag| [tag.full_name, tag.id] }, { :include_blank => true } ], 
     31                [_('Tag'), :select, 'form_tag_id', FormTag.find(:all, :order => 'name').map {|tag| [tag.full_name, tag.id] }, { :include_blank => true } ], 
    3232                [_('Parent'), :select, 'parent_id' ] 
    3333              ] 
    3434    update_possible_parents() 
    35     common_create(ReportCategory, 'name', {:action => 'list'}, {:action => 'list'}) 
     35    common_create(FormCategory, 'name', {:action => 'list'}, {:action => 'list'}) 
    3636  end 
    3737 
    3838  def edit 
    3939    @help = 'general' 
    40     @title = _('Edit report category') 
    41     @report_category = ReportCategory.find params[:id] 
     40    @title = _('Edit form category') 
     41    @form_category = FormCategory.find params[:id] 
    4242    @fields = [ 
    4343                [_('Name'), :text_field, 'name', { :size => 40, :maxlength => 40 }], 
    44                 [_('Tag'), :select, 'report_tag_id', ReportTag.find(:all, :order => 'name').map {|tag| [tag.full_name, tag.id] }, { :include_blank => true } ], 
     44                [_('Tag'), :select, 'form_tag_id', FormTag.find(:all, :order => 'name').map {|tag| [tag.full_name, tag.id] }, { :include_blank => true } ], 
    4545                [_('Parent'), :select, 'parent_id' ] 
    4646              ] 
    47     update_possible_parents(@report_category) 
    48     common_edit(ReportCategory, 'name', {:action => 'list'}, {:action => 'list'}) 
     47    update_possible_parents(@form_category) 
     48    common_edit(FormCategory, 'name', {:action => 'list'}, {:action => 'list'}) 
    4949  end 
    5050 
    5151  def remove 
    52     common_remove(ReportCategory, 'name', :action => 'list')  {|instance| 
    53       unless instance.children.empty? and instance.report_types.empty? 
     52    common_remove(FormCategory, 'name', :action => 'list')  {|instance| 
     53      unless instance.children.empty? and instance.form_types.empty? 
    5454        msg_could_not_remove_because_not_empty(instance) 
    5555      end 
     
    5959  def view_as_tree 
    6060    @help = 'general' 
    61     @title = ('Report category hierarchy') 
    62     @report_categories = ReportCategory.find :all, :readonly => true, :order => 'name' 
     61    @title = ('Form category hierarchy') 
     62    @form_categories = FormCategory.find :all, :readonly => true, :order => 'name' 
    6363  end 
    6464 
     
    6868  # ================================= 
    6969  # 
    70   # Updates possible parents for the report_category. 
     70  # Updates possible parents for the form_category. 
    7171  # 
    72   # If no report_category is given, then the list of 
     72  # If no form_category is given, then the list of 
    7373  # possible parents will contain all existing categories. 
    74   def update_possible_parents(report_category = nil) 
    75     report_categories = ReportCategory.find(:all, :order => 'name') 
     74  def update_possible_parents(form_category = nil) 
     75    form_categories = FormCategory.find(:all, :order => 'name') 
    7676    possible_parents = [[_('No parent'), 0]] 
    7777 
    78     report_categories.each do |potential_parent| 
    79       unless potential_parent.is_child_of?(report_category) or potential_parent == report_category 
     78    form_categories.each do |potential_parent| 
     79      unless potential_parent.is_child_of?(form_category) or potential_parent == form_category 
    8080        possible_parents << [potential_parent.name, potential_parent.id] 
    8181      end 
  • branches/workorder_report_rename/app/controllers/form_controller.rb

    r373 r452  
    44require 'RMagick' 
    55 
    6 # Class: ReportController 
     6# Class: FormController 
    77# =========================== 
    88# 
     
    1111# <ApplicationController> 
    1212# 
    13 class ReportController < ApplicationController 
     13class FormController < ApplicationController 
    1414  prepend_before_filter :login_required 
    1515 
     
    1717 
    1818  def edit_protector 
    19     remove_report_lock 
    20     user_left_page_group(:report_edit) 
     19    remove_form_lock 
     20    user_left_page_group(:form_edit) 
    2121    redirect_to(params[:destination]) 
    2222  end 
     
    2525  # ============== 
    2626  # 
    27   # Lists reports for asset @selected_asset. 
    28   # Optionaly also lists reports for all asset's subassets: 
     27  # Lists forms for asset @selected_asset. 
     28  # Optionaly also lists forms for all asset's subassets: 
    2929  # The choice is saved to session so that it is rememberd when returned to this action. 
    3030  def list 
     
    3232 
    3333    if session[:select_branches] 
    34       @title = _('Reports for selected assets in branch %s', @selected_asset.code_and_name) 
    35     else 
    36       @title = _('Reports for asset %s', @selected_asset.code_and_name) 
     34      @title = _('Forms for selected assets in branch %s', @selected_asset.code_and_name) 
     35    else 
     36      @title = _('Forms for asset %s', @selected_asset.code_and_name) 
    3737    end 
    3838 
     
    4040 
    4141    @items_limit = 10 
    42     generate_report_lists(ReportType.find(:all, :readonly => true), @selected_assets_condition) 
    43     render(:partial => 'report_list', :layout => 'mainlevel') 
    44   end 
    45  
    46   def select_report_type 
    47     unless @selected_asset.authorized_to_create_report
    48       redirect_with_error_message(msg_unauthorized_operation(_('create report'), @selected_asset.code_and_name), :action => 'index') 
    49       return 
    50     end 
    51  
    52     redirect_to(:action => 'create', :id => params[:report_type][:id], :cause_work_order_id => params[:cause_work_order_id]) and return if request.post? 
    53  
    54     @title = _('Select report type to create') 
    55     @help = 'general' 
    56  
    57     report_types = params[:tag_id].nil? ? ReportType.find(:all, :conditions => ['ready = ?', true], :readonly => true) : ReportTag.find(params[:tag_id]).report_types 
    58  
    59     redirect_with_message(_('No report types defined.'), :back) and return if report_types.empty? 
     42    generate_form_lists(FormType.find(:all, :readonly => true), @selected_assets_condition) 
     43    render(:partial => 'form_list', :layout => 'mainlevel') 
     44  end 
     45 
     46  def select_form_type 
     47    unless @selected_asset.authorized_to_create_form
     48      redirect_with_error_message(msg_unauthorized_operation(_('create form'), @selected_asset.code_and_name), :action => 'index') 
     49      return 
     50    end 
     51 
     52    redirect_to(:action => 'create', :id => params[:form_type][:id], :cause_work_order_id => params[:cause_work_order_id]) and return if request.post? 
     53 
     54    @title = _('Select form type to create') 
     55    @help = 'general' 
     56 
     57    form_types = params[:tag_id].nil? ? FormType.find(:all, :conditions => ['ready = ?', true], :readonly => true) : FormTag.find(params[:tag_id]).form_types 
     58 
     59    redirect_with_message(_('No form types defined.'), :back) and return if form_types.empty? 
    6060 
    6161    @hidden_fields = [ ['cause_work_order_id', params[:cause_work_order_id].to_i] ] if params[:cause_work_order_id] 
    62     @fields = [ [_('Report type'), 'report_type', 'id', report_types.collect { |type| [type.name, type.id] }] ] 
     62    @fields = [ [_('Form type'), 'form_type', 'id', form_types.collect { |type| [type.name, type.id] }] ] 
    6363    render(:partial => 'shared/select', :layout => 'mainlevel', 
    6464           :locals => { :cancel_url_options => { :action => 'list' } }) 
     
    6767  def create 
    6868    @help = 'general' 
    69     unless @selected_asset.authorized_to_create_report
    70       redirect_with_error_message(msg_unauthorized_operation(_('create report'), @selected_asset.code_and_name), :action => 'index') 
    71       return 
    72     end 
    73  
    74     @title = _('Create a new report') 
    75     @report_type = ReportType.find(params[:id], :conditions => ['ready = ?', true]) 
    76     @report = @report_type.create_empty_report(@selected_asset) 
    77     @report.creator = session[:user] 
     69    unless @selected_asset.authorized_to_create_form
     70      redirect_with_error_message(msg_unauthorized_operation(_('create form'), @selected_asset.code_and_name), :action => 'index') 
     71      return 
     72    end 
     73 
     74    @title = _('Create a new form') 
     75    @form_type = FormType.find(params[:id], :conditions => ['ready = ?', true]) 
     76    @form = @form_type.create_empty_form(@selected_asset) 
     77    @form.creator = session[:user] 
    7878    @cause_work_order_id = params[:cause_work_order_id] if  params[:cause_work_order_id] 
    79     # Report cookies are used to match image field values in the session 
    80     # to specific report creation / edit form. 
    81     @report_cookie = params[:report_cookie] || Time.now.to_i 
     79    # Form cookies are used to match image field values in the session 
     80    # to specific form creation / edit form. 
     81    @form_cookie = params[:form_cookie] || Time.now.to_i 
    8282    session[:image_fields] ||= { } 
    83     session[:image_fields][@report_cookie] ||= {} 
     83    session[:image_fields][@form_cookie] ||= {} 
    8484 
    8585    if request.post? 
    86       for field in @report_type.report_fields 
     86      for field in @form_type.form_fields 
    8787        next if field.automatic? 
    88         @value = @report.get_field_value_for(field) 
    89         raise "No report field value found for report field: #{field.inspect}" unless @value 
    90         if field.type_code == ReportField::IMAGE 
    91           @value.attributes = session[:image_fields][@report_cookie][field.id.to_s] 
     88        @value = @form.get_field_value_for(field) 
     89        raise "No form field value found for form field: #{field.inspect}" unless @value 
     90        if field.type_code == FormField::IMAGE 
     91          @value.attributes = session[:image_fields][@form_cookie][field.id.to_s] 
    9292        else 
    9393          @value.attributes = params[field.form_field_name.to_sym] if @value 
     
    9797      end 
    9898 
    99       @report.cause_work_order_id = @cause_work_order_id if @cause_work_order_id 
    100  
    101       if @report.validate_fields and @report.valid? 
    102         @report.editable = params[:report][:editable] if params[:report] and @report_type.editable 
    103         @report.ready = true 
    104         session[:image_fields].delete(@report_cookie) if session[:image_fields] 
    105  
    106         if @report.save and @report.update_automatic_field_values 
    107           redirect_to :action => 'view', :id => @report.id 
     99      @form.cause_work_order_id = @cause_work_order_id if @cause_work_order_id 
     100 
     101      if @form.validate_fields and @form.valid? 
     102        @form.editable = params[:form][:editable] if params[:form] and @form_type.editable 
     103        @form.ready = true 
     104        session[:image_fields].delete(@form_cookie) if session[:image_fields] 
     105 
     106        if @form.save and @form.update_automatic_field_values 
     107          redirect_to :action => 'view', :id => @form.id 
    108108          return 
    109109        end 
     
    116116    render(:partial => 'creation_form', 
    117117           :layout => 'mainlevel', 
    118            :locals => { :report => @report, :report_type => @report_type }) 
     118           :locals => { :form => @form, :form_type => @form_type }) 
    119119  end 
    120120 
     
    122122  # ============== 
    123123  # 
    124   # Edits an existing report 
     124  # Edits an existing form 
    125125  def edit 
    126126    @help = 'general' 
    127     @title = _('Edit report') 
    128     @report = Report.find(params[:id], :include => [:data_permissions, :report_field_values]) 
    129  
    130     unless @report.editable and @report.authorized_to_edit? 
    131       redirect_with_error_message(msg_unauthorized_operation(_('edit'), @report.to_s), 
    132                                   :action => 'view', :id => @report.id) 
    133       return 
    134     end 
    135  
    136     @report_type = @report.report_type 
    137     # Report cookies are used to match image field values in the session 
    138     # to specific report creation / edit form. 
    139     @report_cookie = params[:report_cookie] || Time.now.to_i 
     127    @title = _('Edit form') 
     128    @form = Form.find(params[:id], :include => [:data_permissions, :form_field_values]) 
     129 
     130    unless @form.editable and @form.authorized_to_edit? 
     131      redirect_with_error_message(msg_unauthorized_operation(_('edit'), @form.to_s), 
     132                                  :action => 'view', :id => @form.id) 
     133      return 
     134    end 
     135 
     136    @form_type = @form.form_type 
     137    # Form cookies are used to match image field values in the session 
     138    # to specific form creation / edit form. 
     139    @form_cookie = params[:form_cookie] || Time.now.to_i 
    140140    session[:image_fields] ||= { } 
    141     session[:image_fields][@report_cookie] ||= {} 
     141    session[:image_fields][@form_cookie] ||= {} 
    142142 
    143143    if request.post? 
    144       for field in @report_type.report_fields 
     144      for field in @form_type.form_fields 
    145145        next if field.automatic? 
    146         @value = @report.get_field_value_for(field) 
    147  
    148         if field.type_code == ReportField::IMAGE 
    149           @value.attributes = session[:image_fields][@report_cookie][field.id.to_s] 
     146        @value = @form.get_field_value_for(field) 
     147 
     148        if field.type_code == FormField::IMAGE 
     149          @value.attributes = session[:image_fields][@form_cookie][field.id.to_s] 
    150150        else 
    151151          @value.attributes = params[field.form_field_name.to_sym] 
     
    154154      end 
    155155 
    156       if @report.validate_fields 
    157         @report.editable = params[:report][:editable] if params[:report] and @report.report_type.editable 
    158         session[:image_fields].delete(@report_cookie) if session[:image_fields] 
    159         if @report.save_with_values 
     156      if @form.validate_fields 
     157        @form.editable = params[:form][:editable] if params[:form] and @form.form_type.editable 
     158        session[:image_fields].delete(@form_cookie) if session[:image_fields] 
     159        if @form.save_with_values 
    160160          flash[:notice] = msg_changes_saved 
    161           redirect_to :action => 'view', :id => @report.id and return 
     161          redirect_to :action => 'view', :id => @form.id and return 
    162162        else 
    163163          flash[:error] = msg_saving_failed 
     
    167167 
    168168    else 
    169       unless @report.lock_for_current_user(LOCK_DURATION) 
    170         flash[:error] = msg_resource_locked(@report
    171         return redirect_to(:action => 'view', :id => @report.id) 
    172       end 
    173  
    174       unless @report.save 
    175         flash[:error] = msg_locking_failed_for(@report
    176         return redirect_to(:action => 'view', :id => @report.id) 
    177       end 
    178  
    179       user_entered_page_group(:report_edit, @report.id) 
     169      unless @form.lock_for_current_user(LOCK_DURATION) 
     170        flash[:error] = msg_resource_locked(@form
     171        return redirect_to(:action => 'view', :id => @form.id) 
     172      end 
     173 
     174      unless @form.save 
     175        flash[:error] = msg_locking_failed_for(@form
     176        return redirect_to(:action => 'view', :id => @form.id) 
     177      end 
     178 
     179      user_entered_page_group(:form_edit, @form.id) 
    180180 
    181181      # Create instance variables that can be used in the form 
    182       for field in @report_type.report_fields 
     182      for field in @form_type.form_fields 
    183183        next if field.automatic? 
    184         @value = @report.get_field_value_for(field) 
    185  
    186         if field.type_code == ReportField::IMAGE 
     184        @value = @form.get_field_value_for(field) 
     185 
     186        if field.type_code == FormField::IMAGE 
    187187          session[:image_fields] ||= {} 
    188           session[:image_fields][@report_cookie] ||= {} 
    189           session[:image_fields][@report_cookie][field.id.to_s] ||= { :position_x => @value.position_x, :position_y => @value.position_y } 
     188          session[:image_fields][@form_cookie] ||= {} 
     189          session[:image_fields][@form_cookie][field.id.to_s] ||= { :position_x => @value.position_x, :position_y => @value.position_y } 
    190190        else 
    191191          instance_variable_set("@#{field.form_field_name}".to_sym, @value) 
     
    196196    render(:partial => 'creation_form', 
    197197           :layout => 'mainlevel', 
    198            :locals => { :report => @report, :report_type => @report.report_type, :preview => false }) 
     198           :locals => { :form => @form, :form_type => @form.form_type, :preview => false }) 
    199199  end 
    200200 
    201201  def fill_image_field 
    202     @field = ReportField.find params[:id] 
    203     @report_cookie = params[:report_cookie] 
     202    @field = FormField.find params[:id] 
     203    @form_cookie = params[:form_cookie] 
    204204    session[:image_fields] ||= { } 
    205     session[:image_fields][@report_cookie] ||= {} 
    206     if session[:image_fields][@report_cookie][@field.id.to_s] 
    207       @position_x = session[:image_fields][@report_cookie][@field.id.to_s][:position_x] 
    208       @position_y = session[:image_fields][@report_cookie][@field.id.to_s][:position_y] 
     205    session[:image_fields][@form_cookie] ||= {} 
     206    if session[:image_fields][@form_cookie][@field.id.to_s] 
     207      @position_x = session[:image_fields][@form_cookie][@field.id.to_s][:position_x] 
     208      @position_y = session[:image_fields][@form_cookie][@field.id.to_s][:position_y] 
    209209    end 
    210210 
     
    221221    field_id, position = params[:field_id_and_xy_position].split('?') 
    222222    position_x, position_y = position.split(',').map {|c| c.to_i} 
    223     report_cookie = params[:report_cookie] 
    224  
    225     session[:image_fields][report_cookie][field_id] = { :position_x => position_x, :position_y => position_y } 
     223    form_cookie = params[:form_cookie] 
     224 
     225    session[:image_fields][form_cookie][field_id] = { :position_x => position_x, :position_y => position_y } 
    226226 
    227227    redirect_to :back 
     
    231231  # ================ 
    232232  # 
    233   # Displays the report listing 
     233  # Displays the form listing 
    234234  def search 
    235235    @help = 'general' 
     
    242242    end 
    243243 
    244     @report_categories = ReportCategory.find(:all, :readonly => true, :order => 'name') 
     244    @form_categories = FormCategory.find(:all, :readonly => true, :order => 'name') 
    245245 
    246246    find_selected_assets 
    247247 
    248     # Report types were selected 
    249     if params[:report_types] 
    250       @selected_types = ReportType.find(params[:report_types], :conditions => ['ready = ?', true], :readonly => true, :order => 'name') 
    251       session[:keywords] = ReportType.get_keywords(@selected_types.collect { |t| t.id }, @selected_assets_condition).sort 
     248    # Form types were selected 
     249    if params[:form_types] 
     250      @selected_types = FormType.find(params[:form_types], :conditions => ['ready = ?', true], :readonly => true, :order => 'name') 
     251      session[:keywords] = FormType.get_keywords(@selected_types.collect { |t| t.id }, @selected_assets_condition).sort 
    252252    else 
    253253      @selected_types = [] 
    254254    end 
    255255 
    256     @year_span = Report.year_span(@selected_assets_condition) 
     256    @year_span = Form.year_span(@selected_assets_condition) 
    257257    @year = params[:year] ? params[:year].to_i : @year_span.last 
    258258    @year = Time.now.year if @year < 1900 or @year > 2100 
     
    273273    conditions = @selected_assets_condition 
    274274    if conditions.is_a?(Array) 
    275       conditions[0] = "(#{conditions[0]}) AND reports.created_at >= ? AND reports.created_at <= ?" 
     275      conditions[0] = "(#{conditions[0]}) AND forms.created_at >= ? AND forms.created_at <= ?" 
    276276      conditions.push(date_start, date_end) 
    277277    else 
    278       conditions = ["(#{conditions}) AND reports.created_at >= ? AND reports.created_at <= ?", date_start, date_end] 
    279     end 
    280  
    281     @keywords = params[:report][:keywords] if params[:report
     278      conditions = ["(#{conditions}) AND forms.created_at >= ? AND forms.created_at <= ?", date_start, date_end] 
     279    end 
     280 
     281    @keywords = params[:form][:keywords] if params[:form
    282282    @keywords ||= "" 
    283283 
    284     generate_report_lists(@selected_types, conditions, @keywords) 
    285   end 
    286  
    287   # Function: auto_complete_for_report_keywords 
     284    generate_form_lists(@selected_types, conditions, @keywords) 
     285  end 
     286 
     287  # Function: auto_complete_for_form_keywords 
    288288  # =========================================== 
    289289  # 
    290290  # Called by AJAX 
    291   def auto_complete_for_report_keywords 
     291  def auto_complete_for_form_keywords 
    292292    input = @request.raw_post.split.last 
    293     input.gsub!("report%5Bkeywords%5D=", "") 
     293    input.gsub!("form%5Bkeywords%5D=", "") 
    294294    input.gsub!("%C3%A4", "À") 
    295295    input.gsub!("%C3%B6", "ö") 
     
    304304  # ============== 
    305305  # 
    306   # Displays the report in html. 
     306  # Displays the form in html. 
    307307  def view 
    308308    @help = 'general' 
    309309    begin 
    310       @report = Report.find(params[:id], :include => [:data_permissions, :asset]) 
     310      @form = Form.find(params[:id], :include => [:data_permissions, :asset]) 
    311311    rescue ActiveRecord::RecordNotFound 
    312312      if params[:cmms_link] 
    313313        redirect_with_error_message(msg_invalid_link_in_markup("[#{params[:id]}]"), :back) 
    314314      else 
    315         redirect_with_error_message(msg_non_existing_data(Report, params[:id]), :action => 'list') 
     315        redirect_with_error_message(msg_non_existing_data(Form, params[:id]), :action => 'list') 
    316316      end        
    317317      return 
    318318    end 
    319319 
    320     unless @report.authorized_to_read? 
    321       redirect_with_error_message(msg_unauthorized_operation('read', @report.id), :action => 'list') 
    322       return 
    323     end 
    324  
    325     @title = _('Report %s (%s)', @report.to_s, @report.report_type.name) 
    326     info("Displaying report ID:#{params[:id]}") 
    327  
    328     if @report.report_type and @report.report_type.report_html_template 
    329       image_base_url = url_for(:controller => 'report', :action => 'get_report_image', :id => @report.id) + '?filename=' 
    330       html_report = @report.report_type.report_html_template.create_filled_version(@report, image_base_url) 
    331       @report_style = html_report.style 
    332       @report_body = html_report.body 
    333     else 
    334       flash[:error] = msg_system_failure_in(_('Displaying the report')) 
     320    unless @form.authorized_to_read? 
     321      redirect_with_error_message(msg_unauthorized_operation('read', @form.id), :action => 'list') 
     322      return 
     323    end 
     324 
     325    @title = _('Form %s (%s)', @form.to_s, @form.form_type.name) 
     326    info("Displaying form ID:#{params[:id]}") 
     327 
     328    if @form.form_type and @form.form_type.form_html_template 
     329      image_base_url = url_for(:controller => 'form', :action => 'get_form_image', :id => @form.id) + '?filename=' 
     330      html_form = @form.form_type.form_html_template.create_filled_version(@form, image_base_url) 
     331      @form_style = html_form.style 
     332      @form_body = html_form.body 
     333    else 
     334      flash[:error] = msg_system_failure_in(_('Displaying the form')) 
    335335      redirect_to :back 
    336336    end 
     
    340340  # =================== 
    341341  # 
    342   # Displays report template image in the report creation wizard 
     342  # Displays form template image in the form creation wizard 
    343343  def get_image 
    344     image = ReportTemplateImage.find_by_report_type_id_and_name(params[:id], params[:name]) 
     344    image = FormTemplateImage.find_by_form_type_id_and_name(params[:id], params[:name]) 
    345345    if image 
    346346      data = image.data 
    347347      position_x = params[:position_x] 
    348348      position_y = params[:position_y] 
    349       data = ReportFieldImageValue.draw_marker(data, position_x.to_i, position_y.to_i) if position_x and position_y 
     349      data = FormFieldImageValue.draw_marker(data, position_x.to_i, position_y.to_i) if position_x and position_y 
    350350      send_data(data) 
    351351    else 
    352       error('Unable to display report template image') 
     352      error('Unable to display form template image') 
    353353      render :text => '' 
    354354    end 
    355355  end 
    356356 
    357   # Function: get_report_image 
     357  # Function: get_form_image 
    358358  # ========================== 
    359359  # 
    360   # Displays image from a report 
    361   def get_report_image 
    362     report = Report.find_authorized_to_read(params[:id]) 
    363     image = ReportTemplateImage.find_by_report_type_id_and_filename(report.report_type_id, params[:filename]) 
     360  # Displays image from a form 
     361  def get_form_image 
     362    form = Form.find_authorized_to_read(params[:id]) 
     363    image = FormTemplateImage.find_by_form_type_id_and_filename(form.form_type_id, params[:filename]) 
    364364    if image 
    365       image.draw_marker_if_image_field!(report) if image.is_image_field? 
     365      image.draw_marker_if_image_field!(form) if image.is_image_field? 
    366366      send_data(image.data) 
    367367    else 
    368       error('Unable to display report image') 
     368      error('Unable to display form image') 
    369369      render :text => '' 
    370370    end 
     
    374374  # ================== 
    375375  # 
    376   # Offers OpenDocument report for download 
     376  # Offers OpenDocument form for download 
    377377  def download 
    378378    # Find objects 
    379     report = Report.find(params[:id]) 
    380  
    381     unless report.authorized_to_read? 
    382       redirect_with_error_message(msg_unauthorized_operation('read', report.to_s), :action => 'list') 
    383       return 
    384     end 
    385  
    386     if report.report_type and report.report_type.report_template 
     379    form = Form.find(params[:id]) 
     380 
     381    unless form.authorized_to_read? 
     382      redirect_with_error_message(msg_unauthorized_operation('read', form.to_s), :action => 'list') 
     383      return 
     384    end 
     385 
     386    if form.form_type and form.form_type.form_template 
    387387      # Inserting field values 
    388       od_report = report.report_type.report_template.create_filled_version(report
    389  
    390       info "Offering OpenDocument report ID:#{report.id} for download" 
    391       send_data(od_report.data, :filename => "report_#{report.id}.odt", :disposition => 'inline') 
     388      od_form = form.form_type.form_template.create_filled_version(form
     389 
     390      info "Offering OpenDocument form ID:#{form.id} for download" 
     391      send_data(od_form.data, :filename => "form_#{form.id}.odt", :disposition => 'inline') 
    392392    else 
    393393      flash[:error] = msg_system_failure_in(_('Preparing the document for download')) 
     
    397397 
    398398  def remove 
    399     common_remove(Report, 'id', :action => 'list' ) { |instance| 
     399    common_remove(Form, 'id', :action => 'list' ) { |instance| 
    400400      unless instance.authorized_to_remove?