Permalink
Browse files

testing contenteditable

  • Loading branch information...
Cornu committed Dec 2, 2010
1 parent 889a7b6 commit 27e3b2b81f79eb1e49814bbba00ac26682623d64
Showing with 8,744 additions and 38 deletions.
  1. +1 −0 README
  2. +4 −5 brain/controllers/auth.py
  3. +29 −3 brain/controllers/text.py
  4. +13 −0 brain/helpers.py
  5. +56 −0 brain/static/editable.js
  6. +292 −0 brain/static/icons/format/alignc.svg
  7. +292 −0 brain/static/icons/format/alignf.svg
  8. +292 −0 brain/static/icons/format/alignl.svg
  9. +292 −0 brain/static/icons/format/alignr.svg
  10. +335 −0 brain/static/icons/format/blist.svg
  11. +199 −0 brain/static/icons/format/bold.svg
  12. +374 −0 brain/static/icons/format/dindent.svg
  13. +447 −0 brain/static/icons/format/head1.svg
  14. +489 −0 brain/static/icons/format/head2.svg
  15. +531 −0 brain/static/icons/format/head3.svg
  16. +374 −0 brain/static/icons/format/iindent.svg
  17. +167 −0 brain/static/icons/format/italic.svg
  18. +208 −0 brain/static/icons/format/line.svg
  19. +380 −0 brain/static/icons/format/nlist.svg
  20. +187 −0 brain/static/icons/format/old/Crystal_Clear_app_fonts.svg
  21. +300 −0 brain/static/icons/format/old/Format-indent-less.svg
  22. +295 −0 brain/static/icons/format/old/Format-indent-more.svg
  23. +269 −0 brain/static/icons/format/old/Format-justify-center.svg
  24. +269 −0 brain/static/icons/format/old/Format-justify-fill.svg
  25. +199 −0 brain/static/icons/format/old/Format-justify-left.svg
  26. +269 −0 brain/static/icons/format/old/Format-justify-right.svg
  27. +316 −0 brain/static/icons/format/old/Format-text-bold.svg
  28. +321 −0 brain/static/icons/format/old/Format-text-italic.svg
  29. +410 −0 brain/static/icons/format/old/Format-text-strikethrough.svg
  30. +423 −0 brain/static/icons/format/old/Format-text-underline.svg
  31. +349 −0 brain/static/icons/format/size.svg
  32. +210 −0 brain/static/icons/format/strike.svg
  33. +24 −10 brain/static/index.css
  34. +1 −0 brain/static/layout.css
  35. +29 −8 brain/static/main.js
  36. +28 −0 brain/static/new.css
  37. +16 −0 brain/templates/edit_doc.html
  38. +16 −12 brain/templates/index.html
  39. +38 −0 brain/templates/new_html.html
View
1 README
@@ -12,3 +12,4 @@ TOOLS
- Flask-OpenID ( http://packages.python.org/Flask-OpenID/ )
- Flask-LessCSS ( http://pypi.python.org/pypi/flask-lesscss/ )
- Flask-WTF ( http://packages.python.org/Flask-WTF/ )
+- Flask Celery ( http://celeryproject.org/ )
@@ -67,12 +67,11 @@ def create_profile():
return render_template('create_profile.html', next_url=oid.get_next_url())
@auth.route('/profile', methods=['GET', 'POST'])
+@login_required
def edit_profile():
""" Update the profile """
- if g.user is None:
- return redirect(url_for('login'))
- user = g.couch[g.user['nickname']]
- form = dict(name=user['name'], email=user['email'], nickname=user['_id'])
+ user = g.couch.get(g.user['nickname'])
+ form = dict(name=user['name'], email=user['email'], nickname=user['nickname'])
if request.method == 'POST':
if 'delete' in request.form:
g.couch.delete(g.user)
@@ -93,7 +92,7 @@ def edit_profile():
user['name'] = form['name']
user['email'] = form['email']
user['nickname'] = form['nickname']
- g.couch[g.user['_id']] = user
+ g.couch.save(user)
return redirect(url_for('edit_profile'))
return render_template('edit_profile.html', form=form)
View
@@ -1,18 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from flask import Module, render_template, g, request, flash, url_for, redirect
+from flask import Module, render_template, g, request, flash, url_for, \
+ redirect, jsonify
from uuid import uuid1
from brain.couchviews import *
from brain.helpers import *
text = Module(__name__)
@text.route('/new', methods=['GET', 'POST'])
+@login_required
def new():
""" Creates a new Text Entry """
- if g.user is None:
- return redirect(url_for('login'))
if request.method == 'POST':
subject = request.form['subject']
text = request.form['edit']
@@ -43,6 +43,32 @@ def search():
key = request.form.get('search')
return redirect('/'+key)
+@text.route('/id/<doc_id>')
+def get_doc(doc_id):
+ return jsonify(g.couch[doc_id]) #TODO rohes json empfangen
+
+@text.route('/edit/<doc_id>', methods=['GET', 'POST'])
+@login_required
+def edit_doc(doc_id):
+ doc = g.couch.get(doc_id)
+ if doc is None:
+ return redirect(url_for('index'))
+ if request.method == 'POST':
+ if not request.form['subject']:
+ flash(u'Error: you have to enter a Subject')
+ else:
+ flash(u'Entry successfully updated')
+ doc['title'] = request.form['subject']
+ doc['content'] = request.form['edit']
+ doc['type'] = request.form['type']
+ g.couch.save(doc)
+ return redirect(url_for('index'))
+ return render_template('edit_doc.html', doc=doc)
+
+@text.route('/html')
+def new_html():
+ return render_template('new_html.html')
+
@text.route('/')
def index():
texts = all_text_view()
View
@@ -3,6 +3,8 @@
from datetime import datetime
import math
+from functools import wraps
+from flask import g, request, redirect, url_for
def get_date():
return datetime.utcnow().strftime('%Y/%m/%d %H:%M:%S')
@@ -21,3 +23,14 @@ def datetimeformat(value):
else:
formatting = 'on %d %b %Y'
return value.strftime(formatting)
+
+def login_required(f):
+ """ Decorator Function redirecting to Login
+ if no permission
+ """
+ @wraps(f)
+ def decorated_function(*args, **kwargs):
+ if g.user is None:
+ return redirect(url_for('auth.login'))
+ return f(*args, **kwargs)
+ return decorated_function
View
@@ -0,0 +1,56 @@
+var edit_doc;
+
+$(document).ready(function() {
+ edit_doc = $('#edit');
+ designMode('on');
+
+ $('#bold').click(function(){
+ editCommand('bold');
+ });
+ $('#italic').click(function(){
+ editCommand('italic');
+ });
+ $('#line').click(function(){
+ editCommand('underline');
+ });
+ $('#strike').click(function(){
+ editCommand('strikethrough');
+ });
+ $('#size').click(function(){
+ editCommand('Bold');
+ });
+ $('#heading').click(function(){
+ editCommand('Bold');
+ });
+ $('#nlist').click(function(){
+ editCommand('insertorderedlist');
+ });
+ $('#blist').click(function(){
+ editCommand('insertunorderedlist');
+ });
+ $('#iindent').click(function(){
+ editCommand('indent');
+ });
+ $('#dindent').click(function(){
+ editCommand('outdent');
+ });
+ $('#alignl').click(function(){
+ editCommand('justifyleft');
+ });
+ $('#alignc').click(function(){
+ editCommand('justifycenter');
+ });
+ $('#alignr').click(function(){
+ editCommand('justifyright');
+ });
+
+});
+
+function designMode(mode){
+ edit_doc[0].contentDocument.designMode=mode;
+}
+
+function editCommand(aName, aArg){
+ edit_doc[0].contentDocument.execCommand(aName, false, aArg);
+ edit_doc[0].contentWindow.focus();
+}
Oops, something went wrong.

0 comments on commit 27e3b2b

Please sign in to comment.