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