1 //
  2 // The Antville Project
  3 // http://code.google.com/p/antville
  4 //
  5 // Copyright 2001-2007 by The Antville People
  6 //
  7 // Licensed under the Apache License, Version 2.0 (the ``License'');
  8 // you may not use this file except in compliance with the License.
  9 // You may obtain a copy of the License at
 10 //
 11 //    http://www.apache.org/licenses/LICENSE-2.0
 12 //
 13 // Unless required by applicable law or agreed to in writing, software
 14 // distributed under the License is distributed on an ``AS IS'' BASIS,
 15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 16 // See the License for the specific language governing permissions and
 17 // limitations under the License.
 18 //
 19 // $Revision$
 20 // $LastChangedBy$
 21 // $LastChangedDate$
 22 // $URL$
 23 //
 24 
 25 /**
 26  * @fileOverview Defines the LogEntry prototype.
 27  */
 28 
 29 /**
 30  * @name LogEntry
 31  * @constructor
 32  * @param {HopObject} context
 33  * @param {String} action
 34  * @property {String} action
 35  * @property {HopObject} context
 36  * @property {Number} context_id
 37  * @property {String} context_type
 38  * @property {Date} created
 39  * @property {User} creator
 40  * @property {String} referrer 
 41  * @extends HopObject
 42  */
 43 LogEntry.prototype.constructor = function(context, action) {
 44    this.context = context;
 45    this.action = action;
 46    this.referrer = req.data.http_referer;
 47    this.creator = session.user;
 48    this.created = new Date;
 49    // Won't be stored in database
 50    this.ip = req.data.http_remotehost;
 51    this.site = res.handlers.site;
 52    return this;
 53 }
 54 
 55 /**
 56  * @returns {String}
 57  */
 58 LogEntry.prototype.toString = function() {
 59    return "[LogEntry #" + this._id + ": " + (this.creator || "anonymous") + 
 60          " requested " + this.action + " action of " + this.context_type + 
 61          " #" + this.context_id + " on " + formatDate(this.created) + "]";
 62 } 
 63 
 64 /**
 65  * 
 66  * @param {String} name
 67  * @returns {HopObject}
 68  */
 69 LogEntry.prototype.getMacroHandler = function(name) {
 70    switch (name) {
 71       case "context":
 72       return this.context || {name: this.context_id};
 73    }
 74    return null;
 75 }
 76 
 77 /**
 78  * 
 79  * @param {Object} param
 80  */
 81 LogEntry.prototype.label_macro = function(param) {
 82    if (!User.require(User.PRIVILEGED)) {
 83       return;
 84    }
 85    switch (this.context_type) {
 86       case "Site" :
 87       res.write("<span class=\"flagDark\" style=\"background-color:#006600;\">SITE</span>");
 88       break;
 89       case "User" :
 90       res.write("<span class=\"flagDark\" style=\"background-color:#009900;\">USER</span>");
 91       break;
 92       default :
 93       res.write("<span class=\"flagLight\" style=\"background-color:#FFCC00;\">ROOT</span>");
 94    }
 95    return;
 96 }
 97