//Copyright © [Year(s)] Nokia Corporation and/or its subsidiary(-ies).
Fp.Menu.Rate={userRating:null,poiObj:null,textCache:{heading:""},init:function(){this.setupEvents();},setupEvents:function(){this.addEventToRatingStar({element:Fp.byId("pageActionRating"),event:this.starEvent});new Fp.Utils.Events.addTapEvent({element:Fp.byId("submitRating"),onEvent:this.submitEvent});Fp.addListener("onResize",this.switchContent);},submitEvent:function(){if(Fp.Menu.Rate.userRating){Fp.Popup.show({name:Fp.Popup.NAME.LOADER});Fp.Ratings.submit({rating:Fp.Menu.Rate.userRating,onSuccess:Fp.Menu.Rate.submitSuccess,onFailure:Fp.Menu.Rate.submitFailure,onTimeout:Fp.Menu.Rate.submitFailure,placeId:Fp.Menu.Rate.poiObj.placeId});return true;}return false;},starEvent:function(a){Fp.Menu.Rate.userRating=a.target.title;Fp.Ratings.setRatingVisuals({element:Fp.byId("pageActionRating"),rating:a.target.title,isRTL:Fp.Lang.isRTL});},addEventToRatingStar:function(c){if(c&&c.element&&c.event){for(var b=0,a=c.element.children.length;b<a;b++){c.element.children[b].onclick=c.event;}return true;}return false;},submitSuccess:function(a,b){Fp.Ratings.requestData({placeId:Fp.Menu.Rate.poiObj.placeId,onSuccess:Fp.Menu.Rate.requestSuccess,onFailure:Fp.Menu.Rate.requestFailure,onTimeout:Fp.Menu.Rate.requestFailure});Fp.Popup.show({name:Fp.Popup.NAME.MESSAGE,message:Language["places.thankUforOviVote"],timeout:2});Fp.Pages.showPage({name:Fp.Pages.PAGE.MAIN,fromHistory:true});Fp.Menu.Rate.userRating=null;Fp.Tracking.track("rateContent");},submitFailure:function(a,b){Fp.Popup.show({name:Fp.Popup.NAME.QUESTION,headerText:Language["places.ratingfailed"],subText:Language["places.tryagain"],onYes:function(){Fp.Popup.hide();Fp.Menu.Rate.submitEvent();},onNo:function(){Fp.Popup.hide();Fp.Pages.showPage({name:Fp.Pages.PAGE.MAIN});}});},requestSuccess:function(a,b){var c=Fp.Ratings.getFormatedRating(b);Fp.Menu.Rate.setView(c);Fp.Header.fillHeaderRatings(c);},requestFailure:function(a,b){Fp.Ratings.clearRating({element:Fp.byId("pageActionRating")});},setView:function(a){if(a){Fp.Ratings.clearRating({element:Fp.byId("pageActionRating")});Fp.Ratings.setRatingVisuals({element:Fp.byId("pageRating"),rating:a.rating,isRTL:Fp.Lang.isRTL});Fp.Ratings.setCount({element:Fp.byId("pageRatingCount"),ratingCount:a.ratingCount});return true;}return false;},fillHeader:function(c){var a=Fp.Utils.formatName(c),b=c.address?Fp.Utils.formatAddress(c.address,c.isPlace):"";a+=b?", "+b:"";this.textCache.heading=a;Fp.Utils.addTruncatedString({element:Fp.byId("ratingHeaderName"),text:a});},fillContent:function(a){if(a){this.poiObj=a;this.setView(a.rating);return true;}return false;},switchContent:function(){if(Fp.Pages.overlay.className.indexOf("show")!=-1){Fp.Utils.addTruncatedString({element:Fp.byId("ratingHeaderName"),text:Fp.Menu.Rate.textCache.heading});}}};