settings.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. OC.MountConfig={
  2. saveStorage:function(tr) {
  3. var mountPoint = $(tr).find('.mountPoint input').val();
  4. if (mountPoint == '') {
  5. return false;
  6. }
  7. var backendClass = $(tr).find('.backend').data('class');
  8. var configuration = $(tr).find('.configuration input');
  9. var addMountPoint = true;
  10. if (configuration.length < 1) {
  11. return false;
  12. }
  13. var classOptions = {};
  14. $.each(configuration, function(index, input) {
  15. if ($(input).val() == '' && !$(input).hasClass('optional')) {
  16. addMountPoint = false;
  17. return false;
  18. }
  19. if ($(input).is(':checkbox')) {
  20. if ($(input).is(':checked')) {
  21. classOptions[$(input).data('parameter')] = true;
  22. } else {
  23. classOptions[$(input).data('parameter')] = false;
  24. }
  25. } else {
  26. classOptions[$(input).data('parameter')] = $(input).val();
  27. }
  28. });
  29. if (addMountPoint) {
  30. if ($('#externalStorage').data('admin') === true) {
  31. var isPersonal = false;
  32. var multiselect = $(tr).find('.chzn-select').val();
  33. var oldGroups = $(tr).find('.applicable').data('applicable-groups');
  34. var oldUsers = $(tr).find('.applicable').data('applicable-users');
  35. $.each(multiselect, function(index, value) {
  36. var pos = value.indexOf('(group)');
  37. if (pos != -1) {
  38. var mountType = 'group';
  39. var applicable = value.substr(0, pos);
  40. if ($.inArray(applicable, oldGroups) != -1) {
  41. oldGroups.splice($.inArray(applicable, oldGroups), 1);
  42. }
  43. } else {
  44. var mountType = 'user';
  45. var applicable = value;
  46. if ($.inArray(applicable, oldUsers) != -1) {
  47. oldUsers.splice($.inArray(applicable, oldUsers), 1);
  48. }
  49. }
  50. $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
  51. });
  52. var mountType = 'group';
  53. $.each(oldGroups, function(index, applicable) {
  54. $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
  55. });
  56. var mountType = 'user';
  57. $.each(oldUsers, function(index, applicable) {
  58. $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
  59. });
  60. } else {
  61. var isPersonal = true;
  62. var mountType = 'user';
  63. var applicable = OC.currentUser;
  64. $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
  65. }
  66. return true;
  67. }
  68. }
  69. };
  70. $(document).ready(function() {
  71. $('.chzn-select').chosen();
  72. $('#selectBackend').live('change', function() {
  73. var tr = $(this).parent().parent();
  74. $('#externalStorage tbody').append($(tr).clone());
  75. $('#externalStorage tbody tr').last().find('.mountPoint input').val('');
  76. var selected = $(this).find('option:selected').text();
  77. var backendClass = $(this).val();
  78. $(this).parent().text(selected);
  79. if ($(tr).find('.mountPoint input').val() == '') {
  80. $(tr).find('.mountPoint input').val(suggestMountPoint(selected.replace(/\s+/g, '')));
  81. }
  82. $(tr).addClass(backendClass);
  83. $(tr).find('.backend').data('class', backendClass);
  84. var configurations = $(this).data('configurations');
  85. var td = $(tr).find('td.configuration');
  86. $.each(configurations, function(backend, parameters) {
  87. if (backend == backendClass) {
  88. $.each(parameters['configuration'], function(parameter, placeholder) {
  89. if (placeholder.indexOf('*') != -1) {
  90. td.append('<input type="password" data-parameter="'+parameter+'" placeholder="'+placeholder.substring(1)+'" />');
  91. } else if (placeholder.indexOf('!') != -1) {
  92. td.append('<label><input type="checkbox" data-parameter="'+parameter+'" />'+placeholder.substring(1)+'</label>');
  93. } else if (placeholder.indexOf('&') != -1) {
  94. td.append('<input type="text" class="optional" data-parameter="'+parameter+'" placeholder="'+placeholder.substring(1)+'" />');
  95. } else if (placeholder.indexOf('#') != -1) {
  96. td.append('<input type="hidden" data-parameter="'+parameter+'" />');
  97. } else {
  98. td.append('<input type="text" data-parameter="'+parameter+'" placeholder="'+placeholder+'" />');
  99. }
  100. });
  101. if (parameters['custom'] && $('#externalStorage tbody tr.'+backendClass).length == 1) {
  102. OC.addScript('files_external', parameters['custom']);
  103. }
  104. return false;
  105. }
  106. });
  107. $('.chz-select').chosen();
  108. $(tr).find('td').last().attr('class', 'remove');
  109. $(tr).find('td').last().removeAttr('style');
  110. $(tr).removeAttr('id');
  111. $(this).remove();
  112. });
  113. function suggestMountPoint(defaultMountPoint) {
  114. var i = 1;
  115. var append = '';
  116. var match = true;
  117. while (match && i < 20) {
  118. match = false;
  119. $('#externalStorage tbody td.mountPoint input').each(function(index, mountPoint) {
  120. if ($(mountPoint).val() == defaultMountPoint+append) {
  121. match = true;
  122. return false;
  123. }
  124. });
  125. if (match) {
  126. append = i;
  127. i++;
  128. } else {
  129. break;
  130. }
  131. }
  132. return defaultMountPoint+append;
  133. }
  134. $('#externalStorage td').live('change', function() {
  135. OC.MountConfig.saveStorage($(this).parent());
  136. });
  137. $('td.remove>img').live('click', function() {
  138. var tr = $(this).parent().parent();
  139. var mountPoint = $(tr).find('.mountPoint input').val();
  140. if (!mountPoint) {
  141. var row=this.parentNode.parentNode;
  142. $.post(OC.filePath('files_external', 'ajax', 'removeRootCertificate.php'), { cert: row.id });
  143. $(tr).remove();
  144. return true;
  145. }
  146. if ($('#externalStorage').data('admin') === true) {
  147. var isPersonal = false;
  148. var multiselect = $(tr).find('.chzn-select').val();
  149. $.each(multiselect, function(index, value) {
  150. var pos = value.indexOf('(group)');
  151. if (pos != -1) {
  152. var mountType = 'group';
  153. var applicable = value.substr(0, pos);
  154. } else {
  155. var mountType = 'user';
  156. var applicable = value;
  157. }
  158. $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
  159. });
  160. } else {
  161. var mountType = 'user';
  162. var applicable = OC.currentUser;
  163. var isPersonal = true;
  164. }
  165. $.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
  166. $(tr).remove();
  167. });
  168. $('#allowUserMounting').bind('change', function() {
  169. if (this.checked) {
  170. OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'yes');
  171. } else {
  172. OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'no');
  173. }
  174. });
  175. });