<commit_before>(function (){
  'use strict'

  angular
    .module('thingy.posts.controllers')
    .controller('AddController', AddController);

  AddController.$inject = ['$rootScope', '$scope', 'Authentication', '$route', '$cookies', '$location'];

  function AddController() {
    var vm = this;

    // Functions and Data
    vm.create = create;
    vm.categories = [];
    vm.regions = [];

    // Bindings
    vm.title;
    vm.description;
    vm.price;
    vm.condition;
    vm.category;
    vm.subcategory;
    vm.region;
    vm.subregion;

    activate();

    function activate() {
      Posts.getAllCategories().then(categoriesSuccessFn, categoriesErrorFn);
      Posts.getAllRegions().then(regionsSuccessFn, regionsErrorFn);

      restoreForms();

      function categoriesSuccessFn(data, status, headers, config) {
        vm.categories = data.data;
      }

      function categoriesErrorFn(data, status, headers, config) {
        alert(data.data.error);
      }

      function regionsSuccessFn(data, status, headers, config) {
        vm.regions = data.data;
      }

      function regionsErrorFn(data, status, headers, config) {
        alert(data.data.error);
      }

      function restoreForms() {
        if (savedForm)
        {
          // Forms
          vm.title = savedForm.title;
          vm.description = savedForm.description;
          vm.price = savedForm.price;
          vm.condition = savedForm.condition;
          // TODO
          //vm.category = JSON.parse(savedForm.category); // Working weird
          //vm.subcategory = JSON.parse(savedForm.subcategory); // Working weird
          //vm.region = JSON.parse(savedForm.region); // Working weird
          //vm.subregion = JSON.parse(savedForm.subregion); // Working weird
          // Actions
          //if (searchObject.action) vm.search();
        }
      }

      function bindEvents() {
        // Save form on refresh
        $rootScope.$on('login', function (event, post) {
          $cookies.putObject('savedForm', {
              title: vm.title,
              description: vm.description,
              price: vm.price,
              condition: vm.condition,
              // TODO
              // category: JSON.stringify(vm.category), // Working weird
              // subcategory: JSON.stringify(vm.subcategory) // Working weird
              // category: JSON.stringify(vm.region), // Working weird
              // subcategory: JSON.stringify(vm.subregion) // Working weird
            }, {expires: new Date(Date.now() + 2000)} // valid for 2 seconds
          );
        });
      }
    }

    function add() {
      if (authentication.isAuthenticated())
        Posts.add(
          vm.title,
          vm.description,
          vm.price,
          vm.condition.id,
          vm.subcategory.id,
          vm.subregion.id
        ).then(addPostSuccessFn, addPostErrorFn);
      else alert('You need to log in first');

      /**
      * @name createPostSuccessFn
      * @desc Show snackbar with success message
      */
      function addPostSuccessFn(data, status, headers, config) {
        resetForms();
        $route.reload();
      }

      /**
      * @name createPostErrorFn
      * @desc Propogate error event and show snackbar with error message
      */
      function addPostErrorFn(data, status, headers, config) {
        alert('You need to log in first... I could open the login window instead.');
      };
    }

    function resetForms() {
      vm.title =
      vm.description =
      vm.price =
      vm.category =
      vm.subcategory =
      vm.region =
      vm.subregion =
      "";
    }
  }
})();
<commit_msg>Hotfix<commit_after>(function (){
  'use strict'

  angular
    .module('thingy.posts.controllers')
    .controller('AddController', AddController);

  AddController.$inject = ['$rootScope', '$scope', 'Authentication', '$route', '$cookies', '$location', 'Posts'];

  function AddController($rootScope, $scope, Authentication, $route, $cookies, $location, Posts) {
    var vm = this;

    // Functions and Data
    vm.add = add;
    vm.categories = [];
    vm.regions = [];

    // Bindings
    vm.title;
    vm.description;
    vm.price;
    vm.condition;
    vm.category;
    vm.subcategory;
    vm.region;
    vm.subregion;

    activate();

    function activate() {
      Posts.getAllCategories().then(categoriesSuccessFn, categoriesErrorFn);
      Posts.getAllRegions().then(regionsSuccessFn, regionsErrorFn);

      restoreForms();

      function categoriesSuccessFn(data, status, headers, config) {
        vm.categories = data.data;
      }

      function categoriesErrorFn(data, status, headers, config) {
        alert(data.data.error);
      }

      function regionsSuccessFn(data, status, headers, config) {
        vm.regions = data.data;
      }

      function regionsErrorFn(data, status, headers, config) {
        alert(data.data.error);
      }

      function restoreForms() {
        if (savedForm)
        {
          // Forms
          vm.title = savedForm.title;
          vm.description = savedForm.description;
          vm.price = savedForm.price;
          vm.condition = savedForm.condition;
          // TODO
          //vm.category = JSON.parse(savedForm.category); // Working weird
          //vm.subcategory = JSON.parse(savedForm.subcategory); // Working weird
          //vm.region = JSON.parse(savedForm.region); // Working weird
          //vm.subregion = JSON.parse(savedForm.subregion); // Working weird
          // Actions
          //if (searchObject.action) vm.search();
        }
      }

      function bindEvents() {
        // Save form on refresh
        $rootScope.$on('login', function (event, post) {
          $cookies.putObject('savedForm', {
              title: vm.title,
              description: vm.description,
              price: vm.price,
              condition: vm.condition,
              // TODO
              // category: JSON.stringify(vm.category), // Working weird
              // subcategory: JSON.stringify(vm.subcategory) // Working weird
              // category: JSON.stringify(vm.region), // Working weird
              // subcategory: JSON.stringify(vm.subregion) // Working weird
            }, {expires: new Date(Date.now() + 2000)} // valid for 2 seconds
          );
        });
      }
    }

    function add() {
      if (authentication.isAuthenticated())
        Posts.add(
          vm.title,
          vm.description,
          vm.price,
          vm.condition.id,
          vm.subcategory.id,
          vm.subregion.id
        ).then(addPostSuccessFn, addPostErrorFn);
      else alert('You need to log in first');

      /**
      * @name createPostSuccessFn
      * @desc Show snackbar with success message
      */
      function addPostSuccessFn(data, status, headers, config) {
        resetForms();
        $route.reload();
      }

      /**
      * @name createPostErrorFn
      * @desc Propogate error event and show snackbar with error message
      */
      function addPostErrorFn(data, status, headers, config) {
        alert('You need to log in first... I could open the login window instead.');
      };
    }

    function resetForms() {
      vm.title =
      vm.description =
      vm.price =
      vm.category =
      vm.subcategory =
      vm.region =
      vm.subregion =
      "";
    }
  }
})();

{'fraction_non_alphanumeric': 0.12445652173913044, 'fraction_numerical': 0.001358695652173913, 'mean_word_length': 1.9326693227091634, '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': '3310306', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1995, 'n_words': 449}