2018-06-15 23:03:24 +08:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2015-08-21 01:43:12 +08:00
|
|
|
|
2015-08-19 05:15:46 +08:00
|
|
|
export default Ember.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
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("embedding.embeddable_hosts.@each.isCreated")
|
2015-08-21 01:43:12 +08:00
|
|
|
showSecondary() {
|
2018-06-15 23:03:24 +08:00
|
|
|
const hosts = this.get("embedding.embeddable_hosts");
|
|
|
|
return hosts.length && hosts.findBy("isCreated");
|
2015-08-21 01:43:12 +08:00
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("embedding.base_url")
|
2015-08-21 01:43:12 +08:00
|
|
|
embeddingCode(baseUrl) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const html = `<div id='discourse-comments'></div>
|
2015-08-21 01:43:12 +08:00
|
|
|
|
|
|
|
<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() {
|
2018-06-15 23:03:24 +08:00
|
|
|
const embedding = this.get("embedding");
|
|
|
|
const updates = embedding.getProperties(embedding.get("fields"));
|
|
|
|
|
|
|
|
this.set("saved", false);
|
|
|
|
this.get("embedding")
|
|
|
|
.update(updates)
|
|
|
|
.then(() => this.set("saved", true))
|
|
|
|
.catch(popupAjaxError);
|
2015-08-19 05:15:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
addHost() {
|
2018-06-15 23:03:24 +08:00
|
|
|
const host = this.store.createRecord("embeddable-host");
|
|
|
|
this.get("embedding.embeddable_hosts").pushObject(host);
|
2015-08-19 05:15:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteHost(host) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("embedding.embeddable_hosts").removeObject(host);
|
2015-08-19 05:15:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|