discourse/app/assets/javascripts/admin/controllers/admin-embedding.js.es6

55 lines
1.6 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import computed from "ember-addons/ember-computed-decorators";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Ember.Controller.extend({
saved: false,
embedding: null,
// show settings if we have at least one created host
2018-06-15 23:03:24 +08:00
@computed("embedding.embeddable_hosts.@each.isCreated")
showSecondary() {
2018-06-15 23:03:24 +08:00
const hosts = this.get("embedding.embeddable_hosts");
return hosts.length && hosts.findBy("isCreated");
},
2018-06-15 23:03:24 +08:00
@computed("embedding.base_url")
embeddingCode(baseUrl) {
2018-06-15 23:03:24 +08:00
const html = `<div id='discourse-comments'></div>
<script type="text/javascript">
DiscourseEmbed = { discourseUrl: '${baseUrl}/',
discourseEmbedUrl: 'REPLACE_ME' };
(function() {
var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
})();
</script>`;
return html;
},
actions: {
saveChanges() {
const embedding = this.embedding;
2018-06-15 23:03:24 +08:00
const updates = embedding.getProperties(embedding.get("fields"));
this.set("saved", false);
this.embedding
2018-06-15 23:03:24 +08:00
.update(updates)
.then(() => this.set("saved", true))
.catch(popupAjaxError);
},
addHost() {
2018-06-15 23:03:24 +08:00
const host = this.store.createRecord("embeddable-host");
this.get("embedding.embeddable_hosts").pushObject(host);
},
deleteHost(host) {
2018-06-15 23:03:24 +08:00
this.get("embedding.embeddable_hosts").removeObject(host);
}
}
});