From 0e95df4fe1f02d403686f857e944d4120d76e3f8 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 12 Jul 2015 04:12:27 +0200 Subject: [PATCH] Added setting preferences options. --- .../app/controllers/_settings/area.js.coffee | 24 ++++++++++----- app/models/setting.rb | 1 + db/migrate/20150712000002_update_setting2.rb | 30 +++++++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20150712000002_update_setting2.rb diff --git a/app/assets/javascripts/app/controllers/_settings/area.js.coffee b/app/assets/javascripts/app/controllers/_settings/area.js.coffee index 637a74950..892e5b973 100644 --- a/app/assets/javascripts/app/controllers/_settings/area.js.coffee +++ b/app/assets/javascripts/app/controllers/_settings/area.js.coffee @@ -19,11 +19,19 @@ class App.SettingsArea extends App.Controller ) render: => + + # serach area settings settings = App.Setting.search( filter: area: @area ) + # sort by prio + settings = _.sortBy( settings, (setting) -> + return if !setting.preferences + setting.preferences.prio + ) + html = $('
') for setting in settings if setting.name is 'product_logo' @@ -101,12 +109,16 @@ class App.SettingsAreaItem extends App.Controller msg: App.i18n.translateContent('Update successful!') timeout: 2000 } - ui.render() - App.Event.trigger( 'ui:rerender' ) + # rerender ui || get new collections and session data + if @setting.preferences - # login check - App.Auth.loginCheck() + if @setting.preferences.render + ui.render() + App.Event.trigger( 'ui:rerender' ) + + if @setting.preferences.session_check + App.Auth.loginCheck() fail: => ui.formEnable(e) ) @@ -174,16 +186,12 @@ class App.SettingsAreaLogo extends App.Controller success: (data, status, xhr) => @formEnable(e) if data.result is 'ok' - @formEnable(e) - App.Event.trigger 'notify', { type: 'success' msg: App.i18n.translateContent('Update successful!') timeout: 2000 } - @render() - App.Event.trigger( 'ui:rerender' ) for key, value of data.settings App.Config.set( key, value ) else diff --git a/app/models/setting.rb b/app/models/setting.rb index 5198eb52c..fb82da162 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -4,6 +4,7 @@ class Setting < ApplicationModel store :options store :state store :state_initial + store :preferences before_create :state_check, :set_initial before_update :state_check after_create :delete_cache diff --git a/db/migrate/20150712000002_update_setting2.rb b/db/migrate/20150712000002_update_setting2.rb new file mode 100644 index 000000000..56ae6d2d3 --- /dev/null +++ b/db/migrate/20150712000002_update_setting2.rb @@ -0,0 +1,30 @@ +class UpdateSetting2 < ActiveRecord::Migration + def up + + # add preferences + add_column :settings, :preferences, :string, limit: 2000, null: true + + # update settings + %w(product_name ticket_hook chat).each {|setting_name| + setting = Setting.find_by(name: setting_name) + next if !setting + setting.preferences[:render] = true + setting.save + } + %w(product_name).each {|setting_name| + setting = Setting.find_by(name: setting_name) + next if !setting + setting.preferences[:session_check] = true + setting.save + } + setting = Setting.find_by(name: 'product_name') + setting.preferences[:prio] = 1 + setting.save + setting = Setting.find_by(name: 'organization') + setting.preferences[:prio] = 2 + setting.save + setting = Setting.find_by(name: 'product_logo') + setting.preferences[:prio] = 3 + setting.save + end +end