From b1c669a711f2181d5d036d5d9eb0b34b4c04d04d Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Mon, 9 Jul 2012 21:39:34 +0100 Subject: [PATCH 1/2] MDL-34221 Filepicker - disableIf now prevents drag and drop upload --- lib/form/dndupload.js | 14 ++++++++++++++ lib/form/form.js | 4 ++++ theme/base/style/filemanager.css | 2 ++ 3 files changed, 20 insertions(+) diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index 53018b9f08e..0cdeeee21fd 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -165,11 +165,22 @@ M.form_dndupload.init = function(Y, options) { this.Y.on('dragleave', this.drag_leave_page, 'body', this); }, + /** + * Check if the filemanager / filepicker is disabled + * @return bool - true if disabled + */ + is_disabled: function() { + return this.container.hasClass('disabled'); + }, + /** * Show the 'drop files here' message when file(s) are dragged * onto the page */ drag_enter_page: function(e) { + if (this.is_disabled()) { + return false; + } if (!this.has_files(e)) { return false; } @@ -210,6 +221,9 @@ M.form_dndupload.init = function(Y, options) { * @return boolean true if a valid file drag event */ check_drag: function(e) { + if (this.is_disabled()) { + return false; + } if (!this.has_files(e)) { return false; } diff --git a/lib/form/form.js b/lib/form/form.js index 938fab6be66..2dd75f498f0 100644 --- a/lib/form/form.js +++ b/lib/form/form.js @@ -211,10 +211,14 @@ M.form.initFormDependencies = function(Y, formid, dependencies) { if (this.getAttribute('class') == 'filepickerhidden'){ var pickerbuttons = form.elementsByName(name + 'choose'); pickerbuttons.each(function(){ + var clientid = this.get('id').split('-')[2]; + var filepicker = Y.one('#file_info_'+clientid); if (disabled){ this.setAttribute('disabled','disabled'); + filepicker.addClass('disabled'); } else { this.removeAttribute('disabled'); + filepicker.removeClass('disabled'); } }); } diff --git a/theme/base/style/filemanager.css b/theme/base/style/filemanager.css index 5fbacc3599f..99cdb994077 100644 --- a/theme/base/style/filemanager.css +++ b/theme/base/style/filemanager.css @@ -326,6 +326,8 @@ a.ygtvspacer:hover {color: transparent;text-decoration: none;} /* * Drag and drop support (File Manager only) */ +.filepicker-filelist.disabled {background-color:#ddd;} +.filepicker-filelist.disabled .filepicker-filename {display:none;} .filepicker-filelist .filepicker-container, .filemanager.fm-noitems .fm-empty-container {display:block;position:absolute;top:10px;bottom:10px;left:10px;right:10px;border: 2px dashed #BBBBBB;padding-top:85px;text-align:center;z-index: 3000;} .filepicker-filelist .dndupload-target, From c81f332876e79ab71db930ced89fdd7732554f30 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 13 Jul 2012 16:02:21 +0800 Subject: [PATCH 2/2] MDL-34221 disabledIf support for filemanager and filepicker elements --- lib/form/dndupload.js | 2 +- lib/form/filemanager.js | 21 +++++++++++++++++++-- lib/form/filepicker.js | 4 +++- lib/form/form.js | 22 ++++++++-------------- lib/outputrenderers.php | 2 +- theme/base/style/filemanager.css | 12 +++++++++--- 6 files changed, 41 insertions(+), 22 deletions(-) diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index 0cdeeee21fd..bbadd5c03f6 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -170,7 +170,7 @@ M.form_dndupload.init = function(Y, options) { * @return bool - true if disabled */ is_disabled: function() { - return this.container.hasClass('disabled'); + return (this.container.ancestor('.fitem.disabled') != null); }, /** diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js index 164c6834a4b..cbd528a71d5 100644 --- a/lib/form/filemanager.js +++ b/lib/form/filemanager.js @@ -255,6 +255,9 @@ M.form_filemanager.init = function(Y, options) { this.msg_dlg_node.one('.fp-msg-text').setContent(msg); this.msg_dlg.show(); }, + is_disabled: function() { + return this.filemanager.ancestor('.fitem.disabled') != null; + }, setup_buttons: function() { var button_download = this.filemanager.one('.fp-btn-download'); var button_create = this.filemanager.one('.fp-btn-mkdir'); @@ -272,6 +275,9 @@ M.form_filemanager.init = function(Y, options) { if (this.options.subdirs) { button_create.on('click',function(e) { e.preventDefault(); + if (this.is_disabled()) { + return; + } var scope = this; // a function used to perform an ajax request var perform_action = function(e) { @@ -325,6 +331,9 @@ M.form_filemanager.init = function(Y, options) { // setup 'download this folder' button button_download.on('click',function(e) { e.preventDefault(); + if (this.is_disabled()) { + return; + } var scope = this; // perform downloaddir ajax request this.request({ @@ -351,7 +360,7 @@ M.form_filemanager.init = function(Y, options) { on('click', function(e) { e.preventDefault(); var viewbar = this.filemanager.one('.fp-viewbar') - if (!viewbar || !viewbar.hasClass('disabled')) { + if (!this.is_disabled() && (!viewbar || !viewbar.hasClass('disabled'))) { this.filemanager.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').removeClass('checked') if (e.currentTarget.hasClass('fp-vb-tree')) { this.viewmode = 2; @@ -369,6 +378,9 @@ M.form_filemanager.init = function(Y, options) { show_filepicker: function (e) { // if maxfiles == -1, the no limit e.preventDefault(); + if (this.is_disabled()) { + return; + } var options = this.filepicker_options; options.formcallback = this.filepicker_callback; // XXX: magic here, to let filepicker use filemanager scope @@ -400,7 +412,9 @@ M.form_filemanager.init = function(Y, options) { el.one('.fp-path-folder-name').setContent(p[i].name). on('click', function(e, path) { e.preventDefault(); - this.refresh(path); + if (!this.is_disabled()) { + this.refresh(path); + } }, this, p[i].path); } this.pathbar.removeClass('empty'); @@ -873,6 +887,9 @@ M.form_filemanager.init = function(Y, options) { return node.filepath; }, select_file: function(node) { + if (this.is_disabled()) { + return; + } var selectnode = this.selectnode; selectnode.removeClass('loading').removeClass('fp-folder'). removeClass('fp-file').removeClass('fp-zip').removeClass('fp-cansetmain'); diff --git a/lib/form/filepicker.js b/lib/form/filepicker.js index e372a23c086..b2811a25dbc 100644 --- a/lib/form/filepicker.js +++ b/lib/form/filepicker.js @@ -32,7 +32,9 @@ M.form_filepicker.init = function(Y, options) { } Y.on('click', function(e, client_id) { e.preventDefault(); - M.core_filepicker.instances[client_id].show(); + if (this.ancestor('.fitem.disabled') == null) { + M.core_filepicker.instances[client_id].show(); + } }, '#filepicker-button-'+options.client_id, null, options.client_id); var item = document.getElementById('nonjs-filepicker-'+options.client_id); diff --git a/lib/form/form.js b/lib/form/form.js index 2dd75f498f0..b49d76a0437 100644 --- a/lib/form/form.js +++ b/lib/form/form.js @@ -207,20 +207,14 @@ M.form.initFormDependencies = function(Y, formid, dependencies) { this.removeAttribute('disabled'); } - // Extra code to disable a filepicker - if (this.getAttribute('class') == 'filepickerhidden'){ - var pickerbuttons = form.elementsByName(name + 'choose'); - pickerbuttons.each(function(){ - var clientid = this.get('id').split('-')[2]; - var filepicker = Y.one('#file_info_'+clientid); - if (disabled){ - this.setAttribute('disabled','disabled'); - filepicker.addClass('disabled'); - } else { - this.removeAttribute('disabled'); - filepicker.removeClass('disabled'); - } - }); + // Extra code to disable filepicker or filemanager form elements + var fitem = this.ancestor('.fitem'); + if (fitem && (fitem.hasClass('fitem_ffilemanager') || fitem.hasClass('fitem_ffilepicker'))) { + if (disabled){ + fitem.addClass('disabled'); + } else { + fitem.removeClass('disabled'); + } } }) }, diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index b2d0e491005..e800b8f21e2 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2050,7 +2050,7 @@ $icon_progress