SHARE
TWEET

Untitled

a guest May 14th, 2012 20 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. === modified file 'src/schooltool/skin/flourish/resources/gradebook.js'
  2. --- src/schooltool/skin/flourish/resources/gradebook.js 2012-05-07 13:42:59 +0000
  3. +++ src/schooltool/skin/flourish/resources/gradebook.js 2012-05-12 20:36:42 +0000
  4. @@ -340,7 +340,10 @@
  5.      return third_nav_left == limit;
  6.  }
  7.  
  8. +
  9.  $(document).ready(function() {
  10. +    $('.refine').html($('#worksheet-sidebar').html());
  11. +    $('#worksheet-sidebar').empty();
  12.      var form = $('#grid-form');
  13.      form.data('base-font-size', parseInt(form.css('fontSize')));
  14.      // gradebook-part width calculation
  15. @@ -634,3 +637,111 @@
  16.          e.preventDefault();
  17.      });
  18.  });
  19. +
  20. +ST.gradebook = function () {
  21. +    function element_form(element) {
  22. +        return element.closest('form');
  23. +    };
  24. +    function set_html(container_id) {
  25. +        return function(result) {
  26. +            var container = $('#'+container_id);
  27. +            container.html(result);
  28. +        };
  29. +    };
  30. +    function update_part_widths(form) {
  31. +        var gradebook_w = form.find('#gradebook').outerWidth();
  32. +        var students = form.find('#students-part');
  33. +        var students_w = students.outerWidth();
  34. +        var totals = form.find('#totals-part');
  35. +        var totals_headers = totals.find('tr').first().find('th');
  36. +        var grades = form.find('#grades-part');
  37. +        var totals_w = 0;
  38. +        var base_font_size = form.data('base-font-size');
  39. +        if (totals_headers.length > 0) {
  40. +            if (!totals.data('base-total-column-width')) {
  41. +                totals.data('base-total-column-width',
  42. +                            totals_headers.first().outerWidth());
  43. +            }
  44. +            totals_w = (totals_headers.length *
  45. +                        totals.data('base-total-column-width'));
  46. +            totals.find('thead').find('tr').css({
  47. +                height: students.find('thead').height()
  48. +            });
  49. +            totals.css({
  50. +                width: Math.floor(totals_w/base_font_size)+'em'
  51. +            });
  52. +        };
  53. +        var grades_margin_left = students_w;
  54. +        var grades_margin_right = totals_w;
  55. +        grades.css({
  56. +            marginLeft: grades_margin_left,
  57. +            marginRight: Math.floor(totals_w/base_font_size)+'em'
  58. +        });
  59. +    };
  60. +    function update_widths(container_id) {
  61. +        return function(result) {
  62. +            var container = $('#'+container_id);
  63. +            update_part_widths(container);
  64. +        };
  65. +    };
  66. +    function update_colors(container_id) {
  67. +        return function(result) {
  68. +            var container = $('#'+container_id);
  69. +            var parts = container.find('.gradebook-part');
  70. +            parts.find('tbody').find('tr:odd').addClass('odd');
  71. +        };
  72. +    };
  73. +    function get_url(url) {
  74. +        return $.ajax({
  75. +            type: 'get',
  76. +            url: url
  77. +        });
  78. +    };
  79. +    function post_to_url(url, data) {
  80. +        return $.ajax({
  81. +            type: 'post',
  82. +            url: url,
  83. +            data: data
  84. +        });
  85. +    };
  86. +    function submit_form(form) {
  87. +        var url = form.attr('action');
  88. +        var data = form.serializeArray();
  89. +        return post_to_url(url, data);
  90. +    };
  91. +    function update_sidebar() {
  92. +        return function(result) {
  93. +            $('.refine').html($('#worksheet-sidebar').html());
  94. +            $('#worksheet-sidebar').empty();
  95. +        };
  96. +    };
  97. +    return {
  98. +        on_form_submit: function(target) {
  99. +            var button = $(target);
  100. +            var form = element_form(button);
  101. +            var request = submit_form(form);
  102. +            var container_id = form.attr('id');
  103. +            // show spinner near the save button
  104. +            request.done(set_html(container_id));
  105. +            request.done(update_widths(container_id));
  106. +            request.done(update_colors(container_id));
  107. +            return false;
  108. +        },
  109. +        on_tab_link: function(target) {
  110. +            var link = $(target);
  111. +            var tab = link.parent();
  112. +            var third_nav = tab.parent();
  113. +            third_nav.find('li').removeClass('active');
  114. +            tab.addClass('active');
  115. +            var url = link.attr('href');
  116. +            var container_id = 'grid-form';
  117. +            var request = get_url(url);
  118. +            // show spinner near the tab clicked
  119. +            request.done(set_html(container_id));
  120. +            request.done(update_widths(container_id));
  121. +            request.done(update_colors(container_id));
  122. +            request.done(update_sidebar());
  123. +            return false;
  124. +        }
  125. +    };
  126. +}();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top