From 1a29fd0797cd4f023bc48ee504a8aef4f555733c Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Thu, 19 Oct 2017 18:19:09 -0200 Subject: [PATCH] Merge pull request #8543 from RocketChat/hotfix/color-reset [FIX] Color reset when default value editor is different --- .../server/publications/settings.js | 2 +- packages/rocketchat-ui-admin/client/admin.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/rocketchat-lib/server/publications/settings.js b/packages/rocketchat-lib/server/publications/settings.js index 3fb7be96702..cbc39fb4b8f 100644 --- a/packages/rocketchat-lib/server/publications/settings.js +++ b/packages/rocketchat-lib/server/publications/settings.js @@ -58,7 +58,7 @@ Meteor.methods({ RocketChat.models.Settings.cache.on('changed', function(type, setting) { if (setting['public'] === true) { - RocketChat.Notifications.notifyAllInThisInstance('public-settings-changed', type, _.pick(setting, '_id', 'value', 'properties')); + RocketChat.Notifications.notifyAllInThisInstance('public-settings-changed', type, _.pick(setting, '_id', 'value', 'editor', 'properties')); } return RocketChat.Notifications.notifyLoggedInThisInstance('private-settings-changed', type, setting); }); diff --git a/packages/rocketchat-ui-admin/client/admin.js b/packages/rocketchat-ui-admin/client/admin.js index fa88dc1ce79..b5a67575899 100644 --- a/packages/rocketchat-ui-admin/client/admin.js +++ b/packages/rocketchat-ui-admin/client/admin.js @@ -20,11 +20,9 @@ const setFieldValue = function(settingId, value, type, editor) { input.next()[0].CodeMirror.setValue(value); break; case 'color': + editor = value && value[0] === '#' ? 'color' : 'expression'; input.parents('.horizontal').find('select[name="color-editor"]').val(editor).change(); input.val(value).change(); - if (editor === 'color') { - new jscolor(input); //eslint-disable-line - } break; case 'roomPick': const selectedRooms = Template.instance().selectedRooms.get(); @@ -341,6 +339,9 @@ Template.admin.events({ break; case 'boolean': value = value === '1'; + break; + case 'color': + $(e.target).siblings('.colorpicker-swatch').css('background-color', value); } TempSettings.update({ _id: this._id @@ -354,6 +355,7 @@ Template.admin.events({ 'change select[name=color-editor]'(e) { const value = _.trim($(e.target).val()); TempSettings.update({ _id: this._id }, { $set: { editor: value }}); + RocketChat.settings.collectionPrivate.update({ _id: this._id }, { $set: { editor: value }}); }, 'click .submit .discard'() { const group = FlowRouter.getParam('group'); @@ -566,14 +568,16 @@ Template.admin.onRendered(function() { SideNav.openFlex(); }); Tracker.autorun(function() { - const hasColor = TempSettings.findOne({ + const hasColor = TempSettings.find({ group: FlowRouter.getParam('group'), type: 'color' - }, { fields: { _id: 1 }}); + }, { fields: { _id: 1, editor: 1 }}).fetch().length; if (hasColor) { Meteor.setTimeout(function() { $('.colorpicker-input').each(function(index, el) { - new jscolor(el); //eslint-disable-line + if (!el._jscLinkedInstance) { + new jscolor(el); //eslint-disable-line + } }); }, 400); }