Wiki source code of Zähler


Hide last authors
gru 1.2 1 {{content/}}
2
3 {{id name="fig_counter"/}}
gru 5.7 4 {{figure image="counter_en.png" clear="h1"}}Configuration interface for creating counters: (1) list of existing counters, (2) area for editing the selected counter, (3) metadata of the counter.{{/figure}}
gru 1.2 5
gru 5.7 6 The values of the counters can be changed with the action [[Change counter>>doc:Formcycle.Designer.Workflow.Actions.ModifyCounter]] and read out via [[variables>>doc:Formcycle.UserInterface.Variables]] and thus used in [[conditions>>doc:Formcycle.Designer.Workflow.FlowControl.Condition]], for example.
gru 1.2 7
gru 5.7 8 == Creating a counter ==
gru 1.2 9
gru 5.7 10 Open the "Data > Counter" module and click the "New" button {{ficon name="plus-circle-outline"/}} in the header of the list (see point 1 in [[figure>>||anchor="fig_counter"]]). Then the appropriate [[settings>>||anchor="HKonfigurationsoptionen"]] for the counter can be made. With a click on the //Save// button the counter is created.
gru 1.2 11
gru 5.7 12 == Configuration options ==
gru 1.2 13
14 ; Name
gru 5.7 15 : Name of the counter
16 ; Current value
17 : The current value of the counter is displayed here. After clicking on the pencil symbol, the value can be adjusted and accepted by clicking on the check mark.
18 ; Reset automatically
19 : If this option has been activated, the following options can be used to specify under which conditions the counter is to be reset:
20 :; Initial value
21 :: Value to which the counter is to be reset
22 :; Condition
23 :: Condition under which the counter is to be reset. The following options are available for selection:
24 ::: - Counter greater than or equal
25 ::: - Counter less than or equal
26 ::: - daily
27 ::: - weekly
28 ::: - monthly
29 ::: - yearly
30 :: According to the selection made here, the following fields become visible:
31 ::; Value
32 ::: Value with which the counter is to be compared. Only available if //counter greater than or equal// or //counter less than or equal// has been selected as condition.
33 ::; at
34 ::: Time at which the reset should take place. Only available if //daily//, //weekly//, //monthly// or //annually// is selected as condition.
35 ::; On days
36 ::: Day of the week on which the reset should take place. Only available if //weekly// is selected as condition.
37 ::; Day of the month
38 ::: Day in month on which the counter is to be reset. Only available if //monthly// or //yearly// is selected as condition.
39 ::; Month
40 ::: Month in which the counter is to be reset. Only available if //annual// is selected as condition.
gru 1.2 41
gru 5.7 42 The following information is also displayed under the settings in //Counter meta data//:
gru 1.2 43
44 ; UUID
gru 5.7 45 : System internal UUID of the counter
gru 1.2 46 ; Angelegt am
gru 5.7 47 : Time when the counter was created
gru 1.2 48 ; Geändert am
gru 5.7 49 : Time when changes were last made to the meter
gru 1.2 50
gru 5.7 51 == Variables ==
gru 3.6 52
gru 5.7 53 The values of counters can be read out via [[variables>>doc:Formcycle.UserInterface.Variables]], for example in the workflow or as values of form elements. The syntax is as follows:
gru 3.7 54
gru 5.7 55 {{code language="none"}}[%$COUNTER_CLIENT.<name of the counter>%]{{/code}}
gru 3.7 56
gru 3.12 57
gru 5.7 58 == Access of counter value via servlet ==
gru 3.11 59
gru 5.7 60 === Servlet {{smallcaps}}URL{{/smallcaps}} and parameters ===
gru 3.7 61
gru 5.7 62 The value of the counters can be determined within forms via a servlet call. It is possible to select the counter by its name or UUID. The corresponding {{smallcaps}}URL{{/smallcaps}}s for calling the values could look like the following, for example:
gru 3.11 63
gru 5.7 64 {{code language="none"}}https://<server address>/formcycle/form/clientcounter/?frid=<Valid frid>&name=<name of the counter>{{/code}}
65 and
66 {{code language="none"}}https://<server address>/formcycle/form/clientcounter/?frid=<Valid frid>&uuid=<UUID of the counter>{{/code}}
gru 3.7 67
gru 3.8 68
gru 5.7 69 In both cases a valid //form request id// (frid) is required, which can be found in the form via JavaScript under {{code language="none"}}XFC_METADATA.currentSessionFRID{{/code}}. In the same way, the {{smallcaps}}URL{{/smallcaps}} of the servlet can be read via JavaScript under {{code language="none"}}XFC_METADATA.urls.counter_client{{/code}}. This is important because the {{smallcaps}}URL{{/smallcaps}} differs when called from frontend and master servers.
70
71 === Return values ===
72
73 The result is returned as JSON. Besides the actual value, other information is also returned. The response has the following structure:
gru 3.7 74 ; success
gru 5.7 75 : Boolean value that indicates whether the meter value could be read successfully.
gru 3.7 76 ; msg
gru 5.7 77 : Server message related to the request, which can be used for debugging. A successful access returns e.g. //Counter found//.
gru 3.7 78 ; result
gru 5.7 79 : Response to the request. If the request was not successful, only an empty JSON object literal is returned. On the other hand, if the request was successful, the following sub-items are included in the JSON object literal:
gru 3.7 80 :; lastChange
gru 5.7 81 :: Formatted output of date and time of the last change of the counter value
gru 3.7 82 :; lastChangeTimestamp
gru 5.7 83 :: Epoch of the last change of the counter value
gru 3.7 84 :; name
gru 5.7 85 :: Name of the counter
gru 3.7 86 :; uuid
gru 5.7 87 :: UUID of the counter
gru 3.7 88 :; value
gru 5.7 89 :: Current counter value
gru 3.7 90
gru 5.7 91 === Example of an AJAX request in a form ===
gru 3.12 92
gru 5.7 93 An example AJAX request that writes the current counter value of the //sample counter// to the //tf1// field might look like the following:
gru 3.12 94
95 {{code language="javascript"}}
96 $.ajax({
gru 3.18 97 method: "GET",
98 url: XFC_METADATA.urls.counter_client,
99 data: {
gru 5.7 100 name: "Examplecounter",
gru 3.18 101 frid: XFC_METADATA.currentSessionFRID,
102 }
103 }).then(function(data) {
104 if (data.success) {
105 $('[data-name="tf1"]').val(data.result.value);
106 } else {
gru 5.7 107 console.warn("Access to counter 'Examplecounter' failed:", data.msg);
gru 3.18 108 }
109 }).catch(function(jqXHR, errorTextStatus, errorThrown) {
gru 5.7 110 console.warn("Access to counter 'Examplecounter' failed:", errorThrown, "(" + errorTextStatus + ")");
gru 3.12 111 });
112 {{/code}}
gru 3.21 113
gru 5.7 114 === Inserting a template for an AJAX request in the form ===
gru 3.22 115
gru 5.7 116 {{figure image="counter_query_en.png"}}Selection of the template for the counter query in the JavaScript area of the form designer.{{/figure}}
gru 3.22 117
gru 5.7 118 A template similar to the above example function can be inserted directly in the JavaScript area of the Form Designer using Autocomplete. To do this, enter {{code language="none"}}Counter query{{/code}} (or at least {{code language="none"}}Counter{{/code}}) one after the other in the JavaScript area and select and confirm the //Counter query// option suggested by Autocomplete with a click or with the Arrow keys and the Enter key.
gru 3.22 119
gru 5.7 120 After the template is inserted, the required functionality must be added and the name of the counter must be changed.