var Collaborative=function(){function e(e,o,a,l,t){function r(){return $.ajax({data:JSON.stringify(e),url:o,type:a,contentType:"application/json; charset=utf-8"})}r().done(l).fail(t)}function o(o,a){function l(e){var o=$("#users-clone div:first").clone();o=o[0];var l=$(o);l.attr("id",e.IdUser),l.find(".collaborative-user-avatar").attr("src",e.Picture),l.find(".delete-collaborative-user").attr("data-id-user",e.IdUser),l.find(".email-user").text(a),l.find(".date-created").text((new Date).toLocaleDateString()),$("#users").append(l),swal(locale.generic.genial,locale.collaborative.userAdded,"info")}function t(){swal(locale.generic.mErrorProcessingTitle,locale.collaborative.mErrorProcessingMessageCollaborative+" ("+a+").","error")}var r={idGenially:o,email:a};e(r,c,"POST",l,t)}function a(o){function a(e){$("#"+e).remove(),swal(locale.collaborative.deletedConfirm,locale.collaborative.deletedConfirmMessage,"success")}function l(){swal(locale.generic.mErrorProcessingTitle,locale.collaborative.mErrorProcessingMessageCollaborative,"error")}var t=$("#idGenially").val(),r={idGenially:t,idUser:o};e(r,d,"DELETE",a,l)}function l(){swal({title:locale.collaborative.collaborativeAddTitle,text:locale.collaborative.collaborativeAddDescription,type:"input",showCancelButton:!0,closeOnConfirm:!1,animation:"slide-from-top",confirmButtonColor:"#079dac",inputPlaceholder:locale.collaborative.collaborativeAddPlaceholder},function(e){if(e===!1)return!1;if(""===e||!helper.validateEmail(e))return swal.showInputError(locale.collaborative.inputError),!1;var o=$("#idGenially").val();Collaborative.AddCollaborative(o,e)})}function t(){var e=$(this).attr("data-id-user");swal({title:locale.collaborative.areYouSure,text:locale.collaborative.textAreYouSure,type:"warning",showCancelButton:!0,confirmButtonText:locale.collaborative.confirmDeleteUserCollaborative,closeOnConfirm:!1,confirmButtonColor:"#079dac"},function(){Collaborative.RemoveCollaborative(e)})}function r(){$('[data-toggle="tooltip"]').tooltip({container:"body"})}function i(){$("#addCollaborativeUser").on("click",l),$(document).on("click",".delete-collaborative-user",t)}function n(){$("#page-loader").fadeOut(),r(),i()}var c="/api/Collaborative/AddUser",d="/api/Collaborative/DeleteUser";return{Init:n,AddCollaborative:o,RemoveCollaborative:a}}();$(document).ready(Collaborative.Init());