﻿(function(){SS.views.ApiKeyView=function(A){this.model=A;this.read_terms_checkbox=null;this.keyContent=null;this.email=null;this.url=null;this.get_key=null;this.message=null;this.messageCont=null;this.websiteUrlEl=null;this.keyEl=null;this.key_container=null;this.changeReadTerms=new YAHOO.util.CustomEvent("changeReadTerms",this);this.clickGetKey=new YAHOO.util.CustomEvent("clickGetKey",this)};SS.views.ApiKeyView.prototype.init=function(){this.read_terms_checkbox=$D.get("terms");this.read_terms_checkbox.checked=false;this.keyContent=$D.get("key_content");this.email=$D.get("email_field");this.url=$D.get("url");this.get_key=$D.get("get_key");this.messageCont=$D.get("message_cont");this.message=$D.get("message");this.websiteUrlEl=$D.get("website_url");this.keyEl=$D.get("key");this.keyContEl=$D.get("key_cont");this.key_container=$D.get("key_container");$E.addListener(this.read_terms_checkbox,"click",this.onChangeReadTerms,this,true);$E.addListener(this.get_key,"mouseover",this.onHoverGetKey,true,this);$E.addListener(this.get_key,"mouseout",this.onHoverGetKey,false,this);$E.addListener(this.get_key,"click",this.onClickGetApiKey,this,true);this.showKeyContainer(false)};SS.views.ApiKeyView.prototype.onClickGetApiKey=function(){if(!this.get_key.disabled){this.clickGetKey.fire()}};SS.views.ApiKeyView.prototype.onHoverGetKey=function(B,A){if(!this.get_key.disabled){if(A){if(!$D.hasClass(this.key_container,"hover")){$D.addClass(this.key_container,"hover")}}else{if($D.hasClass(this.key_container,"hover")){$D.removeClass(this.key_container,"hover")}}}};SS.views.ApiKeyView.prototype.showMessage=function(A){if(A!=null&&A!=""){$D.setStyle(this.messageCont,"display","");this.message.innerHTML=A}else{$D.setStyle(this.messageCont,"display","none")}};SS.views.ApiKeyView.prototype.showKeyContainer=function(A){$D.setStyle(this.keyContEl,"display",A?"":"none");$D.setStyle($D.get("email_mess"),"display",A?"":"none")};SS.views.ApiKeyView.prototype.showWebsiteUrl=function(A){this.showKeyContainer(true);this.websiteUrlEl.innerHTML=A};SS.views.ApiKeyView.prototype.showKey=function(A){this.showKeyContainer(true);this.keyEl.value=A};SS.views.ApiKeyView.prototype.onChangeReadTerms=function(){this.changeReadTerms.fire(this.read_terms_checkbox.checked)};SS.views.ApiKeyView.prototype.setEnable=function(A){this.email.disabled=!A;this.url.disabled=!A;this.get_key.disabled=!A;if(A){if($D.hasClass(this.keyContent,"disabled")){$D.removeClass(this.keyContent,"disabled")}}else{if(!$D.hasClass(this.keyContent,"disabled")){$D.addClass(this.keyContent,"disabled")}}}}());
(function(){SS.controllers.ApiKeyController=function(B,A){this.model=B;this.view=A};SS.controllers.ApiKeyController.prototype.init=function(){this.view.changeReadTerms.subscribe(this.onChangeReadTerms,this,true);this.view.clickGetKey.subscribe(this.onStartGeneration,this,true);this.model.dataReceived.subscribe(this.onKeyGenerated,this,true);this.view.setEnable(this.model.formEnabled)};SS.controllers.ApiKeyController.prototype.onKeyGenerated=function(C,A){var B=A[0];this.view.showKey(B);if(typeof window.apiKeyField!=" undefined"&&window.apiKeyField!=null){window.apiKeyField.value=B}};SS.controllers.ApiKeyController.prototype.onStartGeneration=function(){this.model.update(this.view);if(!this.checkUrl(this.model.websiteUrl)){this.view.showMessage(SS.util.gettext("get_key_invalid_url"))}else{if(!this.checkEmail(this.model.email)){this.view.showMessage(SS.util.gettext("get_key_invalid_email"))}else{this.view.showMessage(null);this.view.showWebsiteUrl(this.model.websiteUrl);this.view.showKey(SS.util.gettext("get_key_generating_key"));this.model.getKey()}}};SS.controllers.ApiKeyController.prototype.onChangeReadTerms=function(B,A){this.model.formEnabled=A[0];this.view.setEnable(this.model.formEnabled)};SS.controllers.ApiKeyController.prototype.checkEmail=function(A){var B=/^[^@]+@([a-z0-9\-]+\.)+[a-z]{2,4}$/i;if(B.test(A)){return true}else{return false}};SS.controllers.ApiKeyController.prototype.checkUrl=function(B){var A=new RegExp();A.compile("^https?://[a-zA-Z0-9-?,'/\\+&amp;=:%$#_~]+\\.[a-zA-Z0-9-?,'/\\+&amp;=:%$#_~]+");if(!A.test(B)){A=new RegExp();A.compile("^http://localhost");if(A.test(B)){return true}return false}else{return true}}}());
(function(){SS.models.ApiKeyModel=function(){this.formEnabled=false;this.email="";this.websiteUrl="";this.trans=null;this.callback=null;this.dataReceived=new YAHOO.util.CustomEvent("dataReceived",this)};SS.models.ApiKeyModel.prototype.init=function(A){this.update(A)};SS.models.ApiKeyModel.prototype.getKey=function(){if(this.callback!=null&&this.trans!=null){YAHOO.util.Connect.abort(this.trans,this.callback)}this.callback={success:function(C){var B=C.responseText;if(B==null){B=""}B=SS.util.trim(B);this.dataReceived.fire(B)},failure:function(B){this.dataReceived.fire(null)},cache:true,scope:this};var A=SS.util.appendParamToUrl("/api/get-key.html","email",escape(this.email));A=SS.util.appendParamToUrl(A,"url",escape(this.websiteUrl));this.trans=YAHOO.util.Connect.asyncRequest("get",A,this.callback)};SS.models.ApiKeyModel.prototype.update=function(A){this.formEnabled=A.read_terms_checkbox.checked;this.email=A.email.value;this.websiteUrl=A.url.value}}());
(function(){var A=function(){var D=new SS.models.ApiKeyModel();var C=new SS.views.ApiKeyView(D);var B=new SS.controllers.ApiKeyController(D,C);C.init();B.init();D.init(C)};$E.onDOMReady(A)}());
