drg_cms 0.6.0.8 → 0.6.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +25 -10
- data/app/assets/javascripts/drg_cms/drg_cms.js +208 -81
- data/app/assets/stylesheets/drg_cms/drg_cms.css +298 -93
- data/app/assets/stylesheets/drg_cms/select-multiple.css +1 -1
- data/app/controllers/cmsedit_controller.rb +174 -167
- data/app/controllers/dc_application_controller.rb +230 -196
- data/app/controllers/dc_common_controller.rb +88 -50
- data/app/controls/dc_help_control.rb +138 -0
- data/app/controls/dc_report.rb +12 -16
- data/app/forms/all_options.yml +14 -5
- data/app/forms/cms_menu.yml +7 -1
- data/app/forms/dc_big_table.yml +0 -2
- data/app/forms/dc_big_table_value.yml +0 -2
- data/app/forms/dc_category.yml +2 -1
- data/app/forms/dc_design.yml +2 -2
- data/app/forms/dc_folder_permission.yml +0 -2
- data/app/forms/dc_help_1.yml +110 -0
- data/app/forms/dc_journal.yml +3 -1
- data/app/forms/dc_json_ld.yml +0 -3
- data/app/forms/dc_link.yml +1 -1
- data/app/forms/dc_menu.yml +8 -12
- data/app/forms/dc_menu_item.yml +2 -3
- data/app/forms/dc_page.yml +7 -2
- data/app/forms/dc_part.yml +1 -0
- data/app/forms/dc_piece.yml +1 -0
- data/app/forms/dc_policy.yml +2 -5
- data/app/forms/dc_poll.yml +13 -16
- data/app/forms/dc_seo.yml +1 -2
- data/app/forms/dc_simple_menu.yml +3 -2
- data/app/forms/dc_site.yml +5 -8
- data/app/forms/dc_user.yml +27 -11
- data/app/forms/dc_user_role.yml +3 -0
- data/app/helpers/cms_common_helper.rb +68 -4
- data/app/helpers/cms_edit_helper.rb +73 -55
- data/app/helpers/cms_helper.rb +70 -32
- data/app/helpers/cms_index_helper.rb +155 -102
- data/app/helpers/dc_application_helper.rb +132 -109
- data/app/models/concerns/dc_page_concern.rb +14 -4
- data/app/models/concerns/dc_piece_concern.rb +1 -1
- data/app/models/concerns/dc_policy_rule_concern.rb +20 -8
- data/app/models/concerns/dc_site_concern.rb +56 -44
- data/app/models/concerns/dc_user_concern.rb +58 -19
- data/app/models/dc_big_table.rb +2 -2
- data/app/models/dc_design.rb +29 -19
- data/app/models/dc_filter.rb +28 -22
- data/app/models/dc_key_value_store.rb +1 -0
- data/app/models/dc_permission.rb +19 -9
- data/app/models/dc_policy.rb +25 -14
- data/app/models/dc_policy_role.rb +22 -11
- data/app/models/dc_temp.rb +8 -1
- data/app/models/dc_user_role.rb +2 -2
- data/app/models/drgcms_form_fields/comment.rb +11 -2
- data/app/models/drgcms_form_fields/date_picker.rb +2 -0
- data/app/models/drgcms_form_fields/drgcms_field.rb +2 -1
- data/app/models/drgcms_form_fields/embedded.rb +9 -10
- data/app/models/drgcms_form_fields/file_field.rb +1 -1
- data/app/models/drgcms_form_fields/file_select.rb +2 -2
- data/app/models/drgcms_form_fields/hash_field.rb +11 -7
- data/app/models/drgcms_form_fields/link_to.rb +2 -2
- data/app/models/drgcms_form_fields/method.rb +5 -4
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +1 -1
- data/app/models/drgcms_form_fields/number_field.rb +4 -3
- data/app/models/drgcms_form_fields/readonly.rb +13 -17
- data/app/models/drgcms_form_fields/select.rb +24 -25
- data/app/models/drgcms_form_fields/text_autocomplete.rb +22 -14
- data/app/renderers/dc_page_renderer.rb +7 -6
- data/app/renderers/dc_poll_renderer.rb +16 -20
- data/app/views/cmsedit/_edit_stuff.html.erb +5 -2
- data/app/views/cmsedit/_form.html.erb +3 -2
- data/app/views/cmsedit/_result.html.erb +21 -18
- data/app/views/cmsedit/edit.html.erb +4 -1
- data/app/views/cmsedit/index.html.erb +3 -2
- data/app/views/cmsedit/new.html.erb +5 -2
- data/app/views/dc_common/_help.html.erb +17 -0
- data/app/views/layouts/models.html.erb +2 -1
- data/config/locales/drgcms_en.yml +17 -2
- data/config/locales/drgcms_sl.yml +20 -2
- data/config/locales/models_en.yml +7 -5
- data/config/locales/models_sl.yml +12 -9
- data/drg_cms.gemspec +16 -16
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +94 -2
- metadata +32 -30
- data/app/models/__dc_dummy.rb +0 -102
| @@ -41,9 +41,10 @@ | |
| 41 41 | 
             
            # its control's would be found in model_embedded_controls.rb. By convention module names
         | 
| 42 42 | 
             
            # are declared in camel case, so our dc_page_controls.rb declares DrgcmsControls::DcPageControls module.
         | 
| 43 43 | 
             
            # 
         | 
| 44 | 
            -
            # Controls (among other) may contain  | 
| 44 | 
            +
            # Controls (among other) may contain 7 callback methods.
         | 
| 45 45 | 
             
            # These methods are:
         | 
| 46 46 | 
             
            # * dc_new_record
         | 
| 47 | 
            +
            # * dc_dup_record
         | 
| 47 48 | 
             
            # * dc_before_edit
         | 
| 48 49 | 
             
            # * dc_before_save
         | 
| 49 50 | 
             
            # * dc_after_save
         | 
| @@ -67,7 +68,7 @@ | |
| 67 68 | 
             
            #      if dc_user_can(DcPermission::CAN_READ)
         | 
| 68 69 | 
             
            #        dc_page.where(created_by: session[:user_id])
         | 
| 69 70 | 
             
            #      else
         | 
| 70 | 
            -
            #        flash[:error] = ' | 
| 71 | 
            +
            #        flash[:error] = 'User can not perform this operation!'
         | 
| 71 72 | 
             
            #        nil
         | 
| 72 73 | 
             
            #      end
         | 
| 73 74 | 
             
            #    end
         | 
| @@ -76,7 +77,6 @@ | |
| 76 77 | 
             
            ########################################################################
         | 
| 77 78 | 
             
            class CmseditController < DcApplicationController
         | 
| 78 79 | 
             
            before_action :check_authorization, :except => [:login, :logout, :test, :run]
         | 
| 79 | 
            -
            before_action :dc_reload_patches if Rails.env.development?
         | 
| 80 80 | 
             
            protect_from_forgery with: :null_session, only: Proc.new { |c| c.request.format.json? }
         | 
| 81 81 |  | 
| 82 82 | 
             
            layout 'cms'
         | 
| @@ -88,7 +88,7 @@ def index | |
| 88 88 | 
             
              @form['result_set'] ||= {}
         | 
| 89 89 | 
             
              redirected = (@form['table'] == 'dc_memory' ? process_in_memory : process_collections)
         | 
| 90 90 | 
             
              return if redirected
         | 
| 91 | 
            -
             | 
| 91 | 
            +
             | 
| 92 92 | 
             
              call_callback_method(@form['result_set']['footer'] || 'dc_footer')
         | 
| 93 93 | 
             
              respond_to do |format|
         | 
| 94 94 | 
             
                format.html { render action:  :index }
         | 
| @@ -108,9 +108,9 @@ end | |
| 108 108 | 
             
            ########################################################################
         | 
| 109 109 | 
             
            def show
         | 
| 110 110 | 
             
              find_record
         | 
| 111 | 
            +
              # before_show callback
         | 
| 111 112 | 
             
              if (m = callback_method('before_show') )
         | 
| 112 113 | 
             
                ret = call_callback_method(m)
         | 
| 113 | 
            -
            # Don't do anything if return is false
         | 
| 114 114 | 
             
                if ret.class == FalseClass
         | 
| 115 115 | 
             
                  @form['readonly'] = nil # must be
         | 
| 116 116 | 
             
                  return index 
         | 
| @@ -148,20 +148,21 @@ def logout | |
| 148 148 | 
             
            end
         | 
| 149 149 |  | 
| 150 150 | 
             
            ########################################################################
         | 
| 151 | 
            -
            #  | 
| 152 | 
            -
            # 
         | 
| 153 | 
            -
            #  | 
| 151 | 
            +
            # Shortcut for setting currently selected site in development. Will search
         | 
| 152 | 
            +
            # for dc_site document with site name 'test' and set alias_for to site
         | 
| 153 | 
            +
            # url parameter.
         | 
| 154 154 | 
             
            ########################################################################
         | 
| 155 155 | 
             
            def set_test_site 
         | 
| 156 156 | 
             
              # only in development
         | 
| 157 | 
            -
              return dc_render_404  | 
| 157 | 
            +
              return dc_render_404 unless Rails.env.development?
         | 
| 158 | 
            +
             | 
| 158 159 | 
             
              alias_site = DcSite.find_by(:name => params[:site])
         | 
| 159 160 | 
             
              return dc_render_404 unless alias_site
         | 
| 161 | 
            +
             | 
| 160 162 | 
             
              # update alias for  
         | 
| 161 | 
            -
              site | 
| 163 | 
            +
              site = DcSite.find_by(:name => 'test')
         | 
| 162 164 | 
             
              site.alias_for = params[:site]
         | 
| 163 165 | 
             
              site.save
         | 
| 164 | 
            -
              # redirect to root  
         | 
| 165 166 | 
             
              redirect_to '/'
         | 
| 166 167 | 
             
            end
         | 
| 167 168 |  | 
| @@ -169,17 +170,17 @@ end | |
| 169 170 | 
             
            # New action.
         | 
| 170 171 | 
             
            ########################################################################
         | 
| 171 172 | 
             
            def new
         | 
| 172 | 
            -
            # clear flash messages.
         | 
| 173 | 
            +
              # clear flash messages.
         | 
| 173 174 | 
             
              flash[:error] = flash[:warning] = flash[:info] = nil 
         | 
| 174 175 | 
             
              create_new_empty_record
         | 
| 176 | 
            +
              # before_new callback
         | 
| 175 177 | 
             
              if (m = callback_method('before_new') )
         | 
| 176 178 | 
             
                ret = call_callback_method(m)
         | 
| 177 | 
            -
            # Don't do anything if return is false
         | 
| 178 179 | 
             
                return index if ret.class == FalseClass
         | 
| 179 180 | 
             
              end  
         | 
| 180 181 | 
             
              table = @tables.last[1] + '.'
         | 
| 181 | 
            -
            # initial values set on page
         | 
| 182 | 
            -
              if cookies[:record]  | 
| 182 | 
            +
              # initial values set on page
         | 
| 183 | 
            +
              if cookies[:record] && cookies[:record].size > 0
         | 
| 183 184 | 
             
                Marshal.load(cookies[:record]).each do |k,v|
         | 
| 184 185 | 
             
                  k = k.to_s
         | 
| 185 186 | 
             
                  if k.match(table)
         | 
| @@ -188,15 +189,14 @@ def new | |
| 188 189 | 
             
                  end
         | 
| 189 190 | 
             
                end
         | 
| 190 191 | 
             
              end
         | 
| 191 | 
            -
            # initial values set in url
         | 
| 192 | 
            +
              # initial values set in url (params)
         | 
| 192 193 | 
             
              params.each do |k,v|
         | 
| 193 194 | 
             
                if k.match(table)
         | 
| 194 195 | 
             
                  field = k.split('.').last
         | 
| 195 196 | 
             
                  @record.send("#{field}=", v) if @record.respond_to?(field)
         | 
| 196 197 | 
             
                end
         | 
| 197 198 | 
             
              end
         | 
| 198 | 
            -
            #  | 
| 199 | 
            -
              #dc_new_record() if respond_to?('dc_new_record') 
         | 
| 199 | 
            +
              # new_record callback. Set default values for new record
         | 
| 200 200 | 
             
              if (m = callback_method('new_record') ) then call_callback_method(m)  end
         | 
| 201 201 | 
             
              @parms['action'] = 'create'
         | 
| 202 202 | 
             
            end
         | 
| @@ -204,19 +204,21 @@ end | |
| 204 204 | 
             
            ########################################################################
         | 
| 205 205 | 
             
            # Duplicate embedded document. Since embedded documents are returned differently 
         | 
| 206 206 | 
             
            # then top level document. Subroutine of duplicate_socument.
         | 
| 207 | 
            +
            #
         | 
| 208 | 
            +
            #TODO Works for two embedded levels. Dies with third and more levels.
         | 
| 207 209 | 
             
            ########################################################################
         | 
| 208 210 | 
             
            def duplicate_embedded(source) #:nodoc:
         | 
| 209 | 
            -
            # TODO Works for two embedded levels. Dies with third and more levels.
         | 
| 210 211 | 
             
              dest = {}
         | 
| 211 212 | 
             
              source.each do |attribute_name, value|
         | 
| 212 213 | 
             
                next if attribute_name == '_id' # don't duplicate _id
         | 
| 214 | 
            +
             | 
| 213 215 | 
             
                if value.class == Array
         | 
| 214 216 | 
             
                  dest[attribute_name] = []
         | 
| 215 217 | 
             
                  value.each do |ar|
         | 
| 216 218 | 
             
                    dest[attribute_name] << duplicate_embedded(ar)
         | 
| 217 219 | 
             
                  end
         | 
| 218 | 
            -
                else | 
| 219 | 
            -
            # if duplicate string  | 
| 220 | 
            +
                else
         | 
| 221 | 
            +
                  # if duplicate, string dup is added. For unique fields
         | 
| 220 222 | 
             
                  add_duplicate = params['dup_fields'].to_s.match(attribute_name + ',')
         | 
| 221 223 | 
             
                  dest[attribute_name] = value
         | 
| 222 224 | 
             
                  dest[attribute_name] << ' dup' if add_duplicate
         | 
| @@ -229,20 +231,23 @@ end | |
| 229 231 |  | 
| 230 232 | 
             
            ########################################################################
         | 
| 231 233 | 
             
            # Will create duplicate document of source document. This method is used for 
         | 
| 232 | 
            -
            # duplicating document and is  | 
| 234 | 
            +
            # duplicating document and is subroutine of create action.
         | 
| 233 235 | 
             
            ########################################################################
         | 
| 234 236 | 
             
            def duplicate_document(source)
         | 
| 237 | 
            +
              params['dup_fields'] += ',' if params['dup_fields'] # for easier field matching
         | 
| 235 238 | 
             
              dest = {}
         | 
| 236 239 | 
             
              source.attribute_names.each do |attribute_name|
         | 
| 237 240 | 
             
                next if attribute_name == '_id' # don't duplicate _id
         | 
| 238 | 
            -
             | 
| 241 | 
            +
             | 
| 242 | 
            +
                # if duplicate, string dup is added. For unique fields
         | 
| 239 243 | 
             
                add_duplicate = params['dup_fields'].to_s.match(attribute_name + ',')
         | 
| 240 244 | 
             
                dest[attribute_name] = source[attribute_name]
         | 
| 241 245 | 
             
                dest[attribute_name] << ' dup' if add_duplicate
         | 
| 242 246 | 
             
              end
         | 
| 243 | 
            -
            # embedded documents
         | 
| 247 | 
            +
              # embedded documents
         | 
| 244 248 | 
             
              source.embedded_relations.keys.each do |embedded_name|
         | 
| 245 249 | 
             
                next if source[embedded_name].nil? # it happens
         | 
| 250 | 
            +
             | 
| 246 251 | 
             
                dest[embedded_name] = []
         | 
| 247 252 | 
             
                source[embedded_name].each do |embedded|
         | 
| 248 253 | 
             
                  dest[embedded_name] << duplicate_embedded(embedded)
         | 
| @@ -257,42 +262,44 @@ end | |
| 257 262 | 
             
            # Create (or duplicate) action. Action is also used for turning filter on.
         | 
| 258 263 | 
             
            ########################################################################
         | 
| 259 264 | 
             
            def create
         | 
| 260 | 
            -
            # abusing create for turning filter on
         | 
| 265 | 
            +
              # abusing create for turning filter on
         | 
| 261 266 | 
             
              return index if params[:filter].to_s == 'on'
         | 
| 262 | 
            -
             | 
| 267 | 
            +
             | 
| 268 | 
            +
              # not authorized
         | 
| 263 269 | 
             
              unless dc_user_can(DcPermission::CAN_CREATE)
         | 
| 264 270 | 
             
                flash[:error] = t('drgcms.not_authorized')
         | 
| 265 271 | 
             
                return index
         | 
| 266 272 | 
             
              end
         | 
| 267 | 
            -
             | 
| 268 | 
            -
               | 
| 269 | 
            -
             | 
| 273 | 
            +
             | 
| 274 | 
            +
              # create document
         | 
| 275 | 
            +
              if params['id'].nil?
         | 
| 276 | 
            +
                # Prevent double form submit
         | 
| 270 277 | 
             
                params[:form_time_stamp] = params[:form_time_stamp].to_i
         | 
| 271 278 | 
             
                session[:form_time_stamp] ||= 0
         | 
| 272 279 | 
             
                return index if params[:form_time_stamp] <= session[:form_time_stamp]
         | 
| 280 | 
            +
             | 
| 273 281 | 
             
                session[:form_time_stamp] = params[:form_time_stamp]
         | 
| 274 | 
            -
            #    
         | 
| 275 282 | 
             
                create_new_empty_record
         | 
| 276 283 | 
             
                if save_data
         | 
| 277 284 | 
             
                  flash[:info] = t('drgcms.doc_saved')
         | 
| 278 285 | 
             
                  params[:return_to] = 'index' if params[:commit] == t('drgcms.save&back') # save & back
         | 
| 279 286 | 
             
                  return process_return_to(params[:return_to]) if params[:return_to]
         | 
| 280 287 |  | 
| 281 | 
            -
                  @parms['id'] | 
| 282 | 
            -
                  params[:id] | 
| 288 | 
            +
                  @parms['id'] = @record.id # must be set, for proper update link
         | 
| 289 | 
            +
                  params[:id]  = @record.id # must be set, for find_record
         | 
| 283 290 | 
             
                  edit
         | 
| 284 291 | 
             
                else # error
         | 
| 285 292 | 
             
                  return process_return_to(params[:return_to]) if params[:return_to]
         | 
| 293 | 
            +
             | 
| 286 294 | 
             
                  render action: :new
         | 
| 287 295 | 
             
                end
         | 
| 288 296 | 
             
              else # duplicate record
         | 
| 289 297 | 
             
                find_record
         | 
| 290 | 
            -
                params['dup_fields'] += ',' if params['dup_fields'] # for easier field matching
         | 
| 291 298 | 
             
                new_doc = duplicate_document(@record)
         | 
| 292 299 | 
             
                create_new_empty_record(new_doc)
         | 
| 293 | 
            -
                 | 
| 300 | 
            +
                if (m = callback_method('dup_record')) then call_callback_method(m) end
         | 
| 301 | 
            +
                update_standards
         | 
| 294 302 | 
             
                @record.save!
         | 
| 295 | 
            -
             | 
| 296 303 | 
             
                index
         | 
| 297 304 | 
             
              end
         | 
| 298 305 | 
             
            end
         | 
| @@ -304,7 +311,7 @@ def edit | |
| 304 311 | 
             
              find_record
         | 
| 305 312 | 
             
              if (m = callback_method('before_edit') )
         | 
| 306 313 | 
             
                ret = call_callback_method(m)
         | 
| 307 | 
            -
            #  | 
| 314 | 
            +
                # don't do anything if return is false
         | 
| 308 315 | 
             
                return index if ret.class == FalseClass
         | 
| 309 316 | 
             
              end
         | 
| 310 317 | 
             
              @parms['action'] = 'update'
         | 
| @@ -316,29 +323,25 @@ end | |
| 316 323 | 
             
            ########################################################################
         | 
| 317 324 | 
             
            def update
         | 
| 318 325 | 
             
              find_record
         | 
| 319 | 
            -
            # check if record was not updated in mean time
         | 
| 326 | 
            +
              # check if record was not updated in mean time
         | 
| 320 327 | 
             
              if @record.respond_to?(:updated_at)
         | 
| 321 328 | 
             
                if params[:last_updated_at].to_i != @record.updated_at.to_i
         | 
| 322 329 | 
             
                  flash[:error] = t('drgcms.updated_by_other')
         | 
| 323 330 | 
             
                  return render(action: :edit)
         | 
| 324 331 | 
             
                end
         | 
| 325 332 | 
             
              end
         | 
| 326 | 
            -
             | 
| 327 | 
            -
              if dc_user_can(DcPermission::CAN_EDIT_ALL)  | 
| 328 | 
            -
                ( | 
| 329 | 
            -
             | 
| 330 | 
            -
                  dc_user_can(DcPermission::CAN_EDIT) )
         | 
| 331 | 
            -
            #
         | 
| 333 | 
            +
             | 
| 334 | 
            +
              if dc_user_can(DcPermission::CAN_EDIT_ALL) ||
         | 
| 335 | 
            +
                (@record.respond_to?('created_by') && @record.created_by == session[:user_id] && dc_user_can(DcPermission::CAN_EDIT))
         | 
| 336 | 
            +
             | 
| 332 337 | 
             
                if save_data
         | 
| 333 338 | 
             
                  params[:return_to] = 'index' if params[:commit] == t('drgcms.save&back') # save & back
         | 
| 334 339 | 
             
                  @parms['action'] = 'update'
         | 
| 335 | 
            -
            # Process return_to | 
| 340 | 
            +
                  # Process return_to
         | 
| 336 341 | 
             
                  return process_return_to(params[:return_to]) if params[:return_to]
         | 
| 337 342 | 
             
                else
         | 
| 338 343 | 
             
                  # do not forget before_edit callback
         | 
| 339 | 
            -
                  if m = callback_method('before_edit')
         | 
| 340 | 
            -
                    call_callback_method(m)
         | 
| 341 | 
            -
                  end
         | 
| 344 | 
            +
                  if m = callback_method('before_edit') then call_callback_method(m) end
         | 
| 342 345 | 
             
                  return render action: :edit
         | 
| 343 346 | 
             
                end
         | 
| 344 347 | 
             
              else
         | 
| @@ -352,7 +355,7 @@ end | |
| 352 355 | 
             
            ########################################################################
         | 
| 353 356 | 
             
            def destroy
         | 
| 354 357 | 
             
              find_record
         | 
| 355 | 
            -
            #  | 
| 358 | 
            +
              # check permission required to delete
         | 
| 356 359 | 
             
              permission = if params['operation'].nil?
         | 
| 357 360 | 
             
                if @record.respond_to?('created_by') # needs can_delete_all if created_by is present and not owner
         | 
| 358 361 | 
             
                  (@record.created_by == session[:user_id]) ? DcPermission::CAN_DELETE : DcPermission::CAN_DELETE_ALL
         | 
| @@ -367,38 +370,39 @@ def destroy | |
| 367 370 | 
             
                end
         | 
| 368 371 | 
             
              end
         | 
| 369 372 | 
             
              ok2delete = dc_user_can(permission)
         | 
| 370 | 
            -
             | 
| 373 | 
            +
             | 
| 371 374 | 
             
              case
         | 
| 372 | 
            -
            # not authorized | 
| 375 | 
            +
              # not authorized
         | 
| 373 376 | 
             
              when !ok2delete then
         | 
| 374 377 | 
             
                flash[:error] = t('drgcms.not_authorized')
         | 
| 375 378 | 
             
                return index
         | 
| 376 | 
            -
             | 
| 379 | 
            +
             | 
| 380 | 
            +
              # delete document
         | 
| 377 381 | 
             
              when params['operation'].nil? then
         | 
| 378 | 
            -
            #  | 
| 382 | 
            +
                # before_delete callback
         | 
| 379 383 | 
             
                if (m = callback_method('before_delete') )
         | 
| 380 384 | 
             
                  ret = call_callback_method(m)
         | 
| 381 | 
            -
            #  | 
| 385 | 
            +
                  # don't do anything if return is false
         | 
| 382 386 | 
             
                  return index if ret.class == FalseClass
         | 
| 383 387 | 
             
                end
         | 
| 384 | 
            -
             | 
| 388 | 
            +
             | 
| 385 389 | 
             
                if @record.destroy
         | 
| 386 390 | 
             
                  save_journal(:delete)
         | 
| 387 391 | 
             
                  flash[:info] = t('drgcms.record_deleted')
         | 
| 388 | 
            -
            #  | 
| 392 | 
            +
                  # after_delete callback
         | 
| 389 393 | 
             
                  if (m = callback_method('after_delete') ) 
         | 
| 390 394 | 
             
                    call_callback_method(m)
         | 
| 391 395 | 
             
                  elsif params['after-delete'].to_s.match('return_to')
         | 
| 392 396 | 
             
                    params[:return_to] = params['after-delete']
         | 
| 393 397 | 
             
                  end
         | 
| 394 | 
            -
            # Process return_to link
         | 
| 398 | 
            +
                  # Process return_to link
         | 
| 395 399 | 
             
                  return process_return_to(params[:return_to]) if params[:return_to]
         | 
| 396 400 | 
             
                else
         | 
| 397 401 | 
             
                  flash[:error] = dc_error_messages_for(@record)
         | 
| 398 402 | 
             
                end
         | 
| 399 403 | 
             
                return index
         | 
| 400 404 |  | 
| 401 | 
            -
            #  | 
| 405 | 
            +
              # deactivate document
         | 
| 402 406 | 
             
              when params['operation'] == 'disable' then
         | 
| 403 407 | 
             
                if @record.respond_to?('active')
         | 
| 404 408 | 
             
                  @record.active = false
         | 
| @@ -408,7 +412,7 @@ def destroy | |
| 408 412 | 
             
                  flash[:info] = t('drgcms.doc_disabled')
         | 
| 409 413 | 
             
                end
         | 
| 410 414 |  | 
| 411 | 
            -
            #  | 
| 415 | 
            +
              # reactivate document
         | 
| 412 416 | 
             
              when params['operation'] == 'enable' then
         | 
| 413 417 | 
             
                if @record.respond_to?('active')
         | 
| 414 418 | 
             
                  @record.active = true
         | 
| @@ -418,11 +422,11 @@ def destroy | |
| 418 422 | 
             
                  flash[:info] = t('drgcms.doc_enabled')
         | 
| 419 423 | 
             
                end
         | 
| 420 424 |  | 
| 421 | 
            -
            # reorder documents
         | 
| 425 | 
            +
              #TODO reorder documents
         | 
| 422 426 | 
             
              when params['operation'] == 'reorder' then
         | 
| 423 427 |  | 
| 424 428 | 
             
              end
         | 
| 425 | 
            -
             | 
| 429 | 
            +
             | 
| 426 430 | 
             
              @parms['action'] = 'update'
         | 
| 427 431 | 
             
              render action: :edit
         | 
| 428 432 | 
             
            end
         | 
| @@ -498,7 +502,7 @@ def user_has_permission?(permission, collection_name) | |
| 498 502 | 
             
            end
         | 
| 499 503 |  | 
| 500 504 | 
             
            ########################################################################
         | 
| 501 | 
            -
            # Merges two forms when current form extends other form. Subroutine of  | 
| 505 | 
            +
            # Merges two forms when current form extends other form. Subroutine of read_drg_form.
         | 
| 502 506 | 
             
            # With a little help of https://www.ruby-forum.com/topic/142809 
         | 
| 503 507 | 
             
            ########################################################################
         | 
| 504 508 | 
             
            def forms_merge(hash1, hash2)
         | 
| @@ -510,8 +514,8 @@ def forms_merge(hash1, hash2) | |
| 510 514 | 
             
                end
         | 
| 511 515 | 
             
                target[key] = hash2[key] == '/' ? nil :  hash2[key]
         | 
| 512 516 | 
             
              end
         | 
| 513 | 
            -
            # delete keys with nil value | 
| 514 | 
            -
              target.delete_if{ |k,v| v.nil? }
         | 
| 517 | 
            +
              # delete keys with nil value
         | 
| 518 | 
            +
              target.delete_if { |k, v| v.nil? }
         | 
| 515 519 | 
             
            end
         | 
| 516 520 |  | 
| 517 521 | 
             
            ########################################################################
         | 
| @@ -521,13 +525,13 @@ end | |
| 521 525 | 
             
            # [Parameters:]
         | 
| 522 526 | 
             
            # [extend_option] : Value of @form['extend'] option
         | 
| 523 527 | 
             
            ########################################################################
         | 
| 524 | 
            -
            def  | 
| 528 | 
            +
            def extend_drg_form(extend_option)
         | 
| 525 529 | 
             
              form_file_name = dc_find_form_file(extend_option) 
         | 
| 526 | 
            -
              @form_js <<  | 
| 530 | 
            +
              @form_js << read_js_drg_form(form_file_name)
         | 
| 527 531 | 
             
              form  = YAML.load_file( form_file_name )
         | 
| 528 532 | 
             
              @form = forms_merge(form, @form)
         | 
| 529 | 
            -
            # If combined form contains tabs and fields options, merge fields into tabs
         | 
| 530 | 
            -
              if @form['form']['tabs']  | 
| 533 | 
            +
              # If combined form contains tabs and fields options, merge fields into tabs
         | 
| 534 | 
            +
              if @form['form']['tabs'] && @form['form']['fields']
         | 
| 531 535 | 
             
                @form['form']['tabs']['fields'] = @form['form']['fields']
         | 
| 532 536 | 
             
                @form['form']['fields'] = nil
         | 
| 533 537 | 
             
              end
         | 
| @@ -540,54 +544,59 @@ end | |
| 540 544 | 
             
            # [Parameters:]
         | 
| 541 545 | 
             
            # [include_option] : Value of @form['include'] option
         | 
| 542 546 | 
             
            ########################################################################
         | 
| 543 | 
            -
            def  | 
| 547 | 
            +
            def include_drg_form(include_option)
         | 
| 544 548 | 
             
              includes = include_option.class == Array ? include_option : include_option.split(/\,|\;/)
         | 
| 545 549 | 
             
              includes.each do |include_file|
         | 
| 546 550 | 
             
                form_file_name = dc_find_form_file(include_file)    
         | 
| 547 | 
            -
                @form_js <<  | 
| 551 | 
            +
                @form_js << read_js_drg_form(form_file_name)
         | 
| 548 552 | 
             
                form  = YAML.load_file(form_file_name)    
         | 
| 549 553 | 
             
                @form = forms_merge(@form, form)
         | 
| 550 554 | 
             
              end
         | 
| 551 555 | 
             
            end
         | 
| 552 556 |  | 
| 553 557 | 
             
            ########################################################################
         | 
| 554 | 
            -
            # Will read data from form_file_name.js if  | 
| 558 | 
            +
            # Will read data from form_file_name.js if exists.
         | 
| 555 559 | 
             
            # 
         | 
| 556 560 | 
             
            # [Parameters:]
         | 
| 557 561 | 
             
            # [form_file_name] : Physical form filename
         | 
| 558 562 | 
             
            ########################################################################
         | 
| 559 | 
            -
            def  | 
| 563 | 
            +
            def read_js_drg_form(form_file_name)
         | 
| 560 564 | 
             
              js_form_file_name = form_file_name.sub('.yml','.js')
         | 
| 561 565 | 
             
              File.read(js_form_file_name) rescue ''
         | 
| 562 566 | 
             
            end
         | 
| 563 567 |  | 
| 564 568 | 
             
            ########################################################################
         | 
| 565 | 
            -
            # Read  | 
| 569 | 
            +
            # Read DRG form into @form object. Subroutine of check_authorization.
         | 
| 566 570 | 
             
            ########################################################################
         | 
| 567 | 
            -
            def  | 
| 571 | 
            +
            def read_drg_form
         | 
| 568 572 | 
             
              table_name = decamelize_type(params[:table].strip)
         | 
| 569 573 | 
             
              @tables = table_name.split(';').inject([]) { |r,v| r << [(v.classify.constantize rescue nil), v] }
         | 
| 570 | 
            -
             | 
| 574 | 
            +
             | 
| 575 | 
            +
              # split ids passed when embedded document
         | 
| 571 576 | 
             
              ids = params[:ids].to_s.strip.downcase
         | 
| 572 577 | 
             
              @ids = ids.split(';').inject([]) { |r,v| r << v }
         | 
| 573 | 
            -
             | 
| 578 | 
            +
             | 
| 579 | 
            +
              # form_name defaults to last table specified
         | 
| 574 580 | 
             
              form_name = params[:form_name] || @tables.last[1]
         | 
| 575 581 | 
             
              @form_js = ''
         | 
| 576 | 
            -
             | 
| 582 | 
            +
             | 
| 583 | 
            +
              # dynamically generated form
         | 
| 577 584 | 
             
              @form = if params[:form_name] == 'method'
         | 
| 578 | 
            -
             | 
| 579 | 
            -
             | 
| 580 | 
            -
             | 
| 581 | 
            -
             | 
| 582 | 
            -
             | 
| 583 | 
            -
             | 
| 584 | 
            -
             | 
| 585 | 
            -
               | 
| 586 | 
            -
               | 
| 585 | 
            +
                        dc_eval_class_method(params[:form_method], params)
         | 
| 586 | 
            +
                      else
         | 
| 587 | 
            +
                        form_file_name = dc_find_form_file(form_name)
         | 
| 588 | 
            +
                        @form_js = read_js_drg_form(form_file_name)
         | 
| 589 | 
            +
                        YAML.load_file(form_file_name)
         | 
| 590 | 
            +
                      end
         | 
| 591 | 
            +
             | 
| 592 | 
            +
              # form includes or extends another form file
         | 
| 593 | 
            +
              include_drg_form(@form['include']) if @form['include']
         | 
| 594 | 
            +
              extend_drg_form(@form['extend'])   if @form['extend']
         | 
| 587 595 | 
             
              @form['script'] = (@form['script'].blank? ? @form_js : @form['script'] + @form_js)
         | 
| 588 | 
            -
            # add readonly key to form if readonly parameter is passed in url
         | 
| 596 | 
            +
              # add readonly key to form if readonly parameter is passed in url
         | 
| 589 597 | 
             
              @form['readonly'] = 1 if params['readonly'] #and %w(1 yes true).include?(params['readonly'].to_s.downcase.strip)
         | 
| 590 | 
            -
             | 
| 598 | 
            +
             | 
| 599 | 
            +
              # !!!!!! Always use strings for key names since @parms['table'] != @parms[:table]
         | 
| 591 600 | 
             
              @parms = { 'table' => table_name, 'ids' => params[:ids], 'form_name' => form_name,
         | 
| 592 601 | 
             
                         'return_to' => params['return_to'], 'edit_only' => params['edit_only'],
         | 
| 593 602 | 
             
                         'readonly' => params['readonly'] 
         | 
| @@ -643,7 +652,7 @@ def check_authorization | |
| 643 652 | 
             
                 (table.size < 3 or !dc_user_can(DcPermission::CAN_VIEW))
         | 
| 644 653 | 
             
                return render(action: 'error', locals: { error: t('drgcms.not_authorized')} )
         | 
| 645 654 | 
             
              end
         | 
| 646 | 
            -
               | 
| 655 | 
            +
              read_drg_form
         | 
| 647 656 | 
             
              return render( plain: t('drgcms.form_error') ) if @form.nil?
         | 
| 648 657 |  | 
| 649 658 | 
             
              # Permissions can be also defined on form
         | 
| @@ -672,12 +681,12 @@ end | |
| 672 681 | 
             
            ########################################################################
         | 
| 673 682 | 
             
            # Creates new empty record for new and create action.
         | 
| 674 683 | 
             
            ########################################################################
         | 
| 675 | 
            -
            def create_new_empty_record(initial_data=nil) #:nodoc:
         | 
| 684 | 
            +
            def create_new_empty_record(initial_data = nil) #:nodoc:
         | 
| 676 685 | 
             
              if @tables.size == 1
         | 
| 677 686 | 
             
                @record = @tables.first[0].new(initial_data)
         | 
| 678 687 | 
             
              else
         | 
| 679 688 | 
             
                rec = @tables.first[0].find(@ids.first)             # top most record
         | 
| 680 | 
            -
                1.upto(@tables.size - 2) { |i| rec = rec.send(@tables[i][1].pluralize).find(@ids[i]) }  # find embedded  | 
| 689 | 
            +
                1.upto(@tables.size - 2) { |i| rec = rec.send(@tables[i][1].pluralize).find(@ids[i]) }  # find embedded children by ids
         | 
| 681 690 | 
             
                @record = rec.send(@tables.last[1].pluralize).new(initial_data)   # new record
         | 
| 682 691 | 
             
              end
         | 
| 683 692 | 
             
            end
         | 
| @@ -689,9 +698,9 @@ def update_standards(record = @record) | |
| 689 698 | 
             
              record.updated_by = session[:user_id] if record.respond_to?('updated_by')
         | 
| 690 699 | 
             
              if record.new_record?
         | 
| 691 700 | 
             
                record.created_by = session[:user_id] if record.respond_to?('created_by')
         | 
| 692 | 
            -
            # set this only initialy. Allow to be set to nil on updates.  | 
| 693 | 
            -
            # and will be directly visible only to admins
         | 
| 694 | 
            -
                record.dc_site_id = dc_get_site. | 
| 701 | 
            +
                # set this only initialy. Allow to be set to nil on updates. Document can then belong to all sites
         | 
| 702 | 
            +
                # and will be directly visible only to admins
         | 
| 703 | 
            +
                record.dc_site_id = dc_get_site.id if record.respond_to?('dc_site_id') && record.dc_site_id.nil?
         | 
| 695 704 | 
             
              end
         | 
| 696 705 | 
             
            end
         | 
| 697 706 |  | 
| @@ -703,17 +712,16 @@ end | |
| 703 712 | 
             
            # [changes] Current document changed fields.
         | 
| 704 713 | 
             
            ########################################################################
         | 
| 705 714 | 
             
            def save_journal(operation, changes = {})
         | 
| 706 | 
            -
            #  return unless session[:save_journal]
         | 
| 707 715 | 
             
              if operation == :delete
         | 
| 708 | 
            -
                @record.attributes.each {|k,v| changes[k] = v}
         | 
| 709 | 
            -
            #  elsif operation == :new
         | 
| 710 | 
            -
            #    changes = {}
         | 
| 716 | 
            +
                @record.attributes.each { |k, v| changes[k] = v }
         | 
| 711 717 | 
             
              end
         | 
| 712 | 
            -
             | 
| 713 | 
            -
             | 
| 714 | 
            -
             | 
| 718 | 
            +
              changes.except!('created_at', 'updated_at', 'created_by', 'updated_by')
         | 
| 719 | 
            +
             | 
| 720 | 
            +
              if (operation != :update) || changes.size > 0
         | 
| 721 | 
            +
                # determine site_id
         | 
| 715 722 | 
             
                site_id = @record.site_id if @record.respond_to?('site_id')
         | 
| 716 | 
            -
                site_id = dc_get_site._id if site_id.nil?  | 
| 723 | 
            +
                site_id = dc_get_site._id if site_id.nil? && dc_get_site
         | 
| 724 | 
            +
             | 
| 717 725 | 
             
                DcJournal.create(site_id: site_id,
         | 
| 718 726 | 
             
                                 operation: operation,
         | 
| 719 727 | 
             
                                 user_id: session[:user_id],
         | 
| @@ -731,23 +739,23 @@ end | |
| 731 739 | 
             
            # Returns callback method name or nil if not defined.
         | 
| 732 740 | 
             
            ########################################################################
         | 
| 733 741 | 
             
            def callback_method(key) #:nodoc:
         | 
| 734 | 
            -
              data_key = key.gsub('_','-') #  | 
| 735 | 
            -
               | 
| 742 | 
            +
              data_key = key.gsub('_', '-') # convert _ to -
         | 
| 743 | 
            +
              callback = case
         | 
| 736 744 | 
             
                when params['data'] && params['data'][data_key] then params['data'][data_key]
         | 
| 737 | 
            -
            #  | 
| 745 | 
            +
                # dc_ + key method is present then call it automatically
         | 
| 738 746 | 
             
                when @form['form'][key] then @form['form'][key]
         | 
| 739 747 | 
             
                when respond_to?('dc_' + key) then 'dc_' + key
         | 
| 740 748 | 
             
                when params[data_key] then params[data_key]
         | 
| 741 749 | 
             
                else nil
         | 
| 742 750 | 
             
              end
         | 
| 743 | 
            -
             | 
| 751 | 
            +
             | 
| 744 752 | 
             
              ret = case
         | 
| 745 | 
            -
                when  | 
| 746 | 
            -
                when  | 
| 747 | 
            -
                when  | 
| 748 | 
            -
                  params[:return_to] =  | 
| 753 | 
            +
                when callback.nil? then callback # otherwise there will be errors in next lines
         | 
| 754 | 
            +
                when callback.match('eval ') then callback.sub('eval ','')
         | 
| 755 | 
            +
                when callback.match('return_to ')
         | 
| 756 | 
            +
                  params[:return_to] = callback.sub('return_to ','')
         | 
| 749 757 | 
             
                  return nil
         | 
| 750 | 
            -
                else  | 
| 758 | 
            +
                else callback
         | 
| 751 759 | 
             
              end
         | 
| 752 760 | 
             
              ret
         | 
| 753 761 | 
             
            end
         | 
| @@ -786,16 +794,16 @@ end | |
| 786 794 |  | 
| 787 795 | 
             
            ########################################################################
         | 
| 788 796 | 
             
            # Since tabs have been introduced on form it is a little more complicated
         | 
| 789 | 
            -
            # to  | 
| 797 | 
            +
            # to collect all edit fields on form. This method does it. Subroutine of save_data.
         | 
| 790 798 | 
             
            ########################################################################
         | 
| 791 | 
            -
            def fields_on_form | 
| 799 | 
            +
            def fields_on_form #:nodoc:
         | 
| 792 800 | 
             
              form_fields = []
         | 
| 793 801 | 
             
              if @form['form']['fields']
         | 
| 794 | 
            -
            # read only field elements (key is Integer)
         | 
| 795 | 
            -
                @form['form']['fields'].each {|key,options| form_fields << options if key.class == Integer }
         | 
| 802 | 
            +
                # read only field elements (key is Integer)
         | 
| 803 | 
            +
                @form['form']['fields'].each { |key, options| form_fields << options if key.class == Integer }
         | 
| 796 804 | 
             
              else
         | 
| 797 805 | 
             
                @form['form']['tabs'].keys.each do |tab|
         | 
| 798 | 
            -
                  @form['form']['tabs'][tab].each {|key,options| form_fields << options if key.class == Integer }
         | 
| 806 | 
            +
                  @form['form']['tabs'][tab].each { |key, options| form_fields << options if key.class == Integer }
         | 
| 799 807 | 
             
                end  
         | 
| 800 808 | 
             
              end
         | 
| 801 809 | 
             
              form_fields
         | 
| @@ -808,7 +816,7 @@ end | |
| 808 816 | 
             
            def save_data
         | 
| 809 817 | 
             
              form_fields = fields_on_form()
         | 
| 810 818 | 
             
              return true if form_fields.size == 0
         | 
| 811 | 
            -
             | 
| 819 | 
            +
             | 
| 812 820 | 
             
              form_fields.each do |v|
         | 
| 813 821 | 
             
                session[:form_processing] = v['name'] # for debuging
         | 
| 814 822 | 
             
                next if v['type'].nil? or v['name'].nil? or
         | 
| @@ -821,20 +829,21 @@ def save_data | |
| 821 829 | 
             
                value = DrgcmsFormFields.const_get(v['type'].camelize).get_data(params, v['name'])
         | 
| 822 830 | 
             
                @record.send("#{v['name']}=", value)
         | 
| 823 831 | 
             
              end
         | 
| 824 | 
            -
            #  | 
| 832 | 
            +
              # before_save callback
         | 
| 825 833 | 
             
              if (m = callback_method('before_save') )
         | 
| 826 834 | 
             
                ret = call_callback_method(m)
         | 
| 827 | 
            -
            #  | 
| 835 | 
            +
                # don't save if callback returns false
         | 
| 828 836 | 
             
                return false if ret.class == FalseClass
         | 
| 829 837 | 
             
              end
         | 
| 830 | 
            -
             | 
| 838 | 
            +
             | 
| 839 | 
            +
              # save data
         | 
| 831 840 | 
             
              changes = @record.changes
         | 
| 832 841 | 
             
              update_standards() if changes.size > 0  # update only if there has been some changes
         | 
| 833 842 | 
             
              if (saved = @record.save)
         | 
| 834 843 | 
             
                operation = @record.new_record? ? :new : :update
         | 
| 835 | 
            -
                save_journal(operation,  | 
| 836 | 
            -
            # callback | 
| 837 | 
            -
                if (m = callback_method('after_save') ) then call_callback_method(m) | 
| 844 | 
            +
                save_journal(operation, @record.previous_changes)
         | 
| 845 | 
            +
                # after_save callback
         | 
| 846 | 
            +
                if (m = callback_method('after_save') ) then call_callback_method(m) end
         | 
| 838 847 | 
             
              end
         | 
| 839 848 | 
             
              saved
         | 
| 840 849 | 
             
            end
         | 
| @@ -844,20 +853,18 @@ end | |
| 844 853 | 
             
            # in select_fields and deny_fields
         | 
| 845 854 | 
             
            ########################################################################
         | 
| 846 855 | 
             
            def separated_to_symbols(data)
         | 
| 847 | 
            -
              data.chomp.split(','). | 
| 856 | 
            +
              data.chomp.split(',').map { |e| e.strip.downcase.to_sym }
         | 
| 848 857 | 
             
            end
         | 
| 849 858 |  | 
| 850 859 | 
             
            ########################################################################
         | 
| 851 | 
            -
            # Will process select_fields and deny_fields  | 
| 860 | 
            +
            # Will process only (select_fields) and without (deny_fields) option
         | 
| 852 861 | 
             
            ########################################################################
         | 
| 853 862 | 
             
            def process_select_and_deny_fields
         | 
| 854 | 
            -
               | 
| 855 | 
            -
             | 
| 856 | 
            -
             | 
| 857 | 
            -
             | 
| 858 | 
            -
              if  | 
| 859 | 
            -
                @records = @records.without( separated_to_symbols(@form['result_set']['deny_fields']) )
         | 
| 860 | 
            -
              end
         | 
| 863 | 
            +
              only = @form['result_set']['select_fields'] || @form['result_set']['only']
         | 
| 864 | 
            +
              @records = @records.only( separated_to_symbols(only) ) if only
         | 
| 865 | 
            +
             | 
| 866 | 
            +
              without = @form['result_set']['deny_fields'] || @form['result_set']['without']
         | 
| 867 | 
            +
              @records = @records.without( separated_to_symbols(without) ) if without
         | 
| 861 868 | 
             
            end
         | 
| 862 869 |  | 
| 863 870 | 
             
            ########################################################################
         | 
| @@ -867,18 +874,18 @@ def check_sort_options() #:nodoc: | |
| 867 874 | 
             
              table_name = @tables.first[1]
         | 
| 868 875 | 
             
              old_sort = session[table_name][:sort].to_s
         | 
| 869 876 | 
             
              sort, direction = old_sort.split(' ')
         | 
| 870 | 
            -
             | 
| 877 | 
            +
             | 
| 871 878 | 
             
              if params['sort']
         | 
| 872 879 | 
             
                # reverse sort if same selected
         | 
| 873 880 | 
             
                if params['sort'] == sort
         | 
| 874 881 | 
             
                  direction = (direction == '1') ? '-1' : '1'
         | 
| 875 882 | 
             
                end
         | 
| 876 | 
            -
                direction ||= 1
         | 
| 883 | 
            +
                direction ||= '1'
         | 
| 877 884 | 
             
                sort = params[:sort]
         | 
| 878 885 | 
             
                session[table_name][:sort] = "#{params['sort']} #{direction}"
         | 
| 879 886 | 
             
                session[table_name][:page] = 1
         | 
| 880 887 | 
             
              end
         | 
| 881 | 
            -
              @records.sort( sort => direction.to_i ) if session[table_name][:sort]
         | 
| 888 | 
            +
              @records.sort( sort => direction.to_i ) if session[table_name][:sort] && @records.class == Mongoid::Criteria
         | 
| 882 889 | 
             
              params['sort'] = nil # otherwise there is problem with other links
         | 
| 883 890 | 
             
            end
         | 
| 884 891 |  | 
| @@ -921,45 +928,45 @@ def set_session_filter(table_name) | |
| 921 928 | 
             
              return if params[:filter_oper] && params[:filter_field].blank?
         | 
| 922 929 |  | 
| 923 930 | 
             
              filter_value = if params[:filter_value].nil?
         | 
| 924 | 
            -
            # | 
| 931 | 
            +
                #NIL indicates that no filtering is needed
         | 
| 925 932 | 
             
                '#NIL'
         | 
| 926 933 | 
             
              else     
         | 
| 927 934 | 
             
                if params[:filter_value].class == String and params[:filter_value][0] == '@'
         | 
| 928 | 
            -
            # Internal value. Remove leading @ and evaluate expression
         | 
| 935 | 
            +
                  # Internal value. Remove leading @ and evaluate expression
         | 
| 929 936 | 
             
                  expression = DcInternals.get(params[:filter_value])
         | 
| 930 937 | 
             
                  eval(expression) rescue nil
         | 
| 931 938 | 
             
                else
         | 
| 932 | 
            -
            # No filter when empty | 
| 939 | 
            +
                  # No filter when empty
         | 
| 933 940 | 
             
                  params[:filter_value] == '' ? '#NIL' : params[:filter_value] 
         | 
| 934 941 | 
             
                end
         | 
| 935 942 | 
             
              end
         | 
| 936 | 
            -
            # if filter field parameter is omitted then just set filter value
         | 
| 943 | 
            +
              # if filter field parameter is omitted then just set filter value
         | 
| 937 944 | 
             
              session[table_name][:filter] =
         | 
| 938 945 | 
             
              if params[:filter_field].nil?
         | 
| 939 946 | 
             
                saved = YAML.load(session[table_name][:filter])
         | 
| 940 947 | 
             
                saved['value'] = filter_value
         | 
| 941 948 | 
             
                saved.to_yaml
         | 
| 942 949 | 
             
              else 
         | 
| 943 | 
            -
            #  | 
| 950 | 
            +
                # as field defined. Split name and alternative input field
         | 
| 944 951 | 
             
                field = if params[:filter_field].match(' as ')
         | 
| 945 952 | 
             
                  params[:filter_input] = params[:filter_field].split(' as ').last.strip
         | 
| 946 953 | 
             
                  params[:filter_field].split(' as ').first.strip
         | 
| 947 954 | 
             
                else
         | 
| 948 955 | 
             
                  params[:filter_field]
         | 
| 949 956 | 
             
                end
         | 
| 950 | 
            -
             | 
| 957 | 
            +
             | 
| 951 958 | 
             
                {'field'     => field, 
         | 
| 952 959 | 
             
                 'operation' => params[:filter_oper], 
         | 
| 953 960 | 
             
                 'value'     => filter_value,
         | 
| 954 961 | 
             
                 'input'     => params[:filter_input],
         | 
| 955 962 | 
             
                 'table'     => table_name }.to_yaml
         | 
| 956 963 | 
             
              end
         | 
| 957 | 
            -
            # must be. Otherwise kaminari includes  | 
| 958 | 
            -
             | 
| 959 | 
            -
             | 
| 960 | 
            -
             | 
| 961 | 
            -
             | 
| 962 | 
            -
             | 
| 964 | 
            +
              # must be. Otherwise kaminari includes parames on paging links
         | 
| 965 | 
            +
              params[:filter]        = nil
         | 
| 966 | 
            +
              params[:filter_id]     = nil
         | 
| 967 | 
            +
              params[:filter_oper]   = nil
         | 
| 968 | 
            +
              params[:filter_input]  = nil
         | 
| 969 | 
            +
              params[:filter_field]  = nil
         | 
| 963 970 | 
             
            end
         | 
| 964 971 |  | 
| 965 972 | 
             
            ########################################################################
         | 
| @@ -969,31 +976,27 @@ def check_filter_options() #:nodoc: | |
| 969 976 | 
             
              table_name = @tables.first[1]
         | 
| 970 977 | 
             
              model      = @tables.first[0]
         | 
| 971 978 | 
             
              session[table_name] ||= {}
         | 
| 972 | 
            -
            #  | 
| 979 | 
            +
              # page is set
         | 
| 973 980 | 
             
              session[table_name][:page] = params[:page] if params[:page]
         | 
| 974 | 
            -
            # new filter is applied
         | 
| 981 | 
            +
              # new filter is applied
         | 
| 975 982 | 
             
              if params[:filter]
         | 
| 976 983 | 
             
                set_session_filter(table_name)
         | 
| 977 984 | 
             
                session[table_name][:page] = 1
         | 
| 978 985 | 
             
              end
         | 
| 979 | 
            -
            # if data model has field dc_site_id ensure that only documents which belong to the site are selected.
         | 
| 986 | 
            +
              # if data model has field dc_site_id ensure that only documents which belong to the site are selected.
         | 
| 980 987 | 
             
              site_id = dc_get_site._id if dc_get_site
         | 
| 981 | 
            -
             | 
| 988 | 
            +
             | 
| 989 | 
            +
              # don't filter site if no dc_site_id field or user is ADMIN
         | 
| 982 990 | 
             
              site_id = nil if !model.method_defined?('dc_site_id') or dc_user_can(DcPermission::CAN_ADMIN)
         | 
| 983 991 | 
             
              site_id = nil if session[table_name][:filter].to_s.match('dc_site_id')
         | 
| 984 | 
            -
             | 
| 992 | 
            +
             | 
| 985 993 | 
             
              if @records = DcFilter.get_filter(session[table_name][:filter])
         | 
| 986 994 | 
             
                @records = @records.and(dc_site_id: site_id) if site_id
         | 
| 987 995 | 
             
              else
         | 
| 988 | 
            -
                @records =  | 
| 989 | 
            -
                  model.where(dc_site_id: site_id)
         | 
| 990 | 
            -
                else
         | 
| 991 | 
            -
                  model
         | 
| 992 | 
            -
                end
         | 
| 996 | 
            +
                @records = site_id ? model.where(dc_site_id: site_id) : model
         | 
| 993 997 | 
             
              end
         | 
| 994 | 
            -
            # select only fields or deny fields specified
         | 
| 995 998 | 
             
              process_select_and_deny_fields
         | 
| 996 | 
            -
            # pagination if required
         | 
| 999 | 
            +
              # pagination if required
         | 
| 997 1000 | 
             
              per_page = (@form['result_set']['per_page'] || 30).to_i
         | 
| 998 1001 | 
             
              @records = @records.page(session[table_name][:page]).per(per_page) if per_page > 0
         | 
| 999 1002 | 
             
            end
         | 
| @@ -1002,30 +1005,34 @@ end | |
| 1002 1005 | 
             
            # Process index action for normal collections.
         | 
| 1003 1006 | 
             
            ########################################################################
         | 
| 1004 1007 | 
             
            def process_collections #:nodoc
         | 
| 1005 | 
            -
            # If result_set is not defined on form, then it will fail. :return_to should know where to go
         | 
| 1008 | 
            +
              # If result_set is not defined on form, then it will fail. :return_to should know where to go
         | 
| 1006 1009 | 
             
              if @form['result_set'].nil?
         | 
| 1007 | 
            -
                process_return_to(params[:return_to] || 'reload') | 
| 1010 | 
            +
                process_return_to(params[:return_to] || 'reload')
         | 
| 1008 1011 | 
             
                return true
         | 
| 1009 1012 | 
             
              end
         | 
| 1010 | 
            -
            #  | 
| 1013 | 
            +
              # when result set is evaluated as Rails helper
         | 
| 1014 | 
            +
              @form['result_set']['type'] ||= 'default'
         | 
| 1015 | 
            +
              return unless @form['result_set']['type'] == 'default'
         | 
| 1016 | 
            +
             | 
| 1017 | 
            +
              # for now enable only filtering of top level documents
         | 
| 1011 1018 | 
             
              if @tables.size == 1 
         | 
| 1012 1019 | 
             
                check_filter_options()
         | 
| 1013 1020 | 
             
                check_sort_options()
         | 
| 1014 1021 | 
             
              end  
         | 
| 1015 | 
            -
            # result set is defined by filter method in control object
         | 
| 1022 | 
            +
              # result set is defined by filter method in control object
         | 
| 1016 1023 | 
             
              form_filter = @form['result_set']['filter']
         | 
| 1017 1024 | 
             
              if form_filter
         | 
| 1018 1025 | 
             
                if respond_to?(form_filter)
         | 
| 1019 1026 | 
             
                  @records = send(form_filter)
         | 
| 1020 | 
            -
            # something went wrong. flash[] should have explanation.
         | 
| 1027 | 
            +
                  # something went wrong. flash[] should have explanation.
         | 
| 1021 1028 | 
             
                  if @records.class == FalseClass
         | 
| 1022 1029 | 
             
                    @records = []
         | 
| 1023 1030 | 
             
                    render(action: :index)
         | 
| 1024 1031 | 
             
                    return true
         | 
| 1025 1032 | 
             
                  end
         | 
| 1026 1033 | 
             
                  process_select_and_deny_fields           
         | 
| 1027 | 
            -
            # pagination but only if not already set
         | 
| 1028 | 
            -
                  unless (@form['table'] == 'dc_memory'  | 
| 1034 | 
            +
                  # pagination but only if not already set
         | 
| 1035 | 
            +
                  unless (@form['table'] == 'dc_memory' || @records.options[:limit])
         | 
| 1029 1036 | 
             
                    per_page = (@form['result_set']['per_page'] || 30).to_i
         | 
| 1030 1037 | 
             
                    @records = @records.page(params[:page]).per(per_page) if per_page > 0
         | 
| 1031 1038 | 
             
                  end
         | 
| @@ -1036,10 +1043,10 @@ def process_collections #:nodoc | |
| 1036 1043 | 
             
                if @tables.size > 1 
         | 
| 1037 1044 | 
             
                  rec = @tables.first[0].find(@ids.first)          # top most document.id
         | 
| 1038 1045 | 
             
                  1.upto(@tables.size - 2) { |i| rec = rec.send(@tables[i][1].pluralize).find(@ids[i]) }  # find embedded childrens by ids
         | 
| 1039 | 
            -
            # TO DO. When field name is different then pluralized class name. Not working yet.
         | 
| 1046 | 
            +
                  # TO DO. When field name is different then pluralized class name. Not working yet.
         | 
| 1040 1047 | 
             
                  embedded_field_name = @tables.last[0] ? @tables.last[1].pluralize : @tables.last[1]
         | 
| 1041 1048 | 
             
                  @records = rec.send(embedded_field_name)   # current embedded set
         | 
| 1042 | 
            -
            # sort by order if order field is present in model
         | 
| 1049 | 
            +
                  # sort by order if order field is present in model
         | 
| 1043 1050 | 
             
                  if @tables.last[1].classify.constantize.respond_to?(:order)
         | 
| 1044 1051 | 
             
                    @records = @records.order_by('order asc')
         | 
| 1045 1052 | 
             
                  end
         |