diff --git a/app/controllers/admin/infos_controller.rb b/app/controllers/admin/infos_controller.rb index e79fba7b..d6325ef0 100644 --- a/app/controllers/admin/infos_controller.rb +++ b/app/controllers/admin/infos_controller.rb @@ -40,9 +40,10 @@ class Admin::InfosController < ApplicationController @attribute.update_attributes(params[:info]) @attribute.attribute_fields.each{|t| t.destroy if t["to_delete"] == true} respond_to do |format| - format.html { redirect_to :action => :index } + format.html { redirect_to(edit_admin_info_path(params[:id])) } format.js { render 'admin/attributes/toggle_enable' } end + end def destroy diff --git a/app/models/user/attribute.rb b/app/models/user/attribute.rb index c0970863..a1367c9f 100644 --- a/app/models/user/attribute.rb +++ b/app/models/user/attribute.rb @@ -6,7 +6,9 @@ class Attribute field :key field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - field :title, localize: true + field :title, localize: true + + field :to_search, :type => Boolean, :default => false has_many :attribute_fields, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :attribute_fields, :allow_destroy => true diff --git a/app/models/user/role.rb b/app/models/user/role.rb index e5d8039d..7291c88c 100644 --- a/app/models/user/role.rb +++ b/app/models/user/role.rb @@ -7,8 +7,6 @@ class Role < Attribute field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - field :to_search, :type => Boolean, :default => false - field :title, localize: true has_many :sub_roles, :autosave => true, :dependent => :destroy diff --git a/app/models/user/user.rb b/app/models/user/user.rb index ac32423f..26c8a042 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -72,14 +72,32 @@ class User sub_roles.where(role_id: role.id) end - def disable_sub_role=(var) + def disable_role=(var) var[:id].each do |id,val| # binding.pry if id == '5052c5b22b5c49ab02000004' if (val=="true") + self.roles = self.roles.reject{|t| t.id.to_s==id} + elsif(val=="false") + self.roles << Role.find(id) + end + end + end + + def disable_sub_role=(var) + var[:id].each do |id,val| + + @sr = SubRole.find(id) + + @roid = Role.find(@sr.role_id.to_s) + + # binding.pry if id == '5052c5b22b5c49ab02000004' + + if ( self.roles.include?(@roid) == false or val=="true") self.sub_roles = self.sub_roles.reject{|t| t.id.to_s==id} elsif(val=="false") self.sub_roles << SubRole.find(id) end + end end @@ -189,7 +207,8 @@ class User protected def save_roles - self.roles = self.sub_roles.collect{|t| t.role}.uniq + # self.roles = self.sub_roles.collect{|t| t.role}.uniq + self.roles = self.roles.uniq end diff --git a/app/views/admin/attributes/edit.html.erb b/app/views/admin/attributes/edit.html.erb index a98b4cad..b3cc2bb8 100644 --- a/app/views/admin/attributes/edit.html.erb +++ b/app/views/admin/attributes/edit.html.erb @@ -8,7 +8,7 @@