#-- # Copyright (c) 2012+ Damjan Rems # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ ########################################################################### # # CmseditHelper module defines helper methods used by cmsedit actions. Output is controlled by # data found in 3 major sections of DRG CMS form: index, result_set and form sections. # ########################################################################### module CmsEditHelper ############################################################################ # Will return value when internal or additional parameters are defined in action # Subroutine of dc_actions_for_form. ############################################################################ def dc_value_for_parameter(param, current_document = nil)#:nodoc: if param.class == Hash dc_internal_var(param['object'] ||= 'record', param['method'], current_document) elsif param.to_s.match(/record|document/) current_document ? current_document : @record else param end end ############################################################################ # Creates actions div for edit form. # # Displaying readonly form turned out to be challenge. For now when readonly parameter # has value 2, back link will force readonly form. Value 1 or not set will result in # normal link. ############################################################################ def dc_is_action_active?(options) if options['when_new'] dc_deprecate("when_option will be deprecated and replaced by active: not_new_record! Form #{CmsHelper.form_param(params)}") return !(dc_dont?(options['when_new']) && @record.new_record?) end return true unless options['active'] # alias record and document so both can be used in eval record = document = @record option = options['active'] case # usually only for test when option.class == TrueClass || option['eval'].class == TrueClass then true when option.class == String then if option.match(/new_record/i) (@record.new_record? && option == 'new_record') || (!@record.new_record? && option == 'not_new_record') elsif option.match(/\./) # shortcut for method and eval option dc_process_eval(option, self) else eval(option['eval']) end # direct evaluate expression when option['eval'] then eval(option['eval']) when option['method'] then # if record present send record otherwise send self as parameter dc_process_eval(option['method'], self) else false end end ############################################################################ # Creates actions div for edit form. # # Displaying readonly form turned out to be challenge. For now when readonly parameter # has value 2, back link will force readonly form. Value 1 or not set will result in # normal link. ############################################################################ def dc_actions_for_form(position) # create standard actions std_actions = {1 => 'back', 2 => {'type' => 'submit', 'caption' => 'drgcms.save'}, 3 => {'type' => 'submit', 'caption' => 'drgcms.save&back'} } # when edit only unless @record.try(:id).nil? std_actions.merge!({6 => 'new'} ) std_actions.merge!(@record.active ? {5 => 'disable'} : {5 => 'enable'} ) if @record.respond_to?('active') std_actions.merge!({7 => 'refresh'} ) end # readonly std_actions = { 1 => 'back' } if @form['readonly'] actions = @form['form']['actions'] # shortcut for actions: standard actions = nil if actions.class == String && actions == 'standard' actions = std_actions if actions.nil? # Actions are strictly forbidden if @form['form']['actions'] && dc_dont?(@form['form']['actions']) actions = [] elsif actions['standard'] actions.merge!(std_actions) actions['standard'] = nil end # request for close window button present if actions.class == Hash case params[:window_close] when '0' then actions[1] = 'close'; actions[3] = nil when '1' then actions = { 1 => 'close' } when '2' then actions = { 1 => 'close' } end end # Update save and save&back actions.each do |k, v| if v.class == String if v.match(/save\&back/i) actions[k] = {'type' => 'submit', 'caption' => 'drgcms.save&back'} elsif v == 'save' actions[k] = {'type' => 'submit', 'caption' => 'drgcms.save'} end end end # remove standard option and sort so that standard actions come first actions.delete('standard') actions = actions.to_a.sort { |x, y| x[0] <=> y[0] } # Add spinner to the beginning html = %Q[#{fa_icon('settings-o spin')}
').html_safe end ############################################################################ # Create background div and table definitions for result set. ############################################################################ def dc_background_for_result(start) if start == :start html = '