Tags:
create new tag
, view all tags

Script to Manage Groups

This script help the managing TWikiGroups. To use it, add %INCLUDE{"ScriptToManageGroups"}% to your group and a form will help you to manage it.


The Include Starts Hire

%STARTINCLUDE%
<script type="text/javascript">
<!-- <pre> - scape from TWiki parser  (start)

// Get an array with this group users:
var thisGroupArr = "%GROUP%".replace(/%MAINWEB%\./g,'').replace(/\s/g,'').split(',');
window.thisGroupCount = thisGroupArr.length;
// Transform the Array in a Hash:
window.thisGroup = {};
for ( var i in thisGroupArr ) {
  thisGroup[ thisGroupArr[i] ] = true;
}

function getRawText() {
  if(ta=document.getElementById("rawFrame").contentDocument.getElementsByTagName('textarea')[0]){
    return ta.value;
  } else {
    return false;
  }
}

var lastSearchForUser = {};
function searchUser(field, users) {
  if ( field.value.length == 0 ) { return false; }
  if ( lastSearchForUser[field.name] == field.value ){
    return false;
  } else {
    lastSearchForUser[field.name] = field.value;
  }
  var selectionStart = field.value.length;
  for ( var user in users ) {
    if ( user.toLowerCase().indexOf( field.value.toLowerCase() ) == 0 ) {
      field.value = user;
    }
  }
  var selectionEnd = field.value.length;
  field.selectionStart = selectionStart;
  field.selectionEnd = selectionEnd;
}

function hashKeysToString(hash){
  var array = new Array();
  for ( var key in hash ) {
    if ( hash[key] ) { array = array.concat(key); }
  }
  return array.sort().join(', ');
}

function addUser(form) {
  var user = form["userToAdd"+blockCash].value;
  if ( thisGroup[user] ) {
    alert('The user "'+user+'" is already on this topic.');
    return false;
  }
  if ( !usersToAdd[user] ) {
    alert('The user "'+user+'" is not an valid user to add');
    return false;
  }
  thisGroup[user] = true;
  var users = hashKeysToString(thisGroup);
  var raw = getRawText();
  if ( !raw ) { alert("Can't get raw text.\nPlease, try again."); return false; }
  form.text.value = raw.replace( /(.*   \* Set GROUP = )[^\n]*(\n.*)/g, '$1'+users+'$2' );
  return true;
}

function delUser(form) {
  var user = form["userToDel"+blockCash].value;
  if ( !thisGroup[user] ) {
    alert('The user "'+user+'" is not on this topic.');
    return false;
  }
  thisGroup[user] = false;
  var users = hashKeysToString(thisGroup);
  var raw = getRawText();
  if ( !raw ) { alert("Can't get raw text.\nPlease, try again."); return false; }
  form.text.value = raw.replace( /(.*   \* Set GROUP = )[^\n]*(\n.*)/g, '$1'+users+'$2' );
  return true;
}

function enableGroupManager(){
  document.fAdd["userToAdd"+blockCash].disabled=false;
  document.fAdd["submit"].disabled=false;
  document.fDel["userToDel"+blockCash].disabled=false;
  document.fDel["submit"].disabled=false;
}

function loadGroupManager(){
  window.blockCash = new Date();
  window.blockCash = window.blockCash.getHours().toString()
                   + window.blockCash.getMinutes().toString()
                   + window.blockCash.getSeconds().toString()
                   + window.blockCash.getMilliseconds().toString();
  var html = '<div id="statusLoadGM" style="text-align:center;"><b id="loadingUsers" style="background-color:#FC0;color:#000;">&nbsp; loading users... &nbsp;</b></div>';
  html+= '<form name="fAdd" action="%SCRIPTURL%/preview%SCRIPTSUFFIX%/%INCLUDINGWEB%/%INCLUDINGTOPIC%" onsubmit="return addUser(this)" method="post">';
  html+= 'Add user to this group: ';
  html+= '<input type="text" name="userToAdd'+blockCash+'" size="30" onkeyup="searchUser(this,usersToAdd)" disabled="disabled" />';
  html+= '<input type="hidden" name="text" />';
  html+= '<input type="submit" name="submit" value="Add" style="width:70px;" disabled="disabled" />';
  html+= '</form>';
  html+= '<br/>';
  html+= '<form name="fDel" action="%SCRIPTURL%/preview%SCRIPTSUFFIX%/%INCLUDINGWEB%/%INCLUDINGTOPIC%" onsubmit="return delUser(this)" method="post">';
  html+= 'Remove user from this group: ';
  html+= '<input type="text" name="userToDel'+blockCash+'" size="30" onkeyup="searchUser(this,thisGroup)" disabled="disabled" />';
  html+= '<input type="hidden" name="text" />';
  html+= '<input type="submit" name="submit" value="Remove" style="width:70px;" disabled="disabled" />';
  html+= '</form>';
  var groupManager = document.getElementById("groupManager");
  groupManager.innerHTML = html;
  document.getElementById("scriptFrame").src = "%SCRIPTURL%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%?skin=text&group=%INCLUDINGTOPIC%&search=SEARCH";

  window.loadingUsers = {
    obj : document.getElementById("loadingUsers").style,
    bgColor : parseInt("FFC800", 16),
    incColor : -1,
    pulse : function () {
      this.bgColor += parseInt("000100", 16) * this.incColor * 8;
      if ( this.bgColor == parseInt("FF0000", 16) ) { this.incColor=+1; }
      if ( this.bgColor == parseInt("FFF800", 16) ) { this.incColor=-1; }
      this.obj.backgroundColor = "#" + this.bgColor.toString(16);
      if ( !this.pulsing ){
        this.pulsing = setInterval("loadingUsers.pulse();", 33);
      }
    },
    pulsing : false
  }
  window.loadingUsers.pulse();
}

//  </pre> - scape from TWiki parser  (end) -->
</script>
<iframe id="rawFrame" src="%SCRIPTURL%/view%SCRIPTSUFFIX%/%INCLUDINGWEB%/%INCLUDINGTOPIC%?raw=on&skin=plain" frameborder="0" width="0" height="0" style="display:none;"></iframe>
<iframe id="scriptFrame" src="" Xframeborder="0" Xwidth="0" Xheight="0" Xstyle="display:none;"></iframe>
<div id="groupManager" align="right" style="padding-right:30px;">
<input type="button" onclick="loadGroupManager()" value="Manage this Group" />
</div>
%STOPINCLUDE%

The Include Stops Hire


This script is used in this grups

Searched:

<span class='twikiAlert'> Warning: Can't find topic <nop>Main.<nop>ScriptToManageGroups}nosearch=on </span>

-- TWiki:Main.AurelioAHeckert - 01 May 2005


<!--AutoSection/Main/ScriptToManageGroups/4/2-->

Comments (Only on TWiki.org)

It's working fine in https://gnosislivre.org/twiki/bin/view/Main/GnosisGroup but hire in TWiki.org the loading time is very very long... Are to muth users hire. I need to put a way to the user decide to open the Group Mananger or not.

-- Main.AurelioAHeckert - 01 May 2005

Ok! Now it's working good!

The loading is on a iframe and an "loading..." is puted while the array of users is not done.

Peter, can you put =%<nop>INCLUDE{"ScriptToManageGroups

Number of topics: 0
= in TWikiGroupTemplate?

-- AurelioAHeckert - 01 May 2005

The number off "all users" is wrong becose in past versions of the TWiki the user topic do not recive the parent TWikiUsers. I think the rigth way to put every body is fixing the parent of old users.

-- AurelioAHeckert - 01 May 2005

New ideas hire! I will do it better.

-- AurelioAHeckert - 12 May 2005

Aurelio, i'd like to try your script. I have some questions:

  1. What does the screen on the right do? Currently it seems to display this topic.
  2. How can you select a username "Ab" when there's also a user "Aaaaaaaaaaaa"? This doesn't seem to work on my install (IE6, Win2K)
  3. Would it be a good idea to present a dropdown select box to add/remove users?

-- JosMaccabiani - 30 Jun 2005

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2005-06-30 - JosMaccabiani
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.