Commit aa59ce1d authored by oggei's avatar oggei

* Switched to fckeditor for producing wikitext (#17), reviewing templates accordingly

parent f798d79d
......@@ -56,6 +56,8 @@ sqlalchemy.url = mysql://ngv:ngv@localhost/ngv
languages = en/English, it/Italian, fr/French, es/Spanish, de/German, pt/Portuguese
uploadserver_host = 'blah'
# Logging configuration
[loggers]
keys = root, ngv_frontend
......
......@@ -38,47 +38,57 @@ class DocsController(BaseController):
c.index_data = model.Document.index()
return render('docs/all_pages.html')
def edit_commit(self, title):
contents = request.params.get('contents')
parent_id = request.params.get('parent_id', '')
username = h.logged_author().username
doc = model.Document.query.filter_by(title=title).first()
if doc:
# see if the contents changed at all
if doc.latest_revision().contents != contents:
doc.add_revision(contents, username)
# re-parent logic
if doc.parent and parent_id != doc.parent.id:
if parent_id:
def edit(self, title):
def save(title):
contents = request.params.get('contents')
parent_id = request.params.get('parent_id', '')
username = h.logged_author().username
doc = model.Document.query.filter_by(title=title).first()
if doc:
# see if the contents changed at all
if doc.latest_revision().contents != contents:
doc.add_revision(contents, username)
# re-parent logic
if doc.parent and parent_id != doc.parent.id:
if parent_id:
doc.parent = model.Document.query.get(parent_id)
else:
doc.parent = None
elif not doc.parent and parent_id:
doc.parent = model.Document.query.get(parent_id)
else:
doc.parent = None
elif not doc.parent and parent_id:
doc.parent = model.Document.query.get(parent_id)
else:
doc = model.Document.create(
title=title, contents=contents,
username=username, parent_id=parent_id
)
model.Session.add(doc)
model.Session.commit()
redirect = 'view'
# handle attachment uploads
if hasattr(request.params.get('attachment'), 'filename'):
att = model.DocumentAttachment(document=doc, file=request.POST['attachment'])
model.Session.save(att)
redirect = 'edit'
# eventually remove attachments
if request.params.get('attachment_to_delete'):
a_id = request.params['attachment_to_delete']
att = model.DocumentAttachment.query.get(a_id)
doc.attachments.remove(att)
model.Session.delete(att)
redirect = 'edit'
model.Session.commit()
redirect_to(action=redirect, title=title)
else:
doc = model.Document.create(
title=title, contents=contents,
username=username, parent_id=parent_id
)
model.Session.add(doc)
model.Session.commit()
redirect = 'view'
# handle attachment uploads
if hasattr(request.params.get('attachment'), 'filename'):
att = model.DocumentAttachment(document=doc, file=request.POST['attachment'])
model.Session.save(att)
redirect = 'edit'
# eventually remove attachments
if request.params.get('attachment_to_delete'):
a_id = request.params['attachment_to_delete']
att = model.DocumentAttachment.query.get(a_id)
doc.attachments.remove(att)
model.Session.delete(att)
redirect = 'edit'
model.Session.commit()
redirect_to(action=redirect, title=title)
if request.method == 'POST':
if request.POST.get('mode') == 'preview':
return h.wikify(
request.POST.get('wikitext', 'error occurred')
)
elif request.POST.get('mode') == 'save':
return save(title)
elif request.GET.get('mode') == 'debug':
return '<form method="post" action="#"><input type="hidden" name="mode" value="preview" /><input type="text" name="wikitext" value="cane" /></form>'
def edit(self, title):
c.doc = model.Document.query.filter_by(title=title).first()
if c.doc:
c.parent_id = c.doc.parent_id
......
......@@ -14,6 +14,7 @@ from pylons import g
from webhelpers.rails.wrapped import *
from routes import url_for, redirect_to
from wikimarkup import parse as wikify
def logged_in():
if session.has_key('logged_in'):
......@@ -85,6 +86,23 @@ def sizefmt(size):
units = 'bytes'
return '%.3g %s' % (size, units)
# initialize the FCK editor
def fckeditor_init(textArea):
'''adapted from vanilla distro'''
return '''<script type="text/javascript" src="%s"></script>
<script type="text/javascript">
window.onload = function()
{
var oFCKeditor = new FCKeditor( '%s' ) ;
oFCKeditor.BasePath = "%s" ;
oFCKeditor.ReplaceTextarea() ;
}
</script>
''' % (
url_for('/javascripts/fckeditor/fckeditor.js'),
textArea,
url_for('/javascripts/fckeditor/'))
# initialize the tinyMCE editor
def tinymce_init(theme='simple'):
......
This diff is collapsed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
* Copyright (C) 2003-2008 Frederico Caldeira Knabben
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of any of the following licenses at your
* choice:
*
* - GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
* http://www.gnu.org/licenses/lgpl.html
*
* - Mozilla Public License Version 1.1 or later (the "MPL")
* http://www.mozilla.org/MPL/MPL-1.1.html
*
* == END LICENSE ==
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FCKeditor - Documentation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body { font-family: arial, verdana, sans-serif }
p { margin-left: 20px }
</style>
</head>
<body>
<h1>
FCKeditor Documentation</h1>
<p>
You can find the official documentation for FCKeditor online, at <a href="http://docs.fckeditor.net/">
http://docs.fckeditor.net/</a>.</p>
</body>
</html>
/*
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
* Copyright (C) 2003-2008 Frederico Caldeira Knabben
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of any of the following licenses at your
* choice:
*
* - GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
* http://www.gnu.org/licenses/lgpl.html
*
* - Mozilla Public License Version 1.1 or later (the "MPL")
* http://www.mozilla.org/MPL/MPL-1.1.html
*
* == END LICENSE ==
*
* This is the sample plugin definition file.
*/
// Register the related commands.
FCKCommands.RegisterCommand( 'My_Find' , new FCKDialogCommand( FCKLang['DlgMyFindTitle'] , FCKLang['DlgMyFindTitle'] , FCKConfig.PluginsPath + 'findreplace/find.html' , 340, 170 ) ) ;
FCKCommands.RegisterCommand( 'My_Replace' , new FCKDialogCommand( FCKLang['DlgMyReplaceTitle'], FCKLang['DlgMyReplaceTitle'] , FCKConfig.PluginsPath + 'findreplace/replace.html', 340, 200 ) ) ;
// Create the "Find" toolbar button.
var oFindItem = new FCKToolbarButton( 'My_Find', FCKLang['DlgMyFindTitle'] ) ;
oFindItem.IconPath = FCKConfig.PluginsPath + 'findreplace/find.gif' ;
FCKToolbarItems.RegisterItem( 'My_Find', oFindItem ) ; // 'My_Find' is the name used in the Toolbar config.
// Create the "Replace" toolbar button.
var oReplaceItem = new FCKToolbarButton( 'My_Replace', FCKLang['DlgMyReplaceTitle'] ) ;
oReplaceItem.IconPath = FCKConfig.PluginsPath + 'findreplace/replace.gif' ;
FCKToolbarItems.RegisterItem( 'My_Replace', oReplaceItem ) ; // 'My_Replace' is the name used in the Toolbar config.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
* Copyright (C) 2003-2008 Frederico Caldeira Knabben
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of any of the following licenses at your
* choice:
*
* - GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
* http://www.gnu.org/licenses/lgpl.html
*
* - Mozilla Public License Version 1.1 or later (the "MPL")
* http://www.mozilla.org/MPL/MPL-1.1.html
*
* == END LICENSE ==
*
* This is the sample "Find" plugin window.
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta content="noindex, nofollow" name="robots">
<script type="text/javascript">
var oEditor = window.parent.InnerDialogLoaded() ;
function OnLoad()
{
// Whole word is available on IE only.
if ( oEditor.FCKBrowserInfo.IsIE )
document.getElementById('divWord').style.display = '' ;
// First of all, translate the dialog box texts.
oEditor.FCKLanguageManager.TranslatePage( document ) ;
window.parent.SetAutoSize( true ) ;
}
function btnStat(frm)
{
document.getElementById('btnFind').disabled =
( document.getElementById('txtFind').value.length == 0 ) ;
}
function ReplaceTextNodes( parentNode, regex, replaceValue, replaceAll )
{
for ( var i = 0 ; i < parentNode.childNodes.length ; i++ )
{
var oNode = parentNode.childNodes[i] ;
if ( oNode.nodeType == 3 )
{
var sReplaced = oNode.nodeValue.replace( regex, replaceValue ) ;
if ( oNode.nodeValue != sReplaced )
{
oNode.nodeValue = sReplaced ;
if ( ! replaceAll )
return true ;
}
}
else
{
if ( ReplaceTextNodes( oNode, regex, replaceValue ) )
return true ;
}