plugins/kolab_files

Aleksander Machniak machniak at kolabsys.com
Wed Jun 12 12:38:13 CEST 2013


 plugins/kolab_files/kolab_files.js                         |   63 ++++++++++++-
 plugins/kolab_files/lib/kolab_files_engine.php             |    5 -
 plugins/kolab_files/localization/en_US.inc                 |    6 +
 plugins/kolab_files/skins/larry/images/buttons.png         |binary
 plugins/kolab_files/skins/larry/style.css                  |   12 ++
 plugins/kolab_files/skins/larry/templates/filepreview.html |    3 
 plugins/kolab_files/skins/larry/ui.js                      |   19 +++
 7 files changed, 97 insertions(+), 11 deletions(-)

New commits:
commit ef663058c72c6039d24594266f1b7fdc61ec2bc6
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Wed Jun 12 12:37:48 2013 +0200

    Implemented text file edition, other improvements

diff --git a/plugins/kolab_files/kolab_files.js b/plugins/kolab_files/kolab_files.js
index 9bf7b82..5455d3b 100644
--- a/plugins/kolab_files/kolab_files.js
+++ b/plugins/kolab_files/kolab_files.js
@@ -559,6 +559,16 @@ kolab_files_selected = function()
   return files;
 };
 
+kolab_files_frame_load = function(frame)
+{
+  var win = frame.contentWindow;
+
+  rcmail.file_editor = win.file_editor && win.file_editor.editable ? win.file_editor : null;
+
+  if (rcmail.file_editor)
+    rcmail.enable_command('files-edit', true);
+};
+
 
 /***********************************************************/
 /**********              Commands                 **********/
@@ -666,6 +676,25 @@ rcube_webmail.prototype.files_open = function()
     file_api.file_open(files[0], rcmail.env.viewer);
 };
 
+// enable file editor
+rcube_webmail.prototype.files_edit = function()
+{
+  if (this.file_editor) {
+    this.file_editor.enable();
+    this.enable_command('files-save', true);
+  }
+};
+
+rcube_webmail.prototype.files_save = function()
+{
+  if (!this.file_editor)
+    return;
+
+  var content = this.file_editor.getContent();
+
+  file_api.file_save(this.env.file, content);
+};
+
 rcube_webmail.prototype.files_set_quota = function(p)
 {
   if (p.total) {
@@ -747,7 +776,7 @@ function kolab_files_ui()
       var row = $('<li class="mailbox"><span class="branch"></span></li>');
 
       row.attr('id', f.id).data('folder', i)
-        .append($('<span class="name">').text(f.name))
+        .append($('<span class="name"></span>').text(f.name))
         .click(function() { file_api.folder_select(i); });
 
       if (f.depth)
@@ -776,7 +805,7 @@ function kolab_files_ui()
       var row = $('<li class="mailbox collection ' + n + '"></li>');
 
       row.attr('id', 'folder-collection-' + n)
-        .append($('<span class="name">').text(rcmail.gettext('kolab_files.collection_' + n)))
+        .append($('<span class="name"></span>').text(rcmail.gettext('kolab_files.collection_' + n)))
         .click(function() { file_api.folder_select(n, true); });
 
       list.append(row);
@@ -1433,4 +1462,34 @@ function kolab_files_ui()
     var href = '?' + $.param({_task: 'files', _action: 'open', file: file, viewer: viewer == 2 ? 1 : 0});
     rcmail.open_window(href, false, true);
   };
+
+  // save file
+  this.file_save = function(file, content)
+  {
+    rcmail.enable_command('files-save', false);
+    // because we currently can edit only text files
+    // and we do not expect them to be very big, we save
+    // file in a very simple way, no upload progress, etc.
+    this.req = this.set_busy(true, 'saving');
+    this.request('file_update', {file: file, content: content, info: 1}, 'file_save_response');
+  };
+
+  // file save response handler
+  this.file_save_response = function(response)
+  {
+    rcmail.enable_command('files-save', true);
+
+    if (!this.response(response))
+      return;
+
+    // update file properties table
+    var table = $('#fileinfobox table'), file = response.result;
+
+    if (file) {
+      $('td.filetype', table).text(file.type);
+      $('td.filesize', table).text(this.file_size(file.size));
+      $('td.filemtime', table).text(file.mtime);
+    }
+  };
+
 };
diff --git a/plugins/kolab_files/lib/kolab_files_engine.php b/plugins/kolab_files/lib/kolab_files_engine.php
index 467459d..022fd3e 100644
--- a/plugins/kolab_files/lib/kolab_files_engine.php
+++ b/plugins/kolab_files/lib/kolab_files_engine.php
@@ -444,7 +444,10 @@ class kolab_files_engine
 
         $this->rc->output->add_gui_object('preview_frame', $attrib['id']);
 
-        return html::iframe(array('id' => 'file-content', 'src' => $href));
+        $attrib['src']    = $href;
+        $attrib['onload'] = 'kolab_files_frame_load(this)';
+
+        return html::iframe($attrib);
     }
 
     /**
diff --git a/plugins/kolab_files/localization/en_US.inc b/plugins/kolab_files/localization/en_US.inc
index f75f950..c148856 100644
--- a/plugins/kolab_files/localization/en_US.inc
+++ b/plugins/kolab_files/localization/en_US.inc
@@ -27,7 +27,11 @@ $labels['getfile'] = 'Download file';
 $labels['view'] = 'View';
 $labels['viewfile'] = 'View file';
 $labels['rename'] = 'Rename file';
-$labels['deletefile'] = 'Delete selected file(s)';
+$labels['deletefile'] = 'Delete file(s)';
+$labels['edit'] = 'Edit';
+$labels['editfile'] = 'Edit file';
+$labels['save'] = 'Save';
+$labels['savefile'] = 'Save file';
 $labels['fileedit'] = 'File properties';
 
 $labels['collection_audio'] = 'Audio';
diff --git a/plugins/kolab_files/skins/larry/images/buttons.png b/plugins/kolab_files/skins/larry/images/buttons.png
index 661dbbc..6c83cf7 100644
Binary files a/plugins/kolab_files/skins/larry/images/buttons.png and b/plugins/kolab_files/skins/larry/images/buttons.png differ
diff --git a/plugins/kolab_files/skins/larry/style.css b/plugins/kolab_files/skins/larry/style.css
index b41c369..9f0b5e6 100644
--- a/plugins/kolab_files/skins/larry/style.css
+++ b/plugins/kolab_files/skins/larry/style.css
@@ -31,7 +31,7 @@
 }
 
 #filestoolbar a.button.get {
-  background-position: center -94px;
+  background-position: center -93px;
 }
 
 #filestoolbar a.button.open {
@@ -42,6 +42,14 @@
   background-image: url(../../../../skins/larry/images/buttons.png);
 }
 
+#filestoolbar a.button.edit {
+  background-position: center -173px;
+}
+
+#filestoolbar a.button.save {
+  background-position: center -213px;
+}
+
 #filestoolbar form {
   display: inline;
 }
@@ -325,5 +333,5 @@ a.filesaveall {
 }
 
 ul.toolbarmenu li span.saveas {
-  background: url(images/buttons.png) -5px -180px no-repeat;
+  background: url(images/buttons.png) -5px -253px no-repeat;
 }
diff --git a/plugins/kolab_files/skins/larry/templates/filepreview.html b/plugins/kolab_files/skins/larry/templates/filepreview.html
index 416cbc7..4657f2c 100644
--- a/plugins/kolab_files/skins/larry/templates/filepreview.html
+++ b/plugins/kolab_files/skins/larry/templates/filepreview.html
@@ -14,9 +14,8 @@
 
 <div id="filestoolbar" class="toolbar">
     <roundcube:button command="files-get" type="link" class="button get disabled" classAct="button get" classSel="button get pressed" label="kolab_files.get" title="kolab_files.getfile" />
-<!--
     <roundcube:button command="files-edit" type="link" class="button edit disabled" classAct="button edit" classSel="button edit pressed" label="kolab_files.edit" title="kolab_files.editfile" />
--->
+    <roundcube:button command="files-save" type="link" class="button save disabled" classAct="button save" classSel="button save pressed" label="kolab_files.save" title="kolab_files.savefile" style="display:none" />
     <roundcube:button command="files-delete" type="link" class="button delete disabled" classAct="button delete" classSel="button delete pressed" label="delete" title="kolab_files.deletefile" />
 </div>
 
diff --git a/plugins/kolab_files/skins/larry/ui.js b/plugins/kolab_files/skins/larry/ui.js
index 374e79e..aa2c30f 100644
--- a/plugins/kolab_files/skins/larry/ui.js
+++ b/plugins/kolab_files/skins/larry/ui.js
@@ -1,8 +1,11 @@
 function kolab_files_ui_init()
 {
-  if (rcmail.env.action == 'open')
+  if (rcmail.env.action == 'open') {
     var filesviewsplit = new rcube_splitter({ id:'filesopensplitter', p1:'#fileinfobox', p2:'#filecontent',
       orientation:'v', relative:true, start:226, min:150, size:12 }).init();
+
+    rcmail.addEventListener('enable-command', kolab_files_enable_command);
+  }
   else
     var filesviewsplit = new rcube_splitter({ id:'filesviewsplitter', p1:'#folderlistbox', p2:'#filelistcontainer',
       orientation:'v', relative:true, start:226, min:150, size:12 }).init();
@@ -28,10 +31,19 @@ function kolab_files_ui_init()
   kolab_files_upload_input('#filestoolbar a.upload');
 };
 
+function kolab_files_enable_command(p)
+{
+  if (p.command == 'files-save') {
+    var toolbar = $('#filestoolbar');
+    $('a.button.edit', toolbar).hide();
+    $('a.button.save', toolbar).show();
+  }
+};
+
 function kolab_files_update_quota(p)
 {
     return UI.update_quota(p);
-}
+};
 
 function kolab_files_show_listoptions()
 {
@@ -61,7 +73,8 @@ function kolab_files_show_listoptions()
     close: function() {
       $dialog.dialog('destroy').hide();
     },
-    width: 650
+    minWidth: 400,
+    width: $dialog.width()+20
   }).show();
 };
 





More information about the commits mailing list