Sha256: 4c8f5c9ec1b2fe291e591e906183a485eeeaf03f1ecda8ea65414a30bed126d3

Contents?: true

Size: 1.49 KB

Versions: 19

Compression:

Stored size: 1.49 KB

Contents

module Marty
  class DataGridUserView < DataGridView
    # permissions are handled by #get_records and #get_edit_permissions
    has_marty_permissions read: :any,
                        update: :any

    def configure(c)
      super

      c.attributes =
        [
          :name,
          :created_dt,
        ]
      c.title = I18n.t('data_grid_user_view')
      c.editing = :in_form
    end

    client_class do |c|
      fn = l(<<~JS)
         function(record) {
            var sel = this.getSelectionModel().getSelection()[0];
            var record_id = sel && sel.getId();
            if (!record_id) return;
            this.server.editGrid({record_id: record_id});
         }
      JS

      # inherited perms don't work right, set both fns to the fancy grid edit
      c.do_edit_in_form = fn
      c.do_view_in_form = fn
    end

    def default_bbar
      [:edit_grid]
    end

    def get_records(params)
      cur_perms = Mcfly.whodunnit.roles.map(&:to_sym)
      model.where("permissions->'view'      ?| ARRAY[:roles] OR "\
                  "permissions->'edit_data' ?| ARRAY[:roles] OR "\
                  "permissions->'edit_all'  ?| ARRAY[:roles]",
                  roles: cur_perms).scoping do
        super
      end
    end

    def self.get_edit_permission(permissions)
      cur_perms = current_user_roles.map(&:to_s)
      ['edit_all', 'edit_data', 'view'].detect do |p|
        permissions[p] - cur_perms != permissions[p]
      end
    end
  end
end

DataGridUserView = Marty::DataGridUserView

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
marty-14.3.0 app/components/marty/data_grid_user_view.rb
marty-14.0.0 app/components/marty/data_grid_user_view.rb
marty-13.0.2 app/components/marty/data_grid_user_view.rb
marty-11.0.0 app/components/marty/data_grid_user_view.rb
marty-10.0.3 app/components/marty/data_grid_user_view.rb
marty-10.0.2 app/components/marty/data_grid_user_view.rb
marty-10.0.0 app/components/marty/data_grid_user_view.rb
marty-9.5.1 app/components/marty/data_grid_user_view.rb
marty-9.5.0 app/components/marty/data_grid_user_view.rb
marty-9.3.3 app/components/marty/data_grid_user_view.rb
marty-9.3.2 app/components/marty/data_grid_user_view.rb
marty-9.3.0 app/components/marty/data_grid_user_view.rb
marty-8.5.0 app/components/marty/data_grid_user_view.rb
marty-8.4.1 app/components/marty/data_grid_user_view.rb
marty-8.3.1 app/components/marty/data_grid_user_view.rb
marty-8.2.0 app/components/marty/data_grid_user_view.rb
marty-8.0.0 app/components/marty/data_grid_user_view.rb
marty-6.1.0 app/components/marty/data_grid_user_view.rb
marty-5.2.0 app/components/marty/data_grid_user_view.rb