Browse Source

Fixes #4012 - Textarea size should not increase in ticket zoom sidebar.

Florian Liebe 2 years ago
parent
commit
8df11ef924

+ 0 - 1
.gitattributes

@@ -6,7 +6,6 @@ app/assets/javascripts/app/lib/base/cropper.js linguist-vendored
 app/assets/javascripts/app/lib/base/desktop-notify.js linguist-vendored
 app/assets/javascripts/app/lib/base/email-addresses.js linguist-vendored
 app/assets/javascripts/app/lib/base/exif.js linguist-vendored
-app/assets/javascripts/app/lib/base/expanding.js linguist-vendored
 app/assets/javascripts/app/lib/base/highlight.pack.js linguist-vendored
 app/assets/javascripts/app/lib/base/html5Upload.js linguist-vendored
 app/assets/javascripts/app/lib/base/jquery-scrollto.js linguist-vendored

+ 0 - 5
LICENSE-3RD-PARTY.txt

@@ -44,11 +44,6 @@ Source: https://github.com/jackbowman/email-addresses
 Copyright: 2013 Fog Creek Software, Jack Bowman (https://github.com/jackbowman)
 License: MIT license
 -----------------------------------------------------------------------------
-expanding.js
-Source: https://github.com/bgrins/ExpandingTextareas
-Copyright: Brian Grinstead (https://github.com/bgrins)
-License: MIT license
------------------------------------------------------------------------------
 Exif.js
 Source: https://github.com/exif-js/exif-js
 Copyright: Jacob Seidelin, Roald de Vries

+ 0 - 2
app/assets/javascripts/app/controllers/_ui_element/_application_selector.coffee

@@ -102,8 +102,6 @@ class App.UiElement.ApplicationSelector
           # ignore passwords and relations
           if config.type isnt 'password' && config.name.substr(config.name.length-4,4) isnt '_ids' && config.searchable isnt false
             config.default  = undefined
-            if config.tag is 'textarea'
-              config.expanding = false
             if config.type is 'email' || config.type is 'tel'
               config.type = 'text'
             if config.tag is 'select'

+ 0 - 2
app/assets/javascripts/app/controllers/_ui_element/core_workflow_condition.coffee

@@ -157,8 +157,6 @@ class App.UiElement.core_workflow_condition extends App.UiElement.ApplicationSel
         # ignore passwords and relations
         if config.type isnt 'password' && config.name.substr(config.name.length-4,4) isnt '_ids' && config.searchable isnt false
           config.default  = undefined
-          if config.tag is 'textarea'
-            config.expanding = false
           if config.type is 'email' || config.type is 'tel'
             config.type = 'text'
           for operatorRegEx, operator of operatorsType

+ 11 - 0
app/assets/javascripts/app/controllers/_ui_element/object_manager_attribute.coffee

@@ -274,8 +274,19 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi
       noFieldset: true
       params: params
     )
+    configureAttributes = [
+      { name: 'data_option::rows', display: __('Rows'), tag: 'integer', null: false, default: 4 },
+    ]
+    inputRows = new App.ControllerForm(
+      model:
+        configure_attributes: configureAttributes
+      noFieldset: true
+      params: params
+    )
+
     item.find('.js-inputDefault').html(inputDefault.form)
     item.find('.js-inputMaxlength').html(inputMaxlength.form)
+    item.find('.js-inputRows').html(inputRows.form)
 
   @datetime: (item, localParams, params) ->
     configureAttributes = [

+ 5 - 12
app/assets/javascripts/app/controllers/_ui_element/textarea.coffee

@@ -1,21 +1,14 @@
 # coffeelint: disable=camel_case_classes
 class App.UiElement.textarea
   @render: (attribute) ->
+
+    # set an appropriate default value for rows, if not given
+    if attribute.rows is undefined
+      attribute.rows = 4
+
     fileUploaderId = 'file-uploader-' + new Date().getTime() + '-' + Math.floor( Math.random() * 99999 )
     item = $( App.view('generic/textarea')( attribute: attribute ) + '<div class="file-uploader ' + attribute.class + '" id="' + fileUploaderId + '"></div>' )
 
-    if attribute.expanding isnt false
-      a = ->
-        visible = $( item[0] ).is(':visible')
-        if visible && !$( item[0] ).expanding('active')
-          $( item[0] ).expanding()
-        $( item[0] ).on('focus', ->
-          visible = $( item[0] ).is(':visible')
-          if visible && !$( item[0] ).expanding('active')
-            $( item[0] ).expanding().trigger('focus')
-        )
-      App.Delay.set(a, 80)
-
     if attribute.upload
 
       # add file uploader

+ 0 - 222
app/assets/javascripts/app/lib/base/expanding.js

@@ -1,222 +0,0 @@
-// Expanding Textareas v0.1.1
-// MIT License
-// https://github.com/bgrins/ExpandingTextareas
-
-(function(factory) {
-  // Add jQuery via AMD registration or browser globals
-  if (typeof define === 'function' && define.amd) {
-    define([ 'jquery' ], factory);
-  }
-  else {
-    factory(jQuery);
-  }
-}(function ($) {
-
-  var Expanding = function($textarea, opts) {
-    Expanding._registry.push(this);
-
-    this.$textarea = $textarea;
-    this.$textCopy = $("<span />");
-    this.$clone = $("<pre class='expanding-clone'><br /></pre>").prepend(this.$textCopy);
-
-    this._resetStyles();
-    this._setCloneStyles();
-    this._setTextareaStyles();
-
-    $textarea
-      .wrap($("<div class='expanding-wrapper' style='position:relative' />"))
-      .after(this.$clone);
-
-    this.attach();
-    this.update();
-    if (opts.update) $textarea.on("update.expanding", opts.update);
-  };
-
-  // Stores (active) `Expanding` instances
-  // Destroyed instances are removed
-  Expanding._registry = [];
-
-  // Returns the `Expanding` instance given a DOM node
-  Expanding.getExpandingInstance = function(textarea) {
-    var $textareas = $.map(Expanding._registry, function(instance) {
-        return instance.$textarea[0];
-      }),
-      index = $.inArray(textarea, $textareas);
-    return index > -1 ? Expanding._registry[index] : null;
-  };
-
-  // Returns the version of Internet Explorer or -1
-  // (indicating the use of another browser).
-  // From: http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx#ParsingUA
-  var ieVersion = (function() {
-    var v = -1;
-    if (navigator.appName === "Microsoft Internet Explorer") {
-      var ua = navigator.userAgent;
-      var re = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
-      if (re.exec(ua) !== null) v = parseFloat(RegExp.$1);
-    }
-    return v;
-  })();
-
-  // Check for oninput support
-  // IE9 supports oninput, but not when deleting text, so keyup is used.
-  // onpropertychange _is_ supported by IE8/9, but may not be fired unless
-  // attached with `attachEvent`
-  // (see: http://stackoverflow.com/questions/18436424/ie-onpropertychange-event-doesnt-fire),
-  // and so is avoided altogether.
-  var inputSupported = "oninput" in document.createElement("input") && ieVersion !== 9;
-
-  Expanding.prototype = {
-
-    // Attaches input events
-    // Only attaches `keyup` events if `input` is not fully suported
-    attach: function() {
-      var events = 'input.expanding change.expanding',
-        _this = this;
-      if(!inputSupported) events += ' keyup.expanding';
-      this.$textarea.on(events, function() { _this.update(); });
-    },
-
-    // Updates the clone with the textarea value
-    update: function() {
-      this.$textCopy.text(this.$textarea.val().replace(/\r\n/g, "\n"));
-
-      // Use `triggerHandler` to prevent conflicts with `update` in Prototype.js
-      this.$textarea.triggerHandler("update.expanding");
-    },
-
-    // Tears down the plugin: removes generated elements, applies styles
-    // that were prevously present, removes instance from registry,
-    // unbinds events
-    destroy: function() {
-      this.$clone.remove();
-      this.$textarea
-        .unwrap()
-        .attr('style', this._oldTextareaStyles || '');
-      delete this._oldTextareaStyles;
-      var index = $.inArray(this, Expanding._registry);
-      if (index > -1) Expanding._registry.splice(index, 1);
-      this.$textarea.off(
-        'input.expanding change.expanding keyup.expanding update.expanding');
-    },
-
-    // Applies reset styles to the textarea and clone
-    // Stores the original textarea styles in case of destroying
-    _resetStyles: function() {
-      this._oldTextareaStyles = this.$textarea.attr('style');
-
-      this.$textarea.add(this.$clone).css({
-        margin: 0,
-        webkitBoxSizing: "border-box",
-        mozBoxSizing: "border-box",
-        boxSizing: "border-box",
-        width: "100%"
-      });
-    },
-
-    // Sets the basic clone styles and copies styles over from the textarea
-    _setCloneStyles: function() {
-      var css = {
-        display: 'block',
-        border: '0 solid',
-        visibility: 'hidden',
-        minHeight: this.$textarea.outerHeight()
-      };
-
-      if(this.$textarea.attr("wrap") === "off") css.overflowX = "scroll";
-      else css.whiteSpace = "pre-wrap";
-
-      this.$clone.css(css);
-      this._copyTextareaStylesToClone();
-    },
-
-    _copyTextareaStylesToClone: function() {
-      var _this = this,
-        properties = [
-          'lineHeight', 'textDecoration', 'letterSpacing',
-          'fontSize', 'fontFamily', 'fontStyle',
-          'fontWeight', 'textTransform', 'textAlign',
-          'direction', 'wordSpacing', 'fontSizeAdjust',
-          'wordWrap', 'word-break',
-          'borderLeftWidth', 'borderRightWidth',
-          'borderTopWidth','borderBottomWidth',
-          'paddingLeft', 'paddingRight',
-          'paddingTop','paddingBottom', 'maxHeight'];
-
-      $.each(properties, function(i, property) {
-        var val = _this.$textarea.css(property);
-
-        // Prevent overriding percentage css values.
-        if(_this.$clone.css(property) !== val) {
-          _this.$clone.css(property, val);
-          if(property === 'maxHeight' && val !== 'none') {
-            _this.$clone.css('overflow', 'hidden');
-          }
-        }
-      });
-    },
-
-    _setTextareaStyles: function() {
-      this.$textarea.css({
-        position: "absolute",
-        top: 0,
-        left: 0,
-        height: "100%",
-        resize: "none",
-        overflow: "auto"
-      });
-    }
-  };
-
-  $.expanding = $.extend({
-    autoInitialize: true,
-    initialSelector: "textarea.expanding",
-    opts: {
-      update: function() { }
-    }
-  }, $.expanding || {});
-
-  $.fn.expanding = function(o) {
-
-    if (o === "destroy") {
-      this.each(function() {
-        var instance = Expanding.getExpandingInstance(this);
-        if (instance) instance.destroy();
-      });
-      return this;
-    }
-
-    // Checks to see if any of the given DOM nodes have the
-    // expanding behaviour.
-    if (o === "active") {
-      return !!this.filter(function() {
-        return !!Expanding.getExpandingInstance(this);
-      }).length;
-    }
-
-    var opts = $.extend({ }, $.expanding.opts, o);
-
-    this.filter("textarea").each(function() {
-      var visible = this.offsetWidth > 0 || this.offsetHeight > 0,
-          initialized = Expanding.getExpandingInstance(this);
-
-      if(visible && !initialized) new Expanding($(this), opts);
-      else {
-        if(!visible) _warn("ExpandingTextareas: attempt to initialize an invisible textarea. Call expanding() again once it has been inserted into the page and/or is visible.");
-        if(initialized) _warn("ExpandingTextareas: attempt to initialize a textarea that has already been initialized. Subsequent calls are ignored.");
-      }
-    });
-    return this;
-  };
-
-  function _warn(text) {
-    if(window.console && console.warn) console.warn(text);
-  }
-
-  $(function () {
-    if ($.expanding.autoInitialize) {
-      $($.expanding.initialSelector).expanding();
-    }
-  });
-
-}));

+ 1 - 0
app/assets/javascripts/app/views/object_manager/attribute/textarea.jst.eco

@@ -1,4 +1,5 @@
 <div>
   <div class="js-inputDefault"></div>
   <div class="js-inputMaxlength"></div>
+  <div class="js-inputRows"></div>
 </div>

+ 2 - 1
app/assets/stylesheets/zammad.scss

@@ -2304,6 +2304,7 @@ input.time.time--12 {
 
 textarea.form-control {
   height: 118px;
+  resize: vertical;
 
   &[rows] {
     height: auto;
@@ -6518,7 +6519,7 @@ a.list-group-item.active > .badge,
   resize: vertical;
 }
 
-.bulkAction-secondStep .form-inline .expanding-wrapper {
+.bulkAction-secondStep .form-inline .textarea .controls {
   margin: 0 6px;
 }
 

+ 16 - 0
db/migrate/20220622110749_issue4012_missing_rows_for_textarea_fields.rb

@@ -0,0 +1,16 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+class Issue4012MissingRowsForTextareaFields < ActiveRecord::Migration[6.1]
+  def change
+    return if !Setting.exists?(name: 'system_init_done')
+
+    ObjectManager::Attribute
+      .where(data_type: 'textarea', editable: true)
+      .each do |attribute|
+        next if attribute.data_option[:rows].is_a?(Integer)
+
+        attribute.data_option[:rows] = 4
+        attribute.save!(validate: false)
+      end
+  end
+end

Some files were not shown because too many files changed in this diff