From 74ed72e82528c28579ae8d72fa17a543b4a930da Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Thu, 21 Feb 2019 09:54:54 -0500 Subject: [PATCH] DEV: Remove `d-checkbox` component Replaces the last occurrence of `d-checkbox` with a regular input element. Includes a minor refactor of admin site text search. --- .../controllers/admin-site-text-index.js.es6 | 15 ++++++----- .../admin/templates/site-text-index.hbs | 5 +++- .../discourse/components/d-checkbox.js.es6 | 25 ------------------- .../templates/components/d-checkbox.hbs | 2 -- 4 files changed, 13 insertions(+), 34 deletions(-) delete mode 100644 app/assets/javascripts/discourse/components/d-checkbox.js.es6 delete mode 100644 app/assets/javascripts/discourse/templates/components/d-checkbox.hbs diff --git a/app/assets/javascripts/admin/controllers/admin-site-text-index.js.es6 b/app/assets/javascripts/admin/controllers/admin-site-text-index.js.es6 index a62c74001ac..7ef54696491 100644 --- a/app/assets/javascripts/admin/controllers/admin-site-text-index.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-site-text-index.js.es6 @@ -1,5 +1,4 @@ let lastSearch; -let lastOverridden; export default Ember.Controller.extend({ searching: false, @@ -8,7 +7,7 @@ export default Ember.Controller.extend({ queryParams: ["q", "overridden"], q: null, - overridden: null, + overridden: false, _performSearch() { this.store @@ -24,14 +23,18 @@ export default Ember.Controller.extend({ this.transitionToRoute("adminSiteText.edit", siteText.get("id")); }, - search(overridden) { - if (typeof overridden === "boolean") this.set("overridden", overridden); + toggleOverridden() { + this.toggleProperty("overridden"); + this.set("searching", true); + Ember.run.debounce(this, this._performSearch, 400); + }, + + search() { const q = this.get("q"); - if (q !== lastSearch || overridden !== lastOverridden) { + if (q !== lastSearch) { this.set("searching", true); Ember.run.debounce(this, this._performSearch, 400); lastSearch = q; - lastOverridden = overridden; } } } diff --git a/app/assets/javascripts/admin/templates/site-text-index.hbs b/app/assets/javascripts/admin/templates/site-text-index.hbs index c84233348f0..78f2c1735e7 100644 --- a/app/assets/javascripts/admin/templates/site-text-index.hbs +++ b/app/assets/javascripts/admin/templates/site-text-index.hbs @@ -8,7 +8,10 @@ key-up=(action "search")}}
- {{d-checkbox label="admin.site_text.show_overriden" checked=overridden change=(action "search")}} +
diff --git a/app/assets/javascripts/discourse/components/d-checkbox.js.es6 b/app/assets/javascripts/discourse/components/d-checkbox.js.es6 deleted file mode 100644 index 7bbb682582e..00000000000 --- a/app/assets/javascripts/discourse/components/d-checkbox.js.es6 +++ /dev/null @@ -1,25 +0,0 @@ -import { on } from "ember-addons/ember-computed-decorators"; - -export default Ember.Component.extend({ - tagName: "label", - - @on("didInsertElement") - _init() { - const checked = this.get("checked"); - if (checked && checked !== "false") { - this.$("input").prop("checked", true); - } - - // In Ember 13.3 we can use action on the checkbox `{{input}}` but not in 1.11 - this.$("input").on("click.d-checkbox", () => { - Ember.run.scheduleOnce("afterRender", () => - this.change(this.$("input").prop("checked")) - ); - }); - }, - - @on("willDestroyElement") - _clear() { - this.$("input").off("click.d-checkbox"); - } -}); diff --git a/app/assets/javascripts/discourse/templates/components/d-checkbox.hbs b/app/assets/javascripts/discourse/templates/components/d-checkbox.hbs deleted file mode 100644 index 8ec5979a1fd..00000000000 --- a/app/assets/javascripts/discourse/templates/components/d-checkbox.hbs +++ /dev/null @@ -1,2 +0,0 @@ - -{{i18n label}}