{"size": 865, "ext": "es6", "max_stars_repo_path": "assets/javascripts/discourse/controllers/rename-tag.js.es6", "max_stars_repo_name": "huydeerpets/testtag", "max_stars_repo_stars_event_min_datetime": "2015-01-13T13:26:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-07T05:52:49.000Z", "max_issues_repo_path": "assets/javascripts/discourse/controllers/rename-tag.js.es6", "max_issues_repo_name": "huydeerpets/testtag", "max_issues_repo_issues_event_min_datetime": "2015-01-15T17:25:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-25T13:27:51.000Z", "max_forks_repo_path": "assets/javascripts/discourse/controllers/rename-tag.js.es6", "max_forks_repo_name": "huydeerpets/testtag", "max_forks_repo_forks_event_min_datetime": "2015-01-12T17:44:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-27T18:46:16.000Z"}
{"max_stars_count": 63, "max_issues_count": 48, "max_forks_count": 73, "avg_line_length": 33.2692307692, "max_line_length": 77, "alphanum_fraction": 0.6335260116}
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import BufferedContent from 'discourse/mixins/buffered-content';

export default Ember.Controller.extend(ModalFunctionality, BufferedContent, {

  renameDisabled: function() {
    const filterRegexp = new RegExp(this.site.tags_filter_regexp, "g"),
          newId = this.get('buffered.id').replace(filterRegexp, '').trim();

    return (newId.length === 0) || (newId === this.get('model.id'));
  }.property('buffered.id', 'id'),

  actions: {
    performRename() {
      const tag = this.get('model'),
            self = this;
      tag.update({ id: this.get('buffered.id') }).then(function() {
        self.send('closeModal');
        self.transitionToRoute('tags.show', tag.get('id'));
      }).catch(function() {
        self.flash(I18n.t('generic_error'), 'error');
      });
    }
  }
});
