1. Module MultiEdit

    Artikel: AN0001821Aktualisiert: 03.10.2018
    Die vorgegebene Sprachenversion vom Artikeltext wird angezeigt, weil es kein Text von der ausgewählten Sprache und Version gibt.

    This module contains webpart for a mass record editing. By means of a simple scripting you can edit more records at one time and accelerate some operations in this way.

     

    You will pass list of records, to which the user has access rights, to the webpart by means of scripting. Webpart will display them in form of rows where each field can be edited. User can also delete records or create new ones.

    There is information about parent record, if it exists, in the upper part of the webpart - e.g. invoice record, where user can change invoice items.

    Webpart does not ensure access right control. This has to be managed by means of scripts by initialization. It is necessary to read only those records that the user can edit and save only what has to be saved.

    Configuration

    Property Description
    Enable new records Property for creation of new records. When enabled user can create a new record.
    Enable to delete records Property for deletion of records. When enabled user can delete records.
    Script for initialization Script is executed at display of the page with webpart.
    Script for reading records Script is executed reading records for editing.
    Script for displaying records Script is executed for ech record before its display on the page.
    Script for initialization of a new record Script is executed at at new record creation.
    Script for saving records Script is executed at saving all the records.
    Script for record deletion Script is executed at record deletion.

    Script parameters for initialization

    Verify in the script whether user can edit anything. Then read the class that will be edited and columns that shall be displayed in the webpart.

    OGInit - object for web initialization.

    OGWebPart - instance of the webpart.

    OGWebParts - list of all webparts in the page. In order to access the webparts use their code.

    Properties of object OGInit.

    Property Description
    bool NewAsPerson Indication, whether first a window for selection of an user shall pop up and the user is then filled in the new record. When not checked new record is added immediately.
    ClassDef ClassDef Class, records of which the user shall edit.
    Query Query Query, records of which the user shall see.
    ColumnClassDefList Columns List of columns from class that shall be displayed to user for editing.
    string ErrorMessage When error message is defined user will be redirected to an error page. Use this property e.g. for unauthorized access to this page.
    string LinkNavigation Text for a breadcrumb navigation. Format is same as by method OGForm.SetLinkNavigation.
    string BackUrl URL for button Back.
    bool HorizontalScrollable Indication whether data shall be displayed in horizontal scrollbar - the page is then not spread too much.
    void SetColumnWidth(int index, int width) Method sets width of the column.
    void SetColumnCss(int index, string css) Method sets CSS style for column.
    void SetColumnReadOnly(int index, bool readOnly) Method sets readonly indication for column.

    Script parameters for reading list of records

    In the script read the records, that the user shall see and edit.

    OGInit - object form initialization. It contains class, for which the records shall be read.

    OGWebPart - instance of the webpart.

    OGWebParts - list of all webparts in the page. In order to access the webparts use their code.

    Return the list of records by means of return.

    Script parameters for record display

    Script is executed for each record before it is displayed in the page.

    OGRow - configuration for currently displayed record.
    OGClassDef - class to which the record belongs.
    OGDataRow - record that shall be displayed.

    OGWebPart - instance of the webpart.

    OGWebParts - list of all webparts in the page. In order to access the webparts use their code.

    Properties of the object OGRow

    Name Description
    bool EnableDelete Indication for enabling/disabling record deletion.
    bool EnableSave Indication for enabling/disabling record saving.
    ColumnMultiEdit this[string code] Function returns column accoridng to the given code.
    ColumnMultiEdit this[int columnId] Function returns column accoridng to the given id.

    Properties of the object ColumnMultiEdit

    Name Decription
    ColumnClassDef Column Determination of column for which the setting applies.
    bool ReadOnly Indication whether column shall be displayed in readonly mode.
    bool Visible Indication whether column shall be displayed.

    Script parameters for a new record

    The script is executed after clicking on button New.

    OGNewDataRow - DataRow for a new record.
    OGActualMessage - object for setting error message.
    OGDataRows - list of records that are already in the multi-edit webpart. You can use it for check whether user can add a new record.
    OGPerson - selected new user.

    OGWebPart - instance of the webpart.

    OGWebParts - list of all webparts in the page. In order to access the webparts use their code.

    When an errror message is set by means of method OGActualMessage.SetError, you can cancel the creation of a new record. An error message is then displayed to the user.

     

    If there is property NewAsPerson checked in the webpart settings, there is a person, that the user selected at creation of a the record, passed in the parameter OGPerson. You can read this property in the script and check, whether a record can be created with selected user. Insert the user into OGNewDataRow if needed.

    Script parameters for storing records

    OGDataRows - list of records that shall be saved. The list contains only records that were changed by the user. At the same timese it contains only records that are not readonly.

    OGWebPart - instance of the webpart.

    OGWebParts - list of all webparts in the page. In order to access the webparts use their code.

    The saving itself will be secured by the webpart. You just check that everything is properly defined. If you find an error, throw an exception (OG.Throw) and saving will be cancelled.

    Script parameters for record deletion

    OGDataRowId - Id of a deleted record

    OGWebPart - instance of the webpart.

    OGWebParts - list of all webparts in the page. In order to access the webparts use their code.

    If you throw an exception (OG.Throw) in the script, saving will be cancelled.

    Scripts on page

    You can set url for button Back and crumbread navigation on page by means of following. You will read the values from the webpart MultiEdit with code multi-edit. You have to define these values before in the initialization script of the webpart.

    function OnPreRender()
    {
        var m = OGWebParts['multi-edit'];

        OGForm.SetLinkNavigation( m.LinkNavigation);

        var b = OGForm.GetControl('backToolbarButton');
        b.Visible = true;
        b.NavigateUrl = m.BackUrl;
    }

    Method SetColumn...

    Methods SetColumn... can set a particular property for particular column. Use them only in initialization script.

    Index for column starts from 0 for the first column.

    CSS styles cannot be inserted into the page by means of this webpart but you can insert them by means of webpart Script.

    Following script inserts a query and two columns into the configuration. Then CSS style is added. Finally horizontal shift is switched on.

    var m = OG.Model.GetByCode('it');
    var q = m.Queries['task_multi_edit'];
    OGInit.Query = q;
    OGInit.Columns.Add( q.Columns['t_name']);
    OGInit.Columns.Add( q.Columns['p_name']);
     
    OGInit.SetColumnCss( 0, 'task headcol');
    OGInit.SetColumnCss( 1, 'proj');
     
    OGInit.HorizontalScrollable = true;

    Script examples

    Below scripts are from capacity planning model, where users can edit project plan capacities.

    Script for initialization

    var cl = OG.ClassDef.GetByCode( 'it', 'project_year_requested_resources_monthly');
    OGInit.ClassDef = cl;
    OGInit.NewAsPerson = true;
    OGInit.Columns.Add(cl.Columns['resource']);
    OGInit.Columns.Add(cl.Columns['requested_resource_status']);
    OGInit.Columns.Add(cl.Columns['m01']);
    OGInit.Columns.Add(cl.Columns['m02']);
    OGInit.Columns.Add(cl.Columns['m03']);
    OGInit.Columns.Add(cl.Columns['m04']);
    OGInit.Columns.Add(cl.Columns['m05']);
    OGInit.Columns.Add(cl.Columns['m06']);
    OGInit.Columns.Add(cl.Columns['m07']);
    OGInit.Columns.Add(cl.Columns['m08']);
    OGInit.Columns.Add(cl.Columns['m09']);
    OGInit.Columns.Add(cl.Columns['m10']);
    OGInit.Columns.Add(cl.Columns['m11']);
    OGInit.Columns.Add(cl.Columns['m12']);

    var zpid = OG.QueryString.GetInt('drId');
    if ( zpid != null)
    {
        var clPR = OG.ClassDef.GetByCode( 'it', 'project_resources');
        var f = OG.DataRow.GetDataRowFilter( clPR.Id, zpid);
        var r = OG.ClassDef.HaveUserRightByClassDef( clPR.Id, OG.ClassDef.ClassDefRoleOperation_Update);
        if ( r == OG.ClassDef.RoleRight_RoleWithOrgStructure)
        {
            f.Filter_AplyOrgStructureForOperation = OG.ClassDef.ClassDefRoleOperation_Update;
        }
        var drl = OG.DataRow.GetDataByFilter(f);

        if ( drl != null && drl.Count == 1)
        {
            var dr = drl[0];
            var drp = dr.GetDR('project');
            var i = OGInit.Detail.CreateItem(clPR.Columns['project'].Name, drp.ShortDescription);
            i.ValueLink = drp.DetailUrl;
            OGInit.Detail.AddRow(i);

            var i1 = OGInit.Detail.CreateItem(clPR.Columns['year'].Name, dr['year']);
            var i2 = OGInit.Detail.CreateItem(clPR.Columns['amount'].Name, dr['amount']);
            OGInit.Detail.AddRow(i1, i2);

            var col = clPR.Columns['cost_type'];
            var i1 = OGInit.Detail.CreateItem(clPR.Columns['cost_type'].Name, dr.GetColumnDataAsString2( col.Id, col.ColumnType));
            var i2 = OGInit.Detail.CreateItem(clPR.Columns['accounting_amount'].Name, dr['accounting_amount']);
            OGInit.Detail.AddRow(i1, i2);

            var col = clPR.Columns['accounting_currency'];
            var i = OGInit.Detail.CreateItem(clPR.Columns['accounting_currency'].Name, dr.GetColumnDataAsString2( col.Id, col.ColumnType));
            OGInit.Detail.AddRow(i);

            OGInit.LinkNavigation = clPR.Model.Name + '|ModelInfo.aspx?Id=' + clPR.Model.Id + '>' + clPR .Name + '|' + dr.ListUrl + '>Záznam ID ' + dr.Id + '|' + dr.DetailUrl + '>Multi edit|WebContentPage.aspx' + OG.QueryString.Query;
            OGInit.BackUrl = dr.DetailUrl;
        }
        else
        {
            OGInit.ErrorMessage = 'Nemáte právo na úpravu zdrojů.';
        }
    }
    else
    {
        OGInit.ErrorMessage = 'Není zadán zdroj pro úpravu.';
    }

    Script for reading records

    var zpid = OG.QueryString.GetInt('drId');
    if ( zpid != null)
    {
        var col = OGInit.ClassDef.Columns['project_resources'];

        var f = OG.DataRow.GetDataRowFilter( OGInit.ClassDef.Id);
        f.Filter_OnlyActive = true;
        f.SetColumnData( col.Id, zpid);
        //seradit
        var drl = OG.DataRow.GetDataByFilter(f);

        var cl = OG.ClassDef.GetByCode( OGInit.ClassDef.Model.Id, 'requested_resource_status');
        var planStatus = OG.DataRow.GetDataRowByCode(null, cl, 'plan');
        var approvedStatus = OG.DataRow.GetDataRowByCode(null, cl, 'approved');
        var forapproveStatus = OG.DataRow.GetDataRowByCode(null, cl, 'for_approve');

        var usIds = ',';
        for( var i = 0; i < drl.Count; ++i)
        {
            var statusId = drl[i]['requested_resource_status'];
            if ( statusId == planStatus.Id || statusId == forapproveStatus.Id)
            {
                usIds += drl[i]['resource'].Id + ',';
            }
        }
        OG.SetItem('users1', usIds);

        return drl;
    }

    return null;

    Script for display of records

    OGRow['resource'].ReadOnly = true;
    OGRow['requested_resource_status'].ReadOnly = true;

    var usIds = OG.GetItem('users1');
    if ( usIds != null)
    {
       var cl = OG.ClassDef.GetByCode( OGClassDef.Model.Id, 'requested_resource_status');
       var approvedStatus = OG.DataRow.GetDataRowByCode(null, cl, 'approved');

       if ( OGDataRow['requested_resource_status'] == approvedStatus.Id && usIds.indexOf( ',' + OGDataRow['resource'].Id + ',') >= 0)
       {
          //var planStatus = OG.DataRow.GetDataRowByCode(null, cl, 'plan');
          var ro = true;   //!( OGDataRow['requested_resource_status'] == planStatus.Id);
          OGRow['m01'].ReadOnly = ro;
          OGRow['m02'].ReadOnly = ro;
          OGRow['m03'].ReadOnly = ro;
          OGRow['m04'].ReadOnly = ro;
          OGRow['m05'].ReadOnly = ro;
          OGRow['m06'].ReadOnly = ro;
          OGRow['m07'].ReadOnly = ro;
          OGRow['m08'].ReadOnly = ro;
          OGRow['m09'].ReadOnly = ro;
          OGRow['m10'].ReadOnly = ro;
          OGRow['m11'].ReadOnly = ro;
          OGRow['m12'].ReadOnly = ro;
       }
    }

    Script for a new record

    var cl1 = OG.ClassDef.GetById( OGNewDataRow.ParentId);
    var cl = OG.ClassDef.GetByCode( cl1.Model.Id, 'requested_resource_status');
    var planStatus = OG.DataRow.GetDataRowByCode(null, cl, 'plan');

    OGNewDataRow['requested_resource_status'] = planStatus .Id;
    OGNewDataRow['resource'] = OGPerson.ToPersonInfo();
    OGNewDataRow['project_resources'] = OG.QueryString.GetInt('drId');

    if ( OGPerson != null && OGDataRows != null)
    {
        for( var i = 0; i < OGDataRows.Count; ++i)
        {
            var p = OGDataRows[i]['resource'];
            if ( p != null && p.Id == OGPerson.Id)
            {
                OGActualMessage.SetError('This user is already selected. Please select another user.');
            }
        }
    }

    Example of appearance

    There are values from a parent record in the upper part of the webpart. Properties and values are populated by a script for initialization.

    Then there are buttons for a new record and saving of all the records.

    The last part are records for editing. In the below example there are two columns in read-only mode. Other columns in a row can be edited.

     

    Webpart configuration example. Each script has its own text field.

×