MDL-34221 disabledIf support for filemanager and filepicker elements
authorMarina Glancy <marina@moodle.com>
Fri, 13 Jul 2012 08:02:21 +0000 (16:02 +0800)
committerSam Hemelryk <sam@moodle.com>
Mon, 23 Jul 2012 00:08:49 +0000 (12:08 +1200)
lib/form/dndupload.js
lib/form/filemanager.js
lib/form/filepicker.js
lib/form/form.js
lib/outputrenderers.php
theme/base/style/filemanager.css

index 0cdeeee..bbadd5c 100644 (file)
@@ -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);
         },
 
         /**
index 164c683..cbd528a 100644 (file)
@@ -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');
index e372a23..b2811a2 100644 (file)
@@ -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);
index 2dd75f4..b49d76a 100644 (file)
@@ -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');
+                        }
                     }
                 })
             },
index b2d0e49..e800b8f 100644 (file)
@@ -2050,7 +2050,7 @@ $icon_progress
 </div>
 <div id="filepicker-wrapper-{$client_id}" class="mdl-left" style="display:none">
     <div>
-        <input type="button" id="filepicker-button-{$client_id}" value="{$straddfile}"{$buttonname}/>
+        <input type="button" class="fp-btn-choose" id="filepicker-button-{$client_id}" value="{$straddfile}"{$buttonname}/>
         <span> $maxsize </span>
     </div>
 EOD;
index 99cdb99..ed52934 100644 (file)
@@ -275,6 +275,10 @@ a.ygtvspacer:hover {color: transparent;text-decoration: none;}
 .filemanager.fm-updating .filemanager-updating {display:block;margin-top: 37px;}
 .filemanager.fm-updating .fm-content-wrapper {display:none;}
 .filemanager.fm-nomkdir .fp-btn-mkdir {display:none;}
+.fitem.disabled .filemanager .filemanager-toolbar,
+.fitem.disabled .filemanager .fp-pathbar,
+.fitem.disabled .filemanager .fp-restrictions,
+.fitem.disabled .filemanager .fm-content-wrapper {display:none;}
 
  /*
  * File Manager layout
@@ -292,6 +296,9 @@ a.ygtvspacer:hover {color: transparent;text-decoration: none;}
 .filemanager-container ul li a{padding:0}*/
 .filemanager .fp-content{overflow: auto;max-height: 472px;min-height: 157px;}
 .filemanager-container, .filepicker-filelist {overflow:hidden;}
+.fitem.disabled .filepicker-filelist, .fitem.disabled .filemanager-container {background-color:#EBEBE4;}
+.fitem.disabled .fp-btn-choose {color:graytext;}
+.fitem.disabled .filepicker-filelist .filepicker-filename {display:none;}
 
 /*
  * Icon view (File Manager only)
@@ -324,10 +331,8 @@ a.ygtvspacer:hover {color: transparent;text-decoration: none;}
 .filemanager .fp-tableview .fp-folder.fp-hascontextmenu .fp-contextmenu {display: inline;position: absolute;left: 14px;margin-right: -20px;top: 6px;}
 
 /*
- * Drag and drop support (File Manager only)
+ * Drag and drop support (filemanager and filepicker form elements)
  */
-.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,
@@ -341,6 +346,7 @@ a.ygtvspacer:hover {color: transparent;text-decoration: none;}
 .dndupload-uploadinprogress {display:none;text-align:center;}
 .dndupload-uploading .dndupload-uploadinprogress {display:block;}
 .dndupload-arrow {background:url([[pix:theme|fp/dnd_arrow]]) center no-repeat;width:60px;height:80px;position:absolute;margin-left: -28px;top: 5px;}
+.fitem.disabled .filepicker-container, .fitem.disabled .fm-empty-container {display:none;}
 
 /*
  * Select Dialogue (File Manager only)