cirandas.net

ref: master

public/javascripts/manage-organizations.js


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(function($) {
  // Pagination
  $('#manage-profiles').on('click', '.pagination a', function () {
    $.ajax({
      url: this.href,
      beforeSend: function(){$('#manage-profiles .results').addClass('fetching')},
      complete: function() {$('#manage-profiles .results').removeClass('fetching')},
      dataType: 'script'
    })
    return false;
  });

  // Actions
  $('#manage-profiles').on('click', '.action', function () {
    if(confirm($(this).data('confirm'))) {
      $.ajax({
        url: this.href,
        method: $(this).data('method') || 'get',
        dataType: 'script',
        success: function(data){
          if(data)
            display_notice(JSON.parse(data));
         },
         error: function(xhr, textStatus, message){
           display_notice(message);
         }
      });
      $('#manage-profiles').submit();
    }
    return false;
  });

  // Sorting and Views
  $('#manage-profiles select').live('change', function(){
    $('#manage-profiles').submit();
  });

  // Form Ajax submission
  $('#manage-profiles').submit(function () {
    $.ajax({
      url: this.action,
      data: $(this).serialize(),
      beforeSend: function(){$('#manage-profiles .results').addClass('fetching')},
      complete: function() {$('#manage-profiles .results').removeClass('fetching')},
      dataType: 'script'
    })
    return false;
  });
})(jQuery);