function __initActionUser() { activeManageRight($('.a-manage')); activeDatatable($('#container')); function activeManageRight(thisitem) { $(thisitem).live("click", function () { var id = $(this).parents('tr[userid]').attr('userid'); $.ajax({ type: "POST", url: '/user/ajaxgetright', async: false, data: {userid: id}, success: function (msg) { showPopupRight(id, msg); /*$("#popup_dialog").html(msg); var buttons = new Object(); buttons[translate('ok')] = function () { var add = new Object(); var del = new Object(); $("#popup_dialog").find(':input.topic[type=checkbox]').each(function (i) { if ($(this).is(':checked')) { if ($(this).val() != "5" && $(this).val() != "4") { add[$(this).val()] = $(this).parents('tr[right]').attr('type'); } else { if ($(this).val() == "5") { // récupération de toutes les sessions cochées var valeurs = []; var valeur = []; $(this).parents('tr').find('input#coord_session:checked').each(function() { valeurs.push($(this).val()); }); add[$(this).val()] = valeurs; } else { // récupération de toutes les sessions cochées var valeurs = []; var valeur = []; $(this).parents('tr').find('input#rev_session:checked').each(function() { valeurs.push($(this).val()); }); add[$(this).val()] = valeurs; } } } else { del[$(this).val()] = $(this).parents('tr[right]').attr('type'); } }); $.ajax({ type: "POST", url: '/user/ajaxmanageright', async: false, data: { userid: id, add: JSON.stringify(add), del: JSON.stringify(del) }, success: function (msg) { $("#container tr[userid=" + id + "]").find("td.user[id=" + id + "]").html(msg); } }); $(this).dialog('close'); }; buttons[translate('cancel')] = function () { $(this).dialog('close'); }; $("#popup_dialog").dialog({ title: translate('TITLE_RIGHT'), width: 600, height: 600, resizable: false, modal: true, buttons: buttons }); */ } } ); }); }; function activeDatatable(thisitem) { $(thisitem).SC_DataTable({"aoColumnDefs": [{"bSortable": false, "aTargets": "viewColumn"}]}); }; } function actionMember(noTable) { activeInputEvent($('input[type=checkbox]')); activeAutoComplete($('#addnew'), '/user/member', 'successMember'); if (typeof noTable == "undefined" ) var oTable = activeDataTable($("#container")); function activeInputEvent (thisitem) { $(thisitem).live('click', function () { var checked = $(this).is(':checked'); if (checked) { if ($(this).val() == 2) { $('input[type=checkbox][userid=' + $(this).attr('userid') + '][value!=2]').attr('checked', 'checked').attr('disabled', 'disabled'); } $('input[type=checkbox][userid=' + $(this).attr('userid') + '][value=1]').removeAttr('checked'); } else { if ($(this).val() == 2) { $('input[type=checkbox][userid=' + $(this).attr('userid') + '][value!=2]').removeAttr('disabled'); } if (!$('input[type=checkbox][userid=' + $(this).attr('userid') + ']').is(':checked')) { $('input[type=checkbox][userid=' + $(this).attr('userid') + '][value=1]').attr('checked','checked'); } } }); }; function activeDataTable (thisitem) { var oTable = $(thisitem).SC_DataTable({"iDisplayLength": 100, "bStateSave" : false, "aaSorting" : [[1, "asc"]], "aoColumnDefs": [{bSortable : false, aTargets : ["noSort"], bSearchable: false}]}); return oTable; }; return oTable; }; function actionManage(noTable) { activeInputEvent($('input[type=checkbox]')); activeAutoComplete($('#addnew'), '/user/manage', 'successManage'); if (typeof noTable == "undefined" ) var oTable = activeDataTable($("#container")); function activeInputEvent (thisitem) { $(thisitem).live('click', function () { var checked = $(this).is(':checked'); if (checked) { if ($(this).val() == 2) { $('input[type=checkbox][userid=' + $(this).attr('userid') + '][value!=2]').attr('checked', 'checked').attr('disabled', 'disabled'); } $('input[type=checkbox][userid=' + $(this).attr('userid') + '][value=1]').removeAttr('checked'); } else { if ($(this).val() == 2) { $('input[type=checkbox][userid=' + $(this).attr('userid') + '][value!=2]').removeAttr('disabled'); } if (!$('input[type=checkbox][userid=' + $(this).attr('userid') + ']').is(':checked')) { $('input[type=checkbox][userid=' + $(this).attr('userid') + '][value=1]').attr('checked','checked'); } } }); }; function activeDataTable (thisitem) { var oTable = $(thisitem).SC_DataTable({"iDisplayLength": 100, "bStateSave" : false, "aaSorting" : [[1, "asc"]], "aoColumnDefs": [{bSortable : false, aTargets : ["noSort"], bSearchable: false}]}); return oTable; }; return oTable; }; function actionSu(){ activeAutoComplete($('#suautocomplete'), '/user/ajaxquerylogin', 'successSu'); } function saveRights ( form ) { oTable.fnDestroy(); return true; } function dialogUserAdd() { var btn = new Object(); btn[translate('cancel')] = function() { $(this).dialog("close"); }; $("#addUser").dialog({ autoOpen: false, modal: true, width: 500, buttons: btn, close: function() {$('.ui-autocomplete').hide();} }).dialog('open'); } function actionCreateAccount () { activeAutoComplete($('#USERNAME'), '/user/ajaxquerylogin', 'successCreate', 'focusCreate'); }; function actionSearch () { activeAutoComplete($('#search'), '/user/ajaxquerylogin', 'successSearch'); $("#search").keyup(function() { $("#submit").attr('disabled', 'disabled'); $("#uid").val(0); }); }; //Ajout d'un nouvel utilisateur dans le tableau des utilisateurs function addUserInTable(lastname, firstname, username, mail, uid){ // Affiche l'utilisateur et propose de prendre son identité var table = document.getElementById("list-users"); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); cell1.innerHTML = lastname+" "+firstname+"
"+username+"
"+mail; var cell2 = row.insertCell(1); var textcell2 = "Prendre identité"; cell2.innerHTML = ""+textcell2+""; } //Reset contenu du tableau qui liste les utilisateurs function resetTable() { while(document.getElementById("list-users").rows.length > 1) document.getElementById("list-users").deleteRow(1); } // Affiche les utilisateurs dont on peut prendre l'identité function successSu(event, ui){ var uid = ui.item.uid; // Requete de création de l'utilisateur dans la base SC si inexistant $.ajax({ url: '/user/ajaxcreateuser', type: 'POST', data: { 'casid' : uid, 'username' : ui.item.username, 'email' : ui.item.mail, 'lastname' : ui.item.lastname, 'firstname' : ui.item.firstname }, success: function(data) { // Affiche l'utilisateur et propose de prendre son identité resetTable(); addUserInTable(ui.item.lastname, ui.item.firstname, ui.item.username, ui.item.mail, uid); $('#list-users').show(); }}); } function successManage (event, ui) { var uid = ui.item.uid; var username = ui.item.username; var lastname = ui.item.lastname; var firstname = ui.item.firstname; var fullname = ui.item.fullname; var mail = ui.item.mail; var label = ui.item.label; var valid = ui.item.valid; // Requete de création de l'utilisateur dans la base SC si inexistant $.ajax({ url: '/user/ajaxcreateuser', type: 'POST', data: { 'casid': uid, 'username': username, 'email': mail, 'lastname': lastname, 'firstname': firstname }, success: function (msg) { var id = msg; var fullname = lastname+' '+firstname; var valid = true; addUserRight(id, fullname, username, mail, valid); $.ajax({ type: "POST", url: '/user/ajaxgetright', async: false, data: {userid: id}, success: function (msg) { showPopupRight(id, msg) } }); } }); /* uid = data; if ( typeof(ui.item)!="undefined" ) { if ( $('#listofspecificuser[userid='+uid+']').length==0 ) { if (!$("#listofspecificuser tr:first").hasClass('specificUser')) { $("#listofspecificuser tr:first").remove(); } var clone = $("#container tfoot tr:last").clone(); $(clone).attr('userid', uid); $(clone).find('input[type=checkbox]').attr('userid', uid); $(clone).find('input[type=checkbox]').each (function (i) { $(this).attr('name', $(this).attr('name') + '[' + uid + ']'); }); $(clone).find('input[type=checkbox]').removeAttr('disabled'); $(clone).find('td:first input[type=checkbox]').attr('style', 'visibility: hidden;'); var old = $(clone).find('.fullname').html(); $(clone).find('.fullname').html(fullname + old); $(clone).find('.email').html(mail); if (valid) { $(clone).find('td:last').find('a:first').replaceWith($(clone).find('td:last').find('a:first').html()); } $(clone).removeClass('clone'); $(clone).addClass('specificUser'); $("#listofspecificuser").prepend($(clone)); $("#listofspecificuser tr:first").show(); } } } }); */ } function addUserRight(uid, fullname, username, mail, valid) { if ( $('#listofspecificuser[userid='+uid+']').length==0 ) { if (!$("#listofspecificuser tr:first").hasClass('specificUser')) { $("#listofspecificuser tr:first").remove(); } var clone = $("#container tfoot tr:last").clone(); $(clone).attr('userid', uid); $(clone).find('input[type=checkbox]').attr('userid', uid); $(clone).find('input[type=checkbox]').each (function (i) { $(this).attr('name', $(this).attr('name') + '[' + uid + ']'); }); $(clone).find('input[type=checkbox]').removeAttr('disabled'); $(clone).find('td:first input[type=checkbox]').attr('style', 'visibility: hidden;'); var old = $(clone).find('.fullname').html(); var ident = fullname + ' ( ' + mail + ')'; $(clone).find('.fullname').html(ident + old); $(clone).find('.email').html(mail); $(clone).find('.user').id = uid; $(clone).find('.no_right').id = uid; $(clone).find('.user').hide(); /* if (valid) { $(clone).find('td:last').find('a:first').replaceWith($(clone).find('td:last').find('a:first').html()); } */ $(clone).removeClass('clone'); $(clone).addClass('specificUser'); $("#listofspecificuser").prepend($(clone)); $("#listofspecificuser tr:first").show(); } } function successMember (event, ui) { var uid = ui.item.uid; var username = ui.item.username; var lastname = ui.item.lastname; var firstname = ui.item.firstname; var fullname = ui.item.fullname; var mail = ui.item.mail; var label = ui.item.label; var valid = ui.item.valid; // Requete de création de l'utilisateur dans la base SC si inexistant $.ajax({ url: '/user/ajaxcreateuser', type: 'POST', data: { 'casid' : uid, 'username' : username, 'email' : mail, 'lastname' : lastname, 'firstname' : firstname }, success: function(data) { uid = data; if ( typeof(ui.item)!="undefined" ) { if ( $('#listofspecificuser[userid='+uid+']').length==0 ) { if (!$("#listofspecificuser tr:first").hasClass('specificUser')) { $("#listofspecificuser tr:first").remove(); } var clone = $("#container tfoot tr:last").clone(); /* $(clone).attr('userid', uid); $(clone).find('input[type=checkbox]').attr('userid', uid); $(clone).find('input[type=checkbox]').each (function (i) { $(this).attr('name', $(this).attr('name') + '[' + uid + ']'); }); $(clone).find('input[type=checkbox]').removeAttr('disabled'); $(clone).find('td:first input[type=checkbox]').attr('style', 'visibility: hidden;'); */ var old = $(clone).find('.fullname').html(); $(clone).find('.fullname').html(fullname + old); $(clone).find('.email').html(mail); if (valid) { $(clone).find('td:last').find('a:first').replaceWith($(clone).find('td:last').find('a:first').html()); } $(clone).removeClass('clone'); $(clone).addClass('specificUser'); $("#listofspecificuser").prepend($(clone)); $("#listofspecificuser tr:first").show(); } } } }); } function successCreate (event, ui) { var uid = ui.item.uid; // Requete de création de l'utilisateur dans la base SC si inexistant $.ajax({ url: '/user/ajaxcreateuser', type: 'POST', data: { 'casid' : uid, 'username' : ui.item.username, 'email' : ui.item.mail, 'lastname' : ui.item.lastname, 'firstname' : ui.item.firstname }, success: function(data) { uid = data; for (var i in ui.item) { if (i.toUpperCase() != "UID") { $("#" + i.toUpperCase()).val(ui.item[i]); console.log(i.toUpperCase()).val(ui.item[i]); } } $("#UID").val(uid); } }); }; function successSearch (event, ui) { var uid = ui.item.uid; // Requete de création de l'utilisateur dans la base SC si inexistant $.ajax({ url: '/user/ajaxcreateuser', type: 'POST', data: { 'casid' : uid, 'username' : ui.item.username, 'email' : ui.item.mail, 'lastname' : ui.item.lastname, 'firstname' : ui.item.firstname }, success: function(data) { uid = data; $("#uid").val(uid); $("#search").val(ui.item.lastname + " " + ui.item.firstname); $("#submit").removeAttr('disabled'); } }); } function focusCreate (event, ui) { if (ui.item.uid != 0) { for (var i in ui.item) { $("#" + i.toUpperCase()).val(ui.item[i]); if (i.toUpperCase() != "USERNAME" && i.toUpperCase() != "UID") { $("#" + i.toUpperCase()).attr('disabled', 'disabled'); } } $("#UID").val(ui.item.uid); } else { $("#form_account :input[type!=submit][type!=hidden]").val(""); $("#form_account :input[type!=submit][type!=hidden]").removeAttr('disabled'); $("#UID").val(ui.item.uid); $("#USERNAME").val(ui.item['value']); } }; function activeAutoComplete (thisitem, source, callback, focus) { console.log($(thisitem).val()); $(thisitem).autocomplete({ source: function(request, response) { $.ajax({ url: source, data: { q : $(thisitem).val() }, success: function(data) { var donnees = toJSON(data); var output = new Array(); for (var i in donnees) { output.push(donnees[i]); } var output = new Array(); for (var i in donnees) { if ( $('#listofspecificuser tr[userid=' + donnees[i].UID +']').length==0) { output.push(donnees[i]); } } response($.map(output, function(row) { return { label : formatLabels(row), fullname : row.FIRSTNAME.charAt(0).toUpperCase() + row.FIRSTNAME.substring(1) + " " + row.LASTNAME.charAt(0).toUpperCase() + row.LASTNAME.substring(1), uid : row.UID, firstname : row.FIRSTNAME, lastname : row.LASTNAME, username : row.USERNAME, mail : row.MAIL, civ : row.CIV, middlename : row.MIDDLENAME, langueid : row.LANGUEID, url : row.URL, phone : row.PHONE, //fax : row.FAX, valid : row.VALID, value : $(thisitem).val() }; })); } }); }, minLength: 1, delay : 500, select : function (event, ui) { eval(callback)(event, ui); //$(thisitem).val($(thisitem).attr('placeholder')); $('.ui-autocomplete').hide(); $("#addUser").dialog('close'); return false; }, focus : function (event, ui) { if (typeof focus != "undefined") { eval(focus)(event, ui); } return false; } }).data( "autocomplete" )._renderItem = function( ul, item ) { return $( "
  • " ) .data( "item.autocomplete", item ) .append( "" + item.label + "" ) .appendTo( ul ); }; $(thisitem).blur(function() { if ($(this).val() == "") { $(this).val($(thisitem).attr('placeholder')); } }).click(function(){ if ($(thisitem).val() == $(thisitem).attr("placeholder") || $(thisitem).val() == "") $(thisitem).val(""); }); }; function formatLabels (row) { var label = ""; if (row.UID != 0) { label = "
     "; label += "" + row.LASTNAME.charAt(0).toUpperCase() + row.LASTNAME.substring(1) + " " + row.FIRSTNAME.charAt(0).toUpperCase() + row.FIRSTNAME.substring(1) + " (" + row.USERNAME + ")"; if (typeof row.MAIL != "undefined" && row.MAIL != "") { label += "
    " + row.MAIL + ""; } label += "
    "; } else { label = "
     " + row.FIRSTNAME + "
    "; } return label; }; function setDataTable(thisitem) { $(thisitem).each (function (i) { var oTable = $(thisitem).SC_DataTable({"aoColumnDefs": [ { "bSortable": false, "aTargets": "viewColumn" }]}); }); $('[other]', thisitem).each (function (i) { $(this).parents('div.container').hide(); }); }; function showLink ( id ) { $('#' + id).toggle(); if($('#' + id).is(':visible')) { $("span." + id + " a").html(translate('hide')); } else { $("span." + id + " a").html(translate('view')); } }; function validUser(id) { $.ajax({ url : '/user/manage', type : 'post', data : { uid : id, method : 'valid' }, success : function (msg) { $("tr[userid=" + id + "]").find('td:last').find('a:first').replaceWith($("tr[userid=" + id + "]").find('td:last').find('a:first').html()); $("tr[userid=" + id + "]").find('td:last').find('img:first').removeClass('bt_valid'); } }); }; function removeUser(elm, isDispatched) { if (isDispatched != undefined) { $.ajax({ url : '/user/manage', type : 'post', data : { uid : elm, method : 'delete' }, success : function (msg) { oTable.fnDeleteRow(oTable.fnGetPosition($("#listofspecificuser").find("tr[userid='" + elm + "']").get(0))); } }); } else { openConfirmBox (translate('deleteUser'), "removeUser ('" + $(elm).closest("tr").attr('userid') + "', true);"); } }; function removeUserRight(elm, isDispatched) { if (isDispatched != undefined) { $.ajax({ url : '/user/manage', type : 'post', data : { uid : elm, method : 'delete' }, success : function (msg) { oTable.fnDeleteRow(oTable.fnGetPosition($("#listofspecificuser").find("tr[userid='" + elm + "']").get(0))); } }); } else { openConfirmBox (translate('deleteUser'), "removeUser ('" + $(elm).closest("tr").attr('userid') + "', true);"); } }; /** * Edition des roles d'un utilisateur * @param elem * @return */ function editPrivileges(elem) { //$(elem).parents('.specificUser').find('.view').hide(); //$(elem).parents('.specificUser').find('.edit').show(); var tr = $(elem).parents('tr.specificUser'); $.each(toJSON(tr.find('.view').find('.group').val()), function(key, value) { //$("#popup_right *[name='" + key + "']").val(value); }); initPopupRight(tr); $('#popup_right').dialog('open'); } /** * Initialisation de la popup * @param elem * @return */ function initPopupRight(elem) { var buttons = {}; buttons[translate('ok')] = function() { //Test Formulaire complet var valid = true; $('#popup_right input.required').each(function(index) { if ($(this).val() == '') { valid = false; } }); if (valid) { // modif droits addRow($('#popup_right form').serializeJSON(), elem); $(this).dialog("close"); } else { alert(translate('form_misinformed')); } }; buttons[translate('cancel')] = function() { $(this).dialog("close"); }; $('#popup_right').dialog('option', 'buttons', buttons); } function filter(elem) { link("/user/manage?" + $(elem).attr('name') + "=" + $(elem).val()); } /*function checkSession(uid) { var nbChecked = $( "input#session_"+uid+":checked" ).length; if (nbChecked > 0) { $('#sreviewer_' + uid).attr('checked', true); } else { $("#sreviewer_" + uid).attr('checked', false); } } */ function showPopupRight(id, msg) { $("#popup_dialog").html(msg); var buttons = new Object(); buttons[translate('ok')] = function () { var add = new Object(); var del = new Object(); $("#popup_dialog").find('input.topic[type=checkbox]').each(function (i) { if ($(this).is(':checked')) { if (($(this).val() != "5") && ($(this).val() != "4")) { add[$(this).val()] = $(this).parents('tr[right]').attr('type'); } else { if ($(this).val() == "5") { // récupération de toutes les sessions cochées var valeurs = []; var valeur = []; $(this).parents('tr').find('input#coord_session:checked').each(function() { valeurs.push($(this).val()); }); add[$(this).val()] = valeurs; } else { // récupération de toutes les sessions cochées var valeurs = []; var valeur = []; $(this).parents('tr').find('input#rev_session:checked').each(function() { valeurs.push($(this).val()); }); add[$(this).val()] = valeurs; } } } else { del[$(this).val()] = $(this).parents('tr[right]').attr('type'); } }); $.ajax({ type: "POST", url: '/user/ajaxmanageright', async: false, data: { userid: id, add: JSON.stringify(add), del: JSON.stringify(del), action: 'new' }, success: function (msg) { $("#container tr[userid=" + id + "]").find("td.user").html(msg); $("#container tr[userid=" + id + "]").find("td.user").show(); $("#container tr[userid=" + id + "]").find("td.no_right").hide() } }); $(this).dialog('close'); }; buttons[translate('cancel')] = function () { $(this).dialog('close'); }; $("#popup_dialog").dialog({ title: translate('TITLE_RIGHT'), width: 600, height: 400, resizable: false, modal: true, buttons: buttons }); } function checkRole(elem) { if ($(elem).is(':checked')) { if ($(elem).val() == '5') { $(elem).parents('tr').find('input#coord_session').attr('checked', true); } else { $(elem).parents('tr').find('input#rev_session').attr('checked', true); } } else { if ($(elem).val() == '5') { $(elem).parents('tr').find('input#coord_session').attr('checked', false); } else { $(elem).parents('tr').find('input#rev_session').attr('checked', false); } } } function checkSession(elem, role) { // var nbChecked = $($(elem)+":checked").length; if (role == '5') { var nbChecked = $("input#coord_session:checked").length; } else { var nbChecked = $("input#rev_session:checked").length; } if (nbChecked > 0) { $(elem).parents('tr').find('input.topic').attr('checked', true); } else { $(elem).parents('tr').find('input.topic').attr('checked', false); } }