Skip to content
Snippets Groups Projects
Commit 2ed257fc authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Add option to disable setting based in other setting and another improvements

parent ec5737af
No related branches found
No related tags found
No related merge requests found
RocketChat.settings._sorter = 0
###
# Add a setting
# @param {String} _id
......@@ -14,6 +16,7 @@ RocketChat.settings.add = (_id, value, options = {}) ->
options.valueSource = 'packageValue'
options.ts = new Date
options.hidden = false
options.sorter ?= RocketChat.settings._sorter++
if process?.env?[_id]?
value = process.env[_id]
......
......@@ -14,32 +14,38 @@ RocketChat.settings.add 'Accounts_Registration_AuthenticationServices_Enabled',
RocketChat.settings.add 'Accounts_PasswordReset', true, { type: 'boolean', group: 'Accounts', public: true, section: 'Registration' }
RocketChat.settings.add 'Accounts_AvatarStoreType', 'GridFS', { type: 'string', group: 'Accounts', section: 'Avatar' }
RocketChat.settings.add 'Accounts_AvatarStorePath', '', { type: 'string', group: 'Accounts', section: 'Avatar' }
RocketChat.settings.add 'Accounts_AvatarResize', true, { type: 'boolean', group: 'Accounts', section: 'Avatar' }
RocketChat.settings.add 'Accounts_AvatarSize', 200, { type: 'int', group: 'Accounts', section: 'Avatar' }
RocketChat.settings.add 'Accounts_AvatarSize', 200, { type: 'int', group: 'Accounts', section: 'Avatar', enableQuery: {_id: 'Accounts_AvatarResize', value: true} }
RocketChat.settings.add 'Accounts_AvatarStoreType', 'GridFS', { type: 'select', group: 'Accounts', section: 'Avatar', values: [ { key: 'GridFS', i18nLabel: 'GridFS' }, { key: 'FileSystem', i18nLabel: 'FileSystem' } ] }
RocketChat.settings.add 'Accounts_AvatarStorePath', '', { type: 'string', group: 'Accounts', section: 'Avatar', enableQuery: {_id: 'Accounts_AvatarStoreType', value: 'FileSystem'} }
RocketChat.settings.add 'Accounts_OAuth_Facebook', false, { type: 'boolean', group: 'Accounts', section: 'Facebook', public: true }
RocketChat.settings.add 'Accounts_OAuth_Facebook_id', '', { type: 'string', group: 'Accounts', section: 'Facebook' }
RocketChat.settings.add 'Accounts_OAuth_Facebook_secret', '', { type: 'string', group: 'Accounts', section: 'Facebook' }
RocketChat.settings.add 'Accounts_OAuth_Facebook_id', '', { type: 'string', group: 'Accounts', section: 'Facebook', enableQuery: {_id: 'Accounts_OAuth_Facebook', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Facebook_secret', '', { type: 'string', group: 'Accounts', section: 'Facebook', enableQuery: {_id: 'Accounts_OAuth_Facebook', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Google', false, { type: 'boolean', group: 'Accounts', section: 'Google', public: true }
RocketChat.settings.add 'Accounts_OAuth_Google_id', '', { type: 'string', group: 'Accounts', section: 'Google' }
RocketChat.settings.add 'Accounts_OAuth_Google_secret', '', { type: 'string', group: 'Accounts', section: 'Google' }
RocketChat.settings.add 'Accounts_OAuth_Google_id', '', { type: 'string', group: 'Accounts', section: 'Google', enableQuery: {_id: 'Accounts_OAuth_Google', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Google_secret', '', { type: 'string', group: 'Accounts', section: 'Google', enableQuery: {_id: 'Accounts_OAuth_Google', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Github', false, { type: 'boolean', group: 'Accounts', section: 'Github', public: true }
RocketChat.settings.add 'Accounts_OAuth_Github_id', '', { type: 'string', group: 'Accounts', section: 'Github' }
RocketChat.settings.add 'Accounts_OAuth_Github_secret', '', { type: 'string', group: 'Accounts', section: 'Github' }
RocketChat.settings.add 'Accounts_OAuth_Github_id', '', { type: 'string', group: 'Accounts', section: 'Github', enableQuery: {_id: 'Accounts_OAuth_Github', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Github_secret', '', { type: 'string', group: 'Accounts', section: 'Github', enableQuery: {_id: 'Accounts_OAuth_Github', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Gitlab', false, { type: 'boolean', group: 'Accounts', section: 'Gitlab', public: true }
RocketChat.settings.add 'Accounts_OAuth_Gitlab_id', '', { type: 'string', group: 'Accounts', section: 'Gitlab' }
RocketChat.settings.add 'Accounts_OAuth_Gitlab_secret', '', { type: 'string', group: 'Accounts', section: 'Gitlab' }
RocketChat.settings.add 'Accounts_OAuth_Gitlab_id', '', { type: 'string', group: 'Accounts', section: 'Gitlab', enableQuery: {_id: 'Accounts_OAuth_Gitlab', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Gitlab_secret', '', { type: 'string', group: 'Accounts', section: 'Gitlab', enableQuery: {_id: 'Accounts_OAuth_Gitlab', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Linkedin', false, { type: 'boolean', group: 'Accounts', section: 'Linkedin', public: true }
RocketChat.settings.add 'Accounts_OAuth_Linkedin_id', '', { type: 'string', group: 'Accounts', section: 'Linkedin' }
RocketChat.settings.add 'Accounts_OAuth_Linkedin_secret', '', { type: 'string', group: 'Accounts', section: 'Linkedin' }
RocketChat.settings.add 'Accounts_OAuth_Linkedin_id', '', { type: 'string', group: 'Accounts', section: 'Linkedin', enableQuery: {_id: 'Accounts_OAuth_Linkedin', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Linkedin_secret', '', { type: 'string', group: 'Accounts', section: 'Linkedin', enableQuery: {_id: 'Accounts_OAuth_Linkedin', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Meteor', false, { type: 'boolean', group: 'Accounts', section: 'Meteor', public: true }
RocketChat.settings.add 'Accounts_OAuth_Meteor_id', '', { type: 'string', group: 'Accounts', section: 'Meteor' }
RocketChat.settings.add 'Accounts_OAuth_Meteor_secret', '', { type: 'string', group: 'Accounts', section: 'Meteor' }
RocketChat.settings.add 'Accounts_OAuth_Meteor_id', '', { type: 'string', group: 'Accounts', section: 'Meteor', enableQuery: {_id: 'Accounts_OAuth_Meteor', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Meteor_secret', '', { type: 'string', group: 'Accounts', section: 'Meteor', enableQuery: {_id: 'Accounts_OAuth_Meteor', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Twitter', false, { type: 'boolean', group: 'Accounts', section: 'Twitter', public: true }
RocketChat.settings.add 'Accounts_OAuth_Twitter_id', '', { type: 'string', group: 'Accounts', section: 'Twitter' }
RocketChat.settings.add 'Accounts_OAuth_Twitter_secret', '', { type: 'string', group: 'Accounts', section: 'Twitter' }
RocketChat.settings.add 'Accounts_OAuth_Twitter_id', '', { type: 'string', group: 'Accounts', section: 'Twitter', enableQuery: {_id: 'Accounts_OAuth_Twitter', value: true} }
RocketChat.settings.add 'Accounts_OAuth_Twitter_secret', '', { type: 'string', group: 'Accounts', section: 'Twitter', enableQuery: {_id: 'Accounts_OAuth_Twitter', value: true} }
RocketChat.settings.add 'Accounts_AllowUserProfileChange', true, { type: 'boolean', group: 'Accounts', section: 'General', public: true }
RocketChat.settings.add 'Accounts_AllowUserAvatarChange', true, { type: 'boolean', group: 'Accounts', section: 'General', public: true }
......
......@@ -1797,6 +1797,12 @@ a.github-fork {
padding-top: 0;
}
&.setting-changed {
> label {
color: #627CFF
}
}
input {
color: #444;
}
......
@TempSettings = new Meteor.Collection null
@Settings.find().observe
added: (data) ->
TempSettings.insert data
changed: (data) ->
TempSettings.update data._id, data
removed: (data) ->
TempSettings.remove data._id
Template.admin.helpers
group: ->
group = FlowRouter.getParam('group')
group ?= Settings.findOne({ type: 'group' })?._id
return Settings.findOne { _id: group, type: 'group' }
group ?= TempSettings.findOne({ type: 'group' })?._id
return TempSettings.findOne { _id: group, type: 'group' }
sections: ->
group = FlowRouter.getParam('group')
group ?= Settings.findOne({ type: 'group' })?._id
settings = Settings.find({ group: group }, {sort: {section: 1, i18nLabel: 1}}).fetch()
group ?= TempSettings.findOne({ type: 'group' })?._id
settings = TempSettings.find({ group: group }, {sort: {section: 1, sort: 1, i18nLabel: 1}}).fetch()
sections = {}
for setting in settings
sections[setting.section or ''] ?= []
......@@ -20,6 +31,30 @@ Template.admin.helpers
return sectionsArray
isDisabled: ->
if not @enableQuery?
return {}
return if TempSettings.findOne(@enableQuery)? then {} else {disabled: 'disabled'}
hasChanges: (section) ->
group = FlowRouter.getParam('group')
query =
group: group
changed: true
if section?
if section is ''
query.$or = [
{section: ''}
{section: {$exists: false}}
]
else
query.section = section
return TempSettings.find(query).count() > 0
flexOpened: ->
return 'opened' if RocketChat.TabBar.isFlexOpen()
arrowPosition: ->
......@@ -44,28 +79,39 @@ Template.admin.helpers
return Random.id()
Template.admin.events
"change .input-monitor": (e, t) ->
value = _.trim $(e.target).val()
switch @type
when 'int'
value = parseInt(value)
when 'boolean'
value = value is "1"
TempSettings.update {_id: @_id},
$set:
value: value
changed: Settings.findOne(@_id).value isnt value
"click .submit .save": (e, t) ->
group = FlowRouter.getParam('group')
settings = Settings.find({ group: group }).fetch()
updateSettings = []
for setting in settings
value = null
if setting.type is 'string'
value = _.trim(t.$("[name=#{setting._id}]").val())
else if setting.type is 'int'
value = parseInt(_.trim(t.$("[name=#{setting._id}]").val()))
else if setting.type is 'boolean' and t.$("[name=#{setting._id}]:checked").length
value = if t.$("[name=#{setting._id}]:checked").val() is "1" then true else false
else if setting.type is 'color'
value = _.trim(t.$("[name=#{setting._id}]").val())
else if setting.type is 'select'
value = t.$("[name=#{setting._id}]").val()
if value?
updateSettings.push { _id: setting._id, value: value }
if not _.isEmpty updateSettings
RocketChat.settings.batchSet updateSettings, (err, success) ->
query =
group: group
changed: true
if @section is ''
query.$or = [
{section: ''}
{section: {$exists: false}}
]
else
query.section = @section
settings = TempSettings.find(query, {fields: {_id: 1, value: 1}}).fetch()
if not _.isEmpty settings
RocketChat.settings.batchSet settings, (err, success) ->
return toastr.error TAPi18n.__ 'Error_updating_settings' if err
toastr.success TAPi18n.__ 'Settings_updated'
......
......@@ -42,28 +42,28 @@
{{/if}}
{{/if}}
{{#each settings}}
<div class="input-line double-col">
<div class="input-line double-col {{#if changed}}setting-changed{{/if}}">
<label>{{label}}</label>
<div>
{{#if $eq type 'string'}}
{{#if multiline}}
<textarea name="{{_id}}" rows="4" style="height: auto">{{value}}</textarea>
<textarea class="input-monitor" name="{{_id}}" rows="4" style="height: auto" {{isDisabled}}>{{value}}</textarea>
{{else}}
<input type="text" name="{{_id}}" value="{{value}}" placeholder="{{placeholder}}" />
<input class="input-monitor" type="text" name="{{_id}}" value="{{value}}" placeholder="{{placeholder}}" {{isDisabled}}/>
{{/if}}
{{/if}}
{{#if $eq type 'int'}}
<input type="number" name="{{_id}}" value="{{value}}" placeholder="{{placeholder}}" />
<input class="input-monitor" type="number" name="{{_id}}" value="{{value}}" placeholder="{{placeholder}}" {{isDisabled}}/>
{{/if}}
{{#if $eq type 'boolean'}}
<label><input type="radio" name="{{_id}}" value="1" checked="{{$eq value true}}" /> {{_ "True"}}</label>
<label><input type="radio" name="{{_id}}" value="0" checked="{{$eq value false}}" /> {{_ "False"}}</label>
<label><input class="input-monitor" type="radio" name="{{_id}}" value="1" checked="{{$eq value true}}" {{isDisabled}}/> {{_ "True"}}</label>
<label><input class="input-monitor" type="radio" name="{{_id}}" value="0" checked="{{$eq value false}}" {{isDisabled}}/> {{_ "False"}}</label>
{{/if}}
{{#if $eq type 'select'}}
<select name="{{_id}}">
<select class="input-monitor" name="{{_id}}" {{isDisabled}}>
{{#each values}}
<option value="{{key}}" selected="{{selectedOption ../_id key}}">{{_ i18nLabel}}</option>
{{/each}}
......@@ -71,11 +71,11 @@
{{/if}}
{{#if $eq type 'color'}}
<input type="text" class="minicolors" name="{{_id}}" value="{{value}}" />
<input class="input-monitor minicolors" type="text" name="{{_id}}" value="{{value}}" {{isDisabled}}/>
{{/if}}
{{#if $eq type 'action'}}
<button type="button" class="button primary action" data-setting="{{_id}}" data-action="{{value}}">{{_ actionText}}</button>
<button type="button" class="button primary action" data-setting="{{_id}}" data-action="{{value}}" {{isDisabled}}>{{_ actionText}}</button>
{{/if}}
{{#if $eq type 'asset'}}
......@@ -115,6 +115,12 @@
</div>
{{/if}}
{{/if}}
{{#if hasChanges section}}
<div class="submit">
<button class="button save"><i class="icon-send"></i><span>{{_ "Save_changes"}}</span></button>
</div>
{{/if}}
</div>
</div>
{{/each}}
......@@ -123,7 +129,6 @@
{{#if $eq group._id 'Accounts'}}
<button class="button secondary add-custom-oauth"><span>{{_ "Add_custom_oauth"}}</span></button>
{{/if}}
<button class="button save"><i class="icon-send"></i><span>{{_ "Save_changes"}}</span></button>
</div>
</div>
{{/unless}}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment