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