mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 07:55:44 +08:00
DEV: introduces prettier for es6 files
This commit is contained in:
@ -1,101 +1,142 @@
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
|
||||
const THEME_FIELD_VARIABLE_TYPE_IDS = [2, 3, 4];
|
||||
|
||||
const SCSS_VARIABLE_NAMES = [
|
||||
// common/foundation/colors.scss
|
||||
"primary", "secondary", "tertiary", "quaternary", "header_background",
|
||||
"header_primary", "highlight", "danger", "success", "love",
|
||||
"primary",
|
||||
"secondary",
|
||||
"tertiary",
|
||||
"quaternary",
|
||||
"header_background",
|
||||
"header_primary",
|
||||
"highlight",
|
||||
"danger",
|
||||
"success",
|
||||
"love",
|
||||
// common/foundation/math.scss
|
||||
"E", "PI", "LN2", "SQRT2",
|
||||
"E",
|
||||
"PI",
|
||||
"LN2",
|
||||
"SQRT2",
|
||||
// common/foundation/variables.scss
|
||||
"small-width", "medium-width", "large-width",
|
||||
"google", "instagram", "facebook", "cas", "twitter", "yahoo", "github",
|
||||
"base-font-size", "base-line-height", "base-font-family",
|
||||
"primary-low", "primary-medium",
|
||||
"secondary-low", "secondary-medium",
|
||||
"tertiary-low", "quaternary-low",
|
||||
"highlight-low", "highlight-medium",
|
||||
"danger-low", "danger-medium",
|
||||
"success-low", "love-low",
|
||||
"small-width",
|
||||
"medium-width",
|
||||
"large-width",
|
||||
"google",
|
||||
"instagram",
|
||||
"facebook",
|
||||
"cas",
|
||||
"twitter",
|
||||
"yahoo",
|
||||
"github",
|
||||
"base-font-size",
|
||||
"base-line-height",
|
||||
"base-font-family",
|
||||
"primary-low",
|
||||
"primary-medium",
|
||||
"secondary-low",
|
||||
"secondary-medium",
|
||||
"tertiary-low",
|
||||
"quaternary-low",
|
||||
"highlight-low",
|
||||
"highlight-medium",
|
||||
"danger-low",
|
||||
"danger-medium",
|
||||
"success-low",
|
||||
"love-low"
|
||||
];
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
adminCustomizeThemesShow: Ember.inject.controller(),
|
||||
|
||||
uploadUrl: '/admin/themes/upload_asset',
|
||||
uploadUrl: "/admin/themes/upload_asset",
|
||||
|
||||
onShow() {
|
||||
this.set('name', null);
|
||||
this.set('fileSelected', false);
|
||||
this.set("name", null);
|
||||
this.set("fileSelected", false);
|
||||
},
|
||||
|
||||
enabled: Em.computed.and('nameValid', 'fileSelected'),
|
||||
disabled: Em.computed.not('enabled'),
|
||||
enabled: Em.computed.and("nameValid", "fileSelected"),
|
||||
disabled: Em.computed.not("enabled"),
|
||||
|
||||
@computed('name', 'adminCustomizeThemesShow.model.theme_fields')
|
||||
@computed("name", "adminCustomizeThemesShow.model.theme_fields")
|
||||
errorMessage(name, themeFields) {
|
||||
if (name) {
|
||||
if (!name.match(/^[a-z_][a-z0-9_-]*$/i)) {
|
||||
return I18n.t("admin.customize.theme.variable_name_error.invalid_syntax");
|
||||
return I18n.t(
|
||||
"admin.customize.theme.variable_name_error.invalid_syntax"
|
||||
);
|
||||
} else if (SCSS_VARIABLE_NAMES.includes(name.toLowerCase())) {
|
||||
return I18n.t("admin.customize.theme.variable_name_error.no_overwrite");
|
||||
} else if (themeFields.some(tf => THEME_FIELD_VARIABLE_TYPE_IDS.includes(tf.type_id) && name === tf.name)) {
|
||||
return I18n.t("admin.customize.theme.variable_name_error.must_be_unique");
|
||||
} else if (
|
||||
themeFields.some(
|
||||
tf =>
|
||||
THEME_FIELD_VARIABLE_TYPE_IDS.includes(tf.type_id) &&
|
||||
name === tf.name
|
||||
)
|
||||
) {
|
||||
return I18n.t(
|
||||
"admin.customize.theme.variable_name_error.must_be_unique"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
@computed('errorMessage')
|
||||
@computed("errorMessage")
|
||||
nameValid(errorMessage) {
|
||||
return null === errorMessage;
|
||||
},
|
||||
|
||||
@observes('name')
|
||||
@observes("name")
|
||||
uploadChanged() {
|
||||
const file = $('#file-input')[0];
|
||||
this.set('fileSelected', file && file.files[0]);
|
||||
const file = $("#file-input")[0];
|
||||
this.set("fileSelected", file && file.files[0]);
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
||||
updateName() {
|
||||
let name = this.get('name');
|
||||
let name = this.get("name");
|
||||
if (Em.isEmpty(name)) {
|
||||
name = $('#file-input')[0].files[0].name;
|
||||
this.set('name', name.split(".")[0]);
|
||||
name = $("#file-input")[0].files[0].name;
|
||||
this.set("name", name.split(".")[0]);
|
||||
}
|
||||
this.uploadChanged();
|
||||
},
|
||||
|
||||
upload() {
|
||||
const file = $('#file-input')[0].files[0];
|
||||
const file = $("#file-input")[0].files[0];
|
||||
|
||||
const options = {
|
||||
type: 'POST',
|
||||
type: "POST",
|
||||
processData: false,
|
||||
contentType: false,
|
||||
data: new FormData()
|
||||
};
|
||||
|
||||
options.data.append('file', file);
|
||||
options.data.append("file", file);
|
||||
|
||||
ajax(this.get('uploadUrl'), options).then(result => {
|
||||
const upload = {
|
||||
upload_id: result.upload_id,
|
||||
name: this.get('name'),
|
||||
original_filename: file.name
|
||||
};
|
||||
this.get('adminCustomizeThemesShow').send('addUpload', upload);
|
||||
this.send('closeModal');
|
||||
}).catch(e => {
|
||||
popupAjaxError(e);
|
||||
});
|
||||
ajax(this.get("uploadUrl"), options)
|
||||
.then(result => {
|
||||
const upload = {
|
||||
upload_id: result.upload_id,
|
||||
name: this.get("name"),
|
||||
original_filename: file.name
|
||||
};
|
||||
this.get("adminCustomizeThemesShow").send("addUpload", upload);
|
||||
this.send("closeModal");
|
||||
})
|
||||
.catch(e => {
|
||||
popupAjaxError(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user