Skip to content

Commit

Permalink
Item10300: dumping abandoned-work-in-progress AutoSavePlugin into svn
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/AutoSavePlugin@10640 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OliverKrueger authored and OliverKrueger committed Jan 31, 2011
0 parents commit 9b28568
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 0 deletions.
22 changes: 22 additions & 0 deletions data/System/AutoSavePlugin.txt
@@ -0,0 +1,22 @@
---+ !AutoSavePlugin

---++ Settings

* Set SHORTDESCRIPTION = Saves a topic automatically. Periods: 10 sec, 15 sec, 30 sec, 1 min, 2 min, 5 min. WARNING! Don't use it in combination with the Foswiki:Extensions.EditChapterPlugin.

---++ Plugin Info

| Plugin Author: | Foswiki:Main.ThomasZobel, Foswiki:Main.OliverKrueger |
| Copyright: | 2009, Thomas Zobel %BR% 2010 Oliver Krueger |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Plugin Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 31 Mar 2010: | Fixed compatibility with newer !TinyMCE |
| 16 Feb 2009: | Initial version |
| Foswiki Dependency: | $Foswiki::Plugins::VERSION 1.1 |
| CPAN Dependencies: | none |
| Dependencies: | %$DEPENDENCIES% |
| Perl Version: | 5.006 |
| Plugin Home: | http://foswiki.org/Extensions/%TOPIC% |

__Related Topics:__ [[%SYSTEMWEB%.Plugins][Plugins]]
79 changes: 79 additions & 0 deletions lib/Foswiki/Plugins/AutoSavePlugin.pm
@@ -0,0 +1,79 @@
package Foswiki::Plugins::AutoSavePlugin;

use strict;
use vars
qw( $VERSION $RELEASE $SHORTDESCRIPTION $debug $pluginName $NO_PREFS_IN_TOPIC );
use Unicode::MapUTF8();

$VERSION = '$Rev$';
$RELEASE = '0.9';
$SHORTDESCRIPTION = 'Saves topics automatically';
$NO_PREFS_IN_TOPIC = 1;

$pluginName = 'AutoSavePlugin';

sub initPlugin {
my ( $topic, $web, $user, $installWeb ) = @_;

Foswiki::Func::registerRESTHandler( 'autoSaveTopic', \&_autoSaveTopic );

if ($Foswiki::cfg{Plugins}{JQueryPlugin}{Enabled}) {
require Foswiki::Plugins::JQueryPlugin;
Foswiki::Plugins::JQueryPlugin::registerPlugin("AutoSave",
'Foswiki::Plugins::AutoSavePlugin::AUTOSAVE');
# Foswiki::Plugins::JQueryPlugin::createPlugin("AutoSave");
}

return 1;
}

sub DISABLE_beforeEditHandler {
my $web = $_[2];
my $topic = $_[1];

my $language = Foswiki::Func::getPreferencesValue( 'LANGUAGE', $Foswiki::cfg{UsersWebName} ) || 'en';
my $wikiName = Foswiki::Func::getWikiName();

my $binPath = Foswiki::Func::getScriptUrl();
Foswiki::Func::addToHEAD( 'AUTOSAVE',
'<style text="text/css">#autoSaveBox { margin-top:10px; } #autoSaveBox select { margin-right:10px; border:1px solid #a7a7a7; }</style><script type="text/javascript">var userLanguage = "'
. $language
. '"; var autoSaveBinPath = "'
. $binPath
. '"; var autoSaveWeb = "'
. $web
. '"; var autoSaveTopic = "'
. $topic
. '";</script><script type="text/javascript" src="%PUBURL%/%SYSTEMWEB%/AutoSavePlugin/autosave.js" /></script>'
);
}

sub _autoSaveTopic {
my ( $session, $params, $topic, $web ) = @_;

my $query = Foswiki::Func::getCgiQuery();
my $topicContent;
my $currentWeb;
my $currentTopic;
my @getTopic;

# TODO: use Foswiki::UTF82SiteCharSet() here
$topicContent = Unicode::MapUTF8::from_utf8(
{ -string => $query->param("text"), -charset => 'ISO-8859-1' } );
$currentWeb = Unicode::MapUTF8::from_utf8(
{ -string => $query->param("web"), -charset => 'ISO-8859-1' } );
$currentTopic = Unicode::MapUTF8::from_utf8(
{ -string => $query->param("topic"), -charset => 'ISO-8859-1' } );

my ( $meta, $text ) =
Foswiki::Func::readTopic( $currentWeb, $currentTopic );

@getTopic = split( /\./, $currentTopic );
$currentTopic = $getTopic[1];

# SMELL: checkAccessPermissions!!!!!
Foswiki::Func::saveTopic( $currentWeb, $currentTopic, $meta,
$topicContent );
}

1;
57 changes: 57 additions & 0 deletions lib/Foswiki/Plugins/AutoSavePlugin/AUTOSAVE.pm
@@ -0,0 +1,57 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Javascript is Copyright (C) 2009 Thomas Zobel
#
# Packaged 2010 for Foswiki by Oliver Krueger, oliver@wiki-one.net
#
# 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.
#
# 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. See the GNU General Public License for more details,
# published at http://www.gnu.org/copyleft/gpl.html

package Foswiki::Plugins::AutoSavePlugin::AUTOSAVE;
use strict;
use warnings;
use Foswiki::Plugins::JQueryPlugin::Plugin;
our @ISA = qw( Foswiki::Plugins::JQueryPlugin::Plugin );

=begin TML
---+ package Foswiki::Plugins::AutoSavePlugin::AUTOSAVE;
This is the perl stub for the autosave plugin.
=cut

=begin TML
---++ ClassMethod new( $class, $session, ... )
Constructor
=cut

sub new {
my $class = shift;
my $session = shift || $Foswiki::Plugins::SESSION;

my $this = bless($class->SUPER::new(
$session,
name => 'AutoSave',
version => '1.0.0',
author => 'Thomas Zobel, Oliver Krueger',
homepage => 'http://foswiki.org/Extensions/AutoSavePlugin',
documentation => "$Foswiki::cfg{SystemWebName}.AutoSavePlugin",
puburl => '%PUBURLPATH%/%SYSTEMWEB%/AutoSavePlugin',
javascript => ['autosave.js']
), $class);

return $this;
}

1;
6 changes: 6 additions & 0 deletions lib/Foswiki/Plugins/AutoSavePlugin/DEPENDENCIES
@@ -0,0 +1,6 @@
# Dependencies for AutoSavePlugin
# Example:
# Time::ParseDate,>=2003.0211,cpan,Required.
# Foswiki::Plugins,>=1.2,perl,Requires version 1.2 of handler API.
Foswiki::Plugins::JQueryPlugin,>=0.4,perl,Requires version 0.4 of JQueryPlugin.

6 changes: 6 additions & 0 deletions lib/Foswiki/Plugins/AutoSavePlugin/MANIFEST
@@ -0,0 +1,6 @@
# Release manifest for AutoSavePlugin
data/System/AutoSavePlugin.txt 0644 Documentation
lib/Foswiki/Plugins/AutoSavePlugin.pm 0644 Perl module
lib/Foswiki/Plugins/AutoSavePlugin/AUTOSAVE.pm 0644 Perl module
pub/System/AutoSavePlugin/autosave.js 0644 Javascript code

24 changes: 24 additions & 0 deletions lib/Foswiki/Plugins/AutoSavePlugin/build.pl
@@ -0,0 +1,24 @@
#!/usr/bin/perl -w
BEGIN { unshift @INC, split( /:/, $ENV{FOSWIKI_LIBS} ); }
use Foswiki::Contrib::Build;

# Create the build object
$build = new Foswiki::Contrib::Build('AutoSavePlugin');

# (Optional) Set the details of the repository for uploads.
# This can be any web on any accessible Foswiki installation.
# These defaults will be used when expanding tokens in .txt
# files, but be warned, they can be overridden at upload time!

# name of web to upload to
$build->{UPLOADTARGETWEB} = 'Extensions';
# Full URL of pub directory
$build->{UPLOADTARGETPUB} = 'http://foswiki.org/pub';
# Full URL of bin directory
$build->{UPLOADTARGETSCRIPT} = 'http://foswiki.org/bin';
# Script extension
$build->{UPLOADTARGETSUFFIX} = '';

# Build the target on the command line, or the default target
$build->build($build->{target});

93 changes: 93 additions & 0 deletions pub/System/AutoSavePlugin/autosave.js
@@ -0,0 +1,93 @@
(function($){
$(function(){
var autoSaveContent = '';

/* TODO: use MAKETEXT instead */
if (userLanguage == 'de') {
autoSaveContent += '<div id="autoSaveBox">';
autoSaveContent += '<input type="checkbox" id="enableAutoSave" name="enableAutoSave" value="yes"/>';
autoSaveContent += '<label for="selectAutoSaveTime">Automatisches Speichern nach</label>';
autoSaveContent += '<select id="selectAutoSaveTime" name="selectAutoSaveTime">';
autoSaveContent += '<option value="10000">10 Sekunden</option>';
autoSaveContent += '<option value="15000" selected="selected">15 Sekunden</option>';
autoSaveContent += '<option value="30000">30 Sekunden</option>';
autoSaveContent += '<option value="60000">1 Minute</option>';
autoSaveContent += '<option value="120000">2 Minuten</option>';
autoSaveContent += '<option value="300000">5 Minuten</option>';
autoSaveContent += '</select>';
autoSaveContent += '<br />';
autoSaveContent += '</div>';

} else {
autoSaveContent += '<div id="autoSaveBox">';
autoSaveContent += '<input type="checkbox" id="enableAutoSave" name="enableAutoSave" value="yes" />';
autoSaveContent += '<label for="selectAutoSaveTime">Automatic save after</label>';
autoSaveContent += '<select id="selectAutoSaveTime" name="selectAutoSaveTime">';
autoSaveContent += '<option value="10000">10 seconds</option>';
autoSaveContent += '<option value="15000" selected="selected">15 seconds</option>';
autoSaveContent += '<option value="30000">30 seconds</option>';
autoSaveContent += '<option value="60000">1 minute</option>';
autoSaveContent += '<option value="120000">2 minutes</option>';
autoSaveContent += '<option value="300000">5 minutes</option>';
autoSaveContent += '</select>';
autoSaveContent += '<br />';
autoSaveContent += '</div>';
}

$('#cancel').after(autoSaveContent);

$('#selectAutoSaveTime').change(setEnableAutosaveTime);
$('#enableAutoSave').click(setEnableAutosaveTime);

if ($('#enableAutoSave:checked').val()) {
var autoSaveTime = 15000;
intervalActive = window.setInterval("saveTopic()", autoSaveTime);
} else {
intervalActive = 0;
}

});


function setEnableAutosaveTime() {
if ($('#enableAutoSave:checked').val()) {
autoSaveTime=$('#selectAutoSaveTime option:selected').val();
window.clearInterval(intervalActive);
intervalActive = window.setInterval("saveTopic()", autoSaveTime);
} else {
window.clearInterval(intervalActive);
}
}

function saveTopic() {

var textTopicTML;
var displayTopic = $('#topic').css('display');

if (displayTopic == 'none') {

var textTopicWYSIWYG = document.getElementById("mce_editor_0").contentWindow.document.body.innerHTML;

$.post(autoSaveBinPath + "/rest/WysiwygPlugin/html2tml", {text: textTopicWYSIWYG, topic: autoSaveWeb + '.' + autoSaveTopic},

function(data) {
$('#topic').val(data);
textTopicTML = $('#topic').val();
$.post( autoSaveBinPath + "/rest/AutoSavePlugin/autoSaveTopic",
{ text:textTopicTML,
web:autoSaveWeb,
topic:autoSaveWeb+'.'+ autoSaveTopic }
);
});

} else {
textTopicTML = $('#topic').val();
$.post( autoSaveBinPath + "/rest/AutoSavePlugin/autoSaveTopic",
{ text:textTopicTML,
web:autoSaveWeb,
topic:autoSaveWeb+'.'+ autoSaveTopic }
);
}
}

})(jQuery);

0 comments on commit 9b28568

Please sign in to comment.