FEATURE: Add per-ad visibility settings for anons and logged-in users (#168)
This commit adds 2 new settings to house ads to control whether an ad is shown to anonymous users and logged in users. Existing ads that were created before this feature will default to true for both settings; i.e., they will remain to be visible to both anonymous and logged-in users, but it will be possible to change the settings. Turning off both settings will effectively disable the ad completely.
This commit is contained in:
@@ -14,7 +14,20 @@ export default Controller.extend(bufferedProperty("model"), {
|
||||
|
||||
nameDirty: propertyNotEqual("buffered.name", "model.name"),
|
||||
htmlDirty: propertyNotEqual("buffered.html", "model.html"),
|
||||
dirty: or("nameDirty", "htmlDirty"),
|
||||
visibleToAnonsDirty: propertyNotEqual(
|
||||
"buffered.visible_to_anons",
|
||||
"model.visible_to_anons"
|
||||
),
|
||||
visibleToLoggedInDirty: propertyNotEqual(
|
||||
"buffered.visible_to_logged_in_users",
|
||||
"model.visible_to_logged_in_users"
|
||||
),
|
||||
dirty: or(
|
||||
"nameDirty",
|
||||
"htmlDirty",
|
||||
"visibleToLoggedInDirty",
|
||||
"visibleToAnonsDirty"
|
||||
),
|
||||
disableSave: not("dirty"),
|
||||
|
||||
actions: {
|
||||
@@ -34,6 +47,10 @@ export default Controller.extend(bufferedProperty("model"), {
|
||||
}
|
||||
data.name = buffered.get("name");
|
||||
data.html = buffered.get("html");
|
||||
data.visible_to_logged_in_users = buffered.get(
|
||||
"visible_to_logged_in_users"
|
||||
);
|
||||
data.visible_to_anons = buffered.get("visible_to_anons");
|
||||
|
||||
ajax(
|
||||
newRecord
|
||||
|
||||
@@ -8,6 +8,8 @@ export default DiscourseRoute.extend({
|
||||
return EmberObject.create({
|
||||
name: I18n.t("admin.adplugin.house_ads.new_name"),
|
||||
html: "",
|
||||
visible_to_logged_in_users: true,
|
||||
visible_to_anons: true,
|
||||
});
|
||||
} else {
|
||||
return this.modelFor("adminPlugins.houseAds").findBy(
|
||||
|
||||
@@ -4,10 +4,30 @@
|
||||
{{ace-editor content=buffered.html mode="html"}}
|
||||
</div>
|
||||
<div class="controls">
|
||||
<div class="visibility-settings">
|
||||
<div>
|
||||
<Input
|
||||
class="visible-to-logged-in-checkbox"
|
||||
@type="checkbox"
|
||||
@checked={{this.buffered.visible_to_logged_in_users}}
|
||||
/>
|
||||
<span>{{i18n "admin.adplugin.house_ads.show_to_logged_in_users"}}</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Input
|
||||
class="visible-to-anonymous-checkbox"
|
||||
@type="checkbox"
|
||||
@checked={{this.buffered.visible_to_anons}}
|
||||
/>
|
||||
<span>{{i18n "admin.adplugin.house_ads.show_to_anons"}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{d-button
|
||||
action=(action "save")
|
||||
disabled=disableSave
|
||||
class="btn-primary"
|
||||
class="btn-primary save-button"
|
||||
label="admin.adplugin.house_ads.save"
|
||||
}}
|
||||
|
||||
|
||||
@@ -28,7 +28,14 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
messageBus.subscribe("/site/house-creatives", function (houseAdsSettings) {
|
||||
const currentUser = container.lookup("service:current-user");
|
||||
let channel;
|
||||
if (currentUser) {
|
||||
channel = "/site/house-creatives/logged-in";
|
||||
} else {
|
||||
channel = "/site/house-creatives/anonymous";
|
||||
}
|
||||
messageBus.subscribe(channel, function (houseAdsSettings) {
|
||||
Site.currentProp("house_creatives", houseAdsSettings);
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user