Skip to content

A platform for community discussion. Free, open, simple.

REFACTOR: admin-customize-colors-show (#16525)

Joffrey JAFFEUX9e2303427c76
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js
index f4b6df17568..160315a5289 100644
--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js
+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js
@@ -3,94 +3,87 @@ import I18n from "I18n";
import bootbox from "bootbox";
import discourseComputed from "discourse-common/utils/decorators";
import { later } from "@ember/runloop";
+import { action } from "@ember/object";
+import { clipboardCopy } from "discourse/lib/utilities";
-export default Controller.extend({
+export default class AdminCustomizeColorsShowController extends Controller {
@discourseComputed("model.colors", "onlyOverridden")
colors(allColors, onlyOverridden) {
if (onlyOverridden) {
- return allColors.filter((color) => color.get("overridden"));
+ return allColors.filterBy("overridden");
} else {
return allColors;
}
- },
+ }
- actions: {
- revert(color) {
- color.revert();
- },
+ @action
+ revert(color) {
+ color.revert();
+ }
- undo(color) {
- color.undo();
- },
+ @action
+ undo(color) {
+ color.undo();
+ }
- copyToClipboard() {
- $(".table.colors").hide();
- let area = $("<textarea id='copy-range'></textarea>");
- $(".table.colors").after(area);
- area.text(this.model.schemeJson());
- let range = document.createRange();
- range.selectNode(area[0]);
- window.getSelection().addRange(range);
- let successful = document.execCommand("copy");
- if (successful) {
- this.set(
- "model.savingStatus",
- I18n.t("admin.customize.copied_to_clipboard")
- );
- } else {
- this.set(
- "model.savingStatus",
- I18n.t("admin.customize.copy_to_clipboard_error")
- );
- }
-
- later(() => {
- this.set("model.savingStatus", null);
- }, 2000);
-
- window.getSelection().removeAllRanges();
+ @action
+ copyToClipboard() {
+ if (clipboardCopy(this.model.schemeJson())) {
+ this.set(
+ "model.savingStatus",
+ I18n.t("admin.customize.copied_to_clipboard")
+ );
+ } else {
+ this.set(
+ "model.savingStatus",
+ I18n.t("admin.customize.copy_to_clipboard_error")
+ );
+ }
- $(".table.colors").show();
- $(area).remove();
- },
+ later(() => {
+ this.set("model.savingStatus", null);
+ }, 2000);
+ }
- copy() {
- const newColorScheme = this.model.copy();
- newColorScheme.set(
- "name",
- I18n.t("admin.customize.colors.copy_name_prefix") +
- " " +
- this.get("model.name")
- );
- newColorScheme.save().then(() => {
- this.allColors.pushObject(newColorScheme);
- this.replaceRoute("adminCustomize.colors.show", newColorScheme);
- });
- },
+ @action
+ copy() {
+ const newColorScheme = this.model.copy();
+ newColorScheme.set(
+ "name",
+ I18n.t("admin.customize.colors.copy_name_prefix") +
+ " " +
+ this.get("model.name")
+ );
+ newColorScheme.save().then(() => {
+ this.allColors.pushObject(newColorScheme);
+ this.replaceRoute("adminCustomize.colors.show", newColorScheme);
+ });
+ }
- save() {
- this.model.save();
- },
+ @action
+ save() {
+ this.model.save();
+ }
- applyUserSelectable() {
- this.model.updateUserSelectable(this.get("model.user_selectable"));
- },
+ @action
+ applyUserSelectable() {
+ this.model.updateUserSelectable(this.get("model.user_selectable"));
+ }
- destroy() {
- const model = this.model;
- return bootbox.confirm(
- I18n.t("admin.customize.colors.delete_confirm"),
- I18n.t("no_value"),
- I18n.t("yes_value"),
- (result) => {
- if (result) {
- model.destroy().then(() => {
- this.allColors.removeObject(model);
- this.replaceRoute("adminCustomize.colors");
- });
- }
+ @action
+ destroy() {
+ return bootbox.confirm(
+ I18n.t("admin.customize.colors.delete_confirm"),
+ I18n.t("no_value"),
+ I18n.t("yes_value"),
+ (result) => {
+ if (result) {
+ this.model.destroy().then(() => {
+ this.allColors.removeObject(this.model);
+ this.replaceRoute("adminCustomize.colors");
+ });
}
- );
- },
- },
-});
+ }
+ );
+ }
+}