Module ckbox_mx.pkg

     1//************************************************************************
     2//     File Name: CkBox_Mx.Pkg
     3// Creation Date: Thu  01-16-1992
     4//     Author(s): John J. Tuohy
     5// 12/13/93 05:50 pm  Major Reworking to work with DAF classes
     6//
     7// Class: Entry_CheckBox_Mixin  - mixin for checkbox support
     8//        CBox_Array            - internal needed by ckbox
     9//
    10// This is a mixin class designed to be used by entry related classes
    11// that need checkbox support. This supports table and entry-form classes.
    12//
    13// 03/15/94 - Optimized cBox so it is only created when it is needed
    14// 07/21/94 - Removed set_checkbox command. Commands, we don't need to show
    15//            you no stinking new commands.
    16// 09/18/94 - entry_display gaurds against empty row in tables
    17// 02/08/95 - JJT **JJT**(2) Modified entry_update logic. doall flag was
    18//                over-doing it.
    19// 09/04/95 JJT - Code Clean up (removed dead commented code)
    20// 2/26/2002  JJT - 8.2 clean up (indirect_file, local, self, etc.)
    21//************************************************************************/
    22
    23use VDFBase.pkg
    24
    25// the object CBox has to get defined directly by the class. If not,
    26// things get buggy (you can't create objects in mixin classes).
    27
    28
    29{ Visibility=Private }
    30Class CBox_Array is an Array
    31  //
    32  // Public Access Methods:
    33  //
    34  // Function  CheckBox_Value Integer Num Integer State Returns String
    35  // Function  CheckBox_Item Integer Num Returns Integer
    36  // Function  CBox_Item_Count Returns Integer
    37  // Procedure CheckBox_Values Integer Itm String TrueValue String FalseValue
    38  //
    39  //
    40  // cbox is a three dimensional array.
    41  // dimension: 0 - Integer : actual item number
    42  //            1 - String  : True value for database
    43  //            2 - String  : False value for database
    44  //
    45  Function CheckBox_Value Integer Num Integer State Returns String
    46     Function_Return (String_Value(self,Num*3+if(State,1,2)))
    47  End_Function
    48
    49  Function CheckBox_Item Integer Num Returns Integer
    50     Function_Return (Integer_Value(self,Num*3))
    51  End_Function
    52
    53  Function CBox_Item_Count Returns Integer
    54     Function_Return (Item_Count(self)/3)
    55  End_Function // CBox_Item_Count
    56
    57  Procedure CheckBox_Values Integer Itm String TrueValue String FalseValue
    58    Integer ArryNum
    59    Get Item_Count to ArryNum
    60    Set Array_Value Item ArryNum to Itm
    61    Increment ArryNum
    62    Set Array_Value Item ArryNum to TrueValue
    63    Increment ArryNum
    64    Set Array_Value Item ArryNum to FalseValue
    65  End_Procedure
    66
    67End_Class
    68
    69
    70{ ClassType=Mixin }
    71Class Entry_CheckBox_Mixin is a mixin
    72
    73  { Visibility=Private }
    74  Procedure Define_CheckBox_Support
    75    // a bit of an optimization. The object will only be created if required.
    76    // once created its ID will be defined here.
    77
    78    { Visibility=Private }
    79    Property Integer CBox_Object 0
    80    Set Select_mode to Multi_Select
    81  End_Procedure
    82
    83  // Bug fix: As a side effect of setting select_mode we get a change in
    84  //          auto_top_item_state. We will make sure that doesn't
    85  //          happen here.
    86
    87  { NoDoc=True MethodType=Property Visibility=Private }
    88  Procedure Set Select_Mode Integer Mode
    89     integer Old_Auto_top
    90     Get Auto_top_item_state to old_auto_top
    91     Forward Set Select_Mode to Mode
    92     Set Auto_top_item_state to old_auto_top
    93  End_Procedure // Set Select_Mode
    94
    95  { NoDoc=True Visibility=Private }
    96  Procedure Entry_Display Integer File# Integer Flag
    97    integer dFile i Limit State Item# Arry#
    98    String  Itm CItm
    99    integer iField
   100
   101    Forward send Entry_Display File# Flag // do normal entdisplay
   102    // no fancy stuff if no items exist
   103    if (item_count(self)=0) Procedure_return
   104    // now check for checkbox states and handle those guys a little
   105    // differently
   106    //
   107    Get CBox_Object to Arry# // obj Id of ckbox array
   108    //
   109    //
   110    If Arry# gt 0 Begin
   111
   112       // Limit has number of checkbox items in this form/row
   113       Get CBox_Item_Count of Arry# to Limit
   114       If Limit Begin         // do we have checkbox items?
   115          Decrement Limit     // yeah..make count zero based
   116          For i from 0 to Limit // for all checkbox items
   117              Get CheckBox_Value of Arry# item i TRUE to CItm
   118              If CItm ne '' Begin
   119                Get CheckBox_Item of Arry# item i to Item# // the actual item number
   120                Move (Item# + Base_item(self)) to Item#
   121                // if a checkbox item plus that item is not just a 0 1
   122                get data_file item item# to dFile
   123                if dfile eq 0 indicate found FALSE
   124                else if file# eq 0 is_file_included dFile 1
   125                else indicate found as (file# = dFile OR flag = TRUE)
   126                [FOUND] begin
   127                   get data_Field Item# to iField
   128                   Get_field_value dFile iField to Itm
   129                   Set Select_State Item Item# to (Itm=CItm)
   130                End
   131              End
   132          Loop
   133       End
   134    End
   135  end_procedure
   136
   137  // **JJT**(2) Modified so Flag is treated as a ignore changed_state
   138  //            and not a doAll flag
   139  //
   140  { NoDoc=True Visibility=Private }
   141  procedure Entry_Update integer file# integer flag
   142    integer dFile CItm Limit State Item# Arry# Ok NP
   143    Forward Send Entry_Update File# Flag // do standard update
   144    integer iField iStat
   145    // now do checkbox updates
   146    Get CBox_Object to Arry# // id of cbox array
   147
   148    If Arry# gt 0 Begin
   149
   150       Get CBox_Item_Count of Arry# to Limit
   151       If Limit Begin            // do we have checkbox items?
   152          Decrement Limit        // yeah..make count zero based
   153          For CItm from 0 to Limit // check all items
   154             // only process if we have a T/F value to set
   155             If (CheckBox_Value(Arry#,CItm,TRUE)<>'') Begin
   156                Get CheckBox_Item of Arry# item CItm to Item# // the actual item number
   157                Move (Item#+Base_Item(self)) to Item# // The item with a row offset
   158                get data_file item item# to dFile
   159                // only proceed if we have a file to update
   160                if dfile Begin
   161                   if (file# = 0 AND flag = 3) Begin
   162                     Get Item_Option Item Item# NOPUT to NP
   163                     If NP Indicate Found False
   164                     else is_file_included dFile 1
   165                   End
   166                   else indicate FOUND as (file# = dFile OR file# = 0) // **JJT**(2)
   167                   // This was wrong. Flag determines if item_changed_state should
   168                   // be ignored.
   169                   //else indicate FOUND as (file# = dFile OR flag = TRUE OR file# = 0) //**JJT**(2)
   170                   Move (Found) to OK
   171                   If Ok Begin
   172                      // if we are updating a new record we want to move the
   173                      // item in no matter what.
   174                      // Flag can also be 3 (= save) **JJT**(2)
   175                      if ( Flag<>1 AND Item_changed_State(self,Item#)=0) begin
   176                            Get_attribute DF_FILE_STATUS of dFile to iStat
   177                            If (iStat<>DF_FILE_INACTIVE) Move 0 to Ok // old record...not ok
   178                      end
   179                      If Ok Begin
   180                         get Select_State Item Item# to State
   181                         get data_Field Item# to iField
   182                         Set_field_value dFile iField to (CheckBox_Value(Arry#,CItm,State))
   183                      End
   184                   End
   185                End
   186             End
   187          Loop
   188       End
   189    End
   190  end_procedure
   191
   192  Procedure Set CheckBox_Item String ItemVal String TrueVal String FalseVal
   193    Integer Item# Obj# CObj
   194    // This is the object that has the items. With tables it is the proto-
   195    // type row, with forms it is itself. This allows table and form support
   196    Get ProtoType_Object to Obj#
   197    Get Current_Item of Obj# to Item#
   198    Set entry_state         of Obj# item Item# to False
   199    Set checkbox_item_State of Obj# item Item# to True
   200    Set Value               of Obj# item Item# to ItemVal
   201    // If only 1 argument passed the T/F values are 0/1 which can be
   202    // handled automatically.
   203    If Num_Arguments gt 1 Begin
   204       Get CBox_Object to CObj
   205       // a bit of an optimization here. Only create the cBox object if needed.
   206       // The first time the ID will be zero. When this occurs call the function
   207       // to create the checkbox and then set the id
   208       If CObj eq 0 begin                 // if no cbox object yet.
   209          Get Create_CBox_Object to CObj  // create the object and
   210          Set Cbox_Object to CObj         // set the property.
   211       End
   212       Send CheckBox_Values to CObj Item# TrueVal FalseVal
   213    End
   214  End_Procedure
   215
   216End_Class
   217
   218