flag_lists_ops.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 ' + Drupal.settings.flag_lists.listname + '?</a><div class="new-list-form"><form><select name="type" class="type"></select><label for="name">New ' + Drupal.settings.flag_lists.listname + ' 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": function() {
  36. var name = $('input.name', $(this)).val();
  37. var type = $('select.type', $(this)).val();
  38. name = encodeURIComponent(name);
  39. $.getJSON(Drupal.settings.flag_lists.json_path.replace('%', type)+ '?form_token=' + Drupal.settings.flag_lists.form_token +'&name='+name, function(data) {
  40. if (data.error) {
  41. alert(data.error);
  42. }
  43. else {
  44. select.append('<option value="'+data.flag.fid+'">'+data.flag.title+'</option>');
  45. $('input.name', $(this)).val('');
  46. location.reload(true);
  47. dialog.dialog('close');
  48. }
  49. });
  50. },
  51. Cancel: function() {
  52. dialog.dialog('close');
  53. }
  54. },
  55. close: function() {
  56. }
  57. });
  58. $('.create-a-new-list', $(this).parent())
  59. .button()
  60. .click(function(e) {
  61. dialog.dialog('open');
  62. });
  63. }
  64. // Put entries into the optgroup
  65. for (j in Drupal.settings.flag_lists.types) {
  66. var type = Drupal.settings.flag_lists.types[j];
  67. $('.new-list-form form select.type').append('<option value="'+type+'" class="'+type+'">' + Drupal.settings.flag_lists.listname + ' for '+type+'</option>');
  68. }
  69. }
  70. if ( Drupal.settings.flag_lists.types.length <= 1) {
  71. $('.new-list-form form select.type', context).hide();
  72. }
  73. });
  74. }
  75. }
  76. })(jQuery);