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

/**
 * Container showing several tabs - all necessary for displaying forms for editing an object.
 */
qx.Class.define("gosa.ui.widgets.WorkflowWizard", {

  extend: qx.ui.core.Widget,

  /**
   * @param workflowObject {gosa.proxy.Object}
   * @param controller {gosa.data.controller.Workflow}
   * @param templates {Array}
   */
  construct: function(workflowObject, controller, templates) {
    this.base(arguments);
    this._setLayout(new qx.ui.layout.HBox(18));

    qx.core.Assert.assertArray(templates);
    qx.core.Assert.assertInstance(controller, gosa.data.controller.Workflow);
    qx.core.Assert.assertInstance(workflowObject, gosa.proxy.Object);

    this.__stepsConfig = [];
    this.__contexts = [];
    this.__controller = controller;
    this.__modelWidgetConnector = new gosa.data.ModelWidgetConnector(workflowObject, this);
    this.__enterCommand = new qx.ui.command.Command("Enter");
    this.__enterCommand.addListener("execute", this.__onEnterPress, this);

    this.__fillStepsConfiguration(templates);
    this.__fillSideBar();
    this.__createButtons();
    this.__showStep(0);
  },

  events : {
    "close" : "qx.event.type.Event"
  },

  properties : {
    appearance : {
      refine : true,
      init : "workflow-wizard"
    }
  },

  members : {
    __controller : null,
    __contexts : null,
    __currentStep : 0,
    __modelWidgetConnector : null,
    __enterCommand : null,

    /**
     * @type {Array} Holds information for the single steps. The order is in which to show the steps. There is one
     * element for each step. Each element is an object with the following attributes:
     *
     * id          : a string identifying the step (e.g. "user-shadow")
     * name        : (human-readable) name of the step
     * description : a short text describing the step
     * template    : the compiled template
     */
    __stepsConfig : null,

    getContexts : function() {
      return this.__contexts;
    },

    validate : function() {
      var valid = this.__contexts.every(function(context) {
        var widgetMap = context.getWidgetRegistry().getMap();
        for (var attributeName in widgetMap) {
          if (widgetMap.hasOwnProperty(attributeName) &&
              !widgetMap[attributeName].isValid() &&
              !widgetMap[attributeName].isBlocked()) {
            return false;
          }
        }
        return true;
      }, this);

      this.getChildControl("next-button").setEnabled(valid);
      this.getChildControl("save-button").setEnabled(valid);
    },

    __onEnterPress : function() {
      if (this.getChildControl("save-button").isVisible()) {
        this.getChildControl("save-button").execute();
      }
      else if (this.getChildControl("next-button").isEnabled()) {
        this.getChildControl("next-button").execute();
      }
    },

    __onCancel : function() {
      var dialog = new gosa.ui.dialogs.Confirmation(
        this.tr("Really abort?"),
        this.tr("All entered data will be lost. Are you sure you want to abort?")
      );
      dialog.setAutoDispose(true);
      dialog.addListenerOnce("confirmed", function(event) {
        if (event.getData()) {
          this.__controller.close();
        }
      }, this);
      dialog.open();
    },<commit_msg>Prevent workflow to save on enter keypress if save button disabled<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.
 */

/**
 * Container showing several tabs - all necessary for displaying forms for editing an object.
 */
qx.Class.define("gosa.ui.widgets.WorkflowWizard", {

  extend: qx.ui.core.Widget,

  /**
   * @param workflowObject {gosa.proxy.Object}
   * @param controller {gosa.data.controller.Workflow}
   * @param templates {Array}
   */
  construct: function(workflowObject, controller, templates) {
    this.base(arguments);
    this._setLayout(new qx.ui.layout.HBox(18));

    qx.core.Assert.assertArray(templates);
    qx.core.Assert.assertInstance(controller, gosa.data.controller.Workflow);
    qx.core.Assert.assertInstance(workflowObject, gosa.proxy.Object);

    this.__stepsConfig = [];
    this.__contexts = [];
    this.__controller = controller;
    this.__modelWidgetConnector = new gosa.data.ModelWidgetConnector(workflowObject, this);
    this.__enterCommand = new qx.ui.command.Command("Enter");
    this.__enterCommand.addListener("execute", this.__onEnterPress, this);

    this.__fillStepsConfiguration(templates);
    this.__fillSideBar();
    this.__createButtons();
    this.__showStep(0);
  },

  events : {
    "close" : "qx.event.type.Event"
  },

  properties : {
    appearance : {
      refine : true,
      init : "workflow-wizard"
    }
  },

  members : {
    __controller : null,
    __contexts : null,
    __currentStep : 0,
    __modelWidgetConnector : null,
    __enterCommand : null,

    /**
     * @type {Array} Holds information for the single steps. The order is in which to show the steps. There is one
     * element for each step. Each element is an object with the following attributes:
     *
     * id          : a string identifying the step (e.g. "user-shadow")
     * name        : (human-readable) name of the step
     * description : a short text describing the step
     * template    : the compiled template
     */
    __stepsConfig : null,

    getContexts : function() {
      return this.__contexts;
    },

    validate : function() {
      var valid = this.__contexts.every(function(context) {
        var widgetMap = context.getWidgetRegistry().getMap();
        for (var attributeName in widgetMap) {
          if (widgetMap.hasOwnProperty(attributeName) &&
              !widgetMap[attributeName].isValid() &&
              !widgetMap[attributeName].isBlocked()) {
            return false;
          }
        }
        return true;
      }, this);

      this.getChildControl("next-button").setEnabled(valid);
      this.getChildControl("save-button").setEnabled(valid);
    },

    __onEnterPress : function() {
      var saveButton = this.getChildControl("save-button");
      if (saveButton.isVisible() && saveButton.isEnabled()) {
        saveButton.execute();
        return;
      }

      var nextButton = this.getChildControl("next-button");
      if (nextButton.isVisible() && nextButton.isEnabled()) {
        nextButton.execute();
      }
    },

    __onCancel : function() {
      var dialog = new gosa.ui.dialogs.Confirmation(
        this.tr("Really abort?"),
        this.tr("All entered data will be lost. Are you sure you want to abort?")
      );
      dialog.setAutoDispose(true);
      dialog.addListenerOnce("confirmed", function(event) {
        if (event.getData()) {
          this.__controller.close();
        }
      }, this);
      dialog.open();
    },
{'fraction_non_alphanumeric': 0.12696460297936313, 'fraction_numerical': 0.004373377067104004, 'mean_word_length': 2.7147208121827413, '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': '2771215', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2141, 'n_words': 482}