home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / progs / ite / ite10d1.exe / DATA.Z / SMGADMIN.JFM < prev    next >
Encoding:
Text File  |  1996-09-07  |  16.1 KB  |  521 lines

  1. /****************************************************************************\
  2. *                                                                            *
  3. * SmGAdmin.jfm  --  Security Group Administration Form                       *
  4. *                                                                            *
  5. * This form is part of the security administration prebuilt business         *
  6. * solution. This is the group adminstration form. It allows you to define    *
  7. * new groups and update existing groups. This form is called from the        *
  8. * SmAdmin form.                                                              *
  9. *                                                                            *
  10. * Dependencies:  secur21.gif                                                 *
  11. *                                                                            *
  12. * Updated 9/3/96 by IntraBuilder Samples Group                               *
  13. * $Revision:   1.5  $                                                        *
  14. *                                                                            *
  15. * Copyright (c) 1996, Borland International, Inc. All rights reserved.       *
  16. *                                                                            *
  17. \****************************************************************************/
  18. #include "security.h"
  19. // {End Header} Do not remove this comment//
  20. // Generated on 09/03/96
  21. //
  22. var f = new smgadminForm();
  23. f.open();
  24. class smgadminForm extends SecurityForm from "SMADMIN.JCF" {
  25.    _sys.scripts.load(_sys.env.home() + "APPS\\SHARED\\CONTROLS.CC")
  26.    with (this) {
  27.       height = 23.8824;
  28.       left = 4.1667;
  29.       top = 0.6471;
  30.       width = 85.6667;
  31.       title = "Group Administration";
  32.       onServerLoad = class::Form_onServerLoad;
  33.    }
  34.  
  35.  
  36.    with (this.rule1 = new Rule(this)){
  37.       left = 2;
  38.       top = 25;
  39.       size = 2;
  40.       right = 76;
  41.       pageno = 0;
  42.    }
  43.  
  44.  
  45.    with (this.rule2 = new Rule(this)){
  46.       left = 2;
  47.       top = 7;
  48.       size = 2;
  49.       right = 76;
  50.       pageno = 0;
  51.    }
  52.  
  53.  
  54.    with (this.actionHTML = new HTML(this)){
  55.       height = 2;
  56.       left = 22;
  57.       top = 3;
  58.       width = 54;
  59.       color = "400040";
  60.       text = "Update Existing Group";
  61.    }
  62.  
  63.  
  64.    with (this.saveButton = new Button(this)){
  65.       left = 28;
  66.       top = 8;
  67.       width = 22;
  68.       text = "Save";
  69.       onServerClick = class::saveButton_onServerClick;
  70.    }
  71.  
  72.  
  73.    with (this.backButton = new Button(this)){
  74.       left = 52;
  75.       top = 8;
  76.       width = 24;
  77.       text = "Back";
  78.       onServerClick = class::backButton_onServerClick;
  79.    }
  80.  
  81.  
  82.    with (this.groupHTML = new HTML(this)){
  83.       height = 1;
  84.       left = 2;
  85.       top = 10;
  86.       width = 24;
  87.       color = "400040";
  88.       fontBold = false;
  89.       text = "Group Name";
  90.    }
  91.  
  92.  
  93.    with (this.groupnameHTML = new HTML(this)){
  94.       height = 1;
  95.       left = 28;
  96.       top = 10;
  97.       width = 22;
  98.       color = "black";
  99.       fontBold = false;
  100.       text = "groupname";
  101.    }
  102.  
  103.  
  104.    with (this.groupnameText = new Text(this)){
  105.       visible = false;
  106.       left = 28;
  107.       top = 10;
  108.       width = 22;
  109.       value = "groupname";
  110.    }
  111.  
  112.  
  113.    with (this.descriptionHTML = new HTML(this)){
  114.       height = 1;
  115.       left = 2;
  116.       top = 11;
  117.       width = 24;
  118.       color = "400040";
  119.       fontBold = false;
  120.       text = "Description";
  121.    }
  122.  
  123.  
  124.    with (this.descriptionText = new Text(this)){
  125.       left = 28;
  126.       top = 11;
  127.       width = 48;
  128.       value = "description";
  129.    }
  130.  
  131.  
  132.    with (this.inUserHTML = new HTML(this)){
  133.       height = 1;
  134.       left = 2;
  135.       top = 13;
  136.       width = 24;
  137.       color = "400040";
  138.       fontBold = false;
  139.       text = "Members";
  140.    }
  141.  
  142.  
  143.    with (this.outUserHTML = new HTML(this)){
  144.       height = 1;
  145.       left = 52;
  146.       top = 13;
  147.       width = 24;
  148.       color = "400040";
  149.       fontBold = false;
  150.       text = "Non-Members";
  151.    }
  152.  
  153.  
  154.    with (this.inUserSelect = new ListBox(this)){
  155.       height = 4;
  156.       left = 2;
  157.       top = 14;
  158.       width = 24;
  159.    }
  160.  
  161.  
  162.    with (this.addUserButton = new Button(this)){
  163.       left = 28;
  164.       top = 15;
  165.       width = 22;
  166.       text = "Add User";
  167.       onServerClick = class::addUserButton_onServerClick;
  168.    }
  169.  
  170.  
  171.    with (this.removeUserButton = new Button(this)){
  172.       left = 28;
  173.       top = 16;
  174.       width = 22;
  175.       text = "Remove User";
  176.       onServerClick = class::removeUserButton_onServerClick;
  177.    }
  178.  
  179.  
  180.    with (this.outUserSelect = new ListBox(this)){
  181.       height = 4;
  182.       left = 52;
  183.       top = 14;
  184.       width = 24;
  185.    }
  186.  
  187.  
  188.    with (this.inResourceHTML = new HTML(this)){
  189.       height = 1;
  190.       left = 2;
  191.       top = 19;
  192.       width = 24;
  193.       color = "400040";
  194.       fontBold = false;
  195.       text = "May Access Resource";
  196.    }
  197.  
  198.  
  199.    with (this.outResourceHTML = new HTML(this)){
  200.       height = 1;
  201.       left = 52;
  202.       top = 19;
  203.       width = 24;
  204.       color = "400040";
  205.       fontBold = false;
  206.       text = "May Not Access Resource";
  207.    }
  208.  
  209.  
  210.    with (this.inResourceSelect = new ListBox(this)){
  211.       height = 4;
  212.       left = 2;
  213.       top = 20;
  214.       width = 24;
  215.    }
  216.  
  217.  
  218.    with (this.addResourceButton = new Button(this)){
  219.       left = 28;
  220.       top = 21;
  221.       width = 22;
  222.       text = "Add Resource";
  223.       onServerClick = class::addResourceButton_onServerClick;
  224.    }
  225.  
  226.  
  227.    with (this.removeResourceButton = new Button(this)){
  228.       left = 28;
  229.       top = 22;
  230.       width = 22;
  231.       text = "Remove Resource";
  232.       onServerClick = class::removeResourceButton_onServerCli;
  233.    }
  234.  
  235.  
  236.    with (this.outResourceSelect = new ListBox(this)){
  237.       height = 4;
  238.       left = 52;
  239.       top = 20;
  240.       width = 24;
  241.    }
  242.  
  243.  
  244.    with (this.errorHTML = new HTML(this)){
  245.       height = 4;
  246.       top = 8;
  247.       width = 80;
  248.       color = "black";
  249.       text = "Error loading group administration form. Notify system administrator.";
  250.       pageno = 2;
  251.    }
  252.  
  253.  
  254.    with (this.backButton2 = new Button(this)){
  255.       top = 12;
  256.       width = 20;
  257.       text = "Back";
  258.       pageno = 2;
  259.       onServerClick = {;this.form.pageno = 1};
  260.    }
  261.  
  262.  
  263.    with (this.GeneratedHTML1 = new GeneratedHTML(this)){
  264.       height = 1;
  265.       left = 2;
  266.       top = 26;
  267.       width = 74;
  268.       pageno = 0;
  269.    }
  270.  
  271.  
  272.    function Form_onServerLoad()
  273.    {
  274.       try {
  275.          // 
  276.          // make sure that all the custom properties are set
  277.          //
  278.          var x = this.copyEntity?1:0;
  279.          var x = this.entity.name;
  280.          var x = this.security._admin;
  281.          var x = this.callingForm.title;
  282.          //
  283.          // set the action text
  284.          //
  285.          this.createNew = true;
  286.          if (this.entity.name == null)
  287.             this.actionHTML.text = "Create New Group";
  288.          else if (this.copyEntity)
  289.             this.actionHTML.text = ("Copy " + this.entity.name + " To New Group");
  290.          else {
  291.             this.createNew = false;
  292.             this.actionHTML.text = "Update Existing Group";
  293.          }
  294.          //
  295.          // set the control values on this form
  296.          //
  297.          if (this.createNew) {
  298.             this.groupnameText.value = new StringEx().replicate(" ",20);
  299.             this.groupnameText.visible = true;
  300.             this.groupnameHTML.visible = false;
  301.          }
  302.          else {
  303.             this.groupnameHTML.text = this.entity.name;
  304.             this.groupnameHTML.visible = true;
  305.             this.groupnameText.visible = false;
  306.          }
  307.          this.descriptionText.value = (this.entity.description == null) ?
  308.                                        new StringEx().replicate(" ",80) : 
  309.                                        this.entity.description;
  310.          // create arrays for the select controls
  311.          this.inUser      = new Array();
  312.          this.outUser     = new Array();
  313.          this.inResource  = new Array();
  314.          this.outResource = new Array();
  315.          // save original groups/resources for use in save
  316.          this.inUserStart     = new Array();
  317.          this.inResourceStart = new Array();
  318.          var entity = "";
  319.          // build user lists
  320.          if (this.createNew)
  321.             var inUser = new AssocArray();
  322.          else
  323.             var inUser = this.security.getAllUsers(this.entity.name, SM_ENTITY_GROUP);
  324.          var outUser = this.security.getAllUsers();
  325.          // add all in users to list
  326.          for (var i = 0; i<inUser.count(); i++) {
  327.             entity = (i==0) ? inUser.firstKey : inUser.nextKey(entity);
  328.             this.inUser.add(entity);
  329.             this.inUserStart.add(entity);
  330.          }
  331.          this.inUser.sort();
  332.          this.inUserSelect.options = 'array this.inUser';
  333.          // add users to out list if they are not in in list
  334.          for (i = 0; i<outUser.count(); i++) {
  335.             entity = (i==0) ? outUser.firstKey : outUser.nextKey(entity);
  336.             if (!inUser.isKey(entity))
  337.                this.outUser.add(entity);
  338.          }
  339.          this.outUser.sort();
  340.          this.outUserSelect.options = 'array this.outUser';
  341.          // build resource lists
  342.          if (this.entity.name == null)
  343.             var inResource = new AssocArray();
  344.          else
  345.             var inResource = this.security.getAllResources(this.entity.name, SM_ENTITY_GROUP);
  346.          var outResource = this.security.getAllResources();
  347.          // add all in resources to list
  348.          for (var i = 0; i<inResource.count(); i++) {
  349.             entity = (i==0) ? inResource.firstKey : inResource.nextKey(entity);
  350.             this.inResource.add(entity);
  351.             this.inResourceStart.add(entity);
  352.          }
  353.          this.inResource.sort();
  354.          this.inResourceSelect.options = 'array this.inResource';
  355.          // add resources to out list if they are not in in list
  356.          for (i = 0; i<outResource.count(); i++) {
  357.             entity = (i==0) ? outResource.firstKey : outResource.nextKey(entity);
  358.             if (!inResource.isKey(entity))
  359.                this.outResource.add(entity);
  360.          }
  361.          this.outResource.sort();
  362.          this.outResourceSelect.options = 'array this.outResource';
  363.       }
  364.       catch (Exception e) {
  365.          this.errorHTML.text = "Error loading group: " + e.message + " (" + e.code + ")";
  366.          this.pageno = 2;
  367.       }
  368.    }
  369.  
  370.    function saveButton_onServerClick()
  371.    {
  372.       var form = this.form;
  373.       try {
  374.          // have an exception ready
  375.          var error = new Exception();
  376.          error.message = "";
  377.          error.code = 0;
  378.          //
  379.          //  set the properties of the entity object
  380.          //
  381.          //  group name
  382.          if (form.createNew) {
  383.             var name = new StringEx(form.groupnameText.value);
  384.             name.string = name.leftTrim();
  385.             name.string = name.rightTrim();
  386.             if (name.length == 0) {
  387.                error.message = "Group name may not be blank";
  388.                throw error;
  389.             }
  390.             else
  391.                form.entity.name = name;
  392.          }
  393.          // description
  394.          form.entity.description = form.descriptionText.value;
  395.          //
  396.          //  call create/update with entity object
  397.          //
  398.          if (form.createNew)
  399.             form.security.createGroup(form.entity);
  400.          else
  401.             form.security.updateGroup(form.entity);
  402.          //
  403.          //  assign user membership
  404.          //
  405.          for (var i = 0; i<form.inUser.length; i++) {
  406.             if ((form.createNew) || (form.inUserStart.scan(form.inUser[i]) < 0))
  407.                form.security.assignGroupUser(form.entity.name,form.inUser[i]);
  408.          }
  409.          //
  410.          //  assign resource privileges
  411.          //
  412.          for (var i = 0; i<form.inResource.length; i++) {
  413.             if ((form.createNew) || (form.inResourceStart.scan(form.inResource[i]) < 0))
  414.                form.security.assignResourceGroup(form.inResource[i],form.entity.name);
  415.          }
  416.          //
  417.          //  remove user memberships for existing groups only
  418.          //
  419.          if (!form.createNew) {
  420.             for (var i = 0; i<form.inUserStart.length; i++) {
  421.                if (form.inUser.scan(form.inUserStart[i]) < 0)
  422.                   form.security.unassignGroupUser(form.entity.name,form.inUserStart[i]);
  423.             }
  424.          }
  425.          //
  426.          //  remove resource privileges for existing groups only
  427.          //
  428.          if (!form.createNew) {
  429.             for (var i = 0; i<form.inResourceStart.length; i++) {
  430.                if (form.inResource.scan(form.inResourceStart[i]) < 0)
  431.                   form.security.unassignResourceGroup(form.inResourceStart[i],form.entity.name);
  432.             }
  433.          }
  434.          //
  435.          //  Successful change, no longer in createNew mode
  436.          //
  437.          if (form.createNew) {
  438.             form.createNew = false;
  439.             form.actionHTML.text = "Update Existing Group";
  440.             form.groupnameHTML.text = form.entity.name;
  441.             form.groupnameHTML.visible = true;
  442.             form.groupnameText.visible = false;
  443.          }
  444.          //
  445.          // current inXxxxx arrays become the inXxxxxStart arrays
  446.          //
  447.          form.inUserStart     = new Array();
  448.          form.inResourceStart = new Array();
  449.          for (var i = 0; i<form.inUser.length; i++)
  450.             form.inUserStart.add(form.inUser[i]);
  451.          for (var i = 0; i<form.inResource.length; i++)
  452.             form.inResourceStart.add(form.inResource[i]);
  453.      }
  454.       catch (Exception e) {
  455.          form.errorHTML.text = "Error saving group: " + e.message + " (" + e.code + ")";
  456.          form.pageno = 2;
  457.       }
  458.    }
  459.  
  460.    function backButton_onServerClick()
  461.    {
  462.       try {
  463.          this.form.callingForm.open();
  464.          this.form.close();
  465.       }
  466.       catch (Exception e) {
  467.          this.form.errorHTML.text = "Unable to return to calling form.";
  468.          this.form.pageno = 2;
  469.       }
  470.    }
  471.  
  472.    function addUserButton_onServerClick()
  473.    {
  474.       if ((this.form.outUserSelect.value.length > 0) && (this.form.outUser.scan(this.form.outUserSelect.value) >= 0)) {
  475.          this.form.inUser.add(this.form.outUserSelect.value);
  476.          this.form.inUser.sort();
  477.          this.form.inUserSelect.options = "array this.form.inUser";
  478.          this.form.outUser.delete(this.form.outUser.scan(this.form.outUserSelect.value));
  479.          this.form.outUser.length -= 1;
  480.          this.form.outUserSelect.options = "array this.form.outUser";
  481.       }
  482.    }
  483.  
  484.    function removeUserButton_onServerClick()
  485.    {
  486.       if ((this.form.inUserSelect.value.length > 0) && (this.form.inUser.scan(this.form.inUserSelect.value) >= 0)) {
  487.          this.form.outUser.add(this.form.inUserSelect.value);
  488.          this.form.outUser.sort();
  489.          this.form.outUserSelect.options = "array this.form.outUser";
  490.          this.form.inUser.delete(this.form.inUser.scan(this.form.inUserSelect.value));
  491.          this.form.inUser.length -= 1;
  492.          this.form.inUserSelect.options  = "array this.form.inUser";
  493.       }
  494.    }
  495.  
  496.    function addResourceButton_onServerClick()
  497.    {
  498.       if ((this.form.outResourceSelect.value.length > 0) && (this.form.outResource.scan(this.form.outResourceSelect.value) >= 0)) {
  499.          this.form.inResource.add(this.form.outResourceSelect.value);
  500.          this.form.inResource.sort();
  501.          this.form.inResourceSelect.options = "array this.form.inResource";
  502.          this.form.outResource.delete(this.form.outResource.scan(this.form.outResourceSelect.value));
  503.          this.form.outResource.length -= 1;
  504.          this.form.outResourceSelect.options = "array this.form.outResource";
  505.       }
  506.    }
  507.  
  508.    function removeResourceButton_onServerClick()
  509.    {
  510.       if ((this.form.inResourceSelect.value.length > 0) && (this.form.inResource.scan(this.form.inResourceSelect.value) >= 0)) {
  511.          this.form.outResource.add(this.form.inResourceSelect.value);
  512.          this.form.outResource.sort();
  513.          this.form.outResourceSelect.options = "array this.form.outResource";
  514.          this.form.inResource.delete(this.form.inResource.scan(this.form.inResourceSelect.value));
  515.          this.form.inResource.length -= 1;
  516.          this.form.inResourceSelect.options  = "array this.form.inResource";
  517.       }
  518.    }
  519.  
  520. }
  521.