]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Added smarter check all checkboxes for ECML admin area.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 19 Apr 2010 19:44:34 +0000 (19:44 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 19 Apr 2010 19:44:34 +0000 (19:44 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@5804 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/ecml/views/default/ecml/admin/ecml_admin.php

index 36ad11f933515217ab2c9bf72189cf65f53993e6..0451ad9218d783decea597153fb799e24c42e0a0 100644 (file)
@@ -82,6 +82,41 @@ $(document).ready(function() {
        // append check all link
        $('.ecml_check_all').before('<input type="checkbox" checked="checked" class="check_all">');
 
+       // determin initial state of checkall checkbox.
+       $('.ecml_check_all').each(function() {
+               var keyword = $(this).hasClass('ecml_keyword');
+               var checkbox = $(this).parent().find('input[type=checkbox]');
+               var checked;
+
+               // no keywords checked, checkall unchecked
+               // any keyword checked, checkall unchecked
+               // all keywords checked, checkall checked
+
+               // if keyword, check the TR
+               if (keyword) {
+                       checked = true;
+                       $(this).parent().parent().find('input').each(function() {
+                               if (!$(this).hasClass('check_all') && !$(this).attr('disabled')) {
+                                       checked = (checked && $(this).attr('checked'));
+                                       // can't break...
+                               }
+                       });
+                       checkbox.attr('checked', checked);
+               } else {
+                       checked = true;
+                       var rowIndex = $(this).parent().parent().children().index($(this).parent());
+
+                       $('.ecml_admin_table > tbody > tr td:nth-child(' + (rowIndex + 1) + ') input[type=checkbox]').each(function() {
+                               if (!$(this).hasClass('check_all') && !$(this).attr('disabled')) {
+                                       checked = (checked && $(this).attr('checked'));
+                                       // can't break...
+                               }
+                       });
+                       checkbox.attr('checked', checked);
+               }
+       });
+
+       // handle checkall boxes
        $('input.check_all').click(function() {
                // yoinked from
                // http://stackoverflow.com/questions/788225/table-row-and-column-number-in-jquery
@@ -105,4 +140,4 @@ $(document).ready(function() {
                }
        });
 });
-</script>
+</script>
\ No newline at end of file