<commit_before>/*
 * This file is part of the GOsa project -  http://gosa-project.org
 *
 * Copyright:
 *    (C) 2010-2017 GONICUS GmbH, Germany, http://www.gonicus.de
 *
 * License:
 *    LGPL-2.1: http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * See the LICENSE file in the project's top-level directory for details.
 */

qx.Class.define("gosa.proxy.Object", {

  extend: qx.core.Object,

  construct: function(data){

    // Call parent contructor
    this.base(arguments);
    this._setAttributes(data);
    this._listeners = new qx.data.Array();
    this._listeners.push(gosa.io.Sse.getInstance().addListener("objectModified", this._objectEvent, this));
    this._listeners.push(gosa.io.Sse.getInstance().addListener("objectRemoved", this._objectEvent, this));
    this._listeners.push(gosa.io.Sse.getInstance().addListener("objectMoved", this._objectEvent, this));
    this._listeners.push(gosa.io.Sse.getInstance().addListener("objectClosing", this._objectClosingEvent, this));
  },

  destruct : function(){

    // Stop listening for object changes
    this._listeners.forEach(function(listener) {
      gosa.io.Sse.getInstance().removeListenerById(listener);
    }, this);
    this.__listeners = null;

    // Remove every listener that was attached to us.
    // This allows us to set attribute values to null without
    // notifying gui widgets or other things.
    qx.event.Registration.removeAllListeners(this);
    for(var item in this.attributes){
      this.set(this.attributes[item], null);
    }
  },

  properties: {

    // Bound to the gui-editing widget
    uiBound: {
      check: "Boolean",
      init: false
    },

    /**
     * Title to identify this object, usually the first part of the DN
     */
    $$title: {
      check: "String",
      init: "",
      event: "changedTitle"
    },

    /**
     * Optional Icon to identify this object (used in the upper toolbar that shows the open objects)
     */
    $$icon: {
      check: "String",
      nullable: true
    },

    /**
     * Must be true if the object shall write updates to the backend.
     */
    writeAttributeUpdates : {
      check : "Boolean",
      init : true
    }
  },

  events: {
    "foundDifferencesDuringReload": "qx.event.type.Data",
    "propertyUpdateOnServer": "qx.event.type.Data",
    "updatedAttributeValues": "qx.event.type.Data",
    "moved": "qx.event.type.Data",
    "removed": "qx.event.type.Event",
    "closing": "qx.event.type.Data"
  },

  members: {

    _closed: false,
    _listeners: null,
    initialized: null,
    is_reloading: false,
    _updateLastChanged: null,
    skipEvents: false,

    isClosed: function(){
      return(this.isDisposed() || this._closed);
    },

    setClosed : function(value) {
      qx.core.Assert.assertBoolean(value);
      this._closed = value;
    },

    _objectClosingEvent: function(e) {
      // Skip event processing while committing, removing, etc
      if(this.skipEvents){
        return;
      }
      var data = e.getData();
      // Skip events that are not for us
      if(data.uuid != this.uuid) {
        return;
      }
      this.fireDataEvent("closing", data);
    },

    _objectEvent: function(e){

      // Skip event processing while committing, removing, etc
      if(this.skipEvents){
        return;
      }

      // Skip events that are not for us
      var data = e.getData();
      if(data.uuid !== this.uuid){
        return;
      }

      // Act on the event type
      if(data.changeType === "remove") {
        this.fireEvent("removed");
      } else if (data.changeType === "move") {
        this.reload();
        this.fireDataEvent("moved", data.dn);
      } else if(data.changeType === "update"){
        if(!this.is_reloading){

          if(!this.isUiBound()){
            this.reload();
          } else {
            this.mergeChanges();
          }
        }
      }
    },

    /* Helper method that sets attribute values using the
     * json-rpc response
     * */
    _setAttributes: function(data){

      // Initialize object values
      this.initialized = false;
      this.instance_uuid = data.__jsonclass__[1][1];
      this.dn = data.__jsonclass__[1][2];
      this.uuid = data.uuid;

      for(var item in this.attributes){
        var val;<commit_msg>debounce object change events<commit_after>/*
 * This file is part of the GOsa project -  http://gosa-project.org
 *
 * Copyright:
 *    (C) 2010-2017 GONICUS GmbH, Germany, http://www.gonicus.de
 *
 * License:
 *    LGPL-2.1: http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * See the LICENSE file in the project's top-level directory for details.
 */

qx.Class.define("gosa.proxy.Object", {

  extend: qx.core.Object,

  construct: function(data){

    // Call parent contructor
    this.base(arguments);
    this._setAttributes(data);
    this._listeners = new qx.data.Array();
    this._listeners.push(gosa.io.Sse.getInstance().addListener("objectModified", this._objectEvent, this));
    this._listeners.push(gosa.io.Sse.getInstance().addListener("objectRemoved", this._objectEvent, this));
    this._listeners.push(gosa.io.Sse.getInstance().addListener("objectMoved", this._objectEvent, this));
    this._listeners.push(gosa.io.Sse.getInstance().addListener("objectClosing", this._objectClosingEvent, this));

    this.debouncedMergeChanges = qx.util.Function.debounce(this.mergeChanges, 250, false);
  },

  destruct : function(){

    // Stop listening for object changes
    this._listeners.forEach(function(listener) {
      gosa.io.Sse.getInstance().removeListenerById(listener);
    }, this);
    this.__listeners = null;

    // Remove every listener that was attached to us.
    // This allows us to set attribute values to null without
    // notifying gui widgets or other things.
    qx.event.Registration.removeAllListeners(this);
    for(var item in this.attributes){
      this.set(this.attributes[item], null);
    }
  },

  properties: {

    // Bound to the gui-editing widget
    uiBound: {
      check: "Boolean",
      init: false
    },

    /**
     * Title to identify this object, usually the first part of the DN
     */
    $$title: {
      check: "String",
      init: "",
      event: "changedTitle"
    },

    /**
     * Optional Icon to identify this object (used in the upper toolbar that shows the open objects)
     */
    $$icon: {
      check: "String",
      nullable: true
    },

    /**
     * Must be true if the object shall write updates to the backend.
     */
    writeAttributeUpdates : {
      check : "Boolean",
      init : true
    }
  },

  events: {
    "foundDifferencesDuringReload": "qx.event.type.Data",
    "propertyUpdateOnServer": "qx.event.type.Data",
    "updatedAttributeValues": "qx.event.type.Data",
    "moved": "qx.event.type.Data",
    "removed": "qx.event.type.Event",
    "closing": "qx.event.type.Data"
  },

  members: {

    _closed: false,
    _listeners: null,
    initialized: null,
    is_reloading: false,
    _updateLastChanged: null,
    skipEvents: false,

    isClosed: function(){
      return(this.isDisposed() || this._closed);
    },

    setClosed : function(value) {
      qx.core.Assert.assertBoolean(value);
      this._closed = value;
    },

    _objectClosingEvent: function(e) {
      // Skip event processing while committing, removing, etc
      if(this.skipEvents){
        return;
      }
      var data = e.getData();
      // Skip events that are not for us
      if(data.uuid != this.uuid) {
        return;
      }
      this.fireDataEvent("closing", data);
    },

    _objectEvent: function(e){

      // Skip event processing while committing, removing, etc
      if(this.skipEvents){
        return;
      }

      // Skip events that are not for us
      var data = e.getData();
      if(data.uuid !== this.uuid){
        return;
      }

      // Act on the event type
      if(data.changeType === "remove") {
        this.fireEvent("removed");
      } else if (data.changeType === "move") {
        this.reload();
        this.fireDataEvent("moved", data.dn);
      } else if(data.changeType === "update"){
        if(!this.is_reloading){

          if(!this.isUiBound()){
            this.reload();
          } else {
            this.debouncedMergeChanges();
          }
        }
      }
    },

    /* Helper method that sets attribute values using the
     * json-rpc response
     * */
    _setAttributes: function(data){

      // Initialize object values
      this.initialized = false;
      this.instance_uuid = data.__jsonclass__[1][1];
      this.dn = data.__jsonclass__[1][2];
      this.uuid = data.uuid;

      for(var item in this.attributes){
        var val;
{'fraction_non_alphanumeric': 0.1345731777752108, 'fraction_numerical': 0.004042971006122213, 'mean_word_length': 2.4398092967818834, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2766642', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2625, 'n_words': 612}