admin.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. $(document).ready(function(){
  2. newSiteHtml = '<li><input type="text" class="site_name" name="site_name[]" value="" placeholder="Name" />\n\
  3. <input type="text" name="site_url[]" class="site_url" value="" placeholder="URL" />\n\
  4. <img class="svg action delete_button" src="'+OC.imagePath("core", "actions/delete") +'" title="Remove site" /></li>';
  5. // Handler functions
  6. function addSiteEventHandler(event) {
  7. event.preventDefault();
  8. saveSites();
  9. }
  10. function deleteButtonEventHandler(event) {
  11. event.preventDefault();
  12. $(this).tipsy('hide');
  13. $(this).parent().remove();
  14. saveSites();
  15. }
  16. function saveSites() {
  17. var post = $('#external').serialize();
  18. $.post( OC.filePath('external','ajax','setsites.php') , post, function(data) {
  19. // OC.msg.finishedSaving('#site_name .msg', data);
  20. });
  21. }
  22. function showDeleteButton(event) {
  23. $(this).find('img.delete_button').fadeIn(100);
  24. }
  25. function hideDeleteButton(event) {
  26. $(this).find('img.delete_button').fadeOut(100);
  27. }
  28. // Initialize events
  29. $('input[name^=site_]').change(addSiteEventHandler);
  30. $('img.delete_button').click(deleteButtonEventHandler);
  31. $('img.delete_button').tipsy();
  32. $('#external li').hover(showDeleteButton, hideDeleteButton);
  33. $('#add_external_site').click(function(event) {
  34. event.preventDefault();
  35. $('#external ul').append(newSiteHtml);
  36. $('input.site_url:last').prev('input.site_name').andSelf().change(addSiteEventHandler);
  37. $('img.delete_button').click(deleteButtonEventHandler);
  38. $('img.delete_button:last').tipsy();
  39. $('#external li:last').hover(showDeleteButton, hideDeleteButton);
  40. });
  41. });