From f93c575c8f17d208dab2fe243e008eb1138b0cf2 Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 27 Jun 2012 12:56:17 +0200 Subject: [PATCH] FileInput: handle disabled option --- source/Ox.UI/js/Form/FileInput.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/source/Ox.UI/js/Form/FileInput.js b/source/Ox.UI/js/Form/FileInput.js index 0d0ae56d..bf3b4fe9 100644 --- a/source/Ox.UI/js/Form/FileInput.js +++ b/source/Ox.UI/js/Form/FileInput.js @@ -2,10 +2,16 @@ /*@ Ox.FileInput File Input + options Options + disabled If true, the element is disabled + maxFiles Maximum number of files (or -1 for unlimited) + maxLines Maximum number of lines to display (or -1 for unlimited) + maxSize Maximum total file size in bytes (or -1 for unlimited) + value Value (array of file objects) + width Width in px + self Shared private variable ([options[, self]]) -> File Input change change - options Options - self Shared private variable @*/ Ox.FileInput = function(options, self) { @@ -13,6 +19,7 @@ Ox.FileInput = function(options, self) { self = self || {}; var that = Ox.Element({}, self) .defaults({ + disabled: false, maxFiles: -1, maxLines: -1, maxSize: -1, @@ -20,7 +27,14 @@ Ox.FileInput = function(options, self) { width: 256 }) .options(options || {}) - .addClass('OxFileInput') + .update({ + disabled: function() { + that[self.options.disabled ? 'addClass' : 'removeClass']('OxDisabled'); + self.$button.options({disabled: self.options.disabled}); + self.$input && self.$input[self.options.disabled ? 'hide' : 'show'](); + } + }) + .addClass('OxFileInput' + (self.options.disabled ? ' OxDisabled' : '')) .css({width: self.options.width + 'px'}); self.multiple = self.options.maxFiles != 1; @@ -60,6 +74,7 @@ Ox.FileInput = function(options, self) { .appendTo(self.$bar); self.$button = Ox.Button({ + disabled: self.options.disabled, style: 'symbol', title: self.multiple || self.options.value.length == 0 ? 'add' : 'close', @@ -80,6 +95,7 @@ Ox.FileInput = function(options, self) { if (self.multiple || self.options.value.length == 0) { self.$input = renderInput(); + self.options.disabled && self.$input.hide(); } if (self.multiple) { @@ -158,7 +174,7 @@ Ox.FileInput = function(options, self) { b = b.name.toLowerCase(); return a < b ? -1 : a > b ? 1 : 0; } : function(a, b) { - // if there's a max size, + // if there is a max size, // try to add small files first return a.size - b.size; }).forEach(function(file) {