PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/js/setup.js

http://subsonicbox.googlecode.com/
JavaScript | 282 lines | 240 code | 42 blank | 0 comment | 18 complexity | 7f887bf1e4e206e8c89915aa0f255029 MD5 | raw file
  1. function startOp() {
  2. $('#hint').animate({
  3. opacity:.1 },750,function(){
  4. stopOp();
  5. });
  6. setTimeout('startOp()',1500);
  7. }
  8. function stopOp(){
  9. $('#hint').animate({ opacity:1 },750);
  10. }
  11. function getSetup(){
  12. $.ajax({
  13. url:'setup.php',
  14. data:({
  15. basic:true
  16. }),
  17. success:function(a){
  18. $('#main').html(a);
  19. $('#p1next').button({
  20. icons:{ primary:'ui-icon-circle-arrow-e' }
  21. });
  22. $('#p1test').button({
  23. icons:{ primary:'ui-icon-wrench' }
  24. });
  25. $('#subinfo').fadeOut('slow');
  26. $('#sform').fadeIn('slow');
  27. $('#hint').position({ my:'left top',at:'left bottom',of:'#setup',offset:'0 5' }).css('width','82px');
  28. }
  29. });
  30. }
  31. function getFolders(){
  32. $('#folderc').fadeIn();
  33. $.ajax({
  34. url:'setup.php',
  35. data:({
  36. rescan:true
  37. }),
  38. success:function(a){
  39. $('#folders').html(a);
  40. $('#p2next').button({
  41. icons:{ primary:'ui-icon-circle-arrow-e' }
  42. });
  43. }
  44. });
  45. }
  46. $(document).ready(function(){
  47. if (setupcreds == 'setup') {
  48. getSetup();
  49. }
  50. else if (setupcreds == 'folders') {
  51. showFolders();
  52. }
  53. else if (setupcreds == 'profile') {
  54. $('#main').html("<div id='profile'></div>");
  55. getProf();
  56. }
  57. else showFolders();
  58. $('#saveprof').live('click',function() {
  59. $.ajax({
  60. url:'setup.php',
  61. data:({ profile:'true',create:'true',username:$('#prof_user').val(),password:$('#prof_pass').val(),shuffle:'true',repeat:'true',timestamp:'true' }),
  62. success:function(a){
  63. $('#status').html(a);
  64. $('#prof_user').val('');
  65. $('#prof_pass').val('');
  66. }
  67. });
  68. });
  69. $('#profsing').live('click',function() {
  70. $('#profsetup').hide();
  71. });
  72. $('#profmult').live('click',function() {
  73. $('#profsetup').show();
  74. });
  75. $('#p2finish').live('click',function(){
  76. var ct = $('.musicfolderid').size();
  77. var folders = { };
  78. $('.musicfolderid').each(function(i){
  79. if ($('.music:input').eq(i).is(':checked')) {
  80. folders[i] = 'music';
  81. }
  82. if ($('.video:input').eq(i).is(':checked')) {
  83. folders[i] = 'video';
  84. }
  85. });
  86. var folderString = JSON.stringify(folders);
  87. $.ajax({
  88. url:'setup.php',
  89. data:({ setfolders:'true', folder:folders }),
  90. success:function(){
  91. $('#folders').fadeOut();
  92. $('#main').html("<div id='profile'></div>");
  93. $.ajax({
  94. url:'setup.php',
  95. data:({ profile:'true' }),
  96. success:function(a){
  97. if(!standalone) {
  98. $('#profile').html(a).css('height','200px');
  99. $('#status').html("<p>Single Profile: Supersonic will user whatever credentials you supplied in step one to chat, stream, etc.</p><p>Multi - Supersonic will give you the option of setting up different Subsonic users and letting the user choose which profile to load.");
  100. $('#profsetup').hide();
  101. }
  102. else {
  103. $("#main").html("Setup is now complete.");
  104. }
  105. }
  106. });
  107. }
  108. });
  109. });
  110. $('#sform .text').live('hover',function(){
  111. $('#status').text($(this).attr('info'));
  112. },function(){ $('#status').text('');
  113. });
  114. $('#p1test').live('click',function(){
  115. $.ajax({
  116. url:'setup.php',
  117. data:({
  118. ping:'true',
  119. server:$('#server:input').val(),
  120. juke:$('#juke:input').val(),
  121. s_user:$('#s_user:input').val(),
  122. s_pass:$('#s_pass:input').val()
  123. }),
  124. success:function(a){
  125. $('#status').html(a);
  126. },
  127. error:function(a){ $('#main').text('There was an error.'); }
  128. });
  129. });
  130. $('#proftest').live('click',function(){
  131. $.ajax({
  132. url:'setup.php',
  133. data:({
  134. ping:'true',
  135. proftest:'true',
  136. s_user:$('#prof_user:input').val(),
  137. s_pass:$('#prof_pass:input').val()
  138. }),
  139. success:function(a){
  140. $('#status').html(a);
  141. },
  142. error:function(a){ $('#main').text('There was an error.'); }
  143. });
  144. });
  145. $('#p1next').live('click',function(){
  146. if ($('input:#jetty').is(':checked')) {
  147. $.ajax({
  148. url:'setup.php',
  149. data:({
  150. setup:'true',
  151. db_type:'jetty',
  152. server:$('#server:input').val(),
  153. juke:$('#juke:input').val(),
  154. s_user:$('#s_user:input').val(),
  155. s_pass:$('#s_pass:input').val()
  156. }),
  157. success:function(a){
  158. $('#status').text('Settings saved.');
  159. $('#sform').fadeOut('slow');
  160. showFolders();
  161. },
  162. error:function(a){ $('#main').text('There was an error.'); }
  163. });
  164. }
  165. else {
  166. $.ajax({
  167. url:'setup.php',
  168. data:({
  169. setup:'true',
  170. db_type:'standalone',
  171. server:$('#server:input').val(),
  172. juke:$('#juke:input').val(),
  173. s_user:$('#s_user:input').val(),
  174. s_pass:$('#s_pass:input').val()
  175. }),
  176. success:function(a){
  177. $('#status').text('Settings saved. ');
  178. $('#sform').fadeOut('slow');
  179. },
  180. error:function(a){ $('#main').text('There was an error.'); }
  181. });
  182. }
  183. $('#status').text('Please choose the correct media type for the above folders');
  184. });
  185. setTimeout('startOp()',1500);
  186. $('#menu button').each(function(){
  187. $(this).button();
  188. });
  189. $('#setup').click(function(){
  190. getSetup();
  191. });
  192. });
  193. function getProf(){
  194. $.ajax({
  195. url:'setup.php',
  196. data:({ profile:'true' }),
  197. success:function(a){
  198. $('#profile').html(a).css('height','200px');
  199. $('#finishsetup').button();
  200. $('#status').html("<h2>Single Profile</h2> Supersonic will user whatever credentials you supplied in step one to chat, stream, etc.<h2>Multi</h2> Supersonic will give you the option of setting up different Subsonic users and letting the user choose which profile to load.");
  201. $('#hint').position({ my:'left top',at:'left bottom',of:'#profiles',offset:'0 5' }).css('width','64px');
  202. $('#finishsetup').position({ my:'right bottom', at:'right bottom', of:'#profsetup', offset:'0 30',collision:'none' });
  203. $('#profsetup').hide();
  204. $('#saveprof').button();
  205. $('#proftest').button();
  206. }
  207. });
  208. }
  209. function showFolders() {
  210. $.ajax({
  211. url:'setup.php',
  212. data:({ rescan:'true' }),
  213. success:function(a){
  214. $('#main').html("<div id='folders'></div>");
  215. $('#folders').html(a);
  216. $('#folders').fadeIn('slow');
  217. $('#p2back').button();
  218. $('#p2finish').button();
  219. $('#status').text('Please select the appropriate folder types');
  220. $('#hint').position({ my:'left top',at:'left bottom',of:'#foldersetup',offset:'0 5' }).css('width','93px');
  221. displayFolders();
  222. }
  223. });
  224. }
  225. function displayFolders() {
  226. $.ajax({
  227. url:'setup.php',
  228. data:({ config:'true',getfolders:'true' }),
  229. success:function(a){
  230. a = trim(a);
  231. var response = new Array();
  232. response = a.split(' ');
  233. $('#folders *:input').each(function(i) {
  234. $(this).attr('checked','');
  235. if (response[i] == 'true') { $(this).attr('checked','checked'); }
  236. });
  237. }
  238. });
  239. }
  240. function trim(string) { return string.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); }