Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3272

Display file size message with the most readable unit

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Done
    • Affects Version/s: 8.0.2
    • Fix Version/s: 8.5.2
    • Component/s: None
    • Security Level: Jimmy
    • Labels:
      None
    • gh.sprint.customfield.default.name:
      ZK 8.0.3 S7, ZK 8.0.3 S9, ZK 8.0.3 S10, ZK 8.5.2 S1, ZK 8.5.2 S2

      Description

      When exceeding max size, the Dropupload always displays a file size in KB. The code below can convert a file size to the most readable size unit:

      <dropupload maxsize="5" detection="none" onUpload="" >
          <attribute name="content"><![CDATA[
              <b>Drop Here</b><br/>
              size < 5k
          ]]></attribute>
      </dropupload>
      
          zk.fmt.Text.stuff = zk.fmt.Text.format;
      
      	/**
      	 * Formatting a filesize depending on its value:
      	 * >= 1024 GB: 0.0 TB,
      	 * >= 1024 MB: 0.0 GB,
      	 * >= 1024 KB: 0.0 MB,
      	 * >= 1024 B : 0.0 KB,
      	 * else: bytes. Decimal point is determined by System language.
      	 */
          zk.fmt.Text.formatFileSize = function (bytes) {
              var divider = 1024;
      
              if(Math.abs(bytes) < divider) {
                  return bytes + msgzk.BYTES;
              }
      
              var units = [msgzk.KBYTES, msgzk.MBYTES, msgzk.GBYTES, msgzk.TBYTES]
              var unit = -1;
      
              do {
                  bytes /= divider;
                  ++unit;
              } while(Math.abs(bytes) >= divider && unit < units.length - 1);
      
              return +bytes.toFixed(1) + ' ' + units[unit];
          }
      
          zk.fmt.Text.format = function (msg) {
              if (msg == msgzul.UPLOAD_ERROR_EXCEED_MAXSIZE)
                  return zk.fmt.Text.stuff(msg, zk.fmt.Text.formatFileSize(arguments[3]), zk.fmt.Text.formatFileSize(arguments[4]));
              else
                  return zk.fmt.Text.stuff(arguments);
          }
      

        Attachments

          Activity

            People

            • Assignee:
              klyvechen klyvechen
              Reporter:
              hawk hawk
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1 day
                1d
                Remaining:
                Time Spent - 1 hour Remaining Estimate - 7 hours
                7h
                Logged:
                Time Spent - 1 hour Remaining Estimate - 7 hours
                1h