function Wiki( invoker ) { this.next_id = null; this.focused_editor = null; this.blank_editor_id = null; this.notebook = null; this.notebook_id = getElement( "notebook_id" ).value; this.parent_id = getElement( "parent_id" ).value; // id of the notebook containing this one this.startup_notes = new Array(); // map of startup notes: note id to bool this.open_editors = new Array(); // map of open notes: note title to editor this.all_notes_editor = null; // editor for display of list of all notes this.search_results_editor = null; // editor for display of search results this.invoker = invoker; this.rate_plan = evalJSON( getElement( "rate_plan" ).value ); this.storage_usage_high = false; // grab the current notebook from the list of available notebooks var notebooks = evalJSON( getElement( "notebooks" ).value ); for ( var i in notebooks ) { if ( notebooks[ i ].object_id == this.notebook_id ) { this.notebook = notebooks[ i ] break; } } // populate the wiki with startup notes this.populate( evalJSON( getElement( "startup_notes" ).value || "null" ), evalJSON( getElement( "note" ).value || "null" ), evalJSON( getElement( "note_read_write" ).value || "true" ) ); this.display_storage_usage( evalJSON( getElement( "storage_bytes" ).value || "0" ) ); connect( this.invoker, "error_message", this, "display_error" ); connect( this.invoker, "message", this, "display_message" ); connect( "search_form", "onsubmit", this, "search" ); connect( "html", "onclick", this, "background_clicked" ); var self = this; var logout_link = getElement( "logout_link" ); if ( logout_link ) { connect( "logout_link", "onclick", function ( event ) { self.save_editor( null, true ); self.invoker.invoke( "/users/logout", "POST" ); event.stop(); } ); } } Wiki.prototype.update_next_id = function ( result ) { this.next_id = result.next_id; } Wiki.prototype.display_storage_usage = function( storage_bytes ) { if ( !storage_bytes ) return; // display the user's current storage usage var MEGABYTE = 1024 * 1024; function bytes_to_megabytes( storage_bytes ) { return Math.round( storage_bytes / MEGABYTE ); } var quota_bytes = this.rate_plan.storage_quota_bytes; if ( !quota_bytes ) return; var usage_percent = Math.round( storage_bytes / quota_bytes * 100.0 ); if ( usage_percent > 90 ) { var storage_usage_class = "storage_usage_high"; if ( this.storage_usage_high == false ) this.display_message( "You are currently using " + usage_percent + "% of your available storage space. Please delete some notes, empty the trash, or upgrade your account." ); this.storage_usage_high = true; } else if ( usage_percent > 75 ) { var storage_usage_class = "storage_usage_medium"; this.storage_usage_high = false; } else { var storage_usage_class = "storage_usage_low"; this.storage_usage_high = false; } replaceChildNodes( "storage_usage_area", createDOM( "div", { "class": storage_usage_class }, bytes_to_megabytes( storage_bytes ) + " MB (" + usage_percent + "%) of " + bytes_to_megabytes( quota_bytes ) + " MB" ) ); } Wiki.prototype.populate = function ( startup_notes, note, note_read_write ) { // create an editor for each startup note in the received notebook, focusing the first one var focus = true; for ( var i in startup_notes ) { var startup_note = startup_notes[ i ]; this.startup_notes[ startup_note.object_id ] = true; // don't actually create an editor if a particular note was provided in the result if ( !note ) { var editor = this.create_editor( startup_note.object_id, // grab this note's contents from the static