home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************\
- * *
- * SmRAdmin.jfm -- Security Resource Administration Form *
- * *
- * This form is part of the security administration prebuilt business *
- * solution. This is the resource adminstration form. It allows you to define *
- * new groups and update existing resources. 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 smradminForm();
- f.open();
- class smradminForm extends SecurityForm from "SMADMIN.JCF" {
- _sys.scripts.load(_sys.env.home() + "APPS\\SHARED\\CONTROLS.CC")
- with (this) {
- height = 24.2941;
- left = 2.3333;
- top = 0.1765;
- width = 83.3333;
- title = "Resource Administration";
- onServerLoad = class::Form_onServerLoad;
- }
-
-
- with (this.rule1 = new Rule(this)){
- left = 2;
- top = 7;
- size = 2;
- right = 76;
- pageno = 0;
- }
-
-
- with (this.rule2 = new Rule(this)){
- left = 2;
- top = 26;
- size = 2;
- right = 76;
- pageno = 0;
- }
-
-
- with (this.actionHTML = new HTML(this)){
- height = 1;
- left = 22;
- top = 3;
- width = 54;
- color = "400040";
- text = "Update Existing Resource";
- }
-
-
- 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.resourceHTML = new HTML(this)){
- height = 1;
- left = 2;
- top = 10;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "Resource Name";
- }
-
-
- with (this.resourcenameHTML = new HTML(this)){
- height = 1;
- left = 28;
- top = 10;
- width = 22;
- color = "black";
- fontBold = false;
- text = "resourcename";
- }
-
-
- with (this.resourcenameText = new Text(this)){
- visible = false;
- left = 28;
- top = 10;
- width = 22;
- value = "resourcename";
- }
-
-
- 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 = 19;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "Users With Access";
- }
-
-
- with (this.outUserHTML = new HTML(this)){
- height = 1;
- left = 52;
- top = 19;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "Users Without Access";
- }
-
-
- with (this.inUserSelect = new ListBox(this)){
- height = 4;
- left = 2;
- top = 20;
- width = 24;
- }
-
-
- with (this.addUserButton = new Button(this)){
- left = 28;
- top = 21;
- width = 22;
- text = "Add User";
- onServerClick = class::addUserButton_onServerClick;
- }
-
-
- with (this.removeUserButton = new Button(this)){
- left = 28;
- top = 22;
- width = 22;
- text = "Remove User";
- onServerClick = class::removeUserButton_onServerClick;
- }
-
-
- with (this.outUserSelect = new ListBox(this)){
- height = 4;
- left = 52;
- top = 20;
- width = 24;
- }
-
-
- with (this.inGroupHTML = new HTML(this)){
- height = 1;
- left = 2;
- top = 13;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "Groups With Access";
- }
-
-
- with (this.outGroupHTML = new HTML(this)){
- height = 1;
- left = 52;
- top = 13;
- width = 24;
- color = "400040";
- fontBold = false;
- text = "Groups Without Access";
- }
-
-
- with (this.inGroupSelect = new ListBox(this)){
- height = 4;
- left = 2;
- top = 14;
- width = 24;
- }
-
-
- with (this.addGroupButton = new Button(this)){
- left = 28;
- top = 15;
- width = 22;
- text = "Add Group";
- onServerClick = class::addGroupButton_onServerClick;
- }
-
-
- with (this.removeGroupButton = new Button(this)){
- left = 28;
- top = 16;
- width = 22;
- text = "Remove Group";
- onServerClick = class::removeGroupButton_onServerClick;
- }
-
-
- with (this.outGroupSelect = new ListBox(this)){
- height = 4;
- left = 52;
- top = 14;
- width = 24;
- }
-
-
- with (this.errorHTML = new HTML(this)){
- height = 5;
- left = 2;
- top = 8;
- width = 74;
- color = "black";
- text = "Error loading group administration form. Notify system administrator.";
- pageno = 2;
- }
-
-
- with (this.backButton2 = new Button(this)){
- left = 2;
- top = 14;
- 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 Resource";
- else if (this.copyEntity)
- this.actionHTML.text = ("Copy " + this.entity.name + " To New Resource");
- else {
- this.createNew = false;
- this.actionHTML.text = "Update Existing Resource";
- }
- //
- // set the control values on this form
- //
- if (this.createNew) {
- this.resourcenameText.value = new StringEx().replicate(" ",20);
- this.resourcenameText.visible = true;
- this.resourcenameHTML.visible = false;
- }
- else {
- this.resourcenameHTML.text = this.entity.name;
- this.resourcenameHTML.visible = true;
- this.resourcenameText.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.inGroup = new Array();
- this.outGroup = new Array();
- // save original groups/users for use in save
- this.inUserStart = new Array();
- this.inGroupStart = 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_RESOURCE);
- 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 group lists
- if (this.entity.name == null)
- var inGroup = new AssocArray();
- else
- var inGroup = this.security.getAllGroups(this.entity.name, SM_ENTITY_RESOURCE);
- var outGroup = this.security.getAllGroups();
- // add all in group to list
- for (var i = 0; i<inGroup.count(); i++) {
- entity = (i==0) ? inGroup.firstKey : inGroup.nextKey(entity);
- this.inGroup.add(entity);
- this.inGroupStart.add(entity);
- }
- this.inGroup.sort();
- this.inGroupSelect.options = 'array this.inGroup';
- // add groups to out list if they are not in in list
- for (i = 0; i<outGroup.count(); i++) {
- entity = (i==0) ? outGroup.firstKey : outGroup.nextKey(entity);
- if (!inGroup.isKey(entity))
- this.outGroup.add(entity);
- }
- this.outGroup.sort();
- this.outGroupSelect.options = 'array this.outGroup';
- }
- catch (Exception e) {
- form.errorHTML.text = "Error loading resource: " + 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
- //
- // resource name
- if (form.createNew) {
- var name = new StringEx(form.resourcenameText.value);
- name.string = name.leftTrim();
- name.string = name.rightTrim();
- if (name.length == 0) {
- error.message = "Resource 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.createResource(form.entity);
- else
- form.security.updateResource(form.entity);
- //
- // assign user privileges
- //
- for (var i = 0; i<form.inUser.length; i++) {
- if ((form.createNew) || (form.inUserStart.scan(form.inUser[i]) < 0))
- form.security.assignResourceUser(form.entity.name,form.inUser[i]);
- }
- //
- // assign group privileges
- //
- for (var i = 0; i<form.inGroup.length; i++) {
- if ((form.createNew) || (form.inGroupStart.scan(form.inGroup[i]) < 0))
- form.security.assignResourceGroup(form.entity.name,form.inGroup[i]);
- }
- //
- // remove user privileges for existing resources only
- //
- if (!form.createNew) {
- for (var i = 0; i<form.inUserStart.length; i++) {
- if (form.inUser.scan(form.inUserStart[i]) < 0)
- form.security.unassignResourceUser(form.entity.name,form.inUserStart[i]);
- }
- }
- //
- // remove group privileges for existing resources only
- //
- if (!form.createNew) {
- for (var i = 0; i<form.inGroupStart.length; i++) {
- if (form.inGroup.scan(form.inGroupStart[i]) < 0)
- form.security.unassignResourceGroup(form.entity.name,form.inGroupStart[i]);
- }
- }
- //
- // Successful change, no longer in createNew mode
- //
- if (form.createNew) {
- form.createNew = false;
- form.actionHTML.text = "Update Existing Resource";
- form.resourcenameHTML.text = form.entity.name;
- form.resourcenameHTML.visible = true;
- form.resourcenameText.visible = false;
- }
- //
- // current inXxxxx arrays become the inXxxxxStart arrays
- //
- form.inUserStart = new Array();
- form.inGroupStart = new Array();
- for (var i = 0; i<form.inUser.length; i++)
- form.inUserStart.add(form.inUser[i]);
- for (var i = 0; i<form.inGroup.length; i++)
- form.inGroupStart.add(form.inGroup[i]);
- }
- catch (Exception e) {
- form.errorHTML.text = "Error saving resource: " + 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 addGroupButton_onServerClick()
- {
- if ((this.form.outGroupSelect.value.length > 0) && (this.form.outGroup.scan(this.form.outGroupSelect.value) >= 0)) {
- this.form.inGroup.add(this.form.outGroupSelect.value);
- this.form.inGroup.sort();
- this.form.inGroupSelect.options = "array this.form.inGroup";
- this.form.outGroup.delete(this.form.outGroup.scan(this.form.outGroupSelect.value));
- this.form.outGroup.length -= 1;
- this.form.outGroupSelect.options = "array this.form.outGroup";
- }
- }
-
- function removeGroupButton_onServerClick()
- {
- if ((this.form.inGroupSelect.value.length > 0) && (this.form.inGroup.scan(this.form.inGroupSelect.value) >= 0)) {
- this.form.outGroup.add(this.form.inGroupSelect.value);
- this.form.outGroup.sort();
- this.form.outGroupSelect.options = "array this.form.outGroup";
- this.form.inGroup.delete(this.form.inGroup.scan(this.form.inGroupSelect.value));
- this.form.inGroup.length -= 1;
- this.form.inGroupSelect.options = "array this.form.inGroup";
- }
- }
-
- }
-