[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/javascript/ -> moveusers.js (source)

   1  /* Reminder: always indent with 4 spaces (no tabs). */
   2  // +---------------------------------------------------------------------------+
   3  // | Geeklog 1.3                                                               |
   4  // +---------------------------------------------------------------------------+
   5  // | Set of javascript functions to support the user-move feature              |
   6  // | where two selectboxes are presented                                       |
   7  // |                                                                           |
   8  // +---------------------------------------------------------------------------+
   9  // | Copyright (C) 2003,2004 by the following authors:                         |
  10  // |                                                                           |
  11  // | Authors:   Matt Kruse  - matt@mattkruse.com                               |
  12  // |            Blaine Lang - blaine@portalparts.com                           |
  13  // +---------------------------------------------------------------------------+
  14  // |                                                                           |
  15  // | This program is free software; you can redistribute it and/or             |
  16  // | modify it under the terms of the GNU General Public License               |
  17  // | as published by the Free Software Foundation; either version 2            |
  18  // | of the License, or (at your option) any later version.                    |
  19  // |                                                                           |
  20  // | This program is distributed in the hope that it will be useful,           |
  21  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  22  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  23  // | GNU General Public License for more details.                              |
  24  // |                                                                           |
  25  // | You should have received a copy of the GNU General Public License         |
  26  // | along with this program; if not, write to the Free Software Foundation,   |
  27  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  28  // |                                                                           |
  29  // +---------------------------------------------------------------------------+
  30  
  31  
  32  // -------------------------------------------------------------------
  33  // setUsers(select_form)
  34  // Used in the Group Admin function to edit the list of included site members
  35  // Used to set a hidden form variable to the result of all the values in the source selectbox
  36  // -------------------------------------------------------------------
  37  function setUsers(f) { 
  38      var destVals = new Array(), opt = 0, separator = "|", d = f.fieldTo; 
  39      while (d[opt]) 
  40          destVals[opt] = d[opt++].value;
  41          if(d[opt] > 1) {
  42              f.groupmembers.value = separator + destVals.join(separator); 
  43          } else {
  44              f.groupmembers.value = destVals.join(separator); 
  45          }
  46          return true; 
  47  }
  48  
  49  // -------------------------------------------------------------------
  50  // sortSelect(select_object)
  51  //   Pass this function a SELECT object and the options will be sorted
  52  //   by their text (display) values
  53  // -------------------------------------------------------------------
  54  function sortSelect(obj) {
  55      var o = new Array();
  56      if (obj.options==null) { return; }
  57      for (var i=0; i<obj.options.length; i++) {
  58          o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
  59          }
  60      if (o.length==0) { return; }
  61      o = o.sort( 
  62          function(a,b) { 
  63              if ((a.text+"") < (b.text+"")) { return -1; }
  64              if ((a.text+"") > (b.text+"")) { return 1; }
  65              return 0;
  66              } 
  67          );
  68  
  69      for (var i=0; i<o.length; i++) {
  70          obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
  71          }
  72      }
  73  
  74  // -------------------------------------------------------------------
  75  // moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
  76  //  This function moves options between select boxes. Works best with
  77  //  multi-select boxes to create the common Windows control effect.
  78  //  Passes all selected values from the first object to the second
  79  //  object and re-sorts each box.
  80  //  If a third argument of 'false' is passed, then the lists are not
  81  //  sorted after the move.
  82  //  If a fourth string argument is passed, this will function as a
  83  //  Regular Expression to match against the TEXT or the options. If 
  84  //  the text of an option matches the pattern, it will NOT be moved.
  85  //  It will be treated as an unmoveable option.
  86  //  You can also put this into the <SELECT> object as follows:
  87  //    onDblClick="moveSelectedOptions(this,this.form.target)
  88  //  This way, when the user double-clicks on a value in one box, it
  89  //  will be transferred to the other (in browsers that support the 
  90  //  onDblClick() event handler).
  91  // -------------------------------------------------------------------
  92  function moveSelectedOptions(from,to) {
  93      // Unselect matching options, if required
  94      if (arguments.length>3) {
  95          var regex = arguments[3];
  96          if (regex != "") {
  97              unSelectMatchingOptions(from,regex);
  98              }
  99          }
 100      // Move them over
 101      for (var i=0; i<from.options.length; i++) {
 102          var o = from.options[i];
 103          if (o.selected) {
 104              to.options[to.options.length] = new Option( o.text, o.value, false, false);
 105              }
 106          }
 107      // Delete them from original
 108      for (var i=(from.options.length-1); i>=0; i--) {
 109          var o = from.options[i];
 110          if (o.selected) {
 111              from.options[i] = null;
 112              }
 113          }
 114      if ((arguments.length<3) || (arguments[2]==true)) {
 115          sortSelect(from);
 116          sortSelect(to);
 117          }
 118      from.selectedIndex = -1;
 119      to.selectedIndex = -1;
 120      }


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics