Changeset 747
- Timestamp:
- 02/18/08 12:01:07 (11 months ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (1 diff)
- trunk/app/controllers/customer_interface_controller.rb (modified) (4 diffs)
- trunk/app/controllers/form_controller.rb (modified) (5 diffs)
- trunk/app/controllers/task_controller.rb (modified) (1 diff)
- trunk/app/helpers/application_helper.rb (modified) (1 diff)
- trunk/app/views/customer_interface/_form_field_values.rhtml (deleted)
- trunk/app/views/customer_interface/view_form.rhtml (modified) (1 diff)
- trunk/app/views/form/_form_field_values.rhtml (added)
- trunk/app/views/form/print_view.rhtml (added)
- trunk/app/views/form/view.rhtml (modified) (1 diff)
- trunk/app/views/form/view_form_image_field.rhtml (moved) (moved from trunk/app/views/customer_interface/view_form_image_field.rhtml)
- trunk/app/views/layouts/print.rhtml (added)
- trunk/app/views/task/print_view.rhtml (modified) (6 diffs)
- trunk/doc/manual/latex/tex/application_section.tex (modified) (1 diff)
- trunk/doc/manual/latex/tex/customer_interface.tex (modified) (1 diff)
- trunk/public/javascripts/print.js (added)
- trunk/public/stylesheets/print.css (added)
- trunk/public/stylesheets/print_task.css (deleted)
- trunk/test/functional/customer_interface_controller_test.rb (modified) (5 diffs)
- trunk/test/functional/form_controller_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r721 r747 701 701 return true 702 702 end 703 704 # Method: put_form_field_values_to_field_groups 705 # ============================================= 706 # Places the form field values of a form to their field groups. 707 # Used to show the form in a similar order as in form filling view. 708 # 709 # Parameters: 710 # ----------- 711 # form - A <Form> whose field values are grouped. 712 # include_automatic_field - If is true, automatic field values are included. 713 # check_show_to_customers - If is true, the show_to_customers flag of 714 # field values is checked and ones with the flag 715 # set to false are completely ignored. 716 # 717 def put_form_field_values_to_field_groups(form, include_automatic_field = true, check_show_to_customers = false) 718 @field_values_in_groups = [] 719 @groupless_field_values = [] 720 form.form_field_values.each do |field_value| 721 # Check that customer has permission to view the field value. 722 next if check_show_to_customers and not field_value.form_field.show_to_customers 723 next if not include_automatic_field and field_value.form_field.type_code == FormField::AUTOMATIC 724 725 group = field_value.form_field.form_field_group 726 if group 727 elem = nil 728 @field_values_in_groups.each { |g| elem = g if g[:group].id == group.id} 729 if elem 730 elem[:field_values].push(field_value) 731 else 732 @field_values_in_groups.push({ :group => group, :field_values => [field_value] }) 733 end 734 else 735 @groupless_field_values.push(field_value) 736 end 737 end 738 # Sort field groups and field values 739 @field_values_in_groups.sort! { |a,b| a[:group].place <=> b[:group].place } 740 @field_values_in_groups.each { |g| g[:field_values].sort! { |a,b| a.form_field.place <=> b.form_field.place } } 741 @groupless_field_values.sort! { |a,b| a.form_field.place <=> b.form_field.place } 742 end 703 743 end trunk/app/controllers/customer_interface_controller.rb
r739 r747 24 24 prepend_before_filter :login_required 25 25 skip_before_filter :set_selected_asset, :prepare_tree_view, :check_new_service_requests 26 append_before_filter :find_assets_for_user 26 before_filter :find_assets_for_user 27 before_filter :get_form_for_viewing, :only => [:view_form, :print_form] 27 28 28 29 # Method: index … … 280 281 # 281 282 def view_form 282 form = Form.find(params[:id])283 284 unless form.authorized_to_read?285 info('Unauthorized to view form ID=%d' % form.id)286 redirect_to(:action => 'index')287 return288 end289 290 @title = _('Filled-out form %s (%s)', form.to_s, form.form_type.name)291 283 @show_login_name_link = session[:user].instance_of?(Customer) 292 293 # Place the field values to their field groups.294 @field_values_in_groups = []295 @groupless_field_values = []296 form.form_field_values.each do |field_value|297 # Check that customer has permission to view the field value.298 next unless field_value.form_field.show_to_customers299 300 group = field_value.form_field.form_field_group301 if group302 elem = nil303 @field_values_in_groups.each { |g| elem = g if g[:group].id == group.id}304 if elem305 elem[:field_values].push(field_value)306 else307 @field_values_in_groups.push({ :group => group, :field_values => [field_value] })308 end309 else310 @groupless_field_values.push(field_value)311 end312 end313 # Sort field groups and field values314 @field_values_in_groups.sort! { |a,b| a[:group].place <=> b[:group].place }315 @field_values_in_groups.each { |g| g[:field_values].sort! { |a,b| a.form_field.place <=> b.form_field.place } }316 @groupless_field_values.sort! { |a,b| a.form_field.place <=> b.form_field.place }317 284 end 318 285 … … 324 291 def view_form_image_field 325 292 @value = FormFieldImageValue.find(params[:id]) 326 render :layout => false 293 render :layout => false, :template => 'form/view_form_image_field' 294 end 295 296 # Method: print_form 297 # ================== 298 # Simple view for viewing and printing forms. 299 # 300 require_key_for :print_form, 'customer_interface/view_form' 301 def print_form 302 render :layout => 'print', :template => 'form/print_view' 327 303 end 328 304 … … 343 319 @assets.sort! { |a, b| a.full_code <=> b.full_code } 344 320 end 321 322 # Method: get_form_for_viewing 323 # ============================ 324 # Find a form for viewing or printing. 325 # 326 def get_form_for_viewing 327 begin 328 @form = Form.find(params[:id]) 329 330 unless @form.authorized_to_read? 331 info('Unauthorized to view @form ID:%d' % @form.id) 332 redirect_to(:action => 'index') 333 else 334 info('Displaying form ID:%d' % @form.id) 335 @title = _('Filled-out form %s (%s)', @form.to_s, @form.form_type.name) 336 put_form_field_values_to_field_groups(@form, false, true) 337 end 338 rescue ActiveRecord::RecordNotFound 339 redirect_with_error_message(msg_non_existing_data(Form, params[:id]), :action => 'index') 340 end 341 end 345 342 end trunk/app/controllers/form_controller.rb
r739 r747 13 13 class FormController < ApplicationController 14 14 prepend_before_filter :login_required 15 before_filter :get_form_for_viewing, :only => [:view, :print_view] 16 skip_before_filter :set_selected_asset, :prepare_tree_view, :check_new_service_requests, :only => ['get_image_field', 'view_form_image_field'] 15 17 16 18 LOCK_DURATION = 1.hour … … 337 339 # Displays the form in html. 338 340 def view 339 begin340 @form = Form.find(params[:id], :include => [:data_permissions, :asset])341 rescue ActiveRecord::RecordNotFound342 if params[:cmms_link]343 redirect_with_error_message(msg_invalid_link_in_markup("[#{params[:id]}]"), :back)344 else345 redirect_with_error_message(msg_non_existing_data(Form, params[:id]), :action => 'list')346 end347 return348 end349 350 unless @form.authorized_to_read?351 redirect_with_error_message(msg_unauthorized_operation('read', @form.id), :action => 'list')352 return353 end354 355 @title = _('Filled-out form %s (%s)', @form.to_s, @form.form_type.name)356 info("Displaying form ID:#{params[:id]}")357 358 341 @associated_tasks = (@form.opened_tasks + @form.closed_tasks).uniq 359 342 @task_types = TaskType.find(:all, :readonly => true) … … 412 395 # Can be requested by both User and Customer. 413 396 # 414 require_key_for :get_image_field, 'customer_interface/view_form'397 require_key_for :get_image_field, ['customer_interface/view_form', 'form/view'] 415 398 def get_image_field 416 399 field = FormFieldImageValue.find(params[:id]) … … 456 439 end 457 440 } 441 end 442 443 # Method: print_view 444 # ================== 445 # Simple view for viewing and printing forms. 446 # 447 require_key_for :print_view, 'form/view' 448 def print_view 449 put_form_field_values_to_field_groups(@form, true) 450 render :layout => 'print' 451 end 452 453 # Method: view_form_image_field 454 # ============================= 455 # Displays a form image field. 456 # 457 require_key_for :view_form_image_field, 'form/view' 458 def view_form_image_field 459 @value = FormFieldImageValue.find(params[:id]) 460 render :layout => false 458 461 end 459 462 … … 535 538 end 536 539 end 540 541 # Method: get_form_for_viewing 542 # ============================ 543 # Find a form for viewing (or printing). 544 # 545 def get_form_for_viewing 546 begin 547 @form = Form.find(params[:id], :include => [:data_permissions, :asset]) 548 549 unless @form.authorized_to_read? 550 redirect_with_error_message(msg_unauthorized_operation('read', @form.id), :action => 'list') 551 else 552 @title = _('Filled-out form %s (%s)', @form.to_s, @form.form_type.name) 553 info('Displaying form ID:%d' % @form.id) 554 end 555 rescue ActiveRecord::RecordNotFound 556 if params[:cmms_link] 557 redirect_with_error_message(msg_invalid_link_in_markup("[#{params[:id]}]"), :back) 558 else 559 redirect_with_error_message(msg_non_existing_data(Form, params[:id]), :action => 'list') 560 end 561 end 562 end 537 563 end trunk/app/controllers/task_controller.rb
r744 r747 420 420 define_priority_options 421 421 @assigned_workers = @task.workers 422 render :layout => false422 render :layout => 'print' 423 423 end 424 424 trunk/app/helpers/application_helper.rb
r743 r747 828 828 end 829 829 end 830 831 # Method: form_field_value 832 # ========================= 833 # Format an form field value for views. 834 # 835 # Returns nil for image field values. 836 # 837 def form_field_value(field_value) 838 case field_value.class.to_s 839 when 'FormFieldIntValue', 'FormFieldFloatValue' 840 h(field_value.value.to_s) 841 when 'FormFieldStringValue', 'FormFieldLongStringValue', 'FormFieldEnumValue' 842 h(field_value.value) 843 when 'FormFieldBoolValue' 844 field_value.value ? _('Yes') : _('No') 845 when 'FormFieldDateValue', 'FormFieldDatetimeValue' 846 Localization.format_date(field_value.value) 847 when 'FormFieldTimeValue' 848 Localization.format_time(field_value.value) 849 when 'FormFieldImageValue' 850 nil 851 else 852 raise "Unknown form field value type: #{field_value.class}" 853 end 854 end 830 855 end trunk/app/views/customer_interface/view_form.rhtml
r739 r747 2 2 <% for values in @field_values_in_groups -%> 3 3 <h3><%= h(values[:group].name) %></h3> 4 <%= render(:partial => 'form _field_values', :locals => {:form_field_values => values[:field_values]}) %>4 <%= render(:partial => 'form/form_field_values', :locals => {:form_field_values => values[:field_values]}) %> 5 5 <% end -%> 6 6 </br> 7 7 <% unless @groupless_field_values.empty? -%> 8 8 <div class="vspace"></div> 9 <%= render(:partial => 'form _field_values', :locals => {:form_field_values => @groupless_field_values}) %>9 <%= render(:partial => 'form/form_field_values', :locals => {:form_field_values => @groupless_field_values}) %> 10 10 <% end -%> 11 11 </div> 12 <table class="actions"> 13 <tr> 14 <td><%= link_to(image_tag('16x16/print.gif') + _('Printer-friendly'), 15 {:action => 'print_form', :id => @form.id}, :popup => true) %></td> 16 </tr> 17 </table> 12 18 </br> 13 19 <%= link_to(_('Back'), :controller => 'customer_interface', :action => 'index') %> trunk/app/views/form/view.rhtml
r721 r747 43 43 <td><%= link_to(image_tag('16x16/download.png') + _('Download'), 44 44 {:action => 'download', :id => @form.id}) %></td> 45 <td><%= link_to(image_tag('16x16/print.gif') + _('Printer-friendly'), 46 {:action => 'print_view', :id => @form.id}, :popup => true) %></td> 45 47 </tr> 46 48 </table> trunk/app/views/task/print_view.rhtml
r744 r747 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">2 1 <% 3 2 link_url = { … … 7 6 } 8 7 -%> 9 <html xmlns="http://www.w3.org/1999/xhtml">10 <head>11 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />12 <title><%= h(@title) + ' - NorfelloCMMS' %></title>13 <%= stylesheet_link_tag 'print_task' %>14 15 <%= javascript_include_tag 'prototype' %>16 <script type="text/javascript">17 function show(sv, obj) {18 if(sv)19 $(obj).style.visibility = 'visible';20 else21 $(obj).style.visibility = 'hidden';22 }23 24 function print_task() {25 var e = $('printlink');26 show(false, e);27 window.print();28 // XXX: It would be nice to show the element again after printing.29 //show(true, e);30 }31 32 function add_print_link(obj) {33 $(obj).innerHTML = '<hr/><a href="javascript:print_task()"><%= image_tag("16x16/print.gif") + " " + _("Print") %></a>';34 }35 </script>36 </head>37 38 <body onload="add_print_link('printlink')">39 8 <div id="print_task"> 40 <h1><%= @title %></h1>41 42 9 <table> 43 10 <tr> … … 86 53 87 54 <h2><%= _('Asset information') %></h2> 88 <%= link_to(@hide_asset_information ? _('Show') : _('Hide'), link_url.merge(:hide_asset => @hide_asset_information ? 0 : 1) ) %>55 <%= link_to(@hide_asset_information ? _('Show') : _('Hide'), link_url.merge(:hide_asset => @hide_asset_information ? 0 : 1), {:class=>'hide_show'}) %> 89 56 <% unless @hide_asset_information -%> 90 <table> 57 <table id="asset_information"> 58 <%# The div is added inside the <th> because the white-space: nowrap doesn't work on the th tag on IE7. %> 91 59 <tr> 92 <th class="first">< %= _('Code') %></th>60 <th class="first"><div><%= _('Code') %></div></th> 93 61 <td><%= h(@task.asset.full_code) %></td> 94 62 </tr> 95 63 <tr> 96 <th class="first">< %= _('Name') %></th>64 <th class="first"><div><%= _('Name') %></div></th> 97 65 <td><%= h(@task.asset.name) %></td> 98 66 </tr> 99 67 <% if @task.asset.customer -%> 100 68 <tr> 101 <th class="first">< %= _('Customer') %></th>69 <th class="first"><div><%= _('Customer') %></div></th> 102 70 <td><%= h(@task.asset.customer.name) %></td> 103 71 </tr> … … 105 73 <% if @task.asset.asset_type -%> 106 74 <tr> 107 <th class="first">< %= _('Asset type') %></th>75 <th class="first"><div><%= _('Asset type') %></div></th> 108 76 <td><%= h(@task.asset.asset_type.name) %></td> 109 77 </tr> 110 78 <% for field_value in @task.asset.asset_field_values -%> 111 79 <tr> 112 <th class="first">< %= h(field_value.asset_field.name) %></th>80 <th class="first"><div><%= h(field_value.asset_field.name) %></div></th> 113 81 <td><%= asset_field_value(field_value) %></td> 114 82 </tr> … … 126 94 <% unless @task.task_events.empty? -%> 127 95 <h2><%= _('Change history') %></h2> 128 <%= link_to(@hide_history ? _('Show') : _('Hide'), link_url.merge(:hide_history => @hide_history ? 0 : 1) ) %>96 <%= link_to(@hide_history ? _('Show') : _('Hide'), link_url.merge(:hide_history => @hide_history ? 0 : 1), {:class=>'hide_show'}) %> 129 97 <% unless @hide_history -%> 130 98 <div id="print_task_history"> … … 137 105 <% end -%> 138 106 <% end -%> 139 <div id="printlink"></div>140 107 </div> 141 </body>142 </html>trunk/doc/manual/latex/tex/application_section.tex
r745 r747 318 318 \item[Permissions:] Shows you the data permissions for the form, which define what user groups are authorized to do to the form. Form permissions include viewing and editing permissions. You can also edit the data permissions if you have the editing permission to the form. 319 319 \item[Download:] Offers the form to be downloaded as an Open Document file. 320 \item[Printer friendly] Shows the filled form in a simplyfied view that is suited for printing with your web-browser. 320 321 \end{description} 321 322 \paragraph{Search} trunk/doc/manual/latex/tex/customer_interface.tex
r739 r747 23 23 Customers can view filled forms by selecting them from the timeline. 24 24 25 At the bottom of the form viewing page, right above the 'Back' link, there is a link 'Printer friendly' that opens a page that is more suitable for printing with your web-browser. 26 25 27 Each field of each form type can be configured --- in the Form type menu of the Configuration section \ref{subsec:form_types} --- to be viewable for customers. 26 28 \subsubsection{Submit a service request} trunk/test/functional/customer_interface_controller_test.rb
r739 r747 27 27 @user_group_root.form_permission_profiles(:other => true, :group_read => true, :group_edit => true) 28 28 @user_group_root.attachment_permission_profiles(:other => true, :group_read => true, :group_edit => true) 29 end 30 31 # Method: setup_test_form 32 # ======================= 33 # Setup a test form type and create a form for it. 34 # 35 def setup_test_form 36 # Form type 37 @form_type = FormType.create!(:name => 'Test type', :editable => false, :ready => true) 38 # Form field groups 39 @ffg1 = @form_type.form_field_groups.create(:name => 'First', :place => 1) 40 @ffg2 = @form_type.form_field_groups.create(:name => 'Second', :place => 2) 41 # Form fields visible to customers 42 @ff1 = @form_type.form_fields.create(:name => 'Integer', :user_field_name => 'int', :type_code => FormField::INTEGER, :form_field_group => @ffg2, :show_to_customers => true, :show_to_customers => true, :place => 1) 43 @ff2 = @form_type.form_fields.create(:name => 'String', :user_field_name => 'string', :type_code => FormField::STRING, :form_field_group => @ffg2, :show_to_customers => true, :place => 2) 44 @ff3 = @form_type.form_fields.create(:name => 'Boolean', :user_field_name => 'bool', :type_code => FormField::BOOLEAN, :form_field_group => @ffg1, :show_to_customers => true, :place => 2) 45 @ff4 = @form_type.form_fields.create(:name => 'Float', :user_field_name => 'float', :type_code => FormField::FLOAT, :form_field_group => @ffg1, :show_to_customers => true, :place => 1) 46 @ff5 = @form_type.form_fields.create(:name => 'Long string', :user_field_name => 'lstring', :type_code => FormField::LONG_STRING, :show_to_customers => true, :place => 4) 47 @ff6 = @form_type.form_fields.create(:name => 'Date', :user_field_name => 'date', :type_code => FormField::DATE, :show_to_customers => true, :place => 3) 48 @ff7 = @form_type.form_fields.create(:name => 'Time', :user_field_name => 'time', :type_code => FormField::TIME, :show_to_customers => true, :place => 2) 49 @ff8 = @form_type.form_fields.create(:name => 'Datetime', :user_field_name => 'datetime', :type_code => FormField::DATETIME, :show_to_customers => true, :place => 1) 50 @ff9 = @form_type.form_fields.create(:name => 'Automatic 1', :user_field_name => 'cmms_form_id', :type_code => FormField::AUTOMATIC, :show_to_customers => true) 51 # Form fields hidden from customers 52 @form_type.form_fields.create(:name => 'Integer 2', :user_field_name => 'int2', :type_code => FormField::INTEGER) 53 @form_type.form_fields.create(:name => 'String 2', :user_field_name => 'string2', :type_code => FormField::STRING) 54 @form_type.form_fields.create(:name => 'Boolean 2', :user_field_name => 'bool2', :type_code => FormField::BOOLEAN) 55 @form_type.form_fields.create(:name => 'Float 2', :user_field_name => 'float2', :type_code => FormField::FLOAT) 56 @form_type.form_fields.create(:name => 'Long string 2', :user_field_name => 'lstring2', :type_code => FormField::LONG_STRING) 57 @form_type.form_fields.create(:name => 'Date 2', :user_field_name => 'date2', :type_code => FormField::DATE, :form_field_group => @ffg1) 58 @form_type.form_fields.create(:name => 'Time 2', :user_field_name => 'time2', :type_code => FormField::TIME, :form_field_group => @ffg2) 59 @form_type.form_fields.create(:name => 'Datetime 2', :user_field_name => 'datetime2', :type_code => FormField::DATETIME) 60 @form_type.form_fields.create(:name => 'Automatic 2', :user_field_name => 'cmms_form_type_name', :type_code => FormField::AUTOMATIC) 61 @form_type.save! 62 63 # Test form 64 @root.customer = @customer 65 @root.save! 66 @form = @form_type.create_empty_form(@root) 67 @form.ready = true 68 @form.save! 69 @form.update_automatic_field_values 29 70 end 30 71 … … 503 544 end 504 545 546 # Method: test_view_form_unauthorized 547 # =================================== 548 # Checks that form viewing is denied from unauthorized customers. 549 # 550 def test_view_form_unauthorized 551 setup_test_form 552 553 unauthorized_customer = create_customer('unauthorized') 554 login(unauthorized_customer.login) 555 556 # The current customer does not own the asset, so he is unauthorized to 557 # view the form in it. Thus he is silently redirected to index. 558 get 'view_form', :id => @form.id 559 assert_redirected_to :action => 'index' 560 assert_nil flash[:error] 561 assert_nil flash[:notice] 562 assert_nil assigns(:field_values) 563 end 564 505 565 # Method: test_view_form 506 566 # ====================== … … 508 568 # 509 569 def test_view_form 510 # Form type 511 form_type = FormType.create!(:name => 'Test type', :editable => false, :ready => true) 512 # Form field groups 513 g1 = form_type.form_field_groups.create(:name => 'First', :place => 1) 514 g2 = form_type.form_field_groups.create(:name => 'Second', :place => 2) 515 # Form fields visible to customers 516 f1 = form_type.form_fields.create(:name => 'Integer', :user_field_name => 'int', :type_code => FormField::INTEGER, :form_field_group => g2, :show_to_customers => true, :show_to_customers => true, :place => 1) 517 f2 = form_type.form_fields.create(:name => 'String', :user_field_name => 'string', :type_code => FormField::STRING, :form_field_group => g2, :show_to_customers => true, :place => 2) 518 f3 = form_type.form_fields.create(:name => 'Boolean', :user_field_name => 'bool', :type_code => FormField::BOOLEAN, :form_field_group => g1, :show_to_customers => true, :place => 2) 519 f4 = form_type.form_fields.create(:name => 'Float', :user_field_name => 'float', :type_code => FormField::FLOAT, :form_field_group => g1, :show_to_customers => true, :place => 1) 520 f5 = form_type.form_fields.create(:name => 'Long string', :user_field_name => 'lstring', :type_code => FormField::LONG_STRING, :show_to_customers => true, :place => 5) 521 f6 = form_type.form_fields.create(:name => 'Date', :user_field_name => 'date', :type_code => FormField::DATE, :show_to_customers => true, :place => 4) 522 f7 = form_type.form_fields.create(:name => 'Time', :user_field_name => 'time', :type_code => FormField::TIME, :show_to_customers => true, :place => 3) 523 f8 = form_type.form_fields.create(:name => 'Datetime', :user_field_name => 'datetime', :type_code => FormField::DATETIME, :show_to_customers => true, :place => 2) 524 f9 = form_type.form_fields.create(:name => 'Automatic 1', :user_field_name => 'cmms_form_id', :type_code => FormField::AUTOMATIC, :show_to_customers => true, :place => 1) 525 # Form fields hidden from customers 526 form_type.form_fields.create(:name => 'Integer 2', :user_field_name => 'int2', :type_code => FormField::INTEGER) 527 form_type.form_fields.create(:name => 'String 2', :user_field_name => 'string2', :type_code => FormField::STRING) 528 form_type.form_fields.create(:name => 'Boolean 2', :user_field_name => 'bool2', :type_code => FormField::BOOLEAN) 529 form_type.form_fields.create(:name => 'Float 2', :user_field_name => 'float2', :type_code => FormField::FLOAT) 530 form_type.form_fields.create(:name => 'Long string 2', :user_field_name => 'lstring2', :type_code => FormField::LONG_STRING) 531 form_type.form_fields.create(:name => 'Date 2', :user_field_name => 'date2', :type_code => FormField::DATE, :form_field_group => g1) 532 form_type.form_fields.create(:name => 'Time 2', :user_field_name => 'time2', :type_code => FormField::TIME, :form_field_group => g2) 533 form_type.form_fields.create(:name => 'Datetime 2', :user_field_name => 'datetime2', :type_code => FormField::DATETIME) 534 form_type.form_fields.create(:name => 'Automatic 2', :user_field_name => 'cmms_form_type_name', :type_code => FormField::AUTOMATIC) 535 form_type.save! 536 537 # Test form 538 @root.customer = @customer 539 @root.save! 540 form = form_type.create_empty_form(@root) 541 form.ready = true 542 form.save! 543 form.update_automatic_field_values 570 setup_test_form 571 login(@customer.login) 572 573 # The current customer is authorized to view the form 574 assert_equal true, @form.authorized_to_read? 575 get 'view_form', :id => @form.id 576 assert_response :success 577 assert_template 'customer_interface/view_form' 578 assert_nil flash[:error] 579 assert_nil flash[:notice] 580 assert_equal true, assigns(:show_login_name_link) 581 582 field_values_in_groups = assigns(:field_values_in_groups) 583 assert_equal 2, field_values_in_groups.size 584 585 first_group = field_values_in_groups.first 586 assert_equal @ffg1, first_group[:group] 587 assert_equal 2, first_group[:field_values].size 588 assert_equal @ff4, first_group[:field_values].first.form_field 589 assert_equal @ff3, first_group[:field_values].last.form_field 590 591 last_group = field_values_in_groups.last 592 assert_equal @ffg2, last_group[:group] 593 assert_equal 2, last_group[:field_values].size 594 assert_equal @ff1, last_group[:field_values].first.form_field 595 assert_equal @ff2, last_group[:field_values].last.form_field 596 597 groupless_field_values = assigns(:groupless_field_values) 598 assert_equal 4, groupless_field_values.size 599 # Automatic fields are currently not shown. 600 #assert_equal @ff9, groupless_field_values[0].form_field 601 assert_equal @ff8, groupless_field_values[0].form_field 602 assert_equal @ff7, groupless_field_values[1].form_field 603 assert_equal @ff6, groupless_field_values[2].form_field 604 assert_equal @ff5, groupless_field_values[3].form_field 605 end 606 607 # Method: test_print_form_unauthorized 608 # =================================== 609 # Checks that form printing is denied from unauthorized customers. 610 # 611 def test_print_form_unauthorized 612 setup_test_form 544 613 545 614 unauthorized_customer = create_customer('unauthorized') … … 547 616 548 617 # The current customer does not own the asset, so he is unauthorized to 549 # viewthe form in it. Thus he is silently redirected to index.550 get ' view_form', :id =>form.id618 # print the form in it. Thus he is silently redirected to index. 619 get 'print_form', :id => @form.id 551 620 assert_redirected_to :action => 'index' 552 621 assert_nil flash[:error] 553 622 assert_nil flash[:notice] 554 623 assert_nil assigns(:field_values) 555 556 login(@customer.login) 557 558 # The current customer is authorized to view the form 559 assert_equal true, form.authorized_to_read? 560 get 'view_form', :id => form.id 561 assert_response :success 562 assert_template 'customer_interface/view_form' 563 assert_nil flash[:error] 564 assert_nil flash[:notice] 565 assert_equal true, assigns(:show_login_name_link) 624 end 625 626 # Method: test_print_form 627 # ====================== 628 # Checks that form printing works. 629 # 630 def test_print_form 631 setup_test_form 632 login(@customer.login) 633 634 # The current customer is authorized to print the form 635 assert_equal true, @form.authorized_to_read? 636 get 'print_form', :id => @form.id 637 assert_response :success 638 assert_template 'form/print_view' 639 assert_nil flash[:error] 640 assert_nil flash[:notice] 566 641 567 642 field_values_in_groups = assigns(:field_values_in_groups) … … 569 644 570 645 first_group = field_values_in_groups.first 571 assert_equal g1, first_group[:group]646 assert_equal @ffg1, first_group[:group] 572 647 assert_equal 2, first_group[:field_values].size 573 assert_equal f4, first_group[:field_values].first.form_field574 assert_equal f3, first_group[:field_values].last.form_field648 assert_equal @ff4, first_group[:field_values].first.form_field 649 assert_equal @ff3, first_group[:field_values].last.form_field 575 650 576 651 last_group = field_values_in_groups.last 577 assert_equal g2, last_group[:group]652 assert_equal @ffg2, last_group[:group] 578 653 assert_equal 2, last_group[:field_values].size 579 assert_equal f1, last_group[:field_values].first.form_field580 assert_equal f2, last_group[:field_values].last.form_field654 assert_equal @ff1, last_group[:field_values].first.form_field 655 assert_equal @ff2, last_group[:field_values].last.form_field 581 656 582 657 groupless_field_values = assigns(:groupless_field_values) 583 assert_equal 5, groupless_field_values.size 584 assert_equal f9, groupless_field_values[0].form_field 585 assert_equal f8, groupless_field_values[1].form_field 586 assert_equal f7, groupless_field_values[2].form_field 587 assert_equal f6, groupless_field_values[3].form_field 588 assert_equal f5, groupless_field_values[4].form_field 658 assert_equal 4, groupless_field_values.size 659 # Automatic fields are currently not shown. 660 #assert_equal @ff9, groupless_field_values[0].form_field 661 assert_equal @ff8, groupless_field_values[0].form_field 662 assert_equal @ff7, groupless_field_values[1].form_field 663 assert_equal @ff6, groupless_field_values[2].form_field 664 assert_equal @ff5, groupless_field_values[3].form_field 589 665 end 590 666 trunk/test/functional/form_controller_test.rb
r718 r747 273 273 end 274 274 275 # Method: test_print_view 276 # ======================= 277 # Check the print_view action works. 278 def test_print_view 279 @keyring.action_keys << create_action_key('form/view') 280 login('test') 281 282 setup_simple_form_type 283 setup_test_forms 284 285 get 'print_view', :id => @form1.id 286 assert_response :success 287 assert_template 'print_view' 288 assert_equal @form1, assigns(:form) 289 assert_equal [], assigns(:field_values_in_groups) 290 assert_equal @form1.form_field_values.size, assigns(:groupless_field_values).size 291 assigns(:groupless_field_values).each { |v| 292 assert_equal true, @form1.form_field_values.include?(v) 293 } 294 end 295 275 296 private 276 297