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