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

  1. /****************************************************************************\
  2. *                                                                            *
  3. * SmRAdmin.jfm  --  Security Resource Administration Form                    *
  4. *                                                                            *
  5. * This form is part of the security administration prebuilt business         *
  6. * solution. This is the resource adminstration form. It allows you to define *
  7. * new groups and update existing resources. 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 smradminForm();
  23. f.open();
  24. class smradminForm extends SecurityForm from "SMADMIN.JCF" {
  25.    _sys.scripts.load(_sys.env.home() + "APPS\\SHARED\\CONTROLS.CC")
  26.    with (this) {
  27.       height = 24.2941;
  28.       left = 2.3333;
  29.       top = 0.1765;
  30.       width = 83.3333;
  31.       title = "Resource Administration";
  32.       onServerLoad = class::Form_onServerLoad;
  33.    }
  34.  
  35.  
  36.    with (this.rule1 = new Rule(this)){
  37.       left = 2;
  38.       top = 7;
  39.       size = 2;
  40.       right = 76;
  41.       pageno = 0;
  42.    }
  43.  
  44.  
  45.    with (this.rule2 = new Rule(this)){
  46.       left = 2;
  47.       top = 26;
  48.       size = 2;
  49.       right = 76;
  50.       pageno = 0;
  51.    }
  52.  
  53.  
  54.    with (this.actionHTML = new HTML(this)){
  55.       height = 1;
  56.       left = 22;
  57.       top = 3;
  58.       width = 54;
  59.       color = "400040";
  60.       text = "Update Existing Resource";
  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.resourceHTML = new HTML(this)){
  83.       height = 1;
  84.       left = 2;
  85.       top = 10;
  86.       width = 24;
  87.       color = "400040";
  88.       fontBold = false;
  89.       text = "Resource Name";
  90.    }
  91.  
  92.  
  93.    with (this.resourcenameHTML = new HTML(this)){
  94.       height = 1;
  95.       left = 28;
  96.       top = 10;
  97.       width = 22;
  98.       color = "black";
  99.       fontBold = false;
  100.       text = "resourcename";
  101.    }
  102.  
  103.  
  104.    with (this.resourcenameText = new Text(this)){
  105.       visible = false;
  106.       left = 28;
  107.       top = 10;
  108.       width = 22;
  109.       value = "resourcename";
  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 = 19;
  136.       width = 24;
  137.       color = "400040";
  138.       fontBold = false;
  139.       text = "Users With Access";
  140.    }
  141.  
  142.  
  143.    with (this.outUserHTML = new HTML(this)){
  144.       height = 1;
  145.       left = 52;
  146.       top = 19;
  147.       width = 24;
  148.       color = "400040";
  149.       fontBold = false;
  150.       text = "Users Without Access";
  151.    }
  152.  
  153.  
  154.    with (this.inUserSelect = new ListBox(this)){
  155.       height = 4;
  156.       left = 2;
  157.       top = 20;
  158.       width = 24;
  159.    }
  160.  
  161.  
  162.    with (this.addUserButton = new Button(this)){
  163.       left = 28;
  164.       top = 21;
  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 = 22;
  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 = 20;
  184.       width = 24;
  185.    }
  186.  
  187.  
  188.    with (this.inGroupHTML = new HTML(this)){
  189.       height = 1;
  190.       left = 2;
  191.       top = 13;
  192.       width = 24;
  193.       color = "400040";
  194.       fontBold = false;
  195.       text = "Groups With Access";
  196.    }
  197.  
  198.  
  199.    with (this.outGroupHTML = new HTML(this)){
  200.       height = 1;
  201.       left = 52;
  202.       top = 13;
  203.       width = 24;
  204.       color = "400040";
  205.       fontBold = false;
  206.       text = "Groups Without Access";
  207.    }
  208.  
  209.  
  210.    with (this.inGroupSelect = new ListBox(this)){
  211.       height = 4;
  212.       left = 2;
  213.       top = 14;
  214.       width = 24;
  215.    }
  216.  
  217.  
  218.    with (this.addGroupButton = new Button(this)){
  219.       left = 28;
  220.       top = 15;
  221.       width = 22;
  222.       text = "Add Group";
  223.       onServerClick = class::addGroupButton_onServerClick;
  224.    }
  225.  
  226.  
  227.    with (this.removeGroupButton = new Button(this)){
  228.       left = 28;
  229.       top = 16;
  230.       width = 22;
  231.       text = "Remove Group";
  232.       onServerClick = class::removeGroupButton_onServerClick;
  233.    }
  234.  
  235.  
  236.    with (this.outGroupSelect = new ListBox(this)){
  237.       height = 4;
  238.       left = 52;
  239.       top = 14;
  240.       width = 24;
  241.    }
  242.  
  243.  
  244.    with (this.errorHTML = new HTML(this)){
  245.       height = 5;
  246.       left = 2;
  247.       top = 8;
  248.       width = 74;
  249.       color = "black";
  250.       text = "Error loading group administration form. Notify system administrator.";
  251.       pageno = 2;
  252.    }
  253.  
  254.  
  255.    with (this.backButton2 = new Button(this)){
  256.       left = 2;
  257.       top = 14;
  258.       width = 20;
  259.       text = "Back";
  260.       pageno = 2;
  261.       onServerClick = {;this.form.pageno = 1};
  262.    }
  263.  
  264.  
  265.    with (this.GeneratedHTML1 = new GeneratedHTML(this)){
  266.       height = 1;
  267.       left = 2;
  268.       top = 26;
  269.       width = 74;
  270.       pageno = 0;
  271.    }
  272.  
  273.  
  274.    function Form_onServerLoad()
  275.    {
  276.       try {
  277.          // 
  278.          // make sure that all the custom properties are set
  279.          //
  280.          var x = this.copyEntity?1:0;
  281.          var x = this.entity.name;
  282.          var x = this.security._admin;
  283.          var x = this.callingForm.title;
  284.          //
  285.          // set the action text
  286.          //
  287.          this.createNew = true;
  288.          if (this.entity.name == null)
  289.             this.actionHTML.text = "Create New Resource";
  290.          else if (this.copyEntity)
  291.             this.actionHTML.text = ("Copy " + this.entity.name + " To New Resource");
  292.          else {
  293.             this.createNew = false;
  294.             this.actionHTML.text = "Update Existing Resource";
  295.          }
  296.          //
  297.          // set the control values on this form
  298.          //
  299.          if (this.createNew) {
  300.             this.resourcenameText.value = new StringEx().replicate(" ",20);
  301.             this.resourcenameText.visible = true;
  302.             this.resourcenameHTML.visible = false;
  303.          }
  304.          else {
  305.             this.resourcenameHTML.text = this.entity.name;
  306.             this.resourcenameHTML.visible = true;
  307.             this.resourcenameText.visible = false;
  308.          }
  309.          this.descriptionText.value = (this.entity.description == null) ?
  310.                                        new StringEx().replicate(" ",80) : 
  311.                                        this.entity.description;
  312.          // create arrays for the select controls
  313.          this.inUser   = new Array();
  314.          this.outUser  = new Array();
  315.          this.inGroup  = new Array();
  316.          this.outGroup = new Array();
  317.          // save original groups/users for use in save
  318.          this.inUserStart  = new Array();
  319.          this.inGroupStart = new Array();
  320.          var entity = "";
  321.          // build user lists
  322.          if (this.createNew)
  323.             var inUser = new AssocArray();
  324.          else
  325.             var inUser = this.security.getAllUsers(this.entity.name, SM_ENTITY_RESOURCE);
  326.          var outUser = this.security.getAllUsers();
  327.          // add all in users to list
  328.          for (var i = 0; i<inUser.count(); i++) {
  329.             entity = (i==0) ? inUser.firstKey : inUser.nextKey(entity);
  330.             this.inUser.add(entity);
  331.             this.inUserStart.add(entity);
  332.          }
  333.          this.inUser.sort();
  334.          this.inUserSelect.options = 'array this.inUser';
  335.          // add users to out list if they are not in in list
  336.          for (i = 0; i<outUser.count(); i++) {
  337.             entity = (i==0) ? outUser.firstKey : outUser.nextKey(entity);
  338.             if (!inUser.isKey(entity))
  339.                this.outUser.add(entity);
  340.          }
  341.          this.outUser.sort();
  342.          this.outUserSelect.options = 'array this.outUser';
  343.          // build group lists
  344.          if (this.entity.name == null)
  345.             var inGroup = new AssocArray();
  346.          else
  347.             var inGroup = this.security.getAllGroups(this.entity.name, SM_ENTITY_RESOURCE);
  348.          var outGroup = this.security.getAllGroups();
  349.          // add all in group to list
  350.          for (var i = 0; i<inGroup.count(); i++) {
  351.             entity = (i==0) ? inGroup.firstKey : inGroup.nextKey(entity);
  352.             this.inGroup.add(entity);
  353.             this.inGroupStart.add(entity);
  354.          }
  355.          this.inGroup.sort();
  356.          this.inGroupSelect.options = 'array this.inGroup';
  357.          // add groups to out list if they are not in in list
  358.          for (i = 0; i<outGroup.count(); i++) {
  359.             entity = (i==0) ? outGroup.firstKey : outGroup.nextKey(entity);
  360.             if (!inGroup.isKey(entity))
  361.                this.outGroup.add(entity);
  362.          }
  363.          this.outGroup.sort();
  364.          this.outGroupSelect.options = 'array this.outGroup';
  365.       }
  366.       catch (Exception e) {
  367.          form.errorHTML.text = "Error loading resource: " + e.message + " (" + e.code + ")";
  368.          this.pageno = 2;
  369.       }
  370.    }
  371.  
  372.    function saveButton_onServerClick()
  373.    {
  374.       var form = this.form;
  375.       try {
  376.          // have an exception ready
  377.          var error = new Exception();
  378.          error.message = "";
  379.          error.code = 0;
  380.          //
  381.          //  set the properties of the entity object
  382.          //
  383.          //  resource name
  384.          if (form.createNew) {
  385.             var name = new StringEx(form.resourcenameText.value);
  386.             name.string = name.leftTrim();
  387.             name.string = name.rightTrim();
  388.             if (name.length == 0) {
  389.                error.message = "Resource name may not be blank";
  390.                throw error;
  391.             }
  392.             else
  393.                form.entity.name = name;
  394.          }
  395.          // description
  396.          form.entity.description = form.descriptionText.value;
  397.          //
  398.          //  call create/update with entity object
  399.          //
  400.          if (form.createNew)
  401.             form.security.createResource(form.entity);
  402.          else
  403.             form.security.updateResource(form.entity);
  404.          //
  405.          //  assign user privileges
  406.          //
  407.          for (var i = 0; i<form.inUser.length; i++) {
  408.             if ((form.createNew) || (form.inUserStart.scan(form.inUser[i]) < 0))
  409.                form.security.assignResourceUser(form.entity.name,form.inUser[i]);
  410.          }
  411.          //
  412.          //  assign group privileges
  413.          //
  414.          for (var i = 0; i<form.inGroup.length; i++) {
  415.             if ((form.createNew) || (form.inGroupStart.scan(form.inGroup[i]) < 0))
  416.                form.security.assignResourceGroup(form.entity.name,form.inGroup[i]);
  417.          }
  418.          //
  419.          //  remove user privileges for existing resources only
  420.          //
  421.          if (!form.createNew) {
  422.             for (var i = 0; i<form.inUserStart.length; i++) {
  423.                if (form.inUser.scan(form.inUserStart[i]) < 0)
  424.                   form.security.unassignResourceUser(form.entity.name,form.inUserStart[i]);
  425.             }
  426.          }
  427.          //
  428.          //  remove group privileges for existing resources only
  429.          //
  430.          if (!form.createNew) {
  431.             for (var i = 0; i<form.inGroupStart.length; i++) {
  432.                if (form.inGroup.scan(form.inGroupStart[i]) < 0)
  433.                   form.security.unassignResourceGroup(form.entity.name,form.inGroupStart[i]);
  434.             }
  435.          }
  436.          //
  437.          //  Successful change, no longer in createNew mode
  438.          //
  439.          if (form.createNew) {
  440.             form.createNew = false;
  441.             form.actionHTML.text = "Update Existing Resource";
  442.             form.resourcenameHTML.text = form.entity.name;
  443.             form.resourcenameHTML.visible = true;
  444.             form.resourcenameText.visible = false;
  445.          }
  446.          //
  447.          // current inXxxxx arrays become the inXxxxxStart arrays
  448.          //
  449.          form.inUserStart     = new Array();
  450.          form.inGroupStart = new Array();
  451.          for (var i = 0; i<form.inUser.length; i++)
  452.             form.inUserStart.add(form.inUser[i]);
  453.          for (var i = 0; i<form.inGroup.length; i++)
  454.             form.inGroupStart.add(form.inGroup[i]);
  455.       }
  456.       catch (Exception e) {
  457.          form.errorHTML.text = "Error saving resource: " + e.message + " (" + e.code + ")";
  458.          form.pageno = 2;
  459.       }
  460.    }
  461.  
  462.    function backButton_onServerClick()
  463.    {
  464.       try {
  465.          this.form.callingForm.open();
  466.          this.form.close();
  467.       }
  468.       catch (Exception e) {
  469.          this.form.errorHTML.text = "Unable to return to calling form.";
  470.          this.form.pageno = 2;
  471.       }
  472.    }
  473.  
  474.    function addUserButton_onServerClick()
  475.    {
  476.       if ((this.form.outUserSelect.value.length > 0) && (this.form.outUser.scan(this.form.outUserSelect.value) >= 0)) {
  477.          this.form.inUser.add(this.form.outUserSelect.value);
  478.          this.form.inUser.sort();
  479.          this.form.inUserSelect.options = "array this.form.inUser";
  480.          this.form.outUser.delete(this.form.outUser.scan(this.form.outUserSelect.value));
  481.          this.form.outUser.length -= 1;
  482.          this.form.outUserSelect.options = "array this.form.outUser";
  483.       }
  484.    }
  485.  
  486.    function removeUserButton_onServerClick()
  487.    {
  488.       if ((this.form.inUserSelect.value.length > 0) && (this.form.inUser.scan(this.form.inUserSelect.value) >= 0)) {
  489.          this.form.outUser.add(this.form.inUserSelect.value);
  490.          this.form.outUser.sort();
  491.          this.form.outUserSelect.options = "array this.form.outUser";
  492.          this.form.inUser.delete(this.form.inUser.scan(this.form.inUserSelect.value));
  493.          this.form.inUser.length -= 1;
  494.          this.form.inUserSelect.options  = "array this.form.inUser";
  495.       }
  496.    }
  497.  
  498.    function addGroupButton_onServerClick()
  499.    {
  500.       if ((this.form.outGroupSelect.value.length > 0) && (this.form.outGroup.scan(this.form.outGroupSelect.value) >= 0)) {
  501.          this.form.inGroup.add(this.form.outGroupSelect.value);
  502.          this.form.inGroup.sort();
  503.          this.form.inGroupSelect.options = "array this.form.inGroup";
  504.          this.form.outGroup.delete(this.form.outGroup.scan(this.form.outGroupSelect.value));
  505.          this.form.outGroup.length -= 1;
  506.          this.form.outGroupSelect.options = "array this.form.outGroup";
  507.       }
  508.    }
  509.  
  510.    function removeGroupButton_onServerClick()
  511.    {
  512.       if ((this.form.inGroupSelect.value.length > 0) && (this.form.inGroup.scan(this.form.inGroupSelect.value) >= 0)) {
  513.          this.form.outGroup.add(this.form.inGroupSelect.value);
  514.          this.form.outGroup.sort();
  515.          this.form.outGroupSelect.options = "array this.form.outGroup";
  516.          this.form.inGroup.delete(this.form.inGroup.scan(this.form.inGroupSelect.value));
  517.          this.form.inGroup.length -= 1;
  518.          this.form.inGroupSelect.options  = "array this.form.inGroup";
  519.       }
  520.    }
  521.  
  522. }
  523.