home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************\
- * *
- * SmGAdmin.jfm -- Security Group Administration Form *
- * *
- * This form is part of the security administration prebuilt business *
- * solution. This is the group adminstration form. It allows you to define *
- * new groups and update existing groups. This form is called from the *
- * SmAdmin form. *
- * *
- * Dependencies: secur21.gif *
- * *
- * Updated 9/3/96 by IntraBuilder Samples Group *
- * $Revision: 1.5 $ *
- * *
- * Copyright (c) 1996, Borland International, Inc. All rights reserved. *
- * *
- \****************************************************************************/
- #include "security.h"
- // {End Header} Do not remove this comment//
- // Generated on 09/03/96
- //
- var f = new smgadminForm();
- f.open();
- class smgadminForm extends SecurityForm from "SMADMIN.JCF" {
- _sys.scripts.load(_sys.env.home() + "APPS\\SHARED\\CONTROLS.CC")
- with (this) {
- height = 23.8824;
- left = 4.1667;
- top = 0.6471;
- width = 85.6667;
- title = "Group Administration";
- onServerLoad = class::Form_onServerLoad;
- }
-
-
- with (this.rule1 = new Rule(this)){
- left = 2;
- top = 25;
- size = 2;
- right = 76;
- pageno = 0;
- }
-
-
- with (this.rule2 = new Rule(this)){
- left = 2;
- top = 7;
- size = 2;
- right = 76;
- pageno = 0;
- }
-
-
- with (this.actionHTML = new HTML(this)){
- height = 2;
- left = 22;
- top = 3;
- width = 54;
- color = "400040";
- text = "Update Existing Group";
- }
-
-
- with (this.saveButton = new Button(this)){
- left = 28;
- top = 8;
- width = 22;
- text = "Save";
- onServerClick = class::saveButton_onServerClick;
- }
-
-
- with (this.backButton = new Button(this)){
- left = 52;
- top = 8;
- width = 24;
- text = "Back";
- onServerClick = class::backButton_onServerClick;
- }
-
-
- with (this.groupHTML = new HTML(this)){
- height = 1;
- left = 2;
- top = 10;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "Group Name";
- }
-
-
- with (this.groupnameHTML = new HTML(this)){
- height = 1;
- left = 28;
- top = 10;
- width = 22;
- color = "black";
- fontBold = false;
- text = "groupname";
- }
-
-
- with (this.groupnameText = new Text(this)){
- visible = false;
- left = 28;
- top = 10;
- width = 22;
- value = "groupname";
- }
-
-
- with (this.descriptionHTML = new HTML(this)){
- height = 1;
- left = 2;
- top = 11;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "Description";
- }
-
-
- with (this.descriptionText = new Text(this)){
- left = 28;
- top = 11;
- width = 48;
- value = "description";
- }
-
-
- with (this.inUserHTML = new HTML(this)){
- height = 1;
- left = 2;
- top = 13;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "Members";
- }
-
-
- with (this.outUserHTML = new HTML(this)){
- height = 1;
- left = 52;
- top = 13;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "Non-Members";
- }
-
-
- with (this.inUserSelect = new ListBox(this)){
- height = 4;
- left = 2;
- top = 14;
- width = 24;
- }
-
-
- with (this.addUserButton = new Button(this)){
- left = 28;
- top = 15;
- width = 22;
- text = "Add User";
- onServerClick = class::addUserButton_onServerClick;
- }
-
-
- with (this.removeUserButton = new Button(this)){
- left = 28;
- top = 16;
- width = 22;
- text = "Remove User";
- onServerClick = class::removeUserButton_onServerClick;
- }
-
-
- with (this.outUserSelect = new ListBox(this)){
- height = 4;
- left = 52;
- top = 14;
- width = 24;
- }
-
-
- with (this.inResourceHTML = new HTML(this)){
- height = 1;
- left = 2;
- top = 19;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "May Access Resource";
- }
-
-
- with (this.outResourceHTML = new HTML(this)){
- height = 1;
- left = 52;
- top = 19;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "May Not Access Resource";
- }
-
-
- with (this.inResourceSelect = new ListBox(this)){
- height = 4;
- left = 2;
- top = 20;
- width = 24;
- }
-
-
- with (this.addResourceButton = new Button(this)){
- left = 28;
- top = 21;
- width = 22;
- text = "Add Resource";
- onServerClick = class::addResourceButton_onServerClick;
- }
-
-
- with (this.removeResourceButton = new Button(this)){
- left = 28;
- top = 22;
- width = 22;
- text = "Remove Resource";
- onServerClick = class::removeResourceButton_onServerCli;
- }
-
-
- with (this.outResourceSelect = new ListBox(this)){
- height = 4;
- left = 52;
- top = 20;
- width = 24;
- }
-
-
- with (this.errorHTML = new HTML(this)){
- height = 4;
- top = 8;
- width = 80;
- color = "black";
- text = "Error loading group administration form. Notify system administrator.";
- pageno = 2;
- }
-
-
- with (this.backButton2 = new Button(this)){
- top = 12;
- width = 20;
- text = "Back";
- pageno = 2;
- onServerClick = {;this.form.pageno = 1};
- }
-
-
- with (this.GeneratedHTML1 = new GeneratedHTML(this)){
- height = 1;
- left = 2;
- top = 26;
- width = 74;
- pageno = 0;
- }
-
-
- function Form_onServerLoad()
- {
- try {
- //
- // make sure that all the custom properties are set
- //
- var x = this.copyEntity?1:0;
- var x = this.entity.name;
- var x = this.security._admin;
- var x = this.callingForm.title;
- //
- // set the action text
- //
- this.createNew = true;
- if (this.entity.name == null)
- this.actionHTML.text = "Create New Group";
- else if (this.copyEntity)
- this.actionHTML.text = ("Copy " + this.entity.name + " To New Group");
- else {
- this.createNew = false;
- this.actionHTML.text = "Update Existing Group";
- }
- //
- // set the control values on this form
- //
- if (this.createNew) {
- this.groupnameText.value = new StringEx().replicate(" ",20);
- this.groupnameText.visible = true;
- this.groupnameHTML.visible = false;
- }
- else {
- this.groupnameHTML.text = this.entity.name;
- this.groupnameHTML.visible = true;
- this.groupnameText.visible = false;
- }
- this.descriptionText.value = (this.entity.description == null) ?
- new StringEx().replicate(" ",80) :
- this.entity.description;
- // create arrays for the select controls
- this.inUser = new Array();
- this.outUser = new Array();
- this.inResource = new Array();
- this.outResource = new Array();
- // save original groups/resources for use in save
- this.inUserStart = new Array();
- this.inResourceStart = new Array();
- var entity = "";
- // build user lists
- if (this.createNew)
- var inUser = new AssocArray();
- else
- var inUser = this.security.getAllUsers(this.entity.name, SM_ENTITY_GROUP);
- var outUser = this.security.getAllUsers();
- // add all in users to list
- for (var i = 0; i<inUser.count(); i++) {
- entity = (i==0) ? inUser.firstKey : inUser.nextKey(entity);
- this.inUser.add(entity);
- this.inUserStart.add(entity);
- }
- this.inUser.sort();
- this.inUserSelect.options = 'array this.inUser';
- // add users to out list if they are not in in list
- for (i = 0; i<outUser.count(); i++) {
- entity = (i==0) ? outUser.firstKey : outUser.nextKey(entity);
- if (!inUser.isKey(entity))
- this.outUser.add(entity);
- }
- this.outUser.sort();
- this.outUserSelect.options = 'array this.outUser';
- // build resource lists
- if (this.entity.name == null)
- var inResource = new AssocArray();
- else
- var inResource = this.security.getAllResources(this.entity.name, SM_ENTITY_GROUP);
- var outResource = this.security.getAllResources();
- // add all in resources to list
- for (var i = 0; i<inResource.count(); i++) {
- entity = (i==0) ? inResource.firstKey : inResource.nextKey(entity);
- this.inResource.add(entity);
- this.inResourceStart.add(entity);
- }
- this.inResource.sort();
- this.inResourceSelect.options = 'array this.inResource';
- // add resources to out list if they are not in in list
- for (i = 0; i<outResource.count(); i++) {
- entity = (i==0) ? outResource.firstKey : outResource.nextKey(entity);
- if (!inResource.isKey(entity))
- this.outResource.add(entity);
- }
- this.outResource.sort();
- this.outResourceSelect.options = 'array this.outResource';
- }
- catch (Exception e) {
- this.errorHTML.text = "Error loading group: " + e.message + " (" + e.code + ")";
- this.pageno = 2;
- }
- }
-
- function saveButton_onServerClick()
- {
- var form = this.form;
- try {
- // have an exception ready
- var error = new Exception();
- error.message = "";
- error.code = 0;
- //
- // set the properties of the entity object
- //
- // group name
- if (form.createNew) {
- var name = new StringEx(form.groupnameText.value);
- name.string = name.leftTrim();
- name.string = name.rightTrim();
- if (name.length == 0) {
- error.message = "Group name may not be blank";
- throw error;
- }
- else
- form.entity.name = name;
- }
- // description
- form.entity.description = form.descriptionText.value;
- //
- // call create/update with entity object
- //
- if (form.createNew)
- form.security.createGroup(form.entity);
- else
- form.security.updateGroup(form.entity);
- //
- // assign user membership
- //
- for (var i = 0; i<form.inUser.length; i++) {
- if ((form.createNew) || (form.inUserStart.scan(form.inUser[i]) < 0))
- form.security.assignGroupUser(form.entity.name,form.inUser[i]);
- }
- //
- // assign resource privileges
- //
- for (var i = 0; i<form.inResource.length; i++) {
- if ((form.createNew) || (form.inResourceStart.scan(form.inResource[i]) < 0))
- form.security.assignResourceGroup(form.inResource[i],form.entity.name);
- }
- //
- // remove user memberships for existing groups only
- //
- if (!form.createNew) {
- for (var i = 0; i<form.inUserStart.length; i++) {
- if (form.inUser.scan(form.inUserStart[i]) < 0)
- form.security.unassignGroupUser(form.entity.name,form.inUserStart[i]);
- }
- }
- //
- // remove resource privileges for existing groups only
- //
- if (!form.createNew) {
- for (var i = 0; i<form.inResourceStart.length; i++) {
- if (form.inResource.scan(form.inResourceStart[i]) < 0)
- form.security.unassignResourceGroup(form.inResourceStart[i],form.entity.name);
- }
- }
- //
- // Successful change, no longer in createNew mode
- //
- if (form.createNew) {
- form.createNew = false;
- form.actionHTML.text = "Update Existing Group";
- form.groupnameHTML.text = form.entity.name;
- form.groupnameHTML.visible = true;
- form.groupnameText.visible = false;
- }
- //
- // current inXxxxx arrays become the inXxxxxStart arrays
- //
- form.inUserStart = new Array();
- form.inResourceStart = new Array();
- for (var i = 0; i<form.inUser.length; i++)
- form.inUserStart.add(form.inUser[i]);
- for (var i = 0; i<form.inResource.length; i++)
- form.inResourceStart.add(form.inResource[i]);
- }
- catch (Exception e) {
- form.errorHTML.text = "Error saving group: " + e.message + " (" + e.code + ")";
- form.pageno = 2;
- }
- }
-
- function backButton_onServerClick()
- {
- try {
- this.form.callingForm.open();
- this.form.close();
- }
- catch (Exception e) {
- this.form.errorHTML.text = "Unable to return to calling form.";
- this.form.pageno = 2;
- }
- }
-
- function addUserButton_onServerClick()
- {
- if ((this.form.outUserSelect.value.length > 0) && (this.form.outUser.scan(this.form.outUserSelect.value) >= 0)) {
- this.form.inUser.add(this.form.outUserSelect.value);
- this.form.inUser.sort();
- this.form.inUserSelect.options = "array this.form.inUser";
- this.form.outUser.delete(this.form.outUser.scan(this.form.outUserSelect.value));
- this.form.outUser.length -= 1;
- this.form.outUserSelect.options = "array this.form.outUser";
- }
- }
-
- function removeUserButton_onServerClick()
- {
- if ((this.form.inUserSelect.value.length > 0) && (this.form.inUser.scan(this.form.inUserSelect.value) >= 0)) {
- this.form.outUser.add(this.form.inUserSelect.value);
- this.form.outUser.sort();
- this.form.outUserSelect.options = "array this.form.outUser";
- this.form.inUser.delete(this.form.inUser.scan(this.form.inUserSelect.value));
- this.form.inUser.length -= 1;
- this.form.inUserSelect.options = "array this.form.inUser";
- }
- }
-
- function addResourceButton_onServerClick()
- {
- if ((this.form.outResourceSelect.value.length > 0) && (this.form.outResource.scan(this.form.outResourceSelect.value) >= 0)) {
- this.form.inResource.add(this.form.outResourceSelect.value);
- this.form.inResource.sort();
- this.form.inResourceSelect.options = "array this.form.inResource";
- this.form.outResource.delete(this.form.outResource.scan(this.form.outResourceSelect.value));
- this.form.outResource.length -= 1;
- this.form.outResourceSelect.options = "array this.form.outResource";
- }
- }
-
- function removeResourceButton_onServerClick()
- {
- if ((this.form.inResourceSelect.value.length > 0) && (this.form.inResource.scan(this.form.inResourceSelect.value) >= 0)) {
- this.form.outResource.add(this.form.inResourceSelect.value);
- this.form.outResource.sort();
- this.form.outResourceSelect.options = "array this.form.outResource";
- this.form.inResource.delete(this.form.inResource.scan(this.form.inResourceSelect.value));
- this.form.inResource.length -= 1;
- this.form.inResourceSelect.options = "array this.form.inResource";
- }
- }
-
- }
-