Skip to content

Commit

Permalink
Item14223: working on it
Browse files Browse the repository at this point in the history
   * better humanization of file size values
   * more translations
   * separated Dialog component ... maybe travells further away
   * fixed filtering for no result hiding the widget all together
   * added dialog triggered by the paste event to change the filename of the clipboard content being uploaded
  • Loading branch information
MichaelDaum committed Jan 31, 2017
1 parent d3368e7 commit d3e63c5
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 201 deletions.
14 changes: 5 additions & 9 deletions lib/Foswiki/Plugins/TopicInteractionPlugin/Attachments.pm
Expand Up @@ -271,9 +271,10 @@ sub handle {
$text =~ s/\$name\b/$info->{name}/g;
$text =~ s/\$path\b/$info->{path}/g;
$text =~ s/\$size\b/$info->{size}/g;
$text =~ s/\$sizeH\b/$info->{sizeH}/g;
$text =~ s/\$sizeK\b/$info->{sizeK}/g;
$text =~ s/\$sizeM\b/$info->{sizeM}/g;
$text =~ s/\$sizeH\b/_humanizeBytes($info->{size})/ge;
$text =~ s/\$sizeK\b/_humanizeBytes($info->{size}, 'KB')/ge;
$text =~ s/\$sizeM\b/_humanizeBytes($info->{size}, 'MB')/ge;
$text =~ s/\$sizeG\b/_humanizeBytes($info->{size}, 'GB')/ge;
$text =~ s/\$sizeG\b/$info->{sizeG}/g;
$text =~ s/\$url\b/$url/g;
$text =~ s/\$urlpath\b/$urlPath/g;
Expand Down Expand Up @@ -323,18 +324,13 @@ sub getAttachmentInfo {

#print STDERR dump($attachment)."\n";

my $size = $attachment->{size} || 0;
my %info = (
name => $attachment->{name},
attr => ($attachment->{attr} || ''),
autoattached => $attachment->{autoattached} || 0,
date => $attachment->{date},
user => ($attachment->{user} || $attachment->{author} || 'UnknownUser'),
size => $size,
sizeH => _humanizeBytes($size),
sizeK => _humanizeBytes($size, 'KB'),
sizeM => _humanizeBytes($size, 'MB'),
sizeG => _humanizeBytes($size, 'GB'),
size => $attachment->{size} || 0,
comment => (defined $attachment->{comment}) ? $attachment->{comment} : '',
path => ($attachment->{path} || ''),
version => ($attachment->{version} || 1),
Expand Down
33 changes: 31 additions & 2 deletions lib/Foswiki/Plugins/TopicInteractionPlugin/MANIFEST
Expand Up @@ -16,9 +16,32 @@ lib/Foswiki/Plugins/TopicInteractionPlugin/DEPENDENCIES 0644
lib/Foswiki/Plugins/TopicInteractionPlugin.pm 0644
lib/Foswiki/Plugins/TopicInteractionPlugin/Uploader.pm 0644
lib/Foswiki/Plugins/TopicInteractionPlugin/WebDAVUrl.pm 0644
locale/TopicInteractionPlugin/bg.po 0644
locale/TopicInteractionPlugin/cs.po 0644
locale/TopicInteractionPlugin/da.po 0644
locale/TopicInteractionPlugin/de.po 0644
locale/TopicInteractionPlugin/el.po 0644
locale/TopicInteractionPlugin/es.po 0644
locale/TopicInteractionPlugin/fi.po 0644
locale/TopicInteractionPlugin/Foswiki.pot 0644
locale/TopicInteractionPlugin/fr.po 0644
locale/TopicInteractionPlugin/it.po 0644
locale/TopicInteractionPlugin/ja.po 0644
locale/TopicInteractionPlugin/ko.po 0644
locale/TopicInteractionPlugin/nl.po 0644
locale/TopicInteractionPlugin/no.po 0644
locale/TopicInteractionPlugin/pl.po 0644
locale/TopicInteractionPlugin/pt-br.po 0644
locale/TopicInteractionPlugin/pt.po 0644
locale/TopicInteractionPlugin/ru.po 0644
locale/TopicInteractionPlugin/sv.po 0644
locale/TopicInteractionPlugin/tlh.po 0644
locale/TopicInteractionPlugin/tr.po 0644
locale/TopicInteractionPlugin/uk.po 0644
locale/TopicInteractionPlugin/zh-cn.po 0644
locale/TopicInteractionPlugin/zh-tw.po 0644
pub/System/TopicInteractionPlugin/detectos.uncompressed.js 0644
pub/System/TopicInteractionPlugin/dialog.uncompressed.js 0644
pub/System/TopicInteractionPlugin/foswiki.attachments.uncompressed.js 0644
pub/System/TopicInteractionPlugin/foswiki.fileupload.uncompressed.js 0644
pub/System/TopicInteractionPlugin/i18n/cs.js 0644
Expand All @@ -35,11 +58,17 @@ pub/System/TopicInteractionPlugin/i18n/nl.js 0644
pub/System/TopicInteractionPlugin/i18n/pt-br.js 0644
pub/System/TopicInteractionPlugin/i18n/ru.js 0644
pub/System/TopicInteractionPlugin/i18n/sv.js 0644
pub/System/TopicInteractionPlugin/icons/document-export.png 0644
pub/System/TopicInteractionPlugin/icons/download.png 0644
pub/System/TopicInteractionPlugin/icons/insert-image.png 0644
pub/System/TopicInteractionPlugin/icons/insert-link.png 0644
pub/System/TopicInteractionPlugin/icons/trash-full.png 0644
pub/System/TopicInteractionPlugin/icons/trash.png 0644
pub/System/TopicInteractionPlugin/icons/white-bulb.png 0644
pub/System/TopicInteractionPlugin/icons/yellow-bulb.png 0644
pub/System/TopicInteractionPlugin/jquery.fileupload-process.js 0644
pub/System/TopicInteractionPlugin/jquery.fileupload-process.uncompressed.js 0644
pub/System/TopicInteractionPlugin/jquery.fileupload.uncompressed.js 0644
pub/System/TopicInteractionPlugin/jquery.uploader.css.gz 0644
pub/System/TopicInteractionPlugin/jquery.uploader.js.gz 0644
pub/System/TopicInteractionPlugin/LibreOfficeWebDAV.reg 0644
pub/System/TopicInteractionPlugin/Makefile 0644
pub/System/TopicInteractionPlugin/metadata.css 0644
Expand Down
5 changes: 1 addition & 4 deletions lib/Foswiki/Plugins/TopicInteractionPlugin/Uploader.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2010-2016 Michael Daum, http://michaeldaumconsulting.com
# Copyright (C) 2010-2017 Michael Daum, http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -18,11 +18,8 @@ package Foswiki::Plugins::TopicInteractionPlugin::Uploader;
use strict;
use warnings;

use Foswiki::Func ();
use Foswiki::Plugins ();
use Foswiki::Plugins::JQueryPlugin::Plugin ();
use Foswiki::Plugins::TopicInteractionPlugin::Core();
use JSON ();

our @ISA = qw( Foswiki::Plugins::JQueryPlugin::Plugin );

Expand Down
5 changes: 3 additions & 2 deletions pub/System/TopicInteractionPlugin/Makefile
Expand Up @@ -12,17 +12,18 @@ UPLOADER_SOURCE= \
METADATA_SOURCE= \
detectos.uncompressed.js \
webdav.uncompressed.js \
dialog.uncompressed.js \
foswiki.attachments.uncompressed.js

-include $(FOSWIKI_ROOT)/pub/System/JQueryPlugin/Makefile.include

.PRECIOUS: %.uncompressed.js

uploader.uncompressed.js: $(UPLOADER_SOURCE)
cat $^ > $@
@echo creating $@ from $^; echo "/* WARNING: THIS IS A DERIVED FILE. DON'T MODIFIY. */" > $@; $(CAT) $^ >> $@

metadata.uncompressed.js: $(METADATA_SOURCE)
cat $^ > $@
@echo creating $@ from $^; echo "/* WARNING: THIS IS A DERIVED FILE. DON'T MODIFIY. */" > $@; $(CAT) $^ >> $@

clean:
rm -f $(TARGET) *.gz igp_* genpdf_*
Expand Down
112 changes: 112 additions & 0 deletions pub/System/TopicInteractionPlugin/dialog.uncompressed.js
@@ -0,0 +1,112 @@
/*
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
(c)opyright 2017 Michael Daum http://michaeldaumconsulting.com
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
*/

/*eslint-disable no-console */

"use strict";
var Dialog;

(function($) {

var defaults = {
"template": "metadata",
"debug": false
};

/* constructor **********************************************************/
Dialog = function(opts) {
var self = this;

self.opts = $.extend({}, defaults, opts);
};

/* shortcut *************************************************************/
Dialog.load = function(opts) {
var dialog = new Dialog(opts);
return dialog.load();
};

/* logger ***************************************************************/
Dialog.prototype.log = function() {
var self = this, args;

if (!console || !self.opts.debug) {
return;
}

args = $.makeArray(arguments);
args.unshift("DIALOG:");
console.log.apply(console, args);
};


/* load *****************************************************************/
Dialog.prototype.load = function(params) {
var self = this,
opts = $.extend({}, self.opts, params),
$dialog = typeof(opts.id) === 'undefined'?undefined:$(opts.id),
data,
dfd = $.Deferred();

self.log("called load() opts=",opts);

function callback(elem) {
if (typeof(opts.init) === 'function') {
opts.init.call(elem);
}
}

if ($dialog && $dialog.length) {
$dialog.dialog("open");
$dialog.find("form").resetForm();
callback($dialog);
dfd.resolve($dialog);
} else {

data = $.extend({}, opts.data, {
name: opts.template,
expand: opts.expand,
topic: foswiki.getPreference("WEB")+"."+foswiki.getPreference("TOPIC")
});

$.ajax({
url: foswiki.getScriptUrl("rest", "RenderPlugin", "template"),
data: data,
dataType: 'html',
success: function(data) {
var $dialog = $(data);
$dialog.on("dialogopen", function() {
callback($dialog);
dfd.resolve($dialog);
});
$dialog.appendTo("body");
},
error: function(xhr, status, err) {
dfd.reject($dialog, status, err);
}
});
}

return dfd.promise();
};
})(jQuery);

0 comments on commit d3e63c5

Please sign in to comment.