How to refresh topic title when it was changed in one of plugin's custom controllers


(Janno Liivak) #1

I update topic using custom controller where function was triggered through ajax. Client side code gets back result with a changed topic title but I’m unable to figure out how to refresh topic title in topic-view inside “then” callback. Strangely the archieved property change will call archieved “lock” icon to show up. Title will change only in page title but not in topic main title.

export default {
  actions: {
    clickSoldButton(topic) {
      ajax("/topic/sold", {
        type: "PUT",
        data: {
          topic_id: topic.id
        }
      }).then((result) => {
        topic.set('custom_fields.sold_at', result.topic.sold_at);
        topic.set('title', result.topic.title);
        topic.set('archived', result.topic.archived);
      }).catch(() => {
        bootbox.alert(I18n.t('topic_trading.error_while_marked_as_sold'));
      });
    }
  }
};

Is there a certain way to get Title to change other than navigating to topic or page reload?


(Sam Saffron) #2

There is a new event for this you can use after

this.appEvents.trigger('header:update-topic', topic);

Also, if you properly use PostRevisor this is handled automatically for you.


(Janno Liivak) #3

Thank you. But I can’t use PostRevisor as I want topic to be updated even when it’s not editable by user. As I understand, revisor will go through Topic.update which prevents changes after editing time has passed?


(Sam Saffron) #4

Not really a problem, cause you can disable validations when you update if you wish via the api (or perform the edit as system)


(Janno Liivak) #5

Ok. I’ll give it a try. Thanks!