flag_lists_ops.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. (function ($) {
  2. Drupal.behaviors.flagListsOps = {
  3. attach: function(context) {
  4. // Hide the go button, as it is not needed for JS enabled browsers.
  5. $('.flag-lists-ops-go', context).hide();
  6. // Make select all checkbox work
  7. $('input.flo-table-select-all', context).each(function(i) {
  8. var selectall = $(this);
  9. if (!selectall.hasClass('processed')) {
  10. selectall.change(function(e) {
  11. $('input.flo-select', $(this).parents('form')).attr('checked', $(this).attr('checked'));
  12. }).addClass('processed');
  13. }
  14. });
  15. // Animate the deletion for AJAX deleting.
  16. $('.flo-deleted-value', context).each(function(i) {
  17. var parent = $(this).parents('.view');
  18. $('.flo-select[value='+$(this).val()+']', parent).each(function(i) {
  19. $(this).parents('.views-row, tr').fadeOut().delay(300).remove();
  20. });
  21. });
  22. // Add new options to bottom of list ops dropdown to create new lists on the spot
  23. $('.flag-lists-ops-dropdown', context).each(function(i) {
  24. var select = $(this);
  25. if (!select.hasClass('new-list-processed')) {
  26. select.addClass('new-list-processed');
  27. if (Drupal.settings.flag_lists.types.length > 0) {
  28. $(this).after('<a href="#" class="create-a-new-list">New list?</a><div class="new-list-form"><form><select name="type" class="type"></select><label for="name">List name</label><input type="textfield" name="name" class="name" /></form></div>');
  29. var dialog = $('.new-list-form', $(this).parent()).dialog({
  30. autoOpen: false,
  31. height: 300,
  32. width: 350,
  33. modal: true,
  34. buttons: {
  35. "Create a new list": function() {
  36. var name = $('input.name', $(this)).val();
  37. var type = $('select.type', $(this)).val();
  38. $.getJSON(Drupal.settings.flag_lists.json_path.replace('%', type)+'?name='+name, function(data) {
  39. if (data.error) {
  40. alert(data.error);
  41. }
  42. else {
  43. select.append('<option value="'+data.flag.fid+'">'+data.flag.title+'</option>');
  44. $('input.name', $(this)).val('');
  45. dialog.dialog('close');
  46. }
  47. });
  48. },
  49. Cancel: function() {
  50. dialog.dialog('close');
  51. }
  52. },
  53. close: function() {
  54. }
  55. });
  56. $('.create-a-new-list', $(this).parent())
  57. .button()
  58. .click(function(e) {
  59. dialog.dialog('open');
  60. });
  61. }
  62. // Put entries into the optgroup
  63. for (j in Drupal.settings.flag_lists.types) {
  64. var type = Drupal.settings.flag_lists.types[j];
  65. $('.new-list-form form select.type').append('<option value="'+type+'" class="'+type+'">List for '+type+'</option>');
  66. }
  67. }
  68. });
  69. }
  70. }
  71. })(jQuery);