From b56d54ca0453a8fe787b8d6682f544a9e2962eb9 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Sat, 14 Jan 2012 16:41:19 +0000 Subject: [PATCH] MDL-31113 filemanager element - refresh file list from server on load --- lib/form/filemanager.js | 13 ++++++++++--- repository/draftfiles_ajax.php | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js index cf6837b0e1c07..58ceaf727a253 100644 --- a/lib/form/filemanager.js +++ b/lib/form/filemanager.js @@ -76,7 +76,7 @@ M.form_filemanager.init = function(Y, options) { this.filecount = 0; } this.setup_buttons(); - this.render(); + this.refresh(this.currentpath); // MDL-31113 get latest list from server }, wait: function(client_id) { @@ -141,15 +141,18 @@ M.form_filemanager.init = function(Y, options) { } }, filepicker_callback: function(obj) { - var button_addfile = Y.one("#btnadd-"+this.client_id); this.filecount++; + this.check_buttons(); + this.refresh(this.currentpath); + }, + check_buttons: function() { + var button_addfile = Y.one("#btnadd-"+this.client_id); if (this.filecount > 0) { Y.one("#btndwn-"+this.client_id).setStyle('display', 'inline'); } if (this.filecount >= this.maxfiles && this.maxfiles!=-1) { button_addfile.setStyle('display', 'none'); } - this.refresh(this.currentpath); }, refresh: function(filepath) { var scope = this; @@ -164,6 +167,8 @@ M.form_filemanager.init = function(Y, options) { scope: scope, params: {'filepath':filepath}, callback: function(id, obj, args) { + scope.filecount = obj.filecount; + scope.check_buttons(); scope.options = obj; scope.render(obj); } @@ -298,6 +303,8 @@ M.form_filemanager.init = function(Y, options) { scope: scope, params: params, callback: function(id, obj, args) { + scope.filecount = obj.filecount; + scope.check_buttons(); scope.options = obj; scope.render(obj); } diff --git a/repository/draftfiles_ajax.php b/repository/draftfiles_ajax.php index 0f910ddc9af2a..1b9903640c39e 100644 --- a/repository/draftfiles_ajax.php +++ b/repository/draftfiles_ajax.php @@ -59,6 +59,9 @@ $filepath = optional_param('filepath', '/', PARAM_PATH); $data = file_get_drafarea_files($draftid, $filepath); + $info = file_get_draft_area_info($draftid); + $data->filecount = $info['filecount']; + $data->filesize = $info['filesize']; echo json_encode($data); die;