Skip to main content

Template

Template file

TemplateThe template file is the backbone of the whole widget. It is built on the simple JavaScript function building returning vue Instance object.  Each Vue Instanceinstance whichhas a unique id. It serves this purpose for easy saving of the user settings, user's data, and preferences. In the runtime "CustomModuleName_DynamicID" is indivuduallybeing createdreplaced with proper widget's id for everyfurther user and saved to the database.actions.

(function (internalName) {
    var internalID = internalName;
    return {
        name:moduleName: internalID,
        component: Vue.component(internalID, {
            props: [],
            data:, 
            mounted() {},
            activated() {},
            deactivated() {},
            methods: {},
            computed: {},
            template: ``
        }),
    }

}("CustomModuleName_DynamicID"));

LanguageWorking supportwith database

ToEvery useCustomer predefinedPanel languagelaunch strings,system dependingchecks onif the user'sconfiguration defaultfor languagea settingsspecific youcustomer canalready simply reference themexists in the templatedatabase. fileIf likeit this:doesn't exist, it is being created, and then return to the frontend, or in the case, it already exists, simply return.

The system creates the configuration with the following pattern:

  • <module_name>_<module_id>_<user_login>_hkrOUgHKUi_<invoking_module_name>_Settings
  • <module_name>_<module_id>_<user_login>_hkrOUgHKUi_<invoking_module_name>_Data

Saving with Settings prefix is used for storing widget's configuration taken from the global widget's settings.

Saving with Data prefix is used for storing user's saved data. [settings configuration/user's actions/notes]

Set

Setting a user's data can be resolved with the following endpoint:

POST <OTRS_URL>/customer.pl?Action=CustomerFrontend;Subaction=SetWidgetData;ID=<moduleName>

sendNote: widgetTitle(_.debounce(function () {
        returnaxios.post(this.$store.getters["globalConfig/OTRS_URL"] + "customer.pl?Action=CustomerFrontend;Subaction=SetWidgetData;ID=" + this.$t('WidgetmoduleName, name'{
            note: this.note
        }).then((response) => {
            console.log("Send note!")
        }).catch((error) => {
            console.log("ERROR [setWidgetConfig] ", error)
        });
    }, 300),
Get

Getting a user's data can be resolved with the following endpoints:

GET <OTRS_URL>/customer.pl?Action=CustomerFrontend;Subaction=GetWidgetData;ID=<moduleName>

getNote() {
        axios.get(this.$store.getters["globalConfig/OTRS_URL"] + "customer.pl?Action=CustomerFrontend;Subaction=GetWidgetData;ID=" + this.moduleName).then((response) => {
            if (response.data.success) {
                this.note = response.data.data.note
            }})}}

orThese directlyoperations ineasily describe the HTML template:

<span> {{$t('Contract loading')}}</span>

Example HTML template

                <v-flex xs12 md12 d-flex>
                    <material-card
                            style="margin-top:0px"
                            color="primary"
                            :title="widgetTitle">
                        <v-layout class="text-xs-center">
                            <v-flex xs12>
                                <v-rating
                                        v-model="rate"
                                        v-on:input="setMyRate"
                                        :length="5"
                                        :half-increments="false"
                                        hover
                                ></v-rating>
                                <v-card color="success" dark v-if="rate>0"><b>{{$t('Your rate')}}: {{rate}}</b></v-card>
                                <v-card color="error" v-else>{{$t("You haven't rated thiswhole idea yet")}}</v-card>of </v-flex>the </v-layout>template </material-card>
                </v-flex>
mechanism.

Global Storage

Global storage contains the most important informations about OTRS and current CustomerPanel instance.

You can refer to its values by the keyword this.$store  and retrieve properties with  getters . Example of useful values:

[
	"account/getSessionId": "lkDT71THevxijoiKprX9LoHmehkoWu4emCa",
	"globalConfig/BACKEND_VERSION": "1.2.54",
	"globalConfig/FRONTEND_VERSION": "1.1.40",
	"globalConfig/OTRS_DEFAULT_LANG": "en",
	"globalConfig/OTRS_FQDN": "http://helpdesk.int.intalio.pl",
	"globalConfig/OTRS_ScriptAlias": "/otrs/",
	"globalConfig/OTRS_URL": "http://helpdesk.int.intalio.pl/otrs/",
]

These are very useful while working on your widgets. They allow you to connect to OTRS API .

getContractInfo() {
  axios.get(this.$store.getters["globalConfig/OTRS_URL"] + `customer.pl?Action=ContractWidget;Subaction=GetContractInfo;Tn=${this.$route.params.ticketNumber}`).then((response) => {
      if (response.data.success === false) {
          this.contract_info = null
          this.contractLoading = false
      } else {
          this.contract_info = response.data.information
          this.contractLoading = false
     }
  })
}

Language support

To use predefined language strings, depending on the user's default language settings you can simply reference them in the template file like this:

 widgetTitle() {
     return this.$t('Widget name')
}

or directly in the HTML template:

<span> {{$t('Contract loading')}}</span>