<commit_before>'use strict'

let AddPostView = Backbone.View.extend({


  tagName: "div",


  className: "container addpost-form",


  events: {
    "click #closeadd": "closeadd",
    "click #publish-btn": "publish",
  },


  initialize: function(data) {
    this.data = data || {};
    this.data.campaigns = S.collection.get("campaigns").toJSON().map((i) => {
      return S.collection2select({id: i.id, text: i.name});
    });
    S.toggleNavigation();
    //this.scheduler = new SchedulerCreateView();
  },


  closeadd: function() {
    S.toggleNavigation(true);
    this.scheduler = new SchedulerCreateView();
    this.remove();
    this.scheduler.render();
  },


  publish: function() {
    let tags = [];
    tags.push(this.data.bucket);
    tags.push({"like": $("#lkgroups").val()});
    tags.push({"rs": $("#rsgroups").val()});
    let content = {
      txt: $("#postxt").val(),
      img: "http://images2.fanpop.com/image/photos/13700000/Beautiful-Pug-pugs-13728067-1600-1200.jpg",
      tags: tags,
    };

    let post = {
      date: new Date(),
      campaign: $("#campaignSelectorBox").val(),
      phase: $("#phaseSelectorBox").val(),
      content: content,
      owner: S.user.attributes.pk
    };

    let newPost = new Post(post);
    let options = S.addAuthorizationHeader();
    options.error = () => {
      S.logger("bg-danger", "Couldn't schedule new post", true);
    };
    S.collection.get("posts").sync("create", newPost, {
      headers: S.addAuthorizationHeader().headers,
      success: (model, response) => {
        S.logger("bg-success", "Post published succesfully", true);
        this.closeadd();
      },
      error: (model, response) => {<commit_msg>FIX much better solution, add the model to the collection first, then chain-sync... now I recall<commit_after>'use strict'

let AddPostView = Backbone.View.extend({


  tagName: "div",


  className: "container addpost-form",


  events: {
    "click #closeadd": "closeadd",
    "click #publish-btn": "publish",
  },


  initialize: function(data) {
    this.data = data || {};
    this.data.campaigns = S.collection.get("campaigns").toJSON().map((i) => {
      return S.collection2select({id: i.id, text: i.name});
    });
    S.toggleNavigation();
  },


  closeadd: function() {
    S.toggleNavigation(true);
    this.scheduler = new SchedulerCreateView();
    this.remove();
    //this.scheduler.render();
  },


  publish: function() {
    let tags = [];
    tags.push(this.data.bucket);
    tags.push({"like": $("#lkgroups").val()});
    tags.push({"rs": $("#rsgroups").val()});
    let content = {
      txt: $("#postxt").val(),
      img: "http://images2.fanpop.com/image/photos/13700000/Beautiful-Pug-pugs-13728067-1600-1200.jpg",
      tags: tags,
    };

    let post = {
      date: new Date(),
      campaign: $("#campaignSelectorBox").val(),
      phase: $("#phaseSelectorBox").val(),
      content: content,
      owner: S.user.attributes.pk
    };

    let newPost = new Post(post);
    let options = S.addAuthorizationHeader();
    options.error = () => {
      S.logger("bg-danger", "Couldn't schedule new post", true);
    };
    S.collection.get("posts").add(newPost).sync("create", newPost, {
      headers: S.addAuthorizationHeader().headers,
      success: (model, response) => {
        S.logger("bg-success", "Post published succesfully", true);
        this.closeadd();
      },
      error: (model, response) => {
{'fraction_non_alphanumeric': 0.18822843822843824, 'fraction_numerical': 0.015151515151515152, 'mean_word_length': 2.955069124423963, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 11, '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': '1431236', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1078, 'n_words': 212}