[Zope-CVS] CVS: Packages/Moztop/moztop/content/lib - logmanager.js:1.1 logmessagedialog.xul:1.1 taskmanager.js:1.1
Stephan Richter
srichter@cbu.edu
Thu, 20 Mar 2003 10:11:23 -0500
Update of /cvs-repository/Packages/Moztop/moztop/content/lib
In directory cvs.zope.org:/tmp/cvs-serv27382/lib
Added Files:
logmanager.js logmessagedialog.xul taskmanager.js
Log Message:
Renaming continues:
Rename StatusBar --> statusbar
=== Added File Packages/Moztop/moztop/content/lib/logmanager.js ===
/*****************************************************************************
*
* Copyright (c) 2003 Zope Corporation and Contributors.
* All Rights Reserved.
*
* This software is subject to the provisions of the Zope Public License,
* Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
* WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
******************************************************************************
Library to handle log messages.
$Id: logmanager.js,v 1.1 2003/03/20 15:11:22 srichter Exp $
******************************************************************************/
/* Now subclass, then add methods */
LogManager.prototype = new DataSourceManager();
LogManager.prototype.constructor = LogManager;
LogManager.superclass = DataSourceManager;
function LogManager () {
/* This prototype manages interaction with the log viewer.
It creates an RDFDataSource from rdfds.js, grabs the
existing datasource from the logmessages-tree. It also
knows how to add messages and view the selected message.
Finally, it has a method for viewing the RDF contents in
a popup text box. */
// Initialization preocess
if( !(this instanceof LogManager) )
return new LogManager( );
DataSourceManager.call(this);
// Grep the right resource URL for storing it at the right place
this.profileurl = this.getProfileDirURL();
// Initialize RDF data source
this.elementid = "logmessages-tree";
this.ds = new RDFDataSource();
this.urn = "urn:moztop:logmessages";
// Define namespaces required for this RDF graph
this.dcns = "http://www.purl.org/dc/1.1#";
this.zoperdfns = "http://www.zope.org/rdf#";
this.ncns ="http://home.netscape.com/NC-rdf#";
// Setup log message property names
this.titleprop = this.dcns + "title";
this.descriptionprop = this.dcns + "description";
this.timeprop = this.zoperdfns + "time";
this.messageprop = this.zoperdfns + "message";
}
LogManager.prototype.attachDataSource = function() {
/* Called once when log is first loaded */
var lms=this.ds.getNode(this.urn);
lms.makeSeq();
// Now attach the datasource
var logmessages=document.getElementById(this.elementid);
logmessages.database.AddDataSource(this.ds.getRawDataSource());
logmessages.builder.rebuild();
// Create a log message on startup
this.addMessage("Init Log Manager","LogManager.attachDataSource",
"Initializing Log Manager.");
return;
}
LogManager.prototype.addMessage = function(msgtitle, msglocation, msg) {
/* title is the short message, msg is full text displayed on dblclick
msglocation and msg are optional, so that one can use the log manager
for debugging as well.
*/
// Create message date
var date = new Date();
var now = date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
// If there was no location specified, make it null
if (!msglocation)
msglocation = "None specified";
// If there was no message passed, make the message equal the title
if (!msg)
msg = msgtitle;
// Create new RDF message node in graph
var rootnode = this.ds.getNode(this.urn);
var thismsg = this.ds.getNode(this.urn + ":" + date.getTime());
// Add a new log message to the RDF graph.
rootnode.addChild(thismsg);
thismsg.addTarget(this.titleprop, msgtitle);
thismsg.addTarget(this.descriptionprop, msglocation);
thismsg.addTarget(this.timeprop, now);
thismsg.addTarget(this.messageprop, msg);
}
LogManager.prototype.viewSelectedMessage = function () {
/* When a user doubleclicks on a message in the log, this
is called. It finds the selected item in the tree
and pops up a dialog box with the contents of the log message. */
var tree = document.getElementById(this.elementid);
var index = tree.view.selection.currentIndex;
var rdf = tree.view.getItemAtIndex(index).resource;
// Grab the RDF value and popup a dialog window
var node = this.ds.getNode(rdf.Value);
var msg = node.getTarget(this.messageprop);
window.openDialog("chrome://moztop/content/lib/logmessagedialog.xul",
"viewlogmessage", "chrome", msg.getValue());
}
function dump(msg) {
/* Convinience function to allow dump calls to be redirected to the Log
Manager. */
var MAXTITLELENGTH = 40;
if (msg.length < MAXTITLELENGTH)
title = msg;
else
title = msg.slice(0, MAXTITLELENGTH)+"..."
logmanager.addMessage(title, "", msg);
}
/* Initialize the data in the tree object. */
function initLogManager() {
// Remember that logmanager was defined globally, but not initialized.
logmanager = LogManager();
logmanager.attachDataSource();
}
=== Added File Packages/Moztop/moztop/content/lib/logmessagedialog.xul ===
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
<dialog id="logmessage" title="View Log Message"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
buttons="accept"
onload="loadMessage();"
ondialogaccept="return;">
<script>
function loadMessage () {
var msg = window.arguments[0];
var textspot=document.getElementById("textSpot");
while (textspot.childNodes.length > 0)
textspot.removeChild(textspot.childNodes[0]);
textspot.appendChild(document.createTextNode(msg));
return;
}
</script>
<html:div id="textSpot" xmlns:html="http://www.w3.org/1999/xhtml"
style="white-space: pre; overflow: scroll; height: 20em;
width: 30em; background-color: white">
</html:div>
</dialog>
=== Added File Packages/Moztop/moztop/content/lib/taskmanager.js ===
/*****************************************************************************
*
* Copyright (c) 2002, 2003 Zope Corporation and Contributors.
* All Rights Reserved.
*
* This software is subject to the provisions of the Zope Public License,
* Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
* WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
******************************************************************************
Library to handle Task Manager.
$Id: taskmanager.js,v 1.1 2003/03/20 15:11:22 srichter Exp $
******************************************************************************/
/* Now subclass, then add methods */
TaskManager.prototype = new DataSourceManager();
TaskManager.prototype.constructor = TaskManager;
TaskManager.superclass = DataSourceManager;
function TaskManager () {
/* This prototype manages interaction with the log viewer.
It creates an RDFDataSource from rdfds.js, grabs the
existing datasource from the logmessages-tree. It also
knows how to add messages and view the selected message.
Finally, it has a method for viewing the RDF contents in
a popup text box. */
// Initialization preocess
if( !(this instanceof TaskManager) )
return new TaskManager( );
DataSourceManager.call(this);
this.id = 0
// Grep the right resource URL for storing it at the right place
this.profileurl = this.getProfileDirURL();
// Initialize RDF data source
this.elementid = "tasks-tree";
this.ds = new RDFDataSource();
this.urn = "urn:moztop:tasks";
// Define namespaces required for this RDF graph
this.dcns = "http://www.purl.org/dc/1.1#";
this.zoperdfns = "http://www.zope.org/rdf#";
this.ncns ="http://home.netscape.com/NC-rdf#";
// Setup tasks property names
this.idprop = this.dcns + "id";
this.titleprop = this.dcns + "title";
this.descriptionprop = this.dcns + "description";
this.timeprop = this.zoperdfns + "time";
this.statusprop = this.zoperdfns + "status";
}
TaskManager.prototype.attachDataSource = function() {
/* Called once when tasks manager is first loaded */
var lms = this.ds.getNode(this.urn);
lms.makeSeq();
// Now attach the datasource
var tasks = document.getElementById(this.elementid);
tasks.database.AddDataSource(this.ds.getRawDataSource());
tasks.builder.rebuild();
// Create a log message on startup
logmanager.addMessage("Init Task Manager","TaskManager.attachDataSource",
"Task Manager has been initialized.");
}
TaskManager.prototype.addTask = function(title, description, status) {
/* Add a task to the manager; description and status is optional.
*/
// Create id of task
id++;
id = this.id;
// Create task start date
var date = new Date();
var now = date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
// If there was no status passed, make it "In progress"
if (!status)
status = "In progress";
// Create new RDF message node in graph
var rootnode = this.ds.getNode(this.urn);
var task = this.ds.getNode(this.urn + ":" + id);
// Add a new log message to the RDF graph.
rootnode.addChild(task);
task.addTarget(this.idprop, id);
task.addTarget(this.titleprop, title);
task.addTarget(this.descriptionprop, description);
task.addTarget(this.status, status);
task.addTarget(this.timeprop, now);
}
TaskManager.prototype.deleteTask = function(id) {
this.ds.deleteRecursive(this.urn + ":" + id);
}
TaskManager.prototype.viewSelectedTask = function() {
/* When a user doubleclicks on a task in the tree, this
is called. It finds the selected item in the tree
and pops up a dialog box with the contents of the task. */
var tree = document.getElementById(this.elementid);
var index = tree.view.selection.currentIndex;
var rdf = tree.view.getItemAtIndex(index).resource;
// Grab the RDF value and popup a dialog window
var node = this.ds.getNode(rdf.Value);
var task = node.getTarget(this.messageprop);
window.openDialog("chrome://moztop/content/lib/logmessagedialog.xul",
"viewtask", "chrome", task.getValue());
}
/* Initialize the data in the tree object. */
function initTaskManager() {
// Remember that logmanager was defined globally, but not initialized.
taskmanager = TaskManager();
taskmanager.attachDataSource();
}