(function(){angular.module("silverpeas.directives").directive("suggestionboxValidation",["context",function(context){return{restrict:"AE",templateUrl:webContext+"/suggestionBox/jsp/javaScript/angularjs/directives/suggestionbox-validation.jsp",replace:true,link:function postLink(scope,element,attrs){applyTokenSecurity("#suggestionValidation");function getClearedDialog(message){jQuery("#suggestionValidationMessage").html(message);jQuery("#suggestionValidationComment").val("");jQuery(".validationApproveItem").hide();
jQuery(".validationRefuseItem").hide();return jQuery("#suggestionValidation")}function validate(isApproving){var label=isApproving?jQuery("#validationApproveLabel").html():jQuery("#validationRefuseLabel").html();var result=true;var validationComment=jQuery("#suggestionValidationComment").val()||"";if(!isApproving&&validationComment.isNotDefined()){notyError(jQuery("#commentMandatoryErrorMessageMsg").html().replace("@name@",label));result=false}var comment=jQuery("#suggestionValidationComment").val();
var commentNbChar=comment?comment.split(/\n/).length+comment.length:0;if(commentNbChar>2E3){notyError(jQuery("#commentNbMaxCharErrorMessageMsg").html().replace("@name@",label));result=false}return result}scope.approve=function(suggestion){var message=jQuery("#suggestionValidationApproveMsg").html().replace("@name@",suggestion.title);var $confirm=getClearedDialog(message);jQuery(".validationApproveItem").show();$confirm.popup("confirmation",{callback:function(){if(validate(true)){jQuery("#suggestionValidationForm").attr("action",
context.componentUriBase+"suggestions/"+suggestion.id+"/approve").submit();return true}return false}})};scope.refuse=function(suggestion){var message=jQuery("#suggestionValidationRefuseMsg").html().replace("@name@",suggestion.title);var $confirm=getClearedDialog(message);jQuery(".validationRefuseItem").show();$confirm.popup("confirmation",{callback:function(){if(validate(false)){jQuery("#suggestionValidationForm").attr("action",context.componentUriBase+"suggestions/"+suggestion.id+"/refuse").submit();
return true}return false}})}}}}])})();