2018-06-15 11:03:24 -04:00
|
|
|
import Permalink from "admin/models/permalink";
|
2017-07-05 16:47:01 -04:00
|
|
|
|
2015-07-15 08:54:28 -04:00
|
|
|
export default Ember.Component.extend({
|
2018-06-15 11:03:24 -04:00
|
|
|
classNames: ["permalink-form"],
|
2015-07-15 08:54:28 -04:00
|
|
|
formSubmitted: false,
|
2018-06-15 11:03:24 -04:00
|
|
|
permalinkType: "topic_id",
|
2015-07-15 08:54:28 -04:00
|
|
|
|
|
|
|
permalinkTypes: function() {
|
|
|
|
return [
|
2018-06-15 11:03:24 -04:00
|
|
|
{ id: "topic_id", name: I18n.t("admin.permalink.topic_id") },
|
|
|
|
{ id: "post_id", name: I18n.t("admin.permalink.post_id") },
|
|
|
|
{ id: "category_id", name: I18n.t("admin.permalink.category_id") },
|
|
|
|
{ id: "external_url", name: I18n.t("admin.permalink.external_url") }
|
2015-07-15 08:54:28 -04:00
|
|
|
];
|
|
|
|
}.property(),
|
|
|
|
|
|
|
|
permalinkTypePlaceholder: function() {
|
2018-06-15 11:03:24 -04:00
|
|
|
return "admin.permalink." + this.get("permalinkType");
|
|
|
|
}.property("permalinkType"),
|
2015-07-15 08:54:28 -04:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
submit: function() {
|
2018-06-15 11:03:24 -04:00
|
|
|
if (!this.get("formSubmitted")) {
|
2015-07-15 08:54:28 -04:00
|
|
|
const self = this;
|
2018-06-15 11:03:24 -04:00
|
|
|
self.set("formSubmitted", true);
|
|
|
|
const permalink = Permalink.create({
|
|
|
|
url: self.get("url"),
|
|
|
|
permalink_type: self.get("permalinkType"),
|
|
|
|
permalink_type_value: self.get("permalink_type_value")
|
2015-07-15 08:54:28 -04:00
|
|
|
});
|
2018-06-15 11:03:24 -04:00
|
|
|
permalink.save().then(
|
|
|
|
function(result) {
|
|
|
|
self.set("url", "");
|
|
|
|
self.set("permalink_type_value", "");
|
|
|
|
self.set("formSubmitted", false);
|
|
|
|
self.sendAction("action", Permalink.create(result.permalink));
|
|
|
|
Em.run.schedule("afterRender", function() {
|
|
|
|
self.$(".permalink-url").focus();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function(e) {
|
|
|
|
self.set("formSubmitted", false);
|
|
|
|
let error;
|
|
|
|
if (e.responseJSON && e.responseJSON.errors) {
|
|
|
|
error = I18n.t("generic_error_with_reason", {
|
|
|
|
error: e.responseJSON.errors.join(". ")
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
error = I18n.t("generic_error");
|
|
|
|
}
|
|
|
|
bootbox.alert(error, function() {
|
|
|
|
self.$(".permalink-url").focus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2015-07-15 08:54:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement: function() {
|
|
|
|
var self = this;
|
|
|
|
self._super();
|
2018-06-15 11:03:24 -04:00
|
|
|
Em.run.schedule("afterRender", function() {
|
|
|
|
self.$(".external-url").keydown(function(e) {
|
|
|
|
if (e.keyCode === 13) {
|
|
|
|
// enter key
|
|
|
|
self.send("submit");
|
2015-07-15 08:54:28 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|