You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <!--
  2. User list
  3. Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
  4. $Id: settingsGlobalUsers.html 595 2015-04-17 09:50:36Z imoore76 $
  5. -->
  6. <div>
  7. <table style='width: auto; margin-left:auto; margin-right:auto;' class='vboxInvisible'>
  8. <tr>
  9. <td colspan='2'><span class='translate'>Users</span>:</td>
  10. </tr>
  11. <tr style='vertical-align:top'>
  12. <td style='width: 400px'>
  13. <ul id='vboxSettingsUserList' class='vboxBordered vboxList vboxHover' style='width: 400px; margin-top: 0px;'>
  14. <li>user</li>
  15. </ul>
  16. </td>
  17. <td style='width: 10px' id='vboxSettingsGlobalUsersToolbar'></td>
  18. </tr>
  19. </table>
  20. <!-- Main Div -->
  21. </div>
  22. <script type='text/javascript'>
  23. /* Build Toolbar */
  24. /*
  25. * Init Users buttons and toolbar
  26. */
  27. var sButtons = new Array(
  28. {
  29. 'name' : 'addUser',
  30. 'label' : 'Add User',
  31. 'icon' : 'vm_new',
  32. 'click' : function () {
  33. var l = new vboxLoader();
  34. l.addFileToDOM('panes/userEdit.html');
  35. l.onLoad = function(){
  36. // Set mode
  37. $('#vboxUserEdit').trigger('setMode','addUser');
  38. var buttons = {};
  39. buttons[trans('OK','QIMessageBox')] = function() {
  40. var u = $('#vboxUserEdit').find('input[name=username]').first().val();
  41. var p1 = $('#vboxUserEdit').find('input[name=npass1]').first().val();
  42. var p2 = $('#vboxUserEdit').find('input[name=npass2]').first().val();
  43. var a = $('#vboxUserEdit').find('input[name=admin]').first().prop('checked');
  44. if(u.length == 0) {
  45. $(this).remove();
  46. return;
  47. }
  48. if(p1.length == 0 || (p1 != p2)) {
  49. vboxAlert(trans('The passwords you have entered do not match.','UIUsers'),{'width':'auto'});
  50. return;
  51. }
  52. var dialog = this;
  53. var chp = new vboxLoader();
  54. chp.add('addUser',function(d){
  55. if(d) {
  56. if(d.success) {
  57. vboxSettingsGlobalAddUserList({'username':u,'admin':a});
  58. $(dialog).remove();
  59. } else {
  60. vboxAlert(trans('A user with that username already exists.','UIUsers'),{'width':'auto'});
  61. }
  62. } else {
  63. // unknown error
  64. $(dialog).remove();
  65. }
  66. },{'u':u,'p':p1,'a':a});
  67. chp.run();
  68. };
  69. buttons[trans('Cancel','QIMessageBox')] = function(){
  70. $(this).remove();
  71. };
  72. $('#vboxUserEdit').dialog({'closeOnEscape':false,'width':500,'height':220,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/vm_new_16px.png" class="vboxDialogTitleIcon" /> '+trans('Add User','UIUsers')});
  73. };
  74. l.run();
  75. }
  76. },
  77. {
  78. 'name' : 'delUser',
  79. 'label' : 'Remove User',
  80. 'icon' : 'vm_delete',
  81. 'noDisabledIcon' : true,
  82. 'enabled' : function (item) { return (item && $(item).data('username') && $(item).data('username') != $('#vboxPane').data('vboxSession').user); },
  83. 'click' : function () {
  84. var buttons = {};
  85. buttons[trans('OK','QIMessageBox')] = function() {
  86. var user = $('#vboxSettingsUserList').children('li.vboxListItemSelected').data();
  87. var l = new vboxLoader();
  88. l.add('delUser',function(d){
  89. if(d && d.success) {
  90. $('#vboxSettingsUserList').children('li.vboxListItemSelected').remove();
  91. $('#vboxSettingsUserList').trigger('select',null);
  92. }
  93. },{'u':user.username});
  94. l.run();
  95. $(this).remove();
  96. };
  97. var user = $('#vboxSettingsUserList').children('li.vboxListItemSelected').data();
  98. vboxConfirm(trans('Are you sure you want to remove the user <b>%s</b>? This action cannot be undone.','UIUsers').replace('%s',user.username),buttons);
  99. }
  100. },
  101. {
  102. 'name' : 'chpwUser',
  103. 'label' : 'Change Password',
  104. 'icon' : 'register',
  105. 'noDisabledIcon' : true,
  106. 'enabled' : function (item) { return (item && $(item).data('username') && $(item).data('username') == $('#vboxPane').data('vboxSession').user); },
  107. 'click' : function () {
  108. var l = new vboxLoader();
  109. l.addFileToDOM('panes/userEdit.html');
  110. l.onLoad = function(){
  111. // Set mode
  112. $('#vboxUserEdit').trigger('setMode','changePassword');
  113. var buttons = {};
  114. buttons[trans('OK','QIMessageBox')] = function() {
  115. var o = $('#vboxUserEdit').find('input[name=opass]').first().val();
  116. var n1 = $('#vboxUserEdit').find('input[name=npass1]').first().val();
  117. var n2 = $('#vboxUserEdit').find('input[name=npass2]').first().val();
  118. if(o.length == 0) {
  119. vboxAlert(trans('The password you have entered is invalid.','UIUsers'),{'width':'auto'});
  120. return;
  121. }
  122. if(n1.length == 0 || (n1 != n2)) {
  123. vboxAlert(trans('The passwords you have entered do not match.','UIUsers'),{'width':'auto'});
  124. return;
  125. }
  126. var dialog = this;
  127. var chp = new vboxLoader();
  128. chp.add('changePassword',function(d){
  129. if(d) {
  130. if(d.success) {
  131. vboxAlert(trans('Password changed.','UIUsers'),{'width':'auto'});
  132. $(dialog).remove();
  133. } else {
  134. vboxAlert(trans('The password you have entered is invalid.','UIUsers'),{'width':'auto'});
  135. }
  136. } else {
  137. // unknown error
  138. $(dialog).remove();
  139. }
  140. },{'old':o,'new':n1});
  141. chp.run();
  142. };
  143. buttons[trans('Cancel','QIMessageBox')] = function(){
  144. $(this).remove();
  145. };
  146. $('#vboxUserEdit').dialog({'closeOnEscape':false,'width':400,'height':200,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/register_16px.png" class="vboxDialogTitleIcon" /> '+trans('Change Password','UIUsers')});
  147. };
  148. l.run();
  149. }
  150. },
  151. {
  152. 'name' : 'editUser',
  153. 'label' : 'Edit User',
  154. 'icon' : 'register',
  155. 'noDisabledIcon' : true,
  156. 'enabled' : function (item) { return (item && $(item).data('username') && $(item).data('username') != $('#vboxPane').data('vboxSession').user); },
  157. 'click' : function () {
  158. var l = new vboxLoader();
  159. l.addFileToDOM('panes/userEdit.html');
  160. l.onLoad = function(){
  161. // Set mode
  162. $('#vboxUserEdit').trigger('setMode','editUser');
  163. // Set values
  164. var user = $('#vboxSettingsUserList').children('li.vboxListItemSelected').data();
  165. $('#vboxEditUserUsername').html(user.username);
  166. $('#vboxUserEdit').find('input[name=admin]').first().prop('checked', (user.admin ? true : false));
  167. var buttons = {};
  168. buttons[trans('OK','QIMessageBox')] = function() {
  169. var p1 = $('#vboxUserEdit').find('input[name=npass1]').first().val();
  170. var p2 = $('#vboxUserEdit').find('input[name=npass2]').first().val();
  171. var a = $('#vboxUserEdit').find('input[name=admin]').first().prop('checked');
  172. if(p1.length > 0 && (p1 != p2)) {
  173. vboxAlert(trans('The passwords you have entered do not match.','UIUsers'),{'width':'auto'});
  174. return;
  175. }
  176. var dialog = this;
  177. var chp = new vboxLoader();
  178. chp.add('editUser',function(d){
  179. if(d && d.success) {
  180. $('#vboxSettingsUserList').children('li.vboxListItemSelected').data({'admin':a}).html(user.username + (a ? ' ('+trans('Admin User','UIUsers')+')' : ''));
  181. $(dialog).remove();
  182. } else {
  183. // unknown error
  184. $(dialog).remove();
  185. }
  186. },{'u':user.username,'p':p1,'a':a});
  187. chp.run();
  188. };
  189. buttons[trans('Cancel','QIMessageBox')] = function(){
  190. $(this).remove();
  191. };
  192. $('#vboxUserEdit').dialog({'closeOnEscape':false,'width':500,'height':230,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/register_16px.png" class="vboxDialogTitleIcon" /> '+trans('Edit User','UIUsers')});
  193. };
  194. l.run();
  195. }
  196. }
  197. );
  198. var userToolbar = new vboxToolbarSmall({buttons: sButtons, language_context: 'UIUsers'});
  199. userToolbar.disabledString = 'dis';
  200. userToolbar.renderTo('vboxSettingsGlobalUsersToolbar');
  201. $('#vboxSettingsUserList').on('select', function(e,el){userToolbar.update(el);});
  202. /*
  203. *
  204. * Function to fill users
  205. *
  206. */
  207. function vboxSettingsGlobalAddUserList(n) {
  208. $('<li />').attr({'class':'vboxListItem'}).html($('<div />').html(n.username + (n.admin ? ' ('+trans('Admin User','UIUsers')+')' : ''))).hoverClass('vboxHover').data(n).click(function(){
  209. $(this).parent().children('li.vboxListItemSelected').removeClass('vboxListItemSelected').addClass('vboxListItem');
  210. $(this).addClass('vboxListItemSelected').removeClass('vboxListItem');
  211. $('#vboxSettingsUserList').trigger('select',this);
  212. }).appendTo($('#vboxSettingsUserList'));
  213. }
  214. /*
  215. *
  216. * Fill network adapters
  217. *
  218. */
  219. $('#vboxSettingsUserList').children().remove();
  220. var users = $('#vboxSettingsDialog').data('vboxUsers');
  221. for(var i in users) {
  222. vboxSettingsGlobalAddUserList(users[i]);
  223. }
  224. $('#vboxSettingsUserList').trigger('select',null);
  225. </script>