<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.
 */

/**
 * Controller for the {@link gosa.ui.widget.WorkflowWizard} widget; connects it to the model.
 */
qx.Class.define("gosa.data.controller.Workflow", {
  extend : gosa.data.controller.BaseObjectEdit,
  implement: gosa.data.controller.IObject,

  /**
   * @param workflowObject {gosa.proxy.Object}
   */
  construct : function(workflowObject) {
    this.base(arguments);
    qx.core.Assert.assertInstance(workflowObject, gosa.proxy.Object);
    this.__workflowObject = workflowObject;

    this.__backendChangeController = new gosa.data.controller.BackendChanges(this.__workflowObject, this);

    this.__workflowObject.addListener(
      "foundDifferencesDuringReload",
      this.__backendChangeController.onFoundDifferenceDuringReload,
      this.__backendChangeController
    );

    this.__workflowObject.setUiBound(true);
  },

  members : {
    /**
     * @type {gosa.proxy.Object}
     */
    __workflowObject : null,
    __backendChangeController : null,

    /**
     * @return {gosa.proxy.Object}
     */
    getObject : function() {
      return this.__workflowObject;
    },

    /**
      * @param widget {gosa.ui.widgets.WorkflowWizard}
      */
    setWidget : function(widget) {
      qx.core.Assert.assertInstance(widget, gosa.ui.widgets.WorkflowWizard);
      this._widget = widget;
    },

    /**
      * @return {Array | null} List of all attributes of the object
    */
    getAttributes : function() {
      return qx.lang.Type.isArray(this.__workflowObject.attributes) ? this.__workflowObject.attributes : null;
    },

    saveAndClose : function() {
      this.__workflowObject.commit().catch(gosa.ui.dialogs.Error.show, this).then(this.close, this);
    },

    close : function() {
      this.__workflowObject.setUiBound(false);
      this.__workflowObject.close();
      this._widget.fireEvent("close");
      this._widget.destroy();
      this.dispose();
    },

    // Interface methods
    closeWidgetAndObject : function() {
      this.close();
    },

    /**
     * @return {gosa.data.util.ExtensionFinder}
     */
    getExtensionFinder : function() {
      return null;
    },

    /**
     * @return {gosa.data.controller.Extensions}
     */
    getExtensionController : function() {
      return null;
    }
  },

  destruct : function() {
    this.__workflowObject.removeListener(
      "foundDifferencesDuringReload",
      this.__backendChangeController.onFoundDifferenceDuringReload,
      this.__backendChangeController
    );

    this._disposeObjects(
      "__backendChangeController"
    );

    this.__workflowObject = null;
    this.__backendChangeController = null;
  }
});<commit_msg>Validation of workflow attributes<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.
 */

/**
 * Controller for the {@link gosa.ui.widget.WorkflowWizard} widget; connects it to the model.
 */
qx.Class.define("gosa.data.controller.Workflow", {
  extend : gosa.data.controller.BaseObjectEdit,
  implement: gosa.data.controller.IObject,

  /**
   * @param workflowObject {gosa.proxy.Object}
   */
  construct : function(workflowObject) {
    this.base(arguments);
    qx.core.Assert.assertInstance(workflowObject, gosa.proxy.Object);
    this.__workflowObject = workflowObject;

    this.__backendChangeController = new gosa.data.controller.BackendChanges(this.__workflowObject, this);

    this.__workflowObject.addListener(
      "foundDifferencesDuringReload",
      this.__backendChangeController.onFoundDifferenceDuringReload,
      this.__backendChangeController
    );

    this.__workflowObject.addListener("propertyUpdateOnServer", this.__onServerPropertyUpdated, this);

    this.__workflowObject.setUiBound(true);
  },

  members : {
    /**
     * @type {gosa.proxy.Object}
     */
    __workflowObject : null,
    __backendChangeController : null,

    /**
     * @return {gosa.proxy.Object}
     */
    getObject : function() {
      return this.__workflowObject;
    },

    /**
      * @param widget {gosa.ui.widgets.WorkflowWizard}
      */
    setWidget : function(widget) {
      qx.core.Assert.assertInstance(widget, gosa.ui.widgets.WorkflowWizard);
      this._widget = widget;
    },

    /**
      * @return {Array | null} List of all attributes of the object
    */
    getAttributes : function() {
      return qx.lang.Type.isArray(this.__workflowObject.attributes) ? this.__workflowObject.attributes : null;
    },

    saveAndClose : function() {
      this.__workflowObject.commit().catch(gosa.ui.dialogs.Error.show, this).then(this.close, this);
    },

    close : function() {
      this.__workflowObject.setUiBound(false);
      this.__workflowObject.close();
      this._widget.fireEvent("close");
      this._widget.destroy();
      this.dispose();
    },

    // Interface methods
    closeWidgetAndObject : function() {
      this.close();
    },

    /**
     * @return {gosa.data.util.ExtensionFinder}
     */
    getExtensionFinder : function() {
      return null;
    },

    /**
     * @return {gosa.data.controller.Extensions}
     */
    getExtensionController : function() {
      return null;
    },

    /**
     * @param ev {qx.event.type.Data}
     */
    __onServerPropertyUpdated : function(ev) {
      if (qx.core.Environment.get("qx.debug")) {
        qx.core.Assert.assertInstance(ev, qx.event.type.Data);
      }

      var data = ev.getData();
      var widget = this.getWidgetByAttributeName(data.property);

      widget.setValid(data.success);
      data.error && widget.setError(data.error.getData());
    }
  },

  destruct : function() {
    this.__workflowObject.removeListener("propertyUpdateOnServer", this.__onServerPropertyUpdated, this);

    this.__workflowObject.removeListener(
      "foundDifferencesDuringReload",
      this.__backendChangeController.onFoundDifferenceDuringReload,
      this.__backendChangeController
    );

    this._disposeObjects(
      "__backendChangeController"
    );

    this.__workflowObject = null;
    this.__backendChangeController = null;
  }
});
{'fraction_non_alphanumeric': 0.12823243078795254, 'fraction_numerical': 0.0036507453605111044, 'mean_word_length': 2.9560770156438028, 'pattern_counts': {'":': 0, '<': 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': '3524365', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1978, 'n_words': 317}