Streber PM PHP Cross Reference Groupware Applications

Source: /js/listFunctions.js - 249 lines - 7155 bytes - Summary - Text - Print

   1  /**
   2   * all jquery-functions, which are related to lists
   3   *
   4   * is been called on load
   5   *
   6   * included by:
   7   *
   8   * @author     Tino Beirau
   9   * @uses:
  10   * @usedby:     lists
  11   */
  12  
  13  function listFunctions()
  14  {
  15  
  16      /**
  17      * and even rows
  18      *
  19      * since this take up too much client CPU power
  20      * lists are already rendered with odd/even class
  21      *
  22  
  23      $('table.list tr:even').addClass('even');
  24      $('table.list tr:odd').addClass('odd');
  25      */
  26  
  27  
  28      var selected_rows= new Array();
  29      var last_row= false;
  30  
  31      /**
  32      * hover of rows
  33      */
  34      /*$('table.list').find('tr.trow').hover
  35      (
  36          function(){ $(this).addClass('hover'); },
  37          function(){ $(this).removeClass('hover'); }
  38      );
  39      */
  40  
  41  
  42      /**
  43      * prevent normal links from being overwritten by row toggling
  44      */
  45      $('table.list a').click(function(e) {
  46          // Ctrl+Click in Firefox - open link in new Tab
  47          if( e.ctrlKey )
  48          {
  49              document.location.href = gBrowser.addTab(this.href);
  50          }
  51          else 
  52          {
  53              document.location.href= this.href;
  54          }
  55          return false;
  56      });
  57  
  58      $('table.list input[@type=checkbox]').each(function(){
  59          //   td         tr
  60          this.parentNode.parentNode['checkbox_obj']= this;
  61          this['table_row']= this.parentNode.parentNode;
  62          if(this.checked) {
  63              $(this.table_row).addClass('selected');
  64              selected_rows.push(this.table_row);
  65          }
  66      });
  67  
  68  
  69      /**
  70      * click on rows
  71      */
  72      $('table.list.selectable tr').click
  73      (
  74          function(e)
  75          {
  76              var table= this.parentNode.parentNode;
  77  
  78              /**
  79              * add the line to selection if CTRL or ALT pressed
  80              */
  81              if ( e.ctrlKey || e.altKey) {
  82                  if(this.checkbox_obj.checked) {
  83                      this.checkbox_obj.checked= false;
  84                      $(this).removeClass('selected');
  85                      new_rows= Array();
  86  
  87                      for(var i=0; i < selected_rows.length; i++) {
  88                          if(selected_rows[i] != this) {
  89                              new_rows.push(selected_rows[i]);
  90                          }
  91                      }
  92                      selected_rows= new_rows;
  93  
  94                  }
  95                  else {
  96                      this.checkbox_obj.checked= true;
  97                      $(this).addClass('selected');
  98                      selected_rows.push(this);
  99                      last_row= this;
 100                  }
 101              }
 102              /**
 103              * select range
 104              */
 105              else if(e.shiftKey) {
 106                  if(last_row != false) {
 107                      var inside_selection= false;
 108                      var inside_rows= new Array();
 109                      var table_row= this;
 110  
 111                      $(table).find('tr').each(
 112                          function()
 113                          {
 114                              if(this == last_row || this == table_row) {
 115                                  if(inside_selection) {
 116                                      inside_selection = false
 117                                  }
 118                                  else {
 119                                      inside_selection = true;
 120                                  }
 121                              }
 122                              if(inside_selection) {
 123                                  inside_rows.push(this);
 124                              }
 125                          }
 126                      );
 127                  }
 128                  for(var i=0; i < inside_rows.length; i++) {
 129                      $(inside_rows[i]).addClass('selected');
 130                      inside_rows[i].checkbox_obj.checked=true;
 131                      selected_rows.push(inside_rows[i]);
 132                  }
 133                  last_row= table_row;
 134              }
 135  
 136              /**
 137              * deselect all other rows
 138              */
 139              else {
 140                  var was_selected = this.checkbox_obj.checked;
 141  
 142                  last_row= this;
 143  
 144                  var num_selected= selected_rows.length;
 145  
 146                  for(var i=0; i < selected_rows.length; i++) {
 147                      row= selected_rows[i];
 148                      $(row).removeClass('selected');
 149                      row.checkbox_obj.checked = false;
 150                  }
 151  
 152                  /**
 153                  * select new line
 154                  */
 155                  if(was_selected && num_selected == 1)
 156                  {
 157                      this.checkbox_obj.checked= false;
 158                      $(this).removeClass('selected');
 159                      selected_rows= new Array();
 160                  }
 161                  else {
 162                      this.checkbox_obj.checked= true;
 163                      $(this).addClass('selected');
 164  
 165                      selected_rows= new Array(this);
 166                  }
 167                  /**
 168                  * show sideboard
 169                  */
 170                  if(g_enable_sideboard) {
 171                      arr= /\btasks_(\d+)_chk\b/.exec(this.checkbox_obj.id);
 172                      if(arr) {
 173                          id=1*arr[1];
 174      
 175                          $.post('index.php?go=taskAjax',{
 176                              go: 'taskAjax',
 177                              tsk: id
 178                          }, function(str) {
 179                              $('#sideboard').html(str);
 180                              $('#sideboard').addClass('sideboardOn');                        
 181                              $('#outer').addClass('sideboardOn');
 182                              $('#sideboard div.wiki.editable').each(function() {
 183                                  aj= new AjaxEdit(this);
 184                                  ajax_edits.push(aj);
 185                                  this.ajax_edit= aj;
 186                              });
 187                          });
 188                      }
 189                  }
 190              }
 191          }
 192      );
 193  
 194  
 195      /**
 196      * prevent clicks on checkbox to be overwritten by single row select
 197      */
 198      $('table.list input[@type=checkbox]').click
 199      (
 200          function(e)
 201          {
 202              e.stopPropagation();
 203  
 204              if(this.checked)
 205              {
 206                 $(this.parentNode.parentNode).addClass('selected');
 207                 selected_rows.push(this.parentNode.parentNode);
 208              }
 209              else {
 210                 $(this.parentNode.parentNode).removeClass('selected');
 211              }
 212  
 213          }
 214      );
 215  
 216  
 217      /**
 218      * "toggle all checkboxes"-function on top of table
 219      */
 220      $('table.list th.select_col a').click
 221      (
 222          function()
 223          {
 224              selected_rows= new Array();
 225  
 226              //     td         tr         tbody      table
 227              $(this.parentNode.parentNode.parentNode.parentNode).find('tr').each(function()
 228              {
 229                  if(this['checkbox_obj'])
 230                  {
 231                      if(this.checkbox_obj.checked)
 232                      {
 233                          this.checkbox_obj.checked= false;
 234                          $(this).removeClass('selected');
 235                          selected_rows.shift; // here shift works, because jquery runs from Top to Button
 236                      }
 237                      else
 238                      {
 239                          this.checkbox_obj.checked= true;
 240                          $(this).addClass('selected');
 241                          selected_rows.push(this);
 242                      }
 243                  }
 244              });
 245          }
 246      );
 247  
 248  
 249  }

title

Description

title

Description

title

Description

title

title

Body