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 markgettext("Log Entry");
 30 markgettext("log entry");
 31 
 32 /**
 33  * @name LogEntry
 34  * @constructor
 35  * @param {HopObject} context
 36  * @param {String} action
 37  * @property {String} action
 38  * @property {HopObject} context
 39  * @property {Number} context_id
 40  * @property {String} context_type
 41  * @property {Date} created
 42  * @property {User} creator
 43  * @property {String} referrer 
 44  * @extends HopObject
 45  */
 46 LogEntry.prototype.constructor = function(context, action) {
 47    this.context = context;
 48    this.action = action;
 49    this.referrer = req.data.http_referer;
 50    this.creator = session.user;
 51    this.created = new Date;
 52    // Won't be stored in database
 53    this.ip = req.data.http_remotehost;
 54    this.site = res.handlers.site;
 55    return this;
 56 }
 57 
 58 /**
 59  * @returns {String}
 60  */
 61 LogEntry.prototype.toString = function() {
 62    return "[LogEntry #" + this._id + ": " + (this.creator || "anonymous") + 
 63          " requested " + this.action + " action of " + this.context_type + 
 64          " #" + this.context_id + " on " + formatDate(this.created) + "]";
 65 } 
 66 
 67 /**
 68  * 
 69  * @param {String} name
 70  * @returns {HopObject}
 71  */
 72 LogEntry.prototype.getMacroHandler = function(name) {
 73    switch (name) {
 74       case "context":
 75       return this.context || {name: this.context_id};
 76    }
 77    return null;
 78 }
 79 
 80 /**
 81  * 
 82  * @param {Object} param
 83  */
 84 LogEntry.prototype.label_macro = function(param) {
 85    if (!User.require(User.PRIVILEGED)) {
 86       return;
 87    }
 88    switch (this.context_type) {
 89       case "Site" :
 90       res.write("<span class=\"flagDark\" style=\"background-color:#006600;\">SITE</span>");
 91       break;
 92       case "User" :
 93       res.write("<span class=\"flagDark\" style=\"background-color:#009900;\">USER</span>");
 94       break;
 95       default :
 96       res.write("<span class=\"flagLight\" style=\"background-color:#FFCC00;\">ROOT</span>");
 97    }
 98    return;
 99 }
100