1. Kayako Download customers: we will continue to develop and support Kayako Download beyond July 2017, alongside the new Kayako for existing customers.

    Find out more.

  2. The forum you are viewing relates to Kayako Classic. If you signed up or upgraded to the new Kayako (after the 4th July 2016), the information in this thread may not apply to you. You can visit the forums for the new Kayako here.

Hide some inputs in Edit Tab

Discussion in 'Developing, APIs and extending' started by Jessy_J, Oct 28, 2016.

  1. Jessy_J

    Jessy_J New Member

    Hello everyone.


    We need to hide inputs email and SLA (see explanation in the atachment explanation.jpg) from all users group, except Administrator. I came up with the nex idea:


    In line 3200 (kayako\__apps\tickets\staff\class.View_Ticket.php) I changed following code:

    PHP:
    $_EditTabObject->Text('editemail'$this->Language->Get('edit_email'), ''$_ticketEmailAddress);
    by:
    PHP:
    If ($_SWIFT->Staff->GetProperty('staffgroupid') == 1)

    {

        
    $_EditTabObject->Text('editemail'$this->Language->Get('edit_email'), ''$_ticketEmailAddress);

    }

    I repeated it in line 3224 with following code:

    PHP:
    $_EditTabObject->Select('editticketslaplanid'$this->Language->Get('edit_overridesla'), $this->Language->Get('desc_edit_overridesla'), $_optionsContainer);
    by:

    PHP:
    If ($_SWIFT->Staff->GetProperty('staffgroupid') == 1)

    {

    $_EditTabObject->Select('editticketslaplanid'$this->Language->Get('edit_overridesla'), $this->Language->Get('desc_edit_overridesla'), $_optionsContainer);

    }

    In the result inputs were hide but when we try to accept editing, we see errors (see atacments).


    How can I fix it? Maybe there is another way to solve this task?
     

    Attached Files:

  2. Phil R

    Phil R Established Member

    There is.

    The Text function is defined under .../__swift/apps/base/library/UserInterface/class.SWIFT_UserInterfaceTab.php and has the following signature

    Code:
    /**
             * Print a Text Row
             *
             * @author Varun Shoor
             * @param string $_name The Field Name
             * @param string $_title The Field Title
             * @param string $_description (OPTIONAL) The Field Description
             * @param string $_defaultValue (OPTIONAL) The Default Field Value
             * @param string $_type (OPTIONAL) The Field Type (text/password/file)
             * @param int $_fieldSize (OPTIONAL) The Field Size
             * @param int $_maxLength (OPTIONAL) The Maximum Length of Characters Allowed
             * @param string $_id (OPTIONAL) The Unique Field ID
             * @param string $_customClass (OPTIONAL) The Custom Class for this field
             * @param string $_fieldSuffix (OPTIONAL) The Field Suffix
             * @return bool "true" on Success, "false" otherwise
             */
            public function Text($_name, $_title, $_description = '', $_defaultValue = '', $_type = 'text', $_fieldSize = '30', $_maxLength = 0, $_id = '', $_customClass = '', $_fieldSuffix = '')
    
    This leaves a couple of options for you :D

    In all cases, you must make the call to Text as the body needs to contain the value. When you submit the page, the controller expects to see the value (and your edits means it doesn't see them)

    1: The $_type field can be set to "hidden", meaning it is sent to the page, but the input field is not even displayed.

    2: The $_customClass can be defined to something that will allow you define a read/only value. e.g. set the class to "textInputReadOnly swifttext" (swifttext makes sure it is styles by kayako), then include stuff such as the following in custom CSS.

    Code:
    .textInputReadOnly{-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;
    user-select: none;}
    
    3: The $_fieldSuffix is after the input field. You could use this to inject javascript that marks the field readonly.

    For the select fields.

    Code:
            /**
             * Print a Select Row
             *
             * @author Varun Shoor
             * @param string $_name The Field Name
             * @param string $_title The Field Title
             * @param string $_description (OPTIONAL) The Field Description
             * @param array $_optionsContainer The Options Container Array
             * @param string $_onChange (OPTIONAL) The JavaScript to Execute On Change of Select Item
             * @param string $_divContainerID (OPTIONAL) If the Select Data should be placed in a container div
             * @param string $_extendedData (OPTIONAL) The Extended HTML Data
             * @param mixed $_customWidth (OPTIONAL) Specify Custom Width for First Column
             * @param string $_selectStyle (OPTIONAL) Specify a custom select style
             * @return bool "true" on Success, "false" otherwise
             */
            public function Select($_name, $_title, $_description = '', $_optionsContainer = array(), $_onChange = '', $_divContainerID = '',
                            $_extendedData = '', $_customWidth = false, $_selectStyle = '')
    
    Option 3 is possible by setting $_extendedData, and option 2 is sort of possible, but specifying a inline CSS rather than CSS class.
     
    Jessy_J likes this.
  3. Jessy_J

    Jessy_J New Member


    Thanks. I prefer first option, but I don't fully understand where I should write "hidden". Can you write some example, please?
     
  4. Phil R

    Phil R Established Member

    Based on the signatures provided and the original code segments provided (not your suggested code segments).

    First one is each, as it only needs the one extra param.

    From:
    PHP:
    $_EditTabObject->Text('editemail'$this->Language->Get('edit_email'), ''$_ticketEmailAddress);
    To:
    PHP:
    $_EditTabObject->Text('editemail'$this->Language->Get('edit_email'), ''$_ticketEmailAddress'hidden');
    The SLA plan does not have the first option available, as it is a select list.

    However, the following should work just as well. Your source may differ (as my line numbers do not match)

    PHP:
            foreach ($_slaPlanCache as $_slaPlanID => $_slaPlanContainer) {

                if (
    $_SWIFT_TicketObject->GetProperty('ticketslaplanid') == $_slaPlanID) {
                    
    $_optionsContainer[$_index]['selected'] = true;
                    
    $_optionsContainer[$_index]['title'] = $_slaPlanContainer['title'];
                     
    $_optionsContainer[$_index]['value'] = $_slaPlanID;
                } elseif (
    $_SWIFT->Staff->GetProperty('staffgroupid') == 1) {
                    
    $_optionsContainer[$_index]['title'] = $_slaPlanContainer['title'];
                    
    $_optionsContainer[$_index]['value'] = $_slaPlanID;
                }

                 
    $_index++;
            }

            
    $_EditTabObject->Select('editticketslaplanid'$this->Language->Get('edit_overridesla'), $this->Language->Get('desc_edit_overridesla'), $_optionsContainer);
     
    Gary McGrath and Jessy_J like this.
  5. Phil R

    Phil R Established Member

    Infact, my second segment will not work as expected.

    It will offer the default as well as any custom selected one. This means it supports changes.

    However, the core concept and attempts to work on editing it are on the correct theme, it just needs some tweaks.
     
    Jessy_J likes this.
  6. Jessy_J

    Jessy_J New Member

    @Phil R , after 81 trials I made two prototypes:

    1. Administrator can change SLA select. Other users cannot change it. But if administrator will change SLA, then user would have two options in the SLA select: default and current. What should I do to hide from other users all options in the SLA select, except current? Code:

    PHP:
    $_optionsContainer = array();
            
    $_index 1;
            
    $_optionsContainer[0]['title'] = $this->Language->Get('editslausedef');
            
    $_optionsContainer[0]['value'] = '0';

            if (
    $_SWIFT_TicketObject->GetProperty('ticketslaplanid') == '0') {
                
    $_optionsContainer[0]['selected'] = true;
            }

            foreach (
    $_slaPlanCache as $_slaPlanID => $_slaPlanContainer) {
             

                if (
    $_SWIFT->Staff->GetProperty('staffgroupid') == 1) {
                    
    $_optionsContainer[$_index]['selected'] = true;
                    
    $_optionsContainer[$_index]['title'] = $_slaPlanContainer['title'];
                    
    $_optionsContainer[$_index]['value'] = $_slaPlanID;
                } elseif (
    $_SWIFT_TicketObject->GetProperty('ticketslaplanid') == $_slaPlanID) {
                    
    $_optionsContainer[$_index]['title'] = $_slaPlanContainer['title'];
                    
    $_optionsContainer[$_index]['value'] = $_slaPlanID;
                }

                
    $_index++;
            }

            
    $_EditTabObject->Select('editticketslaplanid'$this->Language->Get('edit_overridesla'), $this->Language->Get('desc_edit_overridesla'), $_optionsContainer);
    2. Administrator can change SLA select. Other users cannot change it and they always see default SLA in the SLA select. It means that after editing ticket info they change SLA on the default. How can I keep in the select only current SLA? Code:

    PHP:
    $_optionsContainer = array();
            
    $_index 1;
            
    $_optionsContainer[0]['title'] = $this->Language->Get('editslausedef');
            
    $_optionsContainer[0]['value'] = '0';

            if (
    $_SWIFT_TicketObject->GetProperty('ticketslaplanid') == '0') {
                
    $_optionsContainer[0]['selected'] = true;
            }

            foreach (
    $_slaPlanCache as $_slaPlanID => $_slaPlanContainer) {
              

                if (
    $_SWIFT->Staff->GetProperty('staffgroupid') == 1) {
                    
    $_optionsContainer[$_index]['selected'] = true;
                    
    $_optionsContainer[$_index]['title'] = $_slaPlanContainer['title'];
                    
    $_optionsContainer[$_index]['value'] = $_slaPlanID;
                }

                
    $_index++;
            }

            
    $_EditTabObject->Select('editticketslaplanid'$this->Language->Get('edit_overridesla'), $this->Language->Get('desc_edit_overridesla'), $_optionsContainer);
    If I am correct then this two params: $_optionsContainer[0]['title'] = $this->Language->Get('editslausedef'); and $_optionsContainer[0]['value'] = '0'; are define default values in the SLA Select.
     
  7. Phil R

    Phil R Established Member

    Correct, the $_optionsContainer[0] is the cause, which is the unhandled item I was noting in my quick follow-up reply.

    Now I am in front of a decent editor, the following suggestion could apply.

    PHP:
            $_optionsContainer = array();
            
    $_index 0;

            if (
    $_SWIFT->Staff->GetProperty('staffgroupid') == || $_SWIFT_TicketObject->GetProperty('ticketslaplanid') == '0') {
                
    // The user is an admin OR the current plan is DEFAULT
                
    $_optionsContainer[$_index]['title'] = $this->Language->Get('editslausedef');
                
    $_optionsContainer[$_index]['value'] = '0';

                if (
    $_SWIFT_TicketObject->GetProperty('ticketslaplanid') == '0') {
                    
    $_optionsContainer[$_index]['selected'] = true;
                }

                
    $_index++;
            }

            foreach (
    $_slaPlanCache as $_slaPlanID => $_slaPlanContainer) {
                if (
    $_SWIFT_TicketObject->GetProperty('ticketslaplanid') == $_slaPlanID) {
                    
    // Always include the selection option. This is not triggered if DEFAULT
                    
    $_optionsContainer[$_index]['title'] = $_slaPlanContainer['title'];
                    
    $_optionsContainer[$_index]['value'] = $_slaPlanID;
                    
    $_optionsContainer[$_index]['selected'] = true;
                } elseif (
    $_SWIFT->Staff->GetProperty('staffgroupid') == 1) {
                    
    // User is admin, include the item
                    
    $_optionsContainer[$_index]['title'] = $_slaPlanContainer['title'];
                    
    $_optionsContainer[$_index]['value'] = $_slaPlanID;
                }

                
    $_index++;
            }

            
    $_EditTabObject->Select('editticketslaplanid'$this->Language->Get('edit_overridesla'), $this->Language->Get('desc_edit_overridesla'), $_optionsContainer);
    This will include the "Default" entry only if it is already selected, or they are admin.

    It will then build the rest of the list on the basis of
    * In full if they are admin
    * Only the current selection if not

    It's mutually exclusive. So unless they are admin, they should only see default or the current one.
     
    Jessy_J likes this.
  8. Jessy_J

    Jessy_J New Member

    @Phil R , thank you. It works well. I tried something like this, I was close to conclusion :) Thanks again.
     

Share This Page