users.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
  3. * This file is licensed under the Affero General Public License version 3 or later.
  4. * See the COPYING-README file.
  5. */
  6. $(document).ready(function(){
  7. function applyMultiplySelect(element){
  8. var checked=[];
  9. var user=element.data('username');
  10. if(element.data('userGroups')){
  11. checked=element.data('userGroups').split(', ');
  12. }
  13. if(user){
  14. var checkHandeler=function(group){
  15. if(user==OC.currentUser && group=='admin'){
  16. return false;
  17. }
  18. $.post(
  19. OC.filePath('settings','ajax','togglegroups.php'),
  20. {
  21. username:user,
  22. group:group
  23. },
  24. function(){}
  25. );
  26. };
  27. }else{
  28. checkHandeler=false;
  29. }
  30. element.multiSelect({
  31. createText:'add group',
  32. checked:checked,
  33. oncheck:checkHandeler,
  34. onuncheck:checkHandeler,
  35. minWidth: 100,
  36. });
  37. }
  38. $('select[multiple]').each(function(index,element){
  39. applyMultiplySelect($(element));
  40. });
  41. $('td.remove>img').live('click',function(event){
  42. var uid=$(this).parent().parent().data('uid');
  43. $.post(
  44. OC.filePath('settings','ajax','removeuser.php'),
  45. {username:uid},
  46. function(result){
  47. }
  48. );
  49. $(this).parent().parent().remove();
  50. });
  51. $('td.password>img').live('click',function(event){
  52. event.stopPropagation();
  53. var img=$(this);
  54. var uid=img.parent().parent().data('uid');
  55. var input=$('<input type="password">');
  56. img.css('display','none');
  57. img.parent().children('span').replaceWith(input);
  58. input.focus();
  59. input.keypress(function(event) {
  60. if(event.keyCode == 13) {
  61. if($(this).val().length>0){
  62. $.post(
  63. OC.filePath('settings','ajax','changepassword.php'),
  64. {username:uid,password:$(this).val()},
  65. function(result){}
  66. );
  67. input.blur();
  68. }else{
  69. input.blur();
  70. }
  71. }
  72. });
  73. input.blur(function(){
  74. $(this).replaceWith($('<span>●●●●●●●</span>'));
  75. img.css('display','');
  76. });
  77. });
  78. $('td.password').live('click',function(event){
  79. $(this).children('img').click();
  80. });
  81. $('td.quota>img').live('click',function(event){
  82. event.stopPropagation();
  83. var img=$(this);
  84. var uid=img.parent().parent().data('uid');
  85. var input=$('<input>');
  86. var quota=img.parent().children('span').text();
  87. if(quota=='None'){
  88. quota='';
  89. }
  90. input.val(quota);
  91. img.css('display','none');
  92. img.parent().children('span').replaceWith(input);
  93. input.focus();
  94. input.keypress(function(event) {
  95. if(event.keyCode == 13) {
  96. $(this).parent().attr('data-quota',$(this).val());
  97. if($(this).val().length>0){
  98. $.post(
  99. OC.filePath('settings','ajax','setquota.php'),
  100. {username:uid,quota:$(this).val()},
  101. function(result){
  102. img.parent().children('span').text(result.data.quota)
  103. $(this).parent().attr('data-quota',result.data.quota);
  104. }
  105. );
  106. input.blur();
  107. }else{
  108. input.blur();
  109. }
  110. }
  111. });
  112. input.blur(function(){
  113. var quota=$(this).parent().attr('data-quota');
  114. $(this).replaceWith($('<span>'+quota+'</span>'));
  115. img.css('display','');
  116. });
  117. });
  118. $('td.quota').live('click',function(event){
  119. $(this).children('img').click();
  120. });
  121. $('#newuser').submit(function(event){
  122. event.preventDefault();
  123. var username=$('#newusername').val();
  124. if($('#content table tbody tr').filterAttr('data-uid',username).length>0){
  125. return;
  126. }
  127. if($.trim(username) == '') {
  128. alert('Please provide a username!');
  129. return false;
  130. }
  131. var password=$('#newuserpassword').val();
  132. var groups=$('#newusergroups').prev().children('div').data('settings').checked;
  133. var tr
  134. $.post(
  135. OC.filePath('settings','ajax','createuser.php'),
  136. {
  137. username:username,
  138. password:password,
  139. groups:groups,
  140. },
  141. function(result){
  142. if(result.status!='success'){
  143. tr.remove();
  144. }
  145. }
  146. );
  147. tr=$('#content table tbody tr').first().clone();
  148. tr.attr('data-uid',username);
  149. tr.find('td.name').text(username);
  150. var select=$('<select multiple="multiple" data-placehoder="Groups" title="Groups">');
  151. select.data('username',username);
  152. select.data('userGroups',groups.join(', '));
  153. tr.find('td.groups').empty();
  154. $.each($('#content table').data('groups').split(', '),function(i,group){
  155. select.append($('<option value="'+group+'">'+group+'</option>'));
  156. });
  157. tr.find('td.groups').append(select);
  158. if(tr.find('td.remove img').length==0){
  159. tr.find('td.remove').append($('<img alt="Delete" title="'+t('settings','Delete')+'" class="svg action" src="'+OC.imagePath('core','actions/delete')+'"/>'));
  160. }
  161. applyMultiplySelect(select);
  162. $('#content table tbody').last().after(tr);
  163. });
  164. });