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 TagHub prototype 27 */ 28 29 /** 30 * @name TagHub 31 * @constructor 32 * @param {String} name 33 * @param {Story|Image} tagged 34 * @param {User} user 35 * @property {Tag} tag 36 * @property {Number} tag_id 37 * @property {Story|Image} tagged 38 * @property {Number} tagged_id 39 * @property {String} tagged_type 40 * @property {User} user 41 * @extends HopObject 42 */ 43 TagHub.prototype.constructor = function(name, tagged, user) { 44 var site = tagged.site || res.handlers.site; 45 var tag = site.getTags(tagged._prototype, Tags.ALL).get(name); 46 if (!tag) { 47 tag = new Tag(name, site, tagged._prototype); 48 site.$tags.add(tag); 49 //res.commit(); 50 } 51 this.tag = tag; 52 this.tagged = tagged; 53 this.user = user; 54 return this; 55 } 56 57 /** 58 * 59 * @param {String} name 60 * @returns {HopObject} 61 */ 62 TagHub.prototype.getMacroHandler = function(name) { 63 switch (name.toLowerCase()) { 64 case "tagged": 65 case "story": 66 case "image": 67 return this.tagged; 68 break; 69 } 70 } 71 72 /** 73 * @return {String} 74 */ 75 TagHub.prototype.toString = function() { 76 return "Tag " + this.tag.name + " of " + this.tagged.toString(); 77 } 78