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 this.ip = req.data.http_remotehost; // Won't be stored in database 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