user.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. function populateForm(entries){
  2. //$('#user_details').show();
  3. $('.errors').remove();
  4. $('.success').remove();
  5. $('#user_id').val(entries.id);
  6. $('#login').val(entries.login);
  7. $('#first_name').val(entries.first_name);
  8. $('#last_name').val(entries.last_name);
  9. $('#type').val(entries.type);
  10. $('#email').val(entries.email);
  11. $('#cell_phone').val(entries.cell_phone);
  12. $('#skype').val(entries.skype_contact);
  13. $('#jabber').val(entries.jabber_contact);
  14. if (entries.id.length != 0){
  15. $('#login').attr('readonly', 'readonly');
  16. $('#password').val("xxxxxx");
  17. $('#passwordVerify').val("xxxxxx");
  18. } else {
  19. $('#login').removeAttr('readonly');
  20. $('#password').val("");
  21. $('#passwordVerify').val("");
  22. }
  23. }
  24. function rowClickCallback(row_id){
  25. $.ajax({ url: baseUrl+'User/get-user-data/id/'+ row_id +'/format/json', dataType:"json", success:function(data){
  26. populateForm(data.entries);
  27. }});
  28. }
  29. function removeUserCallback(row_id, nRow){
  30. $.ajax({ url: baseUrl+'User/remove-user/id/'+ row_id +'/format/json', dataType:"text", success:function(data){
  31. var o = $('#users_datatable').dataTable().fnDeleteRow(nRow);
  32. }});
  33. }
  34. function rowCallback( nRow, aData, iDisplayIndex ){
  35. $(nRow).click(function(){rowClickCallback(aData['id'])});
  36. if( aData['delete'] != "self"){
  37. $('td:eq(4)', nRow).append( '<span class="ui-icon ui-icon-closethick"></span>').children('span').click(function(e){e.stopPropagation(); removeUserCallback(aData['id'], nRow)});
  38. }else{
  39. $('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!")});
  40. }
  41. if ( aData['type'] == "A" )
  42. {
  43. $('td:eq(3)', nRow).html( $.i18n._('Admin') );
  44. } else if ( aData['type'] == "H" )
  45. {
  46. $('td:eq(3)', nRow).html( $.i18n._('DJ') );
  47. } else if ( aData['type'] == "G" )
  48. {
  49. $('td:eq(3)', nRow).html( $.i18n._('Guest') );
  50. } else if ( aData['type'] == "P" )
  51. {
  52. $('td:eq(3)', nRow).html( $.i18n._('Program Manager') );
  53. }
  54. return nRow;
  55. }
  56. function populateUserTable() {
  57. $('#users_datatable').dataTable( {
  58. "bProcessing": true,
  59. "bServerSide": true,
  60. "sAjaxSource": baseUrl+"User/get-user-data-table-info/format/json",
  61. "fnServerData": function ( sSource, aoData, fnCallback ) {
  62. $.ajax( {
  63. "dataType": 'json',
  64. "type": "POST",
  65. "url": sSource,
  66. "data": aoData,
  67. "success": fnCallback
  68. } );
  69. },
  70. "fnRowCallback": rowCallback,
  71. "aoColumns": [
  72. /* Id */ { "sName": "id", "bSearchable": false, "bVisible": false, "mDataProp": "id" },
  73. /* user name */ { "sName": "login", "mDataProp": "login" },
  74. /* first name */ { "sName": "first_name", "mDataProp": "first_name" },
  75. /* last name */ { "sName": "last_name", "mDataProp": "last_name" },
  76. /* user type */ { "sName": "type", "bSearchable": false, "mDataProp": "type" },
  77. /* del button */ { "sName": "null as delete", "bSearchable": false, "bSortable": false, "mDataProp": "delete"}
  78. ],
  79. "bJQueryUI": true,
  80. "bAutoWidth": false,
  81. "bLengthChange": false,
  82. "oLanguage": datatables_dict,
  83. "sDom": '<"H"lf<"dt-process-rel"r>>t<"F"ip>',
  84. });
  85. }
  86. function sizeFormElements() {
  87. $("dt[id$='label']").addClass('user-form-label');
  88. $("dd[id$='element']").addClass('user-form-element');
  89. }
  90. function assignUserRightsToUserTypes() {
  91. //assign user-rights and id to each user type option so we can
  92. //display user rights for each with tipsy tooltip
  93. $.each($('#type').children(), function(i, opt) {
  94. switch ($(this).val()) {
  95. case 'G':
  96. $(this).attr('id', 'user-type-G');
  97. $(this).attr('user-rights',
  98. $.i18n._('Guests can do the following:')+'<br><br>'+
  99. $.i18n._('View schedule')+'<br>'+
  100. $.i18n._('View show content')
  101. );
  102. break;
  103. case 'H':
  104. $(this).attr('id', 'user-type-H');
  105. $(this).attr('user-rights',
  106. $.i18n._('DJs can do the following:')+'<br><br>'+
  107. $.i18n._('View schedule')+'<br>'+
  108. $.i18n._('View show content')+'<br>'+
  109. $.i18n._('Manage assigned show content')+'<br>'+
  110. $.i18n._('Import media files')+'<br>'+
  111. $.i18n._('Create playlists, smart blocks, and webstreams')+'<br>'+
  112. $.i18n._('Manage their own library content')
  113. );
  114. break;
  115. case 'P':
  116. $(this).attr('id', 'user-type-P');
  117. $(this).attr('user-rights',
  118. $.i18n._('Program Managers can do the following:')+'<br><br>'+
  119. $.i18n._('View schedule')+'<br>'+
  120. $.i18n._('View and manage show content')+'<br>'+
  121. $.i18n._('Schedule shows')+'<br>'+
  122. $.i18n._('Import media files')+'<br>'+
  123. $.i18n._('Create playlists, smart blocks, and webstreams')+'<br>'+
  124. $.i18n._('Manage all library content')
  125. );
  126. break;
  127. case 'A':
  128. $(this).attr('id', 'user-type-A');
  129. $(this).attr('user-rights',
  130. $.i18n._('Admins can do the following:')+'<br><br>'+
  131. $.i18n._('Manage preferences')+'<br>'+
  132. $.i18n._('Manage users')+'<br>'+
  133. $.i18n._('Manage watched folders')+'<br>'+
  134. $.i18n._('Send support feedback')+'<br>'+
  135. $.i18n._('View system status')+'<br>'+
  136. $.i18n._('Access playout history')+'<br>'+
  137. $.i18n._('View listener stats')+'<br>'+
  138. $.i18n._('View schedule')+'<br>'+
  139. $.i18n._('View and manage show content')+'<br>'+
  140. $.i18n._('Schedule shows')+'<br>'+
  141. $.i18n._('Import media files')+'<br>'+
  142. $.i18n._('Create playlists, smart blocks, and webstreams')+'<br>'+
  143. $.i18n._('Manage all library content')
  144. );
  145. break;
  146. }
  147. });
  148. }
  149. $(document).ready(function() {
  150. populateUserTable();
  151. assignUserRightsToUserTypes();
  152. $('#type').live("change", function(){
  153. //when the title changes on live tipsy tooltips the changes take
  154. //affect the next time tipsy is shown so we need to hide and re-show it
  155. $(this).tipsy('hide').tipsy('show');
  156. });
  157. $('#type').tipsy({
  158. gravity: 'w',
  159. html: true,
  160. opacity: 0.9,
  161. trigger: 'manual',
  162. live: true,
  163. title: function() {
  164. return $('#user-type-'+$(this).val()).attr('user-rights');
  165. }
  166. });
  167. $('#type').tipsy('show');
  168. var newUser = {login:"", first_name:"", last_name:"", type:"G", id:""};
  169. $('#add_user_button').live('click', function(){populateForm(newUser)});
  170. $('#save_user').live('click', function(){
  171. var data = $('#user_form').serialize();
  172. var url = baseUrl+'User/add-user';
  173. $.post(url, {format: "json", data: data}, function(json){
  174. if (json.valid === "true") {
  175. $('#content').empty().append(json.html);
  176. populateUserTable();
  177. assignUserRightsToUserTypes();
  178. } else {
  179. //if form is invalid we only need to redraw the form
  180. $('#user_form').empty().append($(json.html).find('#user_form').children());
  181. $('#password').val("");
  182. $('#passwordVerify').val("");
  183. }
  184. setTimeout(removeSuccessMsg, 5000);
  185. sizeFormElements();
  186. });
  187. });
  188. sizeFormElements();
  189. });