witten
/
luminotes
Archived
1
0
Fork 0

More forum-specific stuff.

This commit is contained in:
Dan Helfman 2008-10-27 16:23:27 -07:00
parent 272240ba41
commit 21a05befe0
6 changed files with 62 additions and 28 deletions

View File

@ -2,7 +2,7 @@ GECKO = /Gecko/.test( navigator.userAgent ) && !/like Gecko/.test( navigator.use
WEBKIT = /WebKit/.test( navigator.userAgent );
function Editor( id, notebook_id, note_text, deleted_from_id, revision, read_write, startup, highlight, focus, position_after, start_dirty ) {
function Editor( id, notebook_id, note_text, deleted_from_id, revision, read_write, startup, highlight, focus, position_after, start_dirty, own_notes_only ) {
this.id = id;
this.notebook_id = notebook_id;
this.initial_text = note_text;
@ -11,6 +11,7 @@ function Editor( id, notebook_id, note_text, deleted_from_id, revision, read_wri
this.revision = revision;
this.user_revisions = new Array(); // cache for this note's list of revisions, loaded from the server on-demand
this.read_write = read_write; // whether the user has read-write access to this Editor
this.own_notes_only = own_notes_only; // whether the user only has read-write access to their own notes
this.edit_enabled = read_write && !deleted_from_id; // whether editing is actually enabled for this Editor
this.startup = startup || false; // whether this Editor is for a startup note
this.init_highlight = highlight || false;
@ -65,18 +66,20 @@ function Editor( id, notebook_id, note_text, deleted_from_id, revision, read_wri
} );
connect( this.changes_button, "onclick", function ( event ) { signal( self, "changes_clicked", event ); } );
this.options_button = createDOM( "input", {
"type": "button",
"class": "note_button",
"id": "options_" + iframe_id,
"value": "options",
"title": "note options"
} );
connect( this.options_button, "onclick", function ( event ) { signal( self, "options_clicked", event ); } );
if ( !own_notes_only ) {
this.options_button = createDOM( "input", {
"type": "button",
"class": "note_button",
"id": "options_" + iframe_id,
"value": "options",
"title": "note options"
} );
connect( this.options_button, "onclick", function ( event ) { signal( self, "options_clicked", event ); } );
}
}
}
if ( !this.deleted_from_id && ( read_write || !startup ) ) {
if ( !this.deleted_from_id && ( read_write || !startup ) && !own_notes_only ) {
this.hide_button = createDOM( "input", {
"type": "button",
"class": "note_button",

View File

@ -35,7 +35,8 @@ function Wiki( invoker ) {
else
this.total_notes_count = null;
this.note_tree = new Note_tree( this, this.notebook_id, this.invoker );
if ( getElement( "note_tree_root_table" ) )
this.note_tree = new Note_tree( this, this.notebook_id, this.invoker );
this.recent_notes = new Recent_notes( this, this.notebook_id, this.invoker );
// grab the current notebook from the list of available notebooks
@ -318,7 +319,8 @@ Wiki.prototype.populate = function ( startup_notes, current_notes, note_read_wri
connect( window, "onunload", function ( event ) { self.editor_focused( null, true ); } );
connect( "newNote", "onclick", this, "create_blank_editor" );
connect( "createLink", "onclick", this, "toggle_link_button" );
connect( "attachFile", "onclick", this, "toggle_attach_button" );
if ( this.notebook.read_write == NOTEBOOK_READ_WRITE )
connect( "attachFile", "onclick", this, "toggle_attach_button" );
connect( "bold", "onclick", function ( event ) { self.toggle_button( event, "bold" ); } );
connect( "italic", "onclick", function ( event ) { self.toggle_button( event, "italic" ); } );
connect( "underline", "onclick", function ( event ) { self.toggle_button( event, "underline" ); } );
@ -329,7 +331,8 @@ Wiki.prototype.populate = function ( startup_notes, current_notes, note_read_wri
this.make_image_button( "newNote", "new_note" );
this.make_image_button( "createLink", "link" );
this.make_image_button( "attachFile", "attach" );
if ( this.notebook.read_write == NOTEBOOK_READ_WRITE )
this.make_image_button( "attachFile", "attach" );
this.make_image_button( "bold" );
this.make_image_button( "italic" );
this.make_image_button( "underline" );
@ -737,12 +740,14 @@ Wiki.prototype.parse_loaded_editor = function ( result, note_title, requested_re
Wiki.prototype.create_editor = function ( id, note_text, deleted_from_id, revision, creation, read_write, highlight, focus, position_after, user_id ) {
var self = this;
var dirty = false;
var own_note_only = false;
if ( read_write == NOTEBOOK_READ_ONLY )
read_write = false;
else if ( read_write == NOTEBOOK_READ_WRITE )
read_write = true;
else if ( read_write == NOTEBOOK_READ_WRITE_FOR_OWN_NOTES ) {
own_notes_only = true;
if ( user_id == this.user.object_id )
read_write = true;
else
@ -780,7 +785,7 @@ Wiki.prototype.create_editor = function ( id, note_text, deleted_from_id, revisi
}
var startup = this.startup_notes[ id ];
var editor = new Editor( id, this.notebook_id, note_text, deleted_from_id, revision, read_write, startup, highlight, focus, position_after, dirty );
var editor = new Editor( id, this.notebook_id, note_text, deleted_from_id, revision, read_write, startup, highlight, focus, position_after, dirty, own_notes_only );
if ( this.notebook.read_write ) {
connect( editor, "state_changed", this, "editor_state_changed" );
@ -1165,6 +1170,9 @@ Wiki.prototype.connect_image_button = function ( button, filename_prefix ) {
Wiki.prototype.down_image_button = function ( name ) {
var button = getElement( name );
if ( !button )
return;
var toolbar_image_dir = this.get_toolbar_image_dir( button.always_small );
if ( !this.resize_toolbar_button( button ) && /_down/.test( button.src ) )
@ -1174,11 +1182,13 @@ Wiki.prototype.down_image_button = function ( name ) {
button.src = toolbar_image_dir + button.filename_prefix + "_button_down_hover.png";
else
button.src = toolbar_image_dir + button.filename_prefix + "_button_down.png";
}
Wiki.prototype.up_image_button = function ( name ) {
var button = getElement( name );
if ( !button )
return;
var toolbar_image_dir = this.get_toolbar_image_dir( button.always_small );
if ( !this.resize_toolbar_button( button ) && !/_down/.test( button.src ) )
@ -1192,6 +1202,9 @@ Wiki.prototype.up_image_button = function ( name ) {
Wiki.prototype.toggle_image_button = function ( name ) {
var button = getElement( name );
if ( !button )
return;
var toolbar_image_dir = this.get_toolbar_image_dir( button.always_small );
if ( /_down/.test( button.src ) ) {
@ -2545,7 +2558,11 @@ Wiki.prototype.delete_all_editors = function ( event ) {
}
this.zero_total_notes_count();
removeElement( "note_tree_root_table" );
var note_tree_root_table = getElement( "note_tree_root_table" );
if ( note_tree_root_table )
removeElement( note_tree_root_table );
this.display_empty_message( true );
event.stop();

View File

@ -166,7 +166,7 @@ class Link_area( Div ):
id = u"this_notebook_area",
),
Div(
( not forum_tag ) and Div(
( len( linked_notebooks ) > 0 ) and H4(
u"notebooks",
Img(
@ -202,7 +202,7 @@ class Link_area( Div ):
class_ = u"link_area_item",
) for nb in linked_notebooks ],
id = u"notebooks_area"
),
) or None,
( user.username is None and notebook_path != "/" ) and P(
A( u"Download", href = u"/download", class_ = u"hook_action" ),

View File

@ -159,7 +159,9 @@ class Main_page( Page ):
Div(
Note_tree_area(
Toolbar(
hide_toolbar = parent_id or notebook.read_write == Notebook.READ_ONLY
notebook,
hide_toolbar = parent_id or notebook.read_write == Notebook.READ_ONLY,
note_word = ( notebook.read_write == Notebook.READ_WRITE_FOR_OWN_NOTES ) and u"post" or u"note",
),
notebook,
root_notes,

View File

@ -6,18 +6,28 @@ class Note_tree_area( Div ):
LINK_PATTERN = re.compile( u'<a\s+(?:[^>]+\s)?href="[^"]+"[^>]*>', re.IGNORECASE )
def __init__( self, toolbar, notebook, root_notes, recent_notes, total_notes_count ):
tags = [ tag for tag in notebook.tags if tag.name == u"forum" ]
if tags:
forum_name = tags[ 0 ].value
forum_tag = True
else:
forum_name = None
forum_tag = False
Div.__init__(
self,
toolbar,
Div(
H4( u"notes",
H4(
forum_tag and u"posts" or u"notes",
Span(
Span( total_notes_count, id = u"total_notes_count" ), u"total",
class_ = u"small_text link_area_item",
),
id = u"note_tree_area_title",
),
self.make_tree(
) or None,
( not forum_tag ) and self.make_tree(
[ self.make_item(
title = note.title,
link_attributes = u'href="/notebooks/%s?note_id=%s"' % ( notebook.object_id, note.object_id ),
@ -31,8 +41,8 @@ class Note_tree_area( Div ):
class_ = ( ( len( root_notes ) > 0 ) and u"undisplayed" or u"" ),
) ) or None,
tree_id = "note_tree_root_table",
),
( recent_notes is not None and notebook.name != u"trash" ) and Span(
) or None,
( not forum_tag and recent_notes is not None and notebook.name != u"trash" ) and Span(
H4( u"recent updates",
id = u"recent_notes_area_title",
),

View File

@ -1,15 +1,16 @@
from Tags import P, Div, A, Input, Span, Br
from model.Notebook import Notebook
class Toolbar( Div ):
def __init__( self, hide_toolbar = False ):
def __init__( self, notebook, hide_toolbar = False, note_word = None ):
Div.__init__(
self,
Div(
P(
Div( Input(
type = u"image",
id = u"newNote", title = u"new note [ctrl-N]",
id = u"newNote", title = u"new %s [ctrl-N]" % ( note_word or u"note" ),
src = u"/static/images/toolbar/new_note_button.png",
width = u"40", height = u"40",
class_ = "image_button",
@ -21,13 +22,14 @@ class Toolbar( Div ):
width = u"40", height = u"40",
class_ = "image_button",
) ),
Div( Input(
# Notebook.READ_WRITE_FOR_OWN_NOTES should not have a file upload button
( notebook.read_write == Notebook.READ_WRITE ) and Div( Input(
type = u"image",
id = u"attachFile", title = u"attach file or image",
src = u"/static/images/toolbar/attach_button.png",
width = u"40", height = u"40",
class_ = "image_button",
) ),
) ) or None,
),
P(
Div( Input(