plugins/kolab_files

Aleksander Machniak machniak at kolabsys.com
Fri Jun 7 12:57:07 CEST 2013


 plugins/kolab_files/kolab_files.js                   |  141 ++++++++++++++-----
 plugins/kolab_files/lib/kolab_files_engine.php       |   30 ++++
 plugins/kolab_files/localization/en_US.inc           |    3 
 plugins/kolab_files/skins/larry/style.css            |    9 +
 plugins/kolab_files/skins/larry/templates/files.html |    3 
 5 files changed, 152 insertions(+), 34 deletions(-)

New commits:
commit 8f0609564040c19b092489bb651ace814baeb213
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Fri Jun 7 12:56:32 2013 +0200

    Implemented file rename, improvements files list request handling

diff --git a/plugins/kolab_files/kolab_files.js b/plugins/kolab_files/kolab_files.js
index c39c910..1495208 100644
--- a/plugins/kolab_files/kolab_files.js
+++ b/plugins/kolab_files/kolab_files.js
@@ -83,7 +83,7 @@ window.rcmail && rcmail.addEventListener('init', function() {
     }
 
     // "one file only" commands
-    rcmail.env.file_commands = ['files-get'];
+    rcmail.env.file_commands = ['files-get', 'files-edit'];
     // "one or more file" commands
     rcmail.env.file_commands_all = ['files-delete', 'files-move', 'files-copy'];
 
@@ -176,18 +176,14 @@ function kolab_directory_selector_dialog(id)
   };
 
   // show dialog window
-  dialog.dialog({
-    modal: true,
-    resizable: !bw.ie6,
-    closeOnEscape: (!bw.ie6 && !bw.ie7),  // disable for performance reasons
+  kolab_dialog_show(dialog, {
     title: rcmail.gettext('kolab_files.' + (id ? 'saveto' : 'saveall')),
-//    close: function() { rcmail.dialog_close(); },
     buttons: buttons,
     minWidth: 250,
     minHeight: 300,
     height: 350,
     width: 300
-    }).show();
+  });
 
   if (!rcmail.env.folders_loaded) {
     file_api.folder_list();
@@ -229,18 +225,14 @@ function kolab_files_selector_dialog()
   };
 
   // show dialog window
-  dialog.dialog({
-    modal: true,
-    resizable: !bw.ie6,
-    closeOnEscape: (!bw.ie6 && !bw.ie7),  // disable for performance reasons
+  kolab_dialog_show(dialog, {
     title: rcmail.gettext('kolab_files.selectfiles'),
-//    close: function() { rcmail.dialog_close(); },
     buttons: buttons,
     minWidth: 500,
     minHeight: 300,
     width: 700,
     height: 500
-    }).show();
+  });
 
   if (!rcmail.env.files_loaded) {
     file_api.folder_list();
@@ -289,18 +281,14 @@ function kolab_files_folder_create_dialog()
   };
 
   // show dialog window
-  dialog.dialog({
-    modal: true,
-    resizable: !bw.ie6,
-    closeOnEscape: (!bw.ie6 && !bw.ie7),  // disable for performance reasons
+  kolab_dialog_show(dialog, {
     title: rcmail.gettext('kolab_files.foldercreate'),
-//    close: function() { rcmail.dialog_close(); },
     buttons: buttons,
     minWidth: 400,
     minHeight: 300,
     width: 500,
     height: 400
-    }).show();
+  });
 
   // build parent selector
   select.append($('<option>').val('').text('---'));
@@ -317,6 +305,52 @@ function kolab_files_folder_create_dialog()
   });
 };
 
+// file edition dialog
+function kolab_files_file_edit_dialog(file)
+{
+  var dialog = $('#files-file-edit-dialog'),
+    buttons = {}, name = file_api.file_name(file)
+    input = $('input[name="name"]', dialog).val(name);
+
+  buttons[rcmail.gettext('kolab_files.save')] = function () {
+    var folder = file_api.file_path(file), name = input.val();
+
+    if (!name)
+      return;
+
+    name = folder + file_api.env.directory_separator + name;
+
+    // @TODO: now we only update filename
+    if (name != file)
+      file_api.file_rename(file, name);
+    dialog.dialog('destroy').hide();
+  };
+  buttons[rcmail.gettext('kolab_files.cancel')] = function () {
+    dialog.dialog('destroy').hide();
+  };
+
+  // show dialog window
+  kolab_dialog_show(dialog, {
+    title: rcmail.gettext('kolab_files.fileedit'),
+    buttons: buttons
+  });
+};
+
+function kolab_dialog_show(dialog, params)
+{
+  params = $.extend({
+    modal: true,
+    resizable: !bw.ie6,
+    closeOnEscape: (!bw.ie6 && !bw.ie7),  // disabled for performance reasons
+    minWidth: 400,
+    minHeight: 300,
+    width: 500,
+    height: 400
+  }, params || {});
+
+  dialog.dialog(params).show();
+};
+
 // smart upload button
 function kolab_files_upload_input(button)
 {
@@ -632,6 +666,14 @@ rcube_webmail.prototype.files_open = function()
     file_api.file_open(files[0], rcmail.env.viewer);
 };
 
+rcube_webmail.prototype.files_edit = function()
+{
+  var files = this.env.file ? [this.env.file] : kolab_files_selected();
+
+  if (files.length == 1)
+    file_api.file_edit_start(files[0]);
+};
+
 rcube_webmail.prototype.files_set_quota = function(p)
 {
   if (p.total) {
@@ -653,6 +695,8 @@ rcube_webmail.prototype.files_set_quota = function(p)
 
 function kolab_files_ui()
 {
+  this.requests = {};
+
 /*
   // Called on "session expired" session
   this.logout = function(response) {};
@@ -795,8 +839,6 @@ function kolab_files_ui()
     rcmail.enable_command('files-folder-delete', 'files-upload', false);
     this.env.folder = null;
     this.env.collection = null;
-
-    this.quota();
   };
 
   // folder create request
@@ -864,6 +906,13 @@ function kolab_files_ui()
     if (!params)
       params = {};
 
+    // reset all pending list requests
+    for (i in this.requests) {
+      this.requests[i].abort();
+      rcmail.hide_message(i);
+      delete this.requests[i];
+    }
+
     if (params.all_folders) {
       params.collection = null;
       params.folder = null;
@@ -891,20 +940,23 @@ function kolab_files_ui()
 
     // empty the list
     this.env.file_list = [];
-    rcmail.file_list.clear();
+    rcmail.file_list.clear(true);
 
     // request
     if (params.collection || params.all_folders)
       this.file_list_loop(params);
     else if (this.env.folder) {
-      this.req = this.set_busy(true, 'loading');
-      this.request('file_list', params, 'file_list_response');
+      params.req_id = this.set_busy(true, 'loading');
+      this.requests[params.req_id] = this.request('file_list', params, 'file_list_response');
     }
   };
 
   // file list response handler
   this.file_list_response = function(response)
   {
+    if (response.req_id)
+      rcmail.hide_message(response.req_id);
+
     if (!this.response(response))
       return;
 
@@ -945,9 +997,9 @@ function kolab_files_ui()
     this.env.folders_loop_lock = false;
 
     for (i=0; i<folders.length && i<limit; i++) {
-      this.req = this.set_busy(true, 'loading');
+      params.req_id = this.set_busy(true, 'loading');
       params.folder = folders.shift();
-      this.request('file_list', params, 'file_list_loop_response');
+      this.requests[params.req_id] = this.request('file_list', params, 'file_list_loop_response');
     }
   };
 
@@ -959,10 +1011,13 @@ function kolab_files_ui()
       limit = Math.max(this.env.search_threads || 1, 1),
       valid = this.response(response);
 
+    if (response.req_id)
+      rcmail.hide_message(response.req_id);
+
     for (i=0; i<folders.length && i<limit; i++) {
-      this.req = this.set_busy(true, 'loading');
+      params.req_id = this.set_busy(true, 'loading');
       params.folder = folders.shift();
-      this.request('file_list', params, 'file_list_loop_response');
+      this.requests[params.req_id] = this.request('file_list', params, 'file_list_loop_response');
     }
 
     if (!valid)
@@ -1060,7 +1115,7 @@ function kolab_files_ui()
       else if (c == 'size')
         col = '<td class="size">' + this.file_size(data.size) + '</td>';
       else if (c == 'options')
-        col = '<td class="options"></td>'; // @TODO
+        col = '<td class="options"><span></span></td>';
       else
         col = '<td class="' + c + '"></td>';
 
@@ -1071,6 +1126,10 @@ function kolab_files_ui()
       .html(row)
       .attr({id: 'rcmrow' + index, 'data-file': file, 'data-type': data.type});
 
+    $('td.options > span', row).click(function(e) {
+      kolab_files_file_edit_dialog(file);
+    });
+
     // collection (or search) lists files from all folders
     // display file name with full path as title
     if (!this.env.folder)
@@ -1259,15 +1318,12 @@ function kolab_files_ui()
       };
 
     // open jquery UI dialog
-    dialog.dialog({
-      modal: true,
-      resizable: !bw.ie6,
-      closeOnEscape: (!bw.ie6 && !bw.ie7),  // disable for performance reasons
+    kolab_dialog_show(dialog.html(text), {
       close: skip_func,
       buttons: buttons,
       minWidth: 400,
       width: 400
-    }).html(text).show();
+    });
   };
 
   // file move (with overwrite) response handler
@@ -1286,6 +1342,23 @@ function kolab_files_ui()
     }
   };
 
+  // file(s) rename request
+  this.file_rename = function(oldfile, newfile)
+  {
+    this.req = this.set_busy(true, 'kolab_files.fileupdating');
+    this.request('file_move', {file: oldfile, 'new': newfile}, 'file_rename_response');
+  };
+
+  // file(s) move response handler
+  this.file_rename_response = function(response)
+  {
+    if (!this.response(response))
+      return;
+
+    // @TODO: we could update metadata instead
+    this.file_list();
+  };
+
   // file upload request
   this.file_upload = function(form)
   {
diff --git a/plugins/kolab_files/lib/kolab_files_engine.php b/plugins/kolab_files/lib/kolab_files_engine.php
index 246abb6..467459d 100644
--- a/plugins/kolab_files/lib/kolab_files_engine.php
+++ b/plugins/kolab_files/lib/kolab_files_engine.php
@@ -100,6 +100,7 @@ class kolab_files_engine
             $this->rc->output->add_handlers(array(
                 'folder-create-form' => array($this, 'folder_create_form'),
                 'file-search-form'   => array($this, 'file_search_form'),
+                'file-edit-form'     => array($this, 'file_edit_form'),
                 'filelist'           => array($this, 'file_list'),
                 'filequotadisplay'   => array($this, 'quota_display'),
             ));
@@ -168,6 +169,35 @@ class kolab_files_engine
     }
 
     /**
+     * Template object for file_edit form
+     */
+    public function file_edit_form($attrib)
+    {
+        $attrib['name'] = 'file-edit-form';
+        if (empty($attrib['id'])) {
+            $attrib['id'] = 'file-edit-form';
+        }
+
+        $input_name    = new html_inputfield(array('id' => 'file-name', 'name' => 'name', 'size' => 30));
+        $table         = new html_table(array('cols' => 2, 'class' => 'propform'));
+
+        $table->add('title', html::label('file-name', Q($this->plugin->gettext('filename'))));
+        $table->add(null, $input_name->show());
+
+        $out = $table->show();
+
+        // add form tag around text field
+        if (empty($attrib['form'])) {
+            $out = $this->rc->output->form_tag($attrib, $out);
+        }
+
+        $this->plugin->add_label('save', 'cancel', 'fileupdating', 'fileedit');
+        $this->rc->output->add_gui_object('file-edit-form', $attrib['id']);
+
+        return $out;
+    }
+
+    /**
      * Template object for file search form in "From cloud" dialog
      */
     public function file_search_form($attrib)
diff --git a/plugins/kolab_files/localization/en_US.inc b/plugins/kolab_files/localization/en_US.inc
index 96c49bf..f75f950 100644
--- a/plugins/kolab_files/localization/en_US.inc
+++ b/plugins/kolab_files/localization/en_US.inc
@@ -26,7 +26,9 @@ $labels['get'] = 'Download';
 $labels['getfile'] = 'Download file';
 $labels['view'] = 'View';
 $labels['viewfile'] = 'View file';
+$labels['rename'] = 'Rename file';
 $labels['deletefile'] = 'Delete selected file(s)';
+$labels['fileedit'] = 'File properties';
 
 $labels['collection_audio'] = 'Audio';
 $labels['collection_video'] = 'Video';
@@ -43,6 +45,7 @@ $labels['foldercreatenotice'] = 'Folder created successfully.';
 $labels['saveallnotice'] = 'Successfully saved $n file(s).';
 $labels['saveallerror'] = 'Saving $n file(s) failed.';
 $labels['attacherror'] = 'Failed to attach file(s) from the cloud';
+$labels['fileupdating'] = 'Updating file...';
 $labels['filemoving'] = 'Moving file(s)...';
 $labels['filecopying'] = 'Copying file(s)...';
 $labels['filedeleting'] = 'Deleting file(s)...';
diff --git a/plugins/kolab_files/skins/larry/style.css b/plugins/kolab_files/skins/larry/style.css
index 06ff3e1..b41c369 100644
--- a/plugins/kolab_files/skins/larry/style.css
+++ b/plugins/kolab_files/skins/larry/style.css
@@ -168,6 +168,7 @@
 
 #filelist tr td.options {
   width: 26px;
+  cursor: pointer;
 }
 
 #filelist thead tr td.filename,
@@ -214,6 +215,13 @@
   padding: 0 3px;
 }
 
+#filelist tbody tr td.options:hover span {
+  width: 26px;
+  height: 18px;
+  background: url(../../../../skins/larry/images/buttons.png) -5px -418px no-repeat;
+  display: block;
+}
+
 #filelist td.filename {
   padding: 0 4px;
 }
@@ -249,6 +257,7 @@
 
 #files-dialog,
 #files-compose-dialog,
+#files-file-edit-dialog,
 #files-folder-create-dialog {
   display: none;
 }
diff --git a/plugins/kolab_files/skins/larry/templates/files.html b/plugins/kolab_files/skins/larry/templates/files.html
index fc45ca9..cc4e709 100644
--- a/plugins/kolab_files/skins/larry/templates/files.html
+++ b/plugins/kolab_files/skins/larry/templates/files.html
@@ -60,6 +60,9 @@
 <div id="files-folder-create-dialog">
     <roundcube:object name="folder-create-form" />
 </div>
+<div id="files-file-edit-dialog">
+    <roundcube:object name="file-edit-form" />
+</div>
 
 <div id="listoptions" class="propform popupdialog">
 <roundcube:if condition="!in_array('kolab_files_list_cols', (array)config:dont_override)" />





More information about the commits mailing list