mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 02:41:09 +08:00
FIX: ensure theme variables are unique when adding an upload
This commit is contained in:
@ -3,6 +3,8 @@ import { ajax } from 'discourse/lib/ajax';
|
|||||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||||
|
|
||||||
|
const THEME_FIELD_VARIABLE_TYPE_IDS = [2, 3, 4];
|
||||||
|
|
||||||
export default Ember.Controller.extend(ModalFunctionality, {
|
export default Ember.Controller.extend(ModalFunctionality, {
|
||||||
adminCustomizeThemesShow: Ember.inject.controller(),
|
adminCustomizeThemesShow: Ember.inject.controller(),
|
||||||
|
|
||||||
@ -14,9 +16,11 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||||||
enabled: Em.computed.and('nameValid', 'fileSelected'),
|
enabled: Em.computed.and('nameValid', 'fileSelected'),
|
||||||
disabled: Em.computed.not('enabled'),
|
disabled: Em.computed.not('enabled'),
|
||||||
|
|
||||||
@computed('name')
|
@computed('name', 'adminCustomizeThemesShow.model.theme_fields')
|
||||||
nameValid(name) {
|
nameValid(name, themeFields) {
|
||||||
return name && name.match(/^[a-z_][a-z0-9_-]*$/i);
|
return name &&
|
||||||
|
name.match(/^[a-z_][a-z0-9_-]*$/i) &&
|
||||||
|
!themeFields.some(tf => THEME_FIELD_VARIABLE_TYPE_IDS.includes(tf.type_id) && name === tf.name);
|
||||||
},
|
},
|
||||||
|
|
||||||
@observes('name')
|
@observes('name')
|
||||||
|
@ -3099,7 +3099,7 @@ en:
|
|||||||
add_upload: "Add Upload"
|
add_upload: "Add Upload"
|
||||||
upload_file_tip: "Choose an asset to upload (png, woff2, etc...)"
|
upload_file_tip: "Choose an asset to upload (png, woff2, etc...)"
|
||||||
variable_name: "SCSS var name:"
|
variable_name: "SCSS var name:"
|
||||||
variable_name_invalid: "Invalid variable name. Only alphanumeric allowed. Must start with a letter."
|
variable_name_invalid: "Invalid variable name. Only alphanumeric allowed. Must start with a letter. Must be unique."
|
||||||
upload: "Upload"
|
upload: "Upload"
|
||||||
child_themes_check: "Theme includes other child themes"
|
child_themes_check: "Theme includes other child themes"
|
||||||
css_html: "Custom CSS/HTML"
|
css_html: "Custom CSS/HTML"
|
||||||
|
Reference in New Issue
Block a user