<commit_before>/*========================================================================

   This file is part of the GOsa project -  http://gosa-project.org
  
   Copyright:
      (C) 2010-2012 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.ui.widgets.QPushButtonWidget",
{
  extend : gosa.ui.widgets.Widget,

  properties: {

    // The buttons text
    text : {
      init : "",
      check : "String",
      apply : "_setText",
      nullable: true
    }
  },

  construct : function()
  {
    this.base(arguments);

    // Call super class
    this.contents.setLayout(new qx.ui.layout.Canvas());
    this._widget = new qx.ui.form.Button();
    this._widget.addListener("execute", function(){
        if(this._dialog){
          var d = this.getParent()._dialogs[this._dialog];
          if(d){
            d.open();
          }else{
            this.error("no such dialog named '" + this._dialog + "'!");
          }
        }
      }, this);
    this.contents.add(this._widget, {top:0, bottom:0, left:0, right: 0});
  },

  members :
  {
    _widget: null,
    _dialog: null,

    _setText : function(value)
    {
      this._widget.setLabel(this['tr'](value));
    },

    /* Apply collected gui properties to this widet
     * */
    _applyGuiProperties: function(props){

      // This happens when this widgets gets destroyed - all properties will be set to null.
      if(!props){
        return;
      }

      // Check if we have to open a dialog.
      if(props["dialog"] && props["dialog"]["string"]){
        this._dialog = props["dialog"]["string"];
      }

      if(props["text"] && props["text"]["string"]){
        this._setText(props["text"]["string"]);
      }
    }
  }
});

// vim:tabstop=2:expandtab:shiftwidth=2<commit_msg>Added property 'dialog' to QPushButton that opens on button execution<commit_after>/*========================================================================

   This file is part of the GOsa project -  http://gosa-project.org

   Copyright:
      (C) 2010-2012 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.ui.widgets.QPushButtonWidget", {

  extend : gosa.ui.widgets.Widget,

  construct : function() {
    this.base(arguments);

    this.contents.setLayout(new qx.ui.layout.Canvas());
    this._widget = new qx.ui.form.Button();
    this._widget.addListener("execute", function() {
        if (this._dialog) {
          var d = this.getParent()._dialogs[this._dialog];
          if (d) {
            d.open();
          } else {
            this.error("no such dialog named '" + this._dialog + "'!");
          }
        }
      }, this);

    this.contents.add(this._widget, {
      top : 0,
      bottom : 0,
      left : 0,
      right : 0
    });
  },

  properties: {
    /**
     * The button label.
     */
    text : {
      init : "",
      check : "String",
      apply : "_setText",
      nullable: true
    },

    /**
     * Base name of a dialog class. On click on the button, this class is searched for in the namespace of
     * "gosa.ui.dialogs" and then a new such dialog will be created. Example: "ChangePasswordDialog" opens a new
     * "gosa.ui.dialogs.ChangePasswordDialog" dialog.
     */
    dialog : {
      init : null,
      nullable : true,
      check : "String",
      apply : "_applyDialog"
    }
  },

  members : {

    _widget : null,
    _dialog : null,
    _dialogExecutionListener : null,

    _setText : function(value) {
      this._widget.setLabel(this.tr(value));
    },

    _applyGuiProperties : function(props) {
      // properties are null when widget gets destroyed
      if (!props) {
        return;
      }

      if (props.dialog && props.dialog.string) {
        this._dialog = props.dialog.string;
      }
      if (props.text && props.text.string) {
        this._setText(props.text.string);
      }
    },

    _applyDialog : function(value) {
      if (value) {
        this._createDialogExecutionListener();
      }
      else {
        this._removeDialogExecutionListener();
      }
    },

    _createDialogExecutionListener : function() {
      if (!this._dialogExecutionListener) {
        this._dialogExecutionListener = this._widget.addListener("execute", function() {
          var clazz = qx.Class.getByName("gosa.ui.dialogs." + this.getDialog());
          if (!clazz) {
            qx.core.Assert.fail("Unkown dialog class: '" + this.getDialog() + "'");
          }
          var dialog = new clazz();
          dialog.setAutoDispose();
          dialog.open();
        }, this);
      }
    },

    _removeDialogExecutionListener : function() {
      if (this._dialogExecutionListener) {
        this._widget.removeListenerById(this._dialogExecutionListener);
        this._dialogExecutionListener = null;
      }
    }
  },

  destruct : function() {
    this._removeDialogExecutionListener();
  }
});
{'fraction_non_alphanumeric': 0.18672433245581047, 'fraction_numerical': 0.006393380970289583, 'mean_word_length': 2.332706766917293, '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': '6543497', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1538, 'n_words': 333}