2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2015-08-21 01:43:12 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2015-08-21 01:43:12 +08:00
|
|
|
saved: false,
|
2015-08-19 05:15:46 +08:00
|
|
|
embedding: null,
|
|
|
|
|
2015-08-21 01:43:12 +08:00
|
|
|
// show settings if we have at least one created host
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("embedding.embeddable_hosts.@each.isCreated")
|
2015-08-21 01:43:12 +08:00
|
|
|
showSecondary() {
|
|
|
|
const hosts = this.get("embedding.embeddable_hosts");
|
2016-10-27 03:44:36 +08:00
|
|
|
return hosts.length && hosts.findBy("isCreated");
|
2015-08-21 01:43:12 +08:00
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("embedding.base_url")
|
2015-08-21 01:43:12 +08:00
|
|
|
embeddingCode(baseUrl) {
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2015-08-19 05:15:46 +08:00
|
|
|
actions: {
|
|
|
|
saveChanges() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const embedding = this.embedding;
|
2015-08-21 01:43:12 +08:00
|
|
|
const updates = embedding.getProperties(embedding.get("fields"));
|
2018-06-15 23:03:24 +08:00
|
|
|
|
2015-08-21 01:43:12 +08:00
|
|
|
this.set("saved", false);
|
2019-05-27 16:15:39 +08:00
|
|
|
this.embedding
|
2016-08-23 00:43:02 +08:00
|
|
|
.update(updates)
|
|
|
|
.then(() => this.set("saved", true))
|
|
|
|
.catch(popupAjaxError);
|
2015-08-19 05:15:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
addHost() {
|
|
|
|
const host = this.store.createRecord("embeddable-host");
|
|
|
|
this.get("embedding.embeddable_hosts").pushObject(host);
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteHost(host) {
|
|
|
|
this.get("embedding.embeddable_hosts").removeObject(host);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|