2011-02-09 19:03:46 +01:00
|
|
|
function populateForm(entries){
|
|
|
|
//$('#user_details').show();
|
|
|
|
|
|
|
|
$('.errors').remove();
|
2011-03-25 03:29:14 +01:00
|
|
|
$('.success').remove();
|
2011-02-09 19:03:46 +01:00
|
|
|
|
2014-06-20 19:36:06 +02:00
|
|
|
if (entries.type === 'S')
|
|
|
|
{
|
|
|
|
$("#user_details").hide();
|
|
|
|
$("#user_details_superadmin_message").show();
|
|
|
|
$('#type').attr('disabled', '1');
|
|
|
|
} else {
|
|
|
|
$("#user_details").show();
|
|
|
|
$("#user_details_superadmin_message").hide();
|
|
|
|
$('#type').removeAttr('disabled');
|
|
|
|
}
|
|
|
|
|
2011-02-09 19:03:46 +01:00
|
|
|
$('#user_id').val(entries.id);
|
|
|
|
$('#login').val(entries.login);
|
|
|
|
$('#first_name').val(entries.first_name);
|
|
|
|
$('#last_name').val(entries.last_name);
|
|
|
|
$('#type').val(entries.type);
|
2011-02-12 00:13:26 +01:00
|
|
|
$('#email').val(entries.email);
|
2012-06-13 19:39:54 +02:00
|
|
|
$('#cell_phone').val(entries.cell_phone);
|
2011-02-12 00:13:26 +01:00
|
|
|
$('#skype').val(entries.skype_contact);
|
|
|
|
$('#jabber').val(entries.jabber_contact);
|
2011-02-09 19:03:46 +01:00
|
|
|
|
|
|
|
if (entries.id.length != 0){
|
|
|
|
$('#login').attr('readonly', 'readonly');
|
|
|
|
$('#password').val("xxxxxx");
|
2013-01-10 23:51:25 +01:00
|
|
|
$('#passwordVerify').val("xxxxxx");
|
2011-02-09 19:03:46 +01:00
|
|
|
} else {
|
|
|
|
$('#login').removeAttr('readonly');
|
|
|
|
$('#password').val("");
|
2013-01-10 23:51:25 +01:00
|
|
|
$('#passwordVerify').val("");
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function rowClickCallback(row_id){
|
2013-01-14 22:00:38 +01:00
|
|
|
$.ajax({ url: baseUrl+'User/get-user-data/id/'+ row_id +'/format/json', dataType:"json", success:function(data){
|
2011-02-09 19:03:46 +01:00
|
|
|
populateForm(data.entries);
|
2015-08-12 16:53:14 +02:00
|
|
|
$("#user_details").css("visibility", "visible");
|
|
|
|
}});
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
|
|
|
|
2015-09-02 18:53:24 +02:00
|
|
|
function removeUserCallback(row_id, nRow) {
|
|
|
|
if (confirm($.i18n._("Are you sure you want to delete this user?"))) {
|
|
|
|
$.ajax({
|
|
|
|
url: baseUrl + 'User/remove-user/id/' + row_id + '/format/json',
|
|
|
|
dataType: "text",
|
|
|
|
success: function (data) {
|
|
|
|
var o = $('#users_datatable').dataTable().fnDeleteRow(nRow);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function rowCallback( nRow, aData, iDisplayIndex ){
|
2012-01-13 20:17:39 +01:00
|
|
|
$(nRow).click(function(){rowClickCallback(aData['id'])});
|
|
|
|
if( aData['delete'] != "self"){
|
|
|
|
$('td:eq(4)', nRow).append( '<span class="ui-icon ui-icon-closethick"></span>').children('span').click(function(e){e.stopPropagation(); removeUserCallback(aData['id'], nRow)});
|
2011-05-06 00:38:33 +02:00
|
|
|
}else{
|
2011-05-06 05:41:48 +02:00
|
|
|
$('td:eq(4)', nRow).empty().append( '<span class="ui-icon ui-icon-closethick"></span>').children('span').click(function(e){e.stopPropagation(); alert("Can't delete yourself!")});
|
2011-05-06 00:38:33 +02:00
|
|
|
}
|
2011-02-11 17:56:14 +01:00
|
|
|
|
2012-01-13 20:17:39 +01:00
|
|
|
if ( aData['type'] == "A" )
|
2011-02-11 17:56:14 +01:00
|
|
|
{
|
2012-11-20 17:16:10 +01:00
|
|
|
$('td:eq(3)', nRow).html( $.i18n._('Admin') );
|
2012-01-13 20:17:39 +01:00
|
|
|
} else if ( aData['type'] == "H" )
|
2011-02-11 17:56:14 +01:00
|
|
|
{
|
2012-11-20 17:16:10 +01:00
|
|
|
$('td:eq(3)', nRow).html( $.i18n._('DJ') );
|
2012-01-13 20:17:39 +01:00
|
|
|
} else if ( aData['type'] == "G" )
|
2011-02-11 17:56:14 +01:00
|
|
|
{
|
2012-11-20 17:16:10 +01:00
|
|
|
$('td:eq(3)', nRow).html( $.i18n._('Guest') );
|
2012-01-13 20:17:39 +01:00
|
|
|
} else if ( aData['type'] == "P" )
|
2011-06-07 20:31:39 +02:00
|
|
|
{
|
2012-11-20 17:16:10 +01:00
|
|
|
$('td:eq(3)', nRow).html( $.i18n._('Program Manager') );
|
2014-06-17 23:40:55 +02:00
|
|
|
} else if ( aData['type'] == "S" )
|
|
|
|
{
|
|
|
|
$('td:eq(3)', nRow).html( $.i18n._('Super Admin') );
|
2014-06-20 19:36:06 +02:00
|
|
|
$('td:eq(4)', nRow).html(""); //Disable deleting the super admin
|
2011-02-11 17:56:14 +01:00
|
|
|
}
|
2011-02-09 19:03:46 +01:00
|
|
|
|
|
|
|
return nRow;
|
|
|
|
}
|
|
|
|
|
2012-10-27 00:09:30 +02:00
|
|
|
function populateUserTable() {
|
2011-02-08 01:03:14 +01:00
|
|
|
$('#users_datatable').dataTable( {
|
|
|
|
"bProcessing": true,
|
|
|
|
"bServerSide": true,
|
2013-01-14 22:00:38 +01:00
|
|
|
"sAjaxSource": baseUrl+"User/get-user-data-table-info/format/json",
|
2011-02-08 01:03:14 +01:00
|
|
|
"fnServerData": function ( sSource, aoData, fnCallback ) {
|
|
|
|
$.ajax( {
|
|
|
|
"dataType": 'json',
|
|
|
|
"type": "POST",
|
|
|
|
"url": sSource,
|
|
|
|
"data": aoData,
|
|
|
|
"success": fnCallback
|
|
|
|
} );
|
|
|
|
},
|
2011-02-09 19:03:46 +01:00
|
|
|
"fnRowCallback": rowCallback,
|
2011-02-08 01:03:14 +01:00
|
|
|
"aoColumns": [
|
2012-01-13 20:17:39 +01:00
|
|
|
/* Id */ { "sName": "id", "bSearchable": false, "bVisible": false, "mDataProp": "id" },
|
|
|
|
/* user name */ { "sName": "login", "mDataProp": "login" },
|
|
|
|
/* first name */ { "sName": "first_name", "mDataProp": "first_name" },
|
|
|
|
/* last name */ { "sName": "last_name", "mDataProp": "last_name" },
|
|
|
|
/* user type */ { "sName": "type", "bSearchable": false, "mDataProp": "type" },
|
|
|
|
/* del button */ { "sName": "null as delete", "bSearchable": false, "bSortable": false, "mDataProp": "delete"}
|
2011-02-08 01:03:14 +01:00
|
|
|
],
|
|
|
|
"bJQueryUI": true,
|
|
|
|
"bAutoWidth": false,
|
2011-02-11 17:56:14 +01:00
|
|
|
"bLengthChange": false,
|
2015-08-15 02:20:30 +02:00
|
|
|
"oLanguage": getDatatablesStrings({
|
|
|
|
"sEmptyTable": $.i18n._("No users were found."),
|
|
|
|
"sEmptyTable": $.i18n._("No users found"),
|
|
|
|
"sZeroRecords": $.i18n._("No matching users found"),
|
|
|
|
"sInfo": $.i18n._("Showing _START_ to _END_ of _TOTAL_ users"),
|
|
|
|
"sInfoEmpty": $.i18n._("Showing 0 to 0 of 0 users"),
|
|
|
|
"sInfoFiltered": $.i18n._("(filtered from _MAX_ total users)"),
|
|
|
|
}),
|
2012-05-18 16:00:36 +02:00
|
|
|
"sDom": '<"H"lf<"dt-process-rel"r>>t<"F"ip>',
|
2011-02-08 01:03:14 +01:00
|
|
|
});
|
2012-10-27 00:09:30 +02:00
|
|
|
}
|
|
|
|
|
2013-01-10 23:51:25 +01:00
|
|
|
function sizeFormElements() {
|
|
|
|
$("dt[id$='label']").addClass('user-form-label');
|
|
|
|
$("dd[id$='element']").addClass('user-form-element');
|
|
|
|
}
|
|
|
|
|
2013-01-11 21:12:41 +01:00
|
|
|
function assignUserRightsToUserTypes() {
|
2012-12-13 18:29:02 +01:00
|
|
|
//assign user-rights and id to each user type option so we can
|
|
|
|
//display user rights for each with tipsy tooltip
|
|
|
|
$.each($('#type').children(), function(i, opt) {
|
|
|
|
switch ($(this).val()) {
|
|
|
|
case 'G':
|
|
|
|
$(this).attr('id', 'user-type-G');
|
|
|
|
$(this).attr('user-rights',
|
|
|
|
$.i18n._('Guests can do the following:')+'<br><br>'+
|
|
|
|
$.i18n._('View schedule')+'<br>'+
|
2012-12-13 21:29:29 +01:00
|
|
|
$.i18n._('View show content')
|
2012-12-13 18:29:02 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
$(this).attr('id', 'user-type-H');
|
|
|
|
$(this).attr('user-rights',
|
|
|
|
$.i18n._('DJs can do the following:')+'<br><br>'+
|
|
|
|
$.i18n._('View schedule')+'<br>'+
|
2012-12-13 21:29:29 +01:00
|
|
|
$.i18n._('View show content')+'<br>'+
|
2012-12-13 18:29:02 +01:00
|
|
|
$.i18n._('Manage assigned show content')+'<br>'+
|
|
|
|
$.i18n._('Import media files')+'<br>'+
|
2012-12-13 21:29:29 +01:00
|
|
|
$.i18n._('Create playlists, smart blocks, and webstreams')+'<br>'+
|
|
|
|
$.i18n._('Manage their own library content')
|
2012-12-13 18:29:02 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
$(this).attr('id', 'user-type-P');
|
|
|
|
$(this).attr('user-rights',
|
2013-01-08 17:57:05 +01:00
|
|
|
$.i18n._('Program Managers can do the following:')+'<br><br>'+
|
2012-12-13 18:29:02 +01:00
|
|
|
$.i18n._('View schedule')+'<br>'+
|
2012-12-13 21:29:29 +01:00
|
|
|
$.i18n._('View and manage show content')+'<br>'+
|
2012-12-13 18:29:02 +01:00
|
|
|
$.i18n._('Schedule shows')+'<br>'+
|
|
|
|
$.i18n._('Import media files')+'<br>'+
|
|
|
|
$.i18n._('Create playlists, smart blocks, and webstreams')+'<br>'+
|
2012-12-13 21:29:29 +01:00
|
|
|
$.i18n._('Manage all library content')
|
2012-12-13 18:29:02 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
$(this).attr('id', 'user-type-A');
|
|
|
|
$(this).attr('user-rights',
|
|
|
|
$.i18n._('Admins can do the following:')+'<br><br>'+
|
|
|
|
$.i18n._('Manage preferences')+'<br>'+
|
|
|
|
$.i18n._('Manage users')+'<br>'+
|
|
|
|
$.i18n._('Manage watched folders')+'<br>'+
|
|
|
|
$.i18n._('Send support feedback')+'<br>'+
|
|
|
|
$.i18n._('View system status')+'<br>'+
|
|
|
|
$.i18n._('Access playout history')+'<br>'+
|
|
|
|
$.i18n._('View listener stats')+'<br>'+
|
|
|
|
$.i18n._('View schedule')+'<br>'+
|
2012-12-13 21:29:29 +01:00
|
|
|
$.i18n._('View and manage show content')+'<br>'+
|
2012-12-13 18:29:02 +01:00
|
|
|
$.i18n._('Schedule shows')+'<br>'+
|
|
|
|
$.i18n._('Import media files')+'<br>'+
|
|
|
|
$.i18n._('Create playlists, smart blocks, and webstreams')+'<br>'+
|
2012-12-13 21:29:29 +01:00
|
|
|
$.i18n._('Manage all library content')
|
2012-12-13 18:29:02 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2013-01-11 21:12:41 +01:00
|
|
|
}
|
2012-12-13 18:29:02 +01:00
|
|
|
|
2015-08-31 21:25:17 +02:00
|
|
|
function init() {
|
|
|
|
var type = $('#type');
|
|
|
|
|
|
|
|
type.live("change", function(){
|
2012-12-13 18:29:02 +01:00
|
|
|
//when the title changes on live tipsy tooltips the changes take
|
|
|
|
//affect the next time tipsy is shown so we need to hide and re-show it
|
|
|
|
$(this).tipsy('hide').tipsy('show');
|
|
|
|
});
|
2015-08-31 21:25:17 +02:00
|
|
|
|
|
|
|
type.tipsy({
|
2012-12-13 18:29:02 +01:00
|
|
|
gravity: 'w',
|
|
|
|
html: true,
|
2012-12-13 18:58:26 +01:00
|
|
|
opacity: 0.9,
|
2012-12-13 18:29:02 +01:00
|
|
|
trigger: 'manual',
|
|
|
|
live: true,
|
|
|
|
title: function() {
|
|
|
|
return $('#user-type-'+$(this).val()).attr('user-rights');
|
|
|
|
}
|
|
|
|
});
|
2015-08-12 16:53:14 +02:00
|
|
|
|
|
|
|
var table = $("#users_datable");//.DataTable();
|
|
|
|
$('.datatable tbody').on( 'click', 'tr', function () {
|
|
|
|
$(this).parent().find('tr.selected').removeClass('selected');
|
|
|
|
$(this).addClass('selected');
|
|
|
|
} );
|
|
|
|
|
|
|
|
$('#button').click( function () {
|
|
|
|
table.row('.selected').remove().draw( false );
|
|
|
|
} );
|
|
|
|
|
2015-08-31 21:25:17 +02:00
|
|
|
type.tipsy('show');
|
|
|
|
|
2011-02-09 19:03:46 +01:00
|
|
|
var newUser = {login:"", first_name:"", last_name:"", type:"G", id:""};
|
2015-08-31 21:25:17 +02:00
|
|
|
|
2015-08-12 16:53:14 +02:00
|
|
|
$('#add_user_button').live('click', function(){
|
|
|
|
populateForm(newUser);
|
|
|
|
$("#user_details").css("visibility", "visible");
|
|
|
|
});
|
2015-08-31 21:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
populateUserTable();
|
|
|
|
assignUserRightsToUserTypes();
|
|
|
|
init();
|
|
|
|
|
2012-10-27 00:09:30 +02:00
|
|
|
$('#save_user').live('click', function(){
|
|
|
|
var data = $('#user_form').serialize();
|
2013-01-14 22:00:38 +01:00
|
|
|
var url = baseUrl+'User/add-user';
|
2012-10-27 00:09:30 +02:00
|
|
|
|
2013-02-07 21:41:47 +01:00
|
|
|
$.post(url, {format: "json", data: data}, function(json){
|
2012-10-27 00:09:30 +02:00
|
|
|
if (json.valid === "true") {
|
|
|
|
$('#content').empty().append(json.html);
|
|
|
|
populateUserTable();
|
2013-01-11 21:12:41 +01:00
|
|
|
assignUserRightsToUserTypes();
|
2015-08-31 21:25:17 +02:00
|
|
|
init(); // Reinitialize
|
2012-10-27 00:09:30 +02:00
|
|
|
} else {
|
|
|
|
//if form is invalid we only need to redraw the form
|
|
|
|
$('#user_form').empty().append($(json.html).find('#user_form').children());
|
2013-01-10 23:51:25 +01:00
|
|
|
$('#password').val("");
|
|
|
|
$('#passwordVerify').val("");
|
2012-10-27 00:09:30 +02:00
|
|
|
}
|
|
|
|
setTimeout(removeSuccessMsg, 5000);
|
2013-01-10 23:51:25 +01:00
|
|
|
sizeFormElements();
|
2012-10-27 00:09:30 +02:00
|
|
|
});
|
|
|
|
});
|
2013-01-10 23:51:25 +01:00
|
|
|
|
|
|
|
sizeFormElements();
|
2013-01-04 23:19:09 +01:00
|
|
|
|
2011-02-08 01:03:14 +01:00
|
|
|
});
|