Object.extend(Controller.prototype,{index:function(){var c=$$("div.story.summary");for(var b=0,a=c.length;b<a;b++){new View.Controls.Post.Commentable.Story.Summary(c[b])}},read:function(){new View.Controls.Post.Commentable.Story($$("div.story")[0])},create:function(){if(document.forms.create){this.form(document.forms.create)}},edit:function(){if(document.forms.edit){this.form(document.forms.edit)}},form:function(form){new View.Controls.Form(form);with(form){validator.validates(title,"Título",{length:{min:3,max:128},format:/^[^\/\f\n\r\t\v]+$/});validator.validates(content,"Contenido",{stripTags:true,length:{min:3,max:65536}});validator.validates(tags,"Tags",{filled:"optional",length:{min:3,max:128},format:/^[ 0-9a-záéíóúüñ]+(?:\s*,\s*[ 0-9a-záéíóúüñ]+)*$/i},function(error){return !tags.value.strip().split(",").find(function(tag){tag=tag.strip().replace(/\s+/," ");var length=tag.length;if(length<3){return !error("El TAG '%s' es demasiado corto (tiene %d carácteres y el mínimo es %d)",tag,length,3)}if(length>32){return !error("El TAG '%s' es demasiado largo (tiene %d carácteres y el máximo es %d)",tag,length,32)}})});new Ajax.Autocompleter(tags)}},search:function(){new View.Controls.StorySearchForm(document.forms.delimit);this.index();Form.Element.select(document.forms.delimit.term);Form.Element.focus(document.forms.delimit.term)}});View.Controls.CategoriesSelect=Class.create();Object.extend(Object.extend(View.Controls.CategoriesSelect.prototype,View.Controls.CrossSelect.prototype),{initialize:function(e){View.Controls.CrossSelect.prototype.initialize.call(this,e);var a=Element.up(this.availableSelect,"label");var d=a.getElementsByTagName("strong")[0];d.replaceChild(document.createTextNode("Categorías disponibles"),d.firstChild);var b=a.getElementsByTagName("em")[0];b.replaceChild(document.createTextNode(_("Categorias")),b.firstChild);var a=Element.insertAfter(a.cloneNode(true),a);var d=a.getElementsByTagName("strong")[0];d.replaceChild(document.createTextNode("Categorías seleccionadas"),d.firstChild);var b=a.getElementsByTagName("em")[0];b.replaceChild(document.createTextNode("categorías en las que aparecerá la historia"),b.firstChild);a.replaceChild(this.selectedSelect,a.getElementsByTagName("select")[0]);var c=document.createElement("span");c.className="cell";c.style.textAlign="center";c.appendChild(document.createElement("br"));c.appendChild(this.addButton);c.appendChild(document.createElement("br"));c.appendChild(document.createElement("br"));c.appendChild(this.delButton);a.parentNode.insertBefore(c,a);this.update()}});View.Controls.StorySearchForm=Class.create({initialize:function(form){this.form=form;this.formWasEmpty=Form.isEmpty(this.form);var label=document.createElement("label");label.appendChild(document.createElement("br"));var button=view.toolButton({icon:"/images/ico/undelimit.gif",title:"Nueva búsqueda"});label.appendChild(button);Element.insert(Element.up(Element.select(this.form,"button[type=submit]")[0],"label"),{after:label});Event.observe(button,"click",this.onClickUndelimit.bind(this));this.form.validator=new Validator(this.form);with(this.form){validator.validates(term,"Término",{length:{min:3,max:32}});if(this.form.author){validator.validates(author,"Usuario",{filled:"optional",length:{min:3,max:16},format:/^[0-9a-z]+[-0-9a-z]{1,14}[0-9a-z]+$/i})}if(this.form.ip){validator.validates(ip,"IP",{filled:"optional",format:/^\d{1,3}\.(?:\d{1,3}|\*)\.(?:\d{1,3}|\*)\.(?:\d{1,3}|\*)$/})}if(this.form.footprint){validator.validates(footprint,"Huella",{filled:"optional",format:/^[0-9a-z]{1,13}$/})}Event.observe(term,"keyup",this.onChangeTerm.bind(this));if(this.form.story){Event.observe(story,"change",this.onChangeStory.bind(this))}Event.observe(status,"change",this.onChangeStatus.bind(this));Event.observe(term_field,"change",this.onChangeTermField.bind(this));Event.observe(post_type,"change",this.onChangePostType.bind(this));if(this.form.author){Event.observe(author,"keyup",this.onChangeAuthor.bind(this))}if(this.form.ip){Event.observe(ip,"keyup",this.onChangeIp.bind(this))}if(this.form.footprint){Event.observe(footprint,"keyup",this.onChangeFootprint.bind(this))}}this.onChangeTerm();if(this.form.story){this.onChangeStory()}this.onChangeStatus();this.onChangeTermField();this.onChangePostType();if(this.form.author){this.onChangeAuthor()}if(this.form.ip){this.onChangeIp()}if(this.form.footprint){this.onChangeFootprint()}},onClickUndelimit:function(event){with(this.form){if(this.formWasEmpty){Form.reset(this.form)}else{with(this.form){term.value="";if(this.form.story){story.selectedIndex=0}status.selectedIndex=3;term_field.selectedIndex=0;post_type.selectedIndex=1;if(this.form.author){author.value=""}if(this.form.ip){ip.value=""}if(this.form.footprint){footprint.value=""}}submit()}Event.fire(term,"change");if(this.form.story){Event.fire(story,"change")}Event.fire(status,"change");Event.fire(term_field,"change");Event.fire(post_type,"change");if(this.form.author){Event.fire(author,"change")}if(this.form.ip){Event.fire(ip,"change")}if(this.form.footprint){Event.fire(footprint,"change")}}},onChangeTerm:function(){with(this.form){term.style.backgroundColor=term.value.strip()?"":view.colors.get("disabled")}},onChangeStory:function(){with(this.form){story.style.backgroundColor=story.selectedIndex?"":view.colors.get("disabled")}},onChangeStatus:function(){with(this.form){status.style.backgroundColor=status.selectedIndex?"":view.colors.get("disabled")}},onChangeTermField:function(){with(this.form){term_field.style.backgroundColor=term_field.selectedIndex?"":view.colors.get("disabled")}},onChangePostType:function(){with(this.form){post_type.style.backgroundColor=post_type.selectedIndex?"":view.colors.get("disabled")}},onChangeAuthor:function(){with(this.form){author.style.backgroundColor=author.value.strip()?"":view.colors.get("disabled")}},onChangeIp:function(){with(this.form){ip.style.backgroundColor=ip.value.strip()?"":view.colors.get("disabled")}},onChangeFootprint:function(){with(this.form){footprint.style.backgroundColor=footprint.value.strip()?"":view.colors.get("disabled")}}});