Component.WikiPage=Class.create(Component,{initialize:function($super,A){$super(A);
this.setClientProperties();
},setClientProperties:function(){if(this.element!=null&&window.WPCAPI){var ticket=this.element.readAttribute("ticket");
if(TextUtils.hasText(ticket)){WPCAPI.setLoginTicket(ticket);
}WPCAPI.setDeveloperKey(this.element.readAttribute("key"));
WPCAPI.setNamespace(this.element.readAttribute("ns"));
WPCAPI.setCustomDomainHandling(false);
var pageUrl=this.element.readAttribute("pageUrl");
var loginPage="/userAuth.do?displayLogin=&redirectTarget="+pageUrl;
var registerPage="/userAuth.do?displayRegister=&redirectTarget="+pageUrl;
WPCAPI.setLoginDialogProperties({title:"Please Login",message:'You must first <a href="'+loginPage+'">log in to Flixster</a> or <a href="'+registerPage+'">register</a> to make Wiki edits.'});
WPCAPI.processLogin=function(){location.href=loginPage;
};
var childCellId=this.element.readAttribute("childCellId");
if(TextUtils.hasText(childCellId)){WPCAPI.generateCellID=function(parentId,title,tags){return childCellId;
};
var baseCellUrl=this.element.readAttribute("baseCellUrl");
var additionalGenerateCellURLParams=this.element.readAttribute("additionalGenerateCellURLParams");
WPCAPI.generateCellURL=function(parentId,title,tags,cellId){var params="title="+encodeURIComponent(title);
if(TextUtils.hasText(additionalGenerateCellURLParams)){params+="&"+additionalGenerateCellURLParams;
}var request=new Ajax.Request("/wiki/service/unique-vanity-url",{parameters:params,asynchronous:false});
var json=eval("("+request.transport.responseText+")");
return baseCellUrl+json.vanityUrl;
};
}var readOnly=this.element.readAttribute("readOnly")=="true";
WPCAPI.onPageAction=function(url,params){if(readOnly){alert("Sorry, certain wiki features have been temporarily disabled for maintenance. We'll bring them back shortly.");
return false;
}else{var request=new Ajax.Request(url,{parameters:params,asynchronous:false});
var json=eval("("+request.transport.responseText+")");
if(json.error){alert(json.error);
return false;
}}return true;
};
WPCAPI.onpagecreate=function(parentId,title,tags,cellId,cellUrl){var params="title="+encodeURIComponent(title)+"&cellId="+cellId+"&url="+encodeURIComponent(cellUrl)+"&parentId="+parentId;
return WPCAPI.onPageAction("/wiki/service/create-page",params);
};
WPCAPI.onpagedelete=function(cellId,message){var params="cellId="+cellId;
return WPCAPI.onPageAction("/wiki/service/delete-page",params);
};
WPCAPI.onpagerestore=function(cellId,message){var params="cellId="+cellId;
return WPCAPI.onPageAction("/wiki/service/restore-page",params);
};
WPCAPI.onpagerename=function(cellId,title,message){var params="title="+encodeURIComponent(title)+"&cellId="+cellId;
return WPCAPI.onPageAction("/wiki/service/rename-page",params);
};
}}});
Component.WikiFanPages=Class.create(Component.WikiPage,{initialize:function($super,B){$super(B);
this.actorPaneCellId=B.readAttribute("cellId");
var A=$A(B.getElementsByClassName("createLink"));
A.each(function(C){C.observe("click",this.onClick.bindAsEventListener(this));
}.bind(this));
},onClick:function(A){WPCAPI.showAddPageDialog(this.actorPaneCellId);
}});
Component.WikiActorPane=Class.create(Component.WikiPage,{initialize:function($super,A){$super(A);
if(A){A.style.display="block";
}}});
Component.WikiComments=Class.create(Component.HashLoader,{COMMENT_TEMPLATE:new Template('<li><div class="comment">#{comment}</div><span class="info">posted by <a href="/user/#{username}">#{username}</a> a moment ago</span><span class="jlink" component="DeleteWikiCommentLink" commentId="#{commentId}">delete</span></li>'),initialize:function($super,B){$super(B);
this.isSubmitting=false;
this.numComments=parseInt(this.element.readAttribute("numComments"));
this.isExpanded=this.numComments<=1;
this.isExpert=this.element.readAttribute("isExpert")=="true";
if(!this.isExpert){this.element.down("textarea").observe("focus",this.onNonExpert.bind(this));
}this.element.observe("comment:delete",this.onDelete.bindAsEventListener(this));
this.element.down("form").observe("submit",this.onSubmit.bindAsEventListener(this));
this.element.down("form").observe("link:click",this.onCancel.bindAsEventListener(this));
var A=this.element.down(".count .jlink");
if(A){if(this.element.readAttribute("wikiId")==this.getParameter("featured")){this.onShowAll(null);
}else{A.observe("click",this.onShowAll.bindAsEventListener(this));
}}},onSubmit:function(A){A.stop();
if(!currentUser.isLoggedIn()){alert("You must be logged in to submit comments.");
}else{if(this.isSubmitting){alert("Please wait - still processing a prior request.");
}else{if(!this.isExpert){alert("You must be an Expert to comment. Please apply to become an Expert.");
}else{var C=$F(this.element.down("textarea"));
if(!TextUtils.hasText(C)||C==this.element.down("textarea").readAttribute("default")){alert("Please enter a comment before submitting.");
}else{this.isSubmitting=true;
this.element.down(".status").update("Posting...");
this.element.down(".status").removeClassName("success");
this.element.down(".status").removeClassName("err");
this.element.down(".status").addClassName("loading");
var B={comment:C,wikiFeaturedId:this.element.readAttribute("wikiFeaturedId")};
new Ajax.Request("/wiki/service/comment",{parameters:B,method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
}}}}},onSuccess:function(event){this.isSubmitting=false;
var json=eval("("+event.responseText+")");
if(json.success){this.element.down(".status").removeClassName("loading");
this.element.down(".status").addClassName("success");
this.element.down(".status").update("Success!");
this.numComments++;
if(this.isExpanded){this.updateCount();
}else{this.onShowAll(null);
}var newComment=this.element.down("ul").insert({bottom:this.COMMENT_TEMPLATE.evaluate(json)}).childElements().last();
new Component.Binder(newComment);
var priorComment=newComment.previous();
var newClassName=(priorComment&&priorComment.hasClassName("even"))?"odd":"even";
newComment.addClassName(newClassName);
this.element.down("textarea").value=this.element.down("textarea").readAttribute("default");
}else{if(json.error){this.showFailMessage(json.error);
}}},onFailure:function(A){this.isSubmitting=false;
this.showFailMessage("Error with request. Please try again.");
},showFailMessage:function(A){this.element.down(".status").removeClassName("loading");
this.element.down(".status").addClassName("err");
this.element.down(".status").update(A);
},updateCount:function(){var A=this.numComments+" comment"+(this.numComments==1?"":"s");
this.element.down(".count").update(A);
},onDelete:function(A){this.numComments--;
this.updateCount();
},onCancel:function(A){this.element.down(".status").removeClassName("loading");
this.element.down(".status").removeClassName("success");
this.element.down(".status").removeClassName("err");
this.element.down(".status").update("");
this.element.down("textarea").value=this.element.down("textarea").readAttribute("default");
this.isSubmitting=false;
},onNonExpert:function(A){alert("You must be an Expert to comment. Please apply to become an Expert.");
},onShowAll:function(A){this.updateCount();
this.element.down("ul").select("li").each(function(B){B.show();
}.bind(this));
this.isExpanded=true;
}});
Component.DeleteWikiCommentLink=Class.create(Component.Link,{onClick:function(A){new View.ConfirmationPopup(this.element,{content:"Sure you want to delete this comment?",onConfirm:this.onConfirm.bindAsEventListener(this)});
},onConfirm:function(A){this.stopObservingClick();
this.element.removeClassName("jlink");
this.element.update("Deleting...");
this.element.addClassName("loading");
var B={commentId:this.element.readAttribute("commentId")};
new Ajax.Request("/wiki/service/delete-comment",{parameters:B,method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
},onSuccess:function(event){var json=eval("("+event.responseText+")");
if(json.success){this.element.fire("comment:delete");
new Effect.BlindUp(this.element.up("li"),{duration:1});
}else{if(json.error){this.showFailMessage(json.error);
}}},onFailure:function(A){this.showFailMessage("Error with request. Please refresh and try again.");
},showFailMessage:function(A){this.element.removeClassName("loading");
this.element.addClassName("err");
this.element.update(A);
}});
Component.WikiPageAdminWidget=Class.create(Component,{initialize:function($super,B){$super(B);
var C=$("adminToggle");
if(C!=null){C.observe("click",this.onShowAdminPane.bindAsEventListener(this));
}var D=B.down("span.refreshUserIndex");
if(D!=null){D.observe("click",this.onRefreshUserIndex.bindAsEventListener(this));
this.vanityUrl=D.readAttribute("vanityUrl");
}var A=$("moveCellLink");
if(A){A.observe("click",this.onMoveCellLinkClick.bindAsEventListener(this));
}this.moveCellForm=$("moveCellForm");
this.moveCellForm.observe("submit",this.onMoveCellFormSubmit.bindAsEventListener(this));
},onShowAdminPane:function(A){$("adminPane").style.display="block";
Element.hide("adminToggle");
},onRefreshUserIndex:function(A){if(this.element!=null){var C=Form.serialize(this.element);
var B=this.element.action;
this.element.update('<span><img src="http://static5.flixster.com/static/images/wait.mini.gif"/>&nbsp;&nbsp;&nbsp; Regenerating page...</span>');
new Ajax.Request(B,{parameters:C,onSuccess:this.onRefreshUserIndexSuccess.bind(this),onFailure:this.onRefreshUserIndexFailure.bind(this)});
}},onRefreshUserIndexSuccess:function(A){window.location="/wiki/"+this.vanityUrl;
},onRefreshUserIndexFailure:function(A){alert("Regeneration failed for unknown reason. Refresh page and try again.");
},onMoveCellLinkClick:function(A){Element.show("moveCellRow");
Element.show(this.moveCellForm);
Element.hide("moveCell");
},onMoveCellFormSubmit:function(B){B.stop();
var A=$F("parentCellId");
if(TextUtils.hasText(A)){new View.ConfirmationPopup(this.element,{content:"Sure you want to make the page a child of '"+A+"'?",onConfirm:this.onMoveCellConfirm.bindAsEventListener(this)});
}else{new View.ErrorPopup(this.element,{title:"No parent cell specified",content:"Sorry, Wetpaint doesn't currently support moving pages to the top-level."});
}},onMoveCellConfirm:function(A){this.moveCellForm.action="/admin/wiki/action/move-cell";
this.moveCellForm.submit();
}});
Component.WikiExpertRemoveWidget=Class.create(Component,{initialize:function($super,A){$super(A);
this.type=A.readAttribute("type");
this.userId=A.readAttribute("userId");
this.username=A.readAttribute("username");
this.objectId=A.readAttribute("objectId");
this.objectName=A.readAttribute("objectName");
A.addClassName("jlink");
A.observe("click",this.onClick.bindAsEventListener(this));
},onClick:function(C){if(confirm("Are you sure you want to remove "+this.username+" as a Wiki Expert for "+this.objectName+"?")){var B=document.createElement("form");
B.setAttribute("method","POST");
var A="/admin/wiki/action/manage-experts?userId="+this.userId+"&action=";
if(this.type=="movie"){A+="removeMovieExpert&movieId="+this.objectId;
}else{if(this.type=="actor"){A+="removeActorExpert&actorId="+this.objectId;
}}B.setAttribute("action",A);
document.getElementsByTagName("body").item(0).appendChild(B);
B.submit();
}}});
Component.WikiContributorUploadForm=Class.create(Component.Form,{initialize:function($super,A){$super(A);
$("contributorPaste").observe("focus",function(){$("submitTypePaste").click();
});
$("contributorFile").observe("click",function(){$("submitTypeFile").click();
});
$("contributorFile").observe("focus",function(){$("submitTypeFile").click();
});
$("submitTypePaste").observe("click",this.onPasteClick.bindAsEventListener(this));
$("submitTypeFile").observe("click",this.onFileClick.bindAsEventListener(this));
},onFileClick:function(A){$("contributorFile").removeClassName("inactive");
$("contributorPaste").addClassName("inactive");
},onPasteClick:function(A){$("contributorFile").addClassName("inactive");
$("contributorPaste").removeClassName("inactive");
},onSubmit:function(A){A.stop();
if($("submitTypePaste").checked){if($F("contributorPaste").blank()){alert("Please paste data before submitting.");
}else{$("contributorFileForm").submit();
}}else{if($("submitTypeFile").checked){if($("contributorFile").value.length==0){alert("Please browse for the file before clicking 'Upload'");
}else{try{$("contributorFileForm").submit();
}catch(B){alert("The file you chose for upload cannot be accessed. Please choose a valid file.");
}}}}}});




