Colloquio.Views.Tag={};Colloquio.Views.Tag.TagView=Class.create({NEW_TAG_CLASS:'tags-new',TAGS_LIST_CLASS:'tags-list',TAG_NAME_INPUT_ID:'tag_name',_TAGS_CREATE_URI:'/tags/create',initialize:function(element,taggableId,taggableType)
{this.element=$(element);this.tagsListElement=this.element.selectFirstByClassName(this.TAGS_LIST_CLASS);this.newTagElement=this.element.selectFirstByClassName(this.NEW_TAG_CLASS);this.nameInput=$(this.TAG_NAME_INPUT_ID);this.nameAutoComplete=Colloquio.Dom.newNode(Colloquio.Html.Tag.DIV,{cssClass:Colloquio.Views.AUTO_COMPLETE_RESULTS_CLASS});this.nameInput.insert({after:this.nameAutoComplete});new Ajax.Autocompleter(this.nameInput,this.nameAutoComplete,'/tags/auto_complete',{paramName:'query',minChars:3,method:'get'});var form=$(this.element.getElementsByTagName(Colloquio.Html.Tag.FORM)[0]);form.onsubmit=function(){return false;}
form.observe('submit',this._submitForm.bindAsEventListener(this));},_submitForm:function(event)
{new Ajax.Updater(this.tagsListElement,this._TAGS_CREATE_URI,{asynchronous:true,evalScripts:true,parameters:Form.serialize(Event.element(event))});this.nameInput.value='';return false;}});Colloquio.Views.Tag.TaggingsListView=Class.create(Colloquio.Views.ListView,{DESTROY_TAGGING_CLASS:'destroy-tagging',TAGGINGS_NOTICE_CLASS:'taggings-notice',initialize:function($super,element,url,options)
{$super(element,url,options);},_initializeEvents:function($super)
{$super();this.containerElement.selectByClassName(this.DESTROY_TAGGING_CLASS).each(function(t){t.observe('click',this.destroyTagging.bindAsEventListener(this));}.bind(this));this.notice=this.containerElement.selectFirstByClassName(this.TAGGINGS_NOTICE_CLASS);},destroyTagging:function(event)
{var taggingElem=event.element().up();var tid=taggingElem.id.split('_')[1].toInteger();new Ajax.Request(this._taggingUrl(tid),{asynchronous:true,evalScripts:true,method:'delete',onSuccess:this._removeTaggingSuccess.bind(this,taggingElem),onFailure:this._removeTaggingFail.bind(this),onComplete:this._removeTaggingComplete.bind(this),parameters:'authenticity_token='+encodeURIComponent(window._authToken)});},_removeTaggingSuccess:function(taggingElem)
{Colloquio.Notice.update('Tagging successfully removed!',this.notice);new Effect.BlindUp(taggingElem);},_removeTaggingFail:function()
{Colloquio.Notice.update('There was an error removing this tagging.  Please try again later.',this.notice);},_removeTaggingComplete:function(transport)
{this._notifyObservers('tagging:destroyed',transport);},_taggingUrl:function(tid)
{return'/taggings/'+tid;}});Colloquio.Views.Tag.TaggingsListView.addMethods(Colloquio.Observable);Colloquio.Views.Tag.UserTagsView=Class.create(Colloquio.Views.CoreView,{TAG_CLOUD_ID:'user-tag_cloud',TAGGINGS_LIST_ID:'user-taggings-list',TAGGINGS_HEADER_ID:'user-tag-activity-header',TAGGINGS_HEADER_TEMPLATE:new Template("Tag activity for #{tag}"),TAG_CLASS:'tag',initialize:function($super,element,user)
{$super(element);this.user=user;this.tagCloud=$(this.TAG_CLOUD_ID);this.taggingsList=$(this.TAGGINGS_LIST_ID);this.taggingsHeader=$(this.TAGGINGS_HEADER_ID);this.tag=null;this._initializeEvents();this._initializeListView();},_initializeEvents:function()
{var tags=this.tagCloud.selectByClassName(this.TAG_CLASS);tags.each(function(t){t.observe('click',this._updateTaggingsList.bindAsEventListener(this));}.bind(this));},_updateTaggingsList:function(event)
{this.tag=event.element().innerHTML;new Ajax.Updater(this.taggingsList,this._taggingsUrl(),{method:'get',parameters:this._taggingsParams(),evalScripts:true,onComplete:function(){this._initializeListView(this.tag);}.bind(this)});this.taggingsHeader.update(this.TAGGINGS_HEADER_TEMPLATE.evaluate({'tag':this.tag}));},_initializeListView:function()
{this.listView=new Colloquio.Views.Tag.TaggingsListView(this.taggingsList.down(),this._taggingsUrl(),{params:this._taggingsParams(),ajaxUpdate:true,persistent:true});this.listView.observe('tagging:destroyed',this._taggingDestroyed.bind(this));},_taggingDestroyed:function(transport)
{var json=transport.responseJSON;this.tagCloud.update(json.cloud_content);this._initializeEvents();},_taggingsUrl:function()
{return'/users/'+this.user.id+'/taggings';},_taggingsParams:function()
{return this.tag?{'tag':this.tag}:{};}});