<commit_before>App.loadTemplates(['reactions']);

App.Reaction = DS.Model.extend({
    url: 'reactions',

    text: DS.attr('string'),
    author: DS.belongsTo('App.Member', {embedded: true}),
    created: DS.attr('string'),
    timesince: DS.attr('string')
});


App.WallPostReaction = App.Reaction.extend({
    url: 'wallposts/reactions',

    // We need wallpost_id to create reactions in the API
    // This can't be a calculated property because then it won't be part of the API call
    wallpost_id: DS.attr('number'),
    wallpost: DS.belongsTo('App.ProjectWallPost')
});


App.wallPostReactionController = Em.Controller.create({
    model: App.WallPostReaction,

    addReaction: function(reaction, wallpost) {
        // Do a client side check if Reaction as a reaction property set
        // wallpost.reactions has problems with invalid records an will barf
        if (reaction.get('text') == undefined || reaction.get('text') == "") {
            reaction.set('errors', {'text': ['This field is required']});
            return false;
        }
        var transaction = App.store.transaction();
        var model = this.get('model');
        var livereaction = transaction.createRecord(model, reaction.toJSON());
        // Set the wallpost so the list gets updated in the view
        livereaction.set('wallpost_id', wallpost.get('id'));
        livereaction.set('wallpost', wallpost);
        livereaction.on('didCreate', function(record) {
            // Clear the reaction text in the form
            reaction.set('errors', null);
            reaction.set('text', '');
        });
        transaction.commit();
    }
});


App.WallPostReactionFormView = Em.View.extend({
    templateName: 'reaction_form',
    templateFile: 'reactions',
    tagName: 'form',
    classNames: ['reaction-form'],

    wallpostBinding: "parentView.content",

    // This needs to be as a calculated property or all reaction forms will be bound to each other.
    content: function(){
        return App.wallPostReactionController.get('model').createRecord();<commit_msg>Don't use ember-data internal api in Reactions.<commit_after>App.loadTemplates(['reactions']);

App.Reaction = DS.Model.extend({
    url: 'reactions',

    text: DS.attr('string'),
    author: DS.belongsTo('App.Member', {embedded: true}),
    created: DS.attr('string'),
    timesince: DS.attr('string')
});


App.WallPostReaction = App.Reaction.extend({
    url: 'wallposts/reactions',

    // We need wallpost_id to create reactions in the API
    // This can't be a calculated property because then it won't be part of the API call
    wallpost_id: DS.attr('number'),
    wallpost: DS.belongsTo('App.ProjectWallPost')
});


App.wallPostReactionController = Em.Controller.create({
    model: App.WallPostReaction,

    addReaction: function(reaction, wallpost) {
        // Do a client side check if Reaction as a reaction property set
        // wallpost.reactions has problems with invalid records an will barf
        if (reaction.get('text') == undefined || reaction.get('text') == "") {
            reaction.set('errors', {'text': ['This field is required']});
            return false;
        }
        var transaction = App.store.transaction();
        var model = this.get('model');
        var livereaction = transaction.createRecord(model, reaction);
        livereaction.set('text', reaction.get('text'));
        // Set the wallpost so the list gets updated in the view
        livereaction.set('wallpost_id', wallpost.get('id'));
        livereaction.set('wallpost', wallpost);
        livereaction.on('didCreate', function(record) {
            // Clear the reaction text in the form
            reaction.set('errors', null);
            reaction.set('text', '');
        });
        transaction.commit();
    }
});


App.WallPostReactionFormView = Em.View.extend({
    templateName: 'reaction_form',
    templateFile: 'reactions',
    tagName: 'form',
    classNames: ['reaction-form'],

    wallpostBinding: "parentView.content",

    // This needs to be as a calculated property or all reaction forms will be bound to each other.
    content: function(){
        return App.wallPostReactionController.get('model').createRecord();
{'fraction_non_alphanumeric': 0.13327009722551578, 'fraction_numerical': 0.0, 'mean_word_length': 3.0557692307692306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4900459', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1151, 'n_words': 327}