<commit_before>/* Copyright 2016 LasLabs Inc.
 * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
 */

odoo.define('website_field_autocomplete.field_autocomplete', function(require){
  "use strict";

  var snippet_animation = require('web_editor.snippets.animation');
  var $ = require('$');

  snippet_animation.registry.field_autocomplete = snippet_animation.Class.extend({

    selector: '.js_website_autocomplete',

    /* Query remote server for autocomplete suggestions
     * @param request object Request from jQueryUI Autocomplete
     * @param response function Callback for response, accepts array of str
     */
    autocomplete: function(request, response) {
      var self = this;
      var domain = [[this.queryField, 'ilike', request.term]];
      if (this.add_domain) {
        domain = domain.concat(this.add_domain);
      }
      return $.ajax({
        dataType: 'json',
        url: '/website/field_autocomplete/' + self.model,
        method: 'GET',
        data: {
          domain: JSON.stringify(domain),
          fields: JSON.stringify(self.fields),
          limit: self.limit,
        },
      }).then(function(records) {
          var data = records.reduce(function(a, b) {
            a.push({label: b[self.displayField], value: b[self.valueField]});
            return a;
          }, []);
          response(data);
          return records;
        });
    },
    
    /* Return arguments that are used to initialize autocomplete */
    autocompleteArgs: function() {
      return {
        source: function(request, response) {
          this.autocomplete(request, response);
        },
      };
    },
    
    start: function() {
      this.model = this.$target.data('model');
      this.queryField = this.$target.data('query-field') || 'name';
      this.displayField = this.$target.data('display-field') || this.queryField;
      this.valueField = this.$target.data('value-field') || this.displayField;
      this.limit = this.$target.data('limit') || 10;
      this.add_domain = this.$target.data('domain');
      this.fields = [this.displayField];
      if (this.valueField != this.displayField) {
        this.fields.push(this.valueField);
      }
      this.$target.autocomplete(this.autocompleteArgs());
    },
    
  });
    
  return {field_autocomplete: snippet_animation.registry.field_autocomplete};

});
<commit_msg>[FIX] website_field_autocomplete: Fix namespacing<commit_after>/* Copyright 2016 LasLabs Inc.
 * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
 */

odoo.define('website_field_autocomplete.field_autocomplete', function(require){
  "use strict";

  var snippet_animation = require('web_editor.snippets.animation');
  var $ = require('$');

  snippet_animation.registry.field_autocomplete = snippet_animation.Class.extend({

    selector: '.js_website_autocomplete',

    /* Query remote server for autocomplete suggestions
     * @param request object Request from jQueryUI Autocomplete
     * @param response function Callback for response, accepts array of str
     */
    autocomplete: function(request, response) {
      var self = this;
      var domain = [[this.queryField, 'ilike', request.term]];
      if (this.add_domain) {
        domain = domain.concat(this.add_domain);
      }
      return $.ajax({
        dataType: 'json',
        url: '/website/field_autocomplete/' + self.model,
        method: 'GET',
        data: {
          domain: JSON.stringify(domain),
          fields: JSON.stringify(self.fields),
          limit: self.limit,
        },
      }).then(function(records) {
          var data = records.reduce(function(a, b) {
            a.push({label: b[self.displayField], value: b[self.valueField]});
            return a;
          }, []);
          response(data);
          return records;
        });
    },
    
    /* Return arguments that are used to initialize autocomplete */
    autocompleteArgs: function() {
      var self = this;
      return {
        source: function(request, response) {
          self.autocomplete(request, response);
        }
      };
    },
    
    start: function() {
      this.model = this.$target.data('model');
      this.queryField = this.$target.data('query-field') || 'name';
      this.displayField = this.$target.data('display-field') || this.queryField;
      this.valueField = this.$target.data('value-field') || this.displayField;
      this.limit = this.$target.data('limit') || 10;
      this.add_domain = this.$target.data('domain');
      this.fields = [this.displayField];
      if (this.valueField != this.displayField) {
        this.fields.push(this.valueField);
      }
      this.$target.autocomplete(this.autocompleteArgs());
    },
    
  });
    
  return {field_autocomplete: snippet_animation.registry.field_autocomplete};

});

{'fraction_non_alphanumeric': 0.1384169084127642, 'fraction_numerical': 0.003315375051802735, 'mean_word_length': 2.667933130699088, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '531388', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1361, 'n_words': 276}